diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2024-02-14 16:30:56 +0000 |
---|---|---|
committer | FrancescoFioraEst <francesco.fiora@est.tech> | 2024-02-15 15:29:53 +0000 |
commit | e0a13196ebb34c84931df27ba00cd1778adbceb9 (patch) | |
tree | 64f1af69d7802ee41a08278ec1e84b21241c1fb5 /participant | |
parent | 665815fc5c91c3437a0b0459448994789464a391 (diff) |
Add old properties and new properties support
Add old/new properties support in migrate and update,
and add Java code backward compatibility.
Issue-ID: POLICY-4930
Change-Id: I640bc2a858969168b13fe6cdbb557ebf920bafd5
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant')
26 files changed, 1795 insertions, 757 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 02697facc..75f3edb0a 100644 --- 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-2023 Nordix Foundation. + * Copyright (C) 2022-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,22 +23,18 @@ package org.onap.policy.clamp.acm.participant.a1pms.handler; import jakarta.validation.Validation; import jakarta.validation.ValidationException; import java.lang.invoke.MethodHandles; -import java.util.List; import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import lombok.AccessLevel; import lombok.Getter; -import lombok.RequiredArgsConstructor; import org.apache.http.HttpStatus; import org.onap.policy.clamp.acm.participant.a1pms.exception.A1PolicyServiceException; 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.acm.participant.intermediary.api.impl.AcElementListenerV1; import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; -import org.onap.policy.clamp.models.acm.concepts.AcTypeState; -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.StateChangeResult; @@ -55,21 +51,24 @@ import org.springframework.stereotype.Component; * This class handles implementation of automationCompositionElement updates. */ @Component -@RequiredArgsConstructor -public class AutomationCompositionElementHandler implements AutomationCompositionElementListener { +public class AutomationCompositionElementHandler extends AcElementListenerV1 { private static final Coder CODER = new StandardCoder(); private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private final ParticipantIntermediaryApi intermediaryApi; - private final AcA1PmsClient acA1PmsClient; // Map of acElement Id and A1PMS services @Getter(AccessLevel.PACKAGE) private final Map<UUID, ConfigurationEntity> configRequestMap = new ConcurrentHashMap<>(); + public AutomationCompositionElementHandler(ParticipantIntermediaryApi intermediaryApi, + AcA1PmsClient acA1PmsClient) { + super(intermediaryApi); + this.acA1PmsClient = acA1PmsClient; + } + /** * Handle a automation composition element state change. * @@ -128,52 +127,6 @@ public class AutomationCompositionElementHandler implements AutomationCompositio } @Override - public void lock(UUID instanceId, UUID elementId) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED, - StateChangeResult.NO_ERROR, "Locked"); - } - - @Override - public void unlock(UUID instanceId, UUID elementId) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED, - StateChangeResult.NO_ERROR, "Unlocked"); - } - - @Override - public void delete(UUID instanceId, UUID elementId) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.DELETED, null, - StateChangeResult.NO_ERROR, "Deleted"); - } - - @Override - public void update(UUID instanceId, AcElementDeploy element, Map<String, Object> properties) - throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, null, - StateChangeResult.NO_ERROR, "Update not supported"); - } - - @Override - public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList) - throws PfModelException { - intermediaryApi.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed"); - } - - @Override - public void deprime(UUID compositionId) throws PfModelException { - intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, - "Deprimed"); - } - - @Override - public void handleRestartComposition(UUID compositionId, - List<AutomationCompositionElementDefinition> elementDefinitionList, AcTypeState state) - throws PfModelException { - var finalState = AcTypeState.PRIMED.equals(state) || AcTypeState.PRIMING.equals(state) ? AcTypeState.PRIMED - : AcTypeState.COMMISSIONED; - intermediaryApi.updateCompositionState(compositionId, finalState, StateChangeResult.NO_ERROR, "Restarted"); - } - - @Override public void handleRestartInstance(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties, DeployState deployState, LockState lockState) throws PfModelException { if (DeployState.DEPLOYING.equals(deployState)) { @@ -198,11 +151,4 @@ public class AutomationCompositionElementHandler implements AutomationCompositio intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), deployState, lockState, StateChangeResult.NO_ERROR, "Restarted"); } - - @Override - public void migrate(UUID automationCompositionId, AcElementDeploy element, UUID compositionTargetId, - Map<String, Object> properties) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), - DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated"); - } } 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 883b8a17b..752b8d938 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,22 +23,16 @@ package org.onap.policy.clamp.acm.participant.http.main.handler; import jakarta.validation.Validation; import jakarta.ws.rs.core.Response.Status; import java.lang.invoke.MethodHandles; -import java.util.List; import java.util.Map; import java.util.UUID; -import lombok.RequiredArgsConstructor; import org.onap.policy.clamp.acm.participant.http.main.models.ConfigRequest; import org.onap.policy.clamp.acm.participant.http.main.webclient.AcHttpClient; -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.intermediary.api.impl.AcElementListenerV1; import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException; import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; -import org.onap.policy.clamp.models.acm.concepts.AcTypeState; -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.StateChangeResult; -import org.onap.policy.clamp.models.acm.utils.AcmUtils; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; @@ -52,17 +46,19 @@ import org.springframework.stereotype.Component; * This class handles implementation of automationCompositionElement updates. */ @Component -@RequiredArgsConstructor -public class AutomationCompositionElementHandler implements AutomationCompositionElementListener { +public class AutomationCompositionElementHandler extends AcElementListenerV1 { private static final Coder CODER = new StandardCoder(); private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private final ParticipantIntermediaryApi intermediaryApi; - private final AcHttpClient acHttpClient; + public AutomationCompositionElementHandler(ParticipantIntermediaryApi intermediaryApi, AcHttpClient acHttpClient) { + super(intermediaryApi); + this.acHttpClient = acHttpClient; + } + /** * Handle a automation composition element state change. * @@ -119,70 +115,4 @@ public class AutomationCompositionElementHandler implements AutomationCompositio throw new AutomationCompositionException(Status.BAD_REQUEST, "Error extracting ConfigRequest ", e); } } - - @Override - public void lock(UUID instanceId, UUID elementId) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED, - StateChangeResult.NO_ERROR, "Locked"); - } - - @Override - public void unlock(UUID instanceId, UUID elementId) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED, - StateChangeResult.NO_ERROR, "Unlocked"); - } - - @Override - public void delete(UUID instanceId, UUID elementId) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.DELETED, null, - StateChangeResult.NO_ERROR, "Deleted"); - } - - @Override - public void update(UUID instanceId, AcElementDeploy element, Map<String, Object> properties) - throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, null, - StateChangeResult.NO_ERROR, "Update not supported"); - } - - @Override - public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList) - throws PfModelException { - intermediaryApi.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed"); - } - - @Override - public void deprime(UUID compositionId) throws PfModelException { - intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, - "Deprimed"); - } - - @Override - public void handleRestartComposition(UUID compositionId, - List<AutomationCompositionElementDefinition> elementDefinitionList, AcTypeState state) - throws PfModelException { - var finalState = AcTypeState.PRIMED.equals(state) || AcTypeState.PRIMING.equals(state) ? AcTypeState.PRIMED - : AcTypeState.COMMISSIONED; - intermediaryApi.updateCompositionState(compositionId, finalState, StateChangeResult.NO_ERROR, "Restarted"); - } - - @Override - public void handleRestartInstance(UUID automationCompositionId, AcElementDeploy element, - Map<String, Object> properties, DeployState deployState, LockState lockState) throws PfModelException { - if (DeployState.DEPLOYING.equals(deployState)) { - deploy(automationCompositionId, element, properties); - return; - } - deployState = AcmUtils.deployCompleted(deployState); - lockState = AcmUtils.lockCompleted(deployState, lockState); - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), deployState, - lockState, StateChangeResult.NO_ERROR, "Restarted"); - } - - @Override - public void migrate(UUID automationCompositionId, AcElementDeploy element, UUID compositionTargetId, - Map<String, Object> properties) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), - DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated"); - } } 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 417b60978..d4b09c923 100644 --- 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 @@ -26,7 +26,6 @@ import jakarta.validation.Validation; import jakarta.validation.ValidationException; import java.io.IOException; import java.lang.invoke.MethodHandles; -import java.util.List; import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -36,18 +35,15 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import lombok.AccessLevel; import lombok.Getter; -import lombok.RequiredArgsConstructor; import org.apache.http.HttpStatus; -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.intermediary.api.impl.AcElementListenerV1; import org.onap.policy.clamp.acm.participant.kserve.exception.KserveException; import org.onap.policy.clamp.acm.participant.kserve.k8s.InferenceServiceValidator; import org.onap.policy.clamp.acm.participant.kserve.k8s.KserveClient; 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.AcTypeState; -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.StateChangeResult; @@ -64,8 +60,7 @@ import org.springframework.stereotype.Component; * This class handles implementation of automationCompositionElement updates. */ @Component -@RequiredArgsConstructor -public class AutomationCompositionElementHandler implements AutomationCompositionElementListener { +public class AutomationCompositionElementHandler extends AcElementListenerV1 { private static final Coder CODER = new StandardCoder(); @@ -74,13 +69,16 @@ public class AutomationCompositionElementHandler implements AutomationCompositio private ExecutorService executor = Context.taskWrapping( Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())); - private final ParticipantIntermediaryApi intermediaryApi; - private final KserveClient kserveClient; @Getter(AccessLevel.PACKAGE) private final Map<UUID, ConfigurationEntity> configRequestMap = new ConcurrentHashMap<>(); + public AutomationCompositionElementHandler(ParticipantIntermediaryApi intermediaryApi, KserveClient kserveClient) { + super(intermediaryApi); + this.kserveClient = kserveClient; + } + private static class ThreadConfig { private int uninitializedToPassiveTimeout = 60; @@ -174,52 +172,6 @@ public class AutomationCompositionElementHandler implements AutomationCompositio } @Override - public void lock(UUID instanceId, UUID elementId) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED, - StateChangeResult.NO_ERROR, "Locked"); - } - - @Override - public void unlock(UUID instanceId, UUID elementId) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED, - StateChangeResult.NO_ERROR, "Unlocked"); - } - - @Override - public void delete(UUID instanceId, UUID elementId) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.DELETED, null, - StateChangeResult.NO_ERROR, "Deleted"); - } - - @Override - public void update(UUID instanceId, AcElementDeploy element, Map<String, Object> properties) - throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, null, - StateChangeResult.NO_ERROR, "Update not supported"); - } - - @Override - public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList) - throws PfModelException { - intermediaryApi.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed"); - } - - @Override - public void deprime(UUID compositionId) throws PfModelException { - intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, - "Deprimed"); - } - - @Override - public void handleRestartComposition(UUID compositionId, - List<AutomationCompositionElementDefinition> elementDefinitionList, AcTypeState state) - throws PfModelException { - var finalState = AcTypeState.PRIMED.equals(state) || AcTypeState.PRIMING.equals(state) ? AcTypeState.PRIMED - : AcTypeState.COMMISSIONED; - intermediaryApi.updateCompositionState(compositionId, finalState, StateChangeResult.NO_ERROR, "Restarted"); - } - - @Override public void handleRestartInstance(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties, DeployState deployState, LockState lockState) throws PfModelException { if (DeployState.DEPLOYING.equals(deployState)) { @@ -244,11 +196,4 @@ public class AutomationCompositionElementHandler implements AutomationCompositio intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), deployState, lockState, StateChangeResult.NO_ERROR, "Restarted"); } - - @Override - public void migrate(UUID automationCompositionId, AcElementDeploy element, UUID compositionTargetId, - Map<String, Object> properties) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), - DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated"); - } } 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 d6ce70ce1..ae8e47461 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,8 +31,8 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import lombok.AccessLevel; import lombok.Getter; -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.intermediary.api.impl.AcElementListenerV1; import org.onap.policy.clamp.acm.participant.kubernetes.exception.ServiceException; import org.onap.policy.clamp.acm.participant.kubernetes.helm.PodStatusValidator; import org.onap.policy.clamp.acm.participant.kubernetes.models.ChartInfo; @@ -58,7 +58,7 @@ import org.springframework.stereotype.Component; * This class handles implementation of automationCompositionElement updates. */ @Component -public class AutomationCompositionElementHandler implements AutomationCompositionElementListener { +public class AutomationCompositionElementHandler extends AcElementListenerV1 { private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); // Map of helm installation and the status of corresponding pods @@ -69,13 +69,14 @@ public class AutomationCompositionElementHandler implements AutomationCompositio @Autowired private ChartService chartService; - @Autowired - private ParticipantIntermediaryApi intermediaryApi; - // Map of acElement Id and installed Helm charts @Getter(AccessLevel.PACKAGE) private final Map<UUID, ChartInfo> chartMap = new HashMap<>(); + public AutomationCompositionElementHandler(ParticipantIntermediaryApi intermediaryApi) { + super(intermediaryApi); + } + // Default thread config values private static class ThreadConfig { private int uninitializedToPassiveTimeout = 60; @@ -249,11 +250,4 @@ public class AutomationCompositionElementHandler implements AutomationCompositio intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), deployState, lockState, StateChangeResult.NO_ERROR, "Restarted"); } - - @Override - public void migrate(UUID automationCompositionId, AcElementDeploy element, UUID compositionTargetId, - Map<String, Object> properties) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), - DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated"); - } } diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java index fb8a04602..14b505f66 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-2024 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,6 +29,7 @@ import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; import java.io.File; import java.io.IOException; @@ -78,15 +79,12 @@ class AutomationCompositionElementHandlerTest { @InjectMocks @Spy private AutomationCompositionElementHandler automationCompositionElementHandler = - new AutomationCompositionElementHandler(); + new AutomationCompositionElementHandler(mock(ParticipantIntermediaryApi.class)); @Mock private ChartService chartService; @Mock - private ParticipantIntermediaryApi participantIntermediaryApi; - - @Mock private ExecutorService executor; @Mock private Future<String> result; 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 281fe3e01..d66ab3154 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-2024 Nordix Foundation. * ================================================================================ * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -28,15 +28,12 @@ import java.util.List; import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import lombok.RequiredArgsConstructor; import org.apache.http.HttpStatus; -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.intermediary.api.impl.AcElementListenerV1; 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.AcTypeState; -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.StateChangeResult; @@ -53,8 +50,7 @@ import org.springframework.stereotype.Component; * This class handles implementation of automationCompositionElement updates. */ @Component -@RequiredArgsConstructor -public class AutomationCompositionElementHandler implements AutomationCompositionElementListener { +public class AutomationCompositionElementHandler extends AcElementListenerV1 { private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionElementHandler.class); @@ -62,7 +58,20 @@ public class AutomationCompositionElementHandler implements AutomationCompositio private final PolicyApiHttpClient apiHttpClient; private final PolicyPapHttpClient papHttpClient; - private final ParticipantIntermediaryApi intermediaryApi; + + /** + * Constructor. + * + * @param apiHttpClient the PolicyApi Http Client + * @param papHttpClient the Policy Pap Http Client + * @param intermediaryApi the Participant Intermediary Api + */ + public AutomationCompositionElementHandler(PolicyApiHttpClient apiHttpClient, PolicyPapHttpClient papHttpClient, + ParticipantIntermediaryApi intermediaryApi) { + super(intermediaryApi); + this.apiHttpClient = apiHttpClient; + this.papHttpClient = papHttpClient; + } /** * Callback method to handle a automation composition element state change. @@ -214,52 +223,6 @@ public class AutomationCompositionElementHandler implements AutomationCompositio } @Override - public void lock(UUID instanceId, UUID elementId) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED, - StateChangeResult.NO_ERROR, "Locked"); - } - - @Override - public void unlock(UUID instanceId, UUID elementId) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED, - StateChangeResult.NO_ERROR, "Unlocked"); - } - - @Override - public void delete(UUID instanceId, UUID elementId) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.DELETED, null, - StateChangeResult.NO_ERROR, "Deleted"); - } - - @Override - public void update(UUID instanceId, AcElementDeploy element, Map<String, Object> properties) - throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, null, - StateChangeResult.NO_ERROR, "Update not supported"); - } - - @Override - public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList) - throws PfModelException { - intermediaryApi.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed"); - } - - @Override - public void deprime(UUID compositionId) throws PfModelException { - intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, - "Deprimed"); - } - - @Override - public void handleRestartComposition(UUID compositionId, - List<AutomationCompositionElementDefinition> elementDefinitionList, AcTypeState state) - throws PfModelException { - var finalState = AcTypeState.PRIMED.equals(state) || AcTypeState.PRIMING.equals(state) ? AcTypeState.PRIMED - : AcTypeState.COMMISSIONED; - intermediaryApi.updateCompositionState(compositionId, finalState, StateChangeResult.NO_ERROR, "Restarted"); - } - - @Override public void handleRestartInstance(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties, DeployState deployState, LockState lockState) throws PfModelException { if (DeployState.DEPLOYING.equals(deployState)) { @@ -280,11 +243,4 @@ public class AutomationCompositionElementHandler implements AutomationCompositio intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), deployState, lockState, StateChangeResult.NO_ERROR, "Restarted"); } - - @Override - public void migrate(UUID automationCompositionId, AcElementDeploy element, UUID compositionTargetId, - Map<String, Object> properties) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), - DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated"); - } } diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandler.java index 7409c1137..2cba379c4 100644 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandler.java +++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandler.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation. + * Copyright (C) 2023-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,21 +22,20 @@ package org.onap.policy.clamp.acm.participant.sim.main.handler; import java.lang.invoke.MethodHandles; import java.util.ArrayList; -import java.util.List; import java.util.Map; import java.util.UUID; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.Setter; -import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto; import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; +import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementListenerV2; import org.onap.policy.clamp.acm.participant.sim.model.InternalData; import org.onap.policy.clamp.acm.participant.sim.model.InternalDatas; import org.onap.policy.clamp.acm.participant.sim.model.SimConfig; -import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; 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.AutomationCompositionElementDefinition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; @@ -52,41 +51,43 @@ import org.springframework.stereotype.Component; * This class handles implementation of automationCompositionElement updates. */ @Component -@RequiredArgsConstructor -public class AutomationCompositionElementHandler implements AutomationCompositionElementListener { +public class AutomationCompositionElementHandler extends AcElementListenerV2 { private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private final ParticipantIntermediaryApi intermediaryApi; - @Getter @Setter private SimConfig config = new SimConfig(); + public AutomationCompositionElementHandler(ParticipantIntermediaryApi intermediaryApi) { + super(intermediaryApi); + } + /** - * Callback method to handle an update on a automation composition element. + * Handle a deploy on a automation composition element. * - * @param automationCompositionId the automationComposition Id - * @param element the information on the automation composition element - * @param properties properties Map - * @throws PfModelException in case of a exception + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element + * @throws PfModelException from Policy framework */ @Override - public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties) + public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) throws PfModelException { - LOGGER.debug("deploy call"); + LOGGER.debug("deploy call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement); if (!execution(config.getDeployTimerMs(), "Current Thread deploy is Interrupted during execution {}", - element.getId())) { + instanceElement.elementId())) { return; } if (config.isDeploySuccess()) { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), - DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed"); + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, + "Deployed"); } else { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), - DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Deploy failed!"); + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, + "Deploy failed!"); } } @@ -111,99 +112,108 @@ public class AutomationCompositionElementHandler implements AutomationCompositio /** * Handle a automation composition element state change. * - * @param automationCompositionElementId the ID of the automation composition element + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element + * @throws PfModelException from Policy framework */ @Override - public void undeploy(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException { - LOGGER.debug("undeploy call"); + public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + LOGGER.debug("undeploy call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement); if (!execution(config.getUndeployTimerMs(), "Current Thread undeploy is Interrupted during execution {}", - automationCompositionElementId)) { + instanceElement.elementId())) { return; } if (config.isUndeploySuccess()) { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed"); } else { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, DeployState.DEPLOYED, null, StateChangeResult.FAILED, + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Undeploy failed!"); } } @Override - public void lock(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException { - LOGGER.debug("lock call"); + public void lock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + LOGGER.debug("lock call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement); if (!execution(config.getLockTimerMs(), "Current Thread lock is Interrupted during execution {}", - automationCompositionElementId)) { + instanceElement.elementId())) { return; } if (config.isLockSuccess()) { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked"); + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked"); } else { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, null, LockState.UNLOCKED, StateChangeResult.FAILED, "Lock failed!"); + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), null, LockState.UNLOCKED, StateChangeResult.FAILED, "Lock failed!"); } } @Override - public void unlock(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException { - LOGGER.debug("unlock call"); + public void unlock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + LOGGER.debug("unlock call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement); if (!execution(config.getUnlockTimerMs(), "Current Thread unlock is Interrupted during execution {}", - automationCompositionElementId)) { + instanceElement.elementId())) { return; } if (config.isUnlockSuccess()) { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked"); + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked"); } else { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, null, LockState.LOCKED, StateChangeResult.FAILED, "Unlock failed!"); + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), null, LockState.LOCKED, StateChangeResult.FAILED, "Unlock failed!"); } } @Override - public void delete(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException { - LOGGER.debug("delete call"); + public void delete(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + LOGGER.debug("delete call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement); if (!execution(config.getDeleteTimerMs(), "Current Thread delete is Interrupted during execution {}", - automationCompositionElementId)) { + instanceElement.elementId())) { return; } if (config.isDeleteSuccess()) { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted"); + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted"); } else { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, - automationCompositionElementId, DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, - "Delete failed!"); + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, + "Delete failed!"); } } @Override - public void update(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties) - throws PfModelException { - LOGGER.debug("update call"); + public void update(CompositionElementDto compositionElement, InstanceElementDto instanceElement, + InstanceElementDto instanceElementUpdated) throws PfModelException { + LOGGER.debug("update call compositionElement: {}, instanceElement: {}, instanceElementUpdated: {}", + compositionElement, instanceElement, instanceElementUpdated); if (!execution(config.getUpdateTimerMs(), "Current Thread update is Interrupted during execution {}", - element.getId())) { + instanceElement.elementId())) { return; } if (config.isUpdateSuccess()) { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), - DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Updated"); + intermediaryApi.updateAutomationCompositionElementState( + instanceElement.instanceId(), instanceElement.elementId(), + DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Updated"); } else { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), - DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Update failed!"); + intermediaryApi.updateAutomationCompositionElementState( + instanceElement.instanceId(), instanceElement.elementId(), + DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Update failed!"); } } @@ -238,39 +248,38 @@ public class AutomationCompositionElementHandler implements AutomationCompositio } @Override - public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList) - throws PfModelException { - LOGGER.debug("prime call"); + public void prime(CompositionDto composition) throws PfModelException { + LOGGER.debug("prime call composition: {}", composition); if (!execution(config.getPrimeTimerMs(), "Current Thread prime is Interrupted during execution {}", - compositionId)) { + composition.compositionId())) { return; } if (config.isPrimeSuccess()) { - intermediaryApi.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, - "Primed"); + intermediaryApi.updateCompositionState(composition.compositionId(), + AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed"); } else { - intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.FAILED, - "Prime failed!"); + intermediaryApi.updateCompositionState(composition.compositionId(), + AcTypeState.COMMISSIONED, StateChangeResult.FAILED, "Prime failed!"); } } @Override - public void deprime(UUID compositionId) throws PfModelException { - LOGGER.debug("deprime call"); + public void deprime(CompositionDto composition) throws PfModelException { + LOGGER.debug("deprime call composition: {}", composition); if (!execution(config.getDeprimeTimerMs(), "Current Thread deprime is Interrupted during execution {}", - compositionId)) { + composition.compositionId())) { return; } if (config.isDeprimeSuccess()) { - intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, - "Deprimed"); + intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.COMMISSIONED, + StateChangeResult.NO_ERROR, "Deprimed"); } else { - intermediaryApi.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.FAILED, - "Deprime failed!"); + intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.PRIMED, + StateChangeResult.FAILED, "Deprime failed!"); } } @@ -286,6 +295,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio for (var element : instance.getElements().values()) { var data = new InternalData(); data.setCompositionId(instance.getCompositionId()); + data.setCompositionDefinitionElementId(element.getDefinition()); data.setAutomationCompositionId(instance.getInstanceId()); data.setAutomationCompositionElementId(element.getId()); data.setIntProperties(element.getProperties()); @@ -299,55 +309,55 @@ public class AutomationCompositionElementHandler implements AutomationCompositio } @Override - public void handleRestartComposition(UUID compositionId, - List<AutomationCompositionElementDefinition> elementDefinitionList, AcTypeState state) - throws PfModelException { + public void handleRestartComposition(CompositionDto composition, AcTypeState state) throws PfModelException { LOGGER.debug("restart composition definition call"); switch (state) { case PRIMING: - prime(compositionId, elementDefinitionList); + prime(composition); break; case DEPRIMING: - deprime(compositionId); + deprime(composition); break; default: - intermediaryApi.updateCompositionState(compositionId, state, StateChangeResult.NO_ERROR, "Restarted"); + intermediaryApi.updateCompositionState(composition.compositionId(), state, + StateChangeResult.NO_ERROR, "Restarted"); } } @Override - public void handleRestartInstance(UUID automationCompositionId, AcElementDeploy element, - Map<String, Object> properties, DeployState deployState, LockState lockState) throws PfModelException { + public void handleRestartInstance(CompositionElementDto compositionElement, InstanceElementDto instanceElement, + DeployState deployState, LockState lockState) throws PfModelException { LOGGER.debug("restart instance call"); if (!AcmUtils.isInTransitionalState(deployState, lockState)) { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), - deployState, lockState, StateChangeResult.NO_ERROR, "Restarted"); + intermediaryApi.updateAutomationCompositionElementState( + instanceElement.instanceId(), instanceElement.elementId(), deployState, lockState, + StateChangeResult.NO_ERROR, "Restarted"); return; } if (DeployState.DEPLOYING.equals(deployState)) { - deploy(automationCompositionId, element, properties); + deploy(compositionElement, instanceElement); return; } if (DeployState.UNDEPLOYING.equals(deployState)) { - undeploy(automationCompositionId, element.getId()); + undeploy(compositionElement, instanceElement); return; } if (DeployState.UPDATING.equals(deployState)) { - update(automationCompositionId, element, properties); + update(compositionElement, instanceElement, instanceElement); return; } if (DeployState.DELETING.equals(deployState)) { - delete(automationCompositionId, element.getId()); + delete(compositionElement, instanceElement); return; } if (LockState.LOCKING.equals(lockState)) { - lock(automationCompositionId, element.getId()); + lock(compositionElement, instanceElement); return; } if (LockState.UNLOCKING.equals(lockState)) { - unlock(automationCompositionId, element.getId()); + unlock(compositionElement, instanceElement); } } @@ -380,21 +390,26 @@ public class AutomationCompositionElementHandler implements AutomationCompositio } @Override - public void migrate(UUID automationCompositionId, AcElementDeploy element, UUID compositionTargetId, - Map<String, Object> properties) throws PfModelException { - LOGGER.debug("migrate call"); + public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget, + InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate) + throws PfModelException { + LOGGER.debug("migrate call compositionElement: {}, compositionElementTarget: {}, instanceElement: {}," + + " instanceElementMigrate: {}", + compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate); if (!execution(config.getMigrateTimerMs(), "Current Thread migrate is Interrupted during execution {}", - element.getId())) { + instanceElement.elementId())) { return; } if (config.isMigrateSuccess()) { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), - DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated"); + intermediaryApi.updateAutomationCompositionElementState( + instanceElement.instanceId(), instanceElement.elementId(), + DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated"); } else { - intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), - DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migrate failed!"); + intermediaryApi.updateAutomationCompositionElementState( + instanceElement.instanceId(), instanceElement.elementId(), + DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migrate failed!"); } } } diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerTest.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerTest.java index d7c9e17ad..d63405369 100644 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation. + * Copyright (C) 2023-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,10 +26,12 @@ import static org.mockito.Mockito.mock; 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.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto; import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; import org.onap.policy.clamp.acm.participant.sim.comm.CommonTestData; import org.onap.policy.clamp.acm.participant.sim.model.SimConfig; @@ -52,17 +54,19 @@ class AutomationCompositionElementHandlerTest { var intermediaryApi = mock(ParticipantIntermediaryApi.class); var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi); acElementHandler.setConfig(config); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); var instanceId = UUID.randomUUID(); - var element = new AcElementDeploy(); - element.setId(UUID.randomUUID()); - acElementHandler.deploy(instanceId, element, Map.of()); - verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), - DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed"); + var elementId = UUID.randomUUID(); + var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of()); + acElementHandler.deploy(compositionElement, instanceElement); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED, + null, StateChangeResult.NO_ERROR, "Deployed"); config.setDeploySuccess(false); - acElementHandler.deploy(instanceId, element, Map.of()); - verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), - DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Deploy failed!"); + acElementHandler.deploy(compositionElement, instanceElement); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED, + null, StateChangeResult.FAILED, "Deploy failed!"); } @Test @@ -72,14 +76,17 @@ class AutomationCompositionElementHandlerTest { var intermediaryApi = mock(ParticipantIntermediaryApi.class); var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi); acElementHandler.setConfig(config); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); var instanceId = UUID.randomUUID(); var elementId = UUID.randomUUID(); - acElementHandler.undeploy(instanceId, elementId); + var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of()); + acElementHandler.undeploy(compositionElement, instanceElement); verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed"); config.setUndeploySuccess(false); - acElementHandler.undeploy(instanceId, elementId); + acElementHandler.undeploy(compositionElement, instanceElement); verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Undeploy failed!"); } @@ -91,14 +98,17 @@ class AutomationCompositionElementHandlerTest { var intermediaryApi = mock(ParticipantIntermediaryApi.class); var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi); acElementHandler.setConfig(config); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); var instanceId = UUID.randomUUID(); var elementId = UUID.randomUUID(); - acElementHandler.lock(instanceId, elementId); + var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of()); + acElementHandler.lock(compositionElement, instanceElement); verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked"); config.setLockSuccess(false); - acElementHandler.lock(instanceId, elementId); + acElementHandler.lock(compositionElement, instanceElement); verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED, StateChangeResult.FAILED, "Lock failed!"); } @@ -110,14 +120,17 @@ class AutomationCompositionElementHandlerTest { var intermediaryApi = mock(ParticipantIntermediaryApi.class); var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi); acElementHandler.setConfig(config); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); var instanceId = UUID.randomUUID(); var elementId = UUID.randomUUID(); - acElementHandler.unlock(instanceId, elementId); + var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of()); + acElementHandler.unlock(compositionElement, instanceElement); verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked"); config.setUnlockSuccess(false); - acElementHandler.unlock(instanceId, elementId); + acElementHandler.unlock(compositionElement, instanceElement); verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED, StateChangeResult.FAILED, "Unlock failed!"); } @@ -129,15 +142,20 @@ class AutomationCompositionElementHandlerTest { var intermediaryApi = mock(ParticipantIntermediaryApi.class); var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi); acElementHandler.setConfig(config); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); var instanceId = UUID.randomUUID(); var element = new AcElementDeploy(); element.setId(UUID.randomUUID()); - acElementHandler.update(instanceId, element, Map.of()); + var instanceElement = new InstanceElementDto(instanceId, element.getId(), null, Map.of(), Map.of()); + var instanceElementUpdated = new InstanceElementDto(instanceId, element.getId(), null, + Map.of("key", "value"), Map.of()); + acElementHandler.update(compositionElement, instanceElement, instanceElementUpdated); verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Updated"); config.setUpdateSuccess(false); - acElementHandler.update(instanceId, element, Map.of()); + acElementHandler.update(compositionElement, instanceElement, instanceElementUpdated); verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Update failed!"); } @@ -149,14 +167,17 @@ class AutomationCompositionElementHandlerTest { var intermediaryApi = mock(ParticipantIntermediaryApi.class); var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi); acElementHandler.setConfig(config); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); var instanceId = UUID.randomUUID(); var elementId = UUID.randomUUID(); - acElementHandler.delete(instanceId, elementId); + var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of()); + acElementHandler.delete(compositionElement, instanceElement); verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted"); config.setDeleteSuccess(false); - acElementHandler.delete(instanceId, elementId); + acElementHandler.delete(compositionElement, instanceElement); verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Delete failed!"); } @@ -221,12 +242,13 @@ class AutomationCompositionElementHandlerTest { var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi); acElementHandler.setConfig(config); var compositionId = UUID.randomUUID(); - acElementHandler.prime(compositionId, List.of()); + var composition = new CompositionDto(compositionId, Map.of(), Map.of()); + acElementHandler.prime(composition); verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed"); config.setPrimeSuccess(false); - acElementHandler.prime(compositionId, List.of()); + acElementHandler.prime(composition); verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.FAILED, "Prime failed!"); } @@ -239,12 +261,13 @@ class AutomationCompositionElementHandlerTest { var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi); acElementHandler.setConfig(config); var compositionId = UUID.randomUUID(); - acElementHandler.deprime(compositionId); + var composition = new CompositionDto(compositionId, Map.of(), Map.of()); + acElementHandler.deprime(composition); verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, "Deprimed"); config.setDeprimeSuccess(false); - acElementHandler.deprime(compositionId); + acElementHandler.deprime(composition); verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.FAILED, "Deprime failed!"); } @@ -257,15 +280,16 @@ class AutomationCompositionElementHandlerTest { var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi); acElementHandler.setConfig(config); var compositionId = UUID.randomUUID(); - acElementHandler.handleRestartComposition(compositionId, List.of(), AcTypeState.PRIMING); + var composition = new CompositionDto(compositionId, Map.of(), Map.of()); + acElementHandler.handleRestartComposition(composition, AcTypeState.PRIMING); verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed"); - acElementHandler.handleRestartComposition(compositionId, List.of(), AcTypeState.PRIMED); + acElementHandler.handleRestartComposition(composition, AcTypeState.PRIMED); verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Restarted"); - acElementHandler.handleRestartComposition(compositionId, List.of(), AcTypeState.DEPRIMING); + acElementHandler.handleRestartComposition(composition, AcTypeState.DEPRIMING); verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, "Deprimed"); } @@ -278,36 +302,43 @@ class AutomationCompositionElementHandlerTest { var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi); acElementHandler.setConfig(config); var instanceId = UUID.randomUUID(); - var element = new AcElementDeploy(); - element.setId(UUID.randomUUID()); - acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.DEPLOYING, LockState.NONE); - verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), + var elementId = UUID.randomUUID(); + var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of()); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); + acElementHandler.handleRestartInstance(compositionElement, instanceElement, + DeployState.DEPLOYING, LockState.NONE); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed"); - acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.DEPLOYED, LockState.LOCKED); - verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), + acElementHandler.handleRestartInstance(compositionElement, instanceElement, + DeployState.DEPLOYED, LockState.LOCKED); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED, LockState.LOCKED, StateChangeResult.NO_ERROR, "Restarted"); - acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.UPDATING, LockState.LOCKED); - verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), + acElementHandler.handleRestartInstance(compositionElement, instanceElement, + DeployState.UPDATING, LockState.LOCKED); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Updated"); - acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.UNDEPLOYING, + acElementHandler.handleRestartInstance(compositionElement, instanceElement, DeployState.UNDEPLOYING, LockState.LOCKED); - verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), + verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed"); - acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.DELETING, LockState.NONE); - verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), + acElementHandler.handleRestartInstance(compositionElement, instanceElement, + DeployState.DELETING, LockState.NONE); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted"); - acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.DEPLOYED, LockState.LOCKING); - verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), null, + acElementHandler.handleRestartInstance(compositionElement, instanceElement, + DeployState.DEPLOYED, LockState.LOCKING); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked"); - acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.DEPLOYED, + acElementHandler.handleRestartInstance(compositionElement, instanceElement, DeployState.DEPLOYED, LockState.UNLOCKING); - verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), null, + verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked"); } @@ -353,15 +384,24 @@ class AutomationCompositionElementHandlerTest { var intermediaryApi = mock(ParticipantIntermediaryApi.class); var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi); acElementHandler.setConfig(config); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); + var compositionElementTraget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); var instanceId = UUID.randomUUID(); var element = new AcElementDeploy(); element.setId(UUID.randomUUID()); - acElementHandler.migrate(instanceId, element, UUID.randomUUID(), Map.of()); + var instanceElement = new InstanceElementDto(instanceId, element.getId(), null, Map.of(), Map.of()); + var instanceElementMigrated = new InstanceElementDto(instanceId, element.getId(), + null, Map.of("key", "value"), Map.of()); + acElementHandler + .migrate(compositionElement, compositionElementTraget, instanceElement, instanceElementMigrated); verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated"); config.setMigrateSuccess(false); - acElementHandler.migrate(instanceId, element, UUID.randomUUID(), Map.of()); + acElementHandler + .migrate(compositionElement, compositionElementTraget, instanceElement, instanceElementMigrated); verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migrate failed!"); } 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 6e4fca55f..505f515d7 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,12 +20,7 @@ package org.onap.policy.clamp.acm.participant.intermediary.api; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; -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.models.base.PfModelException; @@ -35,45 +30,79 @@ import org.onap.policy.models.base.PfModelException; */ public interface AutomationCompositionElementListener { /** - * Handle a automation composition element state change. + * Handle a deploy on a automation composition element. * - * @param automationCompositionElementId the ID of the automation composition element - * @throws PfModelException in case of a model exception + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element + * @throws PfModelException from Policy framework */ - void undeploy(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException; + void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) throws PfModelException; /** - * Handle an update on a automation composition element. + * Handle an udeploy on a automation composition element. * - * @param automationCompositionId the automationComposition Id - * @param element the information on the automation composition element - * @param properties properties Map - * @throws PfModelException from Policy framework + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element + * @throws PfModelException in case of a model exception */ - void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties) - throws PfModelException; + void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) throws PfModelException; - void lock(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException; + /** + * Handle a lock on a automation composition element. + * + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element + * @throws PfModelException in case of a model exception + */ + void lock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) throws PfModelException; - void unlock(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException; + /** + * Handle an unlock on a automation composition element. + * + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element + * @throws PfModelException in case of a model exception + */ + void unlock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) throws PfModelException; - void delete(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException; + /** + * Handle a delete on a automation composition element. + * + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element + * @throws PfModelException in case of a model exception + */ + void delete(CompositionElementDto compositionElement, InstanceElementDto instanceElement) throws PfModelException; - void update(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties) - throws PfModelException; + /** + * Handle an update on a automation composition element. + * + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element + * @param instanceElementUpdated the information of the Automation Composition Instance Element updated + * @throws PfModelException from Policy framework + */ + void update(CompositionElementDto compositionElement, InstanceElementDto instanceElement, + InstanceElementDto instanceElementUpdated) throws PfModelException; - void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList) - throws PfModelException; + void prime(CompositionDto composition) throws PfModelException; - void deprime(UUID compositionId) throws PfModelException; + void deprime(CompositionDto composition) throws PfModelException; - void handleRestartComposition(UUID compositionId, - List<AutomationCompositionElementDefinition> elementDefinitionList, AcTypeState state) - throws PfModelException; + void handleRestartComposition(CompositionDto composition, AcTypeState state) throws PfModelException; - void handleRestartInstance(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties, + void handleRestartInstance(CompositionElementDto compositionElement, InstanceElementDto instanceElement, DeployState deployState, LockState lockState) throws PfModelException; - void migrate(UUID instanceId, AcElementDeploy element, UUID compositionTargetId, Map<String, Object> properties) - throws PfModelException; + /** + * Handle an update on a automation composition element. + * + * @param compositionElement the information of the Automation Composition Definition Element + * @param compositionElementTarget the information of the Automation Composition Definition Element Target + * @param instanceElement the information of the Automation Composition Instance Element + * @param instanceElementMigrate the information of the Automation Composition Instance Element updated + * @throws PfModelException from Policy framework + */ + void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget, + InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate) throws PfModelException; } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/CompositionDto.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/CompositionDto.java new file mode 100644 index 000000000..88f080bc7 --- /dev/null +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/CompositionDto.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2024 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.participant.intermediary.api; + +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +public record CompositionDto(UUID compositionId, + Map<ToscaConceptIdentifier, Map<String, Object>> inPropertiesMap, + Map<ToscaConceptIdentifier, Map<String, Object>> outPropertiesMap) { +} diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/CompositionElementDto.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/CompositionElementDto.java new file mode 100644 index 000000000..d203f90cb --- /dev/null +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/CompositionElementDto.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2024 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.participant.intermediary.api; + +import java.util.Map; +import java.util.UUID; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +public record CompositionElementDto(UUID compositionId, ToscaConceptIdentifier elementDefinitionId, + Map<String, Object> inProperties, Map<String, Object> outProperties) { +} diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/InstanceElementDto.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/InstanceElementDto.java new file mode 100644 index 000000000..197d7e46d --- /dev/null +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/InstanceElementDto.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2024 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.participant.intermediary.api; + +import java.util.Map; +import java.util.UUID; +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.models.tosca.authorative.concepts.ToscaServiceTemplate; + +public record InstanceElementDto(UUID instanceId, UUID elementId, ToscaServiceTemplate toscaServiceTemplateFragment, + Map<String, Object> inProperties, Map<String, Object> outProperties) { +} diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV1.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV1.java new file mode 100644 index 000000000..f91a2a180 --- /dev/null +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV1.java @@ -0,0 +1,260 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2024 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.participant.intermediary.api.impl; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +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.CompositionDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto; +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.AcTypeState; +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.StateChangeResult; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; + +/** + * Wrapper of AutomationCompositionElementListener. + * Valid since 7.1.0 release. + */ +public abstract class AcElementListenerV1 implements AutomationCompositionElementListener { + protected final ParticipantIntermediaryApi intermediaryApi; + + protected AcElementListenerV1(ParticipantIntermediaryApi intermediaryApi) { + this.intermediaryApi = intermediaryApi; + } + + @Override + public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + var element = new AcElementDeploy(); + element.setId(instanceElement.elementId()); + element.setDefinition(compositionElement.elementDefinitionId()); + element.setToscaServiceTemplateFragment(instanceElement.toscaServiceTemplateFragment()); + element.setProperties(instanceElement.inProperties()); + Map<String, Object> properties = new HashMap<>(instanceElement.inProperties()); + properties.putAll(compositionElement.inProperties()); + deploy(instanceElement.instanceId(), element, properties); + } + + public abstract void deploy(UUID instanceId, AcElementDeploy element, Map<String, Object> properties) + throws PfModelException; + + @Override + public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + undeploy(instanceElement.instanceId(), instanceElement.elementId()); + } + + public abstract void undeploy(UUID instanceId, UUID elementId) throws PfModelException; + + @Override + public void lock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + lock(instanceElement.instanceId(), instanceElement.elementId()); + } + + public void lock(UUID instanceId, UUID elementId) throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED, + StateChangeResult.NO_ERROR, "Locked"); + } + + @Override + public void unlock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + unlock(instanceElement.instanceId(), instanceElement.elementId()); + } + + public void unlock(UUID instanceId, UUID elementId) throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED, + StateChangeResult.NO_ERROR, "Unlocked"); + } + + @Override + public void delete(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + delete(instanceElement.instanceId(), instanceElement.elementId()); + } + + public void delete(UUID instanceId, UUID elementId) throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.DELETED, null, + StateChangeResult.NO_ERROR, "Deleted"); + } + + @Override + public void update(CompositionElementDto compositionElement, InstanceElementDto instanceElement, + InstanceElementDto instanceElementUpdated) throws PfModelException { + var element = new AcElementDeploy(); + element.setId(instanceElementUpdated.elementId()); + element.setDefinition(compositionElement.elementDefinitionId()); + element.setProperties(instanceElementUpdated.inProperties()); + update(instanceElementUpdated.instanceId(), element, element.getProperties()); + } + + public void update(UUID instanceId, AcElementDeploy element, Map<String, Object> properties) + throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, null, + StateChangeResult.NO_ERROR, "Update not supported"); + } + + private List<AutomationCompositionElementDefinition> createAcElementDefinitionList(CompositionDto composition) { + List<AutomationCompositionElementDefinition> elementDefinitionList = new ArrayList<>(); + for (var entry : composition.inPropertiesMap().entrySet()) { + elementDefinitionList.add(createAcElementDefinition(entry.getKey(), entry.getValue(), + composition.outPropertiesMap().get(entry.getKey()))); + } + return elementDefinitionList; + } + + private AutomationCompositionElementDefinition createAcElementDefinition( + ToscaConceptIdentifier toscaConceptIdentifier, Map<String, Object> property, + Map<String, Object> outProperties) { + var acElementDefinition = new AutomationCompositionElementDefinition(); + acElementDefinition.setAcElementDefinitionId(toscaConceptIdentifier); + var toscaNodeTemplate = new ToscaNodeTemplate(); + toscaNodeTemplate.setProperties(property); + acElementDefinition.setAutomationCompositionElementToscaNodeTemplate(toscaNodeTemplate); + acElementDefinition.setOutProperties(outProperties); + return acElementDefinition; + } + + @Override + public void prime(CompositionDto composition) throws PfModelException { + prime(composition.compositionId(), createAcElementDefinitionList(composition)); + } + + public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList) + throws PfModelException { + intermediaryApi.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed"); + } + + @Override + public void deprime(CompositionDto composition) throws PfModelException { + deprime(composition.compositionId()); + } + + public void deprime(UUID compositionId) throws PfModelException { + intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, + "Deprimed"); + } + + @Override + public void handleRestartComposition(CompositionDto composition, AcTypeState state) throws PfModelException { + handleRestartComposition(composition.compositionId(), createAcElementDefinitionList(composition), state); + } + + /** + * Default implementation of handle Restart Composition. + * + * @param compositionId the composition Id + * @param elementDefinitionList the list of AutomationCompositionElementDefinition + * @param state the current AcTypeState + * @throws PfModelException in case of a model exception + */ + public void handleRestartComposition(UUID compositionId, + List<AutomationCompositionElementDefinition> elementDefinitionList, AcTypeState state) throws PfModelException { + switch (state) { + case PRIMING -> prime(compositionId, elementDefinitionList); + case DEPRIMING -> deprime(compositionId); + default -> + intermediaryApi.updateCompositionState(compositionId, state, StateChangeResult.NO_ERROR, "Restarted"); + } + } + + @Override + public void handleRestartInstance(CompositionElementDto compositionElement, InstanceElementDto instanceElement, + DeployState deployState, LockState lockState) throws PfModelException { + var element = new AcElementDeploy(); + element.setId(instanceElement.elementId()); + element.setDefinition(compositionElement.elementDefinitionId()); + element.setProperties(instanceElement.inProperties()); + Map<String, Object> properties = new HashMap<>(instanceElement.inProperties()); + properties.putAll(compositionElement.inProperties()); + handleRestartInstance(instanceElement.instanceId(), element, properties, deployState, lockState); + } + + /** + * Default implementation of handle Restart Instance. + * + * @param instanceId the instance Id + * @param element the AcElementDeploy + * @param properties the in properties + * @param deployState the current deployState + * @param lockState the current lockState + * @throws PfModelException in case of a model exception + */ + public void handleRestartInstance(UUID instanceId, AcElementDeploy element, + Map<String, Object> properties, DeployState deployState, LockState lockState) throws PfModelException { + + if (DeployState.DEPLOYING.equals(deployState)) { + deploy(instanceId, element, properties); + return; + } + if (DeployState.UNDEPLOYING.equals(deployState)) { + undeploy(instanceId, element.getId()); + return; + } + if (DeployState.UPDATING.equals(deployState)) { + update(instanceId, element, properties); + return; + } + if (DeployState.DELETING.equals(deployState)) { + delete(instanceId, element.getId()); + return; + } + if (LockState.LOCKING.equals(lockState)) { + lock(instanceId, element.getId()); + return; + } + if (LockState.UNLOCKING.equals(lockState)) { + unlock(instanceId, element.getId()); + return; + } + intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), + deployState, lockState, StateChangeResult.NO_ERROR, "Restarted"); + } + + @Override + public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget, + InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate) throws PfModelException { + var element = new AcElementDeploy(); + element.setId(instanceElement.elementId()); + element.setDefinition(compositionElement.elementDefinitionId()); + element.setProperties(instanceElement.inProperties()); + migrate(instanceElementMigrate.instanceId(), element, compositionElementTarget.compositionId(), + element.getProperties()); + } + + public void migrate(UUID instanceId, AcElementDeploy element, UUID compositionTargetId, + Map<String, Object> properties) throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), + DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated"); + } +} diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV2.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV2.java new file mode 100644 index 000000000..daf9d6e71 --- /dev/null +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV2.java @@ -0,0 +1,136 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2024 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.participant.intermediary.api.impl; + +import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; +import org.onap.policy.clamp.models.acm.concepts.AcTypeState; +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.StateChangeResult; +import org.onap.policy.models.base.PfModelException; + +/** + * Wrapper of AutomationCompositionElementListener. + * Valid since 7.1.1 release. + */ +public abstract class AcElementListenerV2 implements AutomationCompositionElementListener { + protected final ParticipantIntermediaryApi intermediaryApi; + + protected AcElementListenerV2(ParticipantIntermediaryApi intermediaryApi) { + this.intermediaryApi = intermediaryApi; + } + + @Override + public void lock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked"); + } + + @Override + public void unlock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked"); + } + + @Override + public void delete(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted"); + } + + @Override + public void update(CompositionElementDto compositionElement, InstanceElementDto instanceElement, + InstanceElementDto instanceElementUpdated) throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DEPLOYED, null, + StateChangeResult.NO_ERROR, "Update not supported"); + + } + + @Override + public void prime(CompositionDto composition) throws PfModelException { + intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.PRIMED, + StateChangeResult.NO_ERROR, "Primed"); + } + + @Override + public void deprime(CompositionDto composition) throws PfModelException { + intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.COMMISSIONED, + StateChangeResult.NO_ERROR, "Deprimed"); + } + + @Override + public void handleRestartComposition(CompositionDto composition, AcTypeState state) throws PfModelException { + switch (state) { + case PRIMING -> prime(composition); + case DEPRIMING -> deprime(composition); + default -> intermediaryApi + .updateCompositionState(composition.compositionId(), state, StateChangeResult.NO_ERROR, "Restarted"); + } + } + + @Override + public void handleRestartInstance(CompositionElementDto compositionElement, InstanceElementDto instanceElement, + DeployState deployState, LockState lockState) throws PfModelException { + + if (DeployState.DEPLOYING.equals(deployState)) { + deploy(compositionElement, instanceElement); + return; + } + if (DeployState.UNDEPLOYING.equals(deployState)) { + undeploy(compositionElement, instanceElement); + return; + } + if (DeployState.UPDATING.equals(deployState)) { + update(compositionElement, instanceElement, instanceElement); + return; + } + if (DeployState.DELETING.equals(deployState)) { + delete(compositionElement, instanceElement); + return; + } + if (LockState.LOCKING.equals(lockState)) { + lock(compositionElement, instanceElement); + return; + } + if (LockState.UNLOCKING.equals(lockState)) { + unlock(compositionElement, instanceElement); + return; + } + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), deployState, lockState, StateChangeResult.NO_ERROR, "Restarted"); + } + + @Override + public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget, + InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate) + throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(instanceElementMigrate.instanceId(), + instanceElementMigrate.elementId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated"); + } +} 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 49b7b731e..fd82c37ba 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,13 +21,20 @@ package org.onap.policy.clamp.acm.participant.intermediary.handler; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.UUID; +import java.util.stream.Collectors; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto; import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher; import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; 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; @@ -195,11 +202,12 @@ public class AutomationCompositionHandler { for (var participantDeploy : updateMsg.getParticipantUpdatesList()) { if (cacheProvider.getParticipantId().equals(participantDeploy.getParticipantId())) { + var acCopy = new AutomationComposition(cacheProvider.getAutomationComposition( + updateMsg.getAutomationCompositionId())); updateExistingElementsOnThisParticipant(updateMsg.getAutomationCompositionId(), participantDeploy, DeployState.UPDATING); - callParticipantUpdateProperty(updateMsg.getMessageId(), participantDeploy.getAcElementList(), - updateMsg.getAutomationCompositionId()); + callParticipantUpdateProperty(updateMsg.getMessageId(), participantDeploy.getAcElementList(), acCopy); } } } @@ -228,32 +236,78 @@ public class AutomationCompositionHandler { } } - private void callParticipanDeploy(UUID messageId, List<AcElementDeploy> acElements, Integer startPhaseMsg, - UUID instanceId) { - for (var element : acElements) { - var commonProperties = cacheProvider.getCommonProperties(instanceId, element.getId()); - int startPhase = ParticipantUtils.findStartPhase(commonProperties); + private void callParticipanDeploy(UUID messageId, List<AcElementDeploy> acElementDeployList, + Integer startPhaseMsg, UUID instanceId) { + var automationComposition = cacheProvider.getAutomationComposition(instanceId); + for (var elementDeploy : acElementDeployList) { + var element = automationComposition.getElements().get(elementDeploy.getId()); + var compositionInProperties = cacheProvider + .getCommonProperties(automationComposition.getCompositionId(), element.getDefinition()); + int startPhase = ParticipantUtils.findStartPhase(compositionInProperties); if (startPhaseMsg.equals(startPhase)) { - var map = new HashMap<>(commonProperties); - map.putAll(element.getProperties()); - listener.deploy(messageId, instanceId, element, map); + var compositionElement = createCompositionElementDto(automationComposition.getCompositionId(), + element, compositionInProperties); + var instanceElement = new InstanceElementDto(instanceId, elementDeploy.getId(), + elementDeploy.getToscaServiceTemplateFragment(), + elementDeploy.getProperties(), element.getOutProperties()); + listener.deploy(messageId, compositionElement, instanceElement); } } } - private void callParticipantUpdateProperty(UUID messageId, List<AcElementDeploy> acElements, UUID instanceId) { - for (var element : acElements) { - listener.update(messageId, instanceId, element, element.getProperties()); + private CompositionElementDto createCompositionElementDto(UUID compositionId, AutomationCompositionElement element, + Map<String, Object> compositionInProperties) { + var compositionOutProperties = cacheProvider.getAcElementsDefinitions() + .get(compositionId).get(element.getDefinition()).getOutProperties(); + return new CompositionElementDto(compositionId, + element.getDefinition(), compositionInProperties, compositionOutProperties); + } + + private Map<UUID, CompositionElementDto> getCompositionElementDtoMap(AutomationComposition automationComposition, + UUID compositionId) { + Map<UUID, CompositionElementDto> map = new HashMap<>(); + for (var element : automationComposition.getElements().values()) { + var compositionInProperties = cacheProvider.getCommonProperties(compositionId, element.getDefinition()); + var compositionElement = createCompositionElementDto(compositionId, element, compositionInProperties); + map.put(element.getId(), compositionElement); + } + return map; + } + + private Map<UUID, CompositionElementDto> getCompositionElementDtoMap(AutomationComposition automationComposition) { + return getCompositionElementDtoMap(automationComposition, automationComposition.getCompositionId()); + } + + private Map<UUID, InstanceElementDto> getInstanceElementDtoMap(AutomationComposition automationComposition) { + Map<UUID, InstanceElementDto> map = new HashMap<>(); + for (var element : automationComposition.getElements().values()) { + var instanceElement = new InstanceElementDto(automationComposition.getInstanceId(), element.getId(), + null, element.getProperties(), element.getOutProperties()); + map.put(element.getId(), instanceElement); + } + return map; + } + + private void callParticipantUpdateProperty(UUID messageId, List<AcElementDeploy> acElements, + AutomationComposition acCopy) { + var instanceElementDtoMap = getInstanceElementDtoMap(acCopy); + var instanceElementDtoMapUpdated = getInstanceElementDtoMap( + cacheProvider.getAutomationComposition(acCopy.getInstanceId())); + var compositionElementDtoMap = getCompositionElementDtoMap(acCopy); + for (var acElement : acElements) { + listener.update(messageId, compositionElementDtoMap.get(acElement.getId()), + instanceElementDtoMap.get(acElement.getId()), instanceElementDtoMapUpdated.get(acElement.getId())); } } private void updateExistingElementsOnThisParticipant(UUID instanceId, ParticipantDeploy participantDeploy, - DeployState deployState) { + DeployState deployState) { var acElementList = cacheProvider.getAutomationComposition(instanceId).getElements(); for (var element : participantDeploy.getAcElementList()) { var acElement = acElementList.get(element.getId()); acElement.getProperties().putAll(element.getProperties()); acElement.setDeployState(deployState); + acElement.setDefinition(element.getDefinition()); } } @@ -267,24 +321,34 @@ public class AutomationCompositionHandler { private void handleUndeployState(UUID messageId, final AutomationComposition automationComposition, Integer startPhaseMsg) { automationComposition.setCompositionTargetId(null); - for (var acElement : automationComposition.getElements().values()) { - int startPhase = ParticipantUtils.findStartPhase( - cacheProvider.getCommonProperties(automationComposition.getInstanceId(), acElement.getId())); + for (var element : automationComposition.getElements().values()) { + var compositionInProperties = cacheProvider + .getCommonProperties(automationComposition.getCompositionId(), element.getDefinition()); + int startPhase = ParticipantUtils.findStartPhase(compositionInProperties); if (startPhaseMsg.equals(startPhase)) { - acElement.setDeployState(DeployState.UNDEPLOYING); - listener.undeploy(messageId, automationComposition.getInstanceId(), acElement.getId()); + element.setDeployState(DeployState.UNDEPLOYING); + var compositionElement = createCompositionElementDto(automationComposition.getCompositionId(), + element, compositionInProperties); + var instanceElement = new InstanceElementDto(automationComposition.getInstanceId(), element.getId(), + null, element.getProperties(), element.getOutProperties()); + listener.undeploy(messageId, compositionElement, instanceElement); } } } private void handleDeleteState(UUID messageId, final AutomationComposition automationComposition, Integer startPhaseMsg) { - for (var acElement : automationComposition.getElements().values()) { - int startPhase = ParticipantUtils.findStartPhase( - cacheProvider.getCommonProperties(automationComposition.getInstanceId(), acElement.getId())); + for (var element : automationComposition.getElements().values()) { + var compositionInProperties = cacheProvider + .getCommonProperties(automationComposition.getCompositionId(), element.getDefinition()); + int startPhase = ParticipantUtils.findStartPhase(compositionInProperties); if (startPhaseMsg.equals(startPhase)) { - acElement.setDeployState(DeployState.DELETING); - listener.delete(messageId, automationComposition.getInstanceId(), acElement.getId()); + element.setDeployState(DeployState.DELETING); + var compositionElement = createCompositionElementDto(automationComposition.getCompositionId(), + element, compositionInProperties); + var instanceElement = new InstanceElementDto(automationComposition.getInstanceId(), element.getId(), + null, element.getProperties(), element.getOutProperties()); + listener.delete(messageId, compositionElement, instanceElement); } } } @@ -298,12 +362,17 @@ public class AutomationCompositionHandler { */ private void handleLockState(UUID messageId, final AutomationComposition automationComposition, Integer startPhaseMsg) { - for (var acElement : automationComposition.getElements().values()) { - int startPhase = ParticipantUtils.findStartPhase( - cacheProvider.getCommonProperties(automationComposition.getInstanceId(), acElement.getId())); + for (var element : automationComposition.getElements().values()) { + var compositionInProperties = cacheProvider + .getCommonProperties(automationComposition.getCompositionId(), element.getDefinition()); + int startPhase = ParticipantUtils.findStartPhase(compositionInProperties); if (startPhaseMsg.equals(startPhase)) { - acElement.setLockState(LockState.LOCKING); - listener.lock(messageId, automationComposition.getInstanceId(), acElement.getId()); + element.setLockState(LockState.LOCKING); + var compositionElement = createCompositionElementDto(automationComposition.getCompositionId(), + element, compositionInProperties); + var instanceElement = new InstanceElementDto(automationComposition.getInstanceId(), element.getId(), + null, element.getProperties(), element.getOutProperties()); + listener.lock(messageId, compositionElement, instanceElement); } } } @@ -317,12 +386,17 @@ public class AutomationCompositionHandler { */ private void handleUnlockState(UUID messageId, final AutomationComposition automationComposition, Integer startPhaseMsg) { - for (var acElement : automationComposition.getElements().values()) { - int startPhase = ParticipantUtils.findStartPhase( - cacheProvider.getCommonProperties(automationComposition.getInstanceId(), acElement.getId())); + for (var element : automationComposition.getElements().values()) { + var compositionInProperties = cacheProvider + .getCommonProperties(automationComposition.getCompositionId(), element.getDefinition()); + int startPhase = ParticipantUtils.findStartPhase(compositionInProperties); if (startPhaseMsg.equals(startPhase)) { - acElement.setLockState(LockState.UNLOCKING); - listener.unlock(messageId, automationComposition.getInstanceId(), acElement.getId()); + element.setLockState(LockState.UNLOCKING); + var compositionElement = createCompositionElementDto(automationComposition.getCompositionId(), + element, compositionInProperties); + var instanceElement = new InstanceElementDto(automationComposition.getInstanceId(), element.getId(), + null, element.getProperties(), element.getOutProperties()); + listener.unlock(messageId, compositionElement, instanceElement); } } } @@ -335,7 +409,13 @@ public class AutomationCompositionHandler { * @param list the list of AutomationCompositionElementDefinition */ public void prime(UUID messageId, UUID compositionId, List<AutomationCompositionElementDefinition> list) { - listener.prime(messageId, compositionId, list); + var inPropertiesMap = list.stream().collect(Collectors.toMap( + AutomationCompositionElementDefinition::getAcElementDefinitionId, + el -> el.getAutomationCompositionElementToscaNodeTemplate().getProperties())); + var outPropertiesMap = list.stream().collect(Collectors.toMap( + AutomationCompositionElementDefinition::getAcElementDefinitionId, + AutomationCompositionElementDefinition::getOutProperties)); + listener.prime(messageId, new CompositionDto(compositionId, inPropertiesMap, outPropertiesMap)); } /** @@ -345,7 +425,19 @@ public class AutomationCompositionHandler { * @param compositionId the compositionId */ public void deprime(UUID messageId, UUID compositionId) { - listener.deprime(messageId, compositionId); + var acElementsDefinitions = cacheProvider.getAcElementsDefinitions().get(compositionId); + if (acElementsDefinitions == null) { + // this participant does not handle this composition + return; + } + var list = new ArrayList<>(acElementsDefinitions.values()); + var inPropertiesMap = list.stream().collect(Collectors.toMap( + AutomationCompositionElementDefinition::getAcElementDefinitionId, + el -> el.getAutomationCompositionElementToscaNodeTemplate().getProperties())); + var outPropertiesMap = list.stream().collect(Collectors.toMap( + AutomationCompositionElementDefinition::getAcElementDefinitionId, + AutomationCompositionElementDefinition::getOutProperties)); + listener.deprime(messageId, new CompositionDto(compositionId, inPropertiesMap, outPropertiesMap)); } /** @@ -363,7 +455,14 @@ public class AutomationCompositionHandler { for (var automationcomposition : automationCompositionList) { cacheProvider.initializeAutomationComposition(compositionId, automationcomposition); } - listener.restarted(messageId, compositionId, list, state, automationCompositionList); + var inPropertiesMap = list.stream().collect(Collectors.toMap( + AutomationCompositionElementDefinition::getAcElementDefinitionId, + el -> el.getAutomationCompositionElementToscaNodeTemplate().getProperties())); + var outPropertiesMap = list.stream().collect(Collectors.toMap( + AutomationCompositionElementDefinition::getAcElementDefinitionId, + AutomationCompositionElementDefinition::getOutProperties)); + var composition = new CompositionDto(compositionId, inPropertiesMap, outPropertiesMap); + listener.restarted(messageId, composition, state, automationCompositionList); } /** @@ -382,6 +481,7 @@ public class AutomationCompositionHandler { migrationMsg.getAutomationCompositionId()); return; } + var acCopy = new AutomationComposition(automationComposition); automationComposition.setCompositionTargetId(migrationMsg.getCompositionTargetId()); for (var participantDeploy : migrationMsg.getParticipantUpdatesList()) { if (cacheProvider.getParticipantId().equals(participantDeploy.getParticipantId())) { @@ -390,15 +490,23 @@ public class AutomationCompositionHandler { DeployState.MIGRATING); callParticipantMigrate(migrationMsg.getMessageId(), participantDeploy.getAcElementList(), - migrationMsg.getAutomationCompositionId(), migrationMsg.getCompositionTargetId()); + acCopy, migrationMsg.getCompositionTargetId()); } } } - private void callParticipantMigrate(UUID messageId, List<AcElementDeploy> acElements, UUID instanceId, - UUID compositionTargetId) { - for (var element : acElements) { - listener.migrate(messageId, instanceId, element, compositionTargetId, element.getProperties()); + private void callParticipantMigrate(UUID messageId, List<AcElementDeploy> acElements, + AutomationComposition acCopy, UUID compositionTargetId) { + var compositionElementMap = getCompositionElementDtoMap(acCopy); + var instanceElementMap = getInstanceElementDtoMap(acCopy); + var automationComposition = cacheProvider.getAutomationComposition(acCopy.getInstanceId()); + var compositionElementTargetMap = getCompositionElementDtoMap(automationComposition, compositionTargetId); + var instanceElementMigrateMap = getInstanceElementDtoMap(automationComposition); + + for (var acElement : acElements) { + listener.migrate(messageId, compositionElementMap.get(acElement.getId()), + compositionElementTargetMap.get(acElement.getId()), + instanceElementMap.get(acElement.getId()), instanceElementMigrateMap.get(acElement.getId())); } } } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProvider.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProvider.java index cc61c4739..630dfc6ab 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProvider.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProvider.java @@ -125,6 +125,19 @@ public class CacheProvider { } /** + * Get CommonProperties. + * + * @param compositionId the composition Id + * @param definition the AutomationCompositionElementDefinition Id + * @return the common Properties as Map + */ + public Map<String, Object> getCommonProperties(@NonNull UUID compositionId, + @NonNull ToscaConceptIdentifier definition) { + return acElementsDefinitions.get(compositionId).get(definition) + .getAutomationCompositionElementToscaNodeTemplate().getProperties(); + } + + /** * Initialize an AutomationComposition from a ParticipantDeploy. * * @param compositionId the composition Id 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 8c1aed32f..ce0da680b 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 @@ -196,9 +196,11 @@ public class ParticipantHandler { list.addAll(participantDefinition.getAutomationCompositionElementDefinitionList()); } } - cacheProvider.addElementDefinition(participantPrimeMsg.getCompositionId(), list); - automationCompositionHandler.prime(participantPrimeMsg.getMessageId(), + if (!list.isEmpty()) { + cacheProvider.addElementDefinition(participantPrimeMsg.getCompositionId(), list); + automationCompositionHandler.prime(participantPrimeMsg.getMessageId(), participantPrimeMsg.getCompositionId(), list); + } } else { // deprime automationCompositionHandler.deprime(participantPrimeMsg.getMessageId(), diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandler.java index 0aed919e5..9f3e16777 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandler.java @@ -23,7 +23,6 @@ package org.onap.policy.clamp.acm.participant.intermediary.handler; import io.opentelemetry.context.Context; import java.io.Closeable; import java.io.IOException; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; @@ -33,11 +32,11 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import lombok.RequiredArgsConstructor; import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto; 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.AcElementRestart; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; -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.ParticipantRestartAc; @@ -62,149 +61,163 @@ public class ThreadHandler implements Closeable { Context.taskWrapping(Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())); /** - * Handle an update on a automation composition element. + * Handle a deploy on a automation composition element. * * @param messageId the messageId - * @param instanceId the automationComposition Id - * @param element the information on the automation composition element - * @param properties properties Map + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element */ - public void deploy(UUID messageId, UUID instanceId, AcElementDeploy element, Map<String, Object> properties) { - cleanExecution(element.getId(), messageId); - var result = executor.submit(() -> this.deployProcess(instanceId, element, properties)); - executionMap.put(element.getId(), result); + public void deploy(UUID messageId, CompositionElementDto compositionElement, InstanceElementDto instanceElement) { + cleanExecution(instanceElement.elementId(), messageId); + var result = executor.submit(() -> this.deployProcess(compositionElement, instanceElement)); + executionMap.put(instanceElement.elementId(), result); } - private void deployProcess(UUID instanceId, AcElementDeploy element, Map<String, Object> properties) { + private void deployProcess(CompositionElementDto compositionElement, InstanceElementDto instanceElement) { try { - listener.deploy(instanceId, element, properties); + listener.deploy(compositionElement, instanceElement); } catch (PfModelException e) { - LOGGER.error("Automation composition element deploy failed {} {}", instanceId, e.getMessage()); - intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.UNDEPLOYED, - null, StateChangeResult.FAILED, "Automation composition element deploy failed"); + LOGGER.error("Automation composition element deploy failed {} {}", instanceElement.elementId(), + e.getMessage()); + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, + "Automation composition element deploy failed"); } - executionMap.remove(element.getId()); + executionMap.remove(instanceElement.elementId()); } /** - * Handle a automation composition element state change. + * Handle an udeploy on a automation composition element. * * @param messageId the messageId - * @param instanceId the automationComposition Id - * @param elementId the ID of the automation composition element + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element */ - public void undeploy(UUID messageId, UUID instanceId, UUID elementId) { - cleanExecution(elementId, messageId); - var result = executor.submit(() -> this.undeployProcess(instanceId, elementId)); - executionMap.put(elementId, result); + public void undeploy(UUID messageId, CompositionElementDto compositionElement, InstanceElementDto instanceElement) { + cleanExecution(instanceElement.elementId(), messageId); + var result = executor.submit(() -> this.undeployProcess(compositionElement, instanceElement)); + executionMap.put(instanceElement.elementId(), result); } - private void undeployProcess(UUID instanceId, UUID elementId) { + private void undeployProcess(CompositionElementDto compositionElement, InstanceElementDto instanceElement) { try { - listener.undeploy(instanceId, elementId); + listener.undeploy(compositionElement, instanceElement); } catch (PfModelException e) { - LOGGER.error("Automation composition element undeploy failed {} {}", instanceId, e.getMessage()); - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED, null, - StateChangeResult.FAILED, "Automation composition element undeploy failed"); + LOGGER.error( + "Automation composition element undeploy failed {} {}", instanceElement.elementId(), e.getMessage()); + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DEPLOYED, null, + StateChangeResult.FAILED, "Automation composition element undeploy failed"); } - executionMap.remove(elementId); + executionMap.remove(instanceElement.elementId()); } /** * Handle a automation composition element lock. * * @param messageId the messageId - * @param instanceId the automationComposition Id - * @param elementId the ID of the automation composition element + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element */ - public void lock(UUID messageId, UUID instanceId, UUID elementId) { - cleanExecution(elementId, messageId); - var result = executor.submit(() -> this.lockProcess(instanceId, elementId)); - executionMap.put(elementId, result); + public void lock(UUID messageId, CompositionElementDto compositionElement, InstanceElementDto instanceElement) { + cleanExecution(instanceElement.elementId(), messageId); + var result = executor.submit(() -> this.lockProcess(compositionElement, instanceElement)); + executionMap.put(instanceElement.elementId(), result); } - private void lockProcess(UUID instanceId, UUID elementId) { + private void lockProcess(CompositionElementDto compositionElement, InstanceElementDto instanceElement) { try { - listener.lock(instanceId, elementId); + listener.lock(compositionElement, instanceElement); } catch (PfModelException e) { - LOGGER.error("Automation composition element lock failed {} {}", instanceId, e.getMessage()); - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED, - StateChangeResult.FAILED, "Automation composition element lock failed"); + LOGGER.error("Automation composition element lock failed {} {}", + instanceElement.elementId(), e.getMessage()); + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), null, LockState.UNLOCKED, StateChangeResult.FAILED, + "Automation composition element lock failed"); } - executionMap.remove(elementId); + executionMap.remove(instanceElement.elementId()); } /** * Handle a automation composition element unlock. * * @param messageId the messageId - * @param instanceId the automationComposition Id - * @param elementId the ID of the automation composition element + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element */ - public void unlock(UUID messageId, UUID instanceId, UUID elementId) { - cleanExecution(elementId, messageId); - var result = executor.submit(() -> this.unlockProcess(instanceId, elementId)); - executionMap.put(elementId, result); + public void unlock(UUID messageId, CompositionElementDto compositionElement, InstanceElementDto instanceElement) { + cleanExecution(instanceElement.elementId(), messageId); + var result = executor.submit(() -> this.unlockProcess(compositionElement, instanceElement)); + executionMap.put(instanceElement.elementId(), result); } - private void unlockProcess(UUID instanceId, UUID elementId) { + private void unlockProcess(CompositionElementDto compositionElement, InstanceElementDto instanceElement) { try { - listener.unlock(instanceId, elementId); + listener.unlock(compositionElement, instanceElement); } catch (PfModelException e) { - LOGGER.error("Automation composition element unlock failed {} {}", instanceId, e.getMessage()); - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED, - StateChangeResult.FAILED, "Automation composition element unlock failed"); + LOGGER.error("Automation composition element unlock failed {} {}", + instanceElement.elementId(), e.getMessage()); + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), null, LockState.LOCKED, StateChangeResult.FAILED, + "Automation composition element unlock failed"); } - executionMap.remove(elementId); + executionMap.remove(instanceElement.elementId()); } /** * Handle a automation composition element delete. * * @param messageId the messageId - * @param instanceId the automationComposition Id - * @param elementId the ID of the automation composition element + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element */ - public void delete(UUID messageId, UUID instanceId, UUID elementId) { - cleanExecution(elementId, messageId); - var result = executor.submit(() -> this.deleteProcess(instanceId, elementId)); - executionMap.put(elementId, result); + public void delete(UUID messageId, CompositionElementDto compositionElement, InstanceElementDto instanceElement) { + cleanExecution(instanceElement.elementId(), messageId); + var result = executor.submit(() -> this.deleteProcess(compositionElement, instanceElement)); + executionMap.put(instanceElement.elementId(), result); } - private void deleteProcess(UUID instanceId, UUID elementId) { + private void deleteProcess(CompositionElementDto compositionElement, InstanceElementDto instanceElement) { try { - listener.delete(instanceId, elementId); + listener.delete(compositionElement, instanceElement); } catch (PfModelException e) { - LOGGER.error("Automation composition element delete failed {} {}", instanceId, e.getMessage()); - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED, null, - StateChangeResult.FAILED, "Automation composition element delete failed"); + LOGGER.error("Automation composition element delete failed {} {}", + instanceElement.elementId(), e.getMessage()); + intermediaryApi.updateAutomationCompositionElementState( + instanceElement.instanceId(), instanceElement.elementId(), DeployState.UNDEPLOYED, null, + StateChangeResult.FAILED, "Automation composition element delete failed"); } - executionMap.remove(elementId); + executionMap.remove(instanceElement.elementId()); } /** * Handle a automation composition element properties update. * * @param messageId the messageId - * @param instanceId the automationComposition Id - * @param element the information on the automation composition element - * @param properties properties Map + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element + * @param instanceElementUpdated the information of the Automation Composition Instance Element updated */ - public void update(UUID messageId, UUID instanceId, AcElementDeploy element, Map<String, Object> properties) { - cleanExecution(element.getId(), messageId); - var result = executor.submit(() -> this.updateProcess(instanceId, element, properties)); - executionMap.put(element.getId(), result); + public void update(UUID messageId, CompositionElementDto compositionElement, InstanceElementDto instanceElement, + InstanceElementDto instanceElementUpdated) { + cleanExecution(instanceElement.elementId(), messageId); + var result = executor.submit(() -> + this.updateProcess(compositionElement, instanceElement, instanceElementUpdated)); + executionMap.put(instanceElement.elementId(), result); } - private void updateProcess(UUID instanceId, AcElementDeploy element, Map<String, Object> properties) { + private void updateProcess(CompositionElementDto compositionElement, InstanceElementDto instanceElement, + InstanceElementDto instanceElementUpdated) { try { - listener.update(instanceId, element, properties); + listener.update(compositionElement, instanceElement, instanceElementUpdated); } catch (PfModelException e) { - LOGGER.error("Automation composition element update failed {} {}", instanceId, e.getMessage()); - intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, - null, StateChangeResult.FAILED, "Automation composition element update failed"); + LOGGER.error("Automation composition element update failed {} {}", + instanceElement.elementId(), e.getMessage()); + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DEPLOYED, null, + StateChangeResult.FAILED, "Automation composition element update failed"); } - executionMap.remove(element.getId()); + executionMap.remove(instanceElement.elementId()); } private void cleanExecution(UUID execIdentificationId, UUID messageId) { @@ -222,23 +235,22 @@ public class ThreadHandler implements Closeable { * Handles prime a Composition Definition. * * @param messageId the messageId - * @param compositionId the compositionId - * @param list the list of AutomationCompositionElementDefinition + * @param composition the composition */ - public void prime(UUID messageId, UUID compositionId, List<AutomationCompositionElementDefinition> list) { - cleanExecution(compositionId, messageId); - var result = executor.submit(() -> this.primeProcess(compositionId, list)); - executionMap.put(compositionId, result); + public void prime(UUID messageId, CompositionDto composition) { + cleanExecution(composition.compositionId(), messageId); + var result = executor.submit(() -> this.primeProcess(composition)); + executionMap.put(composition.compositionId(), result); } - private void primeProcess(UUID compositionId, List<AutomationCompositionElementDefinition> list) { + private void primeProcess(CompositionDto composition) { try { - listener.prime(compositionId, list); - executionMap.remove(compositionId); + listener.prime(composition); + executionMap.remove(composition.compositionId()); } catch (PfModelException e) { - LOGGER.error("Composition Defintion prime failed {} {}", compositionId, e.getMessage()); - intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.FAILED, - "Composition Defintion prime failed"); + LOGGER.error("Composition Defintion prime failed {} {}", composition.compositionId(), e.getMessage()); + intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.COMMISSIONED, + StateChangeResult.FAILED, "Composition Defintion prime failed"); } } @@ -246,22 +258,22 @@ public class ThreadHandler implements Closeable { * Handles deprime a Composition Definition. * * @param messageId the messageId - * @param compositionId the compositionId + * @param composition the composition */ - public void deprime(UUID messageId, UUID compositionId) { - cleanExecution(compositionId, messageId); - var result = executor.submit(() -> this.deprimeProcess(compositionId)); - executionMap.put(compositionId, result); + public void deprime(UUID messageId, CompositionDto composition) { + cleanExecution(composition.compositionId(), messageId); + var result = executor.submit(() -> this.deprimeProcess(composition)); + executionMap.put(composition.compositionId(), result); } - private void deprimeProcess(UUID compositionId) { + private void deprimeProcess(CompositionDto composition) { try { - listener.deprime(compositionId); - executionMap.remove(compositionId); + listener.deprime(composition); + executionMap.remove(composition.compositionId()); } catch (PfModelException e) { - LOGGER.error("Composition Defintion deprime failed {} {}", compositionId, e.getMessage()); - intermediaryApi.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.FAILED, - "Composition Defintion deprime failed"); + LOGGER.error("Composition Defintion deprime failed {} {}", composition.compositionId(), e.getMessage()); + intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.PRIMED, + StateChangeResult.FAILED, "Composition Defintion deprime failed"); } } @@ -269,56 +281,51 @@ public class ThreadHandler implements Closeable { * Handles restarted scenario. * * @param messageId the messageId - * @param compositionId the compositionId - * @param list the list of AutomationCompositionElementDefinition + * @param composition the composition * @param state the state of the composition * @param automationCompositionList list of ParticipantRestartAc */ - public void restarted(UUID messageId, UUID compositionId, List<AutomationCompositionElementDefinition> list, + public void restarted(UUID messageId, CompositionDto composition, AcTypeState state, List<ParticipantRestartAc> automationCompositionList) { try { - listener.handleRestartComposition(compositionId, list, state); + listener.handleRestartComposition(composition, state); } catch (PfModelException e) { - LOGGER.error("Composition Defintion restarted failed {} {}", compositionId, e.getMessage()); - intermediaryApi.updateCompositionState(compositionId, state, StateChangeResult.FAILED, + LOGGER.error("Composition Defintion restarted failed {} {}", composition.compositionId(), e.getMessage()); + intermediaryApi.updateCompositionState(composition.compositionId(), state, StateChangeResult.FAILED, "Composition Defintion restarted failed"); } for (var automationComposition : automationCompositionList) { for (var element : automationComposition.getAcElementList()) { + var compositionElement = new CompositionElementDto(composition.compositionId(), + element.getDefinition(), composition.inPropertiesMap().get(element.getDefinition()), + composition.outPropertiesMap().get(element.getDefinition())); + var instanceElementDto = new InstanceElementDto(automationComposition.getAutomationCompositionId(), + element.getId(), element.getToscaServiceTemplateFragment(), + element.getProperties(), element.getOutProperties()); cleanExecution(element.getId(), messageId); - var result = executor.submit(() -> this - .restartedInstanceProcess(automationComposition.getAutomationCompositionId(), element)); + var result = executor.submit(() -> + this.restartedInstanceProcess(compositionElement, instanceElementDto, + element.getDeployState(), element.getLockState())); executionMap.put(element.getId(), result); } } } - private void restartedInstanceProcess(UUID instanceId, AcElementRestart element) { + private void restartedInstanceProcess(CompositionElementDto compositionElement, + InstanceElementDto instanceElementDto, DeployState deployState, LockState lockState) { try { - var map = new HashMap<>(cacheProvider.getCommonProperties(instanceId, element.getId())); - map.putAll(element.getProperties()); - - listener.handleRestartInstance(instanceId, getAcElementDeploy(element), map, element.getDeployState(), - element.getLockState()); - executionMap.remove(element.getId()); + listener.handleRestartInstance(compositionElement, instanceElementDto, deployState, lockState); + executionMap.remove(instanceElementDto.elementId()); } catch (PfModelException e) { - LOGGER.error("Automation composition element deploy failed {} {}", instanceId, e.getMessage()); - intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), - element.getDeployState(), element.getLockState(), StateChangeResult.FAILED, + LOGGER.error("Automation composition element deploy failed {} {}", + instanceElementDto.elementId(), e.getMessage()); + intermediaryApi.updateAutomationCompositionElementState(instanceElementDto.instanceId(), + instanceElementDto.elementId(), deployState, lockState, StateChangeResult.FAILED, "Automation composition element restart failed"); } } - private AcElementDeploy getAcElementDeploy(AcElementRestart element) { - var acElementDeploy = new AcElementDeploy(); - acElementDeploy.setId(element.getId()); - acElementDeploy.setDefinition(element.getDefinition()); - acElementDeploy.setProperties(element.getProperties()); - acElementDeploy.setToscaServiceTemplateFragment(element.getToscaServiceTemplateFragment()); - return acElementDeploy; - } - /** * Closes this stream and releases any system resources associated * with it. If the stream is already closed then invoking this @@ -335,26 +342,32 @@ public class ThreadHandler implements Closeable { * Handles AutomationComposition Migration. * * @param messageId the messageId - * @param instanceId the automationComposition Id - * @param element the information on the automation composition element - * @param compositionTargetId the composition to migrate + * @param compositionElement the information of the Automation Composition Definition Element + * @param compositionElementTarget the information of the Automation Composition Definition Element Target + * @param instanceElement the information of the Automation Composition Instance Element + * @param instanceElementMigrate the information of the Automation Composition Instance Element updated */ - public void migrate(UUID messageId, UUID instanceId, AcElementDeploy element, UUID compositionTargetId, - Map<String, Object> properties) { - cleanExecution(element.getId(), messageId); - var result = executor.submit(() -> this.migrateProcess(instanceId, element, compositionTargetId, properties)); - executionMap.put(element.getId(), result); + public void migrate(UUID messageId, CompositionElementDto compositionElement, + CompositionElementDto compositionElementTarget, InstanceElementDto instanceElement, + InstanceElementDto instanceElementMigrate) { + cleanExecution(instanceElement.elementId(), messageId); + var result = executor.submit(() -> + this.migrateProcess(compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate)); + executionMap.put(instanceElement.elementId(), result); } - private void migrateProcess(UUID instanceId, AcElementDeploy element, UUID compositionTargetId, - Map<String, Object> properties) { + private void migrateProcess(CompositionElementDto compositionElement, + CompositionElementDto compositionElementTarget, InstanceElementDto instanceElement, + InstanceElementDto instanceElementMigrate) { try { - listener.migrate(instanceId, element, compositionTargetId, properties); + listener.migrate(compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate); } catch (PfModelException e) { - LOGGER.error("Automation composition element migrate failed {} {}", instanceId, e.getMessage()); - intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, - null, StateChangeResult.FAILED, "Automation composition element migrate failed"); + LOGGER.error("Automation composition element migrate failed {} {}", + instanceElement.elementId(), e.getMessage()); + intermediaryApi.updateAutomationCompositionElementState( + instanceElement.instanceId(), instanceElement.elementId(), DeployState.DEPLOYED, + null, StateChangeResult.FAILED, "Automation composition element migrate failed"); } - executionMap.remove(element.getId()); + executionMap.remove(instanceElement.elementId()); } } diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV1Test.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV1Test.java new file mode 100755 index 000000000..a60e1b8cd --- /dev/null +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV1Test.java @@ -0,0 +1,239 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2024 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.participant.intermediary.api.impl; + +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 java.util.Map; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.mockito.Answers; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto; +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.AcTypeState; +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.StateChangeResult; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class AcElementListenerV1Test { + + @Test + void deployTest() throws PfModelException { + var acElementListenerV1 = mock(AcElementListenerV1.class, Answers.CALLS_REAL_METHODS); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); + var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of()); + acElementListenerV1.deploy(compositionElement, instanceElement); + verify(acElementListenerV1).deploy(any(), any(), any()); + + clearInvocations(acElementListenerV1); + acElementListenerV1.handleRestartInstance(compositionElement, instanceElement, + DeployState.DEPLOYING, LockState.NONE); + verify(acElementListenerV1).deploy(any(), any(), any()); + } + + @Test + void undeployTest() throws PfModelException { + var acElementListenerV1 = mock(AcElementListenerV1.class, Answers.CALLS_REAL_METHODS); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); + var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of()); + acElementListenerV1.undeploy(compositionElement, instanceElement); + verify(acElementListenerV1).undeploy(instanceElement.instanceId(), instanceElement.elementId()); + + clearInvocations(acElementListenerV1); + acElementListenerV1.handleRestartInstance(compositionElement, instanceElement, + DeployState.UNDEPLOYING, LockState.NONE); + verify(acElementListenerV1).undeploy(instanceElement.instanceId(), instanceElement.elementId()); + } + + @Test + void lockTest() throws PfModelException { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var acElementListenerV1 = createAcElementListenerV1(intermediaryApi); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); + var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of()); + acElementListenerV1.lock(compositionElement, instanceElement); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked"); + } + + @Test + void deleteTest() throws PfModelException { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var acElementListenerV1 = createAcElementListenerV1(intermediaryApi); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); + var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of()); + acElementListenerV1.delete(compositionElement, instanceElement); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted"); + } + + @Test + void updateTest() throws PfModelException { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var acElementListenerV1 = createAcElementListenerV1(intermediaryApi); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); + var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of()); + acElementListenerV1.update(compositionElement, instanceElement, instanceElement); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DEPLOYED, null, + StateChangeResult.NO_ERROR, "Update not supported"); + } + + @Test + void unlockTest() throws PfModelException { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var acElementListenerV1 = createAcElementListenerV1(intermediaryApi); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); + var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of()); + acElementListenerV1.unlock(compositionElement, instanceElement); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked"); + } + + @Test + void primeTest() throws PfModelException { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var acElementListenerV1 = createAcElementListenerV1(intermediaryApi); + var compositionId = UUID.randomUUID(); + var toscaConceptIdentifier = new ToscaConceptIdentifier(); + var composition = new CompositionDto(compositionId, Map.of(toscaConceptIdentifier, Map.of()), Map.of()); + acElementListenerV1.prime(composition); + verify(intermediaryApi) + .updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed"); + } + + @Test + void deprimeTest() throws PfModelException { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var acElementListenerV1 = createAcElementListenerV1(intermediaryApi); + var compositionId = UUID.randomUUID(); + var toscaConceptIdentifier = new ToscaConceptIdentifier(); + var composition = new CompositionDto(compositionId, Map.of(toscaConceptIdentifier, Map.of()), Map.of()); + acElementListenerV1.deprime(composition); + verify(intermediaryApi) + .updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, "Deprimed"); + } + + @Test + void handleRestartComposition() throws PfModelException { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var acElementListenerV1 = createAcElementListenerV1(intermediaryApi); + var compositionId = UUID.randomUUID(); + var toscaConceptIdentifier = new ToscaConceptIdentifier(); + var composition = new CompositionDto(compositionId, Map.of(toscaConceptIdentifier, Map.of()), Map.of()); + + acElementListenerV1.handleRestartComposition(composition, AcTypeState.PRIMED); + verify(intermediaryApi) + .updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Restarted"); + + clearInvocations(intermediaryApi); + acElementListenerV1.handleRestartComposition(composition, AcTypeState.PRIMING); + verify(intermediaryApi) + .updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed"); + + clearInvocations(intermediaryApi); + acElementListenerV1.handleRestartComposition(composition, AcTypeState.DEPRIMING); + verify(intermediaryApi) + .updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, "Deprimed"); + } + + @Test + void handleRestartInstance() throws PfModelException { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var acElementListenerV1 = createAcElementListenerV1(intermediaryApi); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); + var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of()); + + acElementListenerV1.handleRestartInstance(compositionElement, instanceElement, + DeployState.DEPLOYED, LockState.LOCKED); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DEPLOYED, LockState.LOCKED, + StateChangeResult.NO_ERROR, "Restarted"); + + clearInvocations(intermediaryApi); + acElementListenerV1.handleRestartInstance(compositionElement, instanceElement, + DeployState.DEPLOYED, LockState.LOCKING); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked"); + + clearInvocations(intermediaryApi); + acElementListenerV1.handleRestartInstance(compositionElement, instanceElement, + DeployState.DEPLOYED, LockState.UNLOCKING); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked"); + + clearInvocations(intermediaryApi); + acElementListenerV1.handleRestartInstance(compositionElement, instanceElement, + DeployState.UPDATING, LockState.LOCKED); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DEPLOYED, null, + StateChangeResult.NO_ERROR, "Update not supported"); + + clearInvocations(intermediaryApi); + acElementListenerV1.handleRestartInstance(compositionElement, instanceElement, + DeployState.DELETING, LockState.NONE); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted"); + } + + @Test + void migrateTest() throws PfModelException { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var acElementListenerV1 = createAcElementListenerV1(intermediaryApi); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); + var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of()); + acElementListenerV1.migrate(compositionElement, compositionElement, instanceElement, instanceElement); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DEPLOYED, null, + StateChangeResult.NO_ERROR, "Migrated"); + } + + private AcElementListenerV1 createAcElementListenerV1(ParticipantIntermediaryApi intermediaryApi) { + return new AcElementListenerV1(intermediaryApi) { + @Override + public void deploy(UUID instanceId, AcElementDeploy element, Map<String, Object> properties) + throws PfModelException { + + } + + @Override + public void undeploy(UUID instanceId, UUID elementId) throws PfModelException { + + } + }; + } +} diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV2Test.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV2Test.java new file mode 100755 index 000000000..c36e11dbc --- /dev/null +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV2Test.java @@ -0,0 +1,228 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2024 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.participant.intermediary.api.impl; + +import static org.mockito.Mockito.clearInvocations; +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.Answers; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; +import org.onap.policy.clamp.models.acm.concepts.AcTypeState; +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.StateChangeResult; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class AcElementListenerV2Test { + + @Test + void deployTest() throws PfModelException { + var acElementListenerV2 = mock(AcElementListenerV2.class, Answers.CALLS_REAL_METHODS); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); + var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of()); + acElementListenerV2.handleRestartInstance(compositionElement, instanceElement, + DeployState.DEPLOYING, LockState.NONE); + verify(acElementListenerV2).deploy(compositionElement, instanceElement); + } + + @Test + void undeployTest() throws PfModelException { + var acElementListenerV2 = mock(AcElementListenerV2.class, Answers.CALLS_REAL_METHODS); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); + var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of()); + acElementListenerV2.handleRestartInstance(compositionElement, instanceElement, + DeployState.UNDEPLOYING, LockState.NONE); + verify(acElementListenerV2).undeploy(compositionElement, instanceElement); + } + + @Test + void lockTest() throws PfModelException { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var acElementListenerV2 = createAcElementListenerV2(intermediaryApi); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); + var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of()); + acElementListenerV2.lock(compositionElement, instanceElement); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked"); + } + + @Test + void deleteTest() throws PfModelException { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var acElementListenerV2 = createAcElementListenerV2(intermediaryApi); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); + var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of()); + acElementListenerV2.delete(compositionElement, instanceElement); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted"); + } + + @Test + void updateTest() throws PfModelException { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var acElementListenerV2 = createAcElementListenerV2(intermediaryApi); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); + var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of()); + acElementListenerV2.update(compositionElement, instanceElement, instanceElement); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DEPLOYED, null, + StateChangeResult.NO_ERROR, "Update not supported"); + } + + @Test + void unlockTest() throws PfModelException { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var acElementListenerV2 = createAcElementListenerV2(intermediaryApi); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); + var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of()); + acElementListenerV2.unlock(compositionElement, instanceElement); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked"); + } + + @Test + void primeTest() throws PfModelException { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var acElementListenerV2 = createAcElementListenerV2(intermediaryApi); + var compositionId = UUID.randomUUID(); + var toscaConceptIdentifier = new ToscaConceptIdentifier(); + var composition = new CompositionDto(compositionId, Map.of(toscaConceptIdentifier, Map.of()), Map.of()); + acElementListenerV2.prime(composition); + verify(intermediaryApi) + .updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed"); + } + + @Test + void deprimeTest() throws PfModelException { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var acElementListenerV2 = createAcElementListenerV2(intermediaryApi); + var compositionId = UUID.randomUUID(); + var toscaConceptIdentifier = new ToscaConceptIdentifier(); + var composition = new CompositionDto(compositionId, Map.of(toscaConceptIdentifier, Map.of()), Map.of()); + acElementListenerV2.deprime(composition); + verify(intermediaryApi) + .updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, "Deprimed"); + } + + @Test + void handleRestartComposition() throws PfModelException { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var acElementListenerV2 = createAcElementListenerV2(intermediaryApi); + var compositionId = UUID.randomUUID(); + var toscaConceptIdentifier = new ToscaConceptIdentifier(); + var composition = new CompositionDto(compositionId, Map.of(toscaConceptIdentifier, Map.of()), Map.of()); + + acElementListenerV2.handleRestartComposition(composition, AcTypeState.PRIMED); + verify(intermediaryApi) + .updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Restarted"); + + clearInvocations(intermediaryApi); + acElementListenerV2.handleRestartComposition(composition, AcTypeState.PRIMING); + verify(intermediaryApi) + .updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed"); + + clearInvocations(intermediaryApi); + acElementListenerV2.handleRestartComposition(composition, AcTypeState.DEPRIMING); + verify(intermediaryApi) + .updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, "Deprimed"); + } + + @Test + void handleRestartInstance() throws PfModelException { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var acElementListenerV2 = createAcElementListenerV2(intermediaryApi); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); + var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of()); + + acElementListenerV2.handleRestartInstance(compositionElement, instanceElement, + DeployState.DEPLOYED, LockState.LOCKED); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DEPLOYED, LockState.LOCKED, + StateChangeResult.NO_ERROR, "Restarted"); + + clearInvocations(intermediaryApi); + acElementListenerV2.handleRestartInstance(compositionElement, instanceElement, + DeployState.DEPLOYED, LockState.LOCKING); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked"); + + clearInvocations(intermediaryApi); + acElementListenerV2.handleRestartInstance(compositionElement, instanceElement, + DeployState.DEPLOYED, LockState.UNLOCKING); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked"); + + clearInvocations(intermediaryApi); + acElementListenerV2.handleRestartInstance(compositionElement, instanceElement, + DeployState.UPDATING, LockState.LOCKED); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DEPLOYED, null, + StateChangeResult.NO_ERROR, "Update not supported"); + + clearInvocations(intermediaryApi); + acElementListenerV2.handleRestartInstance(compositionElement, instanceElement, + DeployState.DELETING, LockState.NONE); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted"); + } + + @Test + void migrateTest() throws PfModelException { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var acElementListenerV2 = createAcElementListenerV2(intermediaryApi); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); + var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of()); + acElementListenerV2.migrate(compositionElement, compositionElement, instanceElement, instanceElement); + verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DEPLOYED, null, + StateChangeResult.NO_ERROR, "Migrated"); + } + + private AcElementListenerV2 createAcElementListenerV2(ParticipantIntermediaryApi intermediaryApi) { + return new AcElementListenerV2(intermediaryApi) { + @Override + public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + } + + @Override + public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + } + }; + } +} 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 93809ab96..b01065d09 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation. + * Copyright (C) 2023-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,17 +22,24 @@ package org.onap.policy.clamp.acm.participant.intermediary.api.impl; import static org.assertj.core.api.Assertions.assertThatCode; +import java.util.Map; import java.util.UUID; import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto; import org.onap.policy.clamp.acm.participant.intermediary.handler.DummyAcElementListener; -import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; class AutomationCompositionElementListenerTest { @Test - void defaultTest() throws PfModelException { + void defaultTest() { var listener = new DummyAcElementListener(); - assertThatCode(() -> listener.lock(UUID.randomUUID(), UUID.randomUUID())).doesNotThrowAnyException(); - assertThatCode(() -> listener.unlock(UUID.randomUUID(), UUID.randomUUID())).doesNotThrowAnyException(); + var compositionElementDto = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + Map.of(), Map.of()); + var instanceElementDto = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, + Map.of(), Map.of()); + assertThatCode(() -> listener.lock(compositionElementDto, instanceElementDto)).doesNotThrowAnyException(); + assertThatCode(() -> listener.unlock(compositionElementDto, instanceElementDto)).doesNotThrowAnyException(); } } 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 6a00d8cf6..661c009f6 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 @@ -28,11 +28,13 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.util.HashMap; 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.CompositionDto; 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; @@ -48,6 +50,8 @@ import org.onap.policy.clamp.models.acm.messages.kafka.participant.AutomationCom import org.onap.policy.clamp.models.acm.messages.kafka.participant.PropertiesUpdate; 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.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) @@ -79,8 +83,6 @@ class AutomationCompositionHandlerTest { @Test void handleAutomationCompositionStateChangeUndeployTest() { var automationComposition = CommonTestData.getTestAutomationCompositionMap().values().iterator().next(); - var automationCompositionStateChange = CommonTestData.getStateChange(CommonTestData.getParticipantId(), - automationComposition.getInstanceId(), DeployOrder.UNDEPLOY, LockOrder.NONE); var cacheProvider = mock(CacheProvider.class); when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); @@ -89,6 +91,15 @@ class AutomationCompositionHandlerTest { var participantMessagePublisher = mock(ParticipantMessagePublisher.class); var listener = mock(ThreadHandler.class); var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher, listener); + Map<ToscaConceptIdentifier, AutomationCompositionElementDefinition> map = new HashMap<>(); + for (var element : automationComposition.getElements().values()) { + map.put(element.getDefinition(), new AutomationCompositionElementDefinition()); + } + when(cacheProvider.getAcElementsDefinitions()) + .thenReturn(Map.of(automationComposition.getCompositionId(), map)); + var automationCompositionStateChange = CommonTestData.getStateChange(CommonTestData.getParticipantId(), + automationComposition.getInstanceId(), DeployOrder.UNDEPLOY, LockOrder.NONE); + ach.handleAutomationCompositionStateChange(automationCompositionStateChange); verify(listener, times(automationComposition.getElements().size())).undeploy(any(), any(), any()); for (var element : automationComposition.getElements().values()) { @@ -99,8 +110,6 @@ class AutomationCompositionHandlerTest { @Test void handleAutomationCompositionStateChangeLockTest() { var automationComposition = CommonTestData.getTestAutomationCompositionMap().values().iterator().next(); - var automationCompositionStateChange = CommonTestData.getStateChange(CommonTestData.getParticipantId(), - automationComposition.getInstanceId(), DeployOrder.NONE, LockOrder.LOCK); var cacheProvider = mock(CacheProvider.class); when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); @@ -109,6 +118,14 @@ class AutomationCompositionHandlerTest { var participantMessagePublisher = mock(ParticipantMessagePublisher.class); var listener = mock(ThreadHandler.class); var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher, listener); + Map<ToscaConceptIdentifier, AutomationCompositionElementDefinition> map = new HashMap<>(); + for (var element : automationComposition.getElements().values()) { + map.put(element.getDefinition(), new AutomationCompositionElementDefinition()); + } + when(cacheProvider.getAcElementsDefinitions()) + .thenReturn(Map.of(automationComposition.getCompositionId(), map)); + var automationCompositionStateChange = CommonTestData.getStateChange(CommonTestData.getParticipantId(), + automationComposition.getInstanceId(), DeployOrder.NONE, LockOrder.LOCK); ach.handleAutomationCompositionStateChange(automationCompositionStateChange); verify(listener, times(automationComposition.getElements().size())).lock(any(), any(), any()); for (var element : automationComposition.getElements().values()) { @@ -119,8 +136,6 @@ class AutomationCompositionHandlerTest { @Test void handleAutomationCompositionStateChangeUnlockTest() { var automationComposition = CommonTestData.getTestAutomationCompositionMap().values().iterator().next(); - var automationCompositionStateChange = CommonTestData.getStateChange(CommonTestData.getParticipantId(), - automationComposition.getInstanceId(), DeployOrder.NONE, LockOrder.UNLOCK); var cacheProvider = mock(CacheProvider.class); when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); @@ -129,6 +144,14 @@ class AutomationCompositionHandlerTest { var participantMessagePublisher = mock(ParticipantMessagePublisher.class); var listener = mock(ThreadHandler.class); var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher, listener); + Map<ToscaConceptIdentifier, AutomationCompositionElementDefinition> map = new HashMap<>(); + for (var element : automationComposition.getElements().values()) { + map.put(element.getDefinition(), new AutomationCompositionElementDefinition()); + } + when(cacheProvider.getAcElementsDefinitions()) + .thenReturn(Map.of(automationComposition.getCompositionId(), map)); + var automationCompositionStateChange = CommonTestData.getStateChange(CommonTestData.getParticipantId(), + automationComposition.getInstanceId(), DeployOrder.NONE, LockOrder.UNLOCK); ach.handleAutomationCompositionStateChange(automationCompositionStateChange); verify(listener, times(automationComposition.getElements().size())).unlock(any(), any(), any()); for (var element : automationComposition.getElements().values()) { @@ -139,8 +162,6 @@ class AutomationCompositionHandlerTest { @Test void handleAutomationCompositionStateChangeDeleteTest() { var automationComposition = CommonTestData.getTestAutomationCompositionMap().values().iterator().next(); - var automationCompositionStateChange = CommonTestData.getStateChange(CommonTestData.getParticipantId(), - automationComposition.getInstanceId(), DeployOrder.DELETE, LockOrder.NONE); var cacheProvider = mock(CacheProvider.class); when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); @@ -149,6 +170,14 @@ class AutomationCompositionHandlerTest { var participantMessagePublisher = mock(ParticipantMessagePublisher.class); var listener = mock(ThreadHandler.class); var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher, listener); + Map<ToscaConceptIdentifier, AutomationCompositionElementDefinition> map = new HashMap<>(); + for (var element : automationComposition.getElements().values()) { + map.put(element.getDefinition(), new AutomationCompositionElementDefinition()); + } + when(cacheProvider.getAcElementsDefinitions()) + .thenReturn(Map.of(automationComposition.getCompositionId(), map)); + var automationCompositionStateChange = CommonTestData.getStateChange(CommonTestData.getParticipantId(), + automationComposition.getInstanceId(), DeployOrder.DELETE, LockOrder.NONE); ach.handleAutomationCompositionStateChange(automationCompositionStateChange); verify(listener, times(automationComposition.getElements().size())).delete(any(), any(), any()); for (var element : automationComposition.getElements().values()) { @@ -181,6 +210,12 @@ class AutomationCompositionHandlerTest { acElementDeploy.setId(automationComposition.getElements().values().iterator().next().getId()); participantDeploy.getAcElementList().add(acElementDeploy); + Map<ToscaConceptIdentifier, AutomationCompositionElementDefinition> map = new HashMap<>(); + for (var element : automationComposition.getElements().values()) { + map.put(element.getDefinition(), new AutomationCompositionElementDefinition()); + } + when(cacheProvider.getAcElementsDefinitions()) + .thenReturn(Map.of(automationComposition.getCompositionId(), map)); ach.handleAcPropertyUpdate(updateMsg); verify(listener).update(any(), any(), any(), any()); } @@ -205,54 +240,76 @@ class AutomationCompositionHandlerTest { deployMsg.setAutomationCompositionId(automationComposition.getInstanceId()); when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); + Map<ToscaConceptIdentifier, AutomationCompositionElementDefinition> map = new HashMap<>(); for (var element : automationComposition.getElements().values()) { var acElementDeploy = new AcElementDeploy(); acElementDeploy.setProperties(Map.of()); acElementDeploy.setId(element.getId()); participantDeploy.getAcElementList().add(acElementDeploy); + map.put(element.getDefinition(), new AutomationCompositionElementDefinition()); } + when(cacheProvider.getAcElementsDefinitions()) + .thenReturn(Map.of(automationComposition.getCompositionId(), map)); + ach.handleAutomationCompositionDeploy(deployMsg); - verify(listener, times(automationComposition.getElements().size())).deploy(any(), any(), any(), any()); + verify(listener, times(automationComposition.getElements().size())).deploy(any(), any(), any()); } @Test void handleComposiotPrimeTest() { - var listener = mock(ThreadHandler.class); - var ach = new AutomationCompositionHandler(mock(CacheProvider.class), mock(ParticipantMessagePublisher.class), - listener); + var acElementDefinition = new AutomationCompositionElementDefinition(); + acElementDefinition.setAcElementDefinitionId(new ToscaConceptIdentifier("key", "1.0.0")); + var toscaNodeTemplate = new ToscaNodeTemplate(); + toscaNodeTemplate.setProperties(Map.of()); + acElementDefinition.setAutomationCompositionElementToscaNodeTemplate(toscaNodeTemplate); + var list = List.of(acElementDefinition); var compositionId = UUID.randomUUID(); - var list = List.of(new AutomationCompositionElementDefinition()); var messageId = UUID.randomUUID(); + var listener = mock(ThreadHandler.class); + var ach = new AutomationCompositionHandler(mock(CacheProvider.class), mock(ParticipantMessagePublisher.class), + listener); ach.prime(messageId, compositionId, list); - verify(listener).prime(messageId, compositionId, list); + verify(listener).prime(any(UUID.class), any(CompositionDto.class)); } @Test void handleComposiotDeprimeTest() { - var listener = mock(ThreadHandler.class); - var ach = new AutomationCompositionHandler(mock(CacheProvider.class), mock(ParticipantMessagePublisher.class), - listener); + var acElementDefinition = new AutomationCompositionElementDefinition(); + acElementDefinition.setAcElementDefinitionId(new ToscaConceptIdentifier("key", "1.0.0")); + var toscaNodeTemplate = new ToscaNodeTemplate(); + toscaNodeTemplate.setProperties(Map.of()); + acElementDefinition.setAutomationCompositionElementToscaNodeTemplate(toscaNodeTemplate); var compositionId = UUID.randomUUID(); + var listener = mock(ThreadHandler.class); + var cacheProvider = mock(CacheProvider.class); + var ach = new AutomationCompositionHandler(cacheProvider, mock(ParticipantMessagePublisher.class), + listener); + when(cacheProvider.getAcElementsDefinitions()) + .thenReturn(Map.of(compositionId, Map.of(new ToscaConceptIdentifier(), acElementDefinition))); var messageId = UUID.randomUUID(); ach.deprime(messageId, compositionId); - verify(listener).deprime(messageId, compositionId); + verify(listener).deprime(any(UUID.class), any(CompositionDto.class)); } @Test void restartedTest() { + var acElementDefinition = new AutomationCompositionElementDefinition(); + acElementDefinition.setAcElementDefinitionId(new ToscaConceptIdentifier("key", "1.0.0")); + var toscaNodeTemplate = new ToscaNodeTemplate(); + toscaNodeTemplate.setProperties(Map.of()); + acElementDefinition.setAutomationCompositionElementToscaNodeTemplate(toscaNodeTemplate); + var list = List.of(acElementDefinition); + var state = AcTypeState.PRIMED; + var participantRestartAc = CommonTestData.createParticipantRestartAc(); + var automationCompositionList = List.of(participantRestartAc); var listener = mock(ThreadHandler.class); var cacheProvider = mock(CacheProvider.class); var ach = new AutomationCompositionHandler(cacheProvider, mock(ParticipantMessagePublisher.class), listener); - var compositionId = UUID.randomUUID(); var messageId = UUID.randomUUID(); - var list = List.of(new AutomationCompositionElementDefinition()); - var state = AcTypeState.PRIMED; - var participantRestartAc = CommonTestData.createParticipantRestartAc(); - var automationCompositionList = List.of(participantRestartAc); ach.restarted(messageId, compositionId, list, state, automationCompositionList); verify(cacheProvider).initializeAutomationComposition(compositionId, participantRestartAc); - verify(listener).restarted(messageId, compositionId, list, state, automationCompositionList); + verify(listener).restarted(any(), any(), any(), any()); } @Test @@ -272,12 +329,18 @@ class AutomationCompositionHandlerTest { participantDeploy.setParticipantId(CommonTestData.getParticipantId()); when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId()); migrationMsg.getParticipantUpdatesList().add(participantDeploy); + Map<ToscaConceptIdentifier, AutomationCompositionElementDefinition> map = new HashMap<>(); for (var element : automationComposition.getElements().values()) { var acElementDeploy = new AcElementDeploy(); acElementDeploy.setProperties(Map.of()); acElementDeploy.setId(element.getId()); + acElementDeploy.setDefinition(element.getDefinition()); participantDeploy.getAcElementList().add(acElementDeploy); + map.put(element.getDefinition(), new AutomationCompositionElementDefinition()); } + when(cacheProvider.getAcElementsDefinitions()) + .thenReturn(Map.of(automationComposition.getCompositionId(), map, + migrationMsg.getCompositionTargetId(), map)); ach.handleAutomationCompositionMigration(migrationMsg); verify(listener, times(automationComposition.getElements().size())).migrate(any(), any(), any(), any(), any()); diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProviderTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProviderTest.java index 33bd93fb2..d5fe5785b 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProviderTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProviderTest.java @@ -28,6 +28,7 @@ import java.util.Map; import java.util.UUID; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; class CacheProviderTest { @@ -59,9 +60,10 @@ class CacheProviderTest { assertThatThrownBy(() -> cacheProvider.getAutomationComposition(null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> cacheProvider.getCommonProperties(null, null)) + var definition = new ToscaConceptIdentifier(); + assertThatThrownBy(() -> cacheProvider.getCommonProperties(null, definition)) .isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> cacheProvider.getCommonProperties(instanceId, null)) + assertThatThrownBy(() -> cacheProvider.getCommonProperties(instanceId, (UUID) null)) .isInstanceOf(NullPointerException.class); assertThatThrownBy(() -> cacheProvider.removeAutomationComposition(null)) diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/DummyAcElementListener.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/DummyAcElementListener.java index e7b4b676d..24935c1c9 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/DummyAcElementListener.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/DummyAcElementListener.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation. + * Copyright (C) 2023-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,68 +20,71 @@ package org.onap.policy.clamp.acm.participant.intermediary.handler; -import java.util.List; -import java.util.Map; -import java.util.UUID; import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; -import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; -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.models.base.PfModelException; public class DummyAcElementListener implements AutomationCompositionElementListener { @Override - public void undeploy(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException { + public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { } @Override - public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties) - throws PfModelException { + public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { } @Override - public void lock(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException { + public void lock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + } @Override - public void unlock(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException { + public void unlock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + } @Override - public void delete(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException { + public void delete(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { } @Override - public void update(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties) + public void update(CompositionElementDto compositionElement, InstanceElementDto instanceElement, + InstanceElementDto instanceElementUpdated) throws PfModelException { } @Override - public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList) - throws PfModelException { + public void prime(CompositionDto composition) throws PfModelException { } @Override - public void deprime(UUID compositionId) throws PfModelException { + public void deprime(CompositionDto composition) throws PfModelException { } @Override - public void handleRestartComposition(UUID compositionId, - List<AutomationCompositionElementDefinition> elementDefinitionList, AcTypeState state) - throws PfModelException { + public void handleRestartComposition(CompositionDto composition, AcTypeState state) throws PfModelException { } @Override - public void handleRestartInstance(UUID automationCompositionId, AcElementDeploy element, - Map<String, Object> properties, DeployState deployState, LockState lockState) throws PfModelException { + public void handleRestartInstance(CompositionElementDto compositionElement, InstanceElementDto instanceElement, + DeployState deployState, LockState lockState) throws PfModelException { } @Override - public void migrate(UUID instanceId, AcElementDeploy element, UUID compositionTargetId, - Map<String, Object> properties) throws PfModelException { + public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget, + InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate) + throws PfModelException { } } 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 8be19f749..4b58ae177 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 @@ -34,6 +34,7 @@ import org.junit.jupiter.api.Test; 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.AcTypeState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType; import org.onap.policy.clamp.models.acm.messages.kafka.participant.AutomationCompositionDeploy; @@ -234,6 +235,7 @@ class ParticipantHandlerTest { private ParticipantDefinition createParticipantDefinition() { var def = new ParticipantDefinition(); def.setParticipantId(CommonTestData.getParticipantId()); + def.setAutomationCompositionElementDefinitionList(List.of(new AutomationCompositionElementDefinition())); return def; } } diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandlerTest.java index 2ac3c8df2..e4c34845e 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandlerTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandlerTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation. + * Copyright (C) 2023-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,16 +34,19 @@ import java.util.Map; import java.util.UUID; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto; 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.AcElementRestart; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; -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.ParticipantRestartAc; import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; class ThreadHandlerTest { @@ -56,48 +59,57 @@ class ThreadHandlerTest { try (var threadHandler = new ThreadHandler(listener, intermediaryApi, mock(CacheProvider.class))) { var compositionId = UUID.randomUUID(); - var list = List.of(new AutomationCompositionElementDefinition()); var messageId = UUID.randomUUID(); - threadHandler.prime(messageId, compositionId, list); - verify(listener, timeout(TIMEOUT)).prime(compositionId, list); + var composition = new CompositionDto(compositionId, Map.of(), Map.of()); + threadHandler.prime(messageId, composition); + verify(listener, timeout(TIMEOUT)).prime(composition); clearInvocations(listener); - var element = new AcElementDeploy(); - var elementId = UUID.randomUUID(); - element.setId(elementId); Map<String, Object> properties = Map.of("key", "value"); - var instanceId = UUID.randomUUID(); - threadHandler.deploy(messageId, instanceId, element, properties); - verify(listener, timeout(TIMEOUT)).deploy(instanceId, element, properties); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + properties, properties); + var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), + null, properties, properties); + threadHandler.deploy(messageId, compositionElement, instanceElement); + verify(listener, timeout(TIMEOUT)).deploy(compositionElement, instanceElement); clearInvocations(listener); - threadHandler.update(messageId, instanceId, element, properties); - verify(listener, timeout(TIMEOUT)).update(instanceId, element, properties); + var element = new AcElementDeploy(); + var elementId = UUID.randomUUID(); + element.setId(elementId); + var instanceElementUpdated = new InstanceElementDto(instanceElement.instanceId(), + instanceElement.elementId(), null, properties, properties); + threadHandler.update(messageId, compositionElement, instanceElement, instanceElementUpdated); + verify(listener, timeout(TIMEOUT)).update(compositionElement, instanceElement, instanceElementUpdated); clearInvocations(listener); var compositionTargetId = UUID.randomUUID(); - threadHandler.migrate(messageId, instanceId, element, compositionTargetId, properties); - verify(listener, timeout(TIMEOUT)).migrate(instanceId, element, compositionTargetId, properties); + var compositionElementTarget = new CompositionElementDto(compositionTargetId, new ToscaConceptIdentifier(), + properties, properties); + threadHandler.migrate(messageId, compositionElement, compositionElementTarget, + instanceElement, instanceElementUpdated); + verify(listener, timeout(TIMEOUT)).migrate(compositionElement, compositionElementTarget, + instanceElement, instanceElementUpdated); clearInvocations(listener); - threadHandler.lock(messageId, instanceId, elementId); - verify(listener, timeout(TIMEOUT)).lock(instanceId, elementId); + threadHandler.lock(messageId, compositionElement, instanceElement); + verify(listener, timeout(TIMEOUT)).lock(compositionElement, instanceElement); clearInvocations(listener); - threadHandler.unlock(messageId, instanceId, elementId); - verify(listener, timeout(TIMEOUT)).unlock(instanceId, elementId); + threadHandler.unlock(messageId, compositionElement, instanceElement); + verify(listener, timeout(TIMEOUT)).unlock(compositionElement, instanceElement); clearInvocations(listener); - threadHandler.undeploy(messageId, instanceId, elementId); - verify(listener, timeout(TIMEOUT)).undeploy(instanceId, elementId); + threadHandler.undeploy(messageId, compositionElement, instanceElement); + verify(listener, timeout(TIMEOUT)).undeploy(compositionElement, instanceElement); clearInvocations(listener); - threadHandler.delete(messageId, instanceId, elementId); - verify(listener, timeout(TIMEOUT)).delete(instanceId, elementId); + threadHandler.delete(messageId, compositionElement, instanceElement); + verify(listener, timeout(TIMEOUT)).delete(compositionElement, instanceElement); clearInvocations(listener); - threadHandler.deprime(messageId, compositionId); - verify(listener, timeout(TIMEOUT)).deprime(compositionId); + threadHandler.deprime(messageId, composition); + verify(listener, timeout(TIMEOUT)).deprime(composition); } } @@ -108,75 +120,80 @@ class ThreadHandlerTest { try (var threadHandler = new ThreadHandler(listener, intermediaryApi, mock(CacheProvider.class))) { var compositionId = UUID.randomUUID(); - var list = List.of(new AutomationCompositionElementDefinition()); - doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).prime(compositionId, - list); + var composition = new CompositionDto(compositionId, Map.of(), Map.of()); + doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener) + .prime(composition); var messageId = UUID.randomUUID(); - threadHandler.prime(messageId, compositionId, list); + threadHandler.prime(messageId, composition); verify(intermediaryApi, timeout(TIMEOUT)).updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.FAILED, "Composition Defintion prime failed"); clearInvocations(intermediaryApi); - var element = new AcElementDeploy(); - var elementId = UUID.randomUUID(); - element.setId(elementId); Map<String, Object> properties = Map.of("key", "value"); + var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + properties, properties); var instanceId = UUID.randomUUID(); - doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).deploy(instanceId, - element, properties); - threadHandler.deploy(messageId, instanceId, element, properties); + var elementId = UUID.randomUUID(); + var instanceElement = new InstanceElementDto(instanceId, elementId, null, properties, properties); + var element = new AcElementDeploy(); + element.setId(elementId); + doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener) + .deploy(compositionElement, instanceElement); + threadHandler.deploy(messageId, compositionElement, instanceElement); verify(intermediaryApi, timeout(TIMEOUT)).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Automation composition element deploy failed"); clearInvocations(listener); - doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).update(instanceId, - element, properties); - threadHandler.update(messageId, instanceId, element, properties); + var instanceElementUpdated = new InstanceElementDto(instanceElement.instanceId(), + instanceElement.elementId(), null, properties, properties); + doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener) + .update(compositionElement, instanceElement, instanceElementUpdated); + threadHandler.update(messageId, compositionElement, instanceElement, instanceElementUpdated); verify(intermediaryApi, timeout(TIMEOUT)).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Automation composition element update failed"); clearInvocations(listener); - doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).lock(instanceId, - elementId); - threadHandler.lock(messageId, instanceId, elementId); + doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener) + .lock(compositionElement, instanceElement); + threadHandler.lock(messageId, compositionElement, instanceElement); verify(intermediaryApi, timeout(TIMEOUT)).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED, StateChangeResult.FAILED, "Automation composition element lock failed"); clearInvocations(listener); - doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).unlock(instanceId, - elementId); - threadHandler.unlock(messageId, instanceId, elementId); + doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener) + .unlock(compositionElement, instanceElement); + threadHandler.unlock(messageId, compositionElement, instanceElement); verify(intermediaryApi, timeout(TIMEOUT)).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED, StateChangeResult.FAILED, "Automation composition element unlock failed"); clearInvocations(listener); - doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).undeploy(instanceId, - elementId); - threadHandler.undeploy(messageId, instanceId, elementId); + doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener) + .undeploy(compositionElement, instanceElement); + threadHandler.undeploy(messageId, compositionElement, instanceElement); verify(intermediaryApi, timeout(TIMEOUT)).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Automation composition element undeploy failed"); clearInvocations(listener); - doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).delete(instanceId, - elementId); - threadHandler.delete(messageId, instanceId, elementId); + doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener) + .delete(compositionElement, instanceElement); + threadHandler.delete(messageId, compositionElement, instanceElement); verify(intermediaryApi, timeout(TIMEOUT)).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Automation composition element delete failed"); clearInvocations(listener); - doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).deprime(compositionId); - threadHandler.deprime(messageId, compositionId); + doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).deprime(composition); + threadHandler.deprime(messageId, composition); verify(intermediaryApi, timeout(TIMEOUT)).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.FAILED, "Composition Defintion deprime failed"); clearInvocations(listener); doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener) - .handleRestartComposition(compositionId, List.of(), AcTypeState.PRIMING); - threadHandler.restarted(messageId, compositionId, List.of(), AcTypeState.PRIMING, List.of()); + .handleRestartComposition(composition, AcTypeState.PRIMING); + threadHandler.restarted(messageId, composition, AcTypeState.PRIMING, List.of()); verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.FAILED, "Composition Defintion deprime failed"); } @@ -193,9 +210,9 @@ class ThreadHandlerTest { var participantRestartAc = new ParticipantRestartAc(); participantRestartAc.setAutomationCompositionId(UUID.randomUUID()); participantRestartAc.getAcElementList().add(new AcElementRestart()); - threadHandler.restarted(messageId, compositionId, List.of(new AutomationCompositionElementDefinition()), - AcTypeState.PRIMED, List.of(participantRestartAc)); - verify(listener, timeout(TIMEOUT)).handleRestartInstance(any(), any(), any(), any(), any()); + var composition = new CompositionDto(compositionId, Map.of(), Map.of()); + threadHandler.restarted(messageId, composition, AcTypeState.PRIMED, List.of(participantRestartAc)); + verify(listener, timeout(TIMEOUT)).handleRestartInstance(any(), any(), any(), any()); } } } |