2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021,2022 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;
30 import lombok.AllArgsConstructor;
31 import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition;
32 import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils;
33 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdate;
34 import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider;
35 import org.onap.policy.clamp.models.acm.utils.AcmUtils;
36 import org.onap.policy.models.base.PfModelException;
37 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
38 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType;
39 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42 import org.springframework.stereotype.Component;
45 * This class is used to send ParticipantUpdate messages to participants on DMaaP.
49 public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<ParticipantUpdate> {
51 private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantUpdatePublisher.class);
53 private final ServiceTemplateProvider serviceTemplateProvider;
56 * Send ParticipantUpdate to all Participants.
58 * @param name the ToscaServiceTemplate name
59 * @param version the ToscaServiceTemplate version
61 @Timed(value = "publisher.participant_update", description = "PARTICIPANT_UPDATE messages published")
62 public void sendComissioningBroadcast(String name, String version) {
63 sendCommissioning(name, version, null, null);
67 * Send ParticipantUpdate to Participant
68 * if participantType and participantId are null then message is broadcast.
70 * @param name the ToscaServiceTemplate name
71 * @param version the ToscaServiceTemplate version
72 * @param participantType the ParticipantType
73 * @param participantId the ParticipantId
75 @Timed(value = "publisher.participant_update", description = "PARTICIPANT_UPDATE messages published")
76 public boolean sendCommissioning(String name, String version, ToscaConceptIdentifier participantType,
77 ToscaConceptIdentifier participantId) {
78 var message = new ParticipantUpdate();
79 message.setParticipantType(participantType);
80 message.setParticipantId(participantId);
81 message.setTimestamp(Instant.now());
83 ToscaServiceTemplate toscaServiceTemplate = null;
84 Map<String, ToscaNodeType> commonPropertiesMap = null;
86 var list = serviceTemplateProvider.getServiceTemplateList(name, version);
87 if (!list.isEmpty()) {
88 toscaServiceTemplate = list.get(0);
90 serviceTemplateProvider.getCommonOrInstancePropertiesFromNodeTypes(true, toscaServiceTemplate);
92 LOGGER.warn("No tosca service template found, cannot send participantupdate {} {}", name, version);
95 } catch (PfModelException pfme) {
96 LOGGER.warn("Get of tosca service template failed, cannot send participantupdate", pfme);
100 List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
101 for (var toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet()) {
102 if (ParticipantUtils.checkIfNodeTemplateIsAutomationCompositionElement(toscaInputEntry.getValue(),
103 toscaServiceTemplate)) {
104 AcmUtils.prepareParticipantDefinitionUpdate(
105 ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties()),
106 toscaInputEntry.getKey(), toscaInputEntry.getValue(),
107 participantDefinitionUpdates, commonPropertiesMap);
111 // Commission the automation composition but sending participantdefinitions to participants
112 message.setParticipantDefinitionUpdates(participantDefinitionUpdates);
113 LOGGER.debug("Participant Update sent {}", message);
119 * Send ParticipantUpdate to Participant after that commissioning has been removed.
121 @Timed(value = "publisher.participant_update", description = "PARTICIPANT_UPDATE messages published")
122 public void sendDecomisioning() {
123 var message = new ParticipantUpdate();
124 message.setTimestamp(Instant.now());
125 // DeCommission the automation composition but deleting participantdefinitions on participants
126 message.setParticipantDefinitionUpdates(null);
128 LOGGER.debug("Participant Update sent {}", message);