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;
29 import java.util.UUID;
30 import lombok.AllArgsConstructor;
31 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
32 import org.onap.policy.clamp.models.acm.concepts.ParticipantUpdates;
33 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionUpdate;
34 import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
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;
41 * This class is used to send AutomationCompositionUpdate messages to participants on DMaaP.
45 public class AutomationCompositionUpdatePublisher extends AbstractParticipantPublisher<AutomationCompositionUpdate> {
47 private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionUpdatePublisher.class);
48 private final AcDefinitionProvider acDefinitionProvider;
51 * Send AutomationCompositionUpdate to Participant.
53 * @param automationComposition the AutomationComposition
55 @Timed(value = "publisher.automation_composition_update",
56 description = "AUTOMATION_COMPOSITION_UPDATE messages published")
57 public void send(AutomationComposition automationComposition) {
58 send(automationComposition, 0);
62 * Send AutomationCompositionUpdate to Participant.
64 * @param automationComposition the AutomationComposition
65 * @param startPhase the Start Phase
67 @Timed(value = "publisher.automation_composition_update",
68 description = "AUTOMATION_COMPOSITION_UPDATE messages published")
69 public void send(AutomationComposition automationComposition, int startPhase) {
70 var automationCompositionUpdateMsg = new AutomationCompositionUpdate();
71 automationCompositionUpdateMsg.setCompositionId(automationComposition.getCompositionId());
72 automationCompositionUpdateMsg.setStartPhase(startPhase);
73 automationCompositionUpdateMsg.setAutomationCompositionId(automationComposition.getInstanceId());
74 automationCompositionUpdateMsg.setMessageId(UUID.randomUUID());
75 automationCompositionUpdateMsg.setTimestamp(Instant.now());
76 var toscaServiceTemplate = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId());
78 List<ParticipantUpdates> participantUpdates = new ArrayList<>();
79 for (var element : automationComposition.getElements().values()) {
80 AcmUtils.setAcPolicyInfo(element, toscaServiceTemplate);
81 AcmUtils.prepareParticipantUpdate(element, participantUpdates);
83 automationCompositionUpdateMsg.setParticipantUpdatesList(participantUpdates);
85 LOGGER.debug("AutomationCompositionUpdate message sent {}", automationCompositionUpdateMsg);
86 super.send(automationCompositionUpdateMsg);