2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2023 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.acm.participant.intermediary.comm;
24 import io.micrometer.core.annotation.Timed;
25 import java.util.List;
26 import javax.ws.rs.core.Response.Status;
27 import org.onap.policy.clamp.acm.participant.intermediary.handler.Publisher;
28 import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
29 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck;
30 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister;
31 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck;
32 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
33 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
34 import org.onap.policy.common.endpoints.event.comm.TopicSink;
35 import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClient;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38 import org.springframework.stereotype.Component;
41 * This class is used to send Participant Status messages to clamp using TopicSinkClient.
45 public class ParticipantMessagePublisher implements Publisher {
46 private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantMessagePublisher.class);
47 private static final String NOT_ACTIVE_TEXT = "Not Active!";
49 private boolean active = false;
50 private TopicSinkClient topicSinkClient;
53 * Constructor for instantiating ParticipantMessagePublisher.
55 * @param topicSinks the topic sinks
58 public void active(List<TopicSink> topicSinks) {
59 if (topicSinks.size() != 1) {
60 throw new IllegalArgumentException("Configuration unsupported, Topic sinks greater than 1");
62 this.topicSinkClient = new TopicSinkClient(topicSinks.get(0));
67 * Method to send Participant Status message to clamp on demand.
69 * @param participantStatus the Participant Status
71 @Timed(value = "publisher.participant_status", description = "PARTICIPANT_STATUS messages published")
72 public void sendParticipantStatus(final ParticipantStatus participantStatus) {
74 topicSinkClient.send(participantStatus);
75 LOGGER.info("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 @Timed(value = "publisher.participant_register", description = "PARTICIPANT_REGISTER messages published")
84 public void sendParticipantRegister(final ParticipantRegister participantRegister) {
86 topicSinkClient.send(participantRegister);
87 LOGGER.info("Sent Participant Register message to CLAMP - {}", participantRegister);
91 * Method to send Participant Status message to clamp on demand.
93 * @param participantDeregister the Participant Status
95 @Timed(value = "publisher.participant_deregister", description = "PARTICIPANT_DEREGISTER messages published")
96 public void sendParticipantDeregister(final ParticipantDeregister participantDeregister) {
98 topicSinkClient.send(participantDeregister);
99 LOGGER.debug("Sent Participant Deregister message to CLAMP - {}", participantDeregister);
103 * Method to send Participant Prime Ack message to runtime.
105 * @param participantPrimeAck the Participant Prime Ack
107 @Timed(value = "publisher.participant_prime_ack", description = "PARTICIPANT_PRIME_ACK messages published")
108 public void sendParticipantPrimeAck(final ParticipantPrimeAck participantPrimeAck) {
110 topicSinkClient.send(participantPrimeAck);
111 LOGGER.debug("Sent Participant Prime Ack message to CLAMP - {}", participantPrimeAck);
115 * Method to send AutomationComposition Update/StateChange Ack message to runtime.
117 * @param automationCompositionAck AutomationComposition Update/StateChange Ack
119 @Timed(value = "publisher.automation_composition_update_ack",
120 description = "AUTOMATION_COMPOSITION_UPDATE_ACK/AUTOMATION_COMPOSITION_STATECHANGE_ACK messages published")
121 public void sendAutomationCompositionAck(final AutomationCompositionDeployAck automationCompositionAck) {
123 topicSinkClient.send(automationCompositionAck);
124 LOGGER.debug("Sent AutomationComposition Update/StateChange Ack to runtime - {}", automationCompositionAck);
128 * Method to send Participant heartbeat to clamp on demand.
130 * @param participantStatus the Participant Status
132 @Timed(value = "publisher.participant_status", description = "PARTICIPANT_STATUS messages published")
133 public void sendHeartbeat(final ParticipantStatus participantStatus) {
135 topicSinkClient.send(participantStatus);
136 LOGGER.debug("Sent Participant heartbeat to CLAMP - {}", participantStatus);
139 private void validate() {
141 throw new AutomationCompositionRuntimeException(Status.NOT_ACCEPTABLE, NOT_ACTIVE_TEXT);