You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ge...@apache.org on 2018/04/19 12:51:26 UTC
[1/3] brooklyn-server git commit: Defers reading of config in
SshCommandSensor
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 <gi...@nakomis.com>
Authored: Wed Apr 11 13:02:27 2018 +0100
Committer: Martin Harris <gi...@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);
}
}
[3/3] brooklyn-server git commit: Closes #953
Posted by ge...@apache.org.
Closes #953
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/9a13fff4
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/9a13fff4
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/9a13fff4
Branch: refs/heads/master
Commit: 9a13fff41de47001d3de5fa9cb0ae8b2e8aad4b7
Parents: 30ce7fa 4e5dfc3
Author: Geoff Macartney <ge...@cloudsoftcorp.com>
Authored: Thu Apr 19 13:51:15 2018 +0100
Committer: Geoff Macartney <ge...@cloudsoftcorp.com>
Committed: Thu Apr 19 13:51:15 2018 +0100
----------------------------------------------------------------------
.../camp/brooklyn/SshCommandSensorYamlTest.java | 41 +++++++++++++++++++-
.../core/sensor/ssh/SshCommandSensor.java | 13 ++-----
.../apache/brooklyn/feed/CommandPollConfig.java | 8 ++--
3 files changed, 49 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9a13fff4/core/src/main/java/org/apache/brooklyn/core/sensor/ssh/SshCommandSensor.java
----------------------------------------------------------------------
diff --cc core/src/main/java/org/apache/brooklyn/core/sensor/ssh/SshCommandSensor.java
index 6224ed3,27a7d9f..5ec9d22
--- 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
@@@ -70,13 -70,8 +70,10 @@@ public final class SshCommandSensor<T>
public static final ConfigKey<String> SENSOR_EXECUTION_DIR = ConfigKeys.newStringConfigKey("executionDir", "Directory where the command should run; "
+ "if not supplied, executes in the entity's run dir (or home dir if no run dir is defined); "
+ "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 ConfigKey<Object> VALUE_ON_ERROR = ConfigKeys.newConfigKey(Object.class, "value.on.error",
+ "Value to be used if an error occurs whilst executing the ssh command", null);
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);
[2/3] brooklyn-server git commit: Adds test for SshcommandSensor DSL
resolution
Posted by ge...@apache.org.
Adds test for SshcommandSensor DSL resolution
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/4e5dfc34
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/4e5dfc34
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/4e5dfc34
Branch: refs/heads/master
Commit: 4e5dfc3418bc362000a760fd48230862cda6c5c2
Parents: ea59dee
Author: Martin Harris <gi...@nakomis.com>
Authored: Tue Apr 17 17:18:11 2018 +0100
Committer: Martin Harris <gi...@nakomis.com>
Committed: Tue Apr 17 17:18:11 2018 +0100
----------------------------------------------------------------------
.../camp/brooklyn/SshCommandSensorYamlTest.java | 41 +++++++++++++++++++-
1 file changed, 40 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4e5dfc34/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/SshCommandSensorYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/SshCommandSensorYamlTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/SshCommandSensorYamlTest.java
index 09c99ac..1efc04c 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/SshCommandSensorYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/SshCommandSensorYamlTest.java
@@ -110,7 +110,46 @@ public class SshCommandSensorYamlTest extends AbstractYamlTest {
listener.assertEventCount(1);
}});
}
-
+
+ // "Integration" because takes a couple of seconds
+ @Test(groups="Integration")
+ public void testDslWithSshSensor() throws Exception {
+ AttributeSensor<String> mySensor = Sensors.newStringSensor("mySensor");
+ AttributeSensor<String> sourceSensor = Sensors.newStringSensor("sourceSensor");
+
+ Entity app = createAndStartApplication(
+ "location:",
+ " localhost",
+ "services:",
+ "- type: " + VanillaSoftwareProcess.class.getName(),
+ " brooklyn.config:",
+ " onbox.base.dir.skipResolution: true",
+ " checkRunning.command: true",
+ " brooklyn.initializers:",
+ " - type: org.apache.brooklyn.core.sensor.StaticSensor",
+ " brooklyn.config:",
+ " name: " + sourceSensor.getName(),
+ " sensorType: string",
+ " static.value: someValue",
+ " - type: org.apache.brooklyn.core.sensor.ssh.SshCommandSensor",
+ " brooklyn.config:",
+ " name: " + mySensor.getName(),
+ " command: ",
+ " $brooklyn:formatString:",
+ " - echo %s",
+ " - $brooklyn:attributeWhenReady(\"sourceSensor\")",
+ " suppressDuplicates: true",
+ " period: 10ms",
+ " onlyIfServiceUp: false");
+ waitForApplicationTasks(app);
+
+ VanillaSoftwareProcess entity = (VanillaSoftwareProcess) Iterables.getOnlyElement(app.getChildren());
+ EntityAsserts.assertAttributeEqualsEventually(entity, mySensor, "someValue");
+
+ entity.sensors().set(sourceSensor, "newValue");
+ EntityAsserts.assertAttributeEqualsEventually(entity, mySensor, "someValue");
+ }
+
@Override
protected Logger getLogger() {
return log;