2 * ============LICENSE_START======================================================================
3 * Copyright (C) 2023 OpenInfra Foundation Europe. All rights reserved.
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.
16 * ============LICENSE_END========================================================================
19 package com.oransc.rappmanager.models;
21 import com.google.gson.Gson;
22 import com.google.gson.JsonArray;
23 import com.google.gson.JsonParser;
24 import com.oransc.rappmanager.models.rapp.Rapp;
25 import com.oransc.rappmanager.models.rappinstance.RappInstance;
27 import java.util.UUID;
28 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
29 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
30 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
31 import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
32 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
33 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType;
34 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
36 public interface AcmInterceptor {
38 String AC_DEFINITION_ELEMENT_NAME = "onap.policy.clamp.ac.element.AutomationCompositionDefinition";
39 String AC_DEFINITION_ELEMENTS_INDEX = "elements";
41 String AC_NODE_TYPE_ELEMENT_NAME = "org.onap.policy.clamp.acm.AutomationCompositionElement";
42 String AC_NODE_TEMPLATE_PARTICIPANT_TYPE = "org.onap.policy.clamp.acm.Participant";
43 String AC_TOSCA_DATA_TYPE_ROOT = "tosca.datatypes.Root";
44 String TOSCA_IDENTIFIER_KEY = "onap.datatypes.ToscaConceptIdentifier";
45 String TEMPLATE_PROVIDER = "NONRTRIC";
47 String TOSCA_PROPERTY_TYPE_STRING = "string";
48 String TOSCA_PROPERTY_TYPE_LIST = "list";
50 default void injectToscaServiceTemplate(ToscaServiceTemplate toscaServiceTemplate, String acElementName,
51 String acElementVersion) {
52 toscaServiceTemplate.getDataTypes().putAll(getDataTypes());
53 toscaServiceTemplate.getNodeTypes().putAll(getNodeTypes());
54 toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().putAll(getNodeTemplates());
56 Object o = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().get(AC_DEFINITION_ELEMENT_NAME)
57 .getProperties().get(AC_DEFINITION_ELEMENTS_INDEX);
59 JsonArray elementJsonArray = JsonParser.parseString(o.toString()).getAsJsonArray();
61 new Gson().toJsonTree(getElementToscaIdentifier(acElementName, acElementVersion)).getAsJsonObject());
63 toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().get(AC_DEFINITION_ELEMENT_NAME)
64 .getProperties().put(AC_DEFINITION_ELEMENTS_INDEX, elementJsonArray);
67 void injectToscaServiceTemplate(ToscaServiceTemplate toscaServiceTemplate);
69 Map<String, ToscaNodeTemplate> getNodeTemplates();
71 Map<String, ToscaNodeType> getNodeTypes();
73 Map<String, ToscaDataType> getDataTypes();
75 default ToscaConceptIdentifier getElementToscaIdentifier(String acElementName, String acElementVersion) {
76 ToscaConceptIdentifier toscaConceptIdentifier = new ToscaConceptIdentifier();
77 toscaConceptIdentifier.setName(acElementName);
78 toscaConceptIdentifier.setVersion(acElementVersion);
79 return toscaConceptIdentifier;
82 default void injectAutomationComposition(AutomationComposition automationComposition, Rapp rapp,
83 RappInstance rappInstance) {
84 automationComposition.getElements().putAll(getInstantiationElement(rapp, rappInstance));
87 Map<UUID, AutomationCompositionElement> getInstantiationElement(Rapp rapp, RappInstance rappInstance);