diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-07-12 11:20:03 +0100 |
---|---|---|
committer | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-07-12 11:36:42 +0100 |
commit | 51ef04415186a0de3e50339b7fca04fb5ef079c9 (patch) | |
tree | 5cde4512b351dee5735c2651994e20161e001aaa /participant/participant-intermediary/src/main | |
parent | b13d8dc3a73bc372dabe47ebd88ed1892ee688ea (diff) |
Add support participant restart scenario in ACM intermediary
Issue-ID: POLICY-4745
Change-Id: I8ab71137ef981cb4fdeae4bf9732382b9534b442
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-intermediary/src/main')
6 files changed, 137 insertions, 5 deletions
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantRestartListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantRestartListener.java new file mode 100644 index 000000000..7fc9c2764 --- /dev/null +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantRestartListener.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.acm.participant.intermediary.comm; + +import org.onap.policy.clamp.acm.participant.intermediary.handler.ParticipantHandler; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRestart; +import org.springframework.stereotype.Component; + +@Component +public class ParticipantRestartListener extends ParticipantListener<ParticipantRestart> { + + /** + * Constructs the object. + * + * @param participantHandler the handler for managing the state of the participant + */ + public ParticipantRestartListener(ParticipantHandler participantHandler) { + super(ParticipantRestart.class, participantHandler, participantHandler::handleParticipantRestart); + } + + @Override + public String getType() { + return ParticipantMessageType.PARTICIPANT_RESTART.name(); + } +} 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 71c9d9abc..b4735f1c0 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 @@ -26,9 +26,11 @@ import java.util.List; import java.util.UUID; 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.AutomationCompositionElementDefinition; import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy; +import org.onap.policy.clamp.models.acm.concepts.ParticipantRestartAc; import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils; import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy; @@ -334,4 +336,22 @@ public class AutomationCompositionHandler { public void deprime(UUID messageId, UUID compositionId) { listener.deprime(messageId, compositionId); } + + /** + * Handles restarted scenario. + * + * @param messageId the messageId + * @param compositionId the compositionId + * @param list the list of AutomationCompositionElementDefinition + * @param state the state of the composition + * @param automationCompositionList list of ParticipantRestartAc + */ + public void restarted(UUID messageId, UUID compositionId, List<AutomationCompositionElementDefinition> list, + AcTypeState state, List<ParticipantRestartAc> automationCompositionList) { + + for (var automationcomposition : automationCompositionList) { + cacheProvider.initializeAutomationComposition(compositionId, automationcomposition); + } + listener.restarted(messageId, compositionId, list, state, automationCompositionList); + } } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionOutHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionOutHandler.java index cfd61c4fe..334d6a89d 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionOutHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionOutHandler.java @@ -69,11 +69,6 @@ public class AutomationCompositionOutHandler { return; } - if ((deployState != null && lockState != null) || (deployState == null && lockState == null)) { - LOGGER.error("state error {} and {} cannot be handled", deployState, lockState); - return; - } - var automationComposition = cacheProvider.getAutomationComposition(automationCompositionId); if (automationComposition == null) { LOGGER.error("Cannot update Automation composition element state, Automation composition id {} not present", @@ -88,6 +83,13 @@ public class AutomationCompositionOutHandler { return; } + if ((element.getRestarting() != null) + && ((deployState != null && lockState != null) || (deployState == null && lockState == null))) { + LOGGER.error("state error {} and {} cannot be handled", deployState, lockState); + return; + } + element.setRestarting(null); + if (deployState != null) { handleDeployState(automationComposition, element, deployState); } 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 119cc11b5..08d5ccd32 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 @@ -35,6 +35,7 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDef 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.ParticipantRestartAc; import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType; import org.onap.policy.models.base.PfUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @@ -150,4 +151,32 @@ public class CacheProvider { automationComposition.setElements(acElementMap); automationCompositions.put(automationComposition.getInstanceId(), automationComposition); } + + /** + * Initialize an AutomationComposition from a ParticipantRestartAc. + * + * @param compositionId the composition Id + * @param participantRestartAc the ParticipantRestartAc + */ + public void initializeAutomationComposition(@NonNull UUID compositionId, + ParticipantRestartAc participantRestartAc) { + Map<UUID, AutomationCompositionElement> acElementMap = new LinkedHashMap<>(); + for (var element : participantRestartAc.getAcElementList()) { + var acElement = new AutomationCompositionElement(); + acElement.setId(element.getId()); + acElement.setParticipantId(getParticipantId()); + acElement.setDefinition(element.getDefinition()); + acElement.setDeployState(element.getDeployState()); + acElement.setLockState(element.getLockState()); + acElement.setProperties(element.getProperties()); + acElement.setRestarting(true); + acElementMap.put(element.getId(), acElement); + } + + var automationComposition = new AutomationComposition(); + automationComposition.setCompositionId(compositionId); + automationComposition.setInstanceId(participantRestartAc.getAutomationCompositionId()); + automationComposition.setElements(acElementMap); + automationCompositions.put(automationComposition.getInstanceId(), automationComposition); + } } 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 3a3a0cced..c78c7bb43 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 @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.List; import lombok.RequiredArgsConstructor; import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher; +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.AutomationCompositionInfo; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; @@ -40,6 +41,7 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMe import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrime; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegisterAck; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRestart; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatusReq; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.PropertiesUpdate; @@ -197,6 +199,27 @@ public class ParticipantHandler { } /** + * Handle a ParticipantRestart message. + * + * @param participantRestartMsg the participantRestart message + */ + @Timed(value = "listener.participant_restart", description = "PARTICIPANT_RESTART messages received") + public void handleParticipantRestart(ParticipantRestart participantRestartMsg) { + LOGGER.debug("ParticipantRestart message received for participantId {}", + participantRestartMsg.getParticipantId()); + List<AutomationCompositionElementDefinition> list = new ArrayList<>(); + for (var participantDefinition : participantRestartMsg.getParticipantDefinitionUpdates()) { + list.addAll(participantDefinition.getAutomationCompositionElementDefinitionList()); + } + if (!AcTypeState.COMMISSIONED.equals(participantRestartMsg.getState())) { + cacheProvider.addElementDefinition(participantRestartMsg.getCompositionId(), list); + } + automationCompositionHandler.restarted(participantRestartMsg.getMessageId(), + participantRestartMsg.getCompositionId(), list, participantRestartMsg.getState(), + participantRestartMsg.getAutomationcompositionList()); + } + + /** * Dispatch a heartbeat for this participant. */ public void sendHeartbeat() { 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 b5866d71f..65ad131df 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 @@ -37,6 +37,7 @@ 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.slf4j.Logger; @@ -260,6 +261,19 @@ public class ThreadHandler implements Closeable { } } + /** + * Handles restarted scenario. + * + * @param messageId the messageId + * @param compositionId the compositionId + * @param list the list of AutomationCompositionElementDefinition + * @param state the state of the composition + * @param automationCompositionList list of ParticipantRestartAc + */ + public void restarted(UUID messageId, UUID compositionId, List<AutomationCompositionElementDefinition> list, + AcTypeState state, List<ParticipantRestartAc> automationCompositionList) { + // TODO + } /** * Closes this stream and releases any system resources associated |