aboutsummaryrefslogtreecommitdiffstats
path: root/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java
blob: 0a493171524d6953ad7cdef20b445180ceb496ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*-
 * ============LICENSE_START=======================================================
 * openECOMP : SDN-C
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights
 * 			reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.ccsdk.sli.northbound.uebclient;

import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames;
import org.openecomp.sdc.toscaparser.api.NodeTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SdncNodeModel extends SdncBaseModel {

	private String serviceUUID = null;
	private String ecompGeneratedNaming = null;
	private String [] bindingUuids = null; 
	
	// Using ASDC TOSCA Parser 17.07
	public SdncNodeModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) {
		
		super(sdcCsarHelper, nodeTemplate);

		// extract inpuecompGeneratedNamingts
		String ecompGeneratedNaming = extractBooleanInputDefaultValue(SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_ECOMPGENERATEDNAMING);
		addParameter("ecomp_generated_naming",ecompGeneratedNaming);
		addParameter("naming_policy", extractInputDefaultValue(SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_NAMINGPOLICY));
		
		// extract properties
		addParameter("network_type", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE));
		addParameter("network_role", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE));
		addParameter("network_scope", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE));
		addParameter("network_technology", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY));

		// extract properties - network_assignments
		addParameter("is_shared_network", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_ISSHAREDNETWORK));
		addParameter("is_external_network", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_ISEXTERNALNETWORK));

		// extract properties - network_assignments - ipv4_subnet_default_assignment
		String useIpv4 = extractBooleanValue(nodeTemplate, "network_assignments#ipv4_subnet_default_assignment#use_ipv4");
		addParameter("use_ipv4", useIpv4);
		addParameter("ipv4_dhcp_enabled", extractBooleanValue(nodeTemplate, "network_assignments#ipv4_subnet_default_assignment#dhcp_enabled"));
		if (useIpv4.contains("Y")) {
			addParameter("ipv4_ip_version", "ipv4");
		}
		addParameter("ipv4_cidr_mask", extractValue(nodeTemplate, "network_assignments#ipv4_subnet_default_assignment#cidr_mask"));
		addParameter("eipam_v4_address_plan", extractValue(nodeTemplate, "network_assignments#ipv4_subnet_default_assignment#ip_network_address_plan"));
		
		// extract properties - network_assignments - ipv6_subnet_default_assignment
		String useIpv6 = extractBooleanValue(nodeTemplate, "network_assignments#ipv6_subnet_default_assignment#use_ipv6");
		addParameter("use_ipv6", useIpv6);
		addParameter("ipv6_dhcp_enabled", extractBooleanValue(nodeTemplate, "network_assignments#ipv6_subnet_default_assignment#dhcp_enabled"));
		if (useIpv6.contains("Y")) {
			addParameter("ipv6_ip_version", "ipv6");
		}
		addParameter("ipv6_cidr_mask", extractValue(nodeTemplate, "network_assignments#ipv6_subnet_default_assignment#cidr_mask"));
		addParameter("eipam_v6_address_plan", extractValue(nodeTemplate, "network_assignments#ipv6_subnet_default_assignment#ip_network_address_plan"));
		
		// extract properties - provider_network
		addParameter("is_provider_network", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK));
		addParameter("physical_network_name", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_PHYSICALNETWORKNAME));

		// extract properties - network_flows
		addParameter("is_bound_to_vpn", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKFLOWS_ISBOUNDTOVPN));

		// extract properties - network_flows - vpn_bindings
		String vpnBindingString = extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKFLOWS_VPNBINDING);
		bindingUuids = vpnBindingString.split(",");

}

	public String getServiceUUID() {
		return serviceUUID;
	}
	public void setServiceUUID(String serviceUUID) {
		this.serviceUUID = serviceUUID;
	}

	public String getEcompGeneratedNaming() {
		return ecompGeneratedNaming;
	}
	public void setEcompGeneratedNaming(String ecompGeneratedNaming) {
		this.ecompGeneratedNaming = ecompGeneratedNaming;
		if (ecompGeneratedNaming != null && !ecompGeneratedNaming.isEmpty()) {
			params.put("ecomp_generated_naming", "\"" + ecompGeneratedNaming + "\"");			
		}
	}

	public String getSql(String model_yaml) {
		
		StringBuilder sb = new StringBuilder();
		sb.append("INSERT into NETWORK_MODEL (service_uuid, customization_uuid, model_yaml, ");
		
		int paramCount = 0;
		for (String paramKey :  params.keySet()) {
			paramCount++;
		    sb.append(paramKey);
		    if (paramCount < params.size()) sb.append(", ");
		}
		
		sb.append(") values (" + serviceUUID + ", " + getCustomizationUUID() + ", \"" + model_yaml + "\", ");

		paramCount = 0;
		for (String paramKey :  params.keySet()) {
			paramCount++;
			String paramValue = params.get(paramKey);
		    sb.append(paramValue);
		    if (paramCount < params.size()) sb.append(", ");
		}

		sb.append(");");
		return sb.toString();
	}

	public String getVpnBindingsSql() {
		
		StringBuilder sb = new StringBuilder();
		for (int i=0; i < bindingUuids.length; i++) {
			sb.append("INSERT into VPN_BINDINGS (network_customization_uuid, binding_uuid) values (" + getCustomizationUUID() + ", \"" + bindingUuids[i] + "\"); ");
		}

		return sb.toString();
	}
	
}