9e494862eb2294d1c10f8f00c4758fbb3bb8bf6e
[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.ParticipantIntermediaryApi;
35 import org.onap.policy.clamp.controlloop.participant.intermediary.handler.IntermediaryActivator;
36 import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
37 import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
38 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
39
40 /**
41  * This class is api implementation used by participant intermediary.
42  */
43 public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryApi {
44
45     // The activator for the participant intermediary
46     private IntermediaryActivator activator;
47
48     @Override
49     public void init(ParticipantIntermediaryParameters parameters) {
50         activator = new IntermediaryActivator(parameters);
51
52         activator.start();
53     }
54
55     @Override
56     public void close() {
57         activator.shutdown();
58     }
59
60     @Override
61     public List<Participant> getParticipants(String name, String version) {
62         return List.of(activator.getParticipantHandler().getParticipant(name, version));
63     }
64
65     @Override
66     public Participant updateParticipantState(ToscaConceptIdentifier definition, ParticipantState state) {
67         return activator.getParticipantHandler().updateParticipantState(definition, state);
68     }
69
70     @Override
71     public void updateParticipantStatistics(ParticipantStatistics participantStatistics) {
72         // TODO Auto-generated method stub
73     }
74
75     @Override
76     public ControlLoops getControlLoops(String name, String version) {
77         return activator.getParticipantHandler().getControlLoopHandler().getControlLoops();
78     }
79
80     @Override
81     public List<ControlLoopElement> getControlLoopElements(String name, String version) {
82         List<ControlLoop> controlLoops = activator.getParticipantHandler()
83                 .getControlLoopHandler().getControlLoops().getControlLoopList();
84
85         for (ControlLoop controlLoop : controlLoops) {
86             if (controlLoop.getDefinition().getName().equals(name)) {
87                 return controlLoop.getElements();
88             }
89         }
90         return Collections.emptyList();
91     }
92
93     @Override
94     public ControlLoop updateControlLoopState(ToscaConceptIdentifier definition, ControlLoopOrderedState state) {
95         return activator.getParticipantHandler().getControlLoopHandler()
96                 .updateControlLoopState(definition, state);
97     }
98
99     @Override
100     public ControlLoopElement updateControlLoopElementState(UUID id, ControlLoopOrderedState state) {
101         return activator.getParticipantHandler().getControlLoopHandler()
102                 .updateControlLoopElementState(id, state);
103     }
104
105     @Override
106     public void updateControlLoopElementStatistics(ClElementStatistics elementStatistics) {
107         activator.getParticipantHandler().getControlLoopHandler()
108         .updateControlLoopElementStatistics(elementStatistics);
109     }
110
111     @Override
112     public ParticipantHandler getParticipantHandler() {
113         return activator.getParticipantHandler();
114     }
115 }