2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023 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.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
29 import java.util.UUID;
30 import lombok.AllArgsConstructor;
31 import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
32 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
33 import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy;
34 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.PropertiesUpdate;
35 import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
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 PropertiesUpdate messages to participants.
46 public class AcElementPropertiesPublisher extends AbstractParticipantPublisher<PropertiesUpdate> {
48 private static final Logger LOGGER = LoggerFactory.getLogger(AcElementPropertiesPublisher.class);
51 * Send ACElementPropertiesUpdate to Participant.
53 * @param automationComposition the AutomationComposition
55 @Timed(value = "publisher.properties_update",
56 description = "AC Element Properties Update published")
57 public void send(AutomationComposition automationComposition) {
58 Map<UUID, List<AcElementDeploy>> map = new HashMap<>();
59 for (var element : automationComposition.getElements().values()) {
60 var acElementDeploy = AcmUtils.createAcElementDeploy(element, DeployOrder.UPDATE);
61 map.putIfAbsent(element.getParticipantId(), new ArrayList<>());
62 map.get(element.getParticipantId()).add(acElementDeploy);
64 List<ParticipantDeploy> participantDeploys = new ArrayList<>();
65 for (var entry : map.entrySet()) {
66 var participantDeploy = new ParticipantDeploy();
67 participantDeploy.setParticipantId(entry.getKey());
68 participantDeploy.setAcElementList(entry.getValue());
69 participantDeploys.add(participantDeploy);
72 var propertiesUpdate = new PropertiesUpdate();
73 propertiesUpdate.setCompositionId(automationComposition.getCompositionId());
74 propertiesUpdate.setAutomationCompositionId(automationComposition.getInstanceId());
75 propertiesUpdate.setMessageId(UUID.randomUUID());
76 propertiesUpdate.setTimestamp(Instant.now());
77 propertiesUpdate.setParticipantUpdatesList(participantDeploys);
79 LOGGER.debug("AC Element properties update sent {}", propertiesUpdate);
80 super.send(propertiesUpdate);