List of usage examples for org.apache.commons.io FileUtils forceDeleteOnExit
public static void forceDeleteOnExit(File file) throws IOException
From source file:org.apache.hive.beeline.TestSchemaTool.java
@Override protected void tearDown() throws Exception { File metaStoreDir = new File(testMetastoreDB); if (metaStoreDir.exists()) { FileUtils.forceDeleteOnExit(metaStoreDir); }// ww w . j a v a 2s .com System.setOut(outStream); System.setErr(errStream); if (conn != null) { conn.close(); } }
From source file:org.apache.hive.beeline.TestSchemaToolCatalogOps.java
@AfterClass public static void removeDb() throws Exception { File metaStoreDir = new File(testMetastoreDB); if (metaStoreDir.exists()) { FileUtils.forceDeleteOnExit(metaStoreDir); }/*from w ww. j a v a 2 s . c o m*/ }
From source file:org.apache.hive.service.cli.session.SessionManager.java
private void initOperationLogRootDir() { operationLogRootDir = new File(hiveConf.getVar(ConfVars.HIVE_SERVER2_LOGGING_OPERATION_LOG_LOCATION)); isOperationLogEnabled = true;/*from w w w. j av a 2s . com*/ if (operationLogRootDir.exists() && !operationLogRootDir.isDirectory()) { LOG.warn("The operation log root directory exists, but it is not a directory: " + operationLogRootDir.getAbsolutePath()); isOperationLogEnabled = false; } if (!operationLogRootDir.exists()) { if (!operationLogRootDir.mkdirs()) { LOG.warn("Unable to create operation log root directory: " + operationLogRootDir.getAbsolutePath()); isOperationLogEnabled = false; } } if (isOperationLogEnabled) { LOG.info("Operation log root directory is created: " + operationLogRootDir.getAbsolutePath()); try { FileUtils.forceDeleteOnExit(operationLogRootDir); } catch (IOException e) { LOG.warn("Failed to schedule cleanup HS2 operation logging root dir: " + operationLogRootDir.getAbsolutePath(), e); } } }
From source file:org.apache.karaf.tooling.exam.container.internal.KarafTestContainer.java
private void forceCleanup() { LOGGER.info("Can't remove runtime system; shedule it for exit of the jvm."); try {/*from w ww. ja v a 2 s . com*/ FileUtils.forceDeleteOnExit(targetFolder); } catch (IOException e1) { LOGGER.error("Well, this should simply not happen..."); } }
From source file:org.apache.kylin.engine.mr.steps.MergeCuboidJobTest.java
@Test public void test() throws Exception { // String input = // "src/test/resources/data/base_cuboid,src/test/resources/data/6d_cuboid"; String output = "target/test-output/merged_cuboid"; String cubeName = "test_kylin_cube_with_slr_ready"; String jobname = "merge_cuboid"; File baseFolder = File.createTempFile("kylin-f24668f6-dcff-4cb6-a89b-77f1119df8fa-", "base"); FileUtils.forceDelete(baseFolder);// w ww. j a v a 2s . co m baseFolder.mkdir(); FileUtils.copyDirectory(new File("src/test/resources/data/base_cuboid"), baseFolder); FileUtils.forceDeleteOnExit(baseFolder); File eightFoler = File.createTempFile("kylin-f24668f6-dcff-4cb6-a89b-77f1119df8fa-", "8d"); FileUtils.forceDelete(eightFoler); eightFoler.mkdir(); FileUtils.copyDirectory(new File("src/test/resources/data/base_cuboid"), eightFoler); FileUtils.forceDeleteOnExit(eightFoler); FileUtil.fullyDelete(new File(output)); // CubeManager cubeManager = // CubeManager.getInstanceFromEnv(getTestConfig()); String[] args = { "-input", baseFolder.getAbsolutePath() + "," + eightFoler.getAbsolutePath(), "-cubename", cubeName, "-segmentname", "20130331080000_20131212080000", "-output", output, "-jobname", jobname }; assertEquals("Job failed", 0, ToolRunner.run(conf, new MergeCuboidJob(), args)); }
From source file:org.apache.maven.plugins.scmpublish.AbstractScmPublishMojo.java
private void checkCreateRemoteSvnPath() throws MojoExecutionException { getLog().debug(//from w ww . j av a 2s . com "AbstractSvnScmProvider used, so we can check if remote url exists and eventually create it."); AbstractSvnScmProvider svnScmProvider = (AbstractSvnScmProvider) scmProvider; try { boolean remoteExists = svnScmProvider.remoteUrlExist(scmRepository.getProviderRepository(), null); if (remoteExists) { return; } } catch (ScmException e) { throw new MojoExecutionException(e.getMessage(), e); } String remoteUrl = ((SvnScmProviderRepository) scmRepository.getProviderRepository()).getUrl(); if (!automaticRemotePathCreation) { // olamy: return ?? that will fail during checkout IMHO :-) logWarn("Remote svn url %s does not exist and automatic remote path creation disabled.", remoteUrl); return; } logInfo("Remote svn url %s does not exist: creating.", remoteUrl); File baseDir = null; try { // create a temporary directory for svnexec baseDir = File.createTempFile("scm", "tmp"); baseDir.delete(); baseDir.mkdirs(); // to prevent fileSet cannot be empty ScmFileSet scmFileSet = new ScmFileSet(baseDir, new File("")); CommandParameters commandParameters = new CommandParameters(); commandParameters.setString(CommandParameter.SCM_MKDIR_CREATE_IN_LOCAL, Boolean.FALSE.toString()); commandParameters.setString(CommandParameter.MESSAGE, "Automatic svn path creation: " + remoteUrl); svnScmProvider.mkdir(scmRepository.getProviderRepository(), scmFileSet, commandParameters); // new remote url so force checkout! if (checkoutDirectory.exists()) { FileUtils.deleteDirectory(checkoutDirectory); } } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (ScmException e) { throw new MojoExecutionException(e.getMessage(), e); } finally { if (baseDir != null) { try { FileUtils.forceDeleteOnExit(baseDir); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } } } }
From source file:org.apache.oodt.cas.protocol.sftp.TestJschSftpProtocol.java
@Override public void setUp() { try {//from w ww . ja va 2 s . c o m publicKeysDir = new File("src/test/resources/publicKeys"); publicKeysDir.mkdirs(); FileUtils.forceDeleteOnExit(publicKeysDir); FileUtils.copyFile(new File("src/test/resources/authorization.xml"), new File("src/test/resources/publicKeys/authorization.xml")); FileUtils.copyFile(new File("src/test/resources/server.xml"), new File("src/test/resources/publicKeys/server.xml")); FileUtils.copyFile(new File("src/test/resources/platform.xml"), new File("src/test/resources/publicKeys/platform.xml")); ConfigurationLoader.initialize(true, context = new TestXmlServerConfigurationContext()); } catch (Exception e) { fail("Failed to initialize server configuration"); } (thread = new Thread(new Runnable() { public void run() { try { SshDaemon.start(); } catch (Exception e) { LOG.log(Level.SEVERE, e.getMessage()); } } })).start(); }
From source file:org.apache.zeppelin.mongodb.MongoDbInterpreterTest.java
@BeforeClass public static void setup() { // Create a fake 'mongo' final File mongoFile = new File(MONGO_SHELL); try {//from w w w .ja va 2 s . co m FileUtils.write(mongoFile, (IS_WINDOWS ? "@echo off\ntype \"%2%\"" : "cat \"$2\"")); FileUtils.forceDeleteOnExit(mongoFile); } catch (IOException e) { } }
From source file:org.bdval.ConsensusBDVModel.java
/** * Loads the juror models used for consensus. * @param options specific options to use when loading the model * @throws IOException if there is a problem accessing the model * @throws ClassNotFoundException if the type of the model is not recognized *///ww w .j ava2s . c om private void loadJurorModels(final DAVOptions options) throws IOException, ClassNotFoundException { jurorModels.clear(); final String pathToModel = FilenameUtils.getFullPath(modelFilename); final String endpointName = FilenameUtils.getBaseName(FilenameUtils.getPathNoEndSeparator(pathToModel)); if (properties.getBoolean("bdval.consensus.jurors.embedded", false)) { final File tmpdir = File.createTempFile("juror-models", ""); tmpdir.delete(); tmpdir.mkdir(); try { // load juror models from the zip file final ZipFile zipFile = new ZipFile(zipFilename); for (final String jurorPrefix : jurorModelFilenamePrefixes) { // zip files should always use "/" as a separator final String jurorFilename = "models/" + endpointName + "/" + jurorPrefix + ".zip"; LOG.debug("Loading juror model " + jurorFilename); final InputStream jurorStream = zipFile.getInputStream(zipFile.getEntry(jurorFilename)); final File jurorFile = new File(FilenameUtils.concat(tmpdir.getPath(), jurorFilename)); // put the juror model to disk so it can be loaded with existing code IOUtils.copy(jurorStream, FileUtils.openOutputStream(jurorFile)); final BDVModel jurorModel = new BDVModel(jurorFile.getPath()); jurorModel.load(options); jurorModels.add(jurorModel); } } finally { FileUtils.forceDeleteOnExit(tmpdir); } } else { // load juror models from disk final File finalModelPath = new File(pathToModel); final File finalModelParentPath = new File(finalModelPath.getParent()); // assume the model is under a directory "models" at the same level as a models // directory which contains the model components. for (final String jurorPrefix : jurorModelFilenamePrefixes) { final String modelComponentFilename = finalModelParentPath.getParent() + SystemUtils.FILE_SEPARATOR + "models" + SystemUtils.FILE_SEPARATOR + endpointName + SystemUtils.FILE_SEPARATOR + jurorPrefix; LOG.debug("Loading model component " + modelComponentFilename); final BDVModel jurorModel = new BDVModel(modelComponentFilename); jurorModel.load(options); jurorModels.add(jurorModel); } } if (jurorModels.size() < 1) { throw new IllegalStateException("No juror models could be found"); } jurorModelsAreLoaded = true; }
From source file:org.bdval.GenerateFinalModels.java
private void processOneLine(final String featuresDirectoryPath, final String featuresOutputDirectoryPath, final String modelsOutputDirectoryPath, final ProgressLogger pg, final String conditionLine) { final String[] tokens = conditionLine.split("[\t]"); final Object2ObjectMap<String, String> map = new Object2ObjectOpenHashMap<String, String>(); ConsensusMethod consensusMethodThisLine = consensusMethod; if (tokens.length > 0) { parse(tokens, map);/* w w w .j a va 2 s . co m*/ if (consensusMethod == ConsensusMethod.PATHWAY_MODELS_CONSENSUS) { if (map.get("pathways") != null && (map.containsKey("pathway-aggregation-method") || "PCA".equals(map.get("pathway-aggregation-method")))) { // if the modeling condition is a pathway run built with PCA pathway aggregation (which used to be // default pathway aggregation methods when some MAQCII runs were performed), // build model consensus: System.out.println("Detected pathway model, activating generation of model consensus."); consensusMethodThisLine = ConsensusMethod.MODEL_CONSENSUS; } else { // Otherwise, build feature consensus: consensusMethodThisLine = ConsensusMethod.FEATURE_CONSENSUS; } } final ObjectSet<String> featureFilenames = collectFeatureFilenames(featuresDirectoryPath, map); final String modelId = map.get("model-id"); final String datasetName = map.get("dataset-name"); if (featureFilenames != null) { if (!finalModelExists(modelsOutputDirectoryPath, datasetName, modelId, consensusMethodThisLine)) { final int numFeatures = Integer.parseInt(map.get("num-features")); final String label = extractLabel(datasetName, featureFilenames, modelId); if (label != null) { if (consensusMethodThisLine == ConsensusMethod.FEATURE_CONSENSUS) { final String featureConsensusOutputFilename = String.format( "%s/%s/%s-%s-%s-consensus-features.txt", featuresOutputDirectoryPath, datasetName, datasetName, label, modelId); final File consensusFeatureFilename = new File(featureConsensusOutputFilename); final boolean consensusFeatureExist = consensusFeatureFilename.exists(); boolean hasConsensusFeatures = false; if (!consensusFeatureExist) { final ObjectSet<String> consensusFeatures = calculateConsensus( featuresDirectoryPath + "/" + datasetName + "/", featureFilenames, numFeatures, map); assert consensusFeatures != null : "consensus must exist when label is not null."; hasConsensusFeatures = consensusFeatures.size() > 0; final String datasetSpecificConsensusFeatureDir = String.format("%s/%s", featuresOutputDirectoryPath, datasetName); PrintWriter output = null; try { forceCreateDir(datasetSpecificConsensusFeatureDir); output = new PrintWriter(featureConsensusOutputFilename); outputFeatures(output, consensusFeatures); } catch (IOException e) { LOG.error("An error occurred writing output file.", e); } finally { IOUtils.closeQuietly(output); } } if (hasConsensusFeatures) { // create final model dataset specific subdirectory final String datasetSpecificFinalModelDir = String.format("%s/%s", modelsOutputDirectoryPath, datasetName); forceCreateDir(datasetSpecificFinalModelDir); trainFinalModel(modelsOutputDirectoryPath, map, featureConsensusOutputFilename, label, consensusMethodThisLine); pg.update(); } } else if (consensusMethodThisLine == ConsensusMethod.MODEL_CONSENSUS) { final ObjectSet<String> modelComponentPrefixes = collectFeatureFilenames( modelsDirectoryPath, map); PrintWriter writer = null; try { final File modelListTmpFile = File.createTempFile("model-list", ".txt"); FileUtils.forceDeleteOnExit(modelListTmpFile); writer = new PrintWriter(modelListTmpFile); for (final String modelPrefix : modelComponentPrefixes) { LOG.debug("modelPrefix: " + modelPrefix); // old binary format is ".model" - new format is zipped if (modelPrefix.endsWith(".model") || modelPrefix.endsWith(".zip")) { writer.println(modelPrefix); writer.flush(); } } writer.close(); // create final model dataset specific subdirectory final String datasetSpecificFinalModelDir = String.format("%s/%s", modelsOutputDirectoryPath, datasetName); forceCreateDir(datasetSpecificFinalModelDir); trainFinalModel(modelsOutputDirectoryPath, map, modelListTmpFile.getCanonicalPath(), label, consensusMethod); } catch (IOException e) { System.out.println( "Fatal error: cannot create temporary file to store list of model components.."); System.exit(1); } finally { IOUtils.closeQuietly(writer); } } else if (consensusMethodThisLine == ConsensusMethod.DIRECT_METHOD) { try { // Build final feature and model filenames: final String datasetSpecificConsensusFeatureDir = String.format("%s-direct/%s", featuresOutputDirectoryPath, datasetName); forceCreateDir(datasetSpecificConsensusFeatureDir); final String featureConsensusOutputFilename = String.format( "%s-direct/%s/%s-%s-%s-consensus-features.txt", featuresOutputDirectoryPath, datasetName, datasetName, label, modelId); final PrintWriter output = new PrintWriter(featureConsensusOutputFilename); // create final model dataset specific subdirectory final String datasetSpecificFinalModelDir = String.format("%s-direct/%s", modelsOutputDirectoryPath, datasetName); // forceCreateDir(modelsOutputDirectoryPath); forceCreateDir(datasetSpecificFinalModelDir); // Run sequence mode to generate final model: trainFinalModelDirectMethod(modelsOutputDirectoryPath, map, featureConsensusOutputFilename, label); } catch (IOException e) { System.out.println( "Fatal error: cannot create temporary file to store list of model components.."); System.exit(1); } } } } else { System.out.println("skipping pre-existing final model for model id: " + modelId); } } } }