summaryrefslogtreecommitdiffstats
path: root/plugins/plugins-executor/plugins-executor-mvel/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/plugins-executor/plugins-executor-mvel/src/main')
-rw-r--r--plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MVELExecutorParameters.java42
-rw-r--r--plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelStateFinalizerExecutor.java118
-rw-r--r--plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutor.java117
-rw-r--r--plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskSelectExecutor.java120
-rw-r--r--plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/package-info.java30
5 files changed, 427 insertions, 0 deletions
diff --git a/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MVELExecutorParameters.java b/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MVELExecutorParameters.java
new file mode 100644
index 000000000..21d124212
--- /dev/null
+++ b/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MVELExecutorParameters.java
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.plugins.executor.mvel;
+
+import org.onap.policy.apex.core.engine.ExecutorParameters;
+
+/**
+ * This class provides executor parameters for the MVEL Executor plugin. It specifies the classes that provide the MVEL
+ * implementations of the abstract classes {@link org.onap.policy.apex.core.engine.executor.TaskExecutor},
+ * {@link org.onap.policy.apex.core.engine.executor.TaskSelectExecutor}, and
+ * {@link org.onap.policy.apex.core.engine.executor.StateFinalizerExecutor}.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class MVELExecutorParameters extends ExecutorParameters {
+ /**
+ * Constructor that sets the abstract implementation classes.
+ */
+ public MVELExecutorParameters() {
+ this.setTaskExecutorPluginClass(MvelTaskExecutor.class.getCanonicalName());
+ this.setTaskSelectionExecutorPluginClass(MvelTaskSelectExecutor.class.getCanonicalName());
+ this.setStateFinalizerExecutorPluginClass(MvelStateFinalizerExecutor.class.getCanonicalName());
+ }
+}
diff --git a/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelStateFinalizerExecutor.java b/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelStateFinalizerExecutor.java
new file mode 100644
index 000000000..8cd76a94d
--- /dev/null
+++ b/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelStateFinalizerExecutor.java
@@ -0,0 +1,118 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.plugins.executor.mvel;
+
+import static org.onap.policy.apex.model.utilities.Assertions.argumentNotNull;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.mvel2.MVEL;
+import org.onap.policy.apex.context.ContextException;
+import org.onap.policy.apex.core.engine.executor.StateFinalizerExecutor;
+import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * The Class MvelStateFinalizerExecutor is the state finalizer executor for state finalizer logic written in MVEL.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class MvelStateFinalizerExecutor extends StateFinalizerExecutor {
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(MvelStateFinalizerExecutor.class);
+
+ // The MVEL code
+ private Serializable compiled = null;
+
+ /**
+ * Prepares the state finalizer for processing.
+ *
+ * @throws StateMachineException thrown when a state machine execution error occurs
+ */
+ @Override
+ public void prepare() throws StateMachineException {
+ // Call generic prepare logic
+ super.prepare();
+
+ // Compile the MVEL code
+ try {
+ compiled = MVEL.compileExpression(getSubject().getLogic());
+ } catch (final Exception e) {
+ LOGGER.warn("failed to compile MVEL code for state " + getSubject().getKey().getID(), e);
+ throw new StateMachineException("failed to compile MVEL code for state " + getSubject().getKey().getID(),
+ e);
+ }
+ }
+
+ /**
+ * Executes the executor for the state finalizer logic in a sequential manner.
+ *
+ * @param executionID the execution ID for the current APEX policy execution
+ * @param incomingFields the incoming fields for finalisation
+ * @return The state output for the state
+ * @throws StateMachineException on an execution error
+ * @throws ContextException on context errors
+ */
+ @Override
+ public String execute(final long executionID, final Map<String, Object> incomingFields)
+ throws StateMachineException, ContextException {
+ // Do execution pre work
+ executePre(executionID, incomingFields);
+
+ // Check and execute the MVEL logic
+ argumentNotNull(compiled, "MVEL state finalizer logic not compiled.");
+
+ boolean returnValue = false;
+ try {
+ // Execute the MVEL code
+ returnValue =
+ (boolean) MVEL.executeExpression(compiled, getExecutionContext(), new HashMap<String, Object>());
+ } catch (final Exception e) {
+ LOGGER.warn("failed to execute MVEL code for state " + getSubject().getKey().getID(), e);
+ throw new StateMachineException("failed to execute MVEL code for state " + getSubject().getKey().getID(),
+ e);
+ }
+
+ // Do the execution post work
+ executePost(returnValue);
+
+ // Send back the return event
+ if (returnValue) {
+ return getOutgoing();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Cleans up the state finalizer after processing.
+ *
+ * @throws StateMachineException thrown when a state machine execution error occurs
+ */
+ @Override
+ public void cleanUp() throws StateMachineException {
+ LOGGER.debug("cleanUp:" + getSubject().getKey().getID() + "," + getSubject().getLogicFlavour() + ","
+ + getSubject().getLogic());
+ }
+}
diff --git a/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutor.java b/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutor.java
new file mode 100644
index 000000000..8599eabac
--- /dev/null
+++ b/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutor.java
@@ -0,0 +1,117 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.plugins.executor.mvel;
+
+import static org.onap.policy.apex.model.utilities.Assertions.argumentNotNull;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.mvel2.MVEL;
+import org.onap.policy.apex.context.ContextException;
+import org.onap.policy.apex.core.engine.executor.TaskExecutor;
+import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * The Class MvelTaskExecutor is the task executor for task logic written in MVEL.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class MvelTaskExecutor extends TaskExecutor {
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(MvelTaskExecutor.class);
+
+ // The MVEL code
+ private Serializable compiled = null;
+
+ /**
+ * Prepares the task for processing.
+ *
+ * @throws StateMachineException thrown when a state machine execution error occurs
+ */
+ @Override
+ public void prepare() throws StateMachineException {
+ // Call generic prepare logic
+ super.prepare();
+
+ // Compile the MVEL code
+ try {
+ compiled = MVEL.compileExpression(getSubject().getTaskLogic().getLogic());
+ } catch (final Exception e) {
+ LOGGER.warn("failed to compile MVEL code for task " + getSubject().getKey().getID(), e);
+ throw new StateMachineException("failed to compile MVEL code for task " + getSubject().getKey().getID(), e);
+ }
+ argumentNotNull(compiled, "MVEL task not compiled.");
+ }
+
+ /**
+ * Executes the executor for the task in a sequential manner.
+ *
+ * @param executionID the execution ID for the current APEX policy execution
+ * @param incomingFields the incoming fields
+ * @return The outgoing fields
+ * @throws StateMachineException on an execution error
+ * @throws ContextException on context errors
+ */
+ @Override
+ public Map<String, Object> execute(final long executionID, final Map<String, Object> incomingFields)
+ throws StateMachineException, ContextException {
+ // Do execution pre work
+ executePre(executionID, incomingFields);
+
+ // Check and execute the MVEL logic
+ argumentNotNull(compiled, "MVEL task not compiled.");
+ boolean returnValue = false;
+
+ try {
+ // Execute the MVEL code
+ returnValue =
+ (boolean) MVEL.executeExpression(compiled, getExecutionContext(), new HashMap<String, Object>());
+ } catch (final Exception e) {
+ LOGGER.warn("failed to execute MVEL code for task " + getSubject().getKey().getID(), e);
+ throw new StateMachineException("failed to execute MVEL code for task " + getSubject().getKey().getID(), e);
+ }
+
+ // Do the execution post work
+ executePost(returnValue);
+
+ // Send back the return event
+ if (returnValue) {
+ return getOutgoing();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Cleans up the task after processing.
+ *
+ * @throws StateMachineException thrown when a state machine execution error occurs
+ */
+ @Override
+ public void cleanUp() throws StateMachineException {
+ LOGGER.debug("cleanUp:" + getSubject().getKey().getID() + "," + getSubject().getTaskLogic().getLogicFlavour()
+ + "," + getSubject().getTaskLogic().getLogic());
+ }
+}
diff --git a/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskSelectExecutor.java b/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskSelectExecutor.java
new file mode 100644
index 000000000..3cb5d9bf6
--- /dev/null
+++ b/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskSelectExecutor.java
@@ -0,0 +1,120 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.plugins.executor.mvel;
+
+import static org.onap.policy.apex.model.utilities.Assertions.argumentNotNull;
+
+import java.io.Serializable;
+import java.util.HashMap;
+
+import org.mvel2.MVEL;
+import org.onap.policy.apex.context.ContextException;
+import org.onap.policy.apex.core.engine.event.EnEvent;
+import org.onap.policy.apex.core.engine.executor.TaskSelectExecutor;
+import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * The Class MvelTaskSelectExecutor is the task selection executor for task selection logic written in MVEL.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class MvelTaskSelectExecutor extends TaskSelectExecutor {
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(MvelTaskSelectExecutor.class);
+
+ // The MVEL code
+ private Serializable compiled = null;
+
+ /**
+ * Prepares the task for processing.
+ *
+ * @throws StateMachineException thrown when a state machine execution error occurs
+ */
+ @Override
+ public void prepare() throws StateMachineException {
+ // Call generic prepare logic
+ super.prepare();
+
+ // Compile the MVEL code
+ try {
+ compiled = MVEL.compileExpression(getSubject().getTaskSelectionLogic().getLogic());
+ } catch (final Exception e) {
+ LOGGER.warn("failed to compile MVEL code for state " + getSubject().getKey().getID(), e);
+ throw new StateMachineException("failed to compile MVEL code for state " + getSubject().getKey().getID(),
+ e);
+ }
+ }
+
+ /**
+ * Executes the executor for the task in a sequential manner.
+ *
+ * @param executionID the execution ID for the current APEX policy execution
+ * @param incomingEvent the incoming event
+ * @return The outgoing event
+ * @throws StateMachineException on an execution error
+ * @throws ContextException on context errors
+ */
+ @Override
+ public AxArtifactKey execute(final long executionID, final EnEvent incomingEvent)
+ throws StateMachineException, ContextException {
+ // Do execution pre work
+ executePre(executionID, incomingEvent);
+
+ // Check and execute the MVEL logic
+ argumentNotNull(compiled, "MVEL task not compiled.");
+
+ boolean returnValue = false;
+ try {
+ // Execute the MVEL code
+ returnValue =
+ (boolean) MVEL.executeExpression(compiled, getExecutionContext(), new HashMap<String, Object>());
+ } catch (final Exception e) {
+ LOGGER.warn("failed to execute MVEL code for state " + getSubject().getKey().getID(), e);
+ throw new StateMachineException("failed to execute MVEL code for state " + getSubject().getKey().getID(),
+ e);
+ }
+
+ // Do the execution post work
+ executePost(returnValue);
+
+ // Send back the return event
+ if (returnValue) {
+ return getOutgoing();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Cleans up the task after processing.
+ *
+ * @throws StateMachineException thrown when a state machine execution error occurs
+ */
+ @Override
+ public void cleanUp() throws StateMachineException {
+ LOGGER.debug("cleanUp:" + getSubject().getKey().getID() + ","
+ + getSubject().getTaskSelectionLogic().getLogicFlavour() + ","
+ + getSubject().getTaskSelectionLogic().getLogic());
+ }
+}
diff --git a/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/package-info.java b/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/package-info.java
new file mode 100644
index 000000000..8e8ab889b
--- /dev/null
+++ b/plugins/plugins-executor/plugins-executor-mvel/src/main/java/org/onap/policy/apex/plugins/executor/mvel/package-info.java
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+/**
+ * Implements the MVEL executor plugin for APEX, providing extensions of the abstract classes
+ * {@link com.ericsson.apex.core.engine.executor.TaskExecutor},
+ * {@link com.ericsson.apex.core.engine.executor.TaskSelectExecutor}, and
+ * {@link com.ericsson.apex.core.engine.executor.StateFinalizerExecutor}.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+
+package org.onap.policy.apex.plugins.executor.mvel;