2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023-2025 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.acm.runtime.participants;
23 import java.util.List;
25 import java.util.UUID;
26 import java.util.function.Function;
27 import java.util.stream.Collectors;
28 import lombok.RequiredArgsConstructor;
29 import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantStatusReqPublisher;
30 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
31 import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState;
32 import org.onap.policy.clamp.models.acm.concepts.Participant;
33 import org.onap.policy.clamp.models.acm.concepts.ParticipantInformation;
34 import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.data.domain.Pageable;
38 import org.springframework.stereotype.Service;
39 import org.springframework.transaction.annotation.Transactional;
43 @RequiredArgsConstructor
44 public class AcmParticipantProvider {
46 private static final Logger LOGGER = LoggerFactory.getLogger(AcmParticipantProvider.class);
47 private final ParticipantProvider participantProvider;
48 private final ParticipantStatusReqPublisher participantStatusReqPublisher;
51 * Get all participants.
53 * @param pageable the Pageable
54 * @return A list of available participants
56 public List<ParticipantInformation> getAllParticipants(final Pageable pageable) {
57 var participants = this.participantProvider.getParticipants();
58 return participants.stream().map(participant -> createParticipantInformation(participant, pageable)).toList();
61 private ParticipantInformation createParticipantInformation(Participant participant, Pageable pageable) {
62 var participantInformation = new ParticipantInformation();
63 participantInformation.setParticipant(participant);
64 participantInformation.setAcElementInstanceMap(
65 getAcElementsForParticipant(participant.getParticipantId(), pageable));
66 participantInformation.setAcNodeTemplateStateDefinitionMap(
67 getNodeTemplateStatesForParticipant(participant.getParticipantId(), pageable));
68 return participantInformation;
74 * @param participantId The UUID of the participant to get
75 * @param pageable the Pageable
76 * @return The participant
78 public ParticipantInformation getParticipantById(final UUID participantId, final Pageable pageable) {
79 var participant = this.participantProvider.getParticipantById(participantId);
80 return createParticipantInformation(participant, pageable);
84 * Send a participant status request.
86 * @param participantId The UUID of the participant to send request to
88 public void sendParticipantStatusRequest(UUID participantId) {
89 // check if participant is present
90 this.participantProvider.getParticipantById(participantId);
92 LOGGER.debug("Requesting Participant Status Now ParticipantStatusReq");
93 participantStatusReqPublisher.send(participantId);
97 * Send status request to all participants.
100 public void sendAllParticipantStatusRequest() {
101 this.participantStatusReqPublisher.send((UUID) null);
104 private Map<UUID, AutomationCompositionElement> getAcElementsForParticipant(UUID participantId, Pageable pageable) {
105 var automationCompositionElements =
106 participantProvider.getAutomationCompositionElements(participantId, pageable);
107 return automationCompositionElements
108 .stream().collect(Collectors.toMap(AutomationCompositionElement::getId, Function.identity()));
111 private Map<UUID, NodeTemplateState> getNodeTemplateStatesForParticipant(UUID participantId, Pageable pageable) {
112 var acNodeTemplateStates = participantProvider.getAcNodeTemplateStates(participantId, pageable);
113 return acNodeTemplateStates
114 .stream().collect(Collectors.toMap(NodeTemplateState::getNodeTemplateStateId, Function.identity()));