2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2024 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;
25 import java.util.UUID;
26 import lombok.RequiredArgsConstructor;
27 import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
28 import org.onap.policy.clamp.acm.participant.intermediary.handler.AutomationCompositionOutHandler;
29 import org.onap.policy.clamp.acm.participant.intermediary.handler.CacheProvider;
30 import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
31 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
32 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
33 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
34 import org.onap.policy.clamp.models.acm.concepts.DeployState;
35 import org.onap.policy.clamp.models.acm.concepts.LockState;
36 import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
37 import org.onap.policy.models.base.PfUtils;
38 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
39 import org.springframework.stereotype.Component;
42 * This class is api implementation used by participant intermediary.
45 @RequiredArgsConstructor
46 public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryApi {
48 // The handler for the automationComposition intermediary
49 private final AutomationCompositionOutHandler automationCompositionHandler;
50 private final CacheProvider cacheProvider;
53 public void updateAutomationCompositionElementState(UUID instance, UUID elementId, DeployState deployState,
54 LockState lockState, StateChangeResult stateChangeResult, String message) {
55 automationCompositionHandler.updateAutomationCompositionElementState(instance, elementId, deployState,
56 lockState, stateChangeResult, message);
60 public void updateAutomationCompositionElementStage(UUID instance, UUID elementId,
61 StateChangeResult stateChangeResult, int stage, String message) {
66 public void sendAcElementInfo(UUID instance, UUID elementId, String useState,
67 String operationalState, Map<String, Object> outProperties) {
68 automationCompositionHandler.sendAcElementInfo(instance, elementId, useState, operationalState,
73 public Map<UUID, AutomationComposition> getAutomationCompositions() {
74 return PfUtils.mapMap(cacheProvider.getAutomationCompositions(), AutomationComposition::new);
78 public void updateCompositionState(UUID compositionId, AcTypeState state, StateChangeResult stateChangeResult,
80 automationCompositionHandler.updateCompositionState(compositionId, state, stateChangeResult, message);
84 public AutomationCompositionElement getAutomationCompositionElement(UUID instanceId, UUID elementId) {
85 var automationComposition = cacheProvider.getAutomationCompositions().get(instanceId);
86 if (automationComposition == null) {
89 var element = automationComposition.getElements().get(elementId);
90 return element != null ? new AutomationCompositionElement(element) : null;
94 public void sendAcDefinitionInfo(UUID compositionId, ToscaConceptIdentifier elementId,
95 Map<String, Object> outProperties) {
96 automationCompositionHandler.sendAcDefinitionInfo(compositionId, elementId, outProperties);
100 public AutomationComposition getAutomationComposition(UUID instanceId) {
101 var automationComposition = cacheProvider.getAutomationCompositions().get(instanceId);
102 return automationComposition != null ? new AutomationComposition(automationComposition) : null;
106 public Map<UUID, Map<ToscaConceptIdentifier, AutomationCompositionElementDefinition>> getAcElementsDefinitions() {
107 return PfUtils.mapMap(cacheProvider.getAcElementsDefinitions(),
108 map -> PfUtils.mapMap(map, AutomationCompositionElementDefinition::new));
112 public Map<ToscaConceptIdentifier, AutomationCompositionElementDefinition> getAcElementsDefinitions(
113 UUID compositionId) {
114 var acElementDefinitions = cacheProvider.getAcElementsDefinitions().get(compositionId);
115 if (acElementDefinitions == null) {
118 return PfUtils.mapMap(acElementDefinitions, AutomationCompositionElementDefinition::new);
122 public AutomationCompositionElementDefinition getAcElementDefinition(UUID compositionId,
123 ToscaConceptIdentifier elementId) {
124 var acElementDefinitions = cacheProvider.getAcElementsDefinitions().get(compositionId);
125 if (acElementDefinitions == null) {
128 var acElementDefinition = acElementDefinitions.get(elementId);
129 return acElementDefinition != null ? new AutomationCompositionElementDefinition(acElementDefinition) : null;