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 --- .../policymodel/concepts/PolicyModelTest.java | 3 +- .../policymodel/concepts/StateOutputTest.java | 9 +++-- .../apex/model/policymodel/concepts/TasksTest.java | 46 +++------------------- .../handling/SupportApexPolicyModelCreator.java | 20 +++++++--- 4 files changed, 27 insertions(+), 51 deletions(-) (limited to 'model/policy-model/src/test') diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PolicyModelTest.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PolicyModelTest.java index 86bbf3e93..48022e878 100644 --- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PolicyModelTest.java +++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PolicyModelTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-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. @@ -335,7 +336,7 @@ public class PolicyModelTest { final AxStateOutput so = model.getPolicies().get("policy").getStateMap().get("state").getStateOutputs() .get(savedStateOutputName); - final AxArtifactKey savedOutEvent = so.getOutgingEvent(); + final AxArtifactKey savedOutEvent = so.getOutgoingEvent(); so.setOutgoingEvent(new AxArtifactKey("NonExistantEvent", "0.0.1")); result = new AxValidationResult(); result = model.validate(result); diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateOutputTest.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateOutputTest.java index 8bd29fc55..049783a7f 100644 --- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateOutputTest.java +++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateOutputTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-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. @@ -53,20 +54,20 @@ public class StateOutputTest { final AxArtifactKey eKey = new AxArtifactKey("EventName", "0.0.1"); assertThatThrownBy(() -> so.setKey(null)) - .hasMessage("key may not be null"); + .hasMessage("key is marked non-null but is null"); so.setKey(soKey); assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKey().getId()); assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKeys().get(0).getId()); assertThatThrownBy(() -> so.setNextState(null)) - .hasMessage("nextState may not be null"); + .hasMessage("nextState is marked non-null but is null"); so.setNextState(nsKey); assertEquals(nsKey, so.getNextState()); assertThatThrownBy(() -> so.setOutgoingEvent(null)) - .hasMessage("outgoingEvent may not be null"); + .hasMessage("outgoingEvent is marked non-null but is null"); so.setOutgoingEvent(eKey); - assertEquals(eKey, so.getOutgingEvent()); + assertEquals(eKey, so.getOutgoingEvent()); AxValidationResult result = new AxValidationResult(); result = so.validate(result); diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TasksTest.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TasksTest.java index 100adb9fd..95266acc8 100644 --- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TasksTest.java +++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TasksTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-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. @@ -26,6 +27,7 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.util.Map; import java.util.TreeMap; import java.util.TreeSet; import org.junit.Test; @@ -33,6 +35,7 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; +import org.onap.policy.apex.model.eventmodel.concepts.AxEvent; import org.onap.policy.apex.model.eventmodel.concepts.AxField; import org.onap.policy.apex.model.eventmodel.concepts.AxInputField; import org.onap.policy.apex.model.eventmodel.concepts.AxOutputField; @@ -91,7 +94,8 @@ public class TasksTest { assertEquals(ofMap, task.getOutputFields()); assertTrue(task.getOutputFieldSet().contains(of0)); assertTrue(task.getRawOutputFields().keySet().contains(of0.getKey().getLocalName())); - + task.setInputEvent(new AxEvent()); + task.setOutputEvents(Map.of("Event", new AxEvent())); final TreeMap ifDupMap = new TreeMap<>(); final TreeMap ofDupMap = new TreeMap<>(); ifDupMap.put(if1.getKey().getLocalName(), if1); @@ -131,46 +135,6 @@ public class TasksTest { result = task.validate(result); assertEquals(ValidationResult.VALID, result.getValidationResult()); - task.setInputFields(ifEmptyMap); - result = new AxValidationResult(); - result = task.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - task.setInputFields(ifMap); - result = new AxValidationResult(); - result = task.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - ifMap.put("NullField", null); - result = new AxValidationResult(); - result = task.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - ifMap.remove("NullField"); - result = new AxValidationResult(); - result = task.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - task.setOutputFields(ofEmptyMap); - result = new AxValidationResult(); - result = task.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - task.setOutputFields(ofMap); - result = new AxValidationResult(); - result = task.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - ofMap.put("NullField", null); - result = new AxValidationResult(); - result = task.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - ofMap.remove("NullField"); - result = new AxValidationResult(); - result = task.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - // Empty task parameter map is OK task.setTaskParameters(tpEmptyMap); result = new AxValidationResult(); diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/SupportApexPolicyModelCreator.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/SupportApexPolicyModelCreator.java index 3fca39739..ea2de8603 100644 --- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/SupportApexPolicyModelCreator.java +++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/SupportApexPolicyModelCreator.java @@ -1,25 +1,27 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * 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. * 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.model.policymodel.handling; +import java.util.Map; import java.util.UUID; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo; @@ -52,7 +54,7 @@ import org.onap.policy.apex.model.policymodel.concepts.AxTasks; /** * Model creator for model tests. - * + * * @author Liam Fallon (liam.fallon@ericsson.com) */ public class SupportApexPolicyModelCreator implements TestApexModelCreator { @@ -136,6 +138,9 @@ public class SupportApexPolicyModelCreator implements TestApexModelCreator