brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [5/6] brooklyn-server git commit: SshCommandEffector resolves shell.env against the target entity
Date Thu, 10 Nov 2016 14:20:45 GMT
SshCommandEffector resolves shell.env against the target entity

Rather than always resolving it against the entity the effector is
attached to. This also fixes the resolution of the execution directory.


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

Branch: refs/heads/master
Commit: c256fa97014b2515cf54486b77b2a8f8c3645e14
Parents: e01a4ef
Author: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Authored: Wed Nov 9 15:26:18 2016 +0000
Committer: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Committed: Thu Nov 10 10:31:42 2016 +0000

----------------------------------------------------------------------
 .../core/effector/ssh/SshCommandEffector.java    | 19 ++++++++++---------
 .../core/sensor/ssh/SshCommandSensor.java        |  3 ++-
 2 files changed, 12 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c256fa97/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 8d7ca13..2df5094 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
@@ -59,11 +59,12 @@ public final class SshCommandEffector extends AddEffector {
     public static final ConfigKey<String> EFFECTOR_EXECUTION_DIR = SshCommandSensor.SENSOR_EXECUTION_DIR;
     public static final MapConfigKey<Object> EFFECTOR_SHELL_ENVIRONMENT = BrooklynConfigKeys.SHELL_ENVIRONMENT;
 
-    public static enum ExecutionTarget {
+    public enum ExecutionTarget {
         ENTITY,
         MEMBERS,
         CHILDREN
     }
+
     public static final ConfigKey<ExecutionTarget> EXECUTION_TARGET = ConfigKeys.newConfigKey(ExecutionTarget.class,
"executionTarget", 
         "Where this command should run; by default on this 'entity'; alternatively on all
'children' or all 'members' (if it's a group); "
         + "in the latter cases the sets are filtered by entities which have a machine and
are not stopping.",
@@ -114,7 +115,7 @@ public final class SshCommandEffector extends AddEffector {
         
         public String callOne(ConfigBag params) {
             return queue(
-                makePartialTaskFactory(params)
+                makePartialTaskFactory(params, entity())
                     .summary("effector "+effector.getName()+" ssh call")
                 ).get();
         }
@@ -129,7 +130,7 @@ public final class SshCommandEffector extends AddEffector {
                 Maybe<SshMachineLocation> machine = Locations.findUniqueSshMachineLocation(target.getLocations());
                 if (machine.isAbsent()) continue;
                 
-                SshEffectorTaskFactory<String> t = makePartialTaskFactory(params);
+                SshEffectorTaskFactory<String> t = makePartialTaskFactory(params, target);
                 t.summary("effector "+effector.getName()+" at "+target); 
                 t.machine( machine.get() );
                 
@@ -138,9 +139,9 @@ public final class SshCommandEffector extends AddEffector {
             queue(ptb.build()).getUnchecked();
             return null;
         }
-        
-        public SshEffectorTaskFactory<String> makePartialTaskFactory(ConfigBag params)
{
-            String sshCommand = SshCommandSensor.makeCommandExecutingInDirectory(command,
executionDir, entity());
+
+        public SshEffectorTaskFactory<String> makePartialTaskFactory(ConfigBag params,
Entity entity) {
+            String sshCommand = SshCommandSensor.makeCommandExecutingInDirectory(command,
executionDir, entity);
 
             MutableMap<String, Object> env = MutableMap.of();
 
@@ -150,7 +151,7 @@ public final class SshCommandEffector extends AddEffector {
             }
 
             // Set things from the entity's defined shell environment, if applicable
-            env.putAll(entity().config().get(BrooklynConfigKeys.SHELL_ENVIRONMENT));
+            env.putAll(entity.config().get(BrooklynConfigKeys.SHELL_ENVIRONMENT));
 
             // 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.)
@@ -159,7 +160,7 @@ public final class SshCommandEffector extends AddEffector {
 
             // Add the shell environment entries from the effector configuration
             if (shellEnv != null) env.putAll(shellEnv);
-            
+
             // Add the shell environment entries from our invocation
             Map<String, Object> effectorEnv = params.get(EFFECTOR_SHELL_ENVIRONMENT);
             if (effectorEnv != null) env.putAll(effectorEnv);
@@ -173,7 +174,7 @@ public final class SshCommandEffector extends AddEffector {
 
             // Execute the effector with the serialized environment strings
             ShellEnvironmentSerializer serializer = new ShellEnvironmentSerializer(entity().getManagementContext());
-            
+
             return SshEffectorTasks.ssh(sshCommand)
                     .requiringZeroAndReturningStdout()
                     .environmentVariables(serializer.serialize(env));

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c256fa97/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 8b1d410..24bc2d4 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
@@ -21,6 +21,7 @@ package org.apache.brooklyn.core.sensor.ssh;
 import java.util.Map;
 import java.util.concurrent.ExecutionException;
 
+import org.apache.brooklyn.api.entity.Entity;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -138,7 +139,7 @@ public final class SshCommandSensor<T> extends AddSensor<T>
{
     }
 
     @Beta
-    public static String makeCommandExecutingInDirectory(String command, String executionDir,
EntityLocal entity) {
+    public static String makeCommandExecutingInDirectory(String command, String executionDir,
Entity entity) {
         String finalCommand = command;
         String execDir = executionDir;
         if (Strings.isBlank(execDir)) {


Mime
View raw message