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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.controlloop.participant.simulator.main.handler;
23 import java.time.Instant;
24 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.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.messages.dmaap.participant.ParticipantMessageType;
31 import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener;
32 import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
33 import org.onap.policy.models.base.PfModelException;
34 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
35 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38 import org.springframework.stereotype.Component;
41 * This class handles implementation of controlLoopElement updates.
44 public class ControlLoopElementHandler implements ControlLoopElementListener {
46 private static final Logger LOGGER = LoggerFactory.getLogger(ControlLoopElementHandler.class);
49 private ParticipantIntermediaryApi intermediaryApi;
52 * Callback method to handle a control loop element state change.
54 * @param controlLoopElementId the ID of the control loop element
55 * @param currentState the current state of the control loop element
56 * @param newState the state to which the control loop element is changing to
57 * @throws PfModelException in case of an exception
60 public void controlLoopElementStateChange(ToscaConceptIdentifier controlLoopId,
61 UUID controlLoopElementId, ControlLoopState currentState,
62 ControlLoopOrderedState newState) throws PfModelException {
65 intermediaryApi.updateControlLoopElementState(controlLoopId,
66 controlLoopElementId, newState, ControlLoopState.UNINITIALISED,
67 ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
70 intermediaryApi.updateControlLoopElementState(controlLoopId,
71 controlLoopElementId, newState, ControlLoopState.PASSIVE,
72 ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
75 intermediaryApi.updateControlLoopElementState(controlLoopId,
76 controlLoopElementId, newState, ControlLoopState.RUNNING,
77 ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
80 LOGGER.debug("Unknown orderedstate {}", newState);
86 * Callback method to handle an update on a control loop element.
88 * @param element the information on the control loop element
89 * @param clElementDefinition toscaNodeTemplate
90 * @throws PfModelException in case of an exception
93 public void controlLoopElementUpdate(ToscaConceptIdentifier controlLoopId, ControlLoopElement element,
94 ToscaNodeTemplate clElementDefinition)
95 throws PfModelException {
96 intermediaryApi.updateControlLoopElementState(controlLoopId, element.getId(), element.getOrderedState(),
97 ControlLoopState.PASSIVE, ParticipantMessageType.CONTROL_LOOP_UPDATE);
101 public void handleStatistics(UUID controlLoopElementId) throws PfModelException {
102 var clElement = intermediaryApi.getControlLoopElement(controlLoopElementId);
103 if (clElement != null) {
104 var clElementStatistics = new ClElementStatistics();
105 clElementStatistics.setControlLoopState(clElement.getState());
106 clElementStatistics.setTimeStamp(Instant.now());
107 intermediaryApi.updateControlLoopElementStatistics(controlLoopElementId, clElementStatistics);