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 <[email protected]> Authored: Wed Jul 27 21:00:58 2016 +0100 Committer: Andrew Donald Kennedy <[email protected]> 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); }
