Java Code Examples for com.datatorrent.stram.plan.logical.LogicalPlan#SUBDIR_CHECKPOINTS
The following examples show how to use
com.datatorrent.stram.plan.logical.LogicalPlan#SUBDIR_CHECKPOINTS .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StramLocalClusterTest.java From attic-apex-core with Apache License 2.0 | 6 votes |
@Test public void testAppPath() throws Exception { // add operator for initial checkpoint TestGeneratorInputOperator o1 = dag.addOperator("o1", TestGeneratorInputOperator.class); o1.setMaxTuples(1); File relPath = new File(dag.getAttributes().get(DAGContext.APPLICATION_PATH)); String uriPath = relPath.toURI().toString(); dag.setAttribute(DAGContext.APPLICATION_PATH, uriPath); StramLocalCluster cluster = new StramLocalCluster(dag); // no need for run(), just need the initial checkpoint Assert.assertFalse(cluster.isFinished()); Assert.assertTrue("app path exists", relPath.exists() && relPath.isDirectory()); File checkPointDir = new File(relPath, LogicalPlan.SUBDIR_CHECKPOINTS); Assert.assertTrue("checkpoint path exists", checkPointDir.exists() && checkPointDir.isDirectory()); }
Example 2
Source File: StramClient.java From Bats with Apache License 2.0 | 4 votes |
public void copyInitialState(Path origAppDir) throws IOException { // locate previous snapshot long copyStart = System.currentTimeMillis(); String newAppDir = this.dag.assertAppPath(); FSRecoveryHandler recoveryHandler = new FSRecoveryHandler(origAppDir.toString(), conf); // read snapshot against new dependencies Object snapshot = recoveryHandler.restore(); if (snapshot == null) { throw new IllegalArgumentException("No previous application state found in " + origAppDir); } InputStream logIs = recoveryHandler.getLog(); // modify snapshot state to switch app id ((StreamingContainerManager.CheckpointState)snapshot).setApplicationId(this.dag, conf); Path checkpointPath = new Path(newAppDir, LogicalPlan.SUBDIR_CHECKPOINTS); FileSystem fs = FileSystem.newInstance(origAppDir.toUri(), conf); // remove the path that was created by the storage agent during deserialization and replacement fs.delete(checkpointPath, true); // write snapshot to new location recoveryHandler = new FSRecoveryHandler(newAppDir, conf); recoveryHandler.save(snapshot); OutputStream logOs = recoveryHandler.rotateLog(); IOUtils.copy(logIs, logOs); logOs.flush(); logOs.close(); logIs.close(); List<String> excludeDirs = Arrays.asList(LogicalPlan.SUBDIR_CHECKPOINTS, LogicalPlan.SUBDIR_EVENTS, LogicalPlan.SUBDIR_STATS); // copy sub directories that are not present in target FileStatus[] lFiles = fs.listStatus(origAppDir); // In case of MapR/MapR-FS, f.getPath().toString() returns path as maprfs:///<orig app dir> // whereas origAppDir.toString & newAppDir are in maprfs:/<orig or new app dir> format // e.g. // f.getPath().toString -> maprfs:///user/dtadmin/datatorrent/apps/application_1481890072066_0004/checkpoints // origAppDir -> maprfs:/user/dtadmin/datatorrent/apps/application_1481890072066_0004 // newAppDir -> maprfs:/user/dtadmin/datatorrent/apps/application_1481890072066_0005 String origAppDirPath = Path.getPathWithoutSchemeAndAuthority(origAppDir).toString(); String newAppDirPath = Path.getPathWithoutSchemeAndAuthority(new Path(newAppDir)).toString(); for (FileStatus f : lFiles) { if (f.isDirectory() && !excludeDirs.contains(f.getPath().getName())) { String targetPath = f.getPath().toString().replace(origAppDirPath, newAppDirPath); if (!fs.exists(new Path(targetPath))) { LOG.debug("Copying {} size {} to {}", f.getPath(), f.getLen(), targetPath); long start = System.currentTimeMillis(); FileUtil.copy(fs, f.getPath(), fs, new Path(targetPath), false, conf); LOG.debug("Copying {} to {} took {} ms", f.getPath(), f.getLen(), targetPath, System.currentTimeMillis() - start); } else { LOG.debug("Ignoring {} as it already exists under {}", f.getPath(), targetPath); } } } LOG.info("Copying initial state took {} ms", System.currentTimeMillis() - copyStart); }
Example 3
Source File: StramClient.java From attic-apex-core with Apache License 2.0 | 4 votes |
public void copyInitialState(Path origAppDir) throws IOException { // locate previous snapshot long copyStart = System.currentTimeMillis(); String newAppDir = this.dag.assertAppPath(); FSRecoveryHandler recoveryHandler = new FSRecoveryHandler(origAppDir.toString(), conf); // read snapshot against new dependencies Object snapshot = recoveryHandler.restore(); if (snapshot == null) { throw new IllegalArgumentException("No previous application state found in " + origAppDir); } InputStream logIs = recoveryHandler.getLog(); // modify snapshot state to switch app id ((StreamingContainerManager.CheckpointState)snapshot).setApplicationId(this.dag, conf); Path checkpointPath = new Path(newAppDir, LogicalPlan.SUBDIR_CHECKPOINTS); FileSystem fs = FileSystem.newInstance(origAppDir.toUri(), conf); // remove the path that was created by the storage agent during deserialization and replacement fs.delete(checkpointPath, true); // write snapshot to new location recoveryHandler = new FSRecoveryHandler(newAppDir, conf); recoveryHandler.save(snapshot); OutputStream logOs = recoveryHandler.rotateLog(); IOUtils.copy(logIs, logOs); logOs.flush(); logOs.close(); logIs.close(); List<String> excludeDirs = Arrays.asList(LogicalPlan.SUBDIR_CHECKPOINTS, LogicalPlan.SUBDIR_EVENTS, LogicalPlan.SUBDIR_STATS); // copy sub directories that are not present in target FileStatus[] lFiles = fs.listStatus(origAppDir); // In case of MapR/MapR-FS, f.getPath().toString() returns path as maprfs:///<orig app dir> // whereas origAppDir.toString & newAppDir are in maprfs:/<orig or new app dir> format // e.g. // f.getPath().toString -> maprfs:///user/dtadmin/datatorrent/apps/application_1481890072066_0004/checkpoints // origAppDir -> maprfs:/user/dtadmin/datatorrent/apps/application_1481890072066_0004 // newAppDir -> maprfs:/user/dtadmin/datatorrent/apps/application_1481890072066_0005 String origAppDirPath = Path.getPathWithoutSchemeAndAuthority(origAppDir).toString(); String newAppDirPath = Path.getPathWithoutSchemeAndAuthority(new Path(newAppDir)).toString(); for (FileStatus f : lFiles) { if (f.isDirectory() && !excludeDirs.contains(f.getPath().getName())) { String targetPath = f.getPath().toString().replace(origAppDirPath, newAppDirPath); if (!fs.exists(new Path(targetPath))) { LOG.debug("Copying {} size {} to {}", f.getPath(), f.getLen(), targetPath); long start = System.currentTimeMillis(); FileUtil.copy(fs, f.getPath(), fs, new Path(targetPath), false, conf); LOG.debug("Copying {} to {} took {} ms", f.getPath(), f.getLen(), targetPath, System.currentTimeMillis() - start); } else { LOG.debug("Ignoring {} as it already exists under {}", f.getPath(), targetPath); } } } LOG.info("Copying initial state took {} ms", System.currentTimeMillis() - copyStart); }