<!--
============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.
<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>
<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>
/*-
* ============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.
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;
/**
// 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());
}
*/
@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);
@Override
public void cleanUp() throws StateMachineException {
LOGGER.debug("cleanUp:" + getSubject().getKey().getId() + "," + getSubject().getLogicFlavour() + ","
- + getSubject().getLogic());
+ + getSubject().getLogic());
container.terminate();
container = null;
}
/*-
* ============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.
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;
/**
// 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());
}
*/
@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);
@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;
}
/*-
* ============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.
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;
/**
// 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());
}
*/
@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);
@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;
}
/*-\r
* ============LICENSE_START=======================================================\r
* Copyright (C) 2019 Nordix Foundation.\r
+ * Modifications Copyright (C) 2019 Nordix Foundation.\r
* ================================================================================\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
\r
@Test\r
public void testJrubyTaskExecutor() {\r
+ // Run test twice to check for incorrect shutdown activity\r
+ jrubyExecutorTest();\r
+ jrubyExecutorTest();\r
+ }\r
+\r
+ /**\r
+ * Test the JRuby executor.\r
+ */\r
+ private void jrubyExecutorTest() {\r
JrubyTaskExecutor jte = new JrubyTaskExecutor();\r
assertNotNull(jte);\r
+\r
try {\r
Field fieldContainer = JrubyTaskExecutor.class.getDeclaredField("container");\r
fieldContainer.setAccessible(true);\r
fail("test should throw an exception here");\r
} catch (Exception jteException) {\r
assertEquals("execute-post: task logic execution failure on task \"NULL\" in model NULL:0.0.0",\r
- jteException.getMessage());\r
+ jteException.getMessage());\r
}\r
\r
- final String jrubyLogic =\r
- "if executor.executionId == -1" + "\n return false" + "\n else " + "\n return true" + "\n end";\r
+ final String jrubyLogic = "if executor.executionId == -1" + "\n return false" + "\n else " + "\n return true"\r
+ + "\n end";\r
task.getTaskLogic().setLogic(jrubyLogic);\r
\r
try {\r
} catch (Exception jteException) {\r
fail("test should not throw an exception here");\r
}\r
+\r
+ try {\r
+ jte.prepare();\r
+ Map<String, Object> returnMap = jte.execute(0, new Properties(), incomingParameters);\r
+ assertEquals(0, returnMap.size());\r
+ jte.cleanUp();\r
+ } catch (Exception jteException) {\r
+ fail("test should not throw an exception here");\r
+ }\r
}\r
}\r