From 926646d8e5e86e680a119360f93d7bdb46c89435 Mon Sep 17 00:00:00 2001 From: "a.sreekumar" Date: Tue, 22 Jun 2021 15:55:46 +0100 Subject: Changes to support multiple outputs from a state This review addresses two main changes: 1) inputFields and outputFields are not tied to task definition anymore. Instead inputEvent and outputEvents associated to a task is populated as part of the policy state definition, as the state definition have the information anyway. - Clean up of the usage of inputFields and outputFields in task definition will happen in a future review - inputFields and outputFields defined in task definition in policies until honolulu will not make the policy invalid as the changes are done in backward compatible way. 2) Multiple output events can come out of a final state now. - Define another policy state output with the relevant eventName in the command file - In the task logic, create a map to store the fields of the relevant outputEvent, and then just call "executor.addFieldsToOutput()" These 2 steps are enough to send multiple events to relevant components as per the apex configuration. Change-Id: Id88ca402704106404f529e595e1a76f6bf167876 Issue-ID: POLICY-3336 Signed-off-by: a.sreekumar --- .../onap/policy/apex/plugins/executor/mvel/MvelTaskExecutor.java | 3 ++- .../policy/apex/plugins/executor/mvel/MvelTaskExecutorTest.java | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'plugins/plugins-executor/plugins-executor-mvel') 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 index 179462bb1..07a287f4d 100644 --- 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 @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2021 Bell Canada. 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. @@ -77,7 +78,7 @@ public class MvelTaskExecutor extends TaskExecutor { * @throws ContextException on context errors */ @Override - public Map execute(final long executionId, final Properties executionProperties, + public Map> execute(final long executionId, final Properties executionProperties, final Map incomingFields) throws StateMachineException, ContextException { // Do execution pre work executePre(executionId, executionProperties, incomingFields); diff --git a/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutorTest.java b/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutorTest.java index a4d2cbf2b..3d59c4b21 100644 --- a/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutorTest.java +++ b/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutorTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. * Modifications Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2021 Bell Canada. 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. @@ -28,6 +29,7 @@ import static org.junit.Assert.assertNotNull; import java.util.HashMap; import java.util.Map; import java.util.Properties; +import java.util.TreeMap; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -38,6 +40,7 @@ import org.onap.policy.apex.context.parameters.LockManagerParameters; import org.onap.policy.apex.context.parameters.PersistorParameters; import org.onap.policy.apex.core.engine.context.ApexInternalContext; import org.onap.policy.apex.core.engine.executor.exception.StateMachineException; +import org.onap.policy.apex.model.eventmodel.concepts.AxEvent; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; import org.onap.policy.apex.model.policymodel.concepts.AxTask; import org.onap.policy.common.parameters.ParameterService; @@ -77,6 +80,8 @@ public class MvelTaskExecutorTest { AxTask task = new AxTask(); ApexInternalContext internalContext = null; internalContext = new ApexInternalContext(new AxPolicyModel()); + task.setInputEvent(new AxEvent()); + task.setOutputEvents(new TreeMap<>()); mte.setContext(null, task, internalContext); task.getTaskLogic().setLogic("x > 1 2 ()"); @@ -97,7 +102,7 @@ public class MvelTaskExecutorTest { .hasMessage("execute-post: task logic execution failure on task \"NULL\" in model NULL:0.0.0"); mte.prepare(); - Map returnMap = mte.execute(0, new Properties(), incomingParameters); + Map> returnMap = mte.execute(0, new Properties(), incomingParameters); assertEquals(0, returnMap.size()); mte.cleanUp(); } -- cgit 1.2.3-korg