2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 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.controlloop.runtime.supervision.comm;
23 import java.time.Instant;
24 import java.util.LinkedHashMap;
26 import java.util.UUID;
27 import lombok.AllArgsConstructor;
28 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
29 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
30 import org.onap.policy.clamp.controlloop.runtime.commissioning.CommissioningProvider;
31 import org.onap.policy.models.base.PfModelException;
32 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.stereotype.Component;
38 * This class is used to send ParticipantUpdate messages to participants on DMaaP.
42 public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<ParticipantUpdate> {
44 private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantUpdatePublisher.class);
46 private final CommissioningProvider commissioningProvider;
49 * Send ParticipantUpdate to Participant.
51 * @param participantId the participant Id
52 * @param participantType the participant Type
54 public void send(ToscaConceptIdentifier participantId, ToscaConceptIdentifier participantType) {
55 var message = new ParticipantUpdate();
56 message.setParticipantId(participantId);
57 message.setParticipantType(participantType);
58 message.setTimestamp(Instant.now());
60 var clDefinition = new ControlLoopElementDefinition();
61 clDefinition.setId(UUID.randomUUID());
64 clDefinition.setControlLoopElementToscaServiceTemplate(
65 commissioningProvider.getToscaServiceTemplate(null, null));
66 } catch (PfModelException pfme) {
67 LOGGER.warn("Get of tosca service template failed, cannot send participantupdate", pfme);
71 Map<UUID, ControlLoopElementDefinition> controlLoopElementDefinitionMap = new LinkedHashMap<>();
72 controlLoopElementDefinitionMap.put(UUID.randomUUID(), clDefinition);
74 Map<String, Map<UUID, ControlLoopElementDefinition>> participantDefinitionUpdateMap = new LinkedHashMap<>();
75 participantDefinitionUpdateMap.put(participantId.toString(), controlLoopElementDefinitionMap);
76 message.setParticipantDefinitionUpdateMap(participantDefinitionUpdateMap);
78 LOGGER.debug("Participant Update sent {}", message);