aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-11-15 13:40:08 +0000
committerliamfallon <liam.fallon@est.tech>2019-11-15 13:42:11 +0000
commitc54feabfafaab64d56cf275fb1a474f0e830eba9 (patch)
treee4c47037eac78e0d52436732fc3f6e6158608e38
parent40a1f22ff8d28e78b6512c0a10d454b37f015fdb (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>
-rw-r--r--plugins/plugins-executor/plugins-executor-jruby/pom.xml7
-rw-r--r--plugins/plugins-executor/plugins-executor-jruby/src/main/java/org/onap/policy/apex/plugins/executor/jruby/JrubyStateFinalizerExecutor.java18
-rw-r--r--plugins/plugins-executor/plugins-executor-jruby/src/main/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskExecutor.java18
-rw-r--r--plugins/plugins-executor/plugins-executor-jruby/src/main/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskSelectExecutor.java19
-rw-r--r--plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskExecutorTest.java26
5 files changed, 59 insertions, 29 deletions
diff --git a/plugins/plugins-executor/plugins-executor-jruby/pom.xml b/plugins/plugins-executor/plugins-executor-jruby/pom.xml
index 72fd8cccf..976166bea 100644
--- a/plugins/plugins-executor/plugins-executor-jruby/pom.xml
+++ b/plugins/plugins-executor/plugins-executor-jruby/pom.xml
@@ -1,6 +1,7 @@
<!--
============LICENSE_START=======================================================
Copyright (C) 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.
@@ -33,7 +34,7 @@
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-core</artifactId>
- <version>9.2.0.0</version>
+ <version>9.2.9.0</version>
<exclusions>
<exclusion>
<groupId>org.jruby.extras</groupId>
@@ -52,12 +53,12 @@
<dependency>
<groupId>org.jruby.extras</groupId>
<artifactId>bytelist</artifactId>
- <version>1.0.13</version>
+ <version>1.0.15</version>
</dependency>
<dependency>
<groupId>com.github.jnr</groupId>
<artifactId>jffi</artifactId>
- <version>1.2.10</version>
+ <version>1.2.22</version>
</dependency>
</dependencies>
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;
}
diff --git a/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskExecutorTest.java b/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskExecutorTest.java
index 8b58c38d8..2309c1e29 100644
--- a/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskExecutorTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * 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.
@@ -69,8 +70,18 @@ public class JrubyTaskExecutorTest {
@Test
public void testJrubyTaskExecutor() {
+ // Run test twice to check for incorrect shutdown activity
+ jrubyExecutorTest();
+ jrubyExecutorTest();
+ }
+
+ /**
+ * Test the JRuby executor.
+ */
+ private void jrubyExecutorTest() {
JrubyTaskExecutor jte = new JrubyTaskExecutor();
assertNotNull(jte);
+
try {
Field fieldContainer = JrubyTaskExecutor.class.getDeclaredField("container");
fieldContainer.setAccessible(true);
@@ -101,11 +112,11 @@ public class JrubyTaskExecutorTest {
fail("test should throw an exception here");
} catch (Exception jteException) {
assertEquals("execute-post: task logic execution failure on task \"NULL\" in model NULL:0.0.0",
- jteException.getMessage());
+ jteException.getMessage());
}
- final String jrubyLogic =
- "if executor.executionId == -1" + "\n return false" + "\n else " + "\n return true" + "\n end";
+ final String jrubyLogic = "if executor.executionId == -1" + "\n return false" + "\n else " + "\n return true"
+ + "\n end";
task.getTaskLogic().setLogic(jrubyLogic);
try {
@@ -116,5 +127,14 @@ public class JrubyTaskExecutorTest {
} catch (Exception jteException) {
fail("test should not throw an exception here");
}
+
+ try {
+ jte.prepare();
+ Map<String, Object> returnMap = jte.execute(0, new Properties(), incomingParameters);
+ assertEquals(0, returnMap.size());
+ jte.cleanUp();
+ } catch (Exception jteException) {
+ fail("test should not throw an exception here");
+ }
}
}