From 5f0ec1c2d95c377fbec428f11464e93fe442b5ef Mon Sep 17 00:00:00 2001 From: "a.sreekumar" Date: Tue, 29 Jun 2021 13:57:14 +0100 Subject: Cleanup input & outputFields from Task definition 1) Remove the usage of inputField and outputField from Task definition. 2) Fix issues around populating events to task in case of State Finalizer Logic. Change-Id: Ief17f400729410b83c6b7c665980d443e0cf6f28 Issue-ID: POLICY-3336 Signed-off-by: a.sreekumar --- .../core/engine/engine/impl/ApexEngineImpl.java | 45 +++++++++++++--------- .../core/engine/executor/TaskExecutorTest.java | 2 - .../engine/executor/context/AxTaskFacadeTest.java | 3 -- 3 files changed, 27 insertions(+), 23 deletions(-) (limited to 'core/core-engine') diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java index 878d5277a..d45be9652 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java @@ -50,6 +50,7 @@ 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.AxState; import org.onap.policy.apex.model.policymodel.concepts.AxStateOutput; +import org.onap.policy.apex.model.policymodel.concepts.AxStateTaskOutputType; import org.onap.policy.apex.model.policymodel.concepts.AxStateTaskReference; import org.onap.policy.apex.model.policymodel.concepts.AxTask; import org.slf4j.ext.XLogger; @@ -180,26 +181,34 @@ public class ApexEngineImpl implements ApexEngine { private void updateTaskBasedOnStateOutput(AxPolicyModel apexPolicyModel, Set updatedTasks, AxState state, AxArtifactKey taskKey, AxStateTaskReference taskRef, AxTask task) { Map outputEvents = new TreeMap<>(); - AxStateOutput stateOutput = state.getStateOutputs().get(taskRef.getOutput().getLocalName()); - if (null == stateOutput.getOutgoingEventSet() || stateOutput.getOutgoingEventSet().isEmpty()) { - Set outEventSet = new TreeSet<>(); - outEventSet.add(stateOutput.getOutgoingEvent()); - stateOutput.setOutgoingEventSet(outEventSet); - } - if (state.getNextStateSet().isEmpty() - || state.getNextStateSet().contains(AxReferenceKey.getNullKey().getLocalName())) { - stateOutput.getOutgoingEventSet().forEach(outgoingEventKey -> outputEvents.put(outgoingEventKey.getName(), - apexPolicyModel.getEvents().get(outgoingEventKey))); + AxStateOutput stateOutput = null; + if (AxStateTaskOutputType.LOGIC.equals(taskRef.getStateTaskOutputType())) { + // in case of SFL, outgoing event will be same for all state outputs that are part of SFL.So, take any entry + stateOutput = state.getStateOutputs().values().iterator().next(); } else { - AxArtifactKey outgoingEventKey = stateOutput.getOutgoingEvent(); - outputEvents.put(outgoingEventKey.getName(), apexPolicyModel.getEvents().get(outgoingEventKey)); + stateOutput = state.getStateOutputs().get(taskRef.getOutput().getLocalName()); } - if (updatedTasks.contains(taskKey)) { - // this happens only when same task is used by multiple policies - // with different eventName but same fields - task.getOutputEvents().putAll(outputEvents); - } else { - task.setOutputEvents(outputEvents); + if (null != stateOutput) { + if (null == stateOutput.getOutgoingEventSet() || stateOutput.getOutgoingEventSet().isEmpty()) { + Set outEventSet = new TreeSet<>(); + outEventSet.add(stateOutput.getOutgoingEvent()); + stateOutput.setOutgoingEventSet(outEventSet); + } + if (state.getNextStateSet().isEmpty() + || state.getNextStateSet().contains(AxReferenceKey.getNullKey().getLocalName())) { + stateOutput.getOutgoingEventSet().forEach(outgoingEventKey -> outputEvents + .put(outgoingEventKey.getName(), apexPolicyModel.getEvents().get(outgoingEventKey))); + } else { + AxArtifactKey outgoingEventKey = stateOutput.getOutgoingEvent(); + outputEvents.put(outgoingEventKey.getName(), apexPolicyModel.getEvents().get(outgoingEventKey)); + } + if (updatedTasks.contains(taskKey)) { + // this happens only when same task is used by multiple policies + // with different eventName but same fields + task.getOutputEvents().putAll(outputEvents); + } else { + task.setOutputEvents(outputEvents); + } } } diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/TaskExecutorTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/TaskExecutorTest.java index 1ddc3f5b5..4160a9f19 100644 --- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/TaskExecutorTest.java +++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/TaskExecutorTest.java @@ -125,8 +125,6 @@ public class TaskExecutorTest { Mockito.doReturn(true).when(axOptionalOutputFieldMock).getOptional(); Mockito.doReturn(false).when(axMissingOutputFieldMock).getOptional(); - Mockito.doReturn(inFieldMap).when(axTaskMock).getInputFields(); - Mockito.doReturn(outFieldMap).when(axTaskMock).getOutputFields(); Mockito.doReturn(taskLogicMock).when(axTaskMock).getTaskLogic(); Mockito.doReturn(inEvent).when(axTaskMock).getInputEvent(); diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacadeTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacadeTest.java index 6f8402e55..9da8ecfad 100644 --- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacadeTest.java +++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacadeTest.java @@ -99,9 +99,6 @@ public class AxTaskFacadeTest { Mockito.doReturn(inEvent).when(axTaskMock).getInputEvent(); Mockito.doReturn(outEvents).when(axTaskMock).getOutputEvents(); - Mockito.doReturn(inFieldMap).when(axTaskMock).getInputFields(); - Mockito.doReturn(outFieldMap).when(axTaskMock).getOutputFields(); - Mockito.doReturn(new AxReferenceKey(task0Key, "InField0")).when(axInputFieldMock).getKey(); Mockito.doReturn(stringTypeKey).when(axInputFieldMock).getSchema(); -- cgit 1.2.3-korg