86f2817c5757b1b4ff78ede52368def38e7d186d
[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.policy.main.handler;
22
23 import java.util.List;
24 import java.util.UUID;
25 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics;
26 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
27 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
28 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
29 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
30 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
31 import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener;
32 import org.onap.policy.models.base.PfModelException;
33 import org.onap.policy.models.pdp.concepts.PdpStatistics;
34 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
35
36 /**
37  * This class handles implementation of controlLoopElement updates.
38  */
39 public class ControlLoopElementHandler implements ControlLoopElementListener {
40
41     /**
42      * Callback method to handle a control loop element state change.
43      *
44      * @param controlLoopElementId the ID of the control loop element
45      * @param currentState the current state of the control loop element
46      * @param newState the state to which the control loop element is changing to
47     */
48     @Override
49     public void controlLoopElementStateChange(UUID controlLoopElementId, ControlLoopState currentState,
50             ControlLoopOrderedState newState) {
51     }
52
53     /**
54      * Callback method to handle an update on a control loop element.
55      *
56      * @param element the information on the control loop element
57      * @param controlLoopDefinition toscaServiceTemplate
58      * @throws PfModelException in case of an exception
59      */
60     @Override
61     public void controlLoopElementUpdate(ControlLoopElement element,
62             ToscaServiceTemplate controlLoopDefinition) throws PfModelException {
63         if (controlLoopDefinition.getPolicyTypes() != null) {
64             PolicyHandler.getInstance().getDatabaseProvider().createPolicyTypes(controlLoopDefinition);
65         }
66         if (controlLoopDefinition.getToscaTopologyTemplate().getPolicies() != null) {
67             PolicyHandler.getInstance().getDatabaseProvider().createPolicies(controlLoopDefinition);
68         }
69     }
70 }