0702868dd412007b8b3cd16f5d76f4d3c0c27189
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation.
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.clamp.controlloop.participant.intermediary.api.impl;
22
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.UUID;
26 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics;
27 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
28 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
29 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
30 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
31 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
32 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
33 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics;
34 import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener;
35 import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
36 import org.onap.policy.clamp.controlloop.participant.intermediary.handler.IntermediaryActivator;
37 import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
38 import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
39 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
40
41 /**
42  * This class is api implementation used by participant intermediary.
43  */
44 public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryApi {
45
46     // The activator for the participant intermediary
47     private IntermediaryActivator activator;
48
49     @Override
50     public void init(ParticipantIntermediaryParameters parameters) {
51         activator = new IntermediaryActivator(parameters);
52
53         activator.start();
54     }
55
56     @Override
57     public void close() {
58         activator.shutdown();
59     }
60
61     @Override
62     public void registerControlLoopElementListener(ControlLoopElementListener controlLoopElementListener) {
63         activator.getParticipantHandler().getControlLoopHandler()
64                 .registerControlLoopElementListener(controlLoopElementListener);
65     }
66
67     @Override
68     public List<Participant> getParticipants(String name, String version) {
69         return List.of(activator.getParticipantHandler().getParticipant(name, version));
70     }
71
72     @Override
73     public Participant updateParticipantState(ToscaConceptIdentifier definition, ParticipantState state) {
74         return activator.getParticipantHandler().updateParticipantState(definition, state);
75     }
76
77     @Override
78     public void updateParticipantStatistics(ParticipantStatistics participantStatistics) {
79         // TODO Auto-generated method stub
80     }
81
82     @Override
83     public ControlLoops getControlLoops(String name, String version) {
84         return activator.getParticipantHandler().getControlLoopHandler().getControlLoops();
85     }
86
87     @Override
88     public List<ControlLoopElement> getControlLoopElements(String name, String version) {
89         List<ControlLoop> controlLoops = activator.getParticipantHandler()
90                 .getControlLoopHandler().getControlLoops().getControlLoopList();
91
92         for (ControlLoop controlLoop : controlLoops) {
93             if (controlLoop.getDefinition().getName().equals(name)) {
94                 return controlLoop.getElements();
95             }
96         }
97         return Collections.emptyList();
98     }
99
100     @Override
101     public ControlLoop updateControlLoopState(ToscaConceptIdentifier definition, ControlLoopOrderedState state) {
102         return activator.getParticipantHandler().getControlLoopHandler()
103                 .updateControlLoopState(definition, state);
104     }
105
106     @Override
107     public ControlLoopElement updateControlLoopElementState(UUID id, ControlLoopOrderedState state) {
108         return activator.getParticipantHandler().getControlLoopHandler()
109                 .updateControlLoopElementState(id, state);
110     }
111
112     @Override
113     public void updateControlLoopElementStatistics(ClElementStatistics elementStatistics) {
114         activator.getParticipantHandler().getControlLoopHandler()
115         .updateControlLoopElementStatistics(elementStatistics);
116     }
117
118     @Override
119     public ParticipantHandler getParticipantHandler() {
120         return activator.getParticipantHandler();
121     }
122 }