summaryrefslogtreecommitdiffstats
path: root/plugins/plugins-executor/plugins-executor-java/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/plugins-executor/plugins-executor-java/src/main')
-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
5 files changed, 427 insertions, 0 deletions
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;