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.ControlLoopHandler;
41 import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
42 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
44 import org.springframework.stereotype.Component;
47 * This class is api implementation used by participant intermediary.
50 public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryApi {
52 // The handler for the participant intermediary
53 private final ParticipantHandler participantHandler;
55 // The handler for the controlLoop intermediary
56 private final ControlLoopHandler controlLoopHandler;
61 * @param participantHandler ParticipantHandler
62 * @param controlLoopHandler ControlLoopHandler
64 public ParticipantIntermediaryApiImpl(ParticipantHandler participantHandler,
65 ControlLoopHandler controlLoopHandler) {
66 this.participantHandler = participantHandler;
67 this.controlLoopHandler = controlLoopHandler;
71 public void registerControlLoopElementListener(ControlLoopElementListener controlLoopElementListener) {
72 controlLoopHandler.registerControlLoopElementListener(controlLoopElementListener);
76 public List<Participant> getParticipants(String name, String version) {
77 return List.of(participantHandler.getParticipant(name, version));
81 public Map<String, ToscaProperty> getClElementDefinitionCommonProperties(ToscaConceptIdentifier clElementDef) {
82 return participantHandler.getClElementDefinitionCommonProperties(clElementDef);
86 public Participant updateParticipantState(ToscaConceptIdentifier definition, ParticipantState state) {
87 return participantHandler.updateParticipantState(definition, state);
91 public void updateParticipantStatistics(ParticipantStatistics participantStatistics) {
92 participantHandler.updateParticipantStatistics(participantStatistics);
96 public ControlLoops getControlLoops(String name, String version) {
97 return controlLoopHandler.getControlLoops();
101 public Map<UUID, ControlLoopElement> getControlLoopElements(String name, String version) {
102 List<ControlLoop> controlLoops = controlLoopHandler.getControlLoops().getControlLoopList();
104 for (ControlLoop controlLoop : controlLoops) {
105 if (name.equals(controlLoop.getDefinition().getName())) {
106 return controlLoop.getElements();
109 return new LinkedHashMap<>();
113 public ControlLoopElement getControlLoopElement(UUID id) {
114 List<ControlLoop> controlLoops = controlLoopHandler.getControlLoops().getControlLoopList();
116 for (ControlLoop controlLoop : controlLoops) {
117 ControlLoopElement clElement = controlLoop.getElements().get(id);
118 if (clElement != null) {
126 public ControlLoopElement updateControlLoopElementState(ToscaConceptIdentifier controlLoopId,
127 UUID id, ControlLoopOrderedState currentState,
128 ControlLoopState newState, ParticipantMessageType messageType) {
129 return controlLoopHandler.updateControlLoopElementState(controlLoopId,
130 id, currentState, newState);
134 public void updateControlLoopElementStatistics(UUID id, ClElementStatistics elementStatistics) {
135 controlLoopHandler.updateControlLoopElementStatistics(id, elementStatistics);