You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ha...@apache.org on 2015/08/18 17:04:10 UTC
[61/64] [abbrv] incubator-brooklyn git commit: BROOKLYN-162 - apply
org.apache package prefix to core config packages
BROOKLYN-162 - apply org.apache package prefix to core config packages
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/68240194
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/68240194
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/68240194
Branch: refs/heads/master
Commit: 682401941862421dad1b9fdbf3ca2eb35261ac5f
Parents: 30c9eaa
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Aug 18 14:37:16 2015 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Aug 18 15:05:22 2015 +0100
----------------------------------------------------------------------
.../java/brooklyn/config/BrooklynLogging.java | 74 ---
.../brooklyn/config/BrooklynProperties.java | 483 -------------------
.../brooklyn/config/BrooklynServerConfig.java | 191 --------
.../brooklyn/config/BrooklynServerPaths.java | 280 -----------
.../config/BrooklynServiceAttributes.java | 66 ---
.../java/brooklyn/config/ConfigPredicates.java | 69 ---
.../main/java/brooklyn/config/ConfigUtils.java | 129 -----
.../java/brooklyn/config/WrappedConfigKey.java | 44 --
.../config/internal/AbstractConfigMapImpl.java | 111 -----
.../brooklyn/config/render/RendererHints.java | 283 -----------
.../basic/AbstractMultipleSensorAggregator.java | 3 +-
.../brooklyn/enricher/basic/Aggregator.java | 2 +-
.../brooklyn/entity/basic/AbstractEntity.java | 4 +-
.../java/brooklyn/entity/basic/Attributes.java | 2 +-
.../entity/basic/BrooklynConfigKeys.java | 2 +-
.../brooklyn/entity/basic/DelegateEntity.java | 2 +-
.../brooklyn/entity/basic/DynamicGroupImpl.java | 5 +-
.../java/brooklyn/entity/basic/Entities.java | 2 +-
.../brooklyn/entity/basic/EntityConfigMap.java | 2 +-
.../java/brooklyn/entity/basic/Lifecycle.java | 3 +-
.../entity/basic/ServiceStateLogic.java | 4 +-
.../group/AbstractMembershipTrackingPolicy.java | 2 +-
.../entity/group/DynamicClusterImpl.java | 2 +-
.../rebind/InitialFullRebindIteration.java | 2 +-
.../brooklyn/entity/rebind/RebindIteration.java | 4 +-
.../entity/rebind/RebindManagerImpl.java | 2 +-
.../persister/BrooklynPersistenceUtils.java | 4 +-
.../rebind/persister/FileBasedObjectStore.java | 3 +-
.../java/brooklyn/event/basic/AttributeMap.java | 2 +-
.../main/java/brooklyn/event/basic/Sensors.java | 3 +-
.../catalog/internal/BasicBrooklynCatalog.java | 4 +-
.../catalog/internal/CatalogInitialization.java | 3 +-
.../core/catalog/internal/CatalogUtils.java | 2 +-
.../brooklyn/core/config/BrooklynLogging.java | 74 +++
.../core/config/BrooklynProperties.java | 483 +++++++++++++++++++
.../core/config/BrooklynServerConfig.java | 192 ++++++++
.../core/config/BrooklynServerPaths.java | 281 +++++++++++
.../core/config/BrooklynServiceAttributes.java | 66 +++
.../brooklyn/core/config/ConfigPredicates.java | 69 +++
.../brooklyn/core/config/ConfigUtils.java | 132 +++++
.../brooklyn/core/config/WrappedConfigKey.java | 44 ++
.../config/internal/AbstractConfigMapImpl.java | 111 +++++
.../core/config/render/RendererHints.java | 284 +++++++++++
.../internal/BrooklynFeatureEnablement.java | 3 +-
.../management/entitlement/Entitlements.java | 2 +-
.../entitlement/PerUserEntitlementManager.java | 4 +-
.../ha/HighAvailabilityManagerImpl.java | 2 +-
.../core/management/ha/OsgiManager.java | 5 +-
.../internal/AbstractManagementContext.java | 2 +-
.../internal/BrooklynGarbageCollector.java | 2 +-
.../internal/EntityManagementUtils.java | 2 +-
.../management/internal/LocalEntityManager.java | 2 +-
.../internal/LocalLocationManager.java | 4 +-
.../internal/LocalManagementContext.java | 4 +-
.../internal/ManagementContextInternal.java | 2 +-
.../NonDeploymentManagementContext.java | 2 +-
.../core/policy/basic/ConfigMapImpl.java | 2 +-
.../core/util/BrooklynNetworkUtils.java | 3 +-
.../brooklyn/core/util/task/ssh/SshTasks.java | 2 +-
.../location/basic/BasicLocationRegistry.java | 5 +-
...ocationPropertiesFromBrooklynProperties.java | 7 +-
.../location/basic/SshMachineLocation.java | 4 +-
.../lite/CampPlatformWithJustBrooklynMgmt.java | 4 +-
.../config/BrooklynPropertiesBuilderTest.java | 82 ----
.../BrooklynPropertiesFromGroovyTest.groovy | 56 ---
.../brooklyn/config/BrooklynPropertiesTest.java | 202 --------
.../java/brooklyn/config/ConfigUtilsTest.java | 41 --
.../entity/BrooklynAppLiveTestSupport.java | 2 +-
.../brooklyn/entity/basic/ConfigMapTest.java | 2 +-
.../downloads/BasicDownloadsRegistryTest.java | 2 +-
.../DownloadProducerFromLocalRepoTest.java | 2 +-
.../DownloadProducerFromPropertiesTest.java | 2 +-
.../entity/rebind/RebindCatalogItemTest.java | 6 +-
...talogWhenCatalogPersistenceDisabledTest.java | 5 +-
.../brooklyn/entity/rebind/RebindTestUtils.java | 4 +-
.../core/catalog/internal/CatalogScanTest.java | 4 +-
.../config/BrooklynPropertiesBuilderTest.java | 83 ++++
.../BrooklynPropertiesFromGroovyTest.groovy | 56 +++
.../core/config/BrooklynPropertiesTest.java | 204 ++++++++
.../brooklyn/core/config/ConfigUtilsTest.java | 42 ++
.../internal/BrooklynFeatureEnablementTest.java | 3 +-
.../AcmeEntitlementManagerTestFixture.java | 2 +-
.../entitlement/EntitlementsTest.java | 2 +-
.../entitlement/EntityEntitlementTest.java | 2 +-
.../internal/EntityExecutionManagerTest.java | 2 +-
.../internal/LocalManagementContextTest.java | 5 +-
.../core/management/osgi/OsgiPathTest.java | 6 +-
.../location/access/PortForwardManagerTest.java | 2 +-
.../basic/ByonLocationResolverTest.java | 2 +-
.../basic/HostLocationResolverTest.java | 2 +-
.../basic/LocalhostLocationResolverTest.java | 2 +-
.../LocalhostProvisioningAndAccessTest.java | 2 +-
.../location/basic/LocationRegistryTest.java | 2 +-
.../basic/MultiLocationResolverTest.java | 2 +-
.../SingleMachineLocationResolverTest.java | 2 +-
.../entity/LocalManagementContextForTests.java | 5 +-
.../apache/brooklyn/demo/WebClusterExample.java | 2 +-
.../JcloudsBlobStoreBasedObjectStore.java | 2 +-
.../location/jclouds/JcloudsLocation.java | 2 +-
...JcloudsPropertiesFromBrooklynProperties.java | 4 +-
.../persister/jclouds/BlobStoreCleaner.java | 3 +-
.../persister/jclouds/BlobStoreExpiryTest.java | 2 +-
.../rebind/persister/jclouds/BlobStoreTest.java | 2 +-
...nMementoPersisterJcloudsObjectStoreTest.java | 2 +-
...ailabilityManagerJcloudsObjectStoreTest.java | 2 +-
.../jclouds/JcloudsExpect100ContinueTest.java | 2 +-
.../JcloudsObjectStoreAccessorWriterTest.java | 2 +-
.../jclouds/AbstractJcloudsLiveTest.java | 2 +-
.../jclouds/BailOutJcloudsLocation.java | 2 +-
.../jclouds/JcloudsLocationMetadataTest.java | 2 +-
.../jclouds/JcloudsLocationResolverTest.java | 2 +-
.../location/jclouds/JcloudsLocationTest.java | 2 +-
.../jclouds/StandaloneJcloudsLiveTest.java | 3 +-
.../provider/AbstractJcloudsLocationTest.java | 2 +-
.../provider/CarrenzaLocationLiveTest.groovy | 2 +-
.../basic/AbstractSoftwareProcessSshDriver.java | 2 +-
.../entity/brooklynnode/BrooklynNodeImpl.java | 2 +-
.../brooklynnode/LocalBrooklynNodeImpl.java | 3 +-
.../java/brooklyn/entity/java/JavaAppUtils.java | 2 +-
.../entity/machine/MachineAttributes.java | 2 +-
.../entity/software/SshEffectorTasks.java | 2 +-
.../brooklyn/entity/AbstractEc2LiveTest.java | 4 +-
.../entity/AbstractGoogleComputeLiveTest.java | 2 +-
.../entity/AbstractSoftlayerLiveTest.java | 2 +-
.../BrooklynNodeIntegrationTest.java | 2 +-
.../entity/pool/ServerPoolLiveTest.java | 2 +-
.../pool/ServerPoolLocationResolverTest.java | 2 +-
.../entity/software/AbstractDockerLiveTest.java | 2 +-
.../management/usage/UsageListenerTest.java | 2 +-
.../basic/WinRmMachineLocationLiveTest.java | 2 +-
.../entity/database/crate/CrateNodeImpl.java | 2 +-
.../mariadb/MariaDbIntegrationTest.java | 2 +-
.../database/mysql/MySqlLiveRackspaceTest.java | 4 +-
.../postgresql/PostgreSqlIntegrationTest.java | 3 +-
.../rubyrep/RubyRepIntegrationTest.java | 4 +-
.../brooklyn/entity/messaging/storm/Storm.java | 2 +-
.../nosql/couchbase/CouchbaseClusterImpl.java | 2 +-
.../entity/nosql/couchbase/CouchbaseNode.java | 2 +-
.../couchbase/CouchbaseSyncGatewayImpl.java | 3 +-
.../entity/nosql/mongodb/MongoDBServerImpl.java | 3 +-
.../entity/webapp/DynamicWebAppCluster.java | 2 +-
.../entity/webapp/WebAppServiceConstants.java | 2 +-
.../entity/webapp/WebAppServiceMetrics.java | 2 +-
.../entity/webapp/jboss/JBoss7ServerImpl.java | 2 +-
.../AbstractWebAppFixtureIntegrationTest.java | 2 +-
.../webapp/WebAppLiveIntegrationTest.groovy | 2 +-
.../impl/hazelcast/HazelcastStorageTest.java | 4 +-
.../camp/brooklyn/BrooklynCampConstants.java | 2 +-
.../camp/brooklyn/BrooklynCampPlatform.java | 2 +-
.../BrooklynAssemblyTemplateInstantiator.java | 2 +-
.../catalog/AbstractCatalogXmlTest.java | 5 +-
.../BrooklynJavascriptGuiLauncherTest.java | 2 +-
.../brooklyn/launcher/BrooklynLauncher.java | 8 +-
.../brooklyn/launcher/BrooklynWebServer.java | 4 +-
.../launcher/config/BrooklynGlobalConfig.java | 2 +-
.../BrooklynLauncherHighAvailabilityTest.java | 2 +-
.../BrooklynLauncherRebindTestFixture.java | 4 +-
.../BrooklynLauncherRebindTestToFiles.java | 4 +-
...lynLauncherRebindToCloudObjectStoreTest.java | 4 +-
.../brooklyn/launcher/BrooklynLauncherTest.java | 4 +-
.../launcher/BrooklynWebServerTest.java | 2 +-
.../brooklyn/launcher/WebAppRunnerTest.java | 2 +-
.../apache/brooklyn/rest/BrooklynWebConfig.java | 2 +-
.../BrooklynPropertiesSecurityFilter.java | 4 +-
.../rest/filter/HaMasterCheckFilter.java | 4 +-
.../brooklyn/rest/filter/LoggingFilter.java | 3 +-
.../resources/AbstractBrooklynRestResource.java | 8 +-
.../provider/ExplicitUsersSecurityProvider.java | 4 +-
.../rest/transform/EntityTransformer.java | 4 +-
.../rest/transform/SensorTransformer.java | 4 +-
.../util/json/BrooklynJacksonJsonProvider.java | 4 +-
.../brooklyn/rest/BrooklynRestApiLauncher.java | 7 +-
.../BrooklynRestApiLauncherTestFixture.java | 6 +-
.../brooklyn/rest/domain/SensorSummaryTest.java | 2 +-
.../rest/resources/SensorResourceTest.java | 2 +-
.../ServerResourceIntegrationTest.java | 3 +-
.../rest/resources/ServerResourceTest.java | 2 +-
.../test/config/render/TestRendererHints.java | 2 +-
178 files changed, 2313 insertions(+), 2346 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/68240194/core/src/main/java/brooklyn/config/BrooklynLogging.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/config/BrooklynLogging.java b/core/src/main/java/brooklyn/config/BrooklynLogging.java
deleted file mode 100644
index 379a04d..0000000
--- a/core/src/main/java/brooklyn/config/BrooklynLogging.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package brooklyn.config;
-
-import org.apache.brooklyn.api.entity.Entity;
-import org.slf4j.Logger;
-
-import brooklyn.entity.basic.EntityInternal;
-
-/** contains common logging categories */
-public class BrooklynLogging {
-
- public static final String SSH_IO = "brooklyn.SSH";
-
- public static final String REST = "brooklyn.REST";
-
- /** For convenience here, since SLF4J does not define such an enum */
- public static enum LoggingLevel { ERROR, WARN, INFO, DEBUG, TRACE }
-
- /** As methods on {@link Logger} but taking the level as an argument */
- public static final void log(Logger logger, LoggingLevel level, String message, Object... args) {
- switch (level) {
- case ERROR: logger.error(message, args); break;
- case WARN: logger.warn(message, args); break;
- case INFO: logger.info(message, args); break;
- case DEBUG: logger.debug(message, args); break;
- case TRACE: logger.trace(message, args); break;
- }
- }
-
- /** As methods on {@link Logger} but taking the level as an argument */
- public static final void log(Logger logger, LoggingLevel level, String message, Throwable t) {
- switch (level) {
- case ERROR: logger.error(message, t); break;
- case WARN: logger.warn(message, t); break;
- case INFO: logger.info(message, t); break;
- case DEBUG: logger.debug(message, t); break;
- case TRACE: logger.trace(message, t); break;
- }
- }
-
- /** returns one of three log levels depending on the read-only status of the entity;
- * unknown should only be the case very early in the management cycle */
- public static LoggingLevel levelDependingIfReadOnly(Entity entity, LoggingLevel levelIfWriting, LoggingLevel levelIfReadOnly, LoggingLevel levelIfUnknown) {
- if (entity==null) return levelIfUnknown;
- Boolean ro = ((EntityInternal)entity).getManagementSupport().isReadOnlyRaw();
- if (ro==null) return levelIfUnknown;
- if (ro) return levelIfReadOnly;
- return levelIfWriting;
- }
-
- /** as {@link #levelDependendingIfReadOnly(Entity)} with {@link LoggingLevel#DEBUG} as the default,
- * but {@link LoggingLevel#TRACE} for read-only */
- public static LoggingLevel levelDebugOrTraceIfReadOnly(Entity entity) {
- return levelDependingIfReadOnly(entity, LoggingLevel.DEBUG, LoggingLevel.TRACE, LoggingLevel.DEBUG);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/68240194/core/src/main/java/brooklyn/config/BrooklynProperties.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/config/BrooklynProperties.java b/core/src/main/java/brooklyn/config/BrooklynProperties.java
deleted file mode 100644
index 6ea8a41..0000000
--- a/core/src/main/java/brooklyn/config/BrooklynProperties.java
+++ /dev/null
@@ -1,483 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package brooklyn.config;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import groovy.lang.Closure;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Arrays;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Properties;
-
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.config.StringConfigMap;
-import org.apache.brooklyn.config.ConfigKey.HasConfigKey;
-import org.apache.brooklyn.core.util.ResourceUtils;
-import org.apache.brooklyn.core.util.config.ConfigBag;
-import org.apache.brooklyn.core.util.flags.TypeCoercions;
-import org.apache.brooklyn.util.collections.MutableMap;
-import org.apache.brooklyn.util.guava.Maybe;
-import org.apache.brooklyn.util.os.Os;
-import org.apache.brooklyn.util.text.StringFunctions;
-import org.apache.brooklyn.util.text.Strings;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import brooklyn.event.basic.BasicConfigKey;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.CharMatcher;
-import com.google.common.base.Objects;
-import com.google.common.base.Predicate;
-import com.google.common.base.Throwables;
-import com.google.common.collect.Maps;
-
-/** utils for accessing command-line and system-env properties;
- * doesn't resolve anything (unless an execution context is supplied)
- * and treats ConfigKeys as of type object when in doubt,
- * or string when that is likely wanted (e.g. {@link #getFirst(Map, String...)}
- * <p>
- * TODO methods in this class are not thread safe.
- * intention is that they are set during startup and not modified thereafter. */
-@SuppressWarnings("rawtypes")
-public class BrooklynProperties extends LinkedHashMap implements StringConfigMap {
-
- private static final long serialVersionUID = -945875483083108978L;
- private static final Logger LOG = LoggerFactory.getLogger(BrooklynProperties.class);
-
- public static class Factory {
- /** creates a new empty {@link BrooklynProperties} */
- public static BrooklynProperties newEmpty() {
- return new BrooklynProperties();
- }
-
- /** creates a new {@link BrooklynProperties} with contents loaded
- * from the usual places, including *.properties files and environment variables */
- public static BrooklynProperties newDefault() {
- return new Builder(true).build();
- }
-
- public static Builder builderDefault() {
- return new Builder(true);
- }
-
- public static Builder builderEmpty() {
- return new Builder(true);
- }
-
- public static class Builder {
- private String defaultLocationMetadataUrl;
- private String globalLocationMetadataFile = null;
- private String globalPropertiesFile = null;
- private String localPropertiesFile = null;
- private BrooklynProperties originalProperties = null;
-
- /** @deprecated since 0.7.0 use static methods in {@link Factory} to create */
- public Builder() {
- this(true);
- }
-
- // TODO it's always called with true here, perhaps we don't need the argument?
- private Builder(boolean setGlobalFileDefaults) {
- resetDefaultLocationMetadataUrl();
- if (setGlobalFileDefaults) {
- resetGlobalFiles();
- }
- }
-
- public Builder resetDefaultLocationMetadataUrl() {
- defaultLocationMetadataUrl = "classpath://brooklyn/location-metadata.properties";
- return this;
- }
- public Builder resetGlobalFiles() {
- defaultLocationMetadataUrl = "classpath://brooklyn/location-metadata.properties";
- globalLocationMetadataFile = Os.mergePaths(Os.home(), ".brooklyn", "location-metadata.properties");
- globalPropertiesFile = Os.mergePaths(Os.home(), ".brooklyn", "brooklyn.properties");
- return this;
- }
-
- /**
- * Creates a Builder that when built, will return the BrooklynProperties passed to this constructor
- */
- private Builder(BrooklynProperties originalProperties) {
- this.originalProperties = new BrooklynProperties().addFromMap(originalProperties);
- }
-
- /**
- * The URL of a default location-metadata.properties (for meta-data about different locations, such as iso3166 and global lat/lon).
- * Defaults to classpath://brooklyn/location-metadata.properties
- */
- public Builder defaultLocationMetadataUrl(String val) {
- defaultLocationMetadataUrl = checkNotNull(val, "file");
- return this;
- }
-
- /**
- * The URL of a location-metadata.properties file that appends to and overwrites values in the locationMetadataUrl.
- * Defaults to ~/.brooklyn/location-metadata.properties
- */
- public Builder globalLocationMetadataFile(String val) {
- globalLocationMetadataFile = checkNotNull(val, "file");
- return this;
- }
-
- /**
- * The URL of a shared brooklyn.properties file. Defaults to ~/.brooklyn/brooklyn.properties.
- * Can be null to disable.
- */
- public Builder globalPropertiesFile(String val) {
- globalPropertiesFile = val;
- return this;
- }
-
- @Beta
- public boolean hasDelegateOriginalProperties() {
- return this.originalProperties==null;
- }
-
- /**
- * The URL of a brooklyn.properties file specific to this launch. Appends to and overwrites values in globalPropertiesFile.
- */
- public Builder localPropertiesFile(String val) {
- localPropertiesFile = val;
- return this;
- }
-
- public BrooklynProperties build() {
- if (originalProperties != null)
- return new BrooklynProperties().addFromMap(originalProperties);
-
- BrooklynProperties properties = new BrooklynProperties();
-
- // TODO Could also read from http://brooklyn.io, for up-to-date values?
- // But might that make unit tests run very badly when developer is offline?
- addPropertiesFromUrl(properties, defaultLocationMetadataUrl, false);
-
- addPropertiesFromFile(properties, globalLocationMetadataFile);
- addPropertiesFromFile(properties, globalPropertiesFile);
- addPropertiesFromFile(properties, localPropertiesFile);
-
- properties.addEnvironmentVars();
- properties.addSystemProperties();
-
- return properties;
- }
-
- public static Builder fromProperties(BrooklynProperties brooklynProperties) {
- return new Builder(brooklynProperties);
- }
-
- @Override
- public String toString() {
- return Objects.toStringHelper(this)
- .omitNullValues()
- .add("originalProperties", originalProperties)
- .add("defaultLocationMetadataUrl", defaultLocationMetadataUrl)
- .add("globalLocationMetadataUrl", globalLocationMetadataFile)
- .add("globalPropertiesFile", globalPropertiesFile)
- .add("localPropertiesFile", localPropertiesFile)
- .toString();
- }
- }
-
- private static void addPropertiesFromUrl(BrooklynProperties p, String url, boolean warnIfNotFound) {
- if (url==null) return;
-
- try {
- p.addFrom(ResourceUtils.create(BrooklynProperties.class).getResourceFromUrl(url));
- } catch (Exception e) {
- if (warnIfNotFound)
- LOG.warn("Could not load {}; continuing", url);
- if (LOG.isTraceEnabled()) LOG.trace("Could not load "+url+"; continuing", e);
- }
- }
-
- private static void addPropertiesFromFile(BrooklynProperties p, String file) {
- if (file==null) return;
-
- String fileTidied = Os.tidyPath(file);
- File f = new File(fileTidied);
-
- if (f.exists()) {
- p.addFrom(f);
- }
- }
- }
-
- protected BrooklynProperties() {
- }
-
- public BrooklynProperties addEnvironmentVars() {
- addFrom(System.getenv());
- return this;
- }
-
- public BrooklynProperties addSystemProperties() {
- addFrom(System.getProperties());
- return this;
- }
-
- public BrooklynProperties addFrom(ConfigBag cfg) {
- addFrom(cfg.getAllConfig());
- return this;
- }
-
- @SuppressWarnings("unchecked")
- public BrooklynProperties addFrom(Map map) {
- putAll(Maps.transformValues(map, StringFunctions.trim()));
- return this;
- }
-
- public BrooklynProperties addFrom(InputStream i) {
- // Ugly way to load them in order, but Properties is a Hashtable so loses order otherwise.
- @SuppressWarnings({ "serial" })
- Properties p = new Properties() {
- @Override
- public synchronized Object put(Object key, Object value) {
- // Trim the string values to remove leading and trailing spaces
- String s = (String) value;
- if (Strings.isBlank(s)) {
- s = Strings.EMPTY;
- } else {
- s = CharMatcher.BREAKING_WHITESPACE.trimFrom(s);
- }
- return BrooklynProperties.this.put(key, s);
- }
- };
- try {
- p.load(i);
- } catch (IOException e) {
- throw Throwables.propagate(e);
- }
- return this;
- }
-
- public BrooklynProperties addFrom(File f) {
- if (!f.exists()) {
- LOG.warn("Unable to find file '"+f.getAbsolutePath()+"' when loading properties; ignoring");
- return this;
- } else {
- try {
- return addFrom(new FileInputStream(f));
- } catch (FileNotFoundException e) {
- throw Throwables.propagate(e);
- }
- }
- }
- public BrooklynProperties addFrom(URL u) {
- try {
- return addFrom(u.openStream());
- } catch (IOException e) {
- throw new RuntimeException("Error reading properties from "+u+": "+e, e);
- }
- }
- /**
- * @see ResourceUtils#getResourceFromUrl(String)
- *
- * of the form form file:///home/... or http:// or classpath://xx ;
- * for convenience if not starting with xxx: it is treated as a classpath reference or a file;
- * throws if not found (but does nothing if argument is null)
- */
- public BrooklynProperties addFromUrl(String url) {
- try {
- if (url==null) return this;
- return addFrom(ResourceUtils.create(this).getResourceFromUrl(url));
- } catch (Exception e) {
- throw new RuntimeException("Error reading properties from "+url+": "+e, e);
- }
- }
-
- /** expects a property already set in scope, whose value is acceptable to {@link #addFromUrl(String)};
- * if property not set, does nothing */
- public BrooklynProperties addFromUrlProperty(String urlProperty) {
- String url = (String) get(urlProperty);
- if (url==null) addFromUrl(url);
- return this;
- }
-
- /**
- * adds the indicated properties
- */
- public BrooklynProperties addFromMap(Map properties) {
- putAll(properties);
- return this;
- }
-
- /** inserts the value under the given key, if it was not present */
- public boolean putIfAbsent(String key, Object value) {
- if (containsKey(key)) return false;
- put(key, value);
- return true;
- }
-
- /** @deprecated attempts to call get with this syntax are probably mistakes; get(key, defaultValue) is fine but
- * Map is unlikely the key, much more likely they meant getFirst(flags, key).
- */
- @Deprecated
- public String get(Map flags, String key) {
- LOG.warn("Discouraged use of 'BrooklynProperties.get(Map,String)' (ambiguous); use getFirst(Map,String) or get(String) -- assuming the former");
- LOG.debug("Trace for discouraged use of 'BrooklynProperties.get(Map,String)'",
- new Throwable("Arguments: "+flags+" "+key));
- return getFirst(flags, key);
- }
-
- /** returns the value of the first key which is defined
- * <p>
- * takes the following flags:
- * 'warnIfNone', 'failIfNone' (both taking a boolean (to use default message) or a string (which is the message));
- * and 'defaultIfNone' (a default value to return if there is no such property); defaults to no warning and null response */
- @Override
- public String getFirst(String ...keys) {
- return getFirst(MutableMap.of(), keys);
- }
- @Override
- public String getFirst(Map flags, String ...keys) {
- for (String k: keys) {
- if (k!=null && containsKey(k)) return (String) get(k);
- }
- if (flags.get("warnIfNone")!=null && !Boolean.FALSE.equals(flags.get("warnIfNone"))) {
- if (Boolean.TRUE.equals(flags.get("warnIfNone")))
- LOG.warn("Unable to find Brooklyn property "+keys);
- else
- LOG.warn(""+flags.get("warnIfNone"));
- }
- if (flags.get("failIfNone")!=null && !Boolean.FALSE.equals(flags.get("failIfNone"))) {
- Object f = flags.get("failIfNone");
- if (f instanceof Closure)
- ((Closure)f).call((Object[])keys);
- if (Boolean.TRUE.equals(f))
- throw new NoSuchElementException("Brooklyn unable to find mandatory property "+keys[0]+
- (keys.length>1 ? " (or "+(keys.length-1)+" other possible names, full list is "+Arrays.asList(keys)+")" : "") );
- else
- throw new NoSuchElementException(""+f);
- }
- if (flags.get("defaultIfNone")!=null) {
- return (String) flags.get("defaultIfNone");
- }
- return null;
- }
-
- @Override
- public String toString() {
- return "BrooklynProperties["+size()+"]";
- }
-
- /** like normal map.put, except config keys are dereferenced on the way in */
- @SuppressWarnings("unchecked")
- public Object put(Object key, Object value) {
- if (key instanceof HasConfigKey) key = ((HasConfigKey)key).getConfigKey().getName();
- if (key instanceof ConfigKey) key = ((ConfigKey)key).getName();
- return super.put(key, value);
- }
-
- /** like normal map.putAll, except config keys are dereferenced on the way in */
- @Override
- public void putAll(Map vals) {
- for (Map.Entry<?,?> entry : ((Map<?,?>)vals).entrySet()) {
- put(entry.getKey(), entry.getValue());
- }
- }
-
- @SuppressWarnings("unchecked")
- public <T> Object put(HasConfigKey<T> key, T value) {
- return super.put(key.getConfigKey().getName(), value);
- }
-
- @SuppressWarnings("unchecked")
- public <T> Object put(ConfigKey<T> key, T value) {
- return super.put(key.getName(), value);
- }
-
- public <T> boolean putIfAbsent(ConfigKey<T> key, T value) {
- return putIfAbsent(key.getName(), value);
- }
-
- @Override
- public <T> T getConfig(ConfigKey<T> key) {
- return getConfig(key, null);
- }
-
- @Override
- public <T> T getConfig(HasConfigKey<T> key) {
- return getConfig(key.getConfigKey(), null);
- }
-
- @Override
- public <T> T getConfig(HasConfigKey<T> key, T defaultValue) {
- return getConfig(key.getConfigKey(), defaultValue);
- }
-
- @Override
- public <T> T getConfig(ConfigKey<T> key, T defaultValue) {
- // TODO does not support MapConfigKey etc where entries use subkey notation; for now, access using submap
- if (!containsKey(key.getName())) {
- if (defaultValue!=null) return defaultValue;
- return key.getDefaultValue();
- }
- Object value = get(key.getName());
- if (value==null) return null;
- // no evaluation / key extraction here
- return TypeCoercions.coerce(value, key.getTypeToken());
- }
-
- @Override
- public Object getRawConfig(ConfigKey<?> key) {
- return get(key.getName());
- }
-
- @Override
- public Maybe<Object> getConfigRaw(ConfigKey<?> key, boolean includeInherited) {
- if (containsKey(key.getName())) return Maybe.of(get(key.getName()));
- return Maybe.absent();
- }
-
- @Override
- public Map<ConfigKey<?>, Object> getAllConfig() {
- Map<ConfigKey<?>, Object> result = new LinkedHashMap<ConfigKey<?>, Object>();
- for (Object entry: entrySet())
- result.put(new BasicConfigKey<Object>(Object.class, ""+((Map.Entry)entry).getKey()), ((Map.Entry)entry).getValue());
- return result;
- }
-
- @Override
- public BrooklynProperties submap(Predicate<ConfigKey<?>> filter) {
- BrooklynProperties result = Factory.newEmpty();
- for (Object entry: entrySet()) {
- ConfigKey<?> k = new BasicConfigKey<Object>(Object.class, ""+((Map.Entry)entry).getKey());
- if (filter.apply(k))
- result.put(((Map.Entry)entry).getKey(), ((Map.Entry)entry).getValue());
- }
- return result;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Map<String, Object> asMapWithStringKeys() {
- return this;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/68240194/core/src/main/java/brooklyn/config/BrooklynServerConfig.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/config/BrooklynServerConfig.java b/core/src/main/java/brooklyn/config/BrooklynServerConfig.java
deleted file mode 100644
index 380380e..0000000
--- a/core/src/main/java/brooklyn/config/BrooklynServerConfig.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package brooklyn.config;
-
-import static brooklyn.entity.basic.ConfigKeys.newStringConfigKey;
-
-import java.io.File;
-import java.net.URI;
-import java.util.Map;
-
-import org.apache.brooklyn.api.management.ManagementContext;
-import org.apache.brooklyn.camp.CampPlatform;
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.config.StringConfigMap;
-import org.apache.brooklyn.core.catalog.internal.CatalogInitialization;
-import org.apache.brooklyn.util.guava.Maybe;
-import org.apache.brooklyn.util.os.Os;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import brooklyn.entity.basic.ConfigKeys;
-
-/** Config keys for the brooklyn server */
-public class BrooklynServerConfig {
-
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(BrooklynServerConfig.class);
-
- /**
- * Provided for setting; consumers should use {@link #getMgmtBaseDir(ManagementContext)}
- */
- public static final ConfigKey<String> MGMT_BASE_DIR = newStringConfigKey(
- "brooklyn.base.dir", "Directory for reading and writing all brooklyn server data",
- Os.fromHome(".brooklyn"));
-
- @Deprecated /** @deprecated since 0.7.0 use BrooklynServerConfig routines */
- // copied here so we don't have back-ref to BrooklynConfigKeys
- public static final ConfigKey<String> BROOKLYN_DATA_DIR = newStringConfigKey(
- "brooklyn.datadir", "Directory for writing all brooklyn data");
-
- /**
- * Provided for setting; consumers should query the management context persistence subsystem
- * for the actual target, or use {@link BrooklynServerPaths#newMainPersistencePathResolver(ManagementContext)}
- * if trying to resolve the value
- */
- public static final ConfigKey<String> PERSISTENCE_DIR = newStringConfigKey(
- "brooklyn.persistence.dir",
- "Directory or container name for writing persisted state");
-
- public static final ConfigKey<String> PERSISTENCE_LOCATION_SPEC = newStringConfigKey(
- "brooklyn.persistence.location.spec",
- "Optional location spec string for an object store (e.g. jclouds:swift:URL) where persisted state should be kept; "
- + "if blank or not supplied, the file system is used");
-
- public static final ConfigKey<String> PERSISTENCE_BACKUPS_DIR = newStringConfigKey(
- "brooklyn.persistence.backups.dir",
- "Directory or container name for writing backups of persisted state; "
- + "defaults to 'backups' inside the default persistence directory");
-
- public static final ConfigKey<String> PERSISTENCE_BACKUPS_LOCATION_SPEC = newStringConfigKey(
- "brooklyn.persistence.backups.location.spec",
- "Location spec string for an object store (e.g. jclouds:swift:URL) where backups of persisted state should be kept; "
- + "defaults to the local file system");
-
- public static final ConfigKey<Boolean> PERSISTENCE_BACKUPS_REQUIRED_ON_PROMOTION =
- ConfigKeys.newBooleanConfigKey("brooklyn.persistence.backups.required.promotion",
- "Whether a backup should be made of the persisted state from the persistence location to the backup location on node promotion, "
- + "before any writes from this node", true);
-
- public static final ConfigKey<Boolean> PERSISTENCE_BACKUPS_REQUIRED_ON_DEMOTION =
- ConfigKeys.newBooleanConfigKey("brooklyn.persistence.backups.required.promotion",
- "Whether a backup of in-memory state should be made to the backup persistence location on node demotion, "
- + "in case other nodes might write conflicting state", true);
-
- /** @deprecated since 0.7.0, use {@link #PERSISTENCE_BACKUPS_ON_PROMOTION} and {@link #PERSISTENCE_BACKUPS_ON_DEMOTION},
- * which allow using a different target location and are supported on more environments (and now default to true) */
- @Deprecated
- public static final ConfigKey<Boolean> PERSISTENCE_BACKUPS_REQUIRED =
- ConfigKeys.newBooleanConfigKey("brooklyn.persistence.backups.required",
- "Whether a backup should always be made of the persistence directory; "
- + "if true, it will fail if this operation is not permitted (e.g. jclouds-based cloud object stores); "
- + "if false, the persistence store will be overwritten with changes (but files not removed if they are unreadable); "
- + "if null or not set, the legacy beahviour of creating backups where possible (e.g. file system) is currently used; "
- + "this key is DEPRECATED in favor of promotion and demotion specific flags now defaulting to true");
-
- public static final ConfigKey<String> BROOKLYN_CATALOG_URL = ConfigKeys.newStringConfigKey("brooklyn.catalog.url",
- "The URL of a custom catalog.bom or catalog.xml descriptor to load");
-
- /** @deprecated since 0.7.0 replaced by {@link CatalogInitialization}; also note, default removed
- * (it was overridden anyway, and in almost all cases the new behaviour is still the default behaviour) */
- @Deprecated
- public static final ConfigKey<org.apache.brooklyn.core.catalog.CatalogLoadMode> CATALOG_LOAD_MODE = ConfigKeys.newConfigKey(org.apache.brooklyn.core.catalog.CatalogLoadMode.class,
- "brooklyn.catalog.mode",
- "The mode the management context should use to load the catalog when first starting");
-
- /** string used in places where the management node ID is needed to resolve a path */
- public static final String MANAGEMENT_NODE_ID_PROPERTY = "brooklyn.mgmt.node.id";
-
- public static final ConfigKey<Boolean> USE_OSGI = ConfigKeys.newBooleanConfigKey("brooklyn.osgi.enabled",
- "Whether OSGi is enabled, defaulting to true", true);
- public static final ConfigKey<String> OSGI_CACHE_DIR = ConfigKeys.newStringConfigKey("brooklyn.osgi.cache.dir",
- "Directory to use for OSGi cache, potentially including Freemarker template variables "
- + "${"+MGMT_BASE_DIR.getName()+"} (which is the default for relative paths), "
- + "${"+Os.TmpDirFinder.BROOKLYN_OS_TMPDIR_PROPERTY+"} if it should be in the tmp dir space, "
- + "and ${"+MANAGEMENT_NODE_ID_PROPERTY+"} to include the management node ID (recommended if running multiple OSGi paths)",
- "osgi/cache/${"+MANAGEMENT_NODE_ID_PROPERTY+"}/");
- public static final ConfigKey<Boolean> OSGI_CACHE_CLEAN = ConfigKeys.newBooleanConfigKey("brooklyn.osgi.cache.clean",
- "Whether to delete the OSGi directory before and after use; if unset, it will delete if the node ID forms part of the cache dir path (which by default it does) to avoid file leaks");
-
- public static final ConfigKey<CampPlatform> CAMP_PLATFORM = ConfigKeys.newConfigKey(CampPlatform.class, "brooklyn.camp.platform",
- "Config set at brooklyn management platform to find the CampPlatform instance (bi-directional)");
-
- /** @see BrooklynServerPaths#getMgmtBaseDir(ManagementContext) */
- public static String getMgmtBaseDir(ManagementContext mgmt) {
- return BrooklynServerPaths.getMgmtBaseDir(mgmt);
- }
- /** @see BrooklynServerPaths#getMgmtBaseDir(ManagementContext) */
- public static String getMgmtBaseDir(StringConfigMap brooklynProperties) {
- return BrooklynServerPaths.getMgmtBaseDir(brooklynProperties);
- }
- /** @see BrooklynServerPaths#getMgmtBaseDir(ManagementContext) */
- public static String getMgmtBaseDir(Map<String,?> brooklynProperties) {
- return BrooklynServerPaths.getMgmtBaseDir(brooklynProperties);
- }
-
- /** @deprecated since 0.7.0 use {@link BrooklynServerPaths#newMainPersistencePathResolver(ManagementContext)} */
- public static String getPersistenceDir(ManagementContext mgmt) {
- return getPersistenceDir(mgmt.getConfig());
- }
- /** @deprecated since 0.7.0 use {@link BrooklynServerPaths#newMainPersistencePathResolver(ManagementContext)} */
- public static String getPersistenceDir(StringConfigMap brooklynProperties) {
- return resolvePersistencePath(null, brooklynProperties, null);
- }
-
- /**
- * @param optionalSuppliedValue
- * An optional value which has been supplied explicitly
- * @param brooklynProperties
- * The properties map where the persistence path should be looked up if not supplied,
- * along with finding the brooklyn.base.dir if needed (using file system persistence
- * with a relative path)
- * @param optionalObjectStoreLocationSpec
- * If a location spec is supplied, this will return a container name suitable for use
- * with the given object store based on brooklyn.persistence.dir; if null this method
- * will return a full file system path, relative to the brooklyn.base.dir if the
- * configured brooklyn.persistence.dir is not absolute
- * @return The container name or full path for where persist state should be kept
- * @deprecated since 0.7.0 use {@link BrooklynServerPaths#newMainPersistencePathResolver(ManagementContext)} */
- public static String resolvePersistencePath(String optionalSuppliedValue, StringConfigMap brooklynProperties, String optionalObjectStoreLocationSpec) {
- return BrooklynServerPaths.newMainPersistencePathResolver(brooklynProperties).location(optionalObjectStoreLocationSpec).dir(optionalSuppliedValue).resolve();
- }
-
-
- /** @deprecated since 0.7.0 use {@link BrooklynServerPaths#getBrooklynWebTmpDir(ManagementContext)} */
- public static File getBrooklynWebTmpDir(ManagementContext mgmt) {
- return BrooklynServerPaths.getBrooklynWebTmpDir(mgmt);
- }
-
- /**
- * @return the CAMP platform associated with a management context, if there is one.
- */
- public static Maybe<CampPlatform> getCampPlatform(ManagementContext mgmt) {
- CampPlatform result = mgmt.getConfig().getConfig(BrooklynServerConfig.CAMP_PLATFORM);
- if (result!=null) return Maybe.of(result);
- return Maybe.absent("No CAMP Platform is registered with this Brooklyn management context.");
- }
-
- /**
- * @return {@link ManagementContext#getManagementNodeUri()}, located in this utility class for convenience.
- */
- public static Maybe<URI> getBrooklynWebUri(ManagementContext mgmt) {
- return mgmt.getManagementNodeUri();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/68240194/core/src/main/java/brooklyn/config/BrooklynServerPaths.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/config/BrooklynServerPaths.java b/core/src/main/java/brooklyn/config/BrooklynServerPaths.java
deleted file mode 100644
index e8fb365..0000000
--- a/core/src/main/java/brooklyn/config/BrooklynServerPaths.java
+++ /dev/null
@@ -1,280 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package brooklyn.config;
-
-import java.io.File;
-import java.util.Map;
-
-import javax.annotation.Nullable;
-
-import org.apache.brooklyn.api.management.ManagementContext;
-import org.apache.brooklyn.config.StringConfigMap;
-import org.apache.brooklyn.core.management.internal.ManagementContextInternal;
-import org.apache.brooklyn.core.util.text.TemplateProcessor;
-import org.apache.brooklyn.util.collections.MutableMap;
-import org.apache.brooklyn.util.exceptions.Exceptions;
-import org.apache.brooklyn.util.guava.Maybe;
-import org.apache.brooklyn.util.net.Urls;
-import org.apache.brooklyn.util.os.Os;
-import org.apache.brooklyn.util.text.Identifiers;
-import org.apache.brooklyn.util.text.Strings;
-import org.apache.brooklyn.util.time.Time;
-import org.apache.commons.io.FileUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Objects;
-
-public class BrooklynServerPaths {
-
- private static final Logger log = LoggerFactory.getLogger(BrooklynServerPaths.class);
-
- /** 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 BrooklynServerPaths#getMgmtBaseDir(ManagementContext) */
- @SuppressWarnings("deprecation")
- public static String getMgmtBaseDir(StringConfigMap brooklynProperties) {
- String base = (String) brooklynProperties.getConfigRaw(BrooklynServerConfig.MGMT_BASE_DIR, true).orNull();
- if (base==null) {
- base = brooklynProperties.getConfig(BrooklynServerConfig.BROOKLYN_DATA_DIR);
- if (base!=null)
- log.warn("Using deprecated "+BrooklynServerConfig.BROOKLYN_DATA_DIR.getName()+": use "+BrooklynServerConfig.MGMT_BASE_DIR.getName()+" instead; value: "+base);
- }
- if (base==null) base = brooklynProperties.getConfig(BrooklynServerConfig.MGMT_BASE_DIR);
- return Os.tidyPath(base)+File.separator;
- }
- /** @see BrooklynServerPaths#getMgmtBaseDir(ManagementContext) */
- @SuppressWarnings("deprecation")
- public static String getMgmtBaseDir(Map<String,?> brooklynProperties) {
- String base = (String) brooklynProperties.get(BrooklynServerConfig.MGMT_BASE_DIR.getName());
- if (base==null) base = (String) brooklynProperties.get(BrooklynServerConfig.BROOKLYN_DATA_DIR.getName());
- if (base==null) base = BrooklynServerConfig.MGMT_BASE_DIR.getDefaultValue();
- return Os.tidyPath(base)+File.separator;
- }
-
- protected static String resolveAgainstBaseDir(StringConfigMap brooklynProperties, String path) {
- if (!Os.isAbsolutish(path)) path = Os.mergePaths(getMgmtBaseDir(brooklynProperties), path);
- return Os.tidyPath(path);
- }
-
- // ---------- persistence
-
- public static final String DEFAULT_PERSISTENCE_CONTAINER_NAME = "brooklyn-persisted-state";
- /** on file system, the 'data' subdir is used so that there is an obvious place to put backup dirs */
- public static final String DEFAULT_PERSISTENCE_DIR_FOR_FILESYSTEM = Os.mergePaths(DEFAULT_PERSISTENCE_CONTAINER_NAME, "data");
-
- /** @see PersistencePathResolver */
- public static PersistencePathResolver newMainPersistencePathResolver(StringConfigMap brooklynProperties) {
- return new PersistencePathResolver(brooklynProperties);
- }
- /** @see PersistencePathResolver */
- public static PersistencePathResolver newMainPersistencePathResolver(ManagementContext mgmt) {
- return new PersistencePathResolver(mgmt.getConfig());
- }
-
- /** @see PersistenceBackupPathResolver */
- public static PersistenceBackupPathResolver newBackupPersistencePathResolver(ManagementContext mgmt) {
- return new PersistenceBackupPathResolver(mgmt.getConfig());
- }
-
- /**
- * Utility for computing the path (dir or container name) to use for persistence.
- * <p>
- * Usage is to invoke {@link BrooklynServerPaths#newMainPersistencePathResolver(ManagementContext)}
- * then to set {@link #location(String)} and {@link #dir(String)} as needed, and then to {@link #resolve()}.
- */
- public static class PersistencePathResolver {
- protected final StringConfigMap brooklynProperties;
- protected String locationSpec;
- protected String dirOrContainer;
- private PersistencePathResolver(StringConfigMap brooklynProperties) {
- this.brooklynProperties = brooklynProperties;
- }
- /**
- * Optional location spec. If supplied, the {@link #resolve()} will return a container name suitable for use
- * with the store, based on the {@link #dir(String)};
- * if not supplied, or blank, or localhost this will cause resolution to give a full file system path,
- * if relative taken with respect to the {@link BrooklynServerPaths#getMgmtBaseDir(ManagementContext)}.
- * Config is <b>not</b> looked up for resolving a location spec. */
- public PersistencePathResolver location(@Nullable String locationSpec) {
- this.locationSpec = locationSpec;
- return this;
- }
- /**
- * Optional directory (for localhost/filesystem) or container name.
- * If null or not supplied, config <b>is</b> looked up (because a value is always needed),
- * followed by defaults for {@link BrooklynServerPaths#DEFAULT_PERSISTENCE_DIR_FOR_FILESYSTEM} and
- * {@link BrooklynServerPaths#DEFAULT_PERSISTENCE_CONTAINER_NAME} are used. */
- public PersistencePathResolver dir(@Nullable String dirOrContainer) {
- this.dirOrContainer = dirOrContainer;
- return this;
- }
-
- public String resolve() {
- String path = dirOrContainer;
- if (path==null) path = getDefaultPathFromConfig();
- if (Strings.isBlank(locationSpec) || "localhost".equals(locationSpec)) {
- // file system
- if (Strings.isBlank(path)) path=getDefaultDirForAnyFilesystem();
- return resolveAgainstBaseDir(brooklynProperties, path);
- } else {
- // obj store
- if (path==null) path=getDefaultContainerForAnyNonFilesystem();
- return path;
- }
- }
-
- protected String getDefaultPathFromConfig() {
- return brooklynProperties.getConfig(BrooklynServerConfig.PERSISTENCE_DIR);
- }
- protected String getDefaultDirForAnyFilesystem() {
- return DEFAULT_PERSISTENCE_DIR_FOR_FILESYSTEM;
- }
- protected String getDefaultContainerForAnyNonFilesystem() {
- return DEFAULT_PERSISTENCE_CONTAINER_NAME;
- }
- }
-
- /**
- * Similar to {@link PersistencePathResolver}, but designed for use for backup subpaths.
- * If the container is not explicitly specified, "backups" is appended to the defaults from {@link PersistencePathResolver}.
- * <p>
- * It also includes conveniences for resolving further subpaths, cf {@link PersistenceBackupPathResolver#resolveWithSubpathFor(ManagementContextInternal, String)}.
- */
- public static class PersistenceBackupPathResolver extends PersistencePathResolver {
- private String nonBackupLocationSpec;
- private PersistenceBackupPathResolver(StringConfigMap brooklynProperties) {
- super(brooklynProperties);
- }
- public PersistenceBackupPathResolver nonBackupLocation(@Nullable String locationSpec) {
- this.nonBackupLocationSpec = locationSpec;
- return this;
- }
- @Override
- public PersistenceBackupPathResolver dir(String dirOrContainer) {
- super.dir(dirOrContainer);
- return this;
- }
- @Override
- public PersistenceBackupPathResolver location(String backupLocationSpec) {
- super.location(backupLocationSpec);
- return this;
- }
- protected boolean isBackupSameLocation() {
- return Objects.equal(locationSpec, nonBackupLocationSpec);
- }
- /** Appends a sub-path to the path returned by {@link #resolve()} */
- public String resolveWithSubpath(String subpath) {
- return Urls.mergePaths(super.resolve(), subpath);
- }
- /** 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
- protected String getDefaultPathFromConfig() {
- Maybe<Object> result = brooklynProperties.getConfigRaw(BrooklynServerConfig.PERSISTENCE_BACKUPS_DIR, true);
- if (result.isPresent()) return Strings.toString(result.get());
- if (isBackupSameLocation()) {
- return backupContainerFor(brooklynProperties.getConfig(BrooklynServerConfig.PERSISTENCE_DIR));
- }
- return null;
- }
- protected String backupContainerFor(String nonBackupContainer) {
- if (nonBackupContainer==null) return null;
- return Urls.mergePaths(nonBackupContainer, "backups");
- }
- @Override
- protected String getDefaultDirForAnyFilesystem() {
- return backupContainerFor(DEFAULT_PERSISTENCE_CONTAINER_NAME);
- }
- @Override
- protected String getDefaultContainerForAnyNonFilesystem() {
- return backupContainerFor(super.getDefaultContainerForAnyNonFilesystem());
- }
- }
-
- // ------ web
-
- public static File getBrooklynWebTmpDir(ManagementContext mgmt) {
- String brooklynMgmtBaseDir = getMgmtBaseDir(mgmt);
- File webappTempDir = new File(Os.mergePaths(brooklynMgmtBaseDir, "planes", mgmt.getManagementPlaneId(), 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;
- }
- }
-
- 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, (ManagementContextInternal)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);
- }
-
- 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 getOsgiCacheDirCleanedIfNeeded(ManagementContext mgmt) {
- File cacheDirF = getOsgiCacheDir(mgmt);
- boolean clean = isOsgiCacheForCleaning(mgmt, cacheDirF);
- log.debug("OSGi cache dir computed as "+cacheDirF.getName()+" ("+
- (cacheDirF.exists() ? "already exists" : "does not exist")+", "+
- (clean ? "cleaning now (and on exit)" : "cleaning not requested"));
-
- if (clean) {
- Os.deleteRecursively(cacheDirF);
- Os.deleteOnExitRecursively(cacheDirF);
- }
-
- return cacheDirF;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/68240194/core/src/main/java/brooklyn/config/BrooklynServiceAttributes.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/config/BrooklynServiceAttributes.java b/core/src/main/java/brooklyn/config/BrooklynServiceAttributes.java
deleted file mode 100644
index 355079d..0000000
--- a/core/src/main/java/brooklyn/config/BrooklynServiceAttributes.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package brooklyn.config;
-
-import org.apache.brooklyn.api.management.ManagementContext;
-import org.apache.brooklyn.util.internal.StringSystemProperty;
-
-/** attributes which callers can set and a service application
- * (such as servlet or osgi) will pay attention to,
- * contained in one place for convenience
- *
- * @author alex
- */
-public class BrooklynServiceAttributes {
-
- /*
- * These fields are contained here so that they are visible both to web console
- * and to launcher, without needing a separate web-console-support project,
- * or battling maven etc to build web-console as jar available to launcher
- * (which would contain a lot of crap as well).
- */
-
- /** used to hold the instance of ManagementContext which should be used */
- public static final String BROOKLYN_MANAGEMENT_CONTEXT = ManagementContext.class.getName();
-
- /** poor-man's security, to specify a user to be automatically logged in
- * (e.g. to bypass security, during dev/test); 'admin' is usually a sensible choice.
- * if not specified (the default) username+password is required.
- * @deprecated since 0.6.0; not used; you can now configure security properly instead!
- * (though this may be useful again when we have users and permissions,
- * to indicate the user who should be logged in by default...) */ @Deprecated
- public static final String BROOKLYN_AUTOLOGIN_USERNAME = "brooklyn.autologin.username";
-
- /** poor-man's security, to specify a default password for access
- * @deprecated since 0.6.0; not used; you can now configure security properly instead! */ @Deprecated
- public static final String BROOKLYN_DEFAULT_PASSWORD = "brooklyn.default.password";
-
- // TODO use ConfigKey (or possibly BrooklynSystemProperties ?)
-
- /** in some cases localhost does not resolve correctly
- * (e.g. to an interface which is defined locally but not in operation,
- * or where multiple NICs are available and java's InetAddress.getLocalHost() strategy is not doing what is desired);
- * use this to supply a specific address (e.g. "127.0.0.1" or a specific IP on a specific NIC or FW)
- */
- public static StringSystemProperty LOCALHOST_IP_ADDRESS = new StringSystemProperty("brooklyn.location.localhost.address");
-
- /** Jackson ObjectMapper shared among REST resources */
- public static final String BROOKLYN_REST_OBJECT_MAPPER = "brooklyn.rest.objectMapper";
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/68240194/core/src/main/java/brooklyn/config/ConfigPredicates.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/config/ConfigPredicates.java b/core/src/main/java/brooklyn/config/ConfigPredicates.java
deleted file mode 100644
index 03c0e97..0000000
--- a/core/src/main/java/brooklyn/config/ConfigPredicates.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package brooklyn.config;
-
-import java.util.regex.Pattern;
-
-import javax.annotation.Nullable;
-
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.util.text.WildcardGlobs;
-
-import com.google.common.base.Predicate;
-
-public class ConfigPredicates {
-
- public static Predicate<ConfigKey<?>> startingWith(final String prefix) {
- return new Predicate<ConfigKey<?>>() {
- @Override
- public boolean apply(@Nullable ConfigKey<?> input) {
- return (input != null) && input.getName().startsWith(prefix);
- }
- };
- }
-
- public static Predicate<ConfigKey<?>> matchingGlob(final String glob) {
- return new Predicate<ConfigKey<?>>() {
- @Override
- public boolean apply(@Nullable ConfigKey<?> input) {
- return (input != null) && WildcardGlobs.isGlobMatched(glob, input.getName());
- }
- };
- }
-
- public static Predicate<ConfigKey<?>> matchingRegex(final String regex) {
- final Pattern p = Pattern.compile(regex);
- return new Predicate<ConfigKey<?>>() {
- @Override
- public boolean apply(@Nullable ConfigKey<?> input) {
- return (input != null) && p.matcher(input.getName()).matches();
- }
- };
- }
-
- public static Predicate<ConfigKey<?>> nameMatching(final Predicate<String> filter) {
- return new Predicate<ConfigKey<?>>() {
- @Override
- public boolean apply(@Nullable ConfigKey<?> input) {
- return (input != null) && filter.apply(input.getName());
- }
- };
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/68240194/core/src/main/java/brooklyn/config/ConfigUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/config/ConfigUtils.java b/core/src/main/java/brooklyn/config/ConfigUtils.java
deleted file mode 100644
index fc58f7f..0000000
--- a/core/src/main/java/brooklyn/config/ConfigUtils.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package brooklyn.config;
-
-import java.io.File;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.config.ConfigKey.HasConfigKey;
-import org.apache.brooklyn.util.exceptions.Exceptions;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import brooklyn.entity.basic.ConfigKeys;
-import brooklyn.event.basic.BasicConfigKey;
-
-import com.google.common.base.Predicate;
-
-@SuppressWarnings({"unchecked"})
-public class ConfigUtils {
-
- private static final Logger log = LoggerFactory.getLogger(ConfigUtils.class);
-
- public static <T> T getRequiredConfig(Entity entity, ConfigKey<T> key) {
- T result = entity.getConfig(key);
- if (result==null) throw new IllegalStateException("Configuration "+key+" is required");
- return result;
- }
-
- /** prepends the given prefix to the key. prefix will typically end with a ".".
- * this is useful for configuration purposes when a subsystem uses a short-name config (e.g. "user")
- * but in entity config or at the root (brooklyn.properties) there are longer names (e.g. "brooklyn.ssh.config.user"),
- * and we wish to convert from the shorter names to the longer names. */
- public static <T> ConfigKey<T> prefixedKey(String prefix, ConfigKey<T> key) {
- return ConfigKeys.newConfigKeyWithPrefix(prefix, key);
- }
-
- /** removes the given prefix from the key for configuration purposes; logs warning and does nothing if there is no such prefix.
- * prefix will typically end with a ".".
- * this is useful for configuration purposes when a subsystem uses a short-name config (e.g. "user")
- * but in entity config or at the root (brooklyn.properties) there are longer names (e.g. "brooklyn.ssh.config.user"),
- * and we wish to convert from the longer names to the short-name. */
- public static <T> ConfigKey<T> unprefixedKey(String prefix, ConfigKey<T> key) {
- String newName = key.getName();
- if (newName.startsWith(prefix)) newName = newName.substring(prefix.length());
- else log.warn("Cannot remove prefix "+prefix+" from key "+key+" (ignoring)");
- return new BasicConfigKey<T>(key.getTypeToken(), newName, key.getDescription(), key.getDefaultValue());
- }
-
-
- public static BrooklynProperties loadFromFile(String file) {
- BrooklynProperties result = BrooklynProperties.Factory.newEmpty();
- if (file!=null) result.addFrom(new File(file));
- return result;
- }
-
- public static BrooklynProperties filterFor(BrooklynProperties properties, Predicate<? super String> filter) {
- BrooklynProperties result = BrooklynProperties.Factory.newEmpty();
- for (String k: (Collection<String>)properties.keySet()) {
- if (filter.apply(k)) {
- result.put(k, properties.get(k));
- }
- }
- return result;
- }
-
- public static BrooklynProperties filterForPrefix(BrooklynProperties properties, String prefix) {
- BrooklynProperties result = BrooklynProperties.Factory.newEmpty();
- for (String k: (Collection<String>)properties.keySet()) {
- if (k.startsWith(prefix)) {
- result.put(k, properties.get(k));
- }
- }
- return result;
- }
-
- /** prefix generally ends with a full stop */
- public static BrooklynProperties filterForPrefixAndStrip(Map<String,?> properties, String prefix) {
- BrooklynProperties result = BrooklynProperties.Factory.newEmpty();
- for (String k: properties.keySet()) {
- if (k.startsWith(prefix)) {
- result.put(k.substring(prefix.length()), properties.get(k));
- }
- }
- return result;
- }
-
- @SuppressWarnings("rawtypes")
- public static Set<HasConfigKey<?>> getStaticKeysOnClass(Class<?> type) {
- Set<HasConfigKey<?>> result = new LinkedHashSet<ConfigKey.HasConfigKey<?>>();
- for (Field f: type.getFields()) {
- try {
- if ((f.getModifiers() & Modifier.STATIC)==0)
- continue;
- if (ConfigKey.class.isAssignableFrom(f.getType()))
- result.add(new WrappedConfigKey((ConfigKey<?>) f.get(null)));
- else if (HasConfigKey.class.isAssignableFrom(f.getType()))
- result.add((HasConfigKey<?>) f.get(null));
- } catch (Exception e) {
- log.error("Error retrieving config key for field "+f+" on class "+type+"; rethrowing", e);
- throw Exceptions.propagate(e);
- }
- }
- return Collections.unmodifiableSet(result);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/68240194/core/src/main/java/brooklyn/config/WrappedConfigKey.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/config/WrappedConfigKey.java b/core/src/main/java/brooklyn/config/WrappedConfigKey.java
deleted file mode 100644
index 452d912..0000000
--- a/core/src/main/java/brooklyn/config/WrappedConfigKey.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package brooklyn.config;
-
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.config.ConfigKey.HasConfigKey;
-
-import com.google.common.base.Preconditions;
-
-public class WrappedConfigKey<T> implements HasConfigKey<T> {
-
- private final ConfigKey<T> key;
-
- public WrappedConfigKey(ConfigKey<T> key) {
- this.key = Preconditions.checkNotNull(key);
- }
-
- @Override
- public ConfigKey<T> getConfigKey() {
- return key;
- }
-
- @Override
- public String toString() {
- return key.toString()+"(wrapped)";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/68240194/core/src/main/java/brooklyn/config/internal/AbstractConfigMapImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/config/internal/AbstractConfigMapImpl.java b/core/src/main/java/brooklyn/config/internal/AbstractConfigMapImpl.java
deleted file mode 100644
index bb6d910..0000000
--- a/core/src/main/java/brooklyn/config/internal/AbstractConfigMapImpl.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package brooklyn.config.internal;
-
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.concurrent.Future;
-
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.config.ConfigMap;
-import org.apache.brooklyn.config.ConfigKey.HasConfigKey;
-import org.apache.brooklyn.core.util.flags.TypeCoercions;
-import org.apache.brooklyn.core.util.task.DeferredSupplier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import brooklyn.entity.basic.ConfigMapViewWithStringKeys;
-import brooklyn.event.basic.StructuredConfigKey;
-
-public abstract class AbstractConfigMapImpl implements ConfigMap {
-
- private static final Logger LOG = LoggerFactory.getLogger(AbstractConfigMapImpl.class);
-
- protected final ConfigMapViewWithStringKeys mapViewWithStringKeys = new ConfigMapViewWithStringKeys(this);
-
- /**
- * Map of configuration information that is defined at start-up time for the entity. These
- * configuration parameters are shared and made accessible to the "children" of this
- * entity.
- */
- protected Map<ConfigKey<?>,Object> ownConfig = Collections.synchronizedMap(new LinkedHashMap<ConfigKey<?>, Object>());
-
- public <T> T getConfig(ConfigKey<T> key) {
- return getConfig(key, null);
- }
-
- public <T> T getConfig(HasConfigKey<T> key) {
- return getConfig(key.getConfigKey(), null);
- }
-
- public <T> T getConfig(HasConfigKey<T> key, T defaultValue) {
- return getConfig(key.getConfigKey(), defaultValue);
- }
-
- @Override @Deprecated
- public Object getRawConfig(ConfigKey<?> key) {
- return getConfigRaw(key, true).orNull();
- }
-
- protected Object coerceConfigVal(ConfigKey<?> key, Object v) {
- Object val;
- if ((v instanceof Future) || (v instanceof DeferredSupplier)) {
- // no coercion for these (coerce on exit)
- val = v;
- } else if (key instanceof StructuredConfigKey) {
- // no coercion for these structures (they decide what to do)
- val = v;
- } else if ((v instanceof Map || v instanceof Iterable) && key.getType().isInstance(v)) {
- // don't do coercion on put for these, if the key type is compatible,
- // because that will force resolution deeply
- val = v;
- } else {
- try {
- // try to coerce on input, to detect errors sooner
- val = TypeCoercions.coerce(v, key.getTypeToken());
- } catch (Exception e) {
- throw new IllegalArgumentException("Cannot coerce or set "+v+" to "+key, e);
- // if can't coerce, we could just log as below and *throw* the error when we retrieve the config
- // but for now, fail fast (above), because we haven't encountered strong use cases
- // where we want to do coercion on retrieval, except for the exceptions above
-// Exceptions.propagateIfFatal(e);
-// LOG.warn("Cannot coerce or set "+v+" to "+key+" (ignoring): "+e, e);
-// val = v;
- }
- }
- return val;
- }
-
-
- @Override
- public Map<String,Object> asMapWithStringKeys() {
- return mapViewWithStringKeys;
- }
-
- @Override
- public int size() {
- return ownConfig.size();
- }
-
- @Override
- public boolean isEmpty() {
- return ownConfig.isEmpty();
- }
-}