2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2026 OpenInfra Foundation Europe. All rights reserved.
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.models.acm.messages.kafka.participant;
23 import com.fasterxml.jackson.annotation.JsonFormat;
24 import java.time.Instant;
25 import java.util.HashSet;
27 import java.util.UUID;
28 import lombok.AccessLevel;
30 import lombok.NoArgsConstructor;
31 import lombok.NonNull;
33 import lombok.ToString;
36 * Class to represent the base class for various messages that will be exchanged between the ACM runtime and
43 public class ParticipantMessage {
44 @Setter(AccessLevel.NONE)
45 private ParticipantMessageType messageType;
47 private UUID messageId = UUID.randomUUID();
50 * Time-stamp, in milliseconds, when the message was created. Defaults to the current time.
52 @JsonFormat(shape = JsonFormat.Shape.STRING)
53 private Instant timestamp = Instant.now();
56 * Participant ID, or {@code null} for messages from participants.
58 private UUID participantId;
60 private UUID replicaId;
63 * Automation Composition ID, or {@code null} for messages to participants.
65 private UUID automationCompositionId;
67 private UUID compositionId;
69 private UUID revisionIdComposition;
70 private UUID revisionIdInstance;
73 * List of participantId that should receive the message.
75 private Set<UUID> participantIdList = new HashSet<>();
78 * Constructor for instantiating a participant message class.
80 * @param messageType the message type
82 public ParticipantMessage(final ParticipantMessageType messageType) {
83 this.messageType = messageType;
87 * Constructs the object, making a deep copy. Does <i>not</i> copy the request id or the time stamp.
89 * @param source source from which to copy
91 public ParticipantMessage(final ParticipantMessage source) {
92 this.messageId = source.messageId;
93 this.timestamp = source.timestamp;
94 this.messageType = source.messageType;
95 this.participantId = source.participantId;
96 this.replicaId = source.replicaId;
97 this.automationCompositionId = source.automationCompositionId;
98 this.compositionId = source.compositionId;
99 this.revisionIdComposition = source.revisionIdComposition;
100 this.revisionIdInstance = source.revisionIdInstance;
101 this.participantIdList = new HashSet<>(source.participantIdList);
105 * Determines if this message applies to this participant type.
107 * @param refParticipantId id of the participant from properties file to match against
108 * @param refReplicaId id of the replica from properties file to match against
109 * @return {@code true} if this message applies to this participant, {@code false} otherwise
111 public boolean appliesTo(@NonNull final UUID refParticipantId, @NonNull final UUID refReplicaId) {
112 // Broadcast message to specific list of participants
113 // or all participants when participantIdList is empty
114 // filter backward compatible with old ACM-r
115 if (participantIdList != null && !participantIdList.isEmpty()
116 && !participantIdList.contains(refParticipantId)) {
119 // Broadcast message to all participants and all replicas or specific participant and all replicas,
120 // filter backward compatible with old ACM-r
121 if ((this.participantId == null)
122 || (refParticipantId.equals(this.participantId) && this.replicaId == null)) {
125 // Targeted message at a specific participant and replica
126 return refReplicaId.equals(this.replicaId);