@Test public void testScratchpadLostOnRebind() throws Exception { ConfigKey<String> myKey = ConfigKeys.newStringConfigKey("my"); origManagementContext.getScratchpad().put(myKey, "key"); assertEquals(origManagementContext.getScratchpad().get(myKey), "key"); rebind(); assertFalse(newManagementContext.getScratchpad().contains(myKey), "Scratchpad lost on rebind"); } }
/** * Finds a shared {@link ObjectMapper} or makes a new one, stored against the servlet context; * returns null if a shared instance cannot be created. */ public static ObjectMapper findSharedObjectMapper(ManagementContext mgmt) { checkNotNull(mgmt, "mgmt"); synchronized (mgmt) { ConfigKey<ObjectMapper> key = ConfigKeys.newConfigKey(ObjectMapper.class, BROOKLYN_REST_OBJECT_MAPPER); ObjectMapper mapper = (ObjectMapper) mgmt.getScratchpad().get(key); if (mapper != null) return mapper; mapper = newPrivateObjectMapper(mgmt); log.debug("Storing new ObjectMapper against "+mgmt+" because no ServletContext available: "+mapper); mgmt.getScratchpad().put(key, mapper); return mapper; } }
private Object transform(ConfigKey<?> key, Object value) { if (value instanceof CharSequence) { String raw = value.toString(); if (raw.startsWith(BROOKLYN_YAML_PREFIX)) { CampYamlParser parser = mgmt.getScratchpad().get(CampYamlParser.YAML_PARSER_KEY); if (parser == null) { // TODO Should we fail or return the untransformed value? // Problem is this gets called during initialisation, e.g. by BrooklynFeatureEnablement calling asMapWithStringKeys() // throw new IllegalStateException("Cannot parse external-config for "+key+" because no camp-yaml parser available"); LOG.debug("Not transforming external-config {}, as no camp-yaml parser available", key); return value; } return parser.parse(raw); } } return value; }
mgmt.getScratchpad().put(BrooklynWebConfig.SECURITY_PROVIDER_INSTANCE, delegate);
@Test public void testScratchpadSurvivesReload() throws Exception { String globalPropertiesContents = "brooklyn.location.localhost.displayName=myname"; Files.write(globalPropertiesContents, globalPropertiesFile, Charsets.UTF_8); BrooklynProperties brooklynProperties = BrooklynProperties.Factory.builderDefault() .globalPropertiesFile(globalPropertiesFile.getAbsolutePath()) .build(); context = LocalManagementContextForTests.builder(true).useProperties(brooklynProperties).build(); ConfigKey<String> myKey = ConfigKeys.newStringConfigKey("my"); context.getScratchpad().put(myKey, "key"); assertEquals(context.getScratchpad().get(myKey), "key"); context.reloadBrooklynProperties(); assertEquals(context.getScratchpad().get(myKey), "key"); } }
@Test public void testReloadBrooklynPropertiesNonDeploy() { CampPlatform platform = brooklynMgmt.getScratchpad().get(BrooklynCampConstants.CAMP_PLATFORM); Assert.assertNotNull(platform); brooklynMgmt.reloadBrooklynProperties(); CampPlatform reloadedPlatform = brooklynMgmt.getScratchpad().get(BrooklynCampConstants.CAMP_PLATFORM); Assert.assertEquals(reloadedPlatform, platform); }
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); }
provider = getManagementContext().getScratchpad().get(BrooklynWebConfig.SECURITY_PROVIDER_INSTANCE); if (provider != null) return; if (symbolicName != null) {
@Test public void testCampYamlParserHandlesExternalisedConfig() throws Exception { CampYamlParser parser = mgmt().getScratchpad().get(CampYamlParser.YAML_PARSER_KEY); DeferredSupplier<?> supplier = (DeferredSupplier<?>) parser.parse("$brooklyn:external(\"myprovider\", \"mykey\")"); ExecutionContext exec = mgmt().getServerExecutionContext(); String result = Tasks.resolveValue(supplier, String.class, exec); assertEquals(result, "myval"); }
@Test public void testReloadBrooklynPropertiesDeploy() { brooklynMgmt.reloadBrooklynProperties(); CampPlatform reloadedPlatform = brooklynMgmt.getScratchpad().get(BrooklynCampConstants.CAMP_PLATFORM); Assert.assertNotNull(reloadedPlatform); Reader input = Streams.reader(new ResourceUtils(this).getResourceFromUrl("test-entity-basic-template.yaml")); AssemblyTemplate template = reloadedPlatform.pdp().registerDeploymentPlan(input); try { Assembly assembly = template.getInstantiator().newInstance().instantiate(template, reloadedPlatform); LOG.info("Test - created " + assembly); final Entity app = brooklynMgmt.getEntityManager().getEntity(assembly.getId()); LOG.info("App - " + app); Assert.assertEquals(app.getDisplayName(), "test-entity-basic-template"); EntityAsserts.assertAttributeEqualsEventually(app, Startable.SERVICE_UP, true); } catch (Exception e) { LOG.warn("Unable to instantiate " + template + " (rethrowing): " + e); throw Exceptions.propagate(e); } } }
CampYamlParser parser = mgmt.getScratchpad().get(CampYamlParser.YAML_PARSER_KEY); if (parser != null) { itemMetadataWithoutItemDef = parser.parse((Map<String, Object>) itemMetadataWithoutItemDef);