You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2016/07/27 20:18:25 UTC

[1/2] brooklyn-server git commit: Resolve all environment variables before serializing in SSH command sensor and effector

Repository: brooklyn-server
Updated Branches:
  refs/heads/master e91b6c5c9 -> e9d84bfcb


Resolve all environment variables before serializing in SSH command sensor and effector


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/576801cb
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/576801cb
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/576801cb

Branch: refs/heads/master
Commit: 576801cb59343b019a4ca81d761cbde64671c5da
Parents: e91b6c5
Author: Andrew Donald Kennedy <an...@cloudsoftcorp.com>
Authored: Wed Jul 27 21:00:58 2016 +0100
Committer: Andrew Donald Kennedy <an...@cloudsoftcorp.com>
Committed: Wed Jul 27 21:00:58 2016 +0100

----------------------------------------------------------------------
 .../core/effector/ssh/SshCommandEffector.java   | 39 ++++++++++----------
 .../core/sensor/ssh/SshCommandSensor.java       | 11 +++---
 2 files changed, 26 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/576801cb/core/src/main/java/org/apache/brooklyn/core/effector/ssh/SshCommandEffector.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/effector/ssh/SshCommandEffector.java b/core/src/main/java/org/apache/brooklyn/core/effector/ssh/SshCommandEffector.java
index 6f53c08..957d68e 100644
--- a/core/src/main/java/org/apache/brooklyn/core/effector/ssh/SshCommandEffector.java
+++ b/core/src/main/java/org/apache/brooklyn/core/effector/ssh/SshCommandEffector.java
@@ -79,37 +79,38 @@ public final class SshCommandEffector extends AddEffector {
 
             MutableMap<String, Object> env = MutableMap.of();
 
-            // first set all declared parameters, including default values,
+            // Set all declared parameters, including default values
             for (ParameterType<?> param : effector.getParameters()) {
                 env.addIfNotNull(param.getName(), params.get(Effectors.asConfigKey(param)));
             }
 
-            // then set things from the entities defined shell environment, if applicable
-            env.putAll(entity().getConfig(BrooklynConfigKeys.SHELL_ENVIRONMENT));
+            // Set things from the entities defined shell environment, if applicable
+            env.putAll(entity().config().get(BrooklynConfigKeys.SHELL_ENVIRONMENT));
 
-            // now add the resolved shell environment entries from our configuration
-            try {
-                Map<String, Object> effectorEnv = params.get(EFFECTOR_SHELL_ENVIRONMENT);
-                if (effectorEnv != null && effectorEnv.size() > 0) {
-                    Map<String, Object> effectorEnvResolved = (Map<String, Object>) Tasks.resolveDeepValue(effectorEnv, Object.class, entity().getExecutionContext());
-                    env.putAll(effectorEnvResolved);
-                }
-            } catch (InterruptedException | ExecutionException e) {
-                Exceptions.propagateIfFatal(e);
-            }
+            // Add the shell environment entries from our configuration
+            Map<String, Object> effectorEnv = params.get(EFFECTOR_SHELL_ENVIRONMENT);
+            if (effectorEnv != null) env.putAll(effectorEnv);
 
-            // Finally set the parameters we've been passed. This will repeat declared parameters but to no harm,
+            // Set the parameters we've been passed. This will repeat declared parameters but to no harm,
             // it may pick up additional values (could be a flag defining whether this is permitted or not.)
             // Make sure we do not include the shell.env here again, by filtering it out.
             env.putAll(Maps.filterKeys(params.getAllConfig(), Predicates.not(Predicates.equalTo(EFFECTOR_SHELL_ENVIRONMENT.getName()))));
 
+            // Try to resolve the configuration in the env Map
+            try {
+                env = (MutableMap<String, Object>) Tasks.resolveDeepValue(env, Object.class, entity().getExecutionContext());
+            } catch (InterruptedException | ExecutionException e) {
+                Exceptions.propagateIfFatal(e);
+            }
+
+            // Execute the effector with the serialized environment strings
             ShellEnvironmentSerializer serializer = new ShellEnvironmentSerializer(entity().getManagementContext());
-            SshEffectorTasks.SshEffectorTaskFactory<String> t = SshEffectorTasks.ssh(sshCommand)
-                .requiringZeroAndReturningStdout()
-                .summary("effector "+effector.getName())
-                .environmentVariables(serializer.serialize(env));
+            SshEffectorTasks.SshEffectorTaskFactory<String> task = SshEffectorTasks.ssh(sshCommand)
+                    .requiringZeroAndReturningStdout()
+                    .summary("effector "+effector.getName())
+                    .environmentVariables(serializer.serialize(env));
 
-            return queue(t).get();
+            return queue(task).get();
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/576801cb/core/src/main/java/org/apache/brooklyn/core/sensor/ssh/SshCommandSensor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/sensor/ssh/SshCommandSensor.java b/core/src/main/java/org/apache/brooklyn/core/sensor/ssh/SshCommandSensor.java
index 739bbaf..8b1d410 100644
--- a/core/src/main/java/org/apache/brooklyn/core/sensor/ssh/SshCommandSensor.java
+++ b/core/src/main/java/org/apache/brooklyn/core/sensor/ssh/SshCommandSensor.java
@@ -95,16 +95,17 @@ public final class SshCommandSensor<T> extends AddSensor<T> {
             public Map<String, String> get() {
                 Map<String, Object> env = MutableMap.copyOf(entity.getConfig(BrooklynConfigKeys.SHELL_ENVIRONMENT));
 
-                // now add the resolved shell environment entries from our configuration
+                // Add the shell environment entries from our configuration
+                if (sensorEnv != null) env.putAll(sensorEnv);
+
+                // Try to resolve the configuration in the env Map
                 try {
-                    if (sensorEnv != null && sensorEnv.size() > 0) {
-                        Map<String,Object> sensorEnvResolved = (Map<String, Object>) Tasks.resolveDeepValue(sensorEnv, Object.class, ((EntityInternal) entity).getExecutionContext());
-                        env.putAll(sensorEnvResolved);
-                    }
+                    env = (Map<String, Object>) Tasks.resolveDeepValue(env, Object.class, ((EntityInternal) entity).getExecutionContext());
                 } catch (InterruptedException | ExecutionException e) {
                     Exceptions.propagateIfFatal(e);
                 }
 
+                // Convert the environment into strings with the serializer
                 ShellEnvironmentSerializer serializer = new ShellEnvironmentSerializer(((EntityInternal) entity).getManagementContext());
                 return serializer.serialize(env);
             }


[2/2] brooklyn-server git commit: Closes #275

Posted by sv...@apache.org.
Closes #275

Resolve all environment variables

Use the config resolver on the complete environment map before serializing to strings in SSH command sensor and effector.


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/e9d84bfc
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/e9d84bfc
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/e9d84bfc

Branch: refs/heads/master
Commit: e9d84bfcb11ca2a1b586f4f1ef84e0d78fb2cbcb
Parents: e91b6c5 576801c
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Wed Jul 27 22:18:16 2016 +0200
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Wed Jul 27 22:18:16 2016 +0200

----------------------------------------------------------------------
 .../core/effector/ssh/SshCommandEffector.java   | 39 ++++++++++----------
 .../core/sensor/ssh/SshCommandSensor.java       | 11 +++---
 2 files changed, 26 insertions(+), 24 deletions(-)
----------------------------------------------------------------------