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 * @return the new NodeTemplate
87 public NodeTemplate addNodeTemplate() {
88 String name = "node name";
89 String type = "tosca.nodes.custom";
91 LinkedHashMap<String, Object> ntMap = new LinkedHashMap<>();
92 ntMap.put("type", type);
93 ntMap.put("properties", null);
95 LinkedHashMap<String, Object> ntnodeTemplates = buildCustomTypeDefinitions(name, ntMap);
96 ntnodeTemplates.put("derived_from", null);
97 ntnodeTemplates.put("properties", getImagesDefProps());
99 LinkedHashMap<String, Object> typeInfo = buildNodeTemplateTypeInfo(getImagesDefProps());
100 LinkedHashMap<String, Object> customDefs = buildCustomTypeDefinitions(type, typeInfo);
101 NodeTemplate nodeTemplate = new NodeTemplate(name, ntnodeTemplates, customDefs, null, null);
102 smnodetemplates.add(nodeTemplate);
107 * Simulate the creation of a NodeTemplate by the SDC TOSCA parser. Populate the properties of the NodeTemplate with
108 * the supplied images.
111 * the value of the images property
113 public void addNodeTemplate(Object images) {
114 LinkedHashMap<String, Object> properties = new LinkedHashMap<>();
115 properties.put("images", images);
117 String type = "tosca.nodes.custom";
118 LinkedHashMap<String, Object> nodeTemplate = new LinkedHashMap<>();
119 nodeTemplate.put("type", type);
120 nodeTemplate.put("properties", properties);
122 String name = "node name";
123 LinkedHashMap<String, Object> ntnodeTemplates = buildCustomTypeDefinitions(name, nodeTemplate);
124 ntnodeTemplates.put("derived_from", null);
125 ntnodeTemplates.put("properties", getImagesDefProps());
127 LinkedHashMap<String, Object> typeInfo = buildNodeTemplateTypeInfo(getImagesDefProps());
128 LinkedHashMap<String, Object> customDefs = buildCustomTypeDefinitions(type, typeInfo);
130 smnodetemplates.add(new NodeTemplate(name, ntnodeTemplates, customDefs, null, null));