2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.acm.runtime.supervision.comm;
23 import io.micrometer.core.annotation.Timed;
24 import java.time.Instant;
25 import java.util.List;
26 import java.util.UUID;
27 import lombok.AllArgsConstructor;
28 import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup;
29 import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
30 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
31 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
32 import org.onap.policy.clamp.models.acm.concepts.DeployState;
33 import org.onap.policy.clamp.models.acm.concepts.ParticipantRestartAc;
34 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantSync;
35 import org.onap.policy.clamp.models.acm.utils.AcmUtils;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38 import org.springframework.stereotype.Component;
42 public class ParticipantSyncPublisher extends AbstractParticipantPublisher<ParticipantSync> {
44 private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantSyncPublisher.class);
45 private final AcRuntimeParameterGroup acRuntimeParameterGroup;
48 * Send Restart sync msg to Participant by participantId.
50 * @param participantId the participantId
51 * @param replicaId the replicaId
52 * @param acmDefinition the AutomationComposition Definition
53 * @param automationCompositions the list of automationCompositions
55 @Timed(value = "publisher.participant_sync_msg", description = "Participant Sync published")
56 public void sendRestartMsg(UUID participantId, UUID replicaId, AutomationCompositionDefinition acmDefinition,
57 List<AutomationComposition> automationCompositions) {
59 var message = new ParticipantSync();
60 message.setParticipantId(participantId);
61 message.setReplicaId(replicaId);
62 message.setRestarting(true);
63 message.setCompositionId(acmDefinition.getCompositionId());
64 message.setMessageId(UUID.randomUUID());
65 message.setTimestamp(Instant.now());
66 message.setState(acmDefinition.getState());
67 message.setParticipantDefinitionUpdates(AcmUtils.prepareParticipantRestarting(participantId, acmDefinition,
68 acRuntimeParameterGroup.getAcmParameters().getToscaElementName()));
70 for (var automationComposition : automationCompositions) {
71 var syncAc = AcmUtils.createAcRestart(automationComposition, participantId);
72 message.getAutomationcompositionList().add(syncAc);
75 LOGGER.debug("Participant Restarting Sync sent {}", message);
81 * @return true if default
84 public boolean isDefaultTopic() {
89 * Send AutomationCompositionDefinition sync msg to all Participants.
91 * @param acDefinition the AutomationComposition Definition
92 * @param excludeReplicaId the replica to be excluded
94 @Timed(value = "publisher.participant_sync_msg", description = "Participant Sync published")
95 public void sendSync(AutomationCompositionDefinition acDefinition, UUID excludeReplicaId) {
96 var message = new ParticipantSync();
97 message.setCompositionId(acDefinition.getCompositionId());
98 if (excludeReplicaId != null) {
99 message.getExcludeReplicas().add(excludeReplicaId);
101 message.setState(acDefinition.getState());
102 message.setStateChangeResult(acDefinition.getStateChangeResult());
103 message.setMessageId(UUID.randomUUID());
104 message.setTimestamp(Instant.now());
105 if (AcTypeState.COMMISSIONED.equals(acDefinition.getState())) {
106 message.setDelete(true);
108 message.setParticipantDefinitionUpdates(AcmUtils.prepareParticipantRestarting(null, acDefinition,
109 acRuntimeParameterGroup.getAcmParameters().getToscaElementName()));
111 LOGGER.debug("Participant AutomationCompositionDefinition Sync sent {}", message);
116 * Send AutomationComposition sync msg to all Participants.
118 * @param automationComposition the automationComposition
120 @Timed(value = "publisher.participant_sync_msg", description = "Participant Sync published")
121 public void sendSync(AutomationComposition automationComposition) {
122 var message = new ParticipantSync();
123 message.setCompositionId(automationComposition.getCompositionId());
124 message.setAutomationCompositionId(automationComposition.getInstanceId());
125 message.setState(AcTypeState.PRIMED);
126 message.setMessageId(UUID.randomUUID());
127 message.setTimestamp(Instant.now());
128 var syncAc = new ParticipantRestartAc();
129 syncAc.setAutomationCompositionId(automationComposition.getInstanceId());
130 syncAc.setDeployState(automationComposition.getDeployState());
131 syncAc.setLockState(automationComposition.getLockState());
132 syncAc.setStateChangeResult(automationComposition.getStateChangeResult());
133 if (DeployState.DELETED.equals(automationComposition.getDeployState())) {
134 message.setDelete(true);
136 for (var element : automationComposition.getElements().values()) {
137 var acElementSync = AcmUtils.createAcElementRestart(element);
138 syncAc.getAcElementList().add(acElementSync);
142 message.getAutomationcompositionList().add(syncAc);
144 LOGGER.debug("Participant AutomationComposition Sync sent {}", message.getMessageId());