LocalManagementContext extends AbstractManagementContext { @Override public void reloadBrooklynProperties() { log.info("Reloading brooklyn properties from " + builder); if (builder.hasDelegateOriginalProperties()) log.warn("When reloading, mgmt context "+this+" properties are fixed, so reload will be of limited utility"); BrooklynProperties properties = builder.build(); configMap = new DeferredBrooklynProperties(properties, this); if (brooklynAdditionalProperties != null && !brooklynAdditionalProperties.isEmpty()) { log.info("Reloading additional brooklyn properties from " + brooklynAdditionalProperties); configMap.addFromMap(brooklynAdditionalProperties); } this.downloadsManager = BasicDownloadsManager.newDefault(configMap); this.entitlementManager = Entitlements.newManager(this, configMap); clearLocationRegistry(); BrooklynFeatureEnablement.init(configMap); for (PropertiesReloadListener listener : reloadListeners) { listener.reloaded(); } } LocalManagementContext(); @VisibleForTesting  LocalManagementContext(BrooklynProperties brooklynProperties);  LocalManagementContext(Builder builder);  LocalManagementContext(Builder builder, Map<String, Object> brooklynAdditionalProperties); static void logAll(Logger logger); @Beta static int terminateAll(); @Override @Deprecated String getManagementPlaneId(); @Override Maybe<String> getManagementPlaneIdMaybe(); void setManagementPlaneId(String newPlaneId); void generateManagementPlaneId(); @Override void prePreManage(Entity entity); @Override void prePreManage(Location location); @Override synchronized Collection<Application> getApplications(); @Override void addEntitySetListener(CollectionChangeListener<Entity> listener); @Override void removeEntitySetListener(CollectionChangeListener<Entity> listener); @Override synchronized LocalEntityManager getEntityManager(); @Override InternalEntityFactory getEntityFactory(); @Override InternalLocationFactory getLocationFactory(); @Override InternalPolicyFactory getPolicyFactory(); @Override synchronized LocalLocationManager getLocationManager(); @Override synchronized LocalAccessManager getAccessManager(); @Override synchronized LocalUsageManager getUsageManager(); @Override synchronized Maybe<OsgiManager> getOsgiManager(); @Override synchronized AccessController getAccessController(); @Override synchronized SubscriptionManager getSubscriptionManager(); @Override synchronized ExecutionManager getExecutionManager(); @Override void terminate(); @Override boolean isManagedLocally(Entity e); @Override String toString(); @Override void reloadBrooklynProperties(); @VisibleForTesting void clearLocationRegistry(); @Override void addPropertiesReloadListener(PropertiesReloadListener listener); @Override void removePropertiesReloadListener(PropertiesReloadListener listener); void noteStartupComplete(); void noteStartupTransitioning(); @Override boolean isStartupComplete(); @Override ManagementNodeState getNodeState(); final Throwable constructionStackTrace; }
@Test public void testReloadPropertiesFromBuilder() throws IOException { String globalPropertiesContents = toMapString( LocalManagementContextForTests.builder(true) .useAdditionalProperties(MutableMap.of("brooklyn.location.localhost.displayName", "myname")) .buildProperties() ); Files.write(globalPropertiesContents, globalPropertiesFile, Charsets.UTF_8); Builder propsBuilder = BrooklynProperties.Factory.builderDefault() .globalPropertiesFile(globalPropertiesFile.getAbsolutePath()); context = new LocalManagementContext(propsBuilder); Location location = context.getLocationRegistry().getLocationManaged("localhost"); assertEquals(location.getDisplayName(), "myname"); String newGlobalPropertiesContents = toMapString( LocalManagementContextForTests.builder(true) .useAdditionalProperties(MutableMap.of("brooklyn.location.localhost.displayName", "myname2")) .buildProperties() ); Files.write(newGlobalPropertiesContents, globalPropertiesFile, Charsets.UTF_8); context.reloadBrooklynProperties(); Location location2 = context.getLocationRegistry().getLocationManaged("localhost"); assertEquals(location.getDisplayName(), "myname"); assertEquals(location2.getDisplayName(), "myname2"); }
@Test public void testReloadPropertiesFromProperties() throws IOException { 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(); Location location = context.getLocationRegistry().getLocationManaged("localhost"); assertEquals(location.getDisplayName(), "myname"); String newGlobalPropertiesContents = "brooklyn.location.localhost.displayName=myname2"; Files.write(newGlobalPropertiesContents, globalPropertiesFile, Charsets.UTF_8); context.reloadBrooklynProperties(); Location location2 = context.getLocationRegistry().getLocationManaged("localhost"); assertEquals(location.getDisplayName(), "myname"); assertEquals(location2.getDisplayName(), "myname"); }
@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"); }