9f6f560f8c46581262d5ee767c4176a3e67e485e
[dcaegen2/platform.git] / mod / bpgenerator / src / main / java / org / onap / blueprintgenerator / models / onapbp / OnapBlueprint.java
1 /**============LICENSE_START======================================================= 
2  org.onap.dcae 
3  ================================================================================ 
4  Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. 
5  ================================================================================
6  Modifications Copyright (c) 2020 Nokia. All rights reserved.
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 
11
12       http://www.apache.org/licenses/LICENSE-2.0 
13
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========================================================= 
20
21  */
22
23 package org.onap.blueprintgenerator.models.onapbp;
24
25 import java.util.ArrayList;
26 import java.util.LinkedHashMap;
27 import java.util.TreeMap;
28
29 import org.onap.blueprintgenerator.core.PgaasNodeBuilder;
30 import org.onap.blueprintgenerator.core.PolicyNodeBuilder;
31 import org.onap.blueprintgenerator.models.blueprint.Blueprint;
32 import org.onap.blueprintgenerator.models.blueprint.Imports;
33 import org.onap.blueprintgenerator.models.blueprint.Node;
34 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
35
36 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
37 import com.fasterxml.jackson.annotation.JsonInclude;
38 import com.fasterxml.jackson.annotation.JsonInclude.Include;
39
40 import lombok.Getter; import lombok.Setter;
41 import lombok.EqualsAndHashCode;
42 import lombok.NoArgsConstructor;
43
44
45 @Getter @Setter
46 @JsonInclude(value=Include.NON_NULL)
47
48 public class OnapBlueprint extends Blueprint{
49         public Blueprint createOnapBlueprint(ComponentSpec cs, String importPath, String override) {
50
51                 //create the inputs that will be used
52                 TreeMap<String, LinkedHashMap<String, Object>> inputs = new TreeMap<String, LinkedHashMap<String, Object>>();
53                 //set the tosca definition which is the same for everything
54                 this.setTosca_definitions_version("cloudify_dsl_1_3");
55
56                 //set the imports 
57                 if(!"".equals(importPath)) {
58                         Imports imps = new Imports();
59                         this.setImports(imps.createImportsFromFile(importPath));
60                 }
61                 else {
62                         Imports imps = new Imports();
63                         this.setImports(imps.createOnapImports());
64                 }
65
66                 //create the node template
67                 TreeMap<String, Node> nodeTemplate = new TreeMap<String, Node>();
68                 String nodeName = cs.getSelf().getName();
69
70                 //create the onap node that will be used
71                 OnapNode node = new OnapNode();
72                 inputs = node.createOnapNode(inputs, cs, override);
73                 nodeTemplate.put(nodeName, node);
74                 this.setNode_templates(nodeTemplate);
75
76                 //if present in component spec, populate policyNode information in the blueprint
77                 if(cs.getPolicyInfo() != null){
78                         PolicyNodeBuilder.addPolicyNodesAndInputs(cs, nodeTemplate, inputs);
79                 }
80
81                 //if present in component spec, populate pgaasNodes information in the blueprint
82                 if(cs.getAuxilary().getDatabases() != null){
83                         PgaasNodeBuilder.addPgaasNodesAndInputs(cs, nodeTemplate, inputs);
84                 }
85
86                 //set the inputs
87                 this.setInputs(inputs);
88
89
90                 Blueprint bp = new Blueprint();
91                 bp.setImports(this.getImports());
92                 bp.setInputs(this.getInputs());
93                 bp.setNode_templates(this.getNode_templates());
94                 bp.setTosca_definitions_version(this.getTosca_definitions_version());
95
96                 return bp;
97
98         }
99 }