aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/plugins-executor/plugins-executor-java
diff options
context:
space:
mode:
authorramverma <ram.krishna.verma@ericsson.com>2018-06-11 11:27:47 +0100
committerramverma <ram.krishna.verma@ericsson.com>2018-06-11 17:17:24 +0100
commitd48fd41c995cca495a945da4c183a70bff765dea (patch)
tree38b803637a13c5af6afc16ff7e2b7a2c6b168fc3 /plugins/plugins-executor/plugins-executor-java
parentd0746b062ca6b85eae756db6eb6c4dead037a35a (diff)
Adding plugin-executor module to apex-pdp
Change-Id: I711eaaff3707aa6398c26f1a124fedeb1d0e11f4 Issue-ID: POLICY-862 Signed-off-by: ramverma <ram.krishna.verma@ericsson.com>
Diffstat (limited to 'plugins/plugins-executor/plugins-executor-java')
-rw-r--r--plugins/plugins-executor/plugins-executor-java/pom.xml36
-rw-r--r--plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaExecutorParameters.java42
-rw-r--r--plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutor.java118
-rw-r--r--plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutor.java117
-rw-r--r--plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutor.java120
-rw-r--r--plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/package-info.java30
6 files changed, 463 insertions, 0 deletions
diff --git a/plugins/plugins-executor/plugins-executor-java/pom.xml b/plugins/plugins-executor/plugins-executor-java/pom.xml
new file mode 100644
index 000000000..159e19333
--- /dev/null
+++ b/plugins/plugins-executor/plugins-executor-java/pom.xml
@@ -0,0 +1,36 @@
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 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=========================================================
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.onap.policy.apex-pdp.plugins.plugins-executor</groupId>
+ <artifactId>plugins-executor</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>plugins-executor-java</artifactId>
+ <name>${project.artifactId}</name>
+ <description>[${project.parent.artifactId}] Plugin for execution of Java logic in Apex</description>
+
+ <properties>
+ <apex-plugins-executor-java-dir>${project.basedir}/src</apex-plugins-executor-java-dir>
+ </properties>
+</project> \ No newline at end of file
diff --git a/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaExecutorParameters.java b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaExecutorParameters.java
new file mode 100644
index 000000000..64abeac47
--- /dev/null
+++ b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaExecutorParameters.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.java;
+
+import org.onap.policy.apex.core.engine.ExecutorParameters;
+
+/**
+ * This class provides executor parameters for the Java Executor plugin. It specifies the classes that provide the Java
+ * 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 JavaExecutorParameters extends ExecutorParameters {
+ /**
+ * Constructor that sets the abstract implementation classes.
+ */
+ public JavaExecutorParameters() {
+ this.setTaskExecutorPluginClass(JavaTaskExecutor.class.getCanonicalName());
+ this.setTaskSelectionExecutorPluginClass(JavaTaskSelectExecutor.class.getCanonicalName());
+ this.setStateFinalizerExecutorPluginClass(JavaStateFinalizerExecutor.class.getCanonicalName());
+ }
+}
diff --git a/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutor.java b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutor.java
new file mode 100644
index 000000000..52b78733a
--- /dev/null
+++ b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutor.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.java;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.onap.policy.apex.context.ContextException;
+import org.onap.policy.apex.core.engine.executor.StateFinalizerExecutor;
+import org.onap.policy.apex.core.engine.executor.context.StateFinalizerExecutionContext;
+import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * The Class JavaStateFinalizerExecutor is the state finalizer executor for state finalizer logic written in Java.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class JavaStateFinalizerExecutor extends StateFinalizerExecutor {
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(JavaStateFinalizerExecutor.class);
+
+ // The Java State Finalizer executor class
+ private Object stateFinalizerLogicObject = 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();
+
+ // Get the class for state finalizer execution
+ try {
+ // Create the state finalizer logic object from the byte code of the class
+ stateFinalizerLogicObject = Class.forName(getSubject().getLogic()).newInstance();
+ } catch (final Exception e) {
+ LOGGER.error("instantiation error on Java class \"" + getSubject().getLogic() + "\"", e);
+ throw new StateMachineException("instantiation error on Java class \"" + getSubject().getLogic() + "\"", 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 Java logic
+ boolean returnValue = false;
+ try {
+ // Find and call the method with the signature "public boolean getStateOutput(final
+ // StateFinalizerExecutionContext executor) throws ApexException"
+ // to invoke the
+ // task logic in the Java class
+ final Method method = stateFinalizerLogicObject.getClass().getDeclaredMethod("getStateOutput",
+ new Class[] { StateFinalizerExecutionContext.class });
+ returnValue = (boolean) method.invoke(stateFinalizerLogicObject, getExecutionContext());
+ } catch (final Exception e) {
+ LOGGER.error("execute: state finalizer logic failed to run for state finalizer \"" + getSubject().getID()
+ + "\"");
+ throw new StateMachineException(
+ "state finalizer logic failed to run for state finalizer \"" + getSubject().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().getID() + "," + getSubject().getLogicFlavour() + ","
+ + getSubject().getLogic());
+ }
+}
diff --git a/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutor.java b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutor.java
new file mode 100644
index 000000000..6343f1a9f
--- /dev/null
+++ b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutor.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.java;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.onap.policy.apex.context.ContextException;
+import org.onap.policy.apex.core.engine.executor.TaskExecutor;
+import org.onap.policy.apex.core.engine.executor.context.TaskExecutionContext;
+import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * The Class JavaTaskExecutor is the task executor for task logic written in Java.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class JavaTaskExecutor extends TaskExecutor {
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(JavaTaskExecutor.class);
+
+ // The Java Task executor class
+ private Object taskLogicObject = 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();
+
+ // Get the class for task execution
+ try {
+ // Create the task logic object from the byte code of the class
+ taskLogicObject = Class.forName(getSubject().getTaskLogic().getLogic()).newInstance();
+ } catch (final Exception e) {
+ LOGGER.error("instantiation error on Java class \"" + getSubject().getTaskLogic().getLogic() + "\"", e);
+ throw new StateMachineException(
+ "instantiation error on Java class \"" + getSubject().getTaskLogic().getLogic() + "\"", e);
+ }
+ }
+
+ /**
+ * 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 Java logic
+ boolean returnValue = false;
+ try {
+ // Find and call the method with the signature "public boolean getEvent(final TaskExecutionContext executor)
+ // throws ApexException" to invoke the
+ // task logic in the Java class
+ final Method method = taskLogicObject.getClass().getDeclaredMethod("getEvent",
+ new Class[] { TaskExecutionContext.class });
+ returnValue = (boolean) method.invoke(taskLogicObject, getExecutionContext());
+ } catch (final Exception e) {
+ LOGGER.error("execute: task logic failed to run for task \"" + getSubject().getKey().getID() + "\"");
+ throw new StateMachineException(
+ "task logic failed to run 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-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutor.java b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutor.java
new file mode 100644
index 000000000..ee33c52d1
--- /dev/null
+++ b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutor.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.java;
+
+import java.lang.reflect.Method;
+
+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.context.TaskSelectionExecutionContext;
+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 JavaTaskSelectExecutor is the task selection executor for task selection logic written in Java.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class JavaTaskSelectExecutor extends TaskSelectExecutor {
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(JavaTaskSelectExecutor.class);
+
+ // The Java Task Selection executor class
+ private Object taskSelectionLogicObject = 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();
+
+ // Get the class for task selection
+ try {
+ // Create the task logic object from the byte code of the class
+ taskSelectionLogicObject = Class.forName(getSubject().getTaskSelectionLogic().getLogic()).newInstance();
+ } catch (final Exception e) {
+ LOGGER.error("instantiation error on Java class" + taskSelectionLogicObject, e);
+ throw new StateMachineException("instantiation error on Java class" + taskSelectionLogicObject, 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 Java logic
+ boolean returnValue = false;
+ try {
+ // Find and call the method with the signature "public boolean getTask(final TaskSelectionExecutionContext
+ // executor)" to invoke the task selection
+ // logic in the Java class
+ final Method method = taskSelectionLogicObject.getClass().getDeclaredMethod("getTask",
+ new Class[] { TaskSelectionExecutionContext.class });
+ returnValue = (boolean) method.invoke(taskSelectionLogicObject, getExecutionContext());
+ } catch (final Exception e) {
+ LOGGER.error(
+ "execute: task selection logic failed to run for state \"" + getSubject().getKey().getID() + "\"",
+ e);
+ throw new StateMachineException(
+ "task selection logic failed to run 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-java/src/main/java/org/onap/policy/apex/plugins/executor/java/package-info.java b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/package-info.java
new file mode 100644
index 000000000..21f37b0e2
--- /dev/null
+++ b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/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 Java executor plugin for Apex, providing extensions 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)
+ */
+
+package org.onap.policy.apex.plugins.executor.java;