summaryrefslogtreecommitdiffstats
path: root/plugins/plugins-executor
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/plugins-executor')
-rw-r--r--plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskExecutor.java47
-rw-r--r--plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskSelectExecutor.java50
2 files changed, 61 insertions, 36 deletions
diff --git a/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskExecutor.java b/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskExecutor.java
index 39ca0dc43..bddb63b42 100644
--- a/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskExecutor.java
+++ b/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskExecutor.java
@@ -100,23 +100,7 @@ public class JythonTaskExecutor extends TaskExecutor {
// Set up the Jython engine
interpreter.set("executor", getExecutionContext());
interpreter.exec(compiled);
- try {
- final Object ret = interpreter.get("returnValue", java.lang.Boolean.class);
- if (ret == null) {
- LOGGER.error("execute: task logic failed to set a return value for task \""
- + getSubject().getKey().getId() + "\"");
- throw new StateMachineException("execute: task logic failed to set a return value for task \""
- + getSubject().getKey().getId() + "\"");
- }
- returnValue = (Boolean) ret;
- } catch (NullPointerException | ClassCastException e) {
- LOGGER.error("execute: task selection logic failed to set a correct return value for state \""
- + getSubject().getKey().getId() + "\"", e);
- throw new StateMachineException(
- "execute: task selection logic failed to set a return value for state \""
- + getSubject().getKey().getId() + "\"",
- e);
- }
+ returnValue = handleInterpreterResult();
}
/* */
} catch (final Exception e) {
@@ -137,6 +121,35 @@ public class JythonTaskExecutor extends TaskExecutor {
}
/**
+ * Handle the result returned by the interpreter.
+ *
+ * @return true if the result was successful
+ * @throws StateMachineException on interpreter failures
+ */
+ private boolean handleInterpreterResult() throws StateMachineException {
+ boolean returnValue = false;
+
+ try {
+ final Object ret = interpreter.get("returnValue", java.lang.Boolean.class);
+ if (ret == null) {
+ LOGGER.error("execute: task logic failed to set a return value for task \""
+ + getSubject().getKey().getId() + "\"");
+ throw new StateMachineException("execute: task logic failed to set a return value for task \""
+ + getSubject().getKey().getId() + "\"");
+ }
+ returnValue = (Boolean) ret;
+ } catch (NullPointerException | ClassCastException e) {
+ LOGGER.error("execute: task selection logic failed to set a correct return value for state \""
+ + getSubject().getKey().getId() + "\"", e);
+ throw new StateMachineException(
+ "execute: task selection logic failed to set a return value for state \""
+ + getSubject().getKey().getId() + "\"",
+ e);
+ }
+ return returnValue;
+ }
+
+ /**
* Cleans up the task after processing.
*
* @throws StateMachineException thrown when a state machine execution error occurs
diff --git a/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskSelectExecutor.java b/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskSelectExecutor.java
index 3ff061fa4..9a2433122 100644
--- a/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskSelectExecutor.java
+++ b/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskSelectExecutor.java
@@ -103,25 +103,7 @@ public class JythonTaskSelectExecutor extends TaskSelectExecutor {
// Set up the Jython engine
interpreter.set("executor", getExecutionContext());
interpreter.exec(compiled);
-
- try {
- final Object ret = interpreter.get("returnValue", java.lang.Boolean.class);
- if (ret == null) {
- LOGGER.error(TSL_FAILED_PREFIX
- + getSubject().getKey().getId() + "\"");
- throw new StateMachineException(
- TSL_FAILED_PREFIX
- + getSubject().getKey().getId() + "\"");
- }
- returnValue = (Boolean) ret;
- } catch (NullPointerException | ClassCastException e) {
- LOGGER.error("execute: task selection logic failed to set a correct return value for state \""
- + getSubject().getKey().getId() + "\"", e);
- throw new StateMachineException(
- TSL_FAILED_PREFIX
- + getSubject().getKey().getId() + "\"",
- e);
- }
+ returnValue = handleInterpreterResult();
}
/* */
} catch (final Exception e) {
@@ -143,6 +125,36 @@ public class JythonTaskSelectExecutor extends TaskSelectExecutor {
}
/**
+ * Handle the result returned by the interpreter.
+ *
+ * @return true if the result was successful
+ * @throws StateMachineException on interpreter errors
+ */
+ private boolean handleInterpreterResult() throws StateMachineException {
+ boolean returnValue = false;
+
+ try {
+ final Object ret = interpreter.get("returnValue", java.lang.Boolean.class);
+ if (ret == null) {
+ LOGGER.error(TSL_FAILED_PREFIX
+ + getSubject().getKey().getId() + "\"");
+ throw new StateMachineException(
+ TSL_FAILED_PREFIX
+ + getSubject().getKey().getId() + "\"");
+ }
+ returnValue = (Boolean) ret;
+ } catch (NullPointerException | ClassCastException e) {
+ LOGGER.error("execute: task selection logic failed to set a correct return value for state \""
+ + getSubject().getKey().getId() + "\"", e);
+ throw new StateMachineException(
+ TSL_FAILED_PREFIX
+ + getSubject().getKey().getId() + "\"",
+ e);
+ }
+ return returnValue;
+ }
+
+ /**
* Cleans up the task after processing.
*
* @throws StateMachineException thrown when a state machine execution error occurs