/** @see BrooklynServerPaths#getMgmtBaseDir(ManagementContext) */ public static String getMgmtBaseDir(ManagementContext mgmt) { return BrooklynServerPaths.getMgmtBaseDir(mgmt); } /** @see BrooklynServerPaths#getMgmtBaseDir(ManagementContext) */
public static File getOsgiCacheDirCleanedIfNeeded(ManagementContext mgmt) { File cacheDirF = getOsgiCacheDir(mgmt); boolean clean = isOsgiCacheForCleaning(mgmt, cacheDirF); log.debug("OSGi cache dir computed as "+cacheDirF.getAbsolutePath()+" ("+ (cacheDirF.exists() ? "already exists" : "does not exist")+", "+ (clean ? "cleaning now (and on exit)" : "cleaning not requested")); if (clean) { Os.deleteRecursively(cacheDirF); Os.deleteOnExitRecursively(cacheDirF); } return cacheDirF; }
/** @deprecated since 0.7.0 use {@link BrooklynServerPaths#getBrooklynWebTmpDir(ManagementContext)} */ @Deprecated public static File getBrooklynWebTmpDir(ManagementContext mgmt) { return BrooklynServerPaths.getBrooklynWebTmpDir(mgmt); }
/** * @param optionalSuppliedValue * An optional value which has been supplied explicitly * @param brooklynProperties * The properties map where the persistence path should be looked up if not supplied, * along with finding the brooklyn.base.dir if needed (using file system persistence * with a relative path) * @param optionalObjectStoreLocationSpec * If a location spec is supplied, this will return a container name suitable for use * with the given object store based on brooklyn.persistence.dir; if null this method * will return a full file system path, relative to the brooklyn.base.dir if the * configured brooklyn.persistence.dir is not absolute * @return The container name or full path for where persist state should be kept * @deprecated since 0.7.0 use {@link BrooklynServerPaths#newMainPersistencePathResolver(ManagementContext)} */ @Deprecated public static String resolvePersistencePath(String optionalSuppliedValue, StringConfigMap brooklynProperties, String optionalObjectStoreLocationSpec) { return BrooklynServerPaths.newMainPersistencePathResolver(brooklynProperties).location(optionalObjectStoreLocationSpec).dir(optionalSuppliedValue).resolve(); }
@Test(groups="Integration") // integration only because non-reusable OSGi takes ~200ms public void testOsgiPathDefault() { mgmt = LocalManagementContextForTests.builder(true).enableOsgiNonReusable().build(); String path = BrooklynServerPaths.getOsgiCacheDir(mgmt).getAbsolutePath(); Assert.assertTrue(path.startsWith(BrooklynServerPaths.getMgmtBaseDir(mgmt)), path); Assert.assertTrue(path.contains(mgmt.getManagementNodeId()), path); assertExistsThenIsCleaned(path); }
public static File getOsgiCacheDir(ManagementContext mgmt) { StringConfigMap brooklynProperties = mgmt.getConfig(); String cacheDir = brooklynProperties.getConfig(BrooklynServerConfig.OSGI_CACHE_DIR); // note dir should be different for each instance if starting multiple instances // hence default including management node ID cacheDir = TemplateProcessor.processTemplateContents(cacheDir, mgmt, MutableMap.of(BrooklynServerConfig.MGMT_BASE_DIR.getName(), getMgmtBaseDir(mgmt), BrooklynServerConfig.MANAGEMENT_NODE_ID_PROPERTY, mgmt.getManagementNodeId(), Os.TmpDirFinder.BROOKLYN_OS_TMPDIR_PROPERTY, Os.tmp())); cacheDir = resolveAgainstBaseDir(mgmt.getConfig(), cacheDir); return new File(cacheDir); }
@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 public void testPlaneIdBackedUp() throws Exception { final LocalManagementContext origMgmt = createManagementContext(PersistMode.AUTO, HighAvailabilityMode.AUTO); checkPlaneIdPersisted(origMgmt); Entities.destroyAll(origMgmt); LocalManagementContext rebindMgmt = createManagementContextWithBackups(PersistMode.AUTO, HighAvailabilityMode.AUTO); assertEquals(origMgmt.getManagementPlaneIdMaybe(), rebindMgmt.getManagementPlaneIdMaybe()); String backupContainer = BrooklynServerPaths.newBackupPersistencePathResolver(rebindMgmt).resolve(); File[] promotionFolders = new File(backupContainer).listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.contains("promotion"); } }); assertEquals(promotionFolders.length, 1); File planeIdFile = new File(promotionFolders[0], BrooklynMementoPersisterToObjectStore.PLANE_ID_FILE_NAME); String planeId = readFile(planeIdFile); assertEquals(origMgmt.getManagementPlaneIdMaybe().get(), planeId); }
public String resolve() { String path = dirOrContainer; if (path==null) path = getDefaultPathFromConfig(); if (Strings.isBlank(locationSpec) || "localhost".equals(locationSpec)) { // file system if (Strings.isBlank(path)) path=getDefaultDirForAnyFilesystem(); return resolveAgainstBaseDir(brooklynProperties, path); } else { // obj store if (path==null) path=getDefaultContainerForAnyNonFilesystem(); return path; } }
osgiFrameworkCacheDir = BrooklynServerPaths.getOsgiCacheDirCleanedIfNeeded(mgmt);
} else if (BrooklynServerPaths.isOsgiCacheForCleaning(mgmt, osgiFrameworkCacheDir)) {
@Override protected void checkPersistenceContainerNameIsDefault() { String expected = BrooklynServerPaths.newMainPersistencePathResolver(BrooklynProperties.Factory.newEmpty()).location(null).dir(null).resolve(); checkPersistenceContainerNameIs(expected); }
@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); }
String nonBackupSpec = managementContext.getConfig().getConfig(BrooklynServerConfig.PERSISTENCE_LOCATION_SPEC); try { String backupContainer = BrooklynServerPaths.newBackupPersistencePathResolver(managementContext) .location(backupSpec).nonBackupLocation(nonBackupSpec).resolveWithSubpathFor(managementContext, mode.toString()); destinationObjectStore = BrooklynPersistenceUtils.newPersistenceObjectStore(managementContext, backupSpec, backupContainer); String failedSpec = backupSpec; backupSpec = "localhost"; String backupContainer = BrooklynServerPaths.newBackupPersistencePathResolver(managementContext) .location(backupSpec).nonBackupLocation(nonBackupSpec).resolveWithSubpathFor(managementContext, mode.toString()); destinationObjectStore = BrooklynPersistenceUtils.newPersistenceObjectStore(managementContext, backupSpec, backupContainer);
/** @see BrooklynServerPaths#getMgmtBaseDir(ManagementContext) */ public static String getMgmtBaseDir(StringConfigMap brooklynProperties) { return BrooklynServerPaths.getMgmtBaseDir(brooklynProperties); } /** @see BrooklynServerPaths#getMgmtBaseDir(ManagementContext) */
/** Creates a {@link PersistenceObjectStore} for use with a specified set of modes. */ public static PersistenceObjectStore newPersistenceObjectStore(ManagementContext managementContext, String locationSpecString, String locationContainer, PersistMode persistMode, HighAvailabilityMode highAvailabilityMode) { PersistenceObjectStore destinationObjectStore; locationContainer = BrooklynServerPaths.newMainPersistencePathResolver(managementContext).location(locationSpecString).dir(locationContainer).resolve(); LocationSpec<?> locationSpec = Strings.isBlank(locationSpecString) ? LocationSpec.create(LocalhostMachineProvisioningLocation.class) : managementContext.getLocationRegistry().getLocationSpec(locationSpecString).get(); Location location = managementContext.getLocationManager().createLocation(locationSpec .configure(LocalLocationManager.CREATE_UNMANAGED, true)); if (!(location instanceof LocationWithObjectStore)) { throw new IllegalArgumentException("Destination location "+location+" does not offer a persistent store"); } destinationObjectStore = ((LocationWithObjectStore)location).newPersistenceObjectStore(locationContainer); destinationObjectStore.injectManagementContext(managementContext); destinationObjectStore.prepareForSharedUse(persistMode, highAvailabilityMode); return destinationObjectStore; }
/** @see BrooklynServerPaths#getMgmtBaseDir(ManagementContext) */ public static String getMgmtBaseDir(Map<String,?> brooklynProperties) { return BrooklynServerPaths.getMgmtBaseDir(brooklynProperties); }
persistenceLocation = brooklynProperties.getConfig(BrooklynServerConfig.PERSISTENCE_LOCATION_SPEC); persistenceDir = BrooklynServerPaths.newMainPersistencePathResolver(brooklynProperties).location(persistenceLocation).dir(persistenceDir).resolve(); objectStore = BrooklynPersistenceUtils.newPersistenceObjectStore(managementContext, persistenceLocation, persistenceDir, persistMode, highAvailabilityMode);
/** Computes the base dir where brooklyn should read and write configuration. * Defaults to <code>~/.brooklyn/</code>. * <p> * Also see other variants of this method if a {@link ManagementContext} is not yet available. */ public static String getMgmtBaseDir(ManagementContext mgmt) { return getMgmtBaseDir(mgmt.getConfig()); }
private void initManagementContextAndPersistence(String persistenceDir) { BrooklynProperties brooklynProperties = BrooklynProperties.Factory.builderDefault().build(); brooklynProperties.put(BrooklynServerConfig.MGMT_BASE_DIR.getName(), ""); brooklynProperties.put(BrooklynServerConfig.OSGI_CACHE_DIR, "target/" + BrooklynServerConfig.OSGI_CACHE_DIR.getDefaultValue()); mgmt = LocalManagementContextForTests.newInstance(brooklynProperties); mgmts.add(mgmt); persistenceDir = BrooklynServerPaths.newMainPersistencePathResolver(brooklynProperties).dir(persistenceDir).resolve(); PersistenceObjectStore objectStore = BrooklynPersistenceUtils.newPersistenceObjectStore(mgmt, null, persistenceDir, PersistMode.AUTO, HighAvailabilityMode.HOT_STANDBY); BrooklynMementoPersisterToObjectStore persister = new BrooklynMementoPersisterToObjectStore( objectStore, mgmt); RebindManager rebindManager = mgmt.getRebindManager(); PersistenceExceptionHandler persistenceExceptionHandler = PersistenceExceptionHandlerImpl.builder().build(); ((RebindManagerImpl) rebindManager).setPeriodicPersistPeriod(Duration.ONE_SECOND); rebindManager.setPersister(persister, persistenceExceptionHandler); ((RebindManagerImpl) rebindManager).forcePersistNow(); }