2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 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.controlloop.runtime.supervision.comm;
25 import java.time.Instant;
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.UUID;
29 import lombok.AllArgsConstructor;
30 import org.onap.policy.clamp.controlloop.common.utils.CommonUtils;
31 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
32 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
33 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantUpdates;
34 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate;
35 import org.onap.policy.models.base.PfModelException;
36 import org.onap.policy.models.provider.PolicyModelsProvider;
37 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.springframework.stereotype.Component;
43 * This class is used to send ControlLoopUpdate messages to participants on DMaaP.
47 public class ControlLoopUpdatePublisher extends AbstractParticipantPublisher<ControlLoopUpdate> {
49 private static final Logger LOGGER = LoggerFactory.getLogger(ControlLoopUpdatePublisher.class);
50 private final PolicyModelsProvider modelsProvider;
53 * Send ControlLoopUpdate to Participant.
55 * @param controlLoop the ControlLoop
57 public void send(ControlLoop controlLoop) {
62 * Send ControlLoopUpdate to Participant.
64 * @param controlLoop the ControlLoop
65 * @param startPhase the Start Phase
67 public void send(ControlLoop controlLoop, int startPhase) {
68 var controlLoopUpdateMsg = new ControlLoopUpdate();
69 controlLoopUpdateMsg.setStartPhase(startPhase);
70 controlLoopUpdateMsg.setControlLoopId(controlLoop.getKey().asIdentifier());
71 controlLoopUpdateMsg.setMessageId(UUID.randomUUID());
72 controlLoopUpdateMsg.setTimestamp(Instant.now());
73 ToscaServiceTemplate toscaServiceTemplate;
75 toscaServiceTemplate = modelsProvider.getServiceTemplateList(null, null).get(0);
76 } catch (PfModelException pfme) {
77 LOGGER.warn("Get of tosca service template failed, cannot send participantupdate", pfme);
81 List<ParticipantUpdates> participantUpdates = new ArrayList<>();
82 for (ControlLoopElement element : controlLoop.getElements().values()) {
83 CommonUtils.setServiceTemplatePolicyInfo(element, toscaServiceTemplate);
84 CommonUtils.prepareParticipantUpdate(element, participantUpdates);
86 controlLoopUpdateMsg.setParticipantUpdatesList(participantUpdates);
88 LOGGER.debug("ControlLoopUpdate message sent {}", controlLoopUpdateMsg);
89 super.send(controlLoopUpdateMsg);