private String getIdWithRandomDefault() { return idAsSymbolicNameWithoutVersion != null ? idAsSymbolicNameWithoutVersion : Strings.makeRandomId(10); } public Map<?,?> getItem() {
public void generateManagementPlaneId() { if (this.managementPlaneId != null) { throw new IllegalStateException("Request to generate a management plane ID for node "+getManagementNodeId()+" but one already exists (" + managementPlaneId + ")"); } this.managementPlaneId = Strings.makeRandomId(8); }
protected boolean check(String candidate) { try { File f = new File(candidate); if (!f.exists()) { log.debug("TmpDirFinder: Candidate tmp dir '"+candidate+"' does not exist"); return false; } if (!f.isDirectory()) { log.debug("TmpDirFinder: Candidate tmp dir '"+candidate+"' is not a directory"); return false; } File f2 = new File(f, "brooklyn-tmp-check-"+Strings.makeRandomId(4)); if (!f2.createNewFile()) { log.debug("TmpDirFinder: Candidate tmp dir '"+candidate+"' cannot have files created inside it ("+f2+")"); return false; } if (!f2.delete()) { log.debug("TmpDirFinder: Candidate tmp dir '"+candidate+"' cannot have files deleted inside it ("+f2+")"); return false; } return true; } catch (Exception e) { log.debug("TmpDirFinder: Candidate tmp dir '"+candidate+"' is not valid: "+e); return false; } }
@Override public int copyTo(Map<String,?> props, File src, String destination) { Map<String,?> nonPortProps = Maps.filterKeys(props, Predicates.not(Predicates.containsPattern("port"))); boolean entitySsh = Boolean.TRUE.equals(entity.config().get(DockerContainer.DOCKER_USE_SSH)); boolean dockerSsh = Boolean.TRUE.equals(getOwner().config().get(DockerContainer.DOCKER_USE_SSH)); if (entitySsh && dockerSsh) { return super.copyTo(nonPortProps, src, destination); } else { String tmp = Os.mergePaths("/tmp", Joiner.on('-').join(dockerContainer.getId(), Urls.getBasename(destination), Strings.makeRandomId(4))); hostMachine.copyTo(nonPortProps, src, tmp); copyFile(tmp, destination); return 0; } }
@Override public int copyTo(final Map<String,?> props, final InputStream src, final String destination) { Map<String,?> nonPortProps = Maps.filterKeys(props, Predicates.not(Predicates.containsPattern("port"))); boolean entitySsh = Boolean.TRUE.equals(entity.config().get(DockerContainer.DOCKER_USE_SSH)); boolean dockerSsh = Boolean.TRUE.equals(getOwner().config().get(DockerContainer.DOCKER_USE_SSH)); if (entitySsh && dockerSsh) { return super.copyTo(nonPortProps, src, destination); } else { try { String tmp = Os.mergePaths("/tmp", Joiner.on('-').join(dockerContainer.getId(), Urls.getBasename(destination), Strings.makeRandomId(4))); hostMachine.copyTo(nonPortProps, src, tmp); copyFile(tmp, destination); src.close(); return 0; } catch (IOException ioe) { throw Exceptions.propagate(ioe); } } }
@Override public int copyFrom(final Map<String,?> props, final String remote, final String local) { Map<String,?> nonPortProps = Maps.filterKeys(props, Predicates.not(Predicates.containsPattern("port"))); boolean entitySsh = Boolean.TRUE.equals(entity.config().get(DockerContainer.DOCKER_USE_SSH)); boolean dockerSsh = Boolean.TRUE.equals(getOwner().config().get(DockerContainer.DOCKER_USE_SSH)); if (entitySsh && dockerSsh) { return super.copyFrom(nonPortProps, remote, local); } else { String tmp = Os.mergePaths("/tmp", Joiner.on('-').join(dockerContainer.getId(), Urls.getBasename(local), Strings.makeRandomId(4))); String cp = String.format("cp %s:%s %s", dockerContainer.getContainerId(), remote, tmp); String output = getOwner().getDockerHost().runDockerCommand(cp); hostMachine.copyFrom(nonPortProps, tmp, local); LOG.info("Copying from {}:{} to {} - result: {}", new Object[] { dockerContainer.getContainerId(), remote, local, output }); return 0; } }
@Test(groups={"Integration", "Broken", "Manual"}) public void testRebindCheckingMemoryLeak() throws Exception { TestEntity c1 = origApp.addChild(EntitySpec.create(TestEntity.class)); c1.config().set(TestEntity.CONF_NAME, Strings.makeRandomId(1000000)); gcAndLog("before"); long used0 = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); for (int i=0; i<200; i++) { doPartialRebindOfIds(c1.getId()); origManagementContext.getGarbageCollector().gcIteration(); gcAndLog("iteration "+i); if (i==5) used0 = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); } gcAndLog("after"); long used1 = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); Assert.assertTrue(used1 - used0 < 5000000, "Expected leak of less than 5M; leak was: from "+Strings.makeJavaSizeString(used0)+" to "+Strings.makeJavaSizeString(used1)); }
@Test(groups = "Integration") public void testStartsInAppSpecifiedDirectoryUnderHome() throws Exception { String dir = Os.mergePathsUnix("~/.brooklyn-test-"+Strings.makeRandomId(4)); try { app.config().set(BrooklynConfigKeys.ONBOX_BASE_DIR, dir); doTestSpecifiedDirectory(dir, dir); } finally { Os.deleteRecursively(dir); } }
final String dest = getDeployDir() + "/" + canonicalTargetName; final String tmpDest = dest + "." + Strings.makeRandomId(8) + ".tmp"; final String msg = String.format("deploying %s to %s:%s", new Object[]{url, getHostname(), dest}); log.info(entity + " " + msg);
@Test(groups = "Integration") public void test_localhost() throws Exception { String dataDir = "/tmp/mariadb-data-" + Strings.makeRandomId(8); MariaDbNode mariadb = app.createAndManageChild(EntitySpec.create(MariaDbNode.class) .configure(MariaDbNode.MARIADB_SERVER_CONF, MutableMap.<String, Object>of("skip-name-resolve","")) .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, CREATION_SCRIPT) .configure(MariaDbNode.DATA_DIR, dataDir)); LocalhostMachineProvisioningLocation location = new LocalhostMachineProvisioningLocation(); app.start(ImmutableList.of(location)); log.info("MariaDB started"); new VogellaExampleAccess("com.mysql.jdbc.Driver", mariadb.getAttribute(DatastoreCommon.DATASTORE_URL)).readModifyAndRevertDataBase(); log.info("Ran vogella MySQL example -- SUCCESS"); // Ensure the data directory was successfully overridden. File dataDirFile = new File(dataDir); File mariadbSubdirFile = new File(dataDirFile, "mysql"); Assert.assertTrue(mariadbSubdirFile.exists()); // Clean up. dataDirFile.delete(); } }
@Test(groups = "Integration") public void testStartsInDifferentRunAndInstallSpecifiedDirectories() throws Exception { String dir1 = Os.mergePathsUnix(Os.tmp(), "/brooklyn-test-"+Strings.makeRandomId(4)); String dir2 = Os.mergePathsUnix(Os.tmp(), "/brooklyn-test-"+Strings.makeRandomId(4)); app.config().set(BrooklynConfigKeys.INSTALL_DIR, dir1); app.config().set(BrooklynConfigKeys.RUN_DIR, dir2); doTestSpecifiedDirectory(dir1, dir2); Os.deleteRecursively(dir1); Os.deleteRecursively(dir2); }
@Test public void testPlaneIdRolledBack() throws Exception { final LocalManagementContext mgmt = createManagementContext(PersistMode.AUTO, HighAvailabilityMode.AUTO); checkPlaneIdPersisted(mgmt); final String oldPlaneId = mgmt.getManagementPlaneIdMaybe().get(); mgmt.setManagementPlaneId(Strings.makeRandomId(8)); assertNotEquals(oldPlaneId, mgmt.getManagementPlaneIdMaybe().get()); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertEquals(oldPlaneId, mgmt.getManagementPlaneIdMaybe().get()); } }); }
@Test(groups="Integration") public void testWebServerTempDirRespectsDataDirConfig() throws Exception { String dataDirName = ".brooklyn-foo"+Strings.makeRandomId(4); String dataDir = "~/"+dataDirName; launcher = newLauncherForTests(true) .brooklynProperties(BrooklynServerConfig.MGMT_BASE_DIR, dataDir) .start(); ManagementContext managementContext = launcher.getServerDetails().getManagementContext(); String expectedTempDir = Os.mergePaths(Os.home(), dataDirName, "planes", managementContext.getManagementNodeId(), "jetty"); File webappTempDir = launcher.getServerDetails().getWebServer().getWebappTempDir(); assertEquals(webappTempDir.getAbsolutePath(), expectedTempDir); }
public AbstractManagementContext(BrooklynProperties brooklynProperties) { this.managementNodeId = Strings.makeRandomId(8); this.configMap = new DeferredBrooklynProperties(brooklynProperties, this); this.scratchpad = new BasicScratchpad(); this.entityDriverManager = new BasicEntityDriverManager(); this.downloadsManager = BasicDownloadsManager.newDefault(configMap); this.catalog = new BasicBrooklynCatalog(this); this.typeRegistry = new BasicBrooklynTypeRegistry(this); this.storage = new BrooklynStorageImpl(); this.rebindManager = new RebindManagerImpl(this); // TODO leaking "this" reference; yuck this.highAvailabilityManager = new HighAvailabilityManagerImpl(this); // TODO leaking "this" reference; yuck this.entitlementManager = Entitlements.newManager(this, brooklynProperties); this.configSupplierRegistry = new BasicExternalConfigSupplierRegistry(this); // TODO leaking "this" reference; yuck }
@Test public void testInstallDirAndRunDirUsingTilde() throws Exception { String dataDirName = ".brooklyn-foo"+Strings.makeRandomId(4); String dataDir = "~/"+dataDirName; String resolvedDataDir = Os.mergePaths(Os.home(), dataDirName); MyService entity = app.createAndManageChild(EntitySpec.create(MyService.class) .configure(BrooklynConfigKeys.ONBOX_BASE_DIR, dataDir)); entity.start(ImmutableList.of(loc)); Assert.assertEquals(Os.nativePath(entity.getAttribute(SoftwareProcess.INSTALL_DIR)), Os.nativePath(Os.mergePaths(resolvedDataDir, "installs/MyService"))); Assert.assertEquals(Os.nativePath(entity.getAttribute(SoftwareProcess.RUN_DIR)), Os.nativePath(Os.mergePaths(resolvedDataDir, "apps/"+entity.getApplicationId()+"/entities/MyService_"+entity.getId()))); }
@Test(groups = "Integration") public void testStartsInMgmtSpecifiedDirectory() throws Exception { String dir = Os.mergePathsUnix(Os.tmp(), "/brooklyn-test-"+Strings.makeRandomId(4)); tearDown(); mgmt = new LocalManagementContextForTests(); mgmt.getBrooklynProperties().put(BrooklynConfigKeys.ONBOX_BASE_DIR, dir); setUp(); doTestSpecifiedDirectory(dir, dir); Os.deleteRecursively(dir); }