2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019-2020 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.plugins.executor.javascript;
24 import java.util.Properties;
26 import org.onap.policy.apex.context.ContextException;
27 import org.onap.policy.apex.core.engine.event.EnEvent;
28 import org.onap.policy.apex.core.engine.executor.TaskSelectExecutor;
29 import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
30 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
31 import org.slf4j.ext.XLogger;
32 import org.slf4j.ext.XLoggerFactory;
35 * The Class JavascriptTaskSelectExecutor is the task selection executor for task selection logic written in Javascript
36 * It is unlikely that this is thread safe.
38 * @author Liam Fallon (liam.fallon@ericsson.com)
40 public class JavascriptTaskSelectExecutor extends TaskSelectExecutor {
41 // Logger for this class
42 private static final XLogger LOGGER = XLoggerFactory.getXLogger(JavascriptTaskSelectExecutor.class);
44 private JavascriptExecutor javascriptExecutor;
47 * Prepares the task selection logic for processing.
49 * @throws StateMachineException thrown when a state machine execution error occurs
52 public void prepare() throws StateMachineException {
53 // Call generic prepare logic
56 // Create the executor
57 if (javascriptExecutor == null) {
58 javascriptExecutor = new JavascriptExecutor(getSubject().getKey());
61 // Initialize and cleanup the executor to check the Javascript code
62 javascriptExecutor.init(getSubject().getTaskSelectionLogic().getLogic());
66 * Executes the executor for the task in a sequential manner.
68 * @param executionId the execution ID for the current APEX policy execution
69 * @param executionProperties properties for the current APEX policy execution
70 * @param incomingEvent the incoming event
71 * @return The outgoing event
72 * @throws StateMachineException on an execution error
73 * @throws ContextException on context errors
76 public AxArtifactKey execute(final long executionId, final Properties executionProperties,
77 final EnEvent incomingEvent) throws StateMachineException, ContextException {
78 // Do execution pre work
79 executePre(executionId, executionProperties, incomingEvent);
81 // Execute the Javascript executor
82 boolean result = javascriptExecutor.execute(getExecutionContext());
84 // Execute the Javascript
91 * Cleans up the task after processing.
93 * @throws StateMachineException thrown when a state machine execution error occurs
96 public void cleanUp() throws StateMachineException {
98 "cleanUp:" + getSubject().getKey().getId() + "," + getSubject().getTaskSelectionLogic().getLogicFlavour()
99 + "," + getSubject().getTaskSelectionLogic().getLogic());
101 javascriptExecutor.cleanUp();