2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2023 Nordix Foundation.
4 * ================================================================================
5 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.clamp.acm.runtime.supervision.comm;
25 import io.micrometer.core.annotation.Timed;
26 import java.time.Instant;
27 import java.util.ArrayList;
28 import java.util.List;
29 import java.util.UUID;
30 import lombok.AllArgsConstructor;
31 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
32 import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition;
33 import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils;
34 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdate;
35 import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
36 import org.onap.policy.clamp.models.acm.utils.AcmUtils;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.stereotype.Component;
42 * This class is used to send ParticipantUpdate messages to participants on DMaaP.
46 public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<ParticipantUpdate> {
48 private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantUpdatePublisher.class);
50 private final AcDefinitionProvider acDefinitionProvider;
53 * Send ParticipantUpdate to all Participants.
55 * @param acmDefinition the AutomationComposition Definition
57 @Timed(value = "publisher.participant_update", description = "PARTICIPANT_UPDATE messages published")
58 public void sendComissioningBroadcast(AutomationCompositionDefinition acmDefinition) {
59 sendCommissioning(acmDefinition, null);
63 * Send ParticipantUpdate to Participant
64 * if participantId is null then message is broadcast.
66 * @param participantId the ParticipantId
68 @Timed(value = "publisher.participant_update", description = "PARTICIPANT_UPDATE messages published")
69 public void sendCommissioning(UUID participantId) {
70 var list = acDefinitionProvider.getAllAcDefinitions();
72 LOGGER.warn("No tosca service template found, cannot send participantupdate");
74 for (var acmDefinition : list) {
75 sendCommissioning(acmDefinition, participantId);
80 * Send ParticipantUpdate to Participant
81 * if participantId is null then message is broadcast.
83 * @param acmDefinition the AutomationComposition Definition
84 * @param participantId the ParticipantId
86 @Timed(value = "publisher.participant_update", description = "PARTICIPANT_UPDATE messages published")
87 public void sendCommissioning(AutomationCompositionDefinition acmDefinition,
89 var message = new ParticipantUpdate();
90 message.setCompositionId(acmDefinition.getCompositionId());
91 message.setParticipantId(participantId);
92 message.setTimestamp(Instant.now());
94 var toscaServiceTemplate = acmDefinition.getServiceTemplate();
95 List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
96 for (var toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet()) {
97 if (ParticipantUtils.checkIfNodeTemplateIsAutomationCompositionElement(toscaInputEntry.getValue(),
98 toscaServiceTemplate)) {
99 AcmUtils.prepareParticipantDefinitionUpdate(
101 toscaInputEntry.getKey(), toscaInputEntry.getValue(), participantDefinitionUpdates);
105 // Commission the automation composition but sending participantdefinitions to participants
106 message.setParticipantDefinitionUpdates(participantDefinitionUpdates);
107 LOGGER.debug("Participant Update sent {}", message);
112 * Send ParticipantUpdate to Participant after that commissioning has been removed.
114 @Timed(value = "publisher.participant_update", description = "PARTICIPANT_UPDATE messages published")
115 public void sendDecomisioning(UUID compositionId) {
116 var message = new ParticipantUpdate();
117 message.setCompositionId(compositionId);
118 message.setTimestamp(Instant.now());
119 // DeCommission the automation composition but deleting participantdefinitions on participants
120 message.setParticipantDefinitionUpdates(null);
122 LOGGER.debug("Participant Update sent {}", message);