2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.ccsdk.sli.northbound.uebclient;
24 import java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.HashMap;
29 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
30 import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
31 import org.onap.sdc.toscaparser.api.NodeTemplate;
32 import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public class SdncNodeModel extends SdncBaseModel {
38 private static final Logger LOG = LoggerFactory
39 .getLogger(SdncNodeModel.class);
41 private String serviceUUID = null;
42 private String ecompGeneratedNaming = null;
43 private String [] bindingUuids = null;
45 // Using ASDC TOSCA Parser 17.07
46 public SdncNodeModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, DBResourceManager jdbcDataSource) {
48 super(sdcCsarHelper, nodeTemplate, jdbcDataSource);
50 // extract inpuecompGeneratedNamingts
51 String ecompGeneratedNaming = extractBooleanInputDefaultValue(SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_ECOMPGENERATEDNAMING);
52 addParameter("ecomp_generated_naming",ecompGeneratedNaming);
53 addParameter("naming_policy", extractInputDefaultValue(SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_NAMINGPOLICY));
56 addParameter("network_type", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE));
57 addParameter("network_role", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE));
58 addParameter("network_scope", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE));
59 addParameter("network_technology", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY));
61 // extract properties - network_assignments
62 addParameter("is_shared_network", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_ISSHAREDNETWORK));
63 addParameter("is_external_network", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_ISEXTERNALNETWORK));
64 String trunkNetworkIndicator = extractBooleanValue(nodeTemplate, "network_assignments#is_trunked");
65 addParameter("trunk_network_indicator", trunkNetworkIndicator);
67 // extract properties - network_assignments - ipv4_subnet_default_assignment
68 String useIpv4 = extractBooleanValue(nodeTemplate, "network_assignments#ipv4_subnet_default_assignment#use_ipv4");
69 addParameter("use_ipv4", useIpv4);
70 addParameter("ipv4_dhcp_enabled", extractBooleanValue(nodeTemplate, "network_assignments#ipv4_subnet_default_assignment#dhcp_enabled"));
71 if (useIpv4.contains("Y")) {
72 addParameter("ipv4_ip_version", "ipv4");
74 addParameter("ipv4_cidr_mask", extractValue(nodeTemplate, "network_assignments#ipv4_subnet_default_assignment#cidr_mask"));
75 addParameter("eipam_v4_address_plan", extractValue(nodeTemplate, "network_assignments#ipv4_subnet_default_assignment#ip_network_address_plan"));
77 // extract properties - network_assignments - ipv6_subnet_default_assignment
78 String useIpv6 = extractBooleanValue(nodeTemplate, "network_assignments#ipv6_subnet_default_assignment#use_ipv6");
79 addParameter("use_ipv6", useIpv6);
80 addParameter("ipv6_dhcp_enabled", extractBooleanValue(nodeTemplate, "network_assignments#ipv6_subnet_default_assignment#dhcp_enabled"));
81 if (useIpv6.contains("Y")) {
82 addParameter("ipv6_ip_version", "ipv6");
84 addParameter("ipv6_cidr_mask", extractValue(nodeTemplate, "network_assignments#ipv6_subnet_default_assignment#cidr_mask"));
85 addParameter("eipam_v6_address_plan", extractValue(nodeTemplate, "network_assignments#ipv6_subnet_default_assignment#ip_network_address_plan"));
87 // extract properties - provider_network
88 addParameter("is_provider_network", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK));
89 addParameter("physical_network_name", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_PHYSICALNETWORKNAME));
91 // extract properties - network_flows
92 addParameter("is_bound_to_vpn", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKFLOWS_ISBOUNDTOVPN));
94 // extract properties - network_flows - vpn_bindings
95 String vpnBindingString = extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKFLOWS_VPNBINDING);
96 bindingUuids = vpnBindingString.split(",");
100 public String getServiceUUID() {
103 public void setServiceUUID(String serviceUUID) {
104 this.serviceUUID = serviceUUID;
107 public String getEcompGeneratedNaming() {
108 return ecompGeneratedNaming;
110 public void setEcompGeneratedNaming(String ecompGeneratedNaming) {
111 this.ecompGeneratedNaming = ecompGeneratedNaming;
112 if (ecompGeneratedNaming != null && !ecompGeneratedNaming.isEmpty()) {
113 params.put("ecomp_generated_naming", "\"" + ecompGeneratedNaming + "\"");
117 public void insertNetworkModelData () throws IOException {
119 // Clean up NETWORK_MODEL data for this customization_uuid and service_uuid?
120 cleanUpExistingToscaData("NETWORK_MODEL", "customization_uuid", getCustomizationUUID());
121 cleanUpExistingToscaData("VPN_BINDINGS", "network_customization_uuid", getCustomizationUUID());
122 LOG.info("Call insertToscaData for NETWORK_MODEL customizationUUID = " + getCustomizationUUID());
123 insertToscaData(getSql(model_yaml), null);
124 insertToscaData(getVpnBindingsSql(), null);
125 } catch (IOException e) {
126 LOG.error("Could not insert Tosca CSAR data into the NETWORK_MODEL table");
127 throw new IOException (e);
131 public void insertRelatedNetworkRoleData () throws IOException {
133 Object propertyValue = sdcCsarHelper.getNodeTemplatePropertyValueAsObject(nodeTemplate, "network_assignments#related_networks");
134 ArrayList<Map<String, String>> relatedNetworkList = (ArrayList)propertyValue;
136 String networkModelCustomizationUUID = getCustomizationUUID();
138 if (relatedNetworkList != null) {
141 cleanUpExistingToscaData("RELATED_NETWORK_ROLE", "network_model_customization_uuid", networkModelCustomizationUUID);
142 } catch (IOException e) {
143 LOG.error("Could not clean up Tosca CSAR data in the RELATED_NETWORK_ROLE table");
144 throw new IOException (e);
147 for (Map<String, String> relatedNetworkValue : relatedNetworkList) {
148 LOG.debug("Node Template [" + nodeTemplate.getName() + "], property [" + "related_network_role" + "] property value: " + relatedNetworkValue.get("related_network_role"));
150 String relatedNetworkRoleValue = relatedNetworkValue.get("related_network_role");
153 // Table cleanup RELATED_NETWORK_ROLE occurs per network
154 // If related_network_role for this service already exist in RELATED_NETWORK_ROLE, don't attempt insertion
155 Map<String, String> relatedNetworkRoleParamsCheck = new HashMap<String, String>();
156 addParameter("related_network_role", relatedNetworkRoleValue, relatedNetworkRoleParamsCheck);
157 addParameter("network_model_customization_uuid", networkModelCustomizationUUID, relatedNetworkRoleParamsCheck);
158 if (checkForExistingToscaData("RELATED_NETWORK_ROLE", relatedNetworkRoleParamsCheck) == false) {
159 relatedNetworkRoleParamsCheck.remove("related_network_role");
160 LOG.info("Call insertToscaData for RELATED_NETWORK_ROLE where network_model_customization_uuid = " + networkModelCustomizationUUID);
161 insertToscaData(buildSql("RELATED_NETWORK_ROLE", "related_network_role", "\"" + relatedNetworkRoleValue + "\"", model_yaml, relatedNetworkRoleParamsCheck), null);
163 } catch (IOException e) {
164 LOG.debug("Could not insert Tosca CSAR data into the RELATED_NETWORK_ROLE table");
165 throw new IOException (e);
170 LOG.debug("Node Template [" + nodeTemplate.getName() + "], property [" + "related_networks" + "] property value: " + null);
175 public String getSql(String model_yaml) {
177 StringBuilder sb = new StringBuilder();
178 sb.append("INSERT into NETWORK_MODEL (service_uuid, customization_uuid, model_yaml, ");
181 for (String paramKey : params.keySet()) {
184 if (paramCount < params.size()) sb.append(", ");
187 sb.append(") values (" + serviceUUID + ", " + getCustomizationUUID() + ", \"" + model_yaml + "\", ");
190 for (String paramKey : params.keySet()) {
192 String paramValue = params.get(paramKey);
193 sb.append(paramValue);
194 if (paramCount < params.size()) sb.append(", ");
198 return sb.toString();
201 public String getVpnBindingsSql() {
203 StringBuilder sb = new StringBuilder();
204 for (int i=0; i < bindingUuids.length; i++) {
205 sb.append("INSERT into VPN_BINDINGS (network_customization_uuid, binding_uuid) values (" + getCustomizationUUID() + ", \"" + bindingUuids[i] + "\"); ");
208 return sb.toString();