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.simulation;
23 import java.util.List;
25 import java.util.UUID;
26 import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
27 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
28 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
29 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
30 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType;
31 import org.onap.policy.clamp.controlloop.models.messages.rest.TypedSimpleResponse;
32 import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
33 import org.springframework.stereotype.Service;
36 * This provider class simulation of participants and control loop elements.
39 public class SimulationProvider {
41 private final ParticipantIntermediaryApi intermediaryApi;
44 * Create a participant simulation provider.
45 * @param intermediaryApi the intermediary to use for talking to the CLAMP runtime
47 public SimulationProvider(ParticipantIntermediaryApi intermediaryApi) {
48 this.intermediaryApi = intermediaryApi;
52 * Get the control loops.
54 * @param name the controlLoop, null to get all
55 * @param version the controlLoop, null to get all
56 * @return the control loops
57 * @throws ControlLoopException on errors getting the control loops
59 public ControlLoops getControlLoops(String name, String version) throws ControlLoopException {
60 return intermediaryApi.getControlLoops(name, version);
64 * Get the simulated control loop elements.
66 * @param name the controlLoopElement, null to get all
67 * @param version the controlLoopElement, null to get all
68 * @return the control loop elements
70 public Map<UUID, ControlLoopElement> getControlLoopElements(String name, String version) {
71 return intermediaryApi.getControlLoopElements(name, version);
75 * Update the given control loop element in the simulator.
77 * @param element the control loop element to update
78 * @return response simple response returned
80 public TypedSimpleResponse<ControlLoopElement> updateControlLoopElement(ControlLoopElement element) {
81 TypedSimpleResponse<ControlLoopElement> response = new TypedSimpleResponse<>();
82 response.setResponse(intermediaryApi.updateControlLoopElementState(element.getId(), element.getOrderedState(),
83 element.getState(), ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE));
88 * Get the current simulated participants.
90 * @param name the participant, null to get all
91 * @param version the participant, null to get all
92 * @return the list of participants
94 public List<Participant> getParticipants(String name, String version) {
95 return intermediaryApi.getParticipants(name, version);
99 * Update a simulated participant.
101 * @param participant the participant to update
102 * @return TypedSimpleResponse simple response
104 public TypedSimpleResponse<Participant> updateParticipant(Participant participant) {
105 TypedSimpleResponse<Participant> response = new TypedSimpleResponse<>();
106 response.setResponse(
107 intermediaryApi.updateParticipantState(participant.getDefinition(), participant.getParticipantState()));