/** * 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; } }
@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); }
provider = getManagementContext().getScratchpad().get(BrooklynWebConfig.SECURITY_PROVIDER_INSTANCE); if (provider != null) return; if (symbolicName != null) {
mgmt.getScratchpad().put(BrooklynWebConfig.SECURITY_PROVIDER_INSTANCE, delegate);
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); }
@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"); } }
@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);