43ac3464c0e4493b20674f9a13dedf75877d7d59
[policy/clamp.git] /
1 /*-
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.clamp.controlloop.participant.intermediary.api.impl;
23
24 import java.util.LinkedHashMap;
25 import java.util.List;
26 import java.util.Map;
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;
45
46 /**
47  * This class is api implementation used by participant intermediary.
48  */
49 @Component
50 public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryApi {
51
52     // The handler for the participant intermediary
53     private final ParticipantHandler participantHandler;
54
55     // The handler for the controlLoop intermediary
56     private final ControlLoopHandler controlLoopHandler;
57
58     /**
59      * Constructor.
60      *
61      * @param participantHandler ParticipantHandler
62      * @param controlLoopHandler ControlLoopHandler
63      */
64     public ParticipantIntermediaryApiImpl(ParticipantHandler participantHandler,
65             ControlLoopHandler controlLoopHandler) {
66         this.participantHandler = participantHandler;
67         this.controlLoopHandler = controlLoopHandler;
68     }
69
70     @Override
71     public void registerControlLoopElementListener(ControlLoopElementListener controlLoopElementListener) {
72         controlLoopHandler.registerControlLoopElementListener(controlLoopElementListener);
73     }
74
75     @Override
76     public List<Participant> getParticipants(String name, String version) {
77         return List.of(participantHandler.getParticipant(name, version));
78     }
79
80     @Override
81     public Map<String, ToscaProperty> getClElementDefinitionCommonProperties(ToscaConceptIdentifier clElementDef) {
82         return participantHandler.getClElementDefinitionCommonProperties(clElementDef);
83     }
84
85     @Override
86     public Participant updateParticipantState(ToscaConceptIdentifier definition, ParticipantState state) {
87         return participantHandler.updateParticipantState(definition, state);
88     }
89
90     @Override
91     public void updateParticipantStatistics(ParticipantStatistics participantStatistics) {
92         // TODO Auto-generated method stub
93     }
94
95     @Override
96     public ControlLoops getControlLoops(String name, String version) {
97         return controlLoopHandler.getControlLoops();
98     }
99
100     @Override
101     public Map<UUID, ControlLoopElement> getControlLoopElements(String name, String version) {
102         List<ControlLoop> controlLoops = controlLoopHandler.getControlLoops().getControlLoopList();
103
104         for (ControlLoop controlLoop : controlLoops) {
105             if (name.equals(controlLoop.getDefinition().getName())) {
106                 return controlLoop.getElements();
107             }
108         }
109         return new LinkedHashMap<>();
110     }
111
112     @Override
113     public ControlLoopElement getControlLoopElement(UUID id) {
114         List<ControlLoop> controlLoops = controlLoopHandler.getControlLoops().getControlLoopList();
115
116         for (ControlLoop controlLoop : controlLoops) {
117             ControlLoopElement clElement = controlLoop.getElements().get(id);
118             if (clElement != null) {
119                 return clElement;
120             }
121         }
122         return null;
123     }
124
125     @Override
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);
131     }
132
133     @Override
134     public void updateControlLoopElementStatistics(UUID id, ClElementStatistics elementStatistics) {
135         controlLoopHandler.updateControlLoopElementStatistics(id, elementStatistics);
136     }
137 }