2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2019 European Software Marketing Ltd.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.aai.babel.csar.vnfcatalog;
24 import java.util.ArrayList;
25 import java.util.LinkedHashMap;
26 import org.onap.sdc.toscaparser.api.NodeTemplate;
27 import org.onap.sdc.toscaparser.api.SubstitutionMappings;
29 public class SdcToscaHelper {
31 private ArrayList<NodeTemplate> smnodetemplates = new ArrayList<>();
34 * Create the test SubstitutionMappings.
36 * @return the new Substitution Mappings
38 public SubstitutionMappings buildMappings() {
39 LinkedHashMap<String, Object> defProps = getImagesDefProps();
41 LinkedHashMap<String, Object> defs = buildNodeTemplateTypeInfo(defProps);
42 LinkedHashMap<String, Object> caps = new LinkedHashMap<>();
43 LinkedHashMap<String, Object> reqs = new LinkedHashMap<>();
45 String type = "tosca.nodes.custom";
47 LinkedHashMap<String, Object> smsubMappingDef = new LinkedHashMap<>();
48 smsubMappingDef.put("node_type", type);
49 smsubMappingDef.put("capabilities", caps);
50 smsubMappingDef.put("requirements", reqs);
52 LinkedHashMap<String, Object> smcustomDefs = buildCustomTypeDefinitions(type, defs);
54 return new SubstitutionMappings(smsubMappingDef, smnodetemplates, null, null, null, null, smcustomDefs);
57 private LinkedHashMap<String, Object> getImagesDefProps() {
58 LinkedHashMap<String, Object> imagesDef = new LinkedHashMap<>();
59 imagesDef.put("type", "map");
60 imagesDef.put("required", false);
61 imagesDef.put("entry_schema", "{type=org.openecomp.datatypes.ImageInfo}");
63 LinkedHashMap<String, Object> defProps = new LinkedHashMap<>();
64 defProps.put("images", imagesDef);
68 private LinkedHashMap<String, Object> buildCustomTypeDefinitions(String type,
69 LinkedHashMap<String, Object> typeInfo) {
70 LinkedHashMap<String, Object> customDefs = new LinkedHashMap<>();
71 customDefs.put(type, typeInfo);
75 private LinkedHashMap<String, Object> buildNodeTemplateTypeInfo(LinkedHashMap<String, Object> props) {
76 LinkedHashMap<String, Object> typeInfo = new LinkedHashMap<>();
77 typeInfo.put("derived_from", "tosca.nodes.Root");
78 typeInfo.put("properties", props);
83 * Create a new NodeTemplate and add it to the list (for populating the Substitution Mappings).
85 public void addNodeTemplate() {
86 String name = "node name";
87 String type = "tosca.nodes.custom";
89 LinkedHashMap<String, Object> nodeTemplate = new LinkedHashMap<>();
90 nodeTemplate.put("type", type);
91 nodeTemplate.put("properties", null);
93 LinkedHashMap<String, Object> ntnodeTemplates = buildCustomTypeDefinitions(name, nodeTemplate);
94 ntnodeTemplates.put("derived_from", null);
95 ntnodeTemplates.put("properties", getImagesDefProps());
97 LinkedHashMap<String, Object> typeInfo = buildNodeTemplateTypeInfo(getImagesDefProps());
98 LinkedHashMap<String, Object> customDefs = buildCustomTypeDefinitions(type, typeInfo);
99 smnodetemplates.add(new NodeTemplate(name, ntnodeTemplates, customDefs, null, null));
103 * Simulate the creation of a NodeTemplate by the SDC TOSCA parser. Populate the properties of the NodeTemplate with
104 * the supplied images.
107 * the value of the images property
109 public void addNodeTemplate(Object images) {
110 LinkedHashMap<String, Object> properties = new LinkedHashMap<>();
111 properties.put("images", images);
113 String type = "tosca.nodes.custom";
114 LinkedHashMap<String, Object> nodeTemplate = new LinkedHashMap<>();
115 nodeTemplate.put("type", type);
116 nodeTemplate.put("properties", properties);
118 String name = "node name";
119 LinkedHashMap<String, Object> ntnodeTemplates = buildCustomTypeDefinitions(name, nodeTemplate);
120 ntnodeTemplates.put("derived_from", null);
121 ntnodeTemplates.put("properties", getImagesDefProps());
123 LinkedHashMap<String, Object> typeInfo = buildNodeTemplateTypeInfo(getImagesDefProps());
124 LinkedHashMap<String, Object> customDefs = buildCustomTypeDefinitions(type, typeInfo);
126 smnodetemplates.add(new NodeTemplate(name, ntnodeTemplates, customDefs, null, null));