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; } }
@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); }
@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); }