diff options
Diffstat (limited to 'participant/participant-impl/participant-impl-a1pms')
3 files changed, 41 insertions, 78 deletions
diff --git a/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java index bcc3fd498..a60e7b4bb 100755 --- a/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java +++ b/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022-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. @@ -36,10 +36,9 @@ import org.onap.policy.clamp.acm.participant.a1pms.models.ConfigurationEntity; import org.onap.policy.clamp.acm.participant.a1pms.webclient.AcA1PmsClient; import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; -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.messages.dmaap.participant.ParticipantMessageType; +import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; +import org.onap.policy.clamp.models.acm.concepts.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; @@ -73,42 +72,20 @@ public class AutomationCompositionElementHandler implements AutomationCompositio * * @param automationCompositionId the ID of the automation composition * @param automationCompositionElementId the ID of the automation composition element - * @param currentState the current state of the automation composition element - * @param newState the state to which the automation composition element is changing to * @throws PfModelException in case of a model exception */ @Override - public void automationCompositionElementStateChange(UUID automationCompositionId, - UUID automationCompositionElementId, AutomationCompositionState currentState, - AutomationCompositionOrderedState newState) throws A1PolicyServiceException { - switch (newState) { - case UNINITIALISED: - var configurationEntity = configRequestMap.get(automationCompositionElementId); - if (configurationEntity != null && acA1PmsClient.isPmsHealthy()) { - acA1PmsClient.deleteService(configurationEntity.getPolicyServiceEntities()); - configRequestMap.remove(automationCompositionElementId); - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, newState, AutomationCompositionState.UNINITIALISED, - ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE); - } else { - LOGGER.warn("Failed to connect with A1PMS. Service configuration is: {}", configurationEntity); - throw new A1PolicyServiceException(HttpStatus.SC_SERVICE_UNAVAILABLE, - "Unable to connect with A1PMS"); - } - break; - case PASSIVE: - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, newState, AutomationCompositionState.PASSIVE, - ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE); - break; - case RUNNING: - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, newState, AutomationCompositionState.RUNNING, - ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE); - break; - default: - LOGGER.warn("Cannot transition from state {} to state {}", currentState, newState); - break; + public void undeploy(UUID automationCompositionId, UUID automationCompositionElementId) + throws A1PolicyServiceException { + var configurationEntity = configRequestMap.get(automationCompositionElementId); + if (configurationEntity != null && acA1PmsClient.isPmsHealthy()) { + acA1PmsClient.deleteService(configurationEntity.getPolicyServiceEntities()); + configRequestMap.remove(automationCompositionElementId); + intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, + automationCompositionElementId, DeployState.UNDEPLOYED, LockState.NONE); + } else { + LOGGER.warn("Failed to connect with A1PMS. Service configuration is: {}", configurationEntity); + throw new A1PolicyServiceException(HttpStatus.SC_SERVICE_UNAVAILABLE, "Unable to connect with A1PMS"); } } @@ -116,24 +93,22 @@ public class AutomationCompositionElementHandler implements AutomationCompositio * Callback method to handle an update on an automation composition element. * * @param automationCompositionId the ID of the automation composition - * @param element the information on the automation composition element + * @param element the information on the automation composition element * @param properties properties Map */ @Override - public void automationCompositionElementUpdate(UUID automationCompositionId, - AutomationCompositionElement element, Map<String, Object> properties) throws A1PolicyServiceException { + public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties) + throws A1PolicyServiceException { try { var configurationEntity = CODER.convert(properties, ConfigurationEntity.class); - var violations = - Validation.buildDefaultValidatorFactory().getValidator().validate(configurationEntity); + var violations = Validation.buildDefaultValidatorFactory().getValidator().validate(configurationEntity); if (violations.isEmpty()) { if (acA1PmsClient.isPmsHealthy()) { acA1PmsClient.createService(configurationEntity.getPolicyServiceEntities()); configRequestMap.put(element.getId(), configurationEntity); intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), - AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.PASSIVE, - ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE); + DeployState.DEPLOYED, LockState.LOCKED); } else { LOGGER.error("Failed to connect with A1PMS"); throw new A1PolicyServiceException(HttpStatus.SC_SERVICE_UNAVAILABLE, diff --git a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java index ce775b616..a39076697 100755 --- a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022-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. @@ -39,8 +39,6 @@ import org.onap.policy.clamp.acm.participant.a1pms.utils.CommonTestData; import org.onap.policy.clamp.acm.participant.a1pms.utils.ToscaUtils; import org.onap.policy.clamp.acm.participant.a1pms.webclient.AcA1PmsClient; import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -79,27 +77,17 @@ class AcElementHandlerTest { var automationCompositionElementId = element.getId(); var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); - automationCompositionElementHandler - .automationCompositionElementUpdate(commonTestData.getAutomationCompositionId(), element, - nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties()); + automationCompositionElementHandler.deploy( + commonTestData.getAutomationCompositionId(), element, + nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties()); - assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementStateChange( - automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE, - AutomationCompositionOrderedState.PASSIVE)); - - assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementStateChange( - automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE, - AutomationCompositionOrderedState.UNINITIALISED)); - - assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementStateChange( - automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE, - AutomationCompositionOrderedState.RUNNING)); + assertDoesNotThrow(() -> automationCompositionElementHandler.undeploy( + automationCompositionId, automationCompositionElementId)); when(acA1PmsClient.isPmsHealthy()).thenReturn(Boolean.FALSE); assertThrows(A1PolicyServiceException.class, - () -> automationCompositionElementHandler.automationCompositionElementStateChange( - automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE, - AutomationCompositionOrderedState.UNINITIALISED)); + () -> automationCompositionElementHandler.undeploy( + automationCompositionId, automationCompositionElementId)); } @Test @@ -107,9 +95,9 @@ class AcElementHandlerTest { var element = commonTestData.getAutomationCompositionElement(); var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); - assertDoesNotThrow(() -> automationCompositionElementHandler - .automationCompositionElementUpdate(commonTestData.getAutomationCompositionId(), element, - nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties())); + assertDoesNotThrow(() -> automationCompositionElementHandler.deploy( + commonTestData.getAutomationCompositionId(), element, + nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties())); } @Test @@ -118,8 +106,9 @@ class AcElementHandlerTest { when(acA1PmsClient.isPmsHealthy()).thenReturn(Boolean.FALSE); var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); - assertThrows(A1PolicyServiceException.class, () -> automationCompositionElementHandler - .automationCompositionElementUpdate(commonTestData.getAutomationCompositionId(), element, + assertThrows(A1PolicyServiceException.class, + () -> automationCompositionElementHandler.deploy( + commonTestData.getAutomationCompositionId(), element, nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties())); } @@ -127,7 +116,6 @@ class AcElementHandlerTest { void test_AutomationCompositionElementUpdateWithInvalidConfiguration() { var element = commonTestData.getAutomationCompositionElement(); assertThrows(A1PolicyServiceException.class, () -> automationCompositionElementHandler - .automationCompositionElementUpdate(commonTestData.getAutomationCompositionId(), element, - Map.of())); + .deploy(commonTestData.getAutomationCompositionId(), element, Map.of())); } } diff --git a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonTestData.java b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonTestData.java index b68faa692..d31e81fe8 100755 --- a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonTestData.java +++ b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonTestData.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022-2023 Nordix Foundation. * Modifications Copyright (C) 2022 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,8 +24,8 @@ package org.onap.policy.clamp.acm.participant.a1pms.utils; import java.util.List; import java.util.UUID; import org.onap.policy.clamp.acm.participant.a1pms.models.A1PolicyServiceEntity; -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.AcElementDeploy; +import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; public class CommonTestData { @@ -38,11 +38,11 @@ public class CommonTestData { * * @return automationCompositionElement object */ - public AutomationCompositionElement getAutomationCompositionElement() { - var element = new AutomationCompositionElement(); + public AcElementDeploy getAutomationCompositionElement() { + var element = new AcElementDeploy(); element.setId(UUID.randomUUID()); element.setDefinition(new ToscaConceptIdentifier(TEST_KEY_NAME, "1.0.1")); - element.setOrderedState(AutomationCompositionOrderedState.PASSIVE); + element.setOrderedState(DeployOrder.DEPLOY); return element; } |