Java Code Examples for org.apache.brooklyn.util.os.Os#deleteOnExitRecursivelyAndEmptyParentsUpTo()

The following examples show how to use org.apache.brooklyn.util.os.Os#deleteOnExitRecursivelyAndEmptyParentsUpTo() . 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: BrooklynServerPaths.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public static File getBrooklynWebTmpDir(ManagementContext mgmt) {
    String brooklynMgmtBaseDir = getMgmtBaseDir(mgmt);
    File webappTempDir = new File(Os.mergePaths(brooklynMgmtBaseDir, "planes", mgmt.getManagementNodeId(), "jetty"));
    try {
        FileUtils.forceMkdir(webappTempDir);
        Os.deleteOnExitRecursivelyAndEmptyParentsUpTo(webappTempDir, new File(brooklynMgmtBaseDir)); 
        return webappTempDir;
    } catch (Exception e) {
        Exceptions.propagateIfFatal(e);
        IllegalStateException e2 = new IllegalStateException("Cannot create working directory "+webappTempDir+" for embedded jetty server: "+e, e);
        log.warn(e2.getMessage()+" (rethrowing)");
        throw e2;
    }
}
 
Example 2
Source File: OsgiPathTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups="Integration") // integration only because non-reusable OSGi takes ~200ms
public void testOsgiPathCustom() {
    BrooklynProperties bp = BrooklynProperties.Factory.newEmpty();
    String randomSeg = "osgi-test-"+Identifiers.makeRandomId(4);
    bp.put(BrooklynServerConfig.OSGI_CACHE_DIR, "${brooklyn.os.tmpdir}"+"/"+randomSeg+"/"+"${brooklyn.mgmt.node.id}");
    mgmt = LocalManagementContextForTests.builder(true).enableOsgiNonReusable().useProperties(bp).build();
    String path = BrooklynServerPaths.getOsgiCacheDir(mgmt).getAbsolutePath();
    Os.deleteOnExitRecursivelyAndEmptyParentsUpTo(new File(path), new File(Os.tmp()+"/"+randomSeg));
    
    Assert.assertTrue(path.startsWith(Os.tmp()), path);
    Assert.assertTrue(path.contains(mgmt.getManagementNodeId()), path);
    
    assertExistsThenIsCleaned(path);
}
 
Example 3
Source File: OsgiPathTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups="Integration") // integration only because non-reusable OSGi takes ~200ms
public void testOsgiPathCustomWithoutNodeIdNotCleaned() {
    BrooklynProperties bp = BrooklynProperties.Factory.newEmpty();
    String randomSeg = "osgi-test-"+Identifiers.makeRandomId(4);
    bp.put(BrooklynServerConfig.OSGI_CACHE_DIR, "${brooklyn.os.tmpdir}"+"/"+randomSeg+"/"+"sample");
    mgmt = LocalManagementContextForTests.builder(true).enableOsgiNonReusable().useProperties(bp).build();
    String path = BrooklynServerPaths.getOsgiCacheDir(mgmt).getAbsolutePath();
    Os.deleteOnExitRecursivelyAndEmptyParentsUpTo(new File(path), new File(Os.tmp()+"/"+randomSeg));
    
    Assert.assertTrue(path.startsWith(Os.tmp()), path);
    Assert.assertFalse(path.contains(mgmt.getManagementNodeId()), path);
    
    assertExistsThenCorrectCleanedBehaviour(path, false);
}