/** @deprecated since 0.7.0 use {@link BrooklynServerPaths#newMainPersistencePathResolver(ManagementContext)} */ @Deprecated public static String getPersistenceDir(ManagementContext mgmt) { return getPersistenceDir(mgmt.getConfig()); } /** @deprecated since 0.7.0 use {@link BrooklynServerPaths#newMainPersistencePathResolver(ManagementContext)} */
/** 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()); }
/** @see PersistencePathResolver */ public static PersistencePathResolver newMainPersistencePathResolver(ManagementContext mgmt) { return new PersistencePathResolver(mgmt.getConfig()); }
@Override public Map getProperties() { return mgmt.getConfig().asMapWithStringKeys(); }
/** @see PersistenceBackupPathResolver */ public static PersistenceBackupPathResolver newBackupPersistencePathResolver(ManagementContext mgmt) { return new PersistenceBackupPathResolver(mgmt.getConfig()); }
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; }
/** checks enablement, by looking at <code>key + ".enabled"</code> */ public static boolean isEnabled(ManagementContext mgmt, String key) { ConfigKey<Boolean> k = ConfigKeys.newConfigKeyWithPrefix(key+".", LocationConfigKeys.ENABLED); Boolean enabled = mgmt.getConfig().getConfig(k); if (enabled!=null) return enabled.booleanValue(); return true; }
public List getClasspath() { List classpath = getConfig(CLASSPATH); if (classpath == null || classpath.isEmpty()) { classpath = getManagementContext().getConfig().getConfig(CLASSPATH); } return classpath; }
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); }
@VisibleForTesting public static void addNamedLocationLocalhost(ManagementContext mgmt) { if (!mgmt.getConfig().getConfig(LocalhostLocationResolver.LOCALHOST_ENABLED)) { throw new IllegalStateException("Localhost is disabled."); } // ensure localhost is added (even on windows, it's just for testing) LocationDefinition l = mgmt.getLocationRegistry().getDefinedLocationByName("localhost"); if (l==null) mgmt.getLocationRegistry().updateDefinedLocation( BasicLocationRegistry.localhost(Identifiers.makeRandomId(8)) ); }
@Override public void init() { super.init(); Integer portStartingPoint; Object rawPort = getAllConfigBag().getStringKey(PORT_FORWARD_MANAGER_STARTING_PORT.getName()); if (rawPort != null) { portStartingPoint = getConfig(PORT_FORWARD_MANAGER_STARTING_PORT); } else { portStartingPoint = getManagementContext().getConfig().getConfig(PORT_FORWARD_MANAGER_STARTING_PORT); } portReserved.set(portStartingPoint); log.debug(this+" set initial port to "+portStartingPoint); }
@Override public TemplateModel get(String key) throws TemplateModelException { try { Object result = mgmt.getConfig().getConfig(ConfigKeys.builder(Object.class).name(key).build()); if (result!=null) return wrapAsTemplateModel( result ); } catch (Exception e) { Exceptions.propagateIfFatal(e); throw new IllegalStateException("Error accessing config '"+key+"': "+e, e); } return null; }
protected boolean getNatMicroserviceAutoAllocatesPorts() { if (natMicroserviceAutoAllocatesPorts == null) { Maybe<Object> raw = ((ConfigurationSupportInternal)subnetTier.config()).getRaw(NAT_MICROSERVICE_AUTO_ALLOCATES_PORT); if (raw.isPresent()) { natMicroserviceAutoAllocatesPorts = subnetTier.config().get(NAT_MICROSERVICE_AUTO_ALLOCATES_PORT); } if (natMicroserviceAutoAllocatesPorts == null) { natMicroserviceAutoAllocatesPorts = managementContext.getConfig().getConfig(NAT_MICROSERVICE_AUTO_ALLOCATES_PORT); } } return Boolean.TRUE.equals(natMicroserviceAutoAllocatesPorts); }
public CampPlatformWithJustBrooklynMgmt(ManagementContext mgmt) { this.mgmt = mgmt; // Deprecated in 0.11.0. Add to release notes and remove in next release. ((BrooklynProperties)mgmt.getConfig()).put(BrooklynCampConstants.CAMP_PLATFORM, this); mgmt.getScratchpad().put(BrooklynCampConstants.CAMP_PLATFORM, this); }
/** checks the supplied candidate user and password against the * expect password (or SHA-256 + SALT thereof) defined as brooklyn properties. */ public static boolean checkExplicitUserPassword(ManagementContext mgmt, String user, String password) { BrooklynProperties properties = (BrooklynProperties) mgmt.getConfig(); String expectedPassword = properties.getConfig(BrooklynWebConfig.PASSWORD_FOR_USER(user)); String salt = properties.getConfig(BrooklynWebConfig.SALT_FOR_USER(user)); String expectedSha256 = properties.getConfig(BrooklynWebConfig.SHA256_FOR_USER(user)); return checkPassword(password, expectedPassword, expectedSha256, salt); } /**
public static void forceUseOfDefaultCatalogWithJavaClassPath(ManagementContext manager) { // TODO duplication with BrooklynRestApiLauncher ? // don't use any catalog.xml which is set ((BrooklynProperties)manager.getConfig()).put(BrooklynServerConfig.BROOKLYN_CATALOG_URL, BrooklynRestApiLauncher.SCANNING_CATALOG_BOM_URL); // sets URLs for a surefire ((LocalManagementContext)manager).setBaseClassPathForScanning(ClasspathHelper.forJavaClassPath()); // this also works // ((LocalManagementContext)manager).setBaseClassPathForScanning(ClasspathHelper.forPackage("brooklyn")); // but this (near-default behaviour) does not // ((LocalManagementContext)manager).setBaseClassLoader(getClass().getClassLoader()); }
@Test public void testYamlLiteralFromPropertiesInLocation() throws Exception { ((ManagementContextInternal)mgmt()).getBrooklynProperties().put( ConfigKeys.newStringConfigKey("myDynamicProperty"), "$brooklyn:literal(\"myliteral\")"); String val = mgmt().getConfig().getConfig(ConfigKeys.newStringConfigKey("myDynamicProperty")); assertEquals(val, "myliteral"); }
@Test public void testUsesSupplementaryBrooklynProperties() throws Exception { launcher = newLauncherForTests(true) .webconsole(false) .brooklynProperties("mykey", "myval") .start(); assertEquals(launcher.getServerDetails().getManagementContext().getConfig().getFirst("mykey"), "myval"); }
@Override public String getConfig(String configKey) { if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ALL_SERVER_INFO, null)) { throw WebResourceUtils.forbidden("User '%s' is not authorized for this operation", Entitlements.getEntitlementContext().user()); } ConfigKey<String> config = ConfigKeys.newStringConfigKey(configKey); return (String) WebResourceUtils.getValueForDisplay(mapper(), mgmt().getConfig().getConfig(config), true, true); }
@Test public void testInvalidYamlExpression() throws Exception { ((ManagementContextInternal)mgmt()).getBrooklynProperties().put( ConfigKeys.newStringConfigKey("myInvalidExternal"), "$brooklyn:external"); try { String val = mgmt().getConfig().getConfig(ConfigKeys.newStringConfigKey("myInvalidExternal")); Asserts.shouldHaveFailedPreviously("val="+val); } catch (IllegalArgumentException e) { Asserts.expectedFailureContains(e, "Error evaluating node"); } }