/** @throws Exception If failed. */ @SuppressWarnings({"TypeMayBeWeakened"}) public void testCorrectAntGarTask() throws Exception { String tmpDirName = GridTestProperties.getProperty("ant.gar.tmpdir"); String srcDirName = GridTestProperties.getProperty("ant.gar.srcdir"); String baseDirName = tmpDirName + File.separator + System.currentTimeMillis() + "_0"; String metaDirName = baseDirName + File.separator + "META-INF"; String garFileName = baseDirName + ".gar"; String garDescDirName = U.resolveIgnitePath(GridTestProperties.getProperty("ant.gar.descriptor.dir")) .getAbsolutePath() + File.separator + "ignite.xml"; // Make base and META-INF dir. boolean mkdir = new File(baseDirName).mkdirs(); assert mkdir; mkdir = new File(metaDirName).mkdirs(); assert mkdir; // Make Gar file U.copy(new File(garDescDirName), new File(metaDirName + File.separator + "ignite.xml"), true); // Copy files to basedir U.copy(new File(srcDirName), new File(baseDirName), true); IgniteDeploymentGarAntTask garTask = new IgniteDeploymentGarAntTask(); Project garProject = new Project(); garProject.setName("Gar test project"); garTask.setDestFile(new File(garFileName)); garTask.setBasedir(new File(baseDirName)); garTask.setProject(garProject); garTask.execute(); File garFile = new File(garFileName); assert garFile.exists(); boolean res = checkStructure(garFile, true); assert res; }
/** @throws Exception if error occur. */ @SuppressWarnings("unchecked") private void checkGar() throws Exception { initGar = true; String garDir = "modules/extdata/p2p/deploy"; String garFileName = "p2p.gar"; File origGarPath = U.resolveIgnitePath(garDir + '/' + garFileName); File tmpPath = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); if (!tmpPath.mkdir()) throw new IOException("Can not create temp directory"); try { File newGarFile = new File(tmpPath, garFileName); U.copy(origGarPath, newGarFile, false); assert newGarFile.exists(); try { garFile = "file:///" + tmpPath.getAbsolutePath(); try { Ignite ignite1 = startGrid(1); Ignite ignite2 = startGrid(2); Integer res = ignite1 .compute() .<UUID, Integer>execute(TASK_NAME, ignite2.cluster().localNode().id()); assert res != null; } finally { stopGrid(1); stopGrid(2); } } finally { if (newGarFile != null && !newGarFile.delete()) error("Can not delete temp gar file"); } } finally { if (!tmpPath.delete()) error("Can not delete temp directory"); } }
/** {@inheritDoc} */ @SuppressWarnings("deprecation") @Override public void start() throws IgniteException { if (sesFactory == null && F.isEmpty(hibernateCfgPath)) throw new IgniteException( "Either session factory or Hibernate configuration file is required by " + getClass().getSimpleName() + '.'); if (!F.isEmpty(hibernateCfgPath)) { if (sesFactory == null) { try { URL url = new URL(hibernateCfgPath); sesFactory = new Configuration().configure(url).buildSessionFactory(); } catch (MalformedURLException ignored) { // No-op. } if (sesFactory == null) { File cfgFile = new File(hibernateCfgPath); if (cfgFile.exists()) sesFactory = new Configuration().configure(cfgFile).buildSessionFactory(); } if (sesFactory == null) sesFactory = new Configuration().configure(hibernateCfgPath).buildSessionFactory(); if (sesFactory == null) throw new IgniteException( "Failed to resolve Hibernate configuration file: " + hibernateCfgPath); closeSesOnStop = true; } else U.warn( log, "Hibernate configuration file configured in " + getClass().getSimpleName() + " will be ignored (session factory is already set)."); } }
/** @param workTokDir Token directory (common for multiple nodes). */ private void processTokenDirectory(File workTokDir) { for (File f : workTokDir.listFiles()) { if (!f.isDirectory()) { if (!f.getName().equals(LOCK_FILE_NAME)) { if (log.isDebugEnabled()) log.debug("Unexpected file: " + f.getName()); } continue; } if (f.equals(tokDir)) { if (log.isDebugEnabled()) log.debug("Skipping own token directory: " + tokDir.getName()); continue; } String name = f.getName(); int pid; try { pid = Integer.parseInt(name.substring(name.lastIndexOf('-') + 1)); } catch (NumberFormatException ignored) { if (log.isDebugEnabled()) log.debug("Failed to parse file name: " + name); continue; } // Is process alive? if (IpcSharedMemoryUtils.alive(pid)) { if (log.isDebugEnabled()) log.debug("Skipping alive node: " + pid); continue; } if (log.isDebugEnabled()) log.debug("Possibly stale token folder: " + f); // Process each token under stale token folder. File[] shmemToks = f.listFiles(); if (shmemToks == null) // Although this is strange, but is reproducible sometimes on linux. return; int rmvCnt = 0; try { for (File f0 : shmemToks) { if (log.isDebugEnabled()) log.debug("Processing token file: " + f0.getName()); if (f0.isDirectory()) { if (log.isDebugEnabled()) log.debug("Unexpected directory: " + f0.getName()); } // Token file format: gg-shmem-space-[auto_idx]-[other_party_pid]-[size] String[] toks = f0.getName().split("-"); if (toks.length != 6) { if (log.isDebugEnabled()) log.debug("Unrecognized token file: " + f0.getName()); continue; } int pid0; int size; try { pid0 = Integer.parseInt(toks[4]); size = Integer.parseInt(toks[5]); } catch (NumberFormatException ignored) { if (log.isDebugEnabled()) log.debug("Failed to parse file name: " + name); continue; } if (IpcSharedMemoryUtils.alive(pid0)) { if (log.isDebugEnabled()) log.debug("Skipping alive process: " + pid0); continue; } if (log.isDebugEnabled()) log.debug("Possibly stale token file: " + f0); IpcSharedMemoryUtils.freeSystemResources(f0.getAbsolutePath(), size); if (f0.delete()) { if (log.isDebugEnabled()) log.debug("Deleted file: " + f0.getName()); rmvCnt++; } else if (!f0.exists()) { if (log.isDebugEnabled()) log.debug("File has been concurrently deleted: " + f0.getName()); rmvCnt++; } else if (log.isDebugEnabled()) log.debug("Failed to delete file: " + f0.getName()); } } finally { // Assuming that no new files can appear, since if (rmvCnt == shmemToks.length) { U.delete(f); if (log.isDebugEnabled()) log.debug("Deleted empty token directory: " + f.getName()); } } } }