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.acm.participant.simulator.simulation;
23 import java.util.List;
25 import java.util.UUID;
26 import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
27 import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException;
28 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
29 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
30 import org.onap.policy.clamp.models.acm.concepts.Participant;
31 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
32 import org.onap.policy.clamp.models.acm.messages.rest.TypedSimpleResponse;
33 import org.springframework.stereotype.Service;
36 * This provider class simulation of participants and automation composition elements.
39 public class SimulationProvider {
41 private final ParticipantIntermediaryApi intermediaryApi;
44 * Create a participant simulation provider.
46 * @param intermediaryApi the intermediary to use for talking to the CLAMP runtime
48 public SimulationProvider(ParticipantIntermediaryApi intermediaryApi) {
49 this.intermediaryApi = intermediaryApi;
53 * Get the automation compositions.
55 * @param name the automationComposition, null to get all
56 * @param version the automationComposition, null to get all
57 * @return the automation compositions
58 * @throws AutomationCompositionException on errors getting the automation compositions
60 public AutomationCompositions getAutomationCompositions(String name, String version)
61 throws AutomationCompositionException {
62 return intermediaryApi.getAutomationCompositions(name, version);
66 * Get the simulated automation composition elements.
68 * @param name the automationCompositionElement, null to get all
69 * @param version the automationCompositionElement, null to get all
70 * @return the automation composition elements
72 public Map<UUID, AutomationCompositionElement> getAutomationCompositionElements(String name, String version) {
73 return intermediaryApi.getAutomationCompositionElements(name, version);
77 * Update the given automation composition element in the simulator.
79 * @param element the automation composition element to update
80 * @return response simple response returned
82 public TypedSimpleResponse<AutomationCompositionElement> updateAutomationCompositionElement(
83 AutomationCompositionElement element) {
84 TypedSimpleResponse<AutomationCompositionElement> response = new TypedSimpleResponse<>();
85 response.setResponse(intermediaryApi.updateAutomationCompositionElementState(null, element.getId(),
86 element.getOrderedState(), element.getState(), ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE));
91 * Get the current simulated participants.
93 * @param name the participant, null to get all
94 * @param version the participant, null to get all
95 * @return the list of participants
97 public List<Participant> getParticipants(String name, String version) {
98 return intermediaryApi.getParticipants(name, version);
102 * Update a simulated participant.
104 * @param participant the participant to update
105 * @return TypedSimpleResponse simple response
107 public TypedSimpleResponse<Participant> updateParticipant(Participant participant) {
108 TypedSimpleResponse<Participant> response = new TypedSimpleResponse<>();
109 response.setResponse(
110 intermediaryApi.updateParticipantState(participant.getDefinition(), participant.getParticipantState()));