diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-02-13 11:08:42 +0000 |
---|---|---|
committer | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-02-14 10:32:14 +0000 |
commit | 204be45b2c666a9261e287275ead362b8817f22c (patch) | |
tree | 4c21b8763a6570e920fb8901a33ecd07990def15 | |
parent | 06339bee0cf891144ca781983ba99d170b10b2b7 (diff) |
Implement recording of Operational State and Usage State on ACM-R
Issue-ID: POLICY-4511
Change-Id: I3a241bf602e6625d91cee2dc5242b76165bcd381
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
17 files changed, 461 insertions, 363 deletions
diff --git a/examples/src/main/resources/clamp/acm/pmsh/funtional-pmsh-usecase.yaml b/examples/src/main/resources/clamp/acm/pmsh/funtional-pmsh-usecase.yaml index 9d8a37519..4587e31e8 100644 --- a/examples/src/main/resources/clamp/acm/pmsh/funtional-pmsh-usecase.yaml +++ b/examples/src/main/resources/clamp/acm/pmsh/funtional-pmsh-usecase.yaml @@ -342,7 +342,7 @@ node_types: type: onap.datatypes.ToscaConceptIdentifier description: Specifies a list of automation composition element definitions that make up this automation composition definition org.onap.policy.clamp.acm.PolicyAutomationCompositionElement: - version: 1.0.1 + version: 1.0.0 derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement properties: policy_type_id: @@ -359,7 +359,7 @@ node_types: type: onap.datatypes.ToscaConceptIdentifier required: true org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement: - version: 1.0.1 + version: 1.0.0 derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement properties: chart: @@ -379,7 +379,7 @@ node_types: type: string required: true org.onap.policy.clamp.acm.HttpAutomationCompositionElement: - version: 1.0.1 + version: 1.0.0 derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement properties: baseUrl: @@ -419,7 +419,7 @@ topology_template: org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement: version: 1.2.3 type: org.onap.policy.clamp.acm.PolicyAutomationCompositionElement - type_version: 1.0.1 + type_version: 1.0.0 description: Automation composition element for the operational policy for Performance Management Subscription Handling properties: provider: Ericsson @@ -441,7 +441,7 @@ topology_template: # Chart from new repository version: 1.2.3 type: org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement - type_version: 1.0.1 + type_version: 1.0.0 description: Automation composition element for the K8S microservice for PMSH properties: provider: ONAP @@ -470,7 +470,7 @@ topology_template: # Http config for PMSH. version: 1.2.3 type: org.onap.policy.clamp.acm.HttpAutomationCompositionElement - type_version: 1.0.1 + type_version: 1.0.0 description: Automation composition element for the http requests of PMSH microservice properties: provider: ONAP diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java index af29deb3f..35482b9bb 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java @@ -37,13 +37,13 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; -import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy; +import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; +import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder; import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.common.parameters.ObjectValidationResult; import org.onap.policy.common.parameters.ValidationResult; @@ -67,38 +67,6 @@ public final class AcmUtils { public static final String ENTRY = "entry "; /** - * Prepare participant updates map. - * - * @param acElement automation composition element - * @param participantUpdates list of participantUpdates - */ - public static void prepareParticipantUpdate(AutomationCompositionElement acElement, - List<ParticipantDeploy> participantUpdates) { - if (participantUpdates.isEmpty()) { - participantUpdates.add(getAutomationCompositionElementList(acElement)); - return; - } - - var participantExists = false; - for (ParticipantDeploy participantUpdate : participantUpdates) { - if (participantUpdate.getParticipantId().equals(acElement.getParticipantId())) { - participantUpdate.getAutomationCompositionElementList().add(acElement); - participantExists = true; - } - } - if (!participantExists) { - participantUpdates.add(getAutomationCompositionElementList(acElement)); - } - } - - private static ParticipantDeploy getAutomationCompositionElementList(AutomationCompositionElement acElement) { - var participantUpdate = new ParticipantDeploy(); - participantUpdate.setParticipantId(acElement.getParticipantId()); - participantUpdate.getAutomationCompositionElementList().add(acElement); - return participantUpdate; - } - - /** * Get the Policy information in the service template for the deploy message to participants. * * @param toscaServiceTemplate ToscaServiceTemplate @@ -196,7 +164,7 @@ public final class AcmUtils { public static List<Entry<String, ToscaNodeTemplate>> extractAcElementsFromServiceTemplate( ToscaServiceTemplate serviceTemplate) { return serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet().stream().filter( - nodeTemplateEntry -> checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplateEntry.getValue(), + nodeTemplateEntry -> checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplateEntry.getValue(), serviceTemplate)) .collect(Collectors.toList()); } @@ -309,7 +277,6 @@ public final class AcmUtils { // @formatter:on } - /** * Return true if DeployState and LockState are in a Transitional State. * @@ -321,6 +288,79 @@ public final class AcmUtils { } /** + * Get DeployOrder from transitional DeployState. + * + * @param deployState the Deploy State + * @return the DeployOrder + */ + public static DeployOrder stateDeployToOrder(DeployState deployState) { + if (DeployState.DEPLOYING.equals(deployState)) { + return DeployOrder.DEPLOY; + } else if (DeployState.UNDEPLOYING.equals(deployState)) { + return DeployOrder.UNDEPLOY; + } + return DeployOrder.NONE; + } + + /** + * Get LockOrder from transitional LockState. + * + * @param lockState the Lock State + * @return the LockOrder + */ + public static LockOrder stateLockToOrder(LockState lockState) { + if (LockState.LOCKING.equals(lockState)) { + return LockOrder.LOCK; + } else if (LockState.UNLOCKING.equals(lockState)) { + return LockOrder.UNLOCK; + } + return LockOrder.NONE; + } + + /** + * Get final DeployState from transitional DeployState. + * + * @param deployState the DeployState + * @return the DeployState + */ + public static DeployState deployCompleted(DeployState deployState) { + if (DeployState.DEPLOYING.equals(deployState)) { + return DeployState.DEPLOYED; + } else if (DeployState.UNDEPLOYING.equals(deployState)) { + return DeployState.UNDEPLOYED; + } + return deployState; + } + + /** + * Get final LockState from transitional LockState. + * + * @param lockState the LockState + * @return the LockState + */ + public static LockState lockCompleted(DeployState deployState, LockState lockState) { + if (LockState.LOCKING.equals(lockState) || DeployState.DEPLOYING.equals(deployState)) { + return LockState.LOCKED; + } else if (LockState.UNLOCKING.equals(lockState)) { + return LockState.UNLOCKED; + } else if (DeployState.UNDEPLOYING.equals(deployState)) { + return LockState.NONE; + } + return lockState; + } + + /** + * Return true if transition states is Forward. + * + * @param deployState the DeployState + * @param lockState the LockState + * @return true if transition if Forward + */ + public static boolean isForward(DeployState deployState, LockState lockState) { + return DeployState.DEPLOYING.equals(deployState) || LockState.UNLOCKING.equals(lockState); + } + + /** * Set the states on the automation composition and on all its automation composition elements. * * @param deployState the DeployState we want the automation composition to transition to diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java index 9f235d6ac..e044a2f22 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java @@ -25,7 +25,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.UUID; import org.junit.jupiter.api.Test; @@ -43,28 +42,13 @@ class AutomationCompositionElementTest { ace1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); ace1.setDescription("Description"); ace1.setId(UUID.randomUUID()); - ace1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); ace1.setParticipantId(CommonTestData.getParticipantId()); - ace1.setState(AutomationCompositionState.UNINITIALISED); var ace2 = new AutomationCompositionElement(ace1); assertEquals(ace1, ace2); } @Test - void testAutomationCompositionState() { - var ace0 = new AutomationCompositionElement(); - - assertTrue( - ace0.getOrderedState() - .equalsAutomationCompositionState(AutomationCompositionState.UNINITIALISED)); - - assertTrue( - ace0.getOrderedState().asState() - .equalsAutomationCompositionOrderedState(AutomationCompositionOrderedState.UNINITIALISED)); - } - - @Test void testAutomationCompositionElementLombok() { var ace0 = new AutomationCompositionElement(); @@ -78,9 +62,7 @@ class AutomationCompositionElementTest { ace1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); ace1.setDescription("Description"); ace1.setId(UUID.randomUUID()); - ace1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); ace1.setParticipantId(CommonTestData.getParticipantId()); - ace1.setState(AutomationCompositionState.UNINITIALISED); assertThat(ace1.toString()).contains("AutomationCompositionElement("); assertNotEquals(0, ace1.hashCode()); @@ -94,9 +76,7 @@ class AutomationCompositionElementTest { // @formatter:off assertThatThrownBy(() -> ace2.setDefinition(null)). isInstanceOf(NullPointerException.class); assertThatThrownBy(() -> ace2.setId(null)). isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> ace2.setOrderedState(null)). isInstanceOf(NullPointerException.class); assertThatThrownBy(() -> ace2.setParticipantId(null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> ace2.setState(null)). isInstanceOf(NullPointerException.class); // @formatter:on assertNotEquals(ace2, ace0); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java index e32735f07..64dc6f792 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java @@ -60,8 +60,6 @@ class AutomationCompositionTest { ac1.setDescription("Description"); ac1.setElements(new LinkedHashMap<>()); ac1.setName("Name"); - ac1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); - ac1.setState(AutomationCompositionState.UNINITIALISED); ac1.setVersion("0.0.1"); assertThat(ac1.toString()).contains("AutomationComposition("); @@ -76,20 +74,11 @@ class AutomationCompositionTest { // @formatter:off assertThatThrownBy(() -> ac2.setCompositionId(null)). isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> ac2.setOrderedState(null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> ac2.setState(null)). isInstanceOf(NullPointerException.class); // @formatter:on assertEquals(ac2, ac0); - ac1.setCascadedOrderedState(AutomationCompositionOrderedState.PASSIVE); - assertEquals(AutomationCompositionOrderedState.PASSIVE, ac1.getOrderedState()); - ac1.getElements().put(UUID.randomUUID(), new AutomationCompositionElement()); - ac1.setCascadedOrderedState(AutomationCompositionOrderedState.RUNNING); - assertEquals(AutomationCompositionOrderedState.RUNNING, ac1.getOrderedState()); - assertEquals(AutomationCompositionOrderedState.RUNNING, - ac1.getElements().values().iterator().next().getOrderedState()); assertNull(ac0.getElements().get(UUID.randomUUID())); assertNull(ac1.getElements().get(UUID.randomUUID())); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployTest.java index 2912dee9b..3f64eadd5 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployTest.java @@ -30,9 +30,7 @@ import java.util.List; import java.util.Map; import java.util.UUID; import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy; import org.onap.policy.clamp.models.acm.utils.CommonTestData; import org.onap.policy.common.utils.coder.CoderException; @@ -55,16 +53,10 @@ class AutomationCompositionDeployTest { orig.setMessageId(UUID.randomUUID()); orig.setTimestamp(Instant.ofEpochMilli(3000)); - var acElement = new AutomationCompositionElement(); + var acElement = new AcElementDeploy(); acElement.setId(UUID.randomUUID()); var id = new ToscaConceptIdentifier("id", "1.2.3"); acElement.setDefinition(id); - acElement.setDescription("Description"); - acElement.setOrderedState(AutomationCompositionOrderedState.PASSIVE); - acElement.setState(AutomationCompositionState.PASSIVE); - - var participantId = CommonTestData.getParticipantId(); - acElement.setParticipantId(participantId); var property = new ToscaProperty(); property.setName("test"); @@ -75,8 +67,8 @@ class AutomationCompositionDeployTest { acElement.setProperties(propertiesMap); var participantDeploy = new ParticipantDeploy(); - participantDeploy.setParticipantId(participantId); - participantDeploy.setAutomationCompositionElementList(List.of(acElement)); + participantDeploy.setParticipantId(CommonTestData.getParticipantId()); + participantDeploy.setAcElementList(List.of(acElement)); orig.setParticipantUpdatesList(List.of(participantDeploy)); var other = new AutomationCompositionDeploy(orig); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java index c16beaf87..b332d7d44 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java @@ -24,13 +24,12 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import java.io.File; -import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -41,8 +40,9 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; -import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy; import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate; +import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; +import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType; @@ -69,25 +69,6 @@ class AcmUtilsTest { } @Test - void testCommonUtilsParticipantUpdate() { - var acElement = new AutomationCompositionElement(); - List<ParticipantDeploy> participantUpdates = new ArrayList<>(); - assertThat(participantUpdates).isEmpty(); - - AcmUtils.prepareParticipantUpdate(acElement, participantUpdates); - assertThat(participantUpdates).isNotEmpty(); - assertEquals(acElement, participantUpdates.get(0).getAutomationCompositionElementList().get(0)); - - AcmUtils.prepareParticipantUpdate(acElement, participantUpdates); - var participantId = CommonTestData.getParticipantId(); - assertNotEquals(participantId, participantUpdates.get(0).getParticipantId()); - - acElement.setParticipantId(participantId); - AcmUtils.prepareParticipantUpdate(acElement, participantUpdates); - assertEquals(participantId, participantUpdates.get(1).getParticipantId()); - } - - @Test void testCheckIfNodeTemplateIsAutomationCompositionElement() { var serviceTemplate = CommonTestData.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML); var nodeTemplate = new ToscaNodeTemplate(); @@ -109,12 +90,12 @@ class AcmUtilsTest { Map<ToscaConceptIdentifier, UUID> map = new HashMap<>(); var participantId = UUID.randomUUID(); assertThatThrownBy(() -> AcmUtils.prepareParticipantPriming(acElements, map)).hasMessageMatching( - "Element Type org.onap.policy.clamp.acm.PolicyAutomationCompositionElement 1.0.1 not supported"); - map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyAutomationCompositionElement", "1.0.1"), + "Element Type org.onap.policy.clamp.acm.PolicyAutomationCompositionElement 1.0.0 not supported"); + map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyAutomationCompositionElement", "1.0.0"), participantId); map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement", - "1.0.1"), participantId); - map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.HttpAutomationCompositionElement", "1.0.1"), + "1.0.0"), participantId); + map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.HttpAutomationCompositionElement", "1.0.0"), participantId); var result = AcmUtils.prepareParticipantPriming(acElements, map); assertThat(result).isNotEmpty().hasSize(1); @@ -159,6 +140,47 @@ class AcmUtilsTest { assertFalse(result.isValid()); } + @Test + void testStateDeployToOrder() { + // from transitional state to order state + assertEquals(DeployOrder.DEPLOY, AcmUtils.stateDeployToOrder(DeployState.DEPLOYING)); + assertEquals(DeployOrder.UNDEPLOY, AcmUtils.stateDeployToOrder(DeployState.UNDEPLOYING)); + assertEquals(DeployOrder.NONE, AcmUtils.stateDeployToOrder(DeployState.DEPLOYED)); + } + + @Test + void testStateLockToOrder() { + // from transitional state to order state + assertEquals(LockOrder.LOCK, AcmUtils.stateLockToOrder(LockState.LOCKING)); + assertEquals(LockOrder.UNLOCK, AcmUtils.stateLockToOrder(LockState.UNLOCKING)); + assertEquals(LockOrder.NONE, AcmUtils.stateLockToOrder(LockState.NONE)); + } + + @Test + void testDeployCompleted() { + // from transitional state to final state + assertEquals(DeployState.DEPLOYED, AcmUtils.deployCompleted(DeployState.DEPLOYING)); + assertEquals(DeployState.UNDEPLOYED, AcmUtils.deployCompleted(DeployState.UNDEPLOYING)); + assertEquals(DeployState.DEPLOYED, AcmUtils.deployCompleted(DeployState.DEPLOYED)); + } + + @Test + void testLockCompleted() { + // from transitional state to final state + assertEquals(LockState.LOCKED, AcmUtils.lockCompleted(DeployState.DEPLOYING, LockState.NONE)); + assertEquals(LockState.LOCKED, AcmUtils.lockCompleted(DeployState.DEPLOYED, LockState.LOCKING)); + assertEquals(LockState.UNLOCKED, AcmUtils.lockCompleted(DeployState.DEPLOYED, LockState.UNLOCKING)); + assertEquals(LockState.NONE, AcmUtils.lockCompleted(DeployState.UNDEPLOYING, LockState.LOCKED)); + } + + @Test + void testIsForward() { + assertTrue(AcmUtils.isForward(DeployState.DEPLOYING, LockState.NONE)); + assertTrue(AcmUtils.isForward(DeployState.DEPLOYED, LockState.UNLOCKING)); + assertFalse(AcmUtils.isForward(DeployState.DEPLOYED, LockState.LOCKING)); + assertFalse(AcmUtils.isForward(DeployState.UNDEPLOYING, LockState.LOCKED)); + } + private AutomationComposition getDummyAutomationComposition() { var automationComposition = new AutomationComposition(); automationComposition.setCompositionId(UUID.randomUUID()); diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java index 3e79e78c1..5fcb3837f 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java @@ -79,7 +79,7 @@ public class SupervisionAcHandler { AcmUtils.setCascadedState(automationComposition, DeployState.UNDEPLOYING, LockState.NONE); automationCompositionProvider.updateAutomationComposition(automationComposition); var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate()); - automationCompositionStateChangePublisher.undeploy(automationComposition, startPhase, true); + automationCompositionStateChangePublisher.send(automationComposition, startPhase, true); } /** @@ -92,7 +92,7 @@ public class SupervisionAcHandler { AcmUtils.setCascadedState(automationComposition, DeployState.DEPLOYED, LockState.UNLOCKING); automationCompositionProvider.updateAutomationComposition(automationComposition); var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate()); - automationCompositionStateChangePublisher.unlock(automationComposition, startPhase, true); + automationCompositionStateChangePublisher.send(automationComposition, startPhase, true); } /** @@ -105,7 +105,7 @@ public class SupervisionAcHandler { AcmUtils.setCascadedState(automationComposition, DeployState.DEPLOYED, LockState.LOCKING); automationCompositionProvider.updateAutomationComposition(automationComposition); var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate()); - automationCompositionStateChangePublisher.lock(automationComposition, startPhase, true); + automationCompositionStateChangePublisher.send(automationComposition, startPhase, true); } /** diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java index 8d1f98388..ef50a633e 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java @@ -43,6 +43,7 @@ public class SupervisionAspect implements Closeable { private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionAspect.class); private final SupervisionScanner supervisionScanner; + private final SupervisionPartecipantScanner partecipantScanner; private ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>()); @@ -52,7 +53,12 @@ public class SupervisionAspect implements Closeable { initialDelayString = "${runtime.participantParameters.heartBeatMs}") public void schedule() { LOGGER.info("Add scheduled scanning"); - executor.execute(() -> supervisionScanner.run(true)); + executor.execute(this::executeScan); + } + + private void executeScan() { + supervisionScanner.run(true); + partecipantScanner.run(); } /** @@ -68,7 +74,7 @@ public class SupervisionAspect implements Closeable { @Before("@annotation(MessageIntercept) && args(participantStatusMessage,..)") public void handleParticipantStatus(ParticipantStatus participantStatusMessage) { - executor.execute(() -> supervisionScanner.handleParticipantStatus(participantStatusMessage.getParticipantId())); + executor.execute(() -> partecipantScanner.handleParticipantStatus(participantStatusMessage.getParticipantId())); } @Override diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java new file mode 100644 index 000000000..b396e629c --- /dev/null +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * 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.clamp.acm.runtime.supervision; + +import java.util.UUID; +import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup; +import org.onap.policy.clamp.models.acm.concepts.Participant; +import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +/** + * This class is used to scan the automation compositions in the database and check if they are in the correct state. + */ +@Component +public class SupervisionPartecipantScanner { + private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionPartecipantScanner.class); + + private final HandleCounter<UUID> participantStatusCounter = new HandleCounter<>(); + + private final ParticipantProvider participantProvider; + + /** + * Constructor for instantiating SupervisionPartecipantScanner. + * + * @param participantProvider the Participant Provider + * @param acRuntimeParameterGroup the parameters for the automation composition runtime + */ + public SupervisionPartecipantScanner( + final ParticipantProvider participantProvider, + final AcRuntimeParameterGroup acRuntimeParameterGroup) { + this.participantProvider = participantProvider; + + participantStatusCounter.setMaxRetryCount( + acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount()); + participantStatusCounter.setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs()); + } + + /** + * Run Scanning. + */ + public void run() { + LOGGER.debug("Scanning participans in the database . . ."); + + for (var participant : participantProvider.getParticipants()) { + scanParticipantStatus(participant); + } + + LOGGER.debug("Participans scan complete . . ."); + } + + private void scanParticipantStatus(Participant participant) { + var id = participant.getParticipantId(); + if (participantStatusCounter.isFault(id)) { + LOGGER.debug("report Participant fault"); + return; + } + if (participantStatusCounter.getDuration(id) > participantStatusCounter.getMaxWaitMs() + && !participantStatusCounter.count(id)) { + LOGGER.debug("report Participant fault"); + participantStatusCounter.setFault(id); + participant.setParticipantState(ParticipantState.OFF_LINE); + participantProvider.updateParticipant(participant); + } + } + + /** + * handle participant Status message. + */ + public void handleParticipantStatus(UUID id) { + participantStatusCounter.clear(id); + } +} diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java index 68ec44dc0..7ee7267e2 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java @@ -29,13 +29,11 @@ import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionDeployPublisher; import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.clamp.models.acm.concepts.Participant; -import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils; import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; -import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; +import org.onap.policy.clamp.models.acm.utils.AcmUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,15 +47,12 @@ public class SupervisionScanner { private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionScanner.class); private final HandleCounter<UUID> automationCompositionCounter = new HandleCounter<>(); - private final HandleCounter<UUID> participantStatusCounter = new HandleCounter<>(); - private final Map<UUID, Integer> phaseMap = new HashMap<>(); private final AutomationCompositionProvider automationCompositionProvider; private final AcDefinitionProvider acDefinitionProvider; private final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher; private final AutomationCompositionDeployPublisher automationCompositionDeployPublisher; - private final ParticipantProvider participantProvider; /** * Constructor for instantiating SupervisionScanner. @@ -66,29 +61,22 @@ public class SupervisionScanner { * @param acDefinitionProvider the Policy Models Provider * @param automationCompositionStateChangePublisher the AutomationComposition StateChange Publisher * @param automationCompositionDeployPublisher the AutomationCompositionUpdate Publisher - * @param participantProvider the Participant Provider * @param acRuntimeParameterGroup the parameters for the automation composition runtime */ public SupervisionScanner(final AutomationCompositionProvider automationCompositionProvider, - AcDefinitionProvider acDefinitionProvider, - final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher, - AutomationCompositionDeployPublisher automationCompositionDeployPublisher, - ParticipantProvider participantProvider, - final AcRuntimeParameterGroup acRuntimeParameterGroup) { + final AcDefinitionProvider acDefinitionProvider, + final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher, + final AutomationCompositionDeployPublisher automationCompositionDeployPublisher, + final AcRuntimeParameterGroup acRuntimeParameterGroup) { this.automationCompositionProvider = automationCompositionProvider; this.acDefinitionProvider = acDefinitionProvider; this.automationCompositionStateChangePublisher = automationCompositionStateChangePublisher; this.automationCompositionDeployPublisher = automationCompositionDeployPublisher; - this.participantProvider = participantProvider; automationCompositionCounter.setMaxRetryCount( - acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount()); + acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount()); automationCompositionCounter - .setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs()); - - participantStatusCounter.setMaxRetryCount( - acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount()); - participantStatusCounter.setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs()); + .setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs()); } /** @@ -99,12 +87,6 @@ public class SupervisionScanner { public void run(boolean counterCheck) { LOGGER.debug("Scanning automation compositions in the database . . ."); - if (counterCheck) { - for (var participant : participantProvider.getParticipants()) { - scanParticipantStatus(participant); - } - } - var list = acDefinitionProvider.getAllAcDefinitions(); for (var acDefinition : list) { var acList = automationCompositionProvider.getAcInstancesByCompositionId(acDefinition.getCompositionId()); @@ -116,33 +98,12 @@ public class SupervisionScanner { LOGGER.debug("Automation composition scan complete . . ."); } - private void scanParticipantStatus(Participant participant) { - var id = participant.getParticipantId(); - if (participantStatusCounter.isFault(id)) { - LOGGER.debug("report Participant fault"); - return; - } - if (participantStatusCounter.getDuration(id) > participantStatusCounter.getMaxWaitMs() - && !participantStatusCounter.count(id)) { - LOGGER.debug("report Participant fault"); - participantStatusCounter.setFault(id); - participant.setParticipantState(ParticipantState.OFF_LINE); - participantProvider.updateParticipant(participant); - } - } - - /** - * handle participant Status message. - */ - public void handleParticipantStatus(UUID id) { - participantStatusCounter.clear(id); - } - private void scanAutomationComposition(final AutomationComposition automationComposition, - ToscaServiceTemplate toscaServiceTemplate, boolean counterCheck) { + ToscaServiceTemplate serviceTemplate, boolean counterCheck) { LOGGER.debug("scanning automation composition {} . . .", automationComposition.getInstanceId()); - if (automationComposition.getState().equals(automationComposition.getOrderedState().asState())) { + if (!AcmUtils.isInTransitionalState(automationComposition.getDeployState(), + automationComposition.getLockState())) { LOGGER.debug("automation composition {} scanned, OK", automationComposition.getInstanceId()); // Clear missed report counter on automation composition @@ -156,12 +117,12 @@ public class SupervisionScanner { var defaultMin = 1000; // min startPhase var defaultMax = 0; // max startPhase for (var element : automationComposition.getElements().values()) { - var toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates() - .get(element.getDefinition().getName()); + var toscaNodeTemplate = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates() + .get(element.getDefinition().getName()); int startPhase = ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties()); defaultMin = Math.min(defaultMin, startPhase); defaultMax = Math.max(defaultMax, startPhase); - if (!element.getState().equals(element.getOrderedState().asState())) { + if (AcmUtils.isInTransitionalState(element.getDeployState(), element.getLockState())) { completed = false; minSpNotCompleted = Math.min(minSpNotCompleted, startPhase); maxSpNotCompleted = Math.max(maxSpNotCompleted, startPhase); @@ -169,36 +130,35 @@ public class SupervisionScanner { } if (completed) { - LOGGER.debug("automation composition scan: transition from state {} to {} completed", - automationComposition.getState(), automationComposition.getOrderedState()); + LOGGER.debug("automation composition scan: transition state {} {} ", automationComposition.getDeployState(), + automationComposition.getLockState()); - automationComposition.setState(automationComposition.getOrderedState().asState()); + var deployState = automationComposition.getDeployState(); + automationComposition.setDeployState(AcmUtils.deployCompleted(deployState)); + automationComposition + .setLockState(AcmUtils.lockCompleted(deployState, automationComposition.getLockState())); automationCompositionProvider.updateAutomationComposition(automationComposition); // Clear missed report counter on automation composition clearFaultAndCounter(automationComposition); } else { LOGGER.debug("automation composition scan: transition from state {} to {} not completed", - automationComposition.getState(), automationComposition.getOrderedState()); + automationComposition.getDeployState(), automationComposition.getLockState()); - var nextSpNotCompleted = - AutomationCompositionState.UNINITIALISED2PASSIVE.equals(automationComposition.getState()) - || AutomationCompositionState.PASSIVE2RUNNING.equals(automationComposition.getState()) - ? minSpNotCompleted - : maxSpNotCompleted; + var isForward = + AcmUtils.isForward(automationComposition.getDeployState(), automationComposition.getLockState()); - var firstStartPhase = - AutomationCompositionState.UNINITIALISED2PASSIVE.equals(automationComposition.getState()) - || AutomationCompositionState.PASSIVE2RUNNING.equals(automationComposition.getState()) - ? defaultMin - : defaultMax; + var nextSpNotCompleted = isForward ? minSpNotCompleted : maxSpNotCompleted; + var firstStartPhase = isForward ? defaultMin : defaultMax; if (nextSpNotCompleted != phaseMap.getOrDefault(automationComposition.getInstanceId(), firstStartPhase)) { phaseMap.put(automationComposition.getInstanceId(), nextSpNotCompleted); - sendAutomationCompositionMsg(automationComposition, nextSpNotCompleted); + sendAutomationCompositionMsg(automationComposition, serviceTemplate, nextSpNotCompleted, + firstStartPhase == nextSpNotCompleted); } else if (counterCheck) { phaseMap.put(automationComposition.getInstanceId(), nextSpNotCompleted); - handleCounter(automationComposition, nextSpNotCompleted); + handleCounter(automationComposition, serviceTemplate, nextSpNotCompleted, + firstStartPhase == nextSpNotCompleted); } } } @@ -208,7 +168,8 @@ public class SupervisionScanner { phaseMap.remove(automationComposition.getInstanceId()); } - private void handleCounter(AutomationComposition automationComposition, int startPhase) { + private void handleCounter(AutomationComposition automationComposition, ToscaServiceTemplate serviceTemplate, + int startPhase, boolean firstStartPhase) { var instanceId = automationComposition.getInstanceId(); if (automationCompositionCounter.isFault(instanceId)) { LOGGER.debug("report AutomationComposition fault"); @@ -218,7 +179,7 @@ public class SupervisionScanner { if (automationCompositionCounter.getDuration(instanceId) > automationCompositionCounter.getMaxWaitMs()) { if (automationCompositionCounter.count(instanceId)) { phaseMap.put(instanceId, startPhase); - sendAutomationCompositionMsg(automationComposition, startPhase); + sendAutomationCompositionMsg(automationComposition, serviceTemplate, startPhase, firstStartPhase); } else { LOGGER.debug("report AutomationComposition fault"); automationCompositionCounter.setFault(instanceId); @@ -226,13 +187,15 @@ public class SupervisionScanner { } } - private void sendAutomationCompositionMsg(AutomationComposition automationComposition, int startPhase) { - if (AutomationCompositionState.UNINITIALISED2PASSIVE.equals(automationComposition.getState())) { + private void sendAutomationCompositionMsg(AutomationComposition automationComposition, + ToscaServiceTemplate serviceTemplate, int startPhase, boolean firstStartPhase) { + if (DeployState.DEPLOYING.equals(automationComposition.getDeployState())) { LOGGER.debug("retry message AutomationCompositionUpdate"); - automationCompositionDeployPublisher.send(automationComposition, startPhase); + automationCompositionDeployPublisher.send(automationComposition, serviceTemplate, startPhase, + firstStartPhase); } else { LOGGER.debug("retry message AutomationCompositionStateChange"); - automationCompositionStateChangePublisher.send(automationComposition, startPhase); + automationCompositionStateChangePublisher.send(automationComposition, startPhase, firstStartPhase); } } } diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java index cc4a05939..2628f030d 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java @@ -36,7 +36,6 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; -import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider; import org.onap.policy.clamp.models.acm.utils.AcmUtils; import org.onap.policy.models.base.PfUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @@ -53,53 +52,13 @@ import org.springframework.stereotype.Component; public class AutomationCompositionDeployPublisher extends AbstractParticipantPublisher<AutomationCompositionDeploy> { private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionDeployPublisher.class); - private final AcDefinitionProvider acDefinitionProvider; - - /** - * Send AutomationCompositionDeploy to Participant. - * - * @param automationComposition the AutomationComposition - */ - @Timed(value = "publisher.automation_composition_deploy", - description = "AUTOMATION_COMPOSITION_DEPLOY messages published") - public void send(AutomationComposition automationComposition) { - send(automationComposition, 0); - } - - /** - * Send AutomationCompositionDeploy to Participant. - * - * @param automationComposition the AutomationComposition - * @param startPhase the Start Phase - */ - @Timed(value = "publisher.automation_composition_deploy", - description = "AUTOMATION_COMPOSITION_DEPLOY messages published") - public void send(AutomationComposition automationComposition, int startPhase) { - var acDeployMsg = new AutomationCompositionDeploy(); - acDeployMsg.setCompositionId(automationComposition.getCompositionId()); - acDeployMsg.setStartPhase(startPhase); - acDeployMsg.setAutomationCompositionId(automationComposition.getInstanceId()); - acDeployMsg.setMessageId(UUID.randomUUID()); - acDeployMsg.setTimestamp(Instant.now()); - var toscaServiceTemplate = - acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId()).getServiceTemplate(); - - List<ParticipantDeploy> participantDeploys = new ArrayList<>(); - for (var element : automationComposition.getElements().values()) { - element.setToscaServiceTemplateFragment(AcmUtils.getToscaServiceTemplateFragment(toscaServiceTemplate)); - AcmUtils.prepareParticipantUpdate(element, participantDeploys); - } - acDeployMsg.setParticipantUpdatesList(participantDeploys); - - LOGGER.debug("AutomationCompositionDeploy message sent {}", acDeployMsg); - super.send(acDeployMsg); - } /** * Send AutomationCompositionDeploy to Participant. * * @param automationComposition the AutomationComposition * @param startPhase the Start Phase + * @param firstStartPhase true if the first StartPhase */ @Timed(value = "publisher.automation_composition_deploy", description = "AUTOMATION_COMPOSITION_DEPLOY messages published") diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangePublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangePublisher.java index 56a62e13b..e59c2ac18 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangePublisher.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangePublisher.java @@ -24,8 +24,7 @@ import io.micrometer.core.annotation.Timed; import java.util.UUID; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder; +import org.onap.policy.clamp.models.acm.utils.AcmUtils; import org.springframework.stereotype.Component; /** @@ -36,7 +35,7 @@ public class AutomationCompositionStateChangePublisher extends AbstractParticipantPublisher<AutomationCompositionStateChange> { /** - * Send undeploy message to to Participant. + * Send AutomationCompositionStateChange message to to Participant. * * @param automationComposition the AutomationComposition * @param startPhase the startPhase @@ -44,75 +43,16 @@ public class AutomationCompositionStateChangePublisher @Timed( value = "publisher.automation_composition_state_change", description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published") - public void undeploy(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase) { - send(automationComposition, startPhase, firstStartPhase, DeployOrder.UNDEPLOY, LockOrder.NONE); - } - - /** - * Send unlock message to to Participant. - * - * @param automationComposition the AutomationComposition - * @param startPhase the startPhase - */ - @Timed( - value = "publisher.automation_composition_state_change", - description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published") - public void unlock(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase) { - send(automationComposition, startPhase, firstStartPhase, DeployOrder.NONE, LockOrder.UNLOCK); - } - - /** - * Send lock message to to Participant. - * - * @param automationComposition the AutomationComposition - * @param startPhase the startPhase - */ - @Timed( - value = "publisher.automation_composition_state_change", - description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published") - public void lock(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase) { - send(automationComposition, startPhase, firstStartPhase, DeployOrder.NONE, LockOrder.LOCK); - } - - /** - * Send undeploy message to to Participant. - * - * @param automationComposition the AutomationComposition - * @param startPhase the startPhase - * @param deployOrder the DeployOrder - * @param lockOrder the LockOrder - */ - private void send(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase, - DeployOrder deployOrder, LockOrder lockOrder) { + public void send(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase) { var acsc = new AutomationCompositionStateChange(); acsc.setCompositionId(automationComposition.getCompositionId()); acsc.setAutomationCompositionId(automationComposition.getInstanceId()); acsc.setMessageId(UUID.randomUUID()); - acsc.setDeployOrderedState(deployOrder); - acsc.setLockOrderedState(lockOrder); + acsc.setDeployOrderedState(AcmUtils.stateDeployToOrder(automationComposition.getDeployState())); + acsc.setLockOrderedState(AcmUtils.stateLockToOrder(automationComposition.getLockState())); acsc.setStartPhase(startPhase); acsc.setFirstStartPhase(firstStartPhase); super.send(acsc); } - - /** - * Send AutomationCompositionStateChange to Participant. - * - * @param automationComposition the AutomationComposition - * @param startPhase the startPhase - */ - @Timed( - value = "publisher.automation_composition_state_change", - description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published") - public void send(AutomationComposition automationComposition, int startPhase) { - var acsc = new AutomationCompositionStateChange(); - acsc.setCompositionId(automationComposition.getCompositionId()); - acsc.setAutomationCompositionId(automationComposition.getInstanceId()); - acsc.setMessageId(UUID.randomUUID()); - acsc.setOrderedState(automationComposition.getOrderedState()); - acsc.setStartPhase(startPhase); - - super.send(acsc); - } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java index fb285a84c..153f7a0e0 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java @@ -21,9 +21,12 @@ package org.onap.policy.clamp.acm.runtime.supervision; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML; import java.util.Map; import java.util.Optional; @@ -34,6 +37,7 @@ import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionD import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher; import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.models.acm.concepts.AcElementDeployAck; +import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; @@ -97,4 +101,55 @@ class SupervisionAcHandlerTest { verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); } + + @Test + void testUndeploy() { + var automationCompositionProvider = mock(AutomationCompositionProvider.class); + var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); + var handler = new SupervisionAcHandler(automationCompositionProvider, + mock(AutomationCompositionDeployPublisher.class), + acStateChangePublisher); + var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); + var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); + var automationComposition = + InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Undeploy"); + handler.undeploy(automationComposition, acDefinition); + + verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); + verify(acStateChangePublisher).send(any(AutomationComposition.class), anyInt(), anyBoolean()); + } + + @Test + void testUnlock() { + var automationCompositionProvider = mock(AutomationCompositionProvider.class); + var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); + var handler = new SupervisionAcHandler(automationCompositionProvider, + mock(AutomationCompositionDeployPublisher.class), + acStateChangePublisher); + var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); + var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); + var automationComposition = + InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "UnLock"); + handler.unlock(automationComposition, acDefinition); + + verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); + verify(acStateChangePublisher).send(any(AutomationComposition.class), anyInt(), anyBoolean()); + } + + @Test + void testLock() { + var automationCompositionProvider = mock(AutomationCompositionProvider.class); + var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); + var handler = new SupervisionAcHandler(automationCompositionProvider, + mock(AutomationCompositionDeployPublisher.class), + acStateChangePublisher); + var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); + var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); + var automationComposition = + InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Lock"); + handler.lock(automationComposition, acDefinition); + + verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); + verify(acStateChangePublisher).send(any(AutomationComposition.class), anyInt(), anyBoolean()); + } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java index b913cfac9..c9985e203 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java @@ -34,16 +34,19 @@ class SupervisionAspectTest { @Test void testSchedule() throws Exception { var supervisionScanner = mock(SupervisionScanner.class); - try (var supervisionAspect = new SupervisionAspect(supervisionScanner)) { + var partecipantScanner = mock(SupervisionPartecipantScanner.class); + try (var supervisionAspect = new SupervisionAspect(supervisionScanner, partecipantScanner)) { supervisionAspect.schedule(); verify(supervisionScanner, timeout(500)).run(true); + verify(partecipantScanner, timeout(500)).run(); } } @Test void testDoCheck() throws Exception { var supervisionScanner = mock(SupervisionScanner.class); - try (var supervisionAspect = new SupervisionAspect(supervisionScanner)) { + var partecipantScanner = mock(SupervisionPartecipantScanner.class); + try (var supervisionAspect = new SupervisionAspect(supervisionScanner, partecipantScanner)) { supervisionAspect.doCheck(); supervisionAspect.doCheck(); verify(supervisionScanner, timeout(500).times(2)).run(false); @@ -56,9 +59,10 @@ class SupervisionAspectTest { participantStatusMessage.setParticipantId(CommonTestData.getParticipantId()); var supervisionScanner = mock(SupervisionScanner.class); - try (var supervisionAspect = new SupervisionAspect(supervisionScanner)) { + var partecipantScanner = mock(SupervisionPartecipantScanner.class); + try (var supervisionAspect = new SupervisionAspect(supervisionScanner, partecipantScanner)) { supervisionAspect.handleParticipantStatus(participantStatusMessage); - verify(supervisionScanner, timeout(500)).handleParticipantStatus(CommonTestData.getParticipantId()); + verify(partecipantScanner, timeout(500)).handleParticipantStatus(CommonTestData.getParticipantId()); } } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java new file mode 100644 index 000000000..3ad9f813c --- /dev/null +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * 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.clamp.acm.runtime.supervision; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.List; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.acm.runtime.util.CommonTestData; +import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; +import org.onap.policy.models.base.PfModelException; + +class SupervisionParticipantScannerTest { + + @Test + void testScanParticipant() throws PfModelException { + var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanParticipant"); + acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().setMaxWaitMs(-1); + acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1); + + var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId()); + participant.setParticipantState(ParticipantState.OFF_LINE); + var participantProvider = mock(ParticipantProvider.class); + when(participantProvider.getParticipants()).thenReturn(List.of(participant)); + + var supervisionScanner = new SupervisionPartecipantScanner(participantProvider, acRuntimeParameterGroup); + + supervisionScanner.handleParticipantStatus(participant.getParticipantId()); + supervisionScanner.run(); + verify(participantProvider, times(0)).saveParticipant(any()); + + supervisionScanner.run(); + verify(participantProvider, times(1)).updateParticipant(any()); + } +} diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java index fe34c6b04..032468a56 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java @@ -21,6 +21,7 @@ package org.onap.policy.clamp.acm.runtime.supervision; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -39,13 +40,11 @@ import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionS import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.clamp.models.acm.concepts.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; -import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; -import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; class SupervisionScannerTest { @@ -70,16 +69,15 @@ class SupervisionScannerTest { var automationCompositionProvider = mock(AutomationCompositionProvider.class); var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class); - var participantProvider = mock(ParticipantProvider.class); var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud"); when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId)) - .thenReturn(List.of(automationComposition)); + .thenReturn(List.of(automationComposition)); var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider, - automationCompositionStateChangePublisher, automationCompositionDeployPublisher, participantProvider, - acRuntimeParameterGroup); + automationCompositionStateChangePublisher, automationCompositionDeployPublisher, + acRuntimeParameterGroup); supervisionScanner.run(false); verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class)); @@ -88,20 +86,19 @@ class SupervisionScannerTest { @Test void testScannerOrderedStateDifferentToState() { var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud"); - automationComposition.setState(AutomationCompositionState.UNINITIALISED2PASSIVE); - automationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + automationComposition.setDeployState(DeployState.UNDEPLOYING); + automationComposition.setLockState(LockState.NONE); var automationCompositionProvider = mock(AutomationCompositionProvider.class); when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId)) - .thenReturn(List.of(automationComposition)); + .thenReturn(List.of(automationComposition)); var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class); var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); - var participantProvider = mock(ParticipantProvider.class); var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider, - automationCompositionStateChangePublisher, automationCompositionDeployPublisher, participantProvider, - acRuntimeParameterGroup); + automationCompositionStateChangePublisher, automationCompositionDeployPublisher, + acRuntimeParameterGroup); supervisionScanner.run(false); verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class)); @@ -112,21 +109,16 @@ class SupervisionScannerTest { var automationCompositionProvider = mock(AutomationCompositionProvider.class); var automationComposition = new AutomationComposition(); when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId)) - .thenReturn(List.of(automationComposition)); - - var participantProvider = mock(ParticipantProvider.class); - var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId()); - when(participantProvider.getParticipants()).thenReturn(List.of(participant)); + .thenReturn(List.of(automationComposition)); var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class); var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider, - automationCompositionStateChangePublisher, automationCompositionDeployPublisher, participantProvider, - acRuntimeParameterGroup); + automationCompositionStateChangePublisher, automationCompositionDeployPublisher, + acRuntimeParameterGroup); - supervisionScanner.handleParticipantStatus(participant.getParticipantId()); supervisionScanner.run(true); verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class)); } @@ -134,65 +126,68 @@ class SupervisionScannerTest { @Test void testSendAutomationCompositionMsgUpdate() { var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud"); - automationComposition.setState(AutomationCompositionState.UNINITIALISED2PASSIVE); - automationComposition.setOrderedState(AutomationCompositionOrderedState.PASSIVE); + automationComposition.setDeployState(DeployState.DEPLOYING); + automationComposition.setLockState(LockState.NONE); for (var element : automationComposition.getElements().values()) { if ("org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement" - .equals(element.getDefinition().getName())) { - element.setOrderedState(AutomationCompositionOrderedState.PASSIVE); - element.setState(AutomationCompositionState.UNINITIALISED); + .equals(element.getDefinition().getName())) { + element.setDeployState(DeployState.DEPLOYING); + element.setLockState(LockState.NONE); } else { - element.setOrderedState(AutomationCompositionOrderedState.PASSIVE); - element.setState(AutomationCompositionState.PASSIVE); + element.setDeployState(DeployState.DEPLOYED); + element.setLockState(LockState.LOCKED); } } var automationCompositionProvider = mock(AutomationCompositionProvider.class); when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId)) - .thenReturn(List.of(automationComposition)); + .thenReturn(List.of(automationComposition)); - var participantProvider = mock(ParticipantProvider.class); var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class); var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider, - automationCompositionStateChangePublisher, automationCompositionDeployPublisher, participantProvider, - acRuntimeParameterGroup); + automationCompositionStateChangePublisher, automationCompositionDeployPublisher, + acRuntimeParameterGroup); supervisionScanner.run(false); - verify(automationCompositionDeployPublisher).send(any(AutomationComposition.class), anyInt()); + verify(automationCompositionDeployPublisher).send(any(AutomationComposition.class), + any(ToscaServiceTemplate.class), anyInt(), anyBoolean()); } @Test - void testScanParticipant() throws PfModelException { + void testSendAutomationCompositionMsgUnlocking() { + var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud"); + automationComposition.setDeployState(DeployState.DEPLOYED); + automationComposition.setLockState(LockState.UNLOCKING); + for (var element : automationComposition.getElements().values()) { + if ("org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement" + .equals(element.getDefinition().getName())) { + element.setDeployState(DeployState.DEPLOYED); + element.setLockState(LockState.UNLOCKING); + } else { + element.setDeployState(DeployState.DEPLOYED); + element.setLockState(LockState.UNLOCKED); + } + } + var automationCompositionProvider = mock(AutomationCompositionProvider.class); - var automationComposition = new AutomationComposition(); when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId)) - .thenReturn(List.of(automationComposition)); - - var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanParticipant"); - acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().setMaxWaitMs(-1); - acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1); - - var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId()); - participant.setParticipantState(ParticipantState.OFF_LINE); - var participantProvider = mock(ParticipantProvider.class); - when(participantProvider.getParticipants()).thenReturn(List.of(participant)); + .thenReturn(List.of(automationComposition)); var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class); var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); + var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider, - automationCompositionStateChangePublisher, automationCompositionDeployPublisher, participantProvider, - acRuntimeParameterGroup); + automationCompositionStateChangePublisher, automationCompositionDeployPublisher, + acRuntimeParameterGroup); - supervisionScanner.handleParticipantStatus(participant.getParticipantId()); - supervisionScanner.run(true); - verify(participantProvider, times(0)).saveParticipant(any()); + supervisionScanner.run(false); - supervisionScanner.run(true); - verify(participantProvider, times(1)).updateParticipant(any()); + verify(automationCompositionStateChangePublisher).send(any(AutomationComposition.class), anyInt(), + anyBoolean()); } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java index 0072a1042..e0accc4a0 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java @@ -42,7 +42,8 @@ import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.clamp.models.acm.concepts.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck; @@ -117,14 +118,15 @@ class SupervisionMessagesTest { @Test void testSendAutomationCompositionStateChangePublisherNotActive() { var publisher = new AutomationCompositionStateChangePublisher(); - assertThatThrownBy(() -> publisher.send(getAutomationComposition(), 0)).hasMessage(NOT_ACTIVE); + assertThatThrownBy(() -> publisher.send(getAutomationComposition(), 0, true)).hasMessage(NOT_ACTIVE); } private AutomationComposition getAutomationComposition() { var automationComposition = new AutomationComposition(); automationComposition.setName("NAME"); automationComposition.setVersion("0.0.1"); - automationComposition.setState(AutomationCompositionState.UNINITIALISED); + automationComposition.setDeployState(DeployState.DEPLOYED); + automationComposition.setLockState(LockState.UNLOCKING); return automationComposition; } @@ -133,7 +135,7 @@ class SupervisionMessagesTest { var publisher = new AutomationCompositionStateChangePublisher(); var topicSink = mock(TopicSink.class); publisher.active(List.of(topicSink)); - publisher.send(getAutomationComposition(), 0); + publisher.send(getAutomationComposition(), 0, true); verify(topicSink).send(anyString()); publisher.stop(); } @@ -152,12 +154,12 @@ class SupervisionMessagesTest { var participantId = UUID.randomUUID(); Map<ToscaConceptIdentifier, UUID> supportedElementMap = new HashMap<>(); supportedElementMap.put( - new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyAutomationCompositionElement", "1.0.1"), + new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyAutomationCompositionElement", "1.0.0"), participantId); supportedElementMap.put(new ToscaConceptIdentifier( - "org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement", "1.0.1"), participantId); + "org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement", "1.0.0"), participantId); supportedElementMap.put( - new ToscaConceptIdentifier("org.onap.policy.clamp.acm.HttpAutomationCompositionElement", "1.0.1"), + new ToscaConceptIdentifier("org.onap.policy.clamp.acm.HttpAutomationCompositionElement", "1.0.0"), participantId); var participantProvider = mock(ParticipantProvider.class); when(participantProvider.getSupportedElementMap()).thenReturn(supportedElementMap); |