2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.clamp.acm.participant.intermediary.api.impl;
24 import java.util.LinkedHashMap;
25 import java.util.List;
27 import java.util.UUID;
28 import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
29 import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
30 import org.onap.policy.clamp.acm.participant.intermediary.handler.AutomationCompositionHandler;
31 import org.onap.policy.clamp.acm.participant.intermediary.handler.ParticipantHandler;
32 import org.onap.policy.clamp.models.acm.concepts.AcElementStatistics;
33 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
34 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
35 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
36 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
37 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
38 import org.onap.policy.clamp.models.acm.concepts.Participant;
39 import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
40 import org.onap.policy.clamp.models.acm.concepts.ParticipantStatistics;
41 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
42 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
44 import org.springframework.stereotype.Component;
47 * This class is api implementation used by participant intermediary.
50 public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryApi {
52 // The handler for the participant intermediary
53 private final ParticipantHandler participantHandler;
55 // The handler for the automationComposition intermediary
56 private final AutomationCompositionHandler automationCompositionHandler;
61 * @param participantHandler ParticipantHandler
62 * @param automationCompositionHandler AutomationCompositionHandler
64 public ParticipantIntermediaryApiImpl(ParticipantHandler participantHandler,
65 AutomationCompositionHandler automationCompositionHandler) {
66 this.participantHandler = participantHandler;
67 this.automationCompositionHandler = automationCompositionHandler;
71 public void registerAutomationCompositionElementListener(
72 AutomationCompositionElementListener automationCompositionElementListener) {
73 automationCompositionHandler.registerAutomationCompositionElementListener(automationCompositionElementListener);
77 public List<Participant> getParticipants(String name, String version) {
78 return List.of(participantHandler.getParticipant(name, version));
82 public Map<String, ToscaProperty> getAcElementDefinitionCommonProperties(ToscaConceptIdentifier acElementDef) {
83 return participantHandler.getAcElementDefinitionCommonProperties(acElementDef);
87 public Participant updateParticipantState(ToscaConceptIdentifier definition, ParticipantState state) {
88 return participantHandler.updateParticipantState(definition, state);
92 public void updateParticipantStatistics(ParticipantStatistics participantStatistics) {
93 participantHandler.updateParticipantStatistics(participantStatistics);
97 public AutomationCompositions getAutomationCompositions(String name, String version) {
98 return automationCompositionHandler.getAutomationCompositions();
102 public Map<UUID, AutomationCompositionElement> getAutomationCompositionElements(String name, String version) {
103 List<AutomationComposition> automationCompositions =
104 automationCompositionHandler.getAutomationCompositions().getAutomationCompositionList();
106 for (AutomationComposition automationComposition : automationCompositions) {
107 if (name.equals(automationComposition.getDefinition().getName())) {
108 return automationComposition.getElements();
111 return new LinkedHashMap<>();
115 public AutomationCompositionElement getAutomationCompositionElement(UUID id) {
116 List<AutomationComposition> automationCompositions =
117 automationCompositionHandler.getAutomationCompositions().getAutomationCompositionList();
119 for (AutomationComposition automationComposition : automationCompositions) {
120 AutomationCompositionElement acElement = automationComposition.getElements().get(id);
121 if (acElement != null) {
129 public AutomationCompositionElement updateAutomationCompositionElementState(
130 ToscaConceptIdentifier automationCompositionId, UUID id, AutomationCompositionOrderedState currentState,
131 AutomationCompositionState newState, ParticipantMessageType messageType) {
132 return automationCompositionHandler.updateAutomationCompositionElementState(automationCompositionId, id,
133 currentState, newState);
137 public void updateAutomationCompositionElementStatistics(UUID id, AcElementStatistics elementStatistics) {
138 automationCompositionHandler.updateAutomationCompositionElementStatistics(id, elementStatistics);