diff options
author | liamfallon <liam.fallon@est.tech> | 2019-11-15 13:40:08 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2019-11-15 13:42:11 +0000 |
commit | c54feabfafaab64d56cf275fb1a474f0e830eba9 (patch) | |
tree | e4c47037eac78e0d52436732fc3f6e6158608e38 /plugins/plugins-executor/plugins-executor-jruby/src/main | |
parent | 40a1f22ff8d28e78b6512c0a10d454b37f015fdb (diff) |
Fix JRuby interpreter shutdown issue
The new version of JRuby fixes this issue. Also amended unit test to
check for shutdown and immediate recreation of JRuby interpreter.
Issue-ID: POLICY-1276
Change-Id: I723e0396985d3163b483e52fdaceb4b4fab7274b
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'plugins/plugins-executor/plugins-executor-jruby/src/main')
3 files changed, 32 insertions, 23 deletions
diff --git a/plugins/plugins-executor/plugins-executor-jruby/src/main/java/org/onap/policy/apex/plugins/executor/jruby/JrubyStateFinalizerExecutor.java b/plugins/plugins-executor/plugins-executor-jruby/src/main/java/org/onap/policy/apex/plugins/executor/jruby/JrubyStateFinalizerExecutor.java index d6e9f4d07..28e61b6da 100644 --- a/plugins/plugins-executor/plugins-executor-jruby/src/main/java/org/onap/policy/apex/plugins/executor/jruby/JrubyStateFinalizerExecutor.java +++ b/plugins/plugins-executor/plugins-executor-jruby/src/main/java/org/onap/policy/apex/plugins/executor/jruby/JrubyStateFinalizerExecutor.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,8 +45,8 @@ public class JrubyStateFinalizerExecutor extends StateFinalizerExecutor { private static final XLogger LOGGER = XLoggerFactory.getXLogger(JrubyStateFinalizerExecutor.class); // Jruby container - private ScriptingContainer container = - new ScriptingContainer(LocalContextScope.CONCURRENT, LocalVariableBehavior.TRANSIENT, true); + private ScriptingContainer container = new ScriptingContainer(LocalContextScope.CONCURRENT, + LocalVariableBehavior.TRANSIENT, true); private EmbedEvalUnit parsedjruby = null; /** @@ -60,10 +61,11 @@ public class JrubyStateFinalizerExecutor extends StateFinalizerExecutor { // Set up the JRuby engine container = (container == null) - ? new ScriptingContainer(LocalContextScope.CONCURRENT, LocalVariableBehavior.TRANSIENT, true) - : container; - container.setError(System.err); - container.setOutput(System.out); + ? new ScriptingContainer(LocalContextScope.CONCURRENT, LocalVariableBehavior.TRANSIENT, true) + : container; + + // Use the container.setError(System.err) and container.setOutput(System.out) method calls to redirect output + // and error to standard output and error for debugging container.put("executor", getExecutionContext()); // needed for the compile parsedjruby = container.parse(getSubject().getLogic()); } @@ -80,7 +82,7 @@ public class JrubyStateFinalizerExecutor extends StateFinalizerExecutor { */ @Override public String execute(final long executionId, final Properties executionProperties, - final Map<String, Object> incomingFields) throws StateMachineException, ContextException { + final Map<String, Object> incomingFields) throws StateMachineException, ContextException { // Do execution pre work executePre(executionId, executionProperties, incomingFields); @@ -112,7 +114,7 @@ public class JrubyStateFinalizerExecutor extends StateFinalizerExecutor { @Override public void cleanUp() throws StateMachineException { LOGGER.debug("cleanUp:" + getSubject().getKey().getId() + "," + getSubject().getLogicFlavour() + "," - + getSubject().getLogic()); + + getSubject().getLogic()); container.terminate(); container = null; } diff --git a/plugins/plugins-executor/plugins-executor-jruby/src/main/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskExecutor.java b/plugins/plugins-executor/plugins-executor-jruby/src/main/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskExecutor.java index c805597e9..3944aab50 100644 --- a/plugins/plugins-executor/plugins-executor-jruby/src/main/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskExecutor.java +++ b/plugins/plugins-executor/plugins-executor-jruby/src/main/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskExecutor.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,8 +45,8 @@ public class JrubyTaskExecutor extends TaskExecutor { private static final XLogger LOGGER = XLoggerFactory.getXLogger(JrubyTaskExecutor.class); // Jruby container - private ScriptingContainer container = - new ScriptingContainer(LocalContextScope.CONCURRENT, LocalVariableBehavior.TRANSIENT, true); + private ScriptingContainer container = new ScriptingContainer(LocalContextScope.CONCURRENT, + LocalVariableBehavior.TRANSIENT, true); private EmbedEvalUnit parsedjruby = null; /** @@ -60,10 +61,11 @@ public class JrubyTaskExecutor extends TaskExecutor { // Set up the JRuby engine container = (container == null) - ? new ScriptingContainer(LocalContextScope.CONCURRENT, LocalVariableBehavior.TRANSIENT, true) - : container; - container.setError(System.err); - container.setOutput(System.out); + ? new ScriptingContainer(LocalContextScope.CONCURRENT, LocalVariableBehavior.TRANSIENT, true) + : container; + + // Use the container.setError(System.err) and container.setOutput(System.out) method calls to redirect output + // and error to standard output and error for debugging container.put("executor", getExecutionContext()); // needed for the compile parsedjruby = container.parse(getSubject().getTaskLogic().getLogic()); } @@ -80,7 +82,7 @@ public class JrubyTaskExecutor extends TaskExecutor { */ @Override public Map<String, Object> execute(final long executionId, final Properties executionProperties, - final Map<String, Object> incomingFields) throws StateMachineException, ContextException { + final Map<String, Object> incomingFields) throws StateMachineException, ContextException { // Do execution pre work executePre(executionId, executionProperties, incomingFields); @@ -112,7 +114,7 @@ public class JrubyTaskExecutor extends TaskExecutor { @Override public void cleanUp() throws StateMachineException { LOGGER.debug("cleanUp:" + getSubject().getKey().getId() + "," + getSubject().getTaskLogic().getLogicFlavour() - + "," + getSubject().getTaskLogic().getLogic()); + + "," + getSubject().getTaskLogic().getLogic()); container.terminate(); container = null; } diff --git a/plugins/plugins-executor/plugins-executor-jruby/src/main/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskSelectExecutor.java b/plugins/plugins-executor/plugins-executor-jruby/src/main/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskSelectExecutor.java index 274acbed1..2655aa195 100644 --- a/plugins/plugins-executor/plugins-executor-jruby/src/main/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskSelectExecutor.java +++ b/plugins/plugins-executor/plugins-executor-jruby/src/main/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskSelectExecutor.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,8 +48,8 @@ public class JrubyTaskSelectExecutor extends TaskSelectExecutor { private static final XLogger LOGGER = XLoggerFactory.getXLogger(JrubyTaskSelectExecutor.class); // Jruby container - private ScriptingContainer container = - new ScriptingContainer(LocalContextScope.CONCURRENT, LocalVariableBehavior.TRANSIENT, true); + private ScriptingContainer container = new ScriptingContainer(LocalContextScope.CONCURRENT, + LocalVariableBehavior.TRANSIENT, true); private EmbedEvalUnit parsedjruby = null; /** @@ -63,8 +64,12 @@ public class JrubyTaskSelectExecutor extends TaskSelectExecutor { // Set up the JRuby engine container = (container == null) - ? new ScriptingContainer(LocalContextScope.CONCURRENT, LocalVariableBehavior.TRANSIENT, true) - : container; + ? new ScriptingContainer(LocalContextScope.CONCURRENT, LocalVariableBehavior.TRANSIENT, true) + : container; + + // Use the container.setError(System.err) and container.setOutput(System.out) method calls to redirect output + // and error to standard output and error for debugging + container.put("executor", getExecutionContext()); // needed for compile as a placeholder parsedjruby = container.parse(getSubject().getTaskSelectionLogic().getLogic()); } @@ -81,7 +86,7 @@ public class JrubyTaskSelectExecutor extends TaskSelectExecutor { */ @Override public AxArtifactKey execute(final long executionId, final Properties executionProperties, - final EnEvent incomingEvent) throws StateMachineException, ContextException { + final EnEvent incomingEvent) throws StateMachineException, ContextException { // Do execution pre work executePre(executionId, executionProperties, incomingEvent); @@ -113,8 +118,8 @@ public class JrubyTaskSelectExecutor extends TaskSelectExecutor { @Override public void cleanUp() throws StateMachineException { LOGGER.debug("cleanUp:" + getSubject().getKey().getId() + "," - + getSubject().getTaskSelectionLogic().getLogicFlavour() + "," - + getSubject().getTaskSelectionLogic().getLogic()); + + getSubject().getTaskSelectionLogic().getLogicFlavour() + "," + + getSubject().getTaskSelectionLogic().getLogic()); container.terminate(); container = null; } |