@Override public StoreObjectAccessor newAccessor(String path) { if (!prepared) throw new IllegalStateException("Not yet prepared: "+this); String tmpExt = ".tmp"; if (mgmt!=null && mgmt.getManagementNodeId()!=null) tmpExt = "."+mgmt.getManagementNodeId()+tmpExt; return new FileBasedStoreObjectAccessor(new File(Os.mergePaths(getBaseDir().getAbsolutePath(), path)), tmpExt); }
public static boolean isOsgiCacheForCleaning(ManagementContext mgmt, File cacheDir) { StringConfigMap brooklynProperties = mgmt.getConfig(); Boolean clean = brooklynProperties.getConfig(BrooklynServerConfig.OSGI_CACHE_CLEAN); if (clean==null) { // as per javadoc on key, clean defaults to iff it is a node-id-specific directory clean = cacheDir.getName().contains(mgmt.getManagementNodeId()); } return clean; }
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; } }
/** Appends a standard format subpath sub-path to the path returned by {@link #resolve()}. * <p> * For example, this might write to: * <code>~/.brooklyn/brooklyn-persisted-state/backups/2014-11-13-1201-n0deId-promotion-sA1t */ public String resolveWithSubpathFor(ManagementContext managementContext, String label) { return resolveWithSubpath(Time.makeDateSimpleStampString()+"-"+managementContext.getManagementNodeId()+"-"+label+"-"+Identifiers.makeRandomId(4)); } @Override
log.debug("Reusing OSGi framework container from "+framework.getBundleContext().getProperty(Constants.FRAMEWORK_STORAGE)+" for mgmt node "+mgmt.getManagementNodeId()); log.debug("OSGi framework container created in "+osgiFrameworkCacheDir+" mgmt node "+mgmt.getManagementNodeId()+ (reuseFramework ? "(reusable, "+numberOfReusableFrameworksCreated.get()+" total)" : "") );
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); }
throw Exceptions.propagate(new IllegalStateException("Node record "+nodeFile+" could not be read when "+mgmt.getManagementNodeId()+" was scanning", problem)); } else { LOG.warn("Node record "+nodeFile+" went away while "+mgmt.getManagementNodeId()+" was scanning, ignoring (it has probably been terminated)"); if (memento == null) { throw Exceptions.propagate(new IllegalStateException("Node record "+nodeFile+" could not be deserialized when "+mgmt.getManagementNodeId()+" was scanning: "+nodeContents, problem)); } else { if (memento.getRemoteTimestamp()!=null && preferRemoteTimestampInMemento) {
String label = mgmt().getManagementNodeId()+"-"+Time.makeDateSimpleStampString(); PersistenceObjectStore targetStore = BrooklynPersistenceUtils.newPersistenceObjectStore(mgmt(), null, "tmp/web-persistence-"+label+"-"+Identifiers.makeRandomId(4));
@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); }
@Override public HighAvailabilitySummary getHighAvailabilityPlaneStates() { if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SERVER_STATUS, null)) throw WebResourceUtils.forbidden("User '%s' is not authorized for this operation", Entitlements.getEntitlementContext().user()); ManagementPlaneSyncRecord memento = mgmt().getHighAvailabilityManager().getLastManagementPlaneSyncRecord(); if (memento==null) memento = mgmt().getHighAvailabilityManager().loadManagementPlaneSyncRecord(true); if (memento==null) return null; return HighAvailabilityTransformer.highAvailabilitySummary(mgmt().getManagementNodeId(), memento); }