Adjust BP-gen to correctly support DFC component spec - types
[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  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 static org.onap.blueprintgenerator.models.blueprint.BpConstants.CONTENERIZED_SERVICE_COMPONENT;
26
27 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
28 import com.fasterxml.jackson.annotation.JsonInclude;
29 import com.fasterxml.jackson.annotation.JsonInclude.Include;
30 import java.util.ArrayList;
31 import java.util.LinkedHashMap;
32 import java.util.TreeMap;
33 import lombok.EqualsAndHashCode;
34 import lombok.Getter;
35 import lombok.NoArgsConstructor;
36 import lombok.Setter;
37 import org.onap.blueprintgenerator.core.PgaasNodeBuilder;
38 import org.onap.blueprintgenerator.core.PolicyNodeBuilder;
39 import org.onap.blueprintgenerator.models.blueprint.Interfaces;
40 import org.onap.blueprintgenerator.models.blueprint.Node;
41 import org.onap.blueprintgenerator.models.blueprint.Properties;
42 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
43
44 @JsonIgnoreProperties(ignoreUnknown = true)
45 @Getter
46 @Setter
47 @EqualsAndHashCode(callSuper = false)
48 @NoArgsConstructor
49 @JsonInclude(value = Include.NON_NULL)
50
51 public class OnapNode extends Node {
52
53     public TreeMap<String, LinkedHashMap<String, Object>> createOnapNode(
54         TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) {
55         TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>();
56         retInputs = inps;
57
58         //create and set the interfaces
59         Interfaces inter = new Interfaces();
60         retInputs = inter.createInterface(retInputs, cs);
61         TreeMap<String, Interfaces> interfaces = new TreeMap<String, Interfaces>();
62         interfaces.put("cloudify.interfaces.lifecycle", inter);
63         this.setInterfaces(interfaces);
64
65         //set the type
66         this.setType(CONTENERIZED_SERVICE_COMPONENT);
67
68         //create and set the relationships
69         ArrayList<LinkedHashMap<String, String>> rets = new ArrayList();
70
71         //add relationship for policy if exist
72         if (cs.getPolicyInfo() != null) {
73             ArrayList<LinkedHashMap<String, String>> policyRelationshipsList = PolicyNodeBuilder
74                 .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
81                 .getPgaasNodeRelationships(cs);
82             rets.addAll(pgaasRelationshipsList);
83         }
84
85         this.setRelationships(rets);
86
87         //set the properties
88         Properties props = new Properties();
89         retInputs = props.createOnapProperties(retInputs, cs, override);
90         this.setProperties(props);
91
92         return retInputs;
93     }
94 }