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.api.impl;
24 import java.util.LinkedHashMap;
25 import java.util.List;
27 import java.util.UUID;
28 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics;
29 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
30 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
31 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
32 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
33 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
34 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
35 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
36 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics;
37 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType;
38 import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener;
39 import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
40 import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
41 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
42 import org.springframework.stereotype.Component;
45 * This class is api implementation used by participant intermediary.
48 public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryApi {
50 // The handler for the participant intermediary
51 private ParticipantHandler participantHandler;
56 * @param participantHandler ParticipantHandler
58 public ParticipantIntermediaryApiImpl(ParticipantHandler participantHandler) {
59 this.participantHandler = participantHandler;
63 public void registerControlLoopElementListener(ControlLoopElementListener controlLoopElementListener) {
64 participantHandler.getControlLoopHandler().registerControlLoopElementListener(controlLoopElementListener);
68 public void sendParticipantRegister() {
69 participantHandler.sendParticipantRegister();
73 public void sendParticipantDeregister() {
74 participantHandler.sendParticipantDeregister();
78 public List<Participant> getParticipants(String name, String version) {
79 return List.of(participantHandler.getParticipant(name, version));
83 public Participant updateParticipantState(ToscaConceptIdentifier definition, ParticipantState state) {
84 return participantHandler.updateParticipantState(definition, state);
88 public void updateParticipantStatistics(ParticipantStatistics participantStatistics) {
89 // TODO Auto-generated method stub
93 public ControlLoops getControlLoops(String name, String version) {
94 return participantHandler.getControlLoopHandler().getControlLoops();
98 public Map<UUID, ControlLoopElement> getControlLoopElements(String name, String version) {
99 List<ControlLoop> controlLoops =
100 participantHandler.getControlLoopHandler().getControlLoops().getControlLoopList();
102 for (ControlLoop controlLoop : controlLoops) {
103 if (name.equals(controlLoop.getDefinition().getName())) {
104 return controlLoop.getElements();
107 return new LinkedHashMap<>();
111 public ControlLoopElement getControlLoopElement(UUID id) {
112 List<ControlLoop> controlLoops =
113 participantHandler.getControlLoopHandler().getControlLoops().getControlLoopList();
115 for (ControlLoop controlLoop : controlLoops) {
116 ControlLoopElement clElement = controlLoop.getElements().get(id);
117 if (clElement != null) {
125 public ControlLoopElement updateControlLoopElementState(UUID id, ControlLoopOrderedState currentState,
126 ControlLoopState newState, ParticipantMessageType messageType) {
127 return participantHandler.getControlLoopHandler().updateControlLoopElementState(id, currentState, newState);
131 public void updateControlLoopElementStatistics(UUID id, ClElementStatistics elementStatistics) {
132 participantHandler.getControlLoopHandler().updateControlLoopElementStatistics(id, elementStatistics);