diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-05-10 17:11:04 +0100 |
---|---|---|
committer | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-05-16 08:19:07 +0100 |
commit | 722523f568a682f1e48f6998c24c945802fec782 (patch) | |
tree | ffe6e47aa4c339023772a15d816af8b509b8142e | |
parent | b4b9a1f3c81a1c64271e38d879a84f6b134d3a54 (diff) |
Add participant capability to send message with status and properties
Add participant capability to send message with status and properties
to ACM-R when those values need to be change.
Issue-ID: POLICY-4679
Change-Id: Idca5796c199b235e1f829097316c50688a351e80
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
19 files changed, 269 insertions, 290 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementInfo.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementInfo.java index 1eb4bf8cb..9d8fd72ae 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementInfo.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementInfo.java @@ -20,10 +20,14 @@ package org.onap.policy.clamp.models.acm.concepts; +import java.util.LinkedHashMap; +import java.util.Map; import java.util.UUID; +import java.util.function.UnaryOperator; import lombok.Data; import lombok.NoArgsConstructor; import lombok.ToString; +import org.onap.policy.models.base.PfUtils; /** * Class to represent a automation composition element info instance. @@ -43,6 +47,8 @@ public class AutomationCompositionElementInfo { private String useState; + private Map<String, Object> statusProperties = new LinkedHashMap<>(); + /** * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy. * @@ -54,5 +60,6 @@ public class AutomationCompositionElementInfo { this.lockState = otherElement.lockState; this.operationalState = otherElement.operationalState; this.useState = otherElement.useState; + this.statusProperties = PfUtils.mapMap(otherElement.statusProperties, UnaryOperator.identity()); } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java index 959fd7637..94693fd0b 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java @@ -203,6 +203,7 @@ public class AutomationCompositionProvider { var jpa = acElementRepository.getReferenceById(element.getAutomationCompositionElementId().toString()); jpa.setUseState(element.getUseState()); jpa.setOperationalState(element.getOperationalState()); + jpa.setProperties(element.getStatusProperties()); jpaList.add(jpa); } } 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 a60e7b4bb..8401b934b 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 @@ -38,7 +38,6 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationComposit import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; 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; @@ -82,7 +81,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio acA1PmsClient.deleteService(configurationEntity.getPolicyServiceEntities()); configRequestMap.remove(automationCompositionElementId); intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, DeployState.UNDEPLOYED, LockState.NONE); + automationCompositionElementId, DeployState.UNDEPLOYED, null, "Undeployed"); } else { LOGGER.warn("Failed to connect with A1PMS. Service configuration is: {}", configurationEntity); throw new A1PolicyServiceException(HttpStatus.SC_SERVICE_UNAVAILABLE, "Unable to connect with A1PMS"); @@ -108,7 +107,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio configRequestMap.put(element.getId(), configurationEntity); intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), - DeployState.DEPLOYED, LockState.LOCKED); + DeployState.DEPLOYED, null, "Deployed"); } else { LOGGER.error("Failed to connect with A1PMS"); throw new A1PolicyServiceException(HttpStatus.SC_SERVICE_UNAVAILABLE, diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java index 0568d3b98..f294d47ff 100644 --- a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java +++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java @@ -41,7 +41,6 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationComposit import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; 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; @@ -78,7 +77,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio @Override public void undeploy(UUID automationCompositionId, UUID automationCompositionElementId) { intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, automationCompositionElementId, - DeployState.UNDEPLOYED, LockState.NONE); + DeployState.UNDEPLOYED, null, ""); } /** @@ -99,7 +98,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio .collect(Collectors.toList()); if (failedResponseStatus.isEmpty()) { intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), - DeployState.DEPLOYED, LockState.LOCKED); + DeployState.DEPLOYED, null, "Deployed"); } else { throw new PfModelException(Status.BAD_REQUEST, "Error on Invoking the http request: {}", failedResponseStatus); diff --git a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java index e48fdf91c..e0d6c805f 100644 --- a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java @@ -37,7 +37,6 @@ import org.onap.policy.clamp.acm.participant.http.utils.CommonTestData; import org.onap.policy.clamp.acm.participant.http.utils.ToscaUtils; import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; import org.onap.policy.clamp.models.acm.concepts.DeployState; -import org.onap.policy.clamp.models.acm.concepts.LockState; class AcElementHandlerTest { @@ -57,7 +56,7 @@ class AcElementHandlerTest { automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi); automationCompositionElementHandler.undeploy(instanceId, acElementId); verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, acElementId, - DeployState.UNDEPLOYED, LockState.NONE); + DeployState.UNDEPLOYED, null, ""); } } @@ -90,7 +89,7 @@ class AcElementHandlerTest { automationCompositionElementHandler.deploy(instanceId, element, map); verify(acHttpClient).run(any(ConfigRequest.class), anyMap()); verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), - DeployState.DEPLOYED, LockState.LOCKED); + DeployState.DEPLOYED, null, "Deployed"); } } diff --git a/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java index a6e1c9cbc..6fdb16e53 100755 --- a/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java +++ b/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java @@ -46,7 +46,6 @@ import org.onap.policy.clamp.acm.participant.kserve.models.ConfigurationEntity; import org.onap.policy.clamp.acm.participant.kserve.models.KserveInferenceEntity; 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; @@ -94,7 +93,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio } configRequestMap.remove(automationCompositionElementId); intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, DeployState.UNDEPLOYED, LockState.NONE); + automationCompositionElementId, DeployState.UNDEPLOYED, null, "Undeployed"); } catch (IOException | ApiException exception) { LOGGER.warn("Deletion of Inference service failed", exception); } @@ -131,7 +130,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio if (isAllInferenceSvcDeployed) { configRequestMap.put(element.getId(), configurationEntity); intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), - DeployState.DEPLOYED, LockState.LOCKED); + DeployState.DEPLOYED, null, "Deployed"); } else { LOGGER.error("Inference Service deployment failed"); } diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java index b681ba91d..2f1abe1c0 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java +++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java @@ -33,7 +33,6 @@ import javax.ws.rs.core.Response; import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; -import net.bytebuddy.implementation.bytecode.Throw; 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.acm.participant.kubernetes.exception.ServiceException; @@ -42,7 +41,6 @@ import org.onap.policy.clamp.acm.participant.kubernetes.models.ChartInfo; import org.onap.policy.clamp.acm.participant.kubernetes.service.ChartService; 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; @@ -95,7 +93,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio try { chartService.uninstallChart(chart); intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, DeployState.UNDEPLOYED, LockState.NONE); + automationCompositionElementId, DeployState.UNDEPLOYED, null, "Undeployed"); chartMap.remove(automationCompositionElementId); podStatusMap.remove(chart.getReleaseName()); } catch (ServiceException se) { @@ -150,7 +148,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio if (!result.get().isEmpty()) { LOGGER.info("Pod Status Validator Completed: {}", result.isDone()); intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, elementId, - DeployState.DEPLOYED, LockState.LOCKED); + DeployState.DEPLOYED, null, "Deployed"); } } } diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java index d40ac3276..627f79131 100644 --- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java +++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java @@ -37,7 +37,6 @@ import org.onap.policy.clamp.acm.participant.policy.client.PolicyApiHttpClient; import org.onap.policy.clamp.acm.participant.policy.client.PolicyPapHttpClient; 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.models.base.PfModelException; import org.onap.policy.models.pdp.concepts.DeploymentSubGroup; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @@ -75,7 +74,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio if (automationCompositionDefinition == null) { LOGGER.debug("No policies to undeploy to {}", automationCompositionElementId); intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, DeployState.UNDEPLOYED, LockState.NONE); + automationCompositionElementId, DeployState.UNDEPLOYED, null, "Undeployed"); return; } var policyList = getPolicyList(automationCompositionDefinition); @@ -84,7 +83,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio deletePolicyData(policyTypeList, policyList); serviceTemplateMap.remove(automationCompositionElementId); intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, DeployState.UNDEPLOYED, LockState.NONE); + automationCompositionElementId, DeployState.UNDEPLOYED, null, "Undeployed"); } private void deletePolicyData(List<ToscaConceptIdentifier> policyTypeList, @@ -117,8 +116,10 @@ public class AutomationCompositionElementHandler implements AutomationCompositio } if (!deployFailure) { // Update the AC element state + intermediaryApi.sendAcElementInfo(automationCompositionId, automationCompositionElementId, "IDLE", + "ENABLED", Map.of()); intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, DeployState.DEPLOYED, LockState.LOCKED); + automationCompositionElementId, DeployState.DEPLOYED, null, "Deployed"); } else { throw new PfModelException(Status.BAD_REQUEST, "Deploy of Policy failed."); } @@ -201,16 +202,4 @@ public class AutomationCompositionElementHandler implements AutomationCompositio return policyList; } - - @Override - public String getUseState(UUID automationCompositionId, UUID automationCompositionElementId) - throws PfModelException { - return "IDLE"; - } - - @Override - public String getOperationalState(UUID automationCompositionId, UUID automationCompositionElementId) - throws PfModelException { - return "ENABLED"; - } } diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java index ecc0b88e7..d3b27ae10 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java @@ -21,7 +21,6 @@ package org.onap.policy.clamp.acm.participant.policy.main.handler; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -37,7 +36,6 @@ import org.onap.policy.clamp.acm.participant.policy.client.PolicyApiHttpClient; import org.onap.policy.clamp.acm.participant.policy.client.PolicyPapHttpClient; 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.clamp.models.acm.messages.rest.instantiation.DeployOrder; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @@ -63,7 +61,7 @@ class AutomationCompositionElementHandlerTest { handler.undeploy(AC_ID, automationCompositionElementId); verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId, - DeployState.UNDEPLOYED, LockState.NONE); + DeployState.UNDEPLOYED, null, "Undeployed"); } private AcElementDeploy getTestingAcElement() { @@ -94,9 +92,8 @@ class AutomationCompositionElementHandlerTest { handler.setIntermediaryApi(intermediaryApi); handler.deploy(AC_ID, getTestingAcElement(), Map.of()); - handler.undeploy(AC_ID, automationCompositionElementId); verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId, - DeployState.UNDEPLOYED, LockState.NONE); + DeployState.DEPLOYED, null, "Deployed"); } @Test @@ -134,22 +131,4 @@ class AutomationCompositionElementHandlerTest { assertThatThrownBy(() -> handler.deploy(AC_ID, element, Map.of())) .hasMessageMatching("Deploy of Policy failed."); } - - @Test - void testGetOperationalState() throws PfModelException { - var api = mock(PolicyApiHttpClient.class); - var pap = mock(PolicyPapHttpClient.class); - var handler = new AutomationCompositionElementHandler(api, pap); - - assertEquals("ENABLED", handler.getOperationalState(UUID.randomUUID(), UUID.randomUUID())); - } - - @Test - void testGetUseState() throws PfModelException { - var api = mock(PolicyApiHttpClient.class); - var pap = mock(PolicyPapHttpClient.class); - var handler = new AutomationCompositionElementHandler(api, pap); - - assertEquals("IDLE", handler.getUseState(UUID.randomUUID(), UUID.randomUUID())); - } } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java index a61a6678a..23390699a 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java @@ -57,22 +57,4 @@ public interface AutomationCompositionElementListener { throws PfModelException { // default Unlock Operation } - - public default String getUseState(UUID automationCompositionId, UUID automationCompositionElementId) - throws PfModelException { - // default Use State - return ""; - } - - public default String getOperationalState(UUID automationCompositionId, UUID automationCompositionElementId) - throws PfModelException { - // default Operational State - return ""; - } - - public default Map<String, Object> getStatusProperties(UUID automationCompositionId, - UUID automationCompositionElementId) throws PfModelException { - // default StatusProperties - return Map.of(); - } } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java index 998a63269..509b6ed6e 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java @@ -21,6 +21,7 @@ package org.onap.policy.clamp.acm.participant.intermediary.api; +import java.util.Map; import java.util.UUID; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; @@ -41,9 +42,24 @@ public interface ParticipantIntermediaryApi { /** * Update the state of a automation composition element. * + * @param automationCompositionId the ID of the automation composition to update the state on * @param id the ID of the automation composition element to update the state on - * @param newState the state of the automation composition element + * @param deployState the Deploy State of the automation composition element + * @param lockState the Lock State of the automation composition element + * @param message the message */ - void updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, DeployState newState, - LockState lockState); + void updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, DeployState deployState, + LockState lockState, String message); + + /** + * Send Automation Composition Element update Info to AC-runtime. + * + * @param automationCompositionId the ID of the automation composition to update the states + * @param id the ID of the automation composition element to update the states + * @param useState the use State + * @param operationalState the operational State + * @param statusProperties the status Properties Map + */ + void sendAcElementInfo(UUID automationCompositionId, UUID id, String useState, String operationalState, + Map<String, Object> statusProperties); } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java index d729a097f..20f222ab3 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java @@ -21,6 +21,7 @@ package org.onap.policy.clamp.acm.participant.intermediary.api.impl; +import java.util.Map; import java.util.UUID; import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; @@ -55,8 +56,15 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp @Override public void updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, DeployState newState, - LockState lockState) { + LockState lockState, String message) { automationCompositionHandler.updateAutomationCompositionElementState(automationCompositionId, id, newState, - lockState); + lockState, message); + } + + @Override + public void sendAcElementInfo(UUID automationCompositionId, UUID elementId, String useState, + String operationalState, Map<String, Object> statusProperties) { + automationCompositionHandler.sendAcElementInfo(automationCompositionId, elementId, useState, operationalState, + statusProperties); } } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java index f918ed12c..e35582058 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java @@ -21,7 +21,6 @@ package org.onap.policy.clamp.acm.participant.intermediary.handler; -import com.att.aft.dme2.internal.apache.commons.lang.StringUtils; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; @@ -37,14 +36,19 @@ import org.onap.policy.clamp.models.acm.concepts.AcElementDeployAck; 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.AutomationCompositionElementInfo; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo; 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.concepts.ParticipantState; +import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType; import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus; 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.persistence.provider.AcInstanceStateResolver; @@ -65,16 +69,12 @@ public class AutomationCompositionHandler { private final UUID participantId; private final ParticipantMessagePublisher publisher; private final AcInstanceStateResolver acInstanceStateResolver; + private final List<ParticipantSupportedElementType> supportedAcElementTypes; + private final List<AutomationCompositionElementListener> listeners = new ArrayList<>(); @Getter private final Map<UUID, AutomationComposition> automationCompositionMap = new LinkedHashMap<>(); - @Getter - private final Map<UUID, AutomationCompositionElement> elementsOnThisParticipant = new LinkedHashMap<>(); - - @Getter - private final List<AutomationCompositionElementListener> listeners = new ArrayList<>(); - /** * Constructor, set the participant ID and messageSender. * @@ -85,6 +85,7 @@ public class AutomationCompositionHandler { this.participantId = parameters.getIntermediaryParameters().getParticipantId(); this.publisher = publisher; this.acInstanceStateResolver = new AcInstanceStateResolver(); + this.supportedAcElementTypes = parameters.getIntermediaryParameters().getParticipantSupportedElementTypes(); } public void registerAutomationCompositionElementListener(AutomationCompositionElementListener listener) { @@ -100,57 +101,63 @@ public class AutomationCompositionHandler { * @param lockState the LockState state */ public void updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, DeployState deployState, - LockState lockState) { + LockState lockState, String message) { - if (id == null) { - LOGGER.warn("Cannot update Automation composition element state, id is null"); + if (automationCompositionId == null || id == null) { + LOGGER.error("Cannot update Automation composition element state, id is null"); return; } - // Update states of AutomationCompositionElement in automationCompositionMap - for (var automationComposition : automationCompositionMap.values()) { - var element = automationComposition.getElements().get(id); - if (element != null) { - element.setDeployState(deployState); - element.setLockState(lockState); - element.setUseState(getUseState(automationCompositionId, id)); - element.setOperationalState(getOperationalState(automationCompositionId, id)); - element.setStatusProperties(getStatusProperties(automationCompositionId, id)); - } + if ((deployState != null && lockState != null) || (deployState == null && lockState == null)) { + LOGGER.error("state error {} and {} cannot be handled", deployState, lockState); + return; + } + + var automationComposition = automationCompositionMap.get(automationCompositionId); + if (automationComposition == null) { + LOGGER.error("Cannot update Automation composition element state, Automation composition id {} not present", + automationComposition); + return; + } + + var element = automationComposition.getElements().get(id); + if (element == null) { + var msg = "Cannot update Automation composition element state, AC Element id {} not present"; + LOGGER.error(msg, automationComposition); + return; + } + + if (deployState != null) { + element.setDeployState(deployState); var checkOpt = automationComposition.getElements().values().stream() .filter(acElement -> !deployState.equals(acElement.getDeployState())).findAny(); if (checkOpt.isEmpty()) { automationComposition.setDeployState(deployState); } - checkOpt = automationComposition.getElements().values().stream() + element.setLockState( + DeployState.DEPLOYED.equals(element.getDeployState()) ? LockState.LOCKED : LockState.NONE); + } + if (lockState != null) { + element.setLockState(lockState); + var checkOpt = automationComposition.getElements().values().stream() .filter(acElement -> !lockState.equals(acElement.getLockState())).findAny(); if (checkOpt.isEmpty()) { automationComposition.setLockState(lockState); } } - // Update states of AutomationCompositionElement in elementsOnThisParticipant - var acElement = elementsOnThisParticipant.get(id); - if (acElement != null) { - var automationCompositionStateChangeAck = - new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK); - automationCompositionStateChangeAck.setParticipantId(participantId); - automationCompositionStateChangeAck.setAutomationCompositionId(automationCompositionId); - acElement.setDeployState(deployState); - acElement.setLockState(lockState); - acElement.setUseState(getUseState(automationCompositionId, id)); - acElement.setOperationalState(getOperationalState(automationCompositionId, id)); - acElement.setStatusProperties(getStatusProperties(automationCompositionId, id)); - automationCompositionStateChangeAck.getAutomationCompositionResultMap().put(acElement.getId(), - new AcElementDeployAck(deployState, lockState, acElement.getOperationalState(), - acElement.getUseState(), acElement.getStatusProperties(), true, - "Automation composition element {} state changed to {}\", id, newState)")); - LOGGER.debug("Automation composition element {} state changed to {}", id, deployState); - automationCompositionStateChangeAck - .setMessage("AutomationCompositionElement state changed to {} " + deployState); - automationCompositionStateChangeAck.setResult(true); - publisher.sendAutomationCompositionAck(automationCompositionStateChangeAck); - } + var automationCompositionStateChangeAck = + new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK); + automationCompositionStateChangeAck.setParticipantId(participantId); + automationCompositionStateChangeAck.setMessage(message); + automationCompositionStateChangeAck.setAutomationCompositionId(automationCompositionId); + automationCompositionStateChangeAck.getAutomationCompositionResultMap().put(element.getId(), + new AcElementDeployAck(element.getDeployState(), element.getLockState(), element.getOperationalState(), + element.getUseState(), element.getStatusProperties(), true, + "Automation composition element {} state changed to {}\", id, newState)")); + LOGGER.debug("Automation composition element {} state changed to {}", id, deployState); + automationCompositionStateChangeAck.setResult(true); + publisher.sendAutomationCompositionAck(automationCompositionStateChangeAck); } /** @@ -346,7 +353,6 @@ public class AutomationCompositionHandler { acElement.setDefinition(element.getDefinition()); acElement.setDeployState(DeployState.DEPLOYING); acElement.setLockState(LockState.NONE); - elementsOnThisParticipant.put(element.getId(), acElement); acElementList.add(acElement); } return acElementList; @@ -378,8 +384,6 @@ public class AutomationCompositionHandler { .filter(element -> !DeployState.UNDEPLOYED.equals(element.getDeployState())).findAny().isEmpty(); if (isAllUninitialised) { automationCompositionMap.remove(automationComposition.getInstanceId()); - automationComposition.getElements().values() - .forEach(element -> elementsOnThisParticipant.remove(element.getId())); } } @@ -420,8 +424,8 @@ public class AutomationCompositionHandler { for (var acElementListener : listeners) { try { acElementListener.lock(instanceId, acElement.getId()); - updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED, - LockState.LOCKED); + updateAutomationCompositionElementState(instanceId, acElement.getId(), null, LockState.LOCKED, + "Locked"); } catch (PfModelException e) { LOGGER.error("Automation composition element lock failed {}", instanceId); } @@ -439,8 +443,8 @@ public class AutomationCompositionHandler { for (var acElementListener : listeners) { try { acElementListener.unlock(instanceId, acElement.getId()); - updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED, - LockState.UNLOCKED); + updateAutomationCompositionElementState(instanceId, acElement.getId(), null, LockState.UNLOCKED, + "Unlocked"); } catch (PfModelException e) { LOGGER.error("Automation composition element unlock failed {}", instanceId); } @@ -455,77 +459,112 @@ public class AutomationCompositionHandler { if (acElementNodeTemplate != null) { int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties()); if (startPhaseMsg.equals(startPhase)) { - for (var acElementListener : listeners) { - try { - acElementListener.undeploy(instanceId, acElement.getId()); - } catch (PfModelException e) { - LOGGER.error("Automation composition element update failed {}", instanceId); - } - } + undeployInstanceElements(instanceId, acElement.getId()); } } } + /** - * Get UseState. - * - * @param instanceId the instance Id - * @param acElementId the Automation Composition Element Id - * @return the UseState of the Automation Composition Element + * Undeploy Instance Elements On Participant. */ - public String getUseState(UUID instanceId, UUID acElementId) { - var result = new StringBuilder(); + public void undeployInstances() { + automationCompositionMap.values().forEach(this::undeployInstance); + } + + private void undeployInstance(AutomationComposition automationComposition) { + automationComposition.getElements().values().forEach(element -> { + if (element.getParticipantId().equals(participantId)) { + undeployInstanceElements(automationComposition.getInstanceId(), element.getId()); + } + }); + } + + private void undeployInstanceElements(UUID instanceId, UUID elementId) { for (var acElementListener : listeners) { try { - var state = acElementListener.getUseState(instanceId, acElementId); - if (!StringUtils.isBlank(state)) { - result.append(state); - } + acElementListener.undeploy(instanceId, elementId); } catch (PfModelException e) { - LOGGER.error("Automation composition element get Use State failed {}", acElementId); + LOGGER.error("Automation composition element update failed {}", instanceId); } } - return result.toString(); } /** - * Get OperationalState. + * Send Ac Element Info. * - * @param instanceId the instance Id - * @param acElementId the Automation Composition Element Id - * @return the OperationalState of the Automation Composition Element + * @param automationCompositionId the automationComposition Id + * @param elementId the automationComposition Element id + * @param useState the use State + * @param operationalState the operational State + * @param statusProperties the status Properties Map */ - public String getOperationalState(UUID instanceId, UUID acElementId) { - var result = new StringBuilder(); - for (var acElementListener : listeners) { - try { - var state = acElementListener.getOperationalState(instanceId, acElementId); - if (!StringUtils.isBlank(state)) { - result.append(state); - } - } catch (PfModelException e) { - LOGGER.error("Automation composition element get Use State failed {}", acElementId); - } + public void sendAcElementInfo(UUID automationCompositionId, UUID elementId, String useState, + String operationalState, Map<String, Object> statusProperties) { + + if (automationCompositionId == null || elementId == null) { + LOGGER.error("Cannot update Automation composition element state, id is null"); + return; } - return result.toString(); + + var automationComposition = automationCompositionMap.get(automationCompositionId); + if (automationComposition == null) { + LOGGER.error("Cannot update Automation composition element state, Automation composition id {} not present", + automationComposition); + return; + } + + var element = automationComposition.getElements().get(elementId); + if (element == null) { + var msg = "Cannot update Automation composition element state, AC Element id {} not present"; + LOGGER.error(msg, automationComposition); + return; + } + element.setOperationalState(operationalState); + element.setUseState(useState); + element.setStatusProperties(statusProperties); + + var statusMsg = new ParticipantStatus(); + statusMsg.setParticipantId(participantId); + statusMsg.setState(ParticipantState.ON_LINE); + statusMsg.setParticipantSupportedElementType(new ArrayList<>(supportedAcElementTypes)); + var acInfo = new AutomationCompositionInfo(); + acInfo.setAutomationCompositionId(automationCompositionId); + acInfo.setDeployState(automationComposition.getDeployState()); + acInfo.setLockState(automationComposition.getLockState()); + acInfo.setElements(List.of(getAutomationCompositionElementInfo(element))); + statusMsg.setAutomationCompositionInfoList(List.of(acInfo)); + publisher.sendParticipantStatus(statusMsg); } /** - * Get StatusProperties. + * get AutomationComposition Info List. * - * @param instanceId the instance Id - * @param acElementId the Automation Composition Element Id - * @return the Status Properties Map + * @return list of AutomationCompositionInfo */ - public Map<String, Object> getStatusProperties(UUID instanceId, UUID acElementId) { - Map<String, Object> result = new HashMap<>(); - for (var acElementListener : listeners) { - try { - result.putAll(acElementListener.getStatusProperties(instanceId, acElementId)); - } catch (PfModelException e) { - LOGGER.error("Automation composition element get Status Properties failed {}", acElementId); + public List<AutomationCompositionInfo> getAutomationCompositionInfoList() { + List<AutomationCompositionInfo> automationCompositionInfoList = new ArrayList<>(); + for (var entry : automationCompositionMap.entrySet()) { + var acInfo = new AutomationCompositionInfo(); + acInfo.setAutomationCompositionId(entry.getKey()); + acInfo.setDeployState(entry.getValue().getDeployState()); + acInfo.setLockState(entry.getValue().getLockState()); + for (var element : entry.getValue().getElements().values()) { + acInfo.getElements().add(getAutomationCompositionElementInfo(element)); } + automationCompositionInfoList.add(acInfo); } - return result; + return automationCompositionInfoList; + } + + private AutomationCompositionElementInfo getAutomationCompositionElementInfo(AutomationCompositionElement element) { + var elementInfo = new AutomationCompositionElementInfo(); + elementInfo.setAutomationCompositionElementId(element.getId()); + elementInfo.setDeployState(element.getDeployState()); + elementInfo.setLockState(element.getLockState()); + elementInfo.setOperationalState(element.getOperationalState()); + elementInfo.setUseState(element.getUseState()); + elementInfo.setStatusProperties(element.getStatusProperties()); + return elementInfo; } } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java index 9e2484c7d..44a988a27 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java @@ -31,10 +31,7 @@ import java.util.UUID; import lombok.Getter; import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher; import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantParameters; -import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementInfo; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; import org.onap.policy.clamp.models.acm.concepts.ParticipantState; import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType; @@ -50,7 +47,6 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRe import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegisterAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatusReq; -import org.onap.policy.models.base.PfModelException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -77,6 +73,7 @@ public class ParticipantHandler { * * @param parameters the parameters of the participant * @param publisher the publisher for sending responses to messages + * @param automationCompositionHandler the publisher for sending responses to messages */ public ParticipantHandler(ParticipantParameters parameters, ParticipantMessagePublisher publisher, AutomationCompositionHandler automationCompositionHandler) { @@ -173,32 +170,7 @@ public class ParticipantHandler { var participantDeregister = new ParticipantDeregister(); participantDeregister.setParticipantId(participantId); publisher.sendParticipantDeregister(participantDeregister); - undeployInstancesOnParticipant(); - } - - private void undeployInstancesOnParticipant() { - automationCompositionHandler.getAutomationCompositionMap().values().forEach(ac -> - undeployInstanceOnParticipant(ac) - ); - } - - private void undeployInstanceOnParticipant(AutomationComposition automationComposition) { - automationComposition.getElements().values().forEach(element -> { - if (element.getParticipantId().equals(participantId)) { - undeployInstanceElementsOnParticipant(automationComposition.getInstanceId(), element.getId()); - } - }); - } - - private void undeployInstanceElementsOnParticipant(UUID instanceId, UUID elementId) { - var acElementListeners = automationCompositionHandler.getListeners(); - for (var acElementListener : acElementListeners) { - try { - acElementListener.undeploy(instanceId, elementId); - } catch (PfModelException e) { - LOGGER.debug("Automation composition element update failed {}", instanceId); - } - } + automationCompositionHandler.undeployInstances(); } /** @@ -242,7 +214,7 @@ public class ParticipantHandler { /** * Method to send ParticipantPrimeAck message to automation composition runtime. */ - public void sendParticipantPrimeAck(UUID messageId, UUID compositionId) { + private void sendParticipantPrimeAck(UUID messageId, UUID compositionId) { var participantPrimeAck = new ParticipantPrimeAck(); participantPrimeAck.setResponseTo(messageId); participantPrimeAck.setCompositionId(compositionId); @@ -267,7 +239,7 @@ public class ParticipantHandler { var heartbeat = new ParticipantStatus(); heartbeat.setParticipantId(participantId); heartbeat.setState(ParticipantState.ON_LINE); - heartbeat.setAutomationCompositionInfoList(getAutomationCompositionInfoList()); + heartbeat.setAutomationCompositionInfoList(automationCompositionHandler.getAutomationCompositionInfoList()); heartbeat.setParticipantSupportedElementType(new ArrayList<>(this.supportedAcElementTypes)); if (responseToParticipantStatusReq) { @@ -283,26 +255,4 @@ public class ParticipantHandler { return heartbeat; } - - private List<AutomationCompositionInfo> getAutomationCompositionInfoList() { - List<AutomationCompositionInfo> automationCompositionInfoList = new ArrayList<>(); - for (var entry : automationCompositionHandler.getAutomationCompositionMap().entrySet()) { - var acInfo = new AutomationCompositionInfo(); - acInfo.setAutomationCompositionId(entry.getKey()); - acInfo.setDeployState(entry.getValue().getDeployState()); - acInfo.setLockState(entry.getValue().getLockState()); - for (var element : entry.getValue().getElements().values()) { - var elementInfo = new AutomationCompositionElementInfo(); - elementInfo.setAutomationCompositionElementId(element.getId()); - elementInfo.setDeployState(element.getDeployState()); - elementInfo.setLockState(element.getLockState()); - elementInfo.setOperationalState( - automationCompositionHandler.getOperationalState(entry.getKey(), element.getId())); - elementInfo.setUseState(automationCompositionHandler.getUseState(entry.getKey(), element.getId())); - acInfo.getElements().add(elementInfo); - } - automationCompositionInfoList.add(acInfo); - } - return automationCompositionInfoList; - } } diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AutomationCompositionElementListenerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AutomationCompositionElementListenerTest.java index 6255b886c..93809ab96 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AutomationCompositionElementListenerTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AutomationCompositionElementListenerTest.java @@ -20,7 +20,6 @@ package org.onap.policy.clamp.acm.participant.intermediary.api.impl; -import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; import java.util.UUID; @@ -33,9 +32,6 @@ class AutomationCompositionElementListenerTest { @Test void defaultTest() throws PfModelException { var listener = new DummyAcElementListener(); - assertThat(listener.getStatusProperties(UUID.randomUUID(), UUID.randomUUID())).isNotNull().isEmpty(); - assertThat(listener.getOperationalState(UUID.randomUUID(), UUID.randomUUID())).isNotNull().isEmpty(); - assertThat(listener.getUseState(UUID.randomUUID(), UUID.randomUUID())).isNotNull().isEmpty(); assertThatCode(() -> listener.lock(UUID.randomUUID(), UUID.randomUUID())).doesNotThrowAnyException(); assertThatCode(() -> listener.unlock(UUID.randomUUID(), UUID.randomUUID())).doesNotThrowAnyException(); } diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java index d86c9d0a4..aa39f5a3f 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java @@ -20,36 +20,42 @@ package org.onap.policy.clamp.acm.participant.intermediary.api.impl; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import java.util.Map; import java.util.UUID; import org.junit.jupiter.api.Test; -import org.mockito.Mockito; import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; -import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData; +import org.onap.policy.clamp.acm.participant.intermediary.handler.AutomationCompositionHandler; 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.CoderException; class ParticipantIntermediaryApiImplTest { - private final CommonTestData commonTestData = new CommonTestData(); + private static final String USE_STATE = "useState"; + private static final String OPERATIONAL_STATE = "operationState"; + private static final Map<String, Object> MAP = Map.of("key", 1); @Test void mockParticipantIntermediaryApiImplTest() throws CoderException { - var uuid = UUID.randomUUID(); - var definition = CommonTestData.getDefinition(); - var participantId = CommonTestData.getParticipantId(); - var automationComposiitonHandler = - commonTestData.setTestAutomationCompositionHandler(definition, uuid, participantId); + var automationComposiitonHandler = mock(AutomationCompositionHandler.class); var apiImpl = new ParticipantIntermediaryApiImpl(automationComposiitonHandler); - var acElementListener = Mockito.mock(AutomationCompositionElementListener.class); + + var acElementListener = mock(AutomationCompositionElementListener.class); apiImpl.registerAutomationCompositionElementListener(acElementListener); + verify(automationComposiitonHandler).registerAutomationCompositionElementListener(acElementListener); + + var uuid = UUID.randomUUID(); + var automationCompositionId = UUID.randomUUID(); + apiImpl.updateAutomationCompositionElementState(automationCompositionId, uuid, DeployState.UNDEPLOYED, + LockState.NONE, null); + verify(automationComposiitonHandler).updateAutomationCompositionElementState(automationCompositionId, uuid, + DeployState.UNDEPLOYED, LockState.NONE, null); - apiImpl.updateAutomationCompositionElementState(UUID.randomUUID(), uuid, DeployState.UNDEPLOYED, - LockState.NONE); - var acElement = automationComposiitonHandler.getElementsOnThisParticipant().get(uuid); - assertEquals(DeployState.UNDEPLOYED, acElement.getDeployState()); - assertEquals(uuid, acElement.getId()); + apiImpl.sendAcElementInfo(automationCompositionId, uuid, USE_STATE, OPERATIONAL_STATE, MAP); + verify(automationComposiitonHandler).sendAcElementInfo(automationCompositionId, uuid, USE_STATE, + OPERATIONAL_STATE, MAP); } } diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java index 25b1facf5..d782ae167 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java @@ -29,13 +29,14 @@ import static org.mockito.ArgumentMatchers.anyMap; 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 java.util.Map; import java.util.UUID; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; +import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher; import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData; import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; @@ -61,11 +62,6 @@ class AutomationCompositionHandlerTest { void automationCompositionHandlerTest() { var ach = commonTestData.getMockAutomationCompositionHandler(); assertNotNull(ach.getAutomationCompositionMap()); - assertNotNull(ach.getElementsOnThisParticipant()); - - var listener = mock(AutomationCompositionElementListener.class); - ach.registerAutomationCompositionElementListener(listener); - assertThat(ach.getListeners()).contains(listener); } @Test @@ -73,11 +69,11 @@ class AutomationCompositionHandlerTest { var id = UUID.randomUUID(); var ach = commonTestData.getMockAutomationCompositionHandler(); - assertDoesNotThrow( - () -> ach.updateAutomationCompositionElementState(null, null, DeployState.UNDEPLOYED, LockState.NONE)); + assertDoesNotThrow(() -> ach.updateAutomationCompositionElementState(null, null, DeployState.UNDEPLOYED, null, + "Undeployed")); assertDoesNotThrow( - () -> ach.updateAutomationCompositionElementState(null, id, DeployState.UNDEPLOYED, LockState.NONE)); + () -> ach.updateAutomationCompositionElementState(null, id, DeployState.UNDEPLOYED, null, null)); } @Test @@ -87,23 +83,23 @@ class AutomationCompositionHandlerTest { var definition = CommonTestData.getDefinition(); var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); - var key = ach.getElementsOnThisParticipant().keySet().iterator().next(); - var value = ach.getElementsOnThisParticipant().get(key); - assertEquals(DeployState.UNDEPLOYED, value.getDeployState()); - assertEquals(LockState.LOCKED, value.getLockState()); - ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, uuid, DeployState.DEPLOYED, - LockState.UNLOCKED); + var acKey = ach.getAutomationCompositionMap().keySet().iterator().next(); + var key = ach.getAutomationCompositionMap().get(acKey).getElements().keySet().iterator().next(); + var value = ach.getAutomationCompositionMap().get(acKey).getElements().get(key); + value.setDeployState(DeployState.DEPLOYING); + value.setLockState(LockState.NONE); + ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, uuid, DeployState.DEPLOYED, null, + "Deployed"); assertEquals(DeployState.DEPLOYED, value.getDeployState()); ach.getAutomationCompositionMap().values().iterator().next().getElements().putIfAbsent(key, value); - ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, DeployState.DEPLOYED, - LockState.UNLOCKED); + ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, DeployState.DEPLOYED, null, + "Deployed"); assertEquals(DeployState.DEPLOYED, value.getDeployState()); - ach.getElementsOnThisParticipant().remove(key, value); ach.getAutomationCompositionMap().values().iterator().next().getElements().clear(); - assertDoesNotThrow(() -> ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, - DeployState.DEPLOYED, LockState.UNLOCKED)); + assertDoesNotThrow(() -> ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, null, + LockState.UNLOCKED, null)); } @Test @@ -246,27 +242,39 @@ class AutomationCompositionHandlerTest { verify(listener, times(1)).unlock(any(), any()); } + @Test - void testGetUseState() throws PfModelException { + void testgetAutomationCompositionInfoList() { var uuid = UUID.randomUUID(); var partecipantId = CommonTestData.getParticipantId(); var definition = CommonTestData.getDefinition(); var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); - var listener = mock(AutomationCompositionElementListener.class); - when(listener.getUseState(uuid, uuid)).thenReturn(STATE_VALUE); - ach.registerAutomationCompositionElementListener(listener); - assertEquals(STATE_VALUE, ach.getUseState(uuid, uuid)); + var result = ach.getAutomationCompositionInfoList(); + assertThat(result).hasSize(1); + assertThat(result.get(0).getElements()).hasSize(1); + } + + @Test + void testsendAcElementInfo() { + var participantMessagePublisher = mock(ParticipantMessagePublisher.class); + var ach = new AutomationCompositionHandler(CommonTestData.getParticipantParameters(), + participantMessagePublisher); + ach.getAutomationCompositionMap().putAll(commonTestData.getTestAutomationCompositionMap()); + var key = ach.getAutomationCompositionMap().keySet().iterator().next(); + var keyElement = ach.getAutomationCompositionMap().get(key).getElements().keySet().iterator().next(); + ach.sendAcElementInfo(key, keyElement, "useState", "operationalState", Map.of("key", 1)); + verify(participantMessagePublisher).sendParticipantStatus(any()); } @Test - void testGetOperationalState() throws PfModelException { + void testUndeployInstances() throws PfModelException { var uuid = UUID.randomUUID(); var partecipantId = CommonTestData.getParticipantId(); var definition = CommonTestData.getDefinition(); var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); var listener = mock(AutomationCompositionElementListener.class); - when(listener.getOperationalState(uuid, uuid)).thenReturn(STATE_VALUE); ach.registerAutomationCompositionElementListener(listener); - assertEquals(STATE_VALUE, ach.getOperationalState(uuid, uuid)); + ach.undeployInstances(); + verify(listener).undeploy(any(), any()); } } diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java index 3fed5bb56..30860308e 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java @@ -26,6 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -66,7 +67,6 @@ class ParticipantHandlerTest { var participantHandler = commonTestData.getMockParticipantHandler(); var participantId = CommonTestData.getParticipantId(); - participantPrimeMsg.setAutomationCompositionId(CommonTestData.AC_ID_1); participantPrimeMsg.setCompositionId(CommonTestData.AC_ID_1); participantPrimeMsg.setParticipantId(participantId); participantPrimeMsg.setMessageId(UUID.randomUUID()); @@ -115,13 +115,12 @@ class ParticipantHandlerTest { @Test void getAutomationCompositionInfoListTest() throws CoderException { - var participantHandler = commonTestData.getParticipantHandlerAutomationCompositions(); + var automationCompositionHandler = mock(AutomationCompositionHandler.class); + var participantHandler = + commonTestData.getParticipantHandlerAutomationCompositions(automationCompositionHandler); + clearInvocations(automationCompositionHandler); participantHandler.sendHeartbeat(); - assertEquals(CommonTestData.AC_ID_1, participantHandler.makeHeartbeat(false) - .getAutomationCompositionInfoList() - .get(0) - .getAutomationCompositionId()); - + verify(automationCompositionHandler).getAutomationCompositionInfoList(); } @Test @@ -140,9 +139,7 @@ class ParticipantHandlerTest { var commonTestData = new CommonTestData(); var automationCompositionMap = commonTestData.getTestAutomationCompositionMap(); var automationCompositionHandler = mock(AutomationCompositionHandler.class); - var listener = mock(DummyAcElementListener.class); - when(automationCompositionHandler.getListeners()).thenReturn(List.of(listener)); automationCompositionMap.values().iterator().next().getElements().values().iterator().next() .setParticipantId(CommonTestData.getParticipantId()); when(automationCompositionHandler.getAutomationCompositionMap()).thenReturn(automationCompositionMap); @@ -153,6 +150,6 @@ class ParticipantHandlerTest { participantHandler.sendParticipantDeregister(); verify(publisher).sendParticipantDeregister(any(ParticipantDeregister.class)); - verify(listener).undeploy(any(), any()); + verify(automationCompositionHandler).undeployInstances(); } } diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java index 140fd947a..e627da611 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java @@ -201,6 +201,11 @@ public class CommonTestData { return new ParticipantHandler(parameters, publisher, automationCompositionHandler); } + public ParticipantHandler getParticipantHandlerAutomationCompositions() { + var automationCompositionHandler = Mockito.mock(AutomationCompositionHandler.class); + return getParticipantHandlerAutomationCompositions(automationCompositionHandler); + } + /** * Returns a mocked ParticipantHandler for test cases. * @@ -208,8 +213,8 @@ public class CommonTestData { * * @throws CoderException if there is an error with .json file. */ - public ParticipantHandler getParticipantHandlerAutomationCompositions() throws CoderException { - var automationCompositionHandler = Mockito.mock(AutomationCompositionHandler.class); + public ParticipantHandler getParticipantHandlerAutomationCompositions( + AutomationCompositionHandler automationCompositionHandler) { Mockito.doReturn(getTestAutomationCompositionMap()).when(automationCompositionHandler) .getAutomationCompositionMap(); var publisher = new ParticipantMessagePublisher(); @@ -291,7 +296,9 @@ public class CommonTestData { UUID uuid, UUID participantId) { var ach = getMockAutomationCompositionHandler(); ach.getAutomationCompositionMap().putAll(getTestAutomationCompositionMap()); - ach.getElementsOnThisParticipant().putAll(setAutomationCompositionElementTest(uuid, definition, participantId)); + var acKey = ach.getAutomationCompositionMap().keySet().iterator().next(); + ach.getAutomationCompositionMap().get(acKey) + .setElements(setAutomationCompositionElementTest(uuid, definition, participantId)); return ach; } |