2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2025 OpenInfra Foundation Europe. All rights reserved.
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 jakarta.ws.rs.core.Response.Status;
26 import java.util.List;
28 import org.onap.policy.clamp.acm.participant.intermediary.handler.Publisher;
29 import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
30 import org.onap.policy.clamp.models.acm.messages.kafka.participant.AutomationCompositionDeployAck;
31 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantDeregister;
32 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantPrimeAck;
33 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantRegister;
34 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantReqSync;
35 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatus;
36 import org.onap.policy.common.message.bus.event.TopicSink;
37 import org.onap.policy.common.message.bus.event.client.TopicSinkClient;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.springframework.stereotype.Component;
43 * This class is used to send Participant Status messages to clamp using TopicSinkClient.
47 public class ParticipantMessagePublisher implements Publisher {
48 private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantMessagePublisher.class);
49 private static final String NOT_ACTIVE_TEXT = "Not Active!";
52 private boolean active = false;
53 private TopicSinkClient topicSinkClient;
56 * Constructor for instantiating ParticipantMessagePublisher.
58 * @param topicSinks the topic sinks
61 public void active(List<TopicSink> topicSinks) {
62 if (topicSinks.size() != 1) {
63 throw new IllegalArgumentException("Configuration unsupported, Topic sinks greater than 1");
65 this.topicSinkClient = new TopicSinkClient(topicSinks.get(0));
70 * Method to send Participant Request Sync message to clamp.
72 * @param participantReqSync the Participant Request Sync
74 @Timed(value = "publisher.participant_req_sync", description = "PARTICIPANT_REQ_SYNC_MSG messages published")
75 public void sendParticipantReqSync(final ParticipantReqSync participantReqSync) {
77 topicSinkClient.send(participantReqSync);
78 LOGGER.info("Sent Participant Request Sync to CLAMP - {}", participantReqSync);
82 * Method to send Participant Status message to clamp on demand.
84 * @param participantStatus the Participant Status
86 @Timed(value = "publisher.participant_status", description = "PARTICIPANT_STATUS messages published")
87 public void sendParticipantStatus(final ParticipantStatus participantStatus) {
89 topicSinkClient.send(participantStatus);
90 LOGGER.info("Sent Participant Status message to CLAMP - {}", participantStatus);
94 * Method to send Participant Status message to clamp on demand.
96 * @param participantRegister the Participant Status
98 @Timed(value = "publisher.participant_register", description = "PARTICIPANT_REGISTER messages published")
99 public void sendParticipantRegister(final ParticipantRegister participantRegister) {
101 topicSinkClient.send(participantRegister);
102 LOGGER.info("Sent Participant Register message to CLAMP - {}", participantRegister);
106 * Method to send Participant Status message to clamp on demand.
108 * @param participantDeregister the Participant Status
110 @Timed(value = "publisher.participant_deregister", description = "PARTICIPANT_DEREGISTER messages published")
111 public void sendParticipantDeregister(final ParticipantDeregister participantDeregister) {
113 topicSinkClient.send(participantDeregister);
114 LOGGER.debug("Sent Participant Deregister message to CLAMP - {}", participantDeregister);
118 * Method to send Participant Prime Ack message to runtime.
120 * @param participantPrimeAck the Participant Prime Ack
122 @Timed(value = "publisher.participant_prime_ack", description = "PARTICIPANT_PRIME_ACK messages published")
123 public void sendParticipantPrimeAck(final ParticipantPrimeAck participantPrimeAck) {
125 topicSinkClient.send(participantPrimeAck);
126 LOGGER.debug("Sent Participant Prime Ack message to CLAMP - {}", participantPrimeAck);
130 * Method to send AutomationComposition Update/StateChange Ack message to runtime.
132 * @param automationCompositionAck AutomationComposition Update/StateChange Ack
134 @Timed(value = "publisher.automation_composition_update_ack",
135 description = "AUTOMATION_COMPOSITION_UPDATE_ACK/AUTOMATION_COMPOSITION_STATECHANGE_ACK messages published")
136 public void sendAutomationCompositionAck(final AutomationCompositionDeployAck automationCompositionAck) {
138 topicSinkClient.send(automationCompositionAck);
139 LOGGER.debug("Sent AutomationComposition Update/StateChange Ack to runtime - {}", automationCompositionAck);
142 private void validate() {
144 throw new AutomationCompositionRuntimeException(Status.NOT_ACCEPTABLE, NOT_ACTIVE_TEXT);