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:27 UTC
[04/28] incubator-brooklyn git commit: Initial types for external
config suppliers, and registry of same.
Initial types for external config suppliers, and registry of same.
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/36787a1c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/36787a1c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/36787a1c
Branch: refs/heads/master
Commit: 36787a1c3c1e3625a8292e20f7d0b38dc3b34e05
Parents: 6fe9fc7
Author: Alasdair Hodge <gi...@alasdairhodge.co.uk>
Authored: Mon Jun 22 16:20:46 2015 +0100
Committer: Alasdair Hodge <gi...@alasdairhodge.co.uk>
Committed: Tue Aug 25 11:49:23 2015 +0100
----------------------------------------------------------------------
.../AbstractExternalConfigSupplier.java | 37 +++++++++++
.../config/external/ExternalConfigSupplier.java | 34 ++++++++++
.../BasicExternalConfigSupplierRegistry.java | 69 ++++++++++++++++++++
.../ExternalConfigSupplierRegistry.java | 45 +++++++++++++
4 files changed, 185 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/36787a1c/core/src/main/java/brooklyn/config/external/AbstractExternalConfigSupplier.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/config/external/AbstractExternalConfigSupplier.java b/core/src/main/java/brooklyn/config/external/AbstractExternalConfigSupplier.java
new file mode 100644
index 0000000..6aa6967
--- /dev/null
+++ b/core/src/main/java/brooklyn/config/external/AbstractExternalConfigSupplier.java
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+
+/**
+ * Default superclass for all {@link ExternalConfigSupplier} implementations.
+ */
+abstract public class AbstractExternalConfigSupplier implements ExternalConfigSupplier {
+
+ private final String name;
+
+ protected AbstractExternalConfigSupplier(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/36787a1c/core/src/main/java/brooklyn/config/external/ExternalConfigSupplier.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/config/external/ExternalConfigSupplier.java b/core/src/main/java/brooklyn/config/external/ExternalConfigSupplier.java
new file mode 100644
index 0000000..0df7917
--- /dev/null
+++ b/core/src/main/java/brooklyn/config/external/ExternalConfigSupplier.java
@@ -0,0 +1,34 @@
+/*
+ * 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 com.google.common.annotations.Beta;
+
+/**
+ * Provider of "externalised" entity configuration that is resolved at runtime.
+ *
+ * @since 0.8.0
+ */
+@Beta
+public interface ExternalConfigSupplier {
+
+ String getName();
+ String get(String key);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/36787a1c/core/src/main/java/brooklyn/management/internal/BasicExternalConfigSupplierRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/management/internal/BasicExternalConfigSupplierRegistry.java b/core/src/main/java/brooklyn/management/internal/BasicExternalConfigSupplierRegistry.java
new file mode 100644
index 0000000..605ea11
--- /dev/null
+++ b/core/src/main/java/brooklyn/management/internal/BasicExternalConfigSupplierRegistry.java
@@ -0,0 +1,69 @@
+/*
+ * 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.management.internal;
+
+import java.util.Map;
+
+import brooklyn.config.external.ExternalConfigSupplier;
+
+import com.google.common.collect.Maps;
+
+/**
+ * Simple registry implementation.
+ *
+ * Permits a number of {@link ExternalConfigSupplier} instances to be registered, each with a unique name, for future
+ * (deferred) lookup of configuration values.
+ */
+public class BasicExternalConfigSupplierRegistry implements ExternalConfigSupplierRegistry {
+
+ private final Map<String, ExternalConfigSupplier> providersByName = Maps.newLinkedHashMap();
+ private final Object providersMapMutex = new Object();
+
+ public BasicExternalConfigSupplierRegistry() {
+ }
+
+ @Override
+ public void addProvider(String name, ExternalConfigSupplier supplier) {
+ synchronized (providersMapMutex) {
+ if (providersByName.containsKey(name))
+ throw new IllegalArgumentException("Provider already registered with name '" + name + "'");
+ providersByName.put(name, supplier);
+ }
+ LOG.info("Added external config supplier named '" + name + "': " + supplier);
+ }
+
+ @Override
+ public void removeProvider(String name) {
+ synchronized (providersMapMutex) {
+ ExternalConfigSupplier supplier = providersByName.remove(name);
+ LOG.info("Removed external config supplier named '" + name + "': " + supplier);
+ }
+ }
+
+ @Override
+ public String getConfig(String providerName, String key) {
+ synchronized (providersMapMutex) {
+ ExternalConfigSupplier provider = providersByName.get(providerName);
+ if (provider == null)
+ throw new IllegalArgumentException("No provider found with name '" + providerName + "'");
+ return provider.get(key);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/36787a1c/core/src/main/java/brooklyn/management/internal/ExternalConfigSupplierRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/management/internal/ExternalConfigSupplierRegistry.java b/core/src/main/java/brooklyn/management/internal/ExternalConfigSupplierRegistry.java
new file mode 100644
index 0000000..66eb127
--- /dev/null
+++ b/core/src/main/java/brooklyn/management/internal/ExternalConfigSupplierRegistry.java
@@ -0,0 +1,45 @@
+/*
+ * 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.management.internal;
+
+import com.google.common.annotations.Beta;
+
+import brooklyn.config.external.ExternalConfigSupplier;
+
+
+/**
+ * Permits a number of {@link ExternalConfigSupplier} instances to be registered, each with a unique name, for future
+ * (deferred) lookup of configuration values.
+ *
+ * @since 0.8.0
+ */
+@Beta
+public interface ExternalConfigSupplierRegistry {
+
+ void addProvider(String name, ExternalConfigSupplier provider);
+ void removeProvider(String name);
+
+ /**
+ * Searches the named {@link ExternalConfigSupplier} for the config value associated with the specified key.
+ * Quietly returns <code>null</code> if no config exists for the specified key.
+ * Throws {@link IllegalArgumentException} if no {@link ExternalConfigSupplier} exists for the passed name.
+ */
+ public String getConfig(String providerName, String key);
+
+}