From 5a353b6ed41f45e43cb9bdf0ac590dc8c1613124 Mon Sep 17 00:00:00 2001 From: Martin Harris Date: Mon, 16 Apr 2018 12:34:11 +0100 Subject: [PATCH] SSH Sensor value-on-error Adds `value.on.error` config key to SshCommandSensor to allow a value to be specified for use when an exception occurs when executing the ssh command --- .../org/apache/brooklyn/core/sensor/ssh/SshCommandSensor.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 84b7322b2b..6224ed376c 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 @@ -70,6 +70,8 @@ public final class SshCommandSensor extends AbstractAddSensorFeed { public static final ConfigKey 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 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 SENSOR_SHELL_ENVIRONMENT = BrooklynConfigKeys.SHELL_ENVIRONMENT; protected final String command; @@ -136,7 +138,7 @@ public String get() { .command(commandSupplier) .suppressDuplicates(Boolean.TRUE.equals(suppressDuplicates)) .checkSuccess(SshValueFunctions.exitStatusEquals(0)) - .onFailureOrException(Functions.constant((T) null)) + .onFailureOrException(Functions.constant((T)params.get(VALUE_ON_ERROR))) .onSuccess(Functions.compose(new Function() { @Override public T apply(String input) {