diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-02-10 15:28:50 +0000 |
---|---|---|
committer | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-02-13 16:28:28 +0000 |
commit | e45da39db2625accf9ba3a77dc936a87d560fb5e (patch) | |
tree | 626de1ca14703df7dd1a81526966481cd57cc456 /participant/participant-intermediary | |
parent | 1191f992ddf1f6bcc94e7fa246ee3efbc71a3a8f (diff) |
Deployment and undeployment on Participant Intermediary
Handle AC Element Instance Deployment and undeployment
on Participant Intermediary.
Issue-ID: POLICY-4507
Change-Id: I6a6976a8893450467ee609a1a476dbfa473a0e82
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-intermediary')
8 files changed, 240 insertions, 231 deletions
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 ee769f481..da6bccb41 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-2022 Nordix Foundation. + * Copyright (C) 2021-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,9 +22,7 @@ package org.onap.policy.clamp.acm.participant.intermediary.api; import java.util.Map; import java.util.UUID; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; import org.onap.policy.models.base.PfModelException; /** @@ -35,13 +33,9 @@ public interface AutomationCompositionElementListener { * Handle a automation composition element state change. * * @param automationCompositionElementId the ID of the automation composition element - * @param currentState the current state of the automation composition element - * @param newState the state to which the automation composition element is changing to * @throws PfModelException in case of a model exception */ - public void automationCompositionElementStateChange(UUID automationCompositionId, - UUID automationCompositionElementId, AutomationCompositionState currentState, - AutomationCompositionOrderedState newState) throws PfModelException; + public void undeploy(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException; /** * Handle an update on a automation composition element. @@ -51,6 +45,6 @@ public interface AutomationCompositionElementListener { * @param properties properties Map * @throws PfModelException from Policy framework */ - public void automationCompositionElementUpdate(UUID automationCompositionId, - AutomationCompositionElement element, Map<String, Object> properties) throws PfModelException; + public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties) + throws PfModelException; } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java index d74c41f35..998a63269 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation. + * Copyright (C) 2021-2023 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,10 +22,8 @@ package org.onap.policy.clamp.acm.participant.intermediary.api; import java.util.UUID; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; +import org.onap.policy.clamp.models.acm.concepts.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; /** * This interface is used by participant implementations to use the participant intermediary. @@ -38,17 +36,14 @@ public interface ParticipantIntermediaryApi { * @param automationCompositionElementListener The automation composition element listener to register */ void registerAutomationCompositionElementListener( - AutomationCompositionElementListener automationCompositionElementListener); + AutomationCompositionElementListener automationCompositionElementListener); /** * Update the state of a automation composition element. * * @param id the ID of the automation composition element to update the state on - * @param currentState the state of the automation composition element * @param newState the state of the automation composition element - * @return AutomationCompositionElement updated automation composition element */ - AutomationCompositionElement updateAutomationCompositionElementState(UUID automationCompositionId, - UUID id, AutomationCompositionOrderedState currentState, AutomationCompositionState newState, - ParticipantMessageType messageType); + void updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, DeployState newState, + LockState lockState); } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java index acbcc37a6..d729a097f 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation. + * Copyright (C) 2021-2023 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,10 +25,8 @@ import java.util.UUID; 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.handler.AutomationCompositionHandler; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; +import org.onap.policy.clamp.models.acm.concepts.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; import org.springframework.stereotype.Component; /** @@ -56,10 +54,9 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp } @Override - public AutomationCompositionElement updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, - AutomationCompositionOrderedState currentState, AutomationCompositionState newState, - ParticipantMessageType messageType) { - return automationCompositionHandler.updateAutomationCompositionElementState(automationCompositionId, id, - currentState, newState); + public void updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, DeployState newState, + LockState lockState) { + automationCompositionHandler.updateAutomationCompositionElementState(automationCompositionId, id, newState, + lockState); } } 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 95e0f27bf..2d845d4c8 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 @@ -27,23 +27,26 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.UUID; -import java.util.stream.Collectors; import lombok.Getter; import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher; import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantParameters; +import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; import org.onap.policy.clamp.models.acm.concepts.AcElementDeployAck; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.clamp.models.acm.concepts.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy; import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; +import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; +import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder; +import org.onap.policy.clamp.models.acm.persistence.provider.AcInstanceStateResolver; 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; @@ -60,6 +63,7 @@ public class AutomationCompositionHandler { private final UUID participantId; private final ParticipantMessagePublisher publisher; + private final AcInstanceStateResolver acInstanceStateResolver; @Getter private final Map<UUID, AutomationComposition> automationCompositionMap = new LinkedHashMap<>(); @@ -68,7 +72,7 @@ public class AutomationCompositionHandler { private final Map<UUID, AutomationCompositionElement> elementsOnThisParticipant = new LinkedHashMap<>(); @Getter - private List<AutomationCompositionElementListener> listeners = new ArrayList<>(); + private final List<AutomationCompositionElementListener> listeners = new ArrayList<>(); /** * Constructor, set the participant ID and messageSender. @@ -79,6 +83,7 @@ public class AutomationCompositionHandler { public AutomationCompositionHandler(ParticipantParameters parameters, ParticipantMessagePublisher publisher) { this.participantId = parameters.getIntermediaryParameters().getParticipantId(); this.publisher = publisher; + this.acInstanceStateResolver = new AcInstanceStateResolver(); } public void registerAutomationCompositionElementListener(AutomationCompositionElementListener listener) { @@ -90,30 +95,32 @@ public class AutomationCompositionHandler { * * @param automationCompositionId the automationComposition Id * @param id the automationComposition UUID - * @param orderedState the current state - * @param newState the ordered state - * @return automationCompositionElement the updated automation composition element + * @param deployState the DeployState state */ - public AutomationCompositionElement updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, - AutomationCompositionOrderedState orderedState, AutomationCompositionState newState) { + public void updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, DeployState deployState, + LockState lockState) { if (id == null) { LOGGER.warn("Cannot update Automation composition element state, id is null"); - return null; + return; } // Update states of AutomationCompositionElement in automationCompositionMap for (var automationComposition : automationCompositionMap.values()) { var element = automationComposition.getElements().get(id); if (element != null) { - element.setOrderedState(orderedState); - element.setState(newState); + element.setDeployState(deployState); + element.setLockState(lockState); } var checkOpt = automationComposition.getElements().values().stream() - .filter(acElement -> !newState.equals(acElement.getState())).findAny(); + .filter(acElement -> !deployState.equals(acElement.getDeployState())).findAny(); + if (checkOpt.isEmpty()) { + automationComposition.setDeployState(deployState); + } + checkOpt = automationComposition.getElements().values().stream() + .filter(acElement -> !lockState.equals(acElement.getLockState())).findAny(); if (checkOpt.isEmpty()) { - automationComposition.setState(newState); - automationComposition.setOrderedState(orderedState); + automationComposition.setLockState(lockState); } } @@ -124,19 +131,17 @@ public class AutomationCompositionHandler { new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK); automationCompositionStateChangeAck.setParticipantId(participantId); automationCompositionStateChangeAck.setAutomationCompositionId(automationCompositionId); - acElement.setOrderedState(orderedState); - acElement.setState(newState); + acElement.setDeployState(deployState); + acElement.setLockState(lockState); automationCompositionStateChangeAck.getAutomationCompositionResultMap().put(acElement.getId(), - new AcElementDeployAck(newState, null, null, true, + new AcElementDeployAck(deployState, lockState, true, "Automation composition element {} state changed to {}\", id, newState)")); - LOGGER.debug("Automation composition element {} state changed to {}", id, newState); + LOGGER.debug("Automation composition element {} state changed to {}", id, deployState); automationCompositionStateChangeAck - .setMessage("AutomationCompositionElement state changed to {} " + newState); + .setMessage("AutomationCompositionElement state changed to {} " + deployState); automationCompositionStateChangeAck.setResult(true); publisher.sendAutomationCompositionAck(automationCompositionStateChangeAck); - return acElement; } - return null; } /** @@ -168,8 +173,32 @@ public class AutomationCompositionHandler { return; } - handleState(automationComposition, stateChangeMsg.getOrderedState(), stateChangeMsg.getStartPhase(), - acElementDefinitions); + if (!checkConsistantOrderState(automationComposition, stateChangeMsg.getDeployOrderedState(), + stateChangeMsg.getLockOrderedState())) { + var automationCompositionAck = + new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK); + automationCompositionAck.setParticipantId(participantId); + automationCompositionAck.setMessage("Automation composition is already in state " + + stateChangeMsg.getDeployOrderedState() + " and " + stateChangeMsg.getLockOrderedState()); + automationCompositionAck.setResult(false); + automationCompositionAck.setAutomationCompositionId(automationComposition.getInstanceId()); + publisher.sendAutomationCompositionAck(automationCompositionAck); + return; + } + + if (DeployOrder.NONE.equals(stateChangeMsg.getDeployOrderedState())) { + handleLockOrderState(automationComposition, stateChangeMsg.getLockOrderedState(), + stateChangeMsg.getStartPhase(), acElementDefinitions); + } else { + handleDeployOrderState(automationComposition, stateChangeMsg.getDeployOrderedState(), + stateChangeMsg.getStartPhase(), acElementDefinitions); + } + } + + private boolean checkConsistantOrderState(AutomationComposition automationComposition, DeployOrder deployOrder, + LockOrder lockOrder) { + return acInstanceStateResolver.resolve(deployOrder, lockOrder, automationComposition.getDeployState(), + automationComposition.getLockState()) != null; } /** @@ -180,18 +209,33 @@ public class AutomationCompositionHandler { * @param startPhaseMsg startPhase from message * @param acElementDefinitions the list of AutomationCompositionElementDefinition */ - private void handleState(final AutomationComposition automationComposition, - AutomationCompositionOrderedState orderedState, Integer startPhaseMsg, - List<AutomationCompositionElementDefinition> acElementDefinitions) { + private void handleDeployOrderState(final AutomationComposition automationComposition, DeployOrder orderedState, + Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) { + + if (DeployOrder.UNDEPLOY.equals(orderedState)) { + handleUndeployState(automationComposition, startPhaseMsg, acElementDefinitions); + } else { + LOGGER.debug("StateChange message has no state, state is null {}", automationComposition.getKey()); + } + } + + /** + * Method to handle state changes. + * + * @param automationComposition participant response + * @param orderedState automation composition ordered state + * @param startPhaseMsg startPhase from message + * @param acElementDefinitions the list of AutomationCompositionElementDefinition + */ + private void handleLockOrderState(final AutomationComposition automationComposition, LockOrder orderedState, + Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) { + switch (orderedState) { - case UNINITIALISED: - handleUninitialisedState(automationComposition, orderedState, startPhaseMsg, acElementDefinitions); - break; - case PASSIVE: - handlePassiveState(automationComposition, orderedState, startPhaseMsg, acElementDefinitions); + case LOCK: + handleLockState(automationComposition, startPhaseMsg, acElementDefinitions); break; - case RUNNING: - handleRunningState(automationComposition, orderedState, startPhaseMsg, acElementDefinitions); + case UNLOCK: + handleUnlockState(automationComposition, startPhaseMsg, acElementDefinitions); break; default: LOGGER.debug("StateChange message has no state, state is null {}", automationComposition.getKey()); @@ -208,67 +252,49 @@ public class AutomationCompositionHandler { public void handleAutomationCompositionDeploy(AutomationCompositionDeploy updateMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) { - if (!updateMsg.appliesTo(participantId)) { + if (updateMsg.getParticipantUpdatesList().isEmpty()) { + LOGGER.warn("No AutomationCompositionElement updates in message {}", + updateMsg.getAutomationCompositionId()); return; } - if (0 == updateMsg.getStartPhase()) { - handleAcUpdatePhase0(updateMsg, acElementDefinitions); - } else { - handleAcUpdatePhaseN(updateMsg, acElementDefinitions); + for (var participantDeploy : updateMsg.getParticipantUpdatesList()) { + if (participantId.equals(participantDeploy.getParticipantId())) { + if (updateMsg.isFirstStartPhase()) { + initializeDeploy(updateMsg.getMessageId(), updateMsg.getAutomationCompositionId(), + participantDeploy); + } + callParticipanDeploy(participantDeploy.getAcElementList(), acElementDefinitions, + updateMsg.getStartPhase(), updateMsg.getAutomationCompositionId()); + } } } - private void handleAcUpdatePhase0(AutomationCompositionDeploy updateMsg, - List<AutomationCompositionElementDefinition> acElementDefinitions) { - var automationComposition = automationCompositionMap.get(updateMsg.getAutomationCompositionId()); + private void initializeDeploy(UUID messageId, UUID instanceId, ParticipantDeploy participantDeploy) { + var automationComposition = automationCompositionMap.get(instanceId); - // TODO: Updates to existing AutomationCompositions are not supported yet (Addition/Removal of - // AutomationComposition - // elements to existing AutomationComposition has to be supported). if (automationComposition != null) { var automationCompositionUpdateAck = new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY_ACK); automationCompositionUpdateAck.setParticipantId(participantId); - automationCompositionUpdateAck.setMessage("Automation composition " + updateMsg.getAutomationCompositionId() - + " already defined on participant " + participantId); + automationCompositionUpdateAck.setMessage( + "Automation composition " + instanceId + " already defined on participant " + participantId); automationCompositionUpdateAck.setResult(false); - automationCompositionUpdateAck.setResponseTo(updateMsg.getMessageId()); - automationCompositionUpdateAck.setAutomationCompositionId(updateMsg.getAutomationCompositionId()); + automationCompositionUpdateAck.setResponseTo(messageId); + automationCompositionUpdateAck.setAutomationCompositionId(instanceId); publisher.sendAutomationCompositionAck(automationCompositionUpdateAck); return; } - if (updateMsg.getParticipantUpdatesList().isEmpty()) { - LOGGER.warn("No AutomationCompositionElement updates in message {}", - updateMsg.getAutomationCompositionId()); - return; - } - automationComposition = new AutomationComposition(); - automationComposition.setInstanceId(updateMsg.getAutomationCompositionId()); - var acElements = storeElementsOnThisParticipant(updateMsg.getParticipantUpdatesList()); - var acElementMap = prepareAcElementMap(acElements); - automationComposition.setElements(acElementMap); - automationCompositionMap.put(updateMsg.getAutomationCompositionId(), automationComposition); - - handleAutomationCompositionElementUpdate(acElements, acElementDefinitions, updateMsg.getStartPhase(), - updateMsg.getAutomationCompositionId()); - } - - private void handleAcUpdatePhaseN(AutomationCompositionDeploy updateMsg, - List<AutomationCompositionElementDefinition> acElementDefinitions) { - - var acElementList = updateMsg.getParticipantUpdatesList().stream() - .flatMap(participantUpdate -> participantUpdate.getAutomationCompositionElementList().stream()) - .filter(element -> participantId.equals(element.getParticipantId())).collect(Collectors.toList()); - - handleAutomationCompositionElementUpdate(acElementList, acElementDefinitions, updateMsg.getStartPhase(), - updateMsg.getAutomationCompositionId()); + automationComposition.setInstanceId(instanceId); + var acElements = storeElementsOnThisParticipant(participantDeploy); + automationComposition.setElements(prepareAcElementMap(acElements)); + automationCompositionMap.put(instanceId, automationComposition); } - private void handleAutomationCompositionElementUpdate(List<AutomationCompositionElement> acElements, + private void callParticipanDeploy(List<AcElementDeploy> acElements, List<AutomationCompositionElementDefinition> acElementDefinitions, Integer startPhaseMsg, UUID automationCompositionId) { try { @@ -280,7 +306,7 @@ public class AutomationCompositionHandler { for (var acElementListener : listeners) { var map = new HashMap<>(acElementNodeTemplate.getProperties()); map.putAll(element.getProperties()); - acElementListener.automationCompositionElementUpdate(automationCompositionId, element, map); + acElementListener.deploy(automationCompositionId, element, map); } } } @@ -302,14 +328,16 @@ public class AutomationCompositionHandler { return null; } - private List<AutomationCompositionElement> storeElementsOnThisParticipant( - List<ParticipantDeploy> participantUpdates) { - var acElementList = participantUpdates.stream() - .flatMap(participantUpdate -> participantUpdate.getAutomationCompositionElementList().stream()) - .filter(element -> participantId.equals(element.getParticipantId())).collect(Collectors.toList()); - - for (var element : acElementList) { - elementsOnThisParticipant.put(element.getId(), element); + private List<AutomationCompositionElement> storeElementsOnThisParticipant(ParticipantDeploy participantDeploy) { + List<AutomationCompositionElement> acElementList = new ArrayList<>(); + for (var element : participantDeploy.getAcElementList()) { + var acElement = new AutomationCompositionElement(); + acElement.setId(element.getId()); + acElement.setDefinition(element.getDefinition()); + acElement.setDeployState(DeployState.DEPLOYING); + acElement.setLockState(LockState.NONE); + elementsOnThisParticipant.put(element.getId(), acElement); + acElementList.add(acElement); } return acElementList; } @@ -326,17 +354,18 @@ public class AutomationCompositionHandler { * Method to handle when the new state from participant is UNINITIALISED state. * * @param automationComposition participant response - * @param orderedState orderedState * @param startPhaseMsg startPhase from message * @param acElementDefinitions the list of AutomationCompositionElementDefinition */ - private void handleUninitialisedState(final AutomationComposition automationComposition, - final AutomationCompositionOrderedState orderedState, Integer startPhaseMsg, + private void handleUndeployState(final AutomationComposition automationComposition, Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) { - handleStateChange(automationComposition, orderedState, startPhaseMsg, acElementDefinitions); + + automationComposition.getElements().values().stream() + .forEach(acElement -> automationCompositionElementUndeploy(automationComposition.getInstanceId(), + acElement, startPhaseMsg, acElementDefinitions)); + boolean isAllUninitialised = automationComposition.getElements().values().stream() - .filter(element -> !AutomationCompositionState.UNINITIALISED.equals(element.getState())).findAny() - .isEmpty(); + .filter(element -> !DeployState.UNDEPLOYED.equals(element.getDeployState())).findAny().isEmpty(); if (isAllUninitialised) { automationCompositionMap.remove(automationComposition.getInstanceId()); automationComposition.getElements().values() @@ -348,60 +377,55 @@ public class AutomationCompositionHandler { * Method to handle when the new state from participant is PASSIVE state. * * @param automationComposition participant response - * @param orderedState orderedState * @param startPhaseMsg startPhase from message * @param acElementDefinitions the list of AutomationCompositionElementDefinition */ - private void handlePassiveState(final AutomationComposition automationComposition, - final AutomationCompositionOrderedState orderedState, Integer startPhaseMsg, + private void handleLockState(final AutomationComposition automationComposition, Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) { - handleStateChange(automationComposition, orderedState, startPhaseMsg, acElementDefinitions); + automationComposition.getElements().values().stream() + .forEach(acElement -> automationCompositionElementLock(automationComposition.getInstanceId(), acElement, + startPhaseMsg, acElementDefinitions)); } /** * Method to handle when the new state from participant is RUNNING state. * * @param automationComposition participant response - * @param orderedState orderedState * @param startPhaseMsg startPhase from message * @param acElementDefinitions the list of AutomationCompositionElementDefinition */ - private void handleRunningState(final AutomationComposition automationComposition, - final AutomationCompositionOrderedState orderedState, Integer startPhaseMsg, + private void handleUnlockState(final AutomationComposition automationComposition, Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) { - handleStateChange(automationComposition, orderedState, startPhaseMsg, acElementDefinitions); + automationComposition.getElements().values().stream() + .forEach(acElement -> automationCompositionElementUnlock(automationComposition.getInstanceId(), + acElement, startPhaseMsg, acElementDefinitions)); } - /** - * Method to update the state of automation composition elements. - * - * @param automationComposition participant status in memory - * @param orderedState orderedState the new ordered state the participant should have - * @param startPhaseMsg startPhase from message - * @param acElementDefinitions the list of AutomationCompositionElementDefinition - */ - private void handleStateChange(AutomationComposition automationComposition, - final AutomationCompositionOrderedState orderedState, Integer startPhaseMsg, - List<AutomationCompositionElementDefinition> acElementDefinitions) { - - if (orderedState.equals(automationComposition.getOrderedState())) { - var automationCompositionAck = - new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK); - automationCompositionAck.setParticipantId(participantId); - automationCompositionAck.setMessage("Automation composition is already in state " + orderedState); - automationCompositionAck.setResult(false); - automationCompositionAck.setAutomationCompositionId(automationComposition.getInstanceId()); - publisher.sendAutomationCompositionAck(automationCompositionAck); - return; + private void automationCompositionElementLock(UUID instanceId, AutomationCompositionElement acElement, + Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) { + var acElementNodeTemplate = getAcElementNodeTemplate(acElementDefinitions, acElement.getDefinition()); + if (acElementNodeTemplate != null) { + int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties()); + if (startPhaseMsg.equals(startPhase)) { + updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED, + LockState.LOCKED); + } } + } - automationComposition.getElements().values().stream() - .forEach(acElement -> automationCompositionElementStateChange(automationComposition, orderedState, - acElement, startPhaseMsg, acElementDefinitions)); + private void automationCompositionElementUnlock(UUID instanceId, AutomationCompositionElement acElement, + Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) { + var acElementNodeTemplate = getAcElementNodeTemplate(acElementDefinitions, acElement.getDefinition()); + if (acElementNodeTemplate != null) { + int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties()); + if (startPhaseMsg.equals(startPhase)) { + updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED, + LockState.UNLOCKED); + } + } } - private void automationCompositionElementStateChange(AutomationComposition automationComposition, - AutomationCompositionOrderedState orderedState, AutomationCompositionElement acElement, + private void automationCompositionElementUndeploy(UUID instanceId, AutomationCompositionElement acElement, Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) { var acElementNodeTemplate = getAcElementNodeTemplate(acElementDefinitions, acElement.getDefinition()); if (acElementNodeTemplate != null) { @@ -409,11 +433,9 @@ public class AutomationCompositionHandler { if (startPhaseMsg.equals(startPhase)) { for (var acElementListener : listeners) { try { - acElementListener.automationCompositionElementStateChange(automationComposition.getInstanceId(), - acElement.getId(), acElement.getState(), orderedState); + acElementListener.undeploy(instanceId, acElement.getId()); } catch (PfModelException e) { - LOGGER.debug("Automation composition element update failed {}", - automationComposition.getInstanceId()); + LOGGER.debug("Automation composition element update failed {}", instanceId); } } } 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 3aae2c41a..719c428be 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 @@ -261,7 +261,8 @@ public class ParticipantHandler { for (var entry : automationCompositionHandler.getAutomationCompositionMap().entrySet()) { var acInfo = new AutomationCompositionInfo(); acInfo.setAutomationCompositionId(entry.getKey()); - acInfo.setState(entry.getValue().getState()); + acInfo.setDeployState(entry.getValue().getDeployState()); + acInfo.setLockState(entry.getValue().getLockState()); automationCompositionInfoList.add(acInfo); } return automationCompositionInfoList; diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java index 9b0f910ea..d86c9d0a4 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation. + * Copyright (C) 2021-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,9 +27,8 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; +import org.onap.policy.clamp.models.acm.concepts.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.common.utils.coder.CoderException; class ParticipantIntermediaryApiImplTest { @@ -47,11 +46,10 @@ class ParticipantIntermediaryApiImplTest { var acElementListener = Mockito.mock(AutomationCompositionElementListener.class); apiImpl.registerAutomationCompositionElementListener(acElementListener); - var acElement = apiImpl.updateAutomationCompositionElementState(UUID.randomUUID(), uuid, - AutomationCompositionOrderedState.UNINITIALISED, AutomationCompositionState.PASSIVE, - ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK); - assertEquals(AutomationCompositionOrderedState.UNINITIALISED, acElement.getOrderedState()); + apiImpl.updateAutomationCompositionElementState(UUID.randomUUID(), uuid, DeployState.UNDEPLOYED, + LockState.NONE); + var acElement = automationComposiitonHandler.getElementsOnThisParticipant().get(uuid); + assertEquals(DeployState.UNDEPLOYED, acElement.getDeployState()); assertEquals(uuid, acElement.getId()); - } } 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 ae8a8b2a0..35da039a5 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 @@ -24,7 +24,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.mock; import java.util.List; @@ -33,14 +32,15 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; +import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.clamp.models.acm.concepts.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +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.ToscaNodeTemplate; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -55,15 +55,7 @@ class AutomationCompositionHandlerTest { assertNotNull(ach.getAutomationCompositionMap()); assertNotNull(ach.getElementsOnThisParticipant()); - var elementId1 = UUID.randomUUID(); - var element = new AutomationCompositionElement(); - element.setId(elementId1); - element.setDefinition( - new ToscaConceptIdentifier("org.onap.policy.acm.PolicyAutomationCompositionParticipant", "1.0.1")); - - element.setOrderedState(AutomationCompositionOrderedState.PASSIVE); - - AutomationCompositionElementListener listener = mock(AutomationCompositionElementListener.class); + var listener = mock(AutomationCompositionElementListener.class); ach.registerAutomationCompositionElementListener(listener); assertThat(ach.getListeners()).contains(listener); } @@ -73,11 +65,11 @@ class AutomationCompositionHandlerTest { var id = UUID.randomUUID(); var ach = commonTestData.getMockAutomationCompositionHandler(); - assertNull(ach.updateAutomationCompositionElementState(null, null, - AutomationCompositionOrderedState.UNINITIALISED, AutomationCompositionState.PASSIVE)); + assertDoesNotThrow( + () -> ach.updateAutomationCompositionElementState(null, null, DeployState.UNDEPLOYED, LockState.NONE)); - assertNull(ach.updateAutomationCompositionElementState(null, id, - AutomationCompositionOrderedState.UNINITIALISED, AutomationCompositionState.PASSIVE)); + assertDoesNotThrow( + () -> ach.updateAutomationCompositionElementState(null, id, DeployState.UNDEPLOYED, LockState.NONE)); } @Test @@ -89,29 +81,29 @@ class AutomationCompositionHandlerTest { var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); var key = ach.getElementsOnThisParticipant().keySet().iterator().next(); var value = ach.getElementsOnThisParticipant().get(key); - assertEquals(AutomationCompositionState.UNINITIALISED, value.getState()); - ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, uuid, - AutomationCompositionOrderedState.UNINITIALISED, AutomationCompositionState.PASSIVE); - assertEquals(AutomationCompositionState.PASSIVE, value.getState()); + assertEquals(DeployState.UNDEPLOYED, value.getDeployState()); + assertEquals(LockState.LOCKED, value.getLockState()); + ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, uuid, DeployState.DEPLOYED, + LockState.UNLOCKED); + assertEquals(DeployState.DEPLOYED, value.getDeployState()); ach.getAutomationCompositionMap().values().iterator().next().getElements().putIfAbsent(key, value); - ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, - AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.RUNNING); - assertEquals(AutomationCompositionState.RUNNING, value.getState()); + ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, DeployState.DEPLOYED, + LockState.UNLOCKED); + assertEquals(DeployState.DEPLOYED, value.getDeployState()); ach.getElementsOnThisParticipant().remove(key, value); ach.getAutomationCompositionMap().values().iterator().next().getElements().clear(); - assertNull(ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, - AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.RUNNING)); - + assertDoesNotThrow(() -> ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, + DeployState.DEPLOYED, LockState.UNLOCKED)); } @Test - void handleAutomationCompositionUpdateExceptionTest() { + void handleAutomationCompositionStateChangeTest() { var uuid = UUID.randomUUID(); var partecipantId = CommonTestData.getParticipantId(); var definition = CommonTestData.getDefinition(); - var stateChange = commonTestData.getStateChange(partecipantId, uuid, AutomationCompositionOrderedState.RUNNING); + var stateChange = commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.UNLOCK); var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); assertDoesNotThrow(() -> ach .handleAutomationCompositionStateChange(mock(AutomationCompositionStateChange.class), List.of())); @@ -121,20 +113,30 @@ class AutomationCompositionHandlerTest { stateChange.setAutomationCompositionId(UUID.randomUUID()); stateChange.setParticipantId(newPartecipantId); assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChange, List.of())); + } + @Test + void handleAutomationCompositionDeployTest() { var acd = new AutomationCompositionElementDefinition(); + var definition = CommonTestData.getDefinition(); acd.setAcElementDefinitionId(definition); var updateMsg = new AutomationCompositionDeploy(); updateMsg.setAutomationCompositionId(UUID.randomUUID()); + var uuid = UUID.randomUUID(); updateMsg.setMessageId(uuid); + var partecipantId = CommonTestData.getParticipantId(); updateMsg.setParticipantId(partecipantId); + updateMsg.setFirstStartPhase(true); updateMsg.setStartPhase(0); var acElementDefinitions = List.of(acd); + var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions)); + updateMsg.setFirstStartPhase(false); updateMsg.setStartPhase(1); assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions)); ach.getAutomationCompositionMap().clear(); + updateMsg.setFirstStartPhase(true); updateMsg.setStartPhase(0); assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions)); @@ -145,9 +147,9 @@ class AutomationCompositionHandlerTest { updateMsg.setStartPhase(1); var participantDeploy = new ParticipantDeploy(); participantDeploy.setParticipantId(partecipantId); - var element = new AutomationCompositionElement(); + var element = new AcElementDeploy(); element.setDefinition(definition); - participantDeploy.setAutomationCompositionElementList(List.of(element)); + participantDeploy.setAcElementList(List.of(element)); updateMsg.setParticipantUpdatesList(List.of(participantDeploy)); var acd2 = new AutomationCompositionElementDefinition(); @@ -158,34 +160,38 @@ class AutomationCompositionHandlerTest { } @Test - void automationCompositionStateChangeUninitialisedTest() { + void acUndeployTest() { var uuid = UUID.randomUUID(); var partecipantId = CommonTestData.getParticipantId(); var definition = CommonTestData.getDefinition(); - var stateChangeUninitialised = - commonTestData.getStateChange(partecipantId, uuid, AutomationCompositionOrderedState.UNINITIALISED); + var stateChangeUndeploy = + commonTestData.getStateChange(partecipantId, uuid, DeployOrder.UNDEPLOY, LockOrder.NONE); var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); - ach.handleAutomationCompositionStateChange(stateChangeUninitialised, List.of()); - stateChangeUninitialised.setAutomationCompositionId(UUID.randomUUID()); - stateChangeUninitialised.setParticipantId(CommonTestData.getRndParticipantId()); - assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUninitialised, List.of())); + stateChangeUndeploy + .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey()); + ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of()); + stateChangeUndeploy.setAutomationCompositionId(UUID.randomUUID()); + stateChangeUndeploy.setParticipantId(CommonTestData.getRndParticipantId()); + assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of())); } @Test - void automationCompositionStateChangePassiveTest() { + void automationCompositionStateUnlock() { var uuid = UUID.randomUUID(); var partecipantId = CommonTestData.getParticipantId(); var definition = CommonTestData.getDefinition(); - var stateChangePassive = - commonTestData.getStateChange(partecipantId, uuid, AutomationCompositionOrderedState.PASSIVE); + var stateChangeUnlock = + commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.UNLOCK); var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); - ach.handleAutomationCompositionStateChange(stateChangePassive, List.of()); - stateChangePassive.setAutomationCompositionId(UUID.randomUUID()); - stateChangePassive.setParticipantId(CommonTestData.getRndParticipantId()); - assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangePassive, List.of())); + stateChangeUnlock + .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey()); + ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of()); + stateChangeUnlock.setAutomationCompositionId(UUID.randomUUID()); + stateChangeUnlock.setParticipantId(CommonTestData.getRndParticipantId()); + assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of())); } } diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java index 9641edc2e..4dcfd1428 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java @@ -37,11 +37,12 @@ import org.onap.policy.clamp.acm.participant.intermediary.handler.ParticipantHan import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantIntermediaryParameters; 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.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; 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.messages.dmaap.participant.AutomationCompositionStateChange; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck; +import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; +import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder; import org.onap.policy.common.endpoints.event.comm.TopicSink; import org.onap.policy.common.endpoints.parameters.TopicParameters; import org.onap.policy.common.utils.coder.Coder; @@ -272,7 +273,7 @@ public class CommonTestData { acElement.setId(uuid); acElement.setParticipantId(participantId); acElement.setDefinition(definition); - acElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + acElement.setDeployState(DeployState.UNDEPLOYED); Map<UUID, AutomationCompositionElement> elementsOnThisParticipant = new LinkedHashMap<>(); elementsOnThisParticipant.put(uuid, acElement); @@ -289,14 +290,8 @@ public class CommonTestData { public AutomationCompositionHandler setTestAutomationCompositionHandler(ToscaConceptIdentifier definition, UUID uuid, UUID participantId) { var ach = getMockAutomationCompositionHandler(); - - var key = getTestAutomationCompositionMap().keySet().iterator().next(); - var value = getTestAutomationCompositionMap().get(key); - ach.getAutomationCompositionMap().put(key, value); - - var keyElem = setAutomationCompositionElementTest(uuid, definition, participantId).keySet().iterator().next(); - var valueElem = setAutomationCompositionElementTest(uuid, definition, participantId).get(keyElem); - ach.getElementsOnThisParticipant().put(keyElem, valueElem); + ach.getAutomationCompositionMap().putAll(getTestAutomationCompositionMap()); + ach.getElementsOnThisParticipant().putAll(setAutomationCompositionElementTest(uuid, definition, participantId)); return ach; } @@ -306,17 +301,18 @@ public class CommonTestData { * * @param participantId the participantId * @param uuid UUID - * @param state a AutomationCompositionOrderedState + * @param deployOrder a DeployOrder + * @param lockOrder a LockOrder * @return a AutomationCompositionStateChange */ public AutomationCompositionStateChange getStateChange(UUID participantId, UUID uuid, - AutomationCompositionOrderedState state) { + DeployOrder deployOrder, LockOrder lockOrder) { var stateChange = new AutomationCompositionStateChange(); stateChange.setAutomationCompositionId(UUID.randomUUID()); stateChange.setParticipantId(participantId); stateChange.setMessageId(uuid); - stateChange.setOrderedState(state); - stateChange.setCurrentState(AutomationCompositionState.UNINITIALISED); + stateChange.setDeployOrderedState(deployOrder); + stateChange.setLockOrderedState(lockOrder); stateChange.setTimestamp(Instant.ofEpochMilli(3000)); return stateChange; } |