dbff78cd5647a131dafb618bf7d9d8fc056601c8
[dcaegen2/platform.git] / mod / bpgenerator / src / main / java / org / onap / blueprintgenerator / models / onapbp / OnapNode.java
1 /**============LICENSE_START======================================================= 
2  org.onap.dcae 
3  ================================================================================ 
4  Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. 
5  ================================================================================ 
6  Licensed under the Apache License, Version 2.0 (the "License"); 
7  you may not use this file except in compliance with the License. 
8  You may obtain a copy of the License at 
9
10       http://www.apache.org/licenses/LICENSE-2.0 
11
12  Unless required by applicable law or agreed to in writing, software 
13  distributed under the License is distributed on an "AS IS" BASIS, 
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
15  See the License for the specific language governing permissions and 
16  limitations under the License. 
17  ============LICENSE_END========================================================= 
18
19  */
20
21 package org.onap.blueprintgenerator.models.onapbp;
22
23 import java.util.ArrayList;
24 import java.util.LinkedHashMap;
25 import java.util.TreeMap;
26
27 import org.onap.blueprintgenerator.core.PgaasNodeBuilder;
28 import org.onap.blueprintgenerator.core.PolicyNodeBuilder;
29 import org.onap.blueprintgenerator.models.blueprint.Interfaces;
30 import org.onap.blueprintgenerator.models.blueprint.Node;
31 import org.onap.blueprintgenerator.models.blueprint.Properties;
32 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
33
34 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
35 import com.fasterxml.jackson.annotation.JsonInclude;
36 import com.fasterxml.jackson.annotation.JsonInclude.Include;
37
38 import lombok.AllArgsConstructor;
39 import lombok.Builder;
40 import lombok.Getter; import lombok.Setter;
41 import lombok.EqualsAndHashCode;
42 import lombok.NoArgsConstructor;
43
44 @JsonIgnoreProperties(ignoreUnknown = true)
45 @Getter @Setter
46 @EqualsAndHashCode(callSuper=false)
47 @NoArgsConstructor
48 @JsonInclude(value=Include.NON_NULL)
49
50 public class OnapNode extends Node{
51         private TreeMap<String, Interfaces> interfaces;
52         private Properties properties;
53         private ArrayList<LinkedHashMap<String, String>> relationships;
54
55         public TreeMap<String, LinkedHashMap<String, Object>> createOnapNode(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) {
56                 TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>();
57                 retInputs = inps;
58
59                 //create and set the interfaces
60                 Interfaces inter = new Interfaces();
61                 retInputs = inter.createInterface(retInputs, cs);
62                 TreeMap<String, Interfaces> interfaces = new TreeMap<String, Interfaces>();
63                 interfaces.put("cloudify.interfaces.lifecycle", inter);
64                 this.setInterfaces(interfaces);
65
66                 //set the type
67                 this.setType("dcae.nodes.ContainerizedServiceComponent");
68
69                 //create and set the relationships
70                 ArrayList<LinkedHashMap<String, String>> rets = new ArrayList();
71
72                 //add relationship for policy if exist
73                 if(cs.getPolicyInfo() != null){
74                         ArrayList<LinkedHashMap<String, String>> policyRelationshipsList = PolicyNodeBuilder.getPolicyRelationships(cs);
75                         rets.addAll(policyRelationshipsList);
76                 }
77
78                 //add relationships and env_variables for pgaas dbs if exist
79                 if(cs.getAuxilary().getDatabases() != null){
80                         ArrayList<LinkedHashMap<String, String>> pgaasRelationshipsList = PgaasNodeBuilder.getPgaasNodeRelationships(cs);
81                         rets.addAll(pgaasRelationshipsList);
82                 }
83
84                 this.setRelationships(rets);
85
86                 //set the properties
87                 Properties props = new Properties();
88                 retInputs = props.createOnapProperties(retInputs, cs, override);
89                 this.setProperties(props);
90
91                 return retInputs;
92         }
93 }