fix dmaap-listener startup and library
[sdnc/northbound.git] / ueb-listener / src / main / java / org / openecomp / sdnc / uebclient / SdncNodeModel.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                                      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 package org.openecomp.sdnc.uebclient;
23
24 import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
25 import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames;
26 import org.openecomp.sdc.toscaparser.api.NodeTemplate;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 public class SdncNodeModel extends SdncBaseModel {
31         
32         private static final Logger LOG = LoggerFactory
33                         .getLogger(SdncNodeModel.class);
34         
35         private String serviceUUID = null;
36         private String ecompGeneratedNaming = null;
37         private String [] bindingUuids = null; 
38         
39         // Using ASDC TOSCA Parser 17.07
40         public SdncNodeModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) {
41                 
42                 super(sdcCsarHelper, nodeTemplate);
43
44                 // extract inputs
45                 String ecompGeneratedNaming = extractBooleanInputDefaultValue(SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_ECOMPGENERATEDNAMING);
46                 addParameter("ecomp_generated_naming",ecompGeneratedNaming);
47                 addParameter("naming_policy", extractInputDefaultValue(SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_NAMINGPOLICY));
48                 
49                 // extract properties
50                 addParameter("network_type", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE));
51                 addParameter("network_role", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE));
52                 addParameter("network_scope", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE));
53                 addParameter("network_technology", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY));
54
55                 // extract properties - network_assignments
56                 addParameter("is_shared_network", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_ISSHAREDNETWORK));
57                 addParameter("is_external_network", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_ISEXTERNALNETWORK));
58
59                 // extract properties - network_assignments - ipv4_subnet_default_assignment
60                 String useIpv4 = extractBooleanValue(nodeTemplate, "network_assignments#ipv4_subnet_default_assignment#use_ipv4");
61                 addParameter("use_ipv4", useIpv4);
62                 addParameter("ipv4_dhcp_enabled", extractBooleanValue(nodeTemplate, "network_assignments#ipv4_subnet_default_assignment#dhcp_enabled"));
63                 if (useIpv4.contains("Y")) {
64                         addParameter("ipv4_ip_version", "ipv4");
65                 }
66                 addParameter("ipv4_cidr_mask", extractValue(nodeTemplate, "network_assignments#ipv4_subnet_default_assignment#cidr_mask"));
67                 addParameter("eipam_v4_address_plan", extractValue(nodeTemplate, "network_assignments#ipv4_subnet_default_assignment#ip_network_address_plan"));
68                 
69                 // extract properties - network_assignments - ipv6_subnet_default_assignment
70                 String useIpv6 = extractBooleanValue(nodeTemplate, "network_assignments#ipv6_subnet_default_assignment#use_ipv6");
71                 addParameter("use_ipv6", useIpv6);
72                 addParameter("ipv6_dhcp_enabled", extractBooleanValue(nodeTemplate, "network_assignments#ipv6_subnet_default_assignment#dhcp_enabled"));
73                 if (useIpv6.contains("Y")) {
74                         addParameter("ipv6_ip_version", "ipv6");
75                 }
76                 addParameter("ipv6_cidr_mask", extractValue(nodeTemplate, "network_assignments#ipv6_subnet_default_assignment#cidr_mask"));
77                 addParameter("eipam_v6_address_plan", extractValue(nodeTemplate, "network_assignments#ipv6_subnet_default_assignment#ip_network_address_plan"));
78                 
79                 // extract properties - provider_network
80                 addParameter("is_provider_network", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK));
81                 addParameter("physical_network_name", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_PHYSICALNETWORKNAME));
82
83                 // extract properties - network_flows
84                 addParameter("is_bound_to_vpn", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKFLOWS_ISBOUNDTOVPN));
85
86                 // extract properties - network_flows - vpn_bindings
87                 String vpnBindingString = extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKFLOWS_VPNBINDING);
88                 bindingUuids = vpnBindingString.split(",");
89
90 }
91
92         public String getServiceUUID() {
93                 return serviceUUID;
94         }
95         public void setServiceUUID(String serviceUUID) {
96                 this.serviceUUID = serviceUUID;
97         }
98
99         public String getEcompGeneratedNaming() {
100                 return ecompGeneratedNaming;
101         }
102         public void setEcompGeneratedNaming(String ecompGeneratedNaming) {
103                 this.ecompGeneratedNaming = ecompGeneratedNaming;
104                 if (ecompGeneratedNaming != null && !ecompGeneratedNaming.isEmpty()) {
105                         params.put("ecomp_generated_naming", "\"" + ecompGeneratedNaming + "\"");                       
106                 }
107         }
108
109         public String getSql(String model_yaml) {
110                 
111                 StringBuilder sb = new StringBuilder();
112                 sb.append("INSERT into NETWORK_MODEL (service_uuid, customization_uuid, model_yaml, ");
113                 
114                 int paramCount = 0;
115                 for (String paramKey :  params.keySet()) {
116                         paramCount++;
117                     sb.append(paramKey);
118                     if (paramCount < params.size()) sb.append(", ");
119                 }
120                 
121                 sb.append(") values (" + serviceUUID + ", " + getCustomizationUUID() + ", \"" + model_yaml + "\", ");
122
123                 paramCount = 0;
124                 for (String paramKey :  params.keySet()) {
125                         paramCount++;
126                         String paramValue = params.get(paramKey);
127                     sb.append(paramValue);
128                     if (paramCount < params.size()) sb.append(", ");
129                 }
130
131                 sb.append(");");
132                 return sb.toString();
133         }
134
135         public String getVpnBindingsSql() {
136                 
137                 StringBuilder sb = new StringBuilder();
138                 for (int i=0; i < bindingUuids.length; i++) {
139                         sb.append("INSERT into VPN_BINDINGS (network_customization_uuid, binding_uuid) values (" + getCustomizationUUID() + ", \"" + bindingUuids[i] + "\"); ");
140                 }
141
142                 return sb.toString();
143         }
144         
145 }