2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.clamp.controlloop.participant.intermediary.comm;
24 import java.util.List;
25 import javax.ws.rs.core.Response.Status;
26 import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
27 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopAck;
28 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregister;
29 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegister;
30 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus;
31 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdateAck;
32 import org.onap.policy.clamp.controlloop.participant.intermediary.handler.Publisher;
33 import org.onap.policy.common.endpoints.event.comm.TopicSink;
34 import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClient;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.stereotype.Component;
40 * This class is used to send Participant Status messages to clamp using TopicSinkClient.
44 public class ParticipantMessagePublisher implements Publisher {
45 private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantMessagePublisher.class);
46 private static final String NOT_ACTIVE_TEXT = "Not Active!";
48 private boolean active = false;
49 private TopicSinkClient topicSinkClient;
52 * Constructor for instantiating ParticipantMessagePublisher.
54 * @param topicSinks the topic sinks
57 public void active(List<TopicSink> topicSinks) {
58 if (topicSinks.size() != 1) {
59 throw new IllegalArgumentException("Configuration unsupported, Topic sinks greater than 1");
61 this.topicSinkClient = new TopicSinkClient(topicSinks.get(0));
66 * Method to send Participant Status message to clamp on demand.
68 * @param participantStatus the Participant Status
70 public void sendParticipantStatus(final ParticipantStatus participantStatus) {
72 throw new ControlLoopRuntimeException(Status.NOT_ACCEPTABLE, NOT_ACTIVE_TEXT);
74 topicSinkClient.send(participantStatus);
75 LOGGER.debug("Sent Participant Status message to CLAMP - {}", participantStatus);
79 * Method to send Participant Status message to clamp on demand.
81 * @param participantRegister the Participant Status
83 public void sendParticipantRegister(final ParticipantRegister participantRegister) {
85 throw new ControlLoopRuntimeException(Status.NOT_ACCEPTABLE, NOT_ACTIVE_TEXT);
87 topicSinkClient.send(participantRegister);
88 LOGGER.debug("Sent Participant Register message to CLAMP - {}", participantRegister);
92 * Method to send Participant Status message to clamp on demand.
94 * @param participantDeregister the Participant Status
96 public void sendParticipantDeregister(final ParticipantDeregister participantDeregister) {
98 throw new ControlLoopRuntimeException(Status.NOT_ACCEPTABLE, NOT_ACTIVE_TEXT);
100 topicSinkClient.send(participantDeregister);
101 LOGGER.debug("Sent Participant Deregister message to CLAMP - {}", participantDeregister);
105 * Method to send Participant Update Ack message to runtime.
107 * @param participantUpdateAck the Participant Update Ack
109 public void sendParticipantUpdateAck(final ParticipantUpdateAck participantUpdateAck) {
111 throw new ControlLoopRuntimeException(Status.NOT_ACCEPTABLE, NOT_ACTIVE_TEXT);
113 topicSinkClient.send(participantUpdateAck);
114 LOGGER.debug("Sent Participant Update Ack message to CLAMP - {}", participantUpdateAck);
118 * Method to send ControlLoop Update/StateChange Ack message to runtime.
120 * @param controlLoopAck ControlLoop Update/StateChange Ack
122 public void sendControlLoopAck(final ControlLoopAck controlLoopAck) {
124 throw new ControlLoopRuntimeException(Status.NOT_ACCEPTABLE, NOT_ACTIVE_TEXT);
126 topicSinkClient.send(controlLoopAck);
127 LOGGER.debug("Sent ControlLoop Update/StateChange Ack to runtime - {}", controlLoopAck);
131 * Method to send Participant heartbeat to clamp on demand.
133 * @param participantStatus the Participant Status
135 public void sendHeartbeat(final ParticipantStatus participantStatus) {
137 throw new ControlLoopRuntimeException(Status.NOT_ACCEPTABLE, NOT_ACTIVE_TEXT);
139 topicSinkClient.send(participantStatus);
140 LOGGER.debug("Sent Participant heartbeat to CLAMP - {}", participantStatus);