2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 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<>();
36 public SubstitutionMappings buildMappings() {
37 LinkedHashMap<String, Object> defProps = getImagesDefProps();
39 LinkedHashMap<String, Object> defs = buildNodeTemplateTypeInfo(defProps);
40 LinkedHashMap<String, Object> caps = new LinkedHashMap<>();
41 LinkedHashMap<String, Object> reqs = new LinkedHashMap<>();
43 String type = "tosca.nodes.custom";
45 LinkedHashMap<String, Object> smsubMappingDef = new LinkedHashMap<>();
46 smsubMappingDef.put("node_type", type);
47 smsubMappingDef.put("capabilities", caps);
48 smsubMappingDef.put("requirements", reqs);
50 LinkedHashMap<String, Object> smcustomDefs = buildCustomTypeDefinitions(type, defs);
52 return new SubstitutionMappings(smsubMappingDef, smnodetemplates, null, null, null, null, smcustomDefs);
55 private LinkedHashMap<String, Object> getImagesDefProps() {
56 LinkedHashMap<String, Object> imagesDef = new LinkedHashMap<>();
57 imagesDef.put("type", "map");
58 imagesDef.put("required", false);
59 imagesDef.put("entry_schema", "{type=org.openecomp.datatypes.ImageInfo}");
61 LinkedHashMap<String, Object> defProps = new LinkedHashMap<>();
62 defProps.put("images", imagesDef);
66 private LinkedHashMap<String, Object> buildCustomTypeDefinitions(String type,
67 LinkedHashMap<String, Object> typeInfo) {
68 LinkedHashMap<String, Object> customDefs = new LinkedHashMap<>();
69 customDefs.put(type, typeInfo);
73 private LinkedHashMap<String, Object> buildNodeTemplateTypeInfo(LinkedHashMap<String, Object> props) {
74 LinkedHashMap<String, Object> typeInfo = new LinkedHashMap<>();
75 typeInfo.put("derived_from", "tosca.nodes.Root");
76 typeInfo.put("properties", props);
83 public void addNodeTemplate() {
84 String name = "node name";
85 String type = "tosca.nodes.custom";
87 LinkedHashMap<String, Object> nodeTemplate = new LinkedHashMap<>();
88 nodeTemplate.put("type", type);
89 nodeTemplate.put("properties", null);
91 LinkedHashMap<String, Object> ntnodeTemplates = buildCustomTypeDefinitions(name, nodeTemplate);
92 ntnodeTemplates.put("derived_from", null);
93 ntnodeTemplates.put("properties", getImagesDefProps());
95 LinkedHashMap<String, Object> typeInfo = buildNodeTemplateTypeInfo(getImagesDefProps());
96 LinkedHashMap<String, Object> customDefs = buildCustomTypeDefinitions(type, typeInfo);
97 smnodetemplates.add(new NodeTemplate(name, ntnodeTemplates, customDefs, null, null));
103 public void addNodeTemplate(Object images) {
104 LinkedHashMap<String, Object> properties = new LinkedHashMap<>();
105 properties.put("images", images);
107 String type = "tosca.nodes.custom";
108 LinkedHashMap<String, Object> nodeTemplate = new LinkedHashMap<>();
109 nodeTemplate.put("type", type);
110 nodeTemplate.put("properties", properties);
112 String name = "node name";
113 LinkedHashMap<String, Object> ntnodeTemplates = buildCustomTypeDefinitions(name, nodeTemplate);
114 ntnodeTemplates.put("derived_from", null);
115 ntnodeTemplates.put("properties", getImagesDefProps());
117 LinkedHashMap<String, Object> typeInfo = buildNodeTemplateTypeInfo(getImagesDefProps());
118 LinkedHashMap<String, Object> customDefs = buildCustomTypeDefinitions(type, typeInfo);
120 smnodetemplates.add(new NodeTemplate(name, ntnodeTemplates, customDefs, null, null));