You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2016/02/18 18:29:19 UTC
[1/2] brooklyn-server git commit: Fix external-config for jclouds
credentials
Repository: brooklyn-server
Updated Branches:
refs/heads/master fa19e8f5f -> 8da814a9f
Fix external-config for jclouds credentials
- Adds ResolvingConfigBag, which resolves deferred-supplier on get()
- Use that in jcloudsLocation.getComputeService(ConfigBag)
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/291eb7d2
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/291eb7d2
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/291eb7d2
Branch: refs/heads/master
Commit: 291eb7d2c08fe40b6acd6895a3c126b4455005c0
Parents: a5103bb
Author: Aled Sage <al...@gmail.com>
Authored: Wed Feb 17 14:57:57 2016 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Wed Feb 17 14:57:57 2016 +0000
----------------------------------------------------------------------
.../util/core/config/ResolvingConfigBag.java | 122 +++++++++++++++++++
.../location/jclouds/JcloudsLocation.java | 10 +-
2 files changed, 128 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/291eb7d2/core/src/main/java/org/apache/brooklyn/util/core/config/ResolvingConfigBag.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/config/ResolvingConfigBag.java b/core/src/main/java/org/apache/brooklyn/util/core/config/ResolvingConfigBag.java
new file mode 100644
index 0000000..5c6c3ad
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/util/core/config/ResolvingConfigBag.java
@@ -0,0 +1,122 @@
+/*
+ * 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 org.apache.brooklyn.util.core.config;
+
+import java.util.Map;
+
+import org.apache.brooklyn.api.mgmt.ExecutionContext;
+import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.util.core.task.DeferredSupplier;
+import org.apache.brooklyn.util.core.task.Tasks;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.guava.Maybe;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Function;
+import com.google.common.collect.Maps;
+
+/**
+ * As for {@link ConfigBag}, but resolves values that are of type {@link DeferredSupplier}.
+ */
+@Beta
+public class ResolvingConfigBag extends ConfigBag {
+
+ // Relies on various getters all delegating to a few common methods.
+
+ private final ManagementContext mgmt;
+ protected final ConfigBag parentBag;
+
+ protected transient volatile Function<Object, Object> transformer;
+
+
+ @Beta
+ public static ConfigBag newInstanceExtending(ManagementContext mgmt, ConfigBag parentBag) {
+ return new ResolvingConfigBag(mgmt, parentBag);
+ }
+
+ public ResolvingConfigBag(ManagementContext mgmt, ConfigBag parentBag) {
+ this.mgmt = mgmt;
+ this.parentBag = parentBag;
+ copy(parentBag);
+ }
+
+ protected Function<Object, Object> getTransformer() {
+ if (transformer == null) {
+ transformer = new Function<Object, Object>() {
+ @Override public Object apply(Object input) {
+ if (input instanceof DeferredSupplier<?>) {
+ try {
+ ExecutionContext exec = mgmt.getServerExecutionContext();
+ return Tasks.resolveValue(input, Object.class, exec);
+ } catch (Exception e) {
+ throw Exceptions.propagate(e);
+ }
+ }
+ return input;
+ }
+ };
+ }
+ return transformer;
+ }
+ @Override
+ public void markUsed(String key) {
+ super.markUsed(key);
+ if (parentBag!=null)
+ parentBag.markUsed(key);
+ }
+
+ @Override
+ public Map<String,Object> getAllConfig() {
+ // Lazily transform copy of map
+ return Maps.transformValues(super.getAllConfig(), getTransformer());
+ }
+
+ @Override
+ public Map<ConfigKey<?>, ?> getAllConfigAsConfigKeyMap() {
+ // Lazily transform copy of map
+ return Maps.transformValues(super.getAllConfigAsConfigKeyMap(), getTransformer());
+ }
+
+ @Override
+ public Map<String,Object> getUnusedConfig() {
+ // Lazily transform copy of map
+ return Maps.transformValues(super.getUnusedConfig(), getTransformer());
+ }
+
+ @Override
+ public Map<String,Object> getUnusedConfigMutable() {
+ throw new UnsupportedOperationException();
+ }
+
+ protected synchronized Maybe<Object> getStringKeyMaybe(String key, boolean markUsed) {
+ Maybe<Object> result = super.getStringKeyMaybe(key, markUsed);
+ return (result.isPresent()) ? Maybe.of(getTransformer().apply(result.get())) : result;
+ }
+
+ @Override
+ public Map<String,Object> getAllConfigMutable() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Map<String, Object> getAllConfigRaw() {
+ return getAllConfigMutable();
+ }
+}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/291eb7d2/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
index 4a5cf7a..c244b72 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
@@ -88,6 +88,7 @@ import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.collections.MutableSet;
import org.apache.brooklyn.util.core.ResourceUtils;
import org.apache.brooklyn.util.core.config.ConfigBag;
+import org.apache.brooklyn.util.core.config.ResolvingConfigBag;
import org.apache.brooklyn.util.core.crypto.SecureKeys;
import org.apache.brooklyn.util.core.flags.MethodCoercions;
import org.apache.brooklyn.util.core.flags.SetFromFlag;
@@ -519,7 +520,8 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
}
public ComputeService getComputeService(ConfigBag config) {
- return getConfig(COMPUTE_SERVICE_REGISTRY).findComputeService(config, true);
+ ComputeServiceRegistry registry = getConfig(COMPUTE_SERVICE_REGISTRY);
+ return registry.findComputeService(ResolvingConfigBag.newInstanceExtending(getManagementContext(), config), true);
}
/** @deprecated since 0.7.0 use {@link #listMachines()} */ @Deprecated
@@ -644,7 +646,7 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
JcloudsPortForwarderExtension portForwarder = setup.get(PORT_FORWARDER);
if (usePortForwarding) checkNotNull(portForwarder, "portForwarder, when use-port-forwarding enabled");
- final ComputeService computeService = getConfig(COMPUTE_SERVICE_REGISTRY).findComputeService(setup, true);
+ final ComputeService computeService = getComputeService(setup);
CloudMachineNamer cloudMachineNamer = getCloudMachineNamer(setup);
String groupId = elvis(setup.get(GROUP_ID), cloudMachineNamer.generateNewGroupId(setup));
NodeMetadata node = null;
@@ -1558,7 +1560,7 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
// TODO use key
m1.putStringKey("anyOwner", true);
}
- ComputeService computeServiceLessRestrictive = getConfig(COMPUTE_SERVICE_REGISTRY).findComputeService(m1, true);
+ ComputeService computeServiceLessRestrictive = getComputeService(m1);
Set<? extends Image> imgs = computeServiceLessRestrictive.listImages();
LOG.info(""+imgs.size()+" available images at "+this);
for (Image img: imgs) {
@@ -2439,7 +2441,7 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
protected void releaseNode(String instanceId) {
ComputeService computeService = null;
try {
- computeService = getConfig(COMPUTE_SERVICE_REGISTRY).findComputeService(config().getBag(), true);
+ computeService = getComputeService(config().getBag());
computeService.destroyNode(instanceId);
} finally {
/*
[2/2] brooklyn-server git commit: This closes #29
Posted by al...@apache.org.
This closes #29
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/8da814a9
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/8da814a9
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/8da814a9
Branch: refs/heads/master
Commit: 8da814a9f8c1c6e7849476ff4c0a3513c1b3c9ce
Parents: fa19e8f 291eb7d
Author: Aled Sage <al...@gmail.com>
Authored: Thu Feb 18 17:28:48 2016 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Thu Feb 18 17:28:48 2016 +0000
----------------------------------------------------------------------
.../util/core/config/ResolvingConfigBag.java | 122 +++++++++++++++++++
.../location/jclouds/JcloudsLocation.java | 10 +-
2 files changed, 128 insertions(+), 4 deletions(-)
----------------------------------------------------------------------