You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2015/09/01 17:16:30 UTC
[07/28] incubator-brooklyn git commit: Added basic concrete
ExternalConfigSupplier implementations.
Added basic concrete ExternalConfigSupplier implementations.
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/b8eb3c74
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/b8eb3c74
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/b8eb3c74
Branch: refs/heads/master
Commit: b8eb3c740b3501bbcce12175a9375731f9195a94
Parents: f9cf496
Author: Alasdair Hodge <gi...@alasdairhodge.co.uk>
Authored: Mon Jun 22 17:33:41 2015 +0100
Committer: Alasdair Hodge <gi...@alasdairhodge.co.uk>
Committed: Tue Aug 25 11:51:20 2015 +0100
----------------------------------------------------------------------
.../external/InPlaceExternalConfigSupplier.java | 49 ++++++++++++++
.../PropertiesFileExternalConfigSupplier.java | 67 ++++++++++++++++++++
2 files changed, 116 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b8eb3c74/core/src/main/java/brooklyn/config/external/InPlaceExternalConfigSupplier.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/config/external/InPlaceExternalConfigSupplier.java b/core/src/main/java/brooklyn/config/external/InPlaceExternalConfigSupplier.java
new file mode 100644
index 0000000..2279386
--- /dev/null
+++ b/core/src/main/java/brooklyn/config/external/InPlaceExternalConfigSupplier.java
@@ -0,0 +1,49 @@
+/*
+ * 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.external;
+
+import java.util.Map;
+
+
+/**
+ * Instances are populated via sub-keys specified directly in the <tt>brooklyn.properties</tt> file:
+ *
+ * <pre>
+ * brooklyn.external.foo = brooklyn.management.config.external.InPlaceConfigSupplier
+ * brooklyn.external.foo.key1 = value1
+ * brooklyn.external.foo.key2 = value2
+ * </pre>
+ *
+ * This will instantiate an <code>InPlaceExternalConfigSupplier</code> populated with values for <code>key1</code>
+ * and <code>key2</code>. Note that the <code>brooklyn.external.<name></code> prefix is stripped.
+ */
+public class InPlaceExternalConfigSupplier extends AbstractExternalConfigSupplier {
+
+ private final Map<?,?> config;
+
+ public InPlaceExternalConfigSupplier(String name, Map<?, ?> config) {
+ super(name);
+ this.config = config;
+ }
+
+ public String get(String key) {
+ return (String) config.get(key);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b8eb3c74/core/src/main/java/brooklyn/config/external/PropertiesFileExternalConfigSupplier.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/config/external/PropertiesFileExternalConfigSupplier.java b/core/src/main/java/brooklyn/config/external/PropertiesFileExternalConfigSupplier.java
new file mode 100644
index 0000000..a4d48d9
--- /dev/null
+++ b/core/src/main/java/brooklyn/config/external/PropertiesFileExternalConfigSupplier.java
@@ -0,0 +1,67 @@
+/*
+ * 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.external;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Map;
+import java.util.Properties;
+
+import brooklyn.util.stream.Streams;
+
+
+/**
+ * Instances are populated from a plain java properties file named in the passed <code>config</code> map
+ * under the <code>propertiesUrl</code> key:
+ *
+ * <pre>
+ * brooklyn.external.foo = brooklyn.management.config.external.PropertiesFileExternalConfigSupplier
+ * brooklyn.external.foo.propertiesUrl = http://brooklyn.example.com/config/foo.properties
+ * </pre>
+ */
+public class PropertiesFileExternalConfigSupplier extends AbstractExternalConfigSupplier {
+
+ public static final String PROPERTIES_URL = "propertiesUrl";
+
+ private final Properties properties;
+
+ public PropertiesFileExternalConfigSupplier(String name, Map<?, ?> config) throws IOException {
+ super(name);
+ this.properties = loadProperties((String) config.get(PROPERTIES_URL));
+ }
+
+ public String get(String key) {
+ return properties.getProperty(key);
+ }
+
+ private static Properties loadProperties(String propertiesUrl) throws IOException {
+ InputStream is = null;
+ try {
+ is = new URL(propertiesUrl).openStream();
+ Properties p = new Properties();
+ p.load(is);
+ return p;
+
+ } finally {
+ Streams.closeQuietly(is);
+ }
+ }
+
+}