Add helm artifacts in the CSAR package
[nonrtric/plt/rappmanager.git] / rapp-manager-models / src / main / java / com / oransc / rappmanager / models / AcmInterceptor.java
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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========================================================================
17  */
18
19 package com.oransc.rappmanager.models;
20
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;
26 import java.util.Map;
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;
35
36 public interface AcmInterceptor {
37
38     String AC_DEFINITION_ELEMENT_NAME = "onap.policy.clamp.ac.element.AutomationCompositionDefinition";
39     String AC_DEFINITION_ELEMENTS_INDEX = "elements";
40
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";
46
47     String TOSCA_PROPERTY_TYPE_STRING = "string";
48     String TOSCA_PROPERTY_TYPE_LIST = "list";
49
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());
55
56         Object o = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().get(AC_DEFINITION_ELEMENT_NAME)
57                            .getProperties().get(AC_DEFINITION_ELEMENTS_INDEX);
58
59         JsonArray elementJsonArray = JsonParser.parseString(o.toString()).getAsJsonArray();
60         elementJsonArray.add(
61                 new Gson().toJsonTree(getElementToscaIdentifier(acElementName, acElementVersion)).getAsJsonObject());
62
63         toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().get(AC_DEFINITION_ELEMENT_NAME)
64                 .getProperties().put(AC_DEFINITION_ELEMENTS_INDEX, elementJsonArray);
65     }
66
67     void injectToscaServiceTemplate(ToscaServiceTemplate toscaServiceTemplate);
68
69     Map<String, ToscaNodeTemplate> getNodeTemplates();
70
71     Map<String, ToscaNodeType> getNodeTypes();
72
73     Map<String, ToscaDataType> getDataTypes();
74
75     default ToscaConceptIdentifier getElementToscaIdentifier(String acElementName, String acElementVersion) {
76         ToscaConceptIdentifier toscaConceptIdentifier = new ToscaConceptIdentifier();
77         toscaConceptIdentifier.setName(acElementName);
78         toscaConceptIdentifier.setVersion(acElementVersion);
79         return toscaConceptIdentifier;
80     }
81
82     default void injectAutomationComposition(AutomationComposition automationComposition, Rapp rapp,
83             RappInstance rappInstance) {
84         automationComposition.getElements().putAll(getInstantiationElement(rapp, rappInstance));
85     }
86
87     Map<UUID, AutomationCompositionElement> getInstantiationElement(Rapp rapp, RappInstance rappInstance);
88 }