brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From geom...@apache.org
Subject [1/3] brooklyn-server git commit: Defers reading of config in SshCommandSensor
Date Thu, 19 Apr 2018 12:51:26 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 30ce7faea -> 9a13fff41


Defers reading of config in SshCommandSensor

This allows DSL to be used in the command, env and execution dir as
a management context will then be available


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

Branch: refs/heads/master
Commit: ea59dee2e111f823cf870fc1eb891d90bb5ed0e3
Parents: 12e6b00
Author: Martin Harris <github@nakomis.com>
Authored: Wed Apr 11 13:02:27 2018 +0100
Committer: Martin Harris <github@nakomis.com>
Committed: Tue Apr 17 17:17:46 2018 +0100

----------------------------------------------------------------------
 .../brooklyn/core/sensor/ssh/SshCommandSensor.java     | 13 ++++---------
 .../org/apache/brooklyn/feed/CommandPollConfig.java    |  8 +++++---
 2 files changed, 9 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ea59dee2/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 84b7322..27a7d9f 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
@@ -72,17 +72,9 @@ public final class SshCommandSensor<T> extends AbstractAddSensorFeed<T>
{
         + "use '~' to always execute in the home dir, or 'custom-feed/' to execute in a custom-feed
dir relative to the run dir");
     public static final MapConfigKey<Object> SENSOR_SHELL_ENVIRONMENT = BrooklynConfigKeys.SHELL_ENVIRONMENT;
 
-    protected final String command;
-    protected final String executionDir;
-    protected final Map<String,Object> sensorEnv;
 
     public SshCommandSensor(final ConfigBag params) {
         super(params);
-
-        // TODO create a supplier for the command string to support attribute embedding
-        command = Preconditions.checkNotNull(params.get(SENSOR_COMMAND), "SSH command must
be supplied when defining this sensor");
-        executionDir = params.get(SENSOR_EXECUTION_DIR);
-        sensorEnv = params.get(SENSOR_SHELL_ENVIRONMENT);
     }
 
     @Override
@@ -105,6 +97,7 @@ public final class SshCommandSensor<T> extends AbstractAddSensorFeed<T>
{
                 Map<String, Object> env = MutableMap.copyOf(entity.getConfig(BrooklynConfigKeys.SHELL_ENVIRONMENT));
 
                 // Add the shell environment entries from our configuration
+                Map<String,Object> sensorEnv = params.get(SENSOR_SHELL_ENVIRONMENT);
                 if (sensorEnv != null) env.putAll(sensorEnv);
 
                 // Try to resolve the configuration in the env Map
@@ -126,7 +119,9 @@ public final class SshCommandSensor<T> extends AbstractAddSensorFeed<T>
{
                 // Note that entity may be null during rebind (e.g. if this SshFeed is orphaned,
with no associated entity):
                 // See https://issues.apache.org/jira/browse/BROOKLYN-568.
                 // We therefore guard against null in makeCommandExecutingInDirectory.
-                return makeCommandExecutingInDirectory(command, executionDir, entity);
+                String command = Preconditions.checkNotNull(EntityInitializers.resolve(params,
SENSOR_COMMAND));
+                String dir = EntityInitializers.resolve(params, SENSOR_EXECUTION_DIR);
+                return makeCommandExecutingInDirectory(command, dir, entity);
             }
         };
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ea59dee2/core/src/main/java/org/apache/brooklyn/feed/CommandPollConfig.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/feed/CommandPollConfig.java b/core/src/main/java/org/apache/brooklyn/feed/CommandPollConfig.java
index 6da0985..84c26e4 100644
--- a/core/src/main/java/org/apache/brooklyn/feed/CommandPollConfig.java
+++ b/core/src/main/java/org/apache/brooklyn/feed/CommandPollConfig.java
@@ -167,13 +167,15 @@ public class CommandPollConfig<T> extends PollConfig<SshPollValue,
T, CommandPol
     @Override protected String toStringBaseName() { return "ssh"; }
     @Override protected Object toStringPollSource() {
         if (getCommandSupplier()==null) return null;
-        String command = getCommandSupplier().get();
+        // Cannot call .get() as we may not yet have an execution context for resolving DSL
+        String command = getCommandSupplier().toString();
         return command;
     }
     @Override protected MutableList<Object> equalsFields() { 
         return super.equalsFields()
-            .appendIfNotNull(getCommandSupplier()!=null ? getCommandSupplier().get() : null)
-            .appendIfNotNull(getEnvSupplier()!=null ? getEnvSupplier().get() : null); 
+            // Cannot call .get() as we may not yet have an execution context for resolving
DSL
+            .appendIfNotNull(getCommandSupplier()!=null ? getCommandSupplier() : null)
+            .appendIfNotNull(getEnvSupplier()!=null ? getEnvSupplier() : null);
     }
     
 }


Mime
View raw message