From ea5bf0a1c8a4e525d2cee03841b8e8f9b3563ed0 Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Tue, 18 Jul 2017 20:32:15 -0400 Subject: [CCSDK-6] Populate seed code Add seed code for sli/northbound repository Update groupId to org.onap.ccsdk.sli.northbound Update to use CCSDK version of sli core Change-Id: Id3a154a53150a74f4b65060544e76f3e0cad932e Signed-off-by: Dan Timoney --- ueb-listener/src/assembly/assemble_zip.xml | 63 ++ .../org/openecomp/sdnc/uebclient/SdncARModel.java | 53 + .../openecomp/sdnc/uebclient/SdncArtifactMap.java | 134 +++ .../openecomp/sdnc/uebclient/SdncBaseModel.java | 297 ++++++ .../openecomp/sdnc/uebclient/SdncNodeModel.java | 145 +++ .../sdnc/uebclient/SdncOdlConnection.java | 158 +++ .../openecomp/sdnc/uebclient/SdncServiceModel.java | 98 ++ .../openecomp/sdnc/uebclient/SdncUebCallback.java | 1125 ++++++++++++++++++++ .../openecomp/sdnc/uebclient/SdncUebClient.java | 65 ++ .../sdnc/uebclient/SdncUebConfiguration.java | 280 +++++ .../org/openecomp/sdnc/uebclient/SdncVFCModel.java | 69 ++ .../org/openecomp/sdnc/uebclient/SdncVFModel.java | 56 + .../sdnc/uebclient/SdncVFModuleModel.java | 45 + ueb-listener/src/main/resources/log4j.properties | 37 + .../src/main/resources/normalizeTagNames.xslt | 14 + ueb-listener/src/main/resources/removeNs.xslt | 16 + .../src/main/scripts/start-ueb-listener.sh | 68 ++ ueb-listener/src/main/scripts/stop-ueb-listener.sh | 56 + ueb-listener/src/site/apt/index.apt | 46 + ueb-listener/src/site/site.xml | 31 + 20 files changed, 2856 insertions(+) create mode 100644 ueb-listener/src/assembly/assemble_zip.xml create mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncARModel.java create mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncArtifactMap.java create mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncBaseModel.java create mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncNodeModel.java create mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncOdlConnection.java create mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncServiceModel.java create mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebCallback.java create mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebClient.java create mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebConfiguration.java create mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFCModel.java create mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFModel.java create mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFModuleModel.java create mode 100644 ueb-listener/src/main/resources/log4j.properties create mode 100755 ueb-listener/src/main/resources/normalizeTagNames.xslt create mode 100755 ueb-listener/src/main/resources/removeNs.xslt create mode 100644 ueb-listener/src/main/scripts/start-ueb-listener.sh create mode 100644 ueb-listener/src/main/scripts/stop-ueb-listener.sh create mode 100644 ueb-listener/src/site/apt/index.apt create mode 100644 ueb-listener/src/site/site.xml (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/assembly/assemble_zip.xml b/ueb-listener/src/assembly/assemble_zip.xml new file mode 100644 index 000000000..d1f6679e1 --- /dev/null +++ b/ueb-listener/src/assembly/assemble_zip.xml @@ -0,0 +1,63 @@ + + + + + + assemble_zip + + zip + + + false + + + + src/main/bin + bin + + + target + lib + + *.jar + + + + src/main/resources + lib + + *.xslt + *.properties + + + + + + lib + true + runtime + + + diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncARModel.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncARModel.java new file mode 100644 index 000000000..3472b443a --- /dev/null +++ b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncARModel.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.openecomp.sdnc.uebclient; + +import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; +import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames; +import org.openecomp.sdc.toscaparser.api.Metadata; +import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdncARModel extends SdncBaseModel { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncARModel.class); + + public SdncARModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { + + super(sdcCsarHelper, nodeTemplate); + + // extract metadata + Metadata metadata = nodeTemplate.getMetadata(); + addParameter("type", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_TYPE)); + + // extract properties + //addParameter("role", extractValue (sdcCsarHelper, nodeTemplate, SdcPropertyNames.PROPERTY_NAME_ROLE)); + //addParameter("type", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_TYPE)); - wrong location, get from metadata + addParameter("ecomp_generated_naming", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VFCNAMING_ECOMPGENERATEDNAMING)); + addParameter("naming_policy", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VFCNAMING_NAMINGPOLICY)); + //addParameter("depending_service", extractValue (sdcCsarHelper, nodeTemplate, SdcPropertyNames.PROPERTY_NAME_DEPENDINGSERVICE)); + //addParameter("service_dependency", extractValue (sdcCsarHelper, nodeTemplate, SdcPropertyNames.PROPERTY_NAME_SERVICEDEPENDENCY)); + } + +} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncArtifactMap.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncArtifactMap.java new file mode 100644 index 000000000..4a9f02a8e --- /dev/null +++ b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncArtifactMap.java @@ -0,0 +1,134 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.openecomp.sdnc.uebclient; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdncArtifactMap { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncArtifactMap.class); + + public class SdncArtifactType { + private String tag; + private String artifactType; + private String rpc; + private int pass; + + public String getTag() { + return tag; + } + public String getArtifactType() { + return artifactType; + } + public String getRpc() { + return rpc; + } + + public int getPass() { + return pass; + } + + public String getRpcUrl(String base) { + return(base+rpc); + } + + private SdncArtifactType(String tag, String rpc, String pass) { + this.tag = tag; + this.rpc = rpc; + try { + this.pass = Integer.parseInt(pass); + } catch (Exception e) { + LOG.error("Invalid pass value for artifact map entry ("+tag+","+rpc+","+pass+")"); + } + } + } + + + + private Map mapItems = new HashMap(); + + private int NumPasses = 1; + + public int getNumPasses() { + return NumPasses; + } + + public void load(String fileName) { + + File mapFile = new File(fileName); + + if (mapFile.exists() && mapFile.canRead()) { + + BufferedReader rdr = null; + try { + + rdr = new BufferedReader(new FileReader(mapFile)); + + for (String ln ; (ln = rdr.readLine()) != null ; ) { + String[] lnFields = ln.split(","); + if (lnFields.length == 3) { + SdncArtifactType entry = new SdncArtifactType(lnFields[0], lnFields[1], lnFields[2]); + mapItems.put(entry.getTag(), entry); + if (entry.getPass() + 1 > NumPasses ) { + NumPasses = entry.getPass() + 1; + } + } + } + + + } catch (Exception e) { + LOG.error("Caught exception reading artifact map", e); + return; + } finally { + if (rdr != null) { + try { + rdr.close(); + } catch (IOException e) { + + } + } + } + } + } + + public SdncArtifactType getMapping(String tag) { + if (mapItems.containsKey(tag)) { + return(mapItems.get(tag)); + } else { + return(null); + } + } + + public static SdncArtifactMap getInstance() { + return new SdncArtifactMap(); + } + +} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncBaseModel.java new file mode 100644 index 000000000..39c50aed0 --- /dev/null +++ b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncBaseModel.java @@ -0,0 +1,297 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.openecomp.sdnc.uebclient; + +import java.util.HashMap; +import java.util.Map; + +import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; +import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames; +import org.openecomp.sdc.toscaparser.api.Group; +import org.openecomp.sdc.toscaparser.api.Metadata; +import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdncBaseModel { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncBaseModel.class); + + protected String customizationUUID = null; + protected String invariantUUID = null; + protected String model_yaml = null; + protected String version = null; + + protected Map params = null; + protected ISdcCsarHelper sdcCsarHelper = null; + + public SdncBaseModel() { + + } + + public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata) { + + params = new HashMap(); + this.sdcCsarHelper = sdcCsarHelper; + + // extract service metadata + invariantUUID = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID); + addParameter("invariant_uuid",invariantUUID); + addParameter("version",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_VERSION)); + addParameter("name",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_NAME)); + addParameter("description",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); + addParameter("type",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_TYPE)); + addParameter("category",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_CATEGORY)); + } + + public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { + + params = new HashMap(); + this.sdcCsarHelper = sdcCsarHelper; + + // extract nodeTemplate metadata + Metadata metadata = nodeTemplate.getMetadata(); + customizationUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); + addParameter("invariant_uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); + addParameter("uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_UUID)); + addParameter("version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VERSION)); + } + + public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Group group) { + + params = new HashMap(); + this.sdcCsarHelper = sdcCsarHelper; + + // extract group metadata + Metadata metadata = group.getMetadata(); + //customizationUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULECUSTOMIZATIONUUID); - returning null + customizationUUID = extractValue (metadata, "vfModuleModelCustomizationUUID"); + addParameter("invariant_uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)); + addParameter("uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)); + addParameter("version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)); + } + + protected void addParameter (String name, String value) { + if (value != null && !value.isEmpty()) { + params.put(name, "\"" + value + "\""); + } + } + + protected void addIntParameter (String name, String value) { + if (value != null && !value.isEmpty()) { + params.put(name, value); + } + } + + public static void addIntParameter (String name, String value, Map params) { + if (value != null && !value.isEmpty()) { + params.put(name, value); + } + } + + public static void addParameter (String name, String value, Map params) { + if (value != null && !value.isEmpty()) { + params.put(name, "\"" + value + "\""); + } + } + + protected String extractValue (Metadata metadata, String name) { + String value = sdcCsarHelper.getMetadataPropertyValue(metadata, name); + if (value != null) { + return value; + } else { + return ""; + } + } + + public static String extractValue (ISdcCsarHelper sdcCsarHelper, Metadata metadata, String name) { + String value = sdcCsarHelper.getMetadataPropertyValue(metadata, name); + if (value != null) { + return value; + } else { + return ""; + } + } + + protected String extractValue (NodeTemplate nodeTemplate, String name) { + String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); + if (value != null) { + return value; + } else { + return ""; + } + } + + public static String extractValue (ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, String name) { + String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); + if (value != null) { + return value; + } else { + return ""; + } + } + + protected String extractBooleanValue (NodeTemplate nodeTemplate, String name) { + String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); + if (value != null && !value.isEmpty()) { + return value.contains("true") ? "Y" : "N"; + } else { + return ""; + } + } + + public static String extractBooleanValue (ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, String name) { + String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); + if (value != null && !value.isEmpty()) { + return value.contains("true") ? "Y" : "N"; + } else { + return ""; + } + } + + protected String extractValue (Group group, String name) { + String value = sdcCsarHelper.getGroupPropertyLeafValue(group, name); + if (value != null) { + return value; + } else { + return ""; + } + } + + protected String extractBooleanValue (Group group, String name) { + String value = sdcCsarHelper.getGroupPropertyLeafValue(group, name); + if (value != null && !value.isEmpty()) { + return value.contains("true") ? "Y" : "N"; + } else { + return ""; + } + } + + protected String extractInputDefaultValue (String name) { + String value = sdcCsarHelper.getServiceInputLeafValueOfDefault(name); + if (value != null) { + return value; + } else { + return ""; + } + } + + protected String extractBooleanInputDefaultValue (String name) { + String value = sdcCsarHelper.getServiceInputLeafValueOfDefault(name); + if (value != null && !value.isEmpty()) { + return value.contains("true") ? "Y" : "N"; + } else { + return ""; + } + } + + public static String extractInputDefaultValue (ISdcCsarHelper sdcCsarHelper, String name) { + String value = sdcCsarHelper.getServiceInputLeafValueOfDefault(name); + if (value != null) { + return value; + } else { + return ""; + } + } + + public static String extractBooleanInputDefaultValue (ISdcCsarHelper sdcCsarHelper, String name) { + String value = sdcCsarHelper.getServiceInputLeafValueOfDefault(name); + if (value != null && !value.isEmpty()) { + return value.contains("true") ? "Y" : "N"; + } else { + return ""; + } + } + + public static String extractSubstitutionMappingTypeName (ISdcCsarHelper sdcCsarHelper) { + String value = sdcCsarHelper.getServiceSubstitutionMappingsTypeName(); + if (value != null) { + return value; + } else { + return ""; + } + } + + public String getCustomizationUUID() { + return ("\"" + customizationUUID + "\""); + } + public String getCustomizationUUIDNoQuotes() { + return (customizationUUID); + } + public void setCustomizationUUID(String customizationUUID) { + this.customizationUUID = customizationUUID; + } + + public String getSql(String tableName, String model_yaml) { + + StringBuilder sb = new StringBuilder(); + sb.append("INSERT into " + tableName + " (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 (" + 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 static String getSql(String tableName, String keyName, String keyValue, String model_yaml, Map params) { + + StringBuilder sb = new StringBuilder(); + sb.append("INSERT into " + tableName + " (" + keyName + ", "); + + int paramCount = 0; + for (String paramKey : params.keySet()) { + paramCount++; + sb.append(paramKey); + if (paramCount < params.size()) sb.append(", "); + } + + sb.append(") values (" + keyValue + ", "); + + 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(); + } + +} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncNodeModel.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncNodeModel.java new file mode 100644 index 000000000..f8e5a5b8f --- /dev/null +++ b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncNodeModel.java @@ -0,0 +1,145 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.openecomp.sdnc.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 static final Logger LOG = LoggerFactory + .getLogger(SdncNodeModel.class); + + 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 inputs + 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(); + } + +} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncOdlConnection.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncOdlConnection.java new file mode 100644 index 000000000..4e0cffab1 --- /dev/null +++ b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncOdlConnection.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.openecomp.sdnc.uebclient; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.Authenticator; +import java.net.HttpURLConnection; +import java.net.PasswordAuthentication; +import java.net.URL; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLSession; + +import org.apache.commons.codec.binary.Base64; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class SdncOdlConnection { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncOdlConnection.class); + + private HttpURLConnection httpConn = null; + + private String url = null; + private String user = null; + private String password = null; + + private class SdncAuthenticator extends Authenticator { + + private String user; + private String passwd; + + SdncAuthenticator(String user, String passwd) { + this.user = user; + this.passwd = passwd; + } + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(user, passwd.toCharArray()); + } + + } + + private SdncOdlConnection() { + + } + + private SdncOdlConnection(String url, String user, String password) { + this.url = url; + this.user = user; + this.password = password; + + try { + URL sdncUrl = new URL(url); + Authenticator.setDefault(new SdncAuthenticator(user, password)); + + this.httpConn = (HttpURLConnection) sdncUrl.openConnection(); + } catch (Exception e) { + LOG.error("Unable to create http connection", e); + } + } + + public static SdncOdlConnection newInstance(String url, String user, String password) throws IOException + { + return (new SdncOdlConnection(url, user, password)); + } + + + + public String send(String method, String contentType, String msg) throws IOException { + + LOG.info("Sending REST " + method + " to " + url); + LOG.info("Message body:\n" + msg); + String authStr = user + ":" + password; + String encodedAuthStr = new String(Base64.encodeBase64(authStr.getBytes())); + + httpConn.addRequestProperty("Authentication", "Basic " + encodedAuthStr); + + httpConn.setRequestMethod(method); + httpConn.setRequestProperty("Content-Type", contentType); + httpConn.setRequestProperty("Accept", contentType); + + httpConn.setDoInput(true); + httpConn.setDoOutput(true); + httpConn.setUseCaches(false); + + if (httpConn instanceof HttpsURLConnection) { + HostnameVerifier hostnameVerifier = new HostnameVerifier() { + @Override + public boolean verify(String hostname, SSLSession session) { + return true; + } + }; + ((HttpsURLConnection) httpConn).setHostnameVerifier(hostnameVerifier); + } + + // Write message + httpConn.setRequestProperty("Content-Length", "" + msg.length()); + DataOutputStream outStr = new DataOutputStream(httpConn.getOutputStream()); + outStr.write(msg.getBytes()); + outStr.close(); + + // Read response + BufferedReader respRdr; + + LOG.info("Response: " + httpConn.getResponseCode() + " " + httpConn.getResponseMessage()); + + if (httpConn.getResponseCode() < 300) { + + respRdr = new BufferedReader(new InputStreamReader(httpConn.getInputStream())); + } else { + respRdr = new BufferedReader(new InputStreamReader(httpConn.getErrorStream())); + } + + StringBuffer respBuff = new StringBuffer(); + + String respLn; + + while ((respLn = respRdr.readLine()) != null) { + respBuff.append(respLn + "\n"); + } + respRdr.close(); + + String respString = respBuff.toString(); + + LOG.info("Response body :\n" + respString); + + return (respString); + + } + + +} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncServiceModel.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncServiceModel.java new file mode 100644 index 000000000..0f645d7a3 --- /dev/null +++ b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncServiceModel.java @@ -0,0 +1,98 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.openecomp.sdnc.uebclient; + +import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; +import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames; +import org.openecomp.sdc.toscaparser.api.Metadata; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdncServiceModel extends SdncBaseModel { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncServiceModel.class); + + private String UUID = null; + private String serviceInstanceNamePrefix = null; + private String filename = null; + + public SdncServiceModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata) { + + super(sdcCsarHelper, metadata); + + UUID = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_UUID); + + // extract service topology template input data + addParameter("ecomp_naming",extractBooleanInputDefaultValue(SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_ECOMPGENERATEDNAMING)); + addParameter("naming_policy",extractInputDefaultValue(SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_NAMINGPOLICY)); + } + + public String getServiceUUID() { + return ("\"" + UUID + "\""); + } + public void setServiceUUID(String serviceUUID) { + this.UUID = serviceUUID; + } + public String getServiceInstanceNamePrefix() { + return serviceInstanceNamePrefix; + } + public void setServiceInstanceNamePrefix(String serviceInstanceNamePrefix) { + if (serviceInstanceNamePrefix != null && !serviceInstanceNamePrefix.isEmpty()) { + this.serviceInstanceNamePrefix = serviceInstanceNamePrefix; + params.put("service_instance_name_prefix", "\"" + serviceInstanceNamePrefix + "\""); + } + } + public String getFilename() { + return filename; + } + public void setFilename(String filename) { + this.filename = filename; + } + + public String getSql(String model_yaml) { + + StringBuilder sb = new StringBuilder(); + sb.append("INSERT into SERVICE_MODEL (service_uuid, model_yaml, filename, "); + + int paramCount = 0; + for (String paramKey : params.keySet()) { + paramCount++; + sb.append(paramKey); + if (paramCount < params.size()) sb.append(", "); + } + + sb.append(") values (" + getServiceUUID() + ", \"" + model_yaml + "\", \"" + filename + "\", "); + + 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(); + } + +} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebCallback.java new file mode 100644 index 000000000..496c2cef8 --- /dev/null +++ b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebCallback.java @@ -0,0 +1,1125 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.openecomp.sdnc.uebclient; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.net.Authenticator; +import java.net.HttpURLConnection; +import java.net.PasswordAuthentication; +import java.net.URL; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import javax.sql.rowset.CachedRowSet; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathFactory; + +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.lang3.tuple.Pair; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; +import org.openecomp.sdc.api.IDistributionClient; +import org.openecomp.sdc.api.consumer.IDistributionStatusMessage; +import org.openecomp.sdc.api.consumer.INotificationCallback; +import org.openecomp.sdc.api.notification.IArtifactInfo; +import org.openecomp.sdc.api.notification.INotificationData; +import org.openecomp.sdc.api.notification.IResourceInstance; +import org.openecomp.sdc.api.results.IDistributionClientDownloadResult; +import org.openecomp.sdc.api.results.IDistributionClientResult; +import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; +import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames; +import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory; +import org.openecomp.sdc.toscaparser.api.Group; +import org.openecomp.sdc.toscaparser.api.Metadata; +import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.openecomp.sdc.utils.ArtifactTypeEnum; +import org.openecomp.sdc.utils.DistributionActionResultEnum; +import org.openecomp.sdc.utils.DistributionStatusEnum; +import org.openecomp.sdnc.uebclient.SdncArtifactMap.SdncArtifactType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class SdncUebCallback implements INotificationCallback { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncUebCallback.class); + + private static DBResourceManager jdbcDataSource = null; + private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; + + + private class SdncAuthenticator extends Authenticator { + + private final String user; + private final String passwd; + + SdncAuthenticator(String user, String passwd) { + this.user = user; + this.passwd = passwd; + } + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(user, passwd.toCharArray()); + } + + } + + private class DeployableArtifact { + SdncArtifactType type; + IArtifactInfo artifactInfo; + String svcName; + String resourceName; + String artifactName; + String artifactVersion; + File file; + + public String getArtifactName() { + return artifactName; + } + + + + public String getArtifactVersion() { + return artifactVersion; + } + + + public SdncArtifactType getType() { + return type; + } + + + + public IArtifactInfo getArtifactInfo() { + return artifactInfo; + } + + + public File getFile() { + return file; + } + + + + + public DeployableArtifact(SdncArtifactType type, String svcName, String resourceName, IArtifactInfo artifactInfo, File file) { + this.type = type; + this.artifactInfo = artifactInfo; + this.svcName = svcName; + this.resourceName = resourceName; + this.artifactName = artifactInfo.getArtifactName(); + this.artifactVersion = artifactInfo.getArtifactVersion(); + this.file = file; + } + + + public DeployableArtifact(SdncArtifactType type, String svcName, String resourceName, String artifactName, String artifactVersion, File file) { + this.type = type; + this.artifactInfo = null; + this.svcName = svcName; + this.resourceName = resourceName; + this.artifactName = artifactName; + this.artifactVersion = artifactVersion; + this.file = file; + } + + + + public String getSvcName() { + return svcName; + } + + + + public String getResourceName() { + return resourceName; + } + + } + + private final IDistributionClient client; + private final SdncUebConfiguration config; + + private LinkedList deployList[]; + + private static void setJdbcDataSource() throws IOException { + + String propPath = null; + String propDir = System.getenv(SDNC_CONFIG_DIR); + if (propDir == null) { + + propDir = "/opt/sdnc/data/properties"; + } + propPath = propDir + "/dblib.properties"; + File propFile = new File(propPath); + + if (!propFile.exists()) { + + throw new FileNotFoundException( + "Missing configuration properties file : " + + propFile); + } + + Properties props = new Properties(); + props.load(new FileInputStream(propFile)); + + try { + jdbcDataSource = DBResourceManager.create(props); + } catch(Throwable exc) { + LOG.error("", exc); + } + + if(((DBResourceManager)jdbcDataSource).isActive()){ + LOG.warn( "DBLIB: JDBC DataSource has been initialized."); + } else { + LOG.warn( "DBLIB: JDBC DataSource did not initialize successfully."); + } + } + + private static void loadArtifactMap() { + + } + + public SdncUebCallback(IDistributionClient client, SdncUebConfiguration config) { + this.client = client; + this.config = config; + + } + + @Override + public void activateCallback(INotificationData data) { + + LOG.info("Received notification : ("+data.getDistributionID()+","+data.getServiceName()+","+data.getServiceVersion()+ + ","+data.getServiceDescription() + ")"); + + String incomingDirName = config.getIncomingDir(); + String archiveDirName = config.getArchiveDir(); + + File incomingDir = null; + File archiveDir = null; + + if (!incomingDir.exists()) { + incomingDir.mkdirs(); + } + + + if (!archiveDir.exists()) { + archiveDir.mkdirs(); + } + + // Process service level artifacts + List artifactList = data.getServiceArtifacts(); + + if (artifactList != null) { + + incomingDir = new File(incomingDirName + "/" + escapeFilename(data.getServiceName())); + if (!incomingDir.exists()) { + incomingDir.mkdirs(); + } + + archiveDir = new File(archiveDirName + "/" + escapeFilename(data.getServiceName())); + if (!archiveDir.exists()) { + archiveDir.mkdirs(); + } + for (IArtifactInfo curArtifact : artifactList) + { + + LOG.info("Received artifact " + curArtifact.getArtifactName()); + + handleArtifact(data, data.getServiceName(), null, null, curArtifact, incomingDir, archiveDir); + } + } + + + // Process resource level artifacts + for (IResourceInstance curResource : data.getResources()) { + + LOG.info("Received resource : "+curResource.getResourceName()); + artifactList = curResource.getArtifacts(); + + if (artifactList != null) { + + incomingDir = new File(incomingDirName + "/" + escapeFilename(data.getServiceName()) + "/" + escapeFilename(curResource.getResourceName())); + if (!incomingDir.exists()) { + incomingDir.mkdirs(); + } + + archiveDir = new File(archiveDirName + "/" + escapeFilename(data.getServiceName()) + "/" + escapeFilename(curResource.getResourceName())); + if (!archiveDir.exists()) { + archiveDir.mkdirs(); + } + for (IArtifactInfo curArtifact : artifactList) + { + + LOG.info("Received artifact " + curArtifact.getArtifactName()); + + handleArtifact(data, data.getServiceName(), curResource.getResourceName(), curResource.getResourceType(), curArtifact, incomingDir, archiveDir); + } + } + } + + deployDownloadedFiles(incomingDir, archiveDir, data); + + + } + + + public void deployDownloadedFiles(File incomingDir, File archiveDir, INotificationData data) { + + if (incomingDir == null) { + incomingDir = new File(config.getIncomingDir()); + + if (!incomingDir.exists()) { + incomingDir.mkdirs(); + } + + } + + if (archiveDir == null) { + archiveDir = new File(config.getArchiveDir()); + + if (!archiveDir.exists()) { + archiveDir.mkdirs(); + } + } + + String curFileName = ""; + try (DirectoryStream stream = Files.newDirectoryStream(incomingDir.toPath())) { + for (Path file: stream) { + curFileName = file.toString(); + handleSuccessfulDownload(null,null, null, null, file.toFile(), archiveDir); + } + } catch (Exception x) { + // IOException can never be thrown by the iteration. + // In this snippet, it can only be thrown by newDirectoryStream. + LOG.warn("Cannot process spool file "+ curFileName, x); + } + + // Deploy scheduled deployments + int numPasses = config.getMaxPasses(); + + deployList = new LinkedList[numPasses]; + + for (int i = 0 ; i < numPasses ; i++) { + deployList[i] = new LinkedList(); + } + for (int pass = 0 ; pass < config.getMaxPasses() ; pass++) { + + if (deployList[pass] != null) { + while (! deployList[pass].isEmpty()) { + DeployableArtifact artifact = deployList[pass].pop(); + + DistributionStatusEnum deployResult = DistributionStatusEnum.DEPLOY_ERROR; + + + try { + + deployResult = deploySpoolFile(artifact); + } catch (Exception e) { + LOG.error("Caught exception trying to deploy file", e); + } + + + IArtifactInfo artifactInfo = artifact.getArtifactInfo(); + + if ((artifactInfo != null) && (data != null)) { + IDistributionClientResult deploymentStatus; + deploymentStatus = client.sendDeploymentStatus(buildStatusMessage( + client, data, artifactInfo, + deployResult)); + } + + } + } + } + } + + private void handleArtifact(INotificationData data, String svcName, String resourceName, String resourceType, IArtifactInfo artifact, File incomingDir, File archiveDir) { + + // Download Artifact + IDistributionClientDownloadResult downloadResult = client + .download(artifact); + + if (downloadResult == null) { + + handleFailedDownload(data, artifact); + return; + } + + byte[] payloadBytes = downloadResult.getArtifactPayload(); + + if (payloadBytes == null) { + handleFailedDownload(data, artifact); + return; + } + + String payload = new String(payloadBytes); + + + File spoolFile = new File(incomingDir.getAbsolutePath() + "/" + artifact.getArtifactName()); + + boolean writeSucceeded = false; + + try { + FileWriter spoolFileWriter = new FileWriter(spoolFile); + spoolFileWriter.write(payload); + spoolFileWriter.close(); + writeSucceeded = true; + } catch (Exception e) { + LOG.error("Unable to save downloaded file to spool directory ("+ incomingDir.getAbsolutePath() +")", e); + } + + + if (writeSucceeded && (downloadResult.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS)) { + handleSuccessfulDownload(data, svcName, resourceName, artifact, spoolFile, archiveDir); + + + } else { + handleFailedDownload(data, artifact); + } + + } + + private void handleFailedDownload(INotificationData data, + IArtifactInfo relevantArtifact) { + // Send Download Status + IDistributionClientResult sendDownloadStatus = client + .sendDownloadStatus(buildStatusMessage(client, data, + relevantArtifact, DistributionStatusEnum.DOWNLOAD_ERROR)); + } + + private void handleSuccessfulDownload(INotificationData data, String svcName, String resourceName, + IArtifactInfo artifact, File spoolFile, File archiveDir) { + + if ((data != null) && (artifact != null)) { + // Send Download Status + IDistributionClientResult sendDownloadStatus = client + .sendDownloadStatus(buildStatusMessage(client, data, artifact, DistributionStatusEnum.DOWNLOAD_OK)); + } + + // If an override file exists, read that instead of the file we just downloaded + ArtifactTypeEnum artifactEnum = ArtifactTypeEnum.YANG_XML; + + boolean toscaYamlType = false; + if (artifact != null) { + String artifactTypeString = artifact.getArtifactType(); + if (artifactTypeString.contains("TOSCA_TEMPLATE")) { + toscaYamlType = true; + } + } else { + if (spoolFile.toString().contains(".yml") || spoolFile.toString().contains(".csar")) { + toscaYamlType = true; + } + } + String overrideFileName = config.getOverrideFile(); + if ((overrideFileName != null) && (overrideFileName.length() > 0)) { + File overrideFile = new File(overrideFileName); + + if (overrideFile.exists()) { + artifactEnum = ArtifactTypeEnum.YANG_XML; + spoolFile = overrideFile; + } + + } + + if (toscaYamlType == true) { + processToscaYaml (data, svcName, resourceName, artifact, spoolFile, archiveDir); + + try { + Path source = spoolFile.toPath(); + Path targetDir = archiveDir.toPath(); + + Files.move(source, targetDir.resolve(source.getFileName()), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + LOG.warn("Could not move "+spoolFile.getAbsolutePath()+" to "+archiveDir.getAbsolutePath(), e); + } + + return; + } + + // Process spool file + Document spoolDoc = null; + File transformedFile = null; + + // Apply XSLTs and get Doc object + try { + if (!spoolFile.isDirectory()) { + transformedFile = applyXslts(spoolFile); + } + } catch (Exception e) { + LOG.error("Caught exception trying to parse XML file", e); + } + + if (transformedFile != null) { + try { + + try { + + DocumentBuilderFactory dbf = DocumentBuilderFactory + .newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + + spoolDoc = db.parse(transformedFile); + } catch (Exception e) { + LOG.error( + "Caught exception trying to parse transformed XML file " + + transformedFile.getAbsolutePath(), e); + } + + } catch (Exception e) { + LOG.error("Caught exception trying to deploy file", e); + } + } + + + if (spoolDoc != null) { + // Analyze file type + SdncArtifactType artifactType = analyzeFileType(artifactEnum, + spoolFile, spoolDoc); + + if (artifactType != null) { + + scheduleDeployment(artifactType, svcName, resourceName, artifact, spoolFile.getName(), transformedFile); + + } + + // SDNGC-2660 : Move file to archive directory even if it is an unrecognized type so that + // we do not keep trying and failing to process it. + try { + Path source = spoolFile.toPath(); + Path targetDir = archiveDir.toPath(); + + Files.move(source, targetDir.resolve(source.getFileName()), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + LOG.warn("Could not move "+spoolFile.getAbsolutePath()+" to "+archiveDir.getAbsolutePath(), e); + } + } + + + } + + + private void processToscaYaml(INotificationData data, String svcName, String resourceName, + IArtifactInfo artifact, File spoolFile, File archiveDir) { + + // Use ASDC Dist Client 1.1.5 with TOSCA parsing APIs to extract relevant TOSCA model data + + // TOSCA data extraction flow 1707: + // Use ASDC dist-client to get yaml string - not yet available + String model_yaml = null; + LOG.info("Process TOSCA YAML file: "+spoolFile.toString()); + + SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); + ISdcCsarHelper sdcCsarHelper = null; + try { + sdcCsarHelper = factory.getSdcCsarHelper(spoolFile.getAbsolutePath()); + } catch (SdcToscaParserException e) { + LOG.error("Could not create SDC TOSCA Parser ", e); + factory.close(); + return; + } + + // Ingest Service Data - 1707 + Metadata serviceMetadata = sdcCsarHelper.getServiceMetadata(); + SdncServiceModel serviceModel = new SdncServiceModel(sdcCsarHelper, serviceMetadata); + serviceModel.setFilename(spoolFile.toString().substring(spoolFile.toString().lastIndexOf("/")+1)); // will be csar file name + serviceModel.setServiceInstanceNamePrefix(SdncBaseModel.extractSubstitutionMappingTypeName(sdcCsarHelper).substring(SdncBaseModel.extractSubstitutionMappingTypeName(sdcCsarHelper).lastIndexOf(".")+1)); + + try { + cleanUpExistingToscaServiceData(serviceModel.getServiceUUID()); + LOG.info("Call insertToscaData for SERVICE_MODEL serviceUUID = " + serviceModel.getServiceUUID()); + insertToscaData(serviceModel.getSql(model_yaml)); + } catch (IOException e) { + LOG.error("Could not insert Tosca YAML data into the SERVICE_MODEL table ", e); + factory.close(); + return; + } + + // Ingest Network (VL) Data - 1707 + //List vlNodeTemplatesList = sdcCsarHelper.getServiceNodeTemplatesByType("VL"); + List vlNodeTemplatesList = sdcCsarHelper.getServiceVlList(); + + for (NodeTemplate nodeTemplate : vlNodeTemplatesList) { + SdncNodeModel nodeModel = new SdncNodeModel (sdcCsarHelper, nodeTemplate); + nodeModel.setServiceUUID(serviceModel.getServiceUUID()); + nodeModel.setEcompGeneratedNaming(SdncBaseModel.extractBooleanInputDefaultValue(sdcCsarHelper, SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_ECOMPGENERATEDNAMING));//service_naming#default#ecomp_generated_naming + + try { + cleanUpExistingToscaData("NETWORK_MODEL", "customization_uuid", nodeModel.getCustomizationUUID()); + cleanUpExistingToscaData("VPN_BINDINGS", "network_customization_uuid", nodeModel.getCustomizationUUID()); + LOG.info("Call insertToscaData for NETWORK_MODEL customizationUUID = " + nodeModel.getCustomizationUUID()); + // using ASDC dist-client use method for get yaml string + insertToscaData(nodeModel.getSql(model_yaml)); + insertToscaData(nodeModel.getVpnBindingsSql()); + } catch (IOException e) { + LOG.error("Could not insert Tosca YAML data into the NETWORK_MODEL table ", e); + } + } + + // Ingest Allotted Resource Data - 1707 + List arNodeTemplatesList = sdcCsarHelper.getAllottedResources(); + + for (NodeTemplate nodeTemplate : arNodeTemplatesList) { + SdncARModel nodeModel = new SdncARModel (sdcCsarHelper, nodeTemplate); + + try { + cleanUpExistingToscaData("ALLOTTED_RESOURCE_MODEL", "customization_uuid", nodeModel.getCustomizationUUID()); + LOG.info("Call insertToscaData for ALLOTTED_RESOURCE_MODEL customizationUUID = " + nodeModel.getCustomizationUUID()); + // using ASDC dist-client use method for get yaml string + insertToscaData(nodeModel.getSql("ALLOTTED_RESOURCE_MODEL", model_yaml)); + } catch (IOException e) { + LOG.error("Could not insert Tosca YAML data into the NETWORK_MODEL table ", e); + } + } + + // Ingest Network (VF) Data - 1707 + //List nodeTemplatesList = sdcCsarHelper.getServiceNodeTemplatesByType("VF"); + List vfNodeTemplatesList = sdcCsarHelper.getServiceVfList(); + + for (NodeTemplate nodeTemplate : vfNodeTemplatesList) { + SdncVFModel vfNodeModel = new SdncVFModel (sdcCsarHelper, nodeTemplate); + + try { + cleanUpExistingToscaData("VF_MODEL", "customization_uuid", vfNodeModel.getCustomizationUUID()) ; + LOG.info("Call insertToscaData for VF_MODEL customizationUUID = " + vfNodeModel.getCustomizationUUID()); + insertToscaData(vfNodeModel.getSql("VF_MODEL", model_yaml)); + } catch (IOException e) { + LOG.error("Could not insert Tosca YAML data into the VF_MODEL table ", e); + } + + // For each VF, insert VF_MODULE_MODEL data + List vfModules = sdcCsarHelper.getVfModulesByVf(vfNodeModel.getCustomizationUUIDNoQuotes()); + for (Group group : vfModules){ + SdncVFModuleModel vfModuleModel = new SdncVFModuleModel(sdcCsarHelper, group); + + try { + cleanUpExistingToscaData("VF_MODULE_MODEL", "customization_uuid", vfModuleModel.getCustomizationUUID()); + LOG.info("Call insertToscaData for VF_MODULE_MODEL customizationUUID = " + vfModuleModel.getCustomizationUUID()); + insertToscaData(vfModuleModel.getSql("VF_MODULE_MODEL", model_yaml)); + } catch (IOException e) { + LOG.error("Could not insert Tosca YAML data into the VF_MODULE_MODEL table ", e); + } + + // For each VF Module, get the VFC list, insert VF_MODULE_TO_VFC_MAPPING data + // List groupMembers = sdcCsarHelper.getMembersOfGroup(group); - old version + // For each vfcNode (group member) in the groupMembers list, extract vm_type and vm_count. + // Insert vf_module.customizationUUID, vfcNode.customizationUUID and vm_type and vm_count into VF_MODULE_TO_VFC_MAPPING + List groupMembers = sdcCsarHelper.getMembersOfVfModule(nodeTemplate, group); // not yet available + for (NodeTemplate vfcNode : groupMembers){ + SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, vfcNode); + + try { + cleanUpExistingToscaData("VF_MODULE_TO_VFC_MAPPING", "vf_module_customization_uuid", vfModuleModel.getCustomizationUUID()); + LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING customizationUUID = " + vfModuleModel.getCustomizationUUID()); + insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" + + vfModuleModel.getCustomizationUUID() + ", " + vfcModel.getCustomizationUUID() + ", \"" + vfcModel.getVmType() + "\", \"" + vfcModel.getVmCount() + "\")"); + } catch (IOException e) { + LOG.error("Could not insert Tosca YAML data into the VF_MODULE_TO_VFC_MAPPING table ", e); + } + + } + + } + + // For each VF, insert VFC_MODEL data + List vfcNodes = sdcCsarHelper.getVfcListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()); + for (NodeTemplate vfcNode : vfcNodes){ + SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, vfcNode); + + try { + cleanUpExistingToscaData("VFC_MODEL", "customization_uuid", vfcModel.getCustomizationUUID()); + LOG.info("Call insertToscaData for VFC_MODEL customizationUUID = " + vfcModel.getCustomizationUUID()); + insertToscaData(vfcModel.getSql("VFC_MODEL", model_yaml)); + } catch (IOException e) { + LOG.error("Could not insert Tosca YAML data into the VFC_MODEL table ", e); + } + + } + + // For each VF, insert VF_TO_NETWORK_ROLE_MAPPING data + List cpNodes = sdcCsarHelper.getCpListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()); + for (NodeTemplate cpNode : cpNodes){ + + // Insert into VF_TO_NETWORK_ROLE_MAPPING vf_customization_uuid and network_role + String cpNetworkRole = sdcCsarHelper.getNodeTemplatePropertyLeafValue(cpNode, "network_role_tag"); + + try { + cleanUpExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", "vf_customization_uuid", vfNodeModel.getCustomizationUUID()); + LOG.info("Call insertToscaData for VF_TO_NETWORK_ROLE_MAPPING vfCustomizationUUID = " + vfNodeModel.getCustomizationUUID()); + insertToscaData("insert into VF_TO_NETWORK_ROLE_MAPPING (vf_customization_uuid, network_role) values (" + + vfNodeModel.getCustomizationUUID() + ", \"" + cpNetworkRole + "\")"); + } catch (IOException e) { + LOG.error("Could not insert Tosca YAML data into the VF_TO_NETWORK_ROLE_MAPPING table ", e); + } + + // Insert VFC_TO_NETWORK_ROLE_MAPPING data + Map mappingParams = new HashMap(); + //String cpNetworkRoleTag = "\"" + sdcCsarHelper.getNodeTemplatePropertyLeafValue(cpNode, SdcPropertyNames.PROPERTY_NAME_NETWORKROLETAG) + "\""; + // extract network_role, network_role_tag and virtual_binding from this cpNode + SdncBaseModel.addParameter("network_role", SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "network_role"), mappingParams); + SdncBaseModel.addParameter("network_role_tag", SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "network_role_tag"), mappingParams); + String virtualBinding = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "requirements#virtualBinding") + "\""; + + // get list of cpNodes and vfcNodes with matching virtualBinding + List> matchList = sdcCsarHelper.getNodeTemplatePairsByReqName(sdcCsarHelper.getCpListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()), sdcCsarHelper.getVfcListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()), virtualBinding); + for (Pair match : matchList) { // should be 1 match? + + // extract values from the left "CP" Node + SdncBaseModel.addParameter("ipv4_use_dhcp", SdncBaseModel.extractBooleanValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_DHCPENABLED), mappingParams); + //SdncBaseModel.addParameter("ipv4_ip_version", SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_IPVERSION), mappingParams); + SdncBaseModel.addParameter("ipv4_ip_version", "dummy_ipv4_vers", mappingParams); + SdncBaseModel.addParameter("ipv6_use_dhcp", SdncBaseModel.extractBooleanValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_DHCPENABLED), mappingParams); + //SdncBaseModel.addParameter("ipv6_ip_version", SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_IPVERSION), mappingParams); + SdncBaseModel.addParameter("ipv6_ip_version", "dummy_ipv6_vers", mappingParams); + //String extcp_subnetpool_id = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_SUBNETPOOLID) + "\""; // need path to subnetpoolid + + // extract values from the right "VFC" Node + String vfcCustomizationUuid = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, match.getRight().getMetadata(), "customization_uuid") + "\""; + SdncBaseModel.addParameter("vm_type", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_VMTYPE), mappingParams); + SdncBaseModel.addIntParameter("ipv4_count", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT), mappingParams); + SdncBaseModel.addIntParameter("ipv6_count", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT), mappingParams); + + try { + cleanUpExistingToscaData("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", vfcCustomizationUuid); + LOG.info("Call insertToscaData for VFC_TO_NETWORK_ROLE_MAPPING vfcCustomizationUUID = " + vfcCustomizationUuid); + insertToscaData(SdncBaseModel.getSql("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", vfcCustomizationUuid, "", mappingParams)); + } catch (IOException e) { + LOG.error("Could not insert Tosca YAML data into the VFC_TO_NETWORK_ROLE_MAPPING table ", e); + } + + } + + } // CP loop + + } // VF loop + + // Close ASDC TOSCA Parser factory - we are done processing this distribution + factory.close(); + + if ((artifact != null) && (data != null)) { + LOG.info("Update to SDN-C succeeded"); + IDistributionClientResult deploymentStatus; + deploymentStatus = client.sendDeploymentStatus(buildStatusMessage( + client, data, artifact, + DistributionStatusEnum.DEPLOY_OK)); + } + + } + + private void cleanUpExistingToscaData(String tableName, String keyName, String keyValue) throws IOException + { + + if (jdbcDataSource == null) { + setJdbcDataSource(); + } + try { + int rowCount = 0; + CachedRowSet data = jdbcDataSource.getData("SELECT * from " + tableName + " where " + keyName + " = " + keyValue + ";", null, ""); + while(data.next()) { + rowCount ++; + } + if (rowCount != 0) { + LOG.info("cleanUpExistingToscaData: " + keyValue); + jdbcDataSource.writeData("DELETE from " + tableName + " where " + keyName + " = " + keyValue + ";", null, null); + } + + } catch (SQLException e) { + LOG.error("Could not clean up existing " + tableName + " for " + keyValue, e); + } + + } + + + private void cleanUpExistingToscaServiceData(String serviceUUID) throws IOException + { + + if (jdbcDataSource == null) { + setJdbcDataSource(); + } + try { + int rowCount = 0; + CachedRowSet data = jdbcDataSource.getData("SELECT * from SERVICE_MODEL where service_uuid = " + serviceUUID + ";", null, ""); + while(data.next()) { + rowCount ++; + } + if (rowCount != 0) { + LOG.info("cleanUpExistingToscaData: " + serviceUUID); + jdbcDataSource.writeData("DELETE from NETWORK_MODEL where service_uuid = " + serviceUUID + ";", null, null); + jdbcDataSource.writeData("DELETE from SERVICE_MODEL where service_uuid = " + serviceUUID + ";", null, null); + } + + } catch (SQLException e) { + LOG.error("Could not clean up existing NETWORK_MODEL and SERVICE_MODEL for service_UUID " + serviceUUID, e); + } + + } + + + private void insertToscaData(String toscaDataString) throws IOException + { + LOG.debug("insertToscaData: " + toscaDataString); + + if (jdbcDataSource == null) { + setJdbcDataSource(); + } + try { + + jdbcDataSource.writeData(toscaDataString, null, null); + + } catch (SQLException e) { + LOG.error("Could not insert Tosca YAML data into the database ", e); + } + + } + + + private SdncArtifactType analyzeFileType(ArtifactTypeEnum artifactType, File spoolFile, Document spoolDoc) { + + if (artifactType != ArtifactTypeEnum.YANG_XML) { + LOG.error("Unexpected artifact type - expecting YANG_XML, got "+artifactType); + return (null); + } + + // Examine outer tag + + try { + + + Element root = spoolDoc.getDocumentElement(); + + String rootName = root.getTagName(); + + if (rootName.contains(":")) { + String[] rootNameElems = rootName.split(":"); + rootName = rootNameElems[rootNameElems.length - 1]; + } + + if (rootName != null) { + SdncArtifactType mapEntry = config.getMapping(rootName); + + + if (mapEntry == null) { + + LOG.error("Unexpected file contents - root tag is "+rootName); + } + return(mapEntry); + } else { + LOG.error("Cannot get root tag from file"); + return(null); + } + + } catch (Exception e) { + LOG.error("Could not parse YANG_XML file "+spoolFile.getName(), e); + return(null); + } + } + + private void scheduleDeployment(SdncArtifactType type, String svcName, String resourceName, IArtifactInfo artifactInfo, String spoolFileName, File spoolFile) { + + if (type.getPass() < deployList.length) { + + if (artifactInfo != null) { + LOG.debug("Scheduling "+artifactInfo.getArtifactName()+" version "+artifactInfo.getArtifactVersion()+" for deployment"); + + deployList[type.getPass()].add(new DeployableArtifact(type, svcName, resourceName, artifactInfo, spoolFile)); + } else { + SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss.SSS");//dd/MM/yyyy + Date now = new Date(); + String artifactVersion = sdfDate.format(now); + LOG.debug("Scheduling "+spoolFileName+" version "+artifactVersion+" for deployment"); + String artifactName = spoolFileName; + if (artifactInfo != null) { + artifactName = artifactInfo.getArtifactName(); + } + deployList[type.getPass()].add(new DeployableArtifact(type, svcName, resourceName, artifactName, artifactVersion, spoolFile)); + } + } else { + LOG.info("Pass for type "+type.getTag()+" is "+type.getPass()+" which is not <= "+deployList.length); + } + } + + + private DistributionStatusEnum deploySpoolFile(DeployableArtifact artifact) { + + DistributionStatusEnum deployResult = DistributionStatusEnum.DEPLOY_OK; + + StringBuffer msgBuffer = new StringBuffer(); + + + String namespace = config.getAsdcApiNamespace(); + if ((namespace == null) || (namespace.length() == 0)) { + namespace="com:att:sdnctl:asdcapi"; + } + + msgBuffer.append("\n"); + + String svcName = artifact.getSvcName(); + String resourceName = artifact.getResourceName(); + String artifactName = artifact.getArtifactName(); + + if (svcName != null) { + if (resourceName != null) { + artifactName = svcName + "/" + resourceName + "/" + artifactName; + } else { + artifactName = svcName + "/" + artifactName; + } + } + + msgBuffer.append(""+artifactName+"\n"); + msgBuffer.append(""+artifact.getArtifactVersion()+"\n"); + + + try { + BufferedReader rdr = new BufferedReader(new FileReader(artifact.getFile())); + + String curLine = rdr.readLine(); + + while (curLine != null) { + + if (!curLine.startsWith("\n"); + + + byte[] msgBytes = msgBuffer.toString().getBytes(); + + Document results = postRestXml(artifact.getType().getRpcUrl(config.getAsdcApiBaseUrl()), msgBytes); + + if (results == null) { + + deployResult = DistributionStatusEnum.DEPLOY_ERROR; + } else { + + XPathFactory xpf = XPathFactory.newInstance(); + XPath xp = xpf.newXPath(); + + String asdcApiResponseCode = "500"; + + try { + + asdcApiResponseCode = xp.evaluate("//asdc-api-response-code[position()=1]/text()", results.getDocumentElement()); + } catch (Exception e) { + LOG.error("Caught exception retrying to evaluate xpath", e); + } + + if (asdcApiResponseCode.contains("200")) { + LOG.info("Update to SDN-C succeeded"); + deployResult = DistributionStatusEnum.DEPLOY_OK; + } else { + LOG.info("Update to SDN-C failed (response code "+asdcApiResponseCode+")"); + + if (asdcApiResponseCode.contains("409")) { + deployResult = DistributionStatusEnum.ALREADY_DEPLOYED; + } else { + + deployResult = DistributionStatusEnum.DEPLOY_ERROR; + } + } + } + + + + return(deployResult); + } + + + + + + public static IDistributionStatusMessage buildStatusMessage( + final IDistributionClient client, final INotificationData data, + final IArtifactInfo relevantArtifact, + final DistributionStatusEnum status) { + IDistributionStatusMessage statusMessage = new IDistributionStatusMessage() { + + @Override + public long getTimestamp() { + long currentTimeMillis = System.currentTimeMillis(); + return currentTimeMillis; + } + + @Override + public DistributionStatusEnum getStatus() { + return status; + } + + @Override + public String getDistributionID() { + return data.getDistributionID(); + } + + @Override + public String getConsumerID() { + return client.getConfiguration().getConsumerID(); + } + + @Override + public String getArtifactURL() { + return relevantArtifact.getArtifactURL(); + } + }; + return statusMessage; + + } + + private HttpURLConnection getRestXmlConnection(String urlString, String method) throws IOException + { + URL sdncUrl = new URL(urlString); + Authenticator.setDefault(new SdncAuthenticator(config.getSdncUser(), config.getSdncPasswd())); + + HttpURLConnection conn = (HttpURLConnection) sdncUrl.openConnection(); + + String authStr = config.getSdncUser()+":"+config.getSdncPasswd(); + String encodedAuthStr = new String(Base64.encodeBase64(authStr.getBytes())); + + conn.addRequestProperty("Authentication", "Basic "+encodedAuthStr); + + conn.setRequestMethod(method); + conn.setRequestProperty("Content-Type", "application/xml"); + conn.setRequestProperty("Accept", "application/xml"); + + conn.setDoInput(true); + conn.setDoOutput(true); + conn.setUseCaches(false); + + return(conn); + + } + + private Document postRestXml(String urlString, byte[] msgBytes) { + Document response = null; + + try { + SdncOdlConnection odlConn = SdncOdlConnection.newInstance(urlString, config.getSdncUser(), config.getSdncPasswd()); + + String sdncResp = odlConn.send("POST", "application/xml", new String(msgBytes)); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + + + response = db.parse(new ByteArrayInputStream(sdncResp.getBytes())); + } catch (Exception e) { + LOG.error("Caught exception posting to ODL tier", e); + } + + return(response); + + } + + private File applyXslts(File srcFile) { + + Document doc = null; + + + File inFile = srcFile; + File outFile = null; + + String xsltPathList = config.getXsltPathList(); + + if ((xsltPathList == null) || (xsltPathList.length() == 0)) { + outFile = inFile; + } else { + + String[] xsltPaths = xsltPathList.split(","); + + for (String xsltPath : xsltPaths) { + try{ + + outFile = File.createTempFile("tmp", "xml"); + TransformerFactory factory = TransformerFactory.newInstance(); + Source xslt = new StreamSource(new File(xsltPath)); + Transformer transformer = factory.newTransformer(xslt); + Source text = new StreamSource(inFile); + + + transformer.transform(text, new StreamResult(outFile)); + + inFile = outFile; + + } catch (Exception e) { + LOG.error("Caught exception trying to apply XSLT template "+xsltPath, e); + + } + + } + } + + // After transformations, parse transformed XML + + + return(outFile); + } + + private String escapeFilename(String str) { + StringBuffer retval = new StringBuffer(); + + for (int i = 0 ; i < str.length() ; i++) { + char curchar = str.charAt(i); + if (Character.isJavaIdentifierPart(curchar)) { + retval.append(curchar); + } + } + + return(retval.toString()); + + } + +} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebClient.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebClient.java new file mode 100644 index 000000000..df5dfc0a9 --- /dev/null +++ b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebClient.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.openecomp.sdnc.uebclient; + +import org.openecomp.sdc.api.IDistributionClient; +import org.openecomp.sdc.api.results.IDistributionClientResult; +import org.openecomp.sdc.impl.DistributionClientFactory; +import org.openecomp.sdc.utils.DistributionActionResultEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdncUebClient { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncUebConfiguration.class); + + public static void main(String[] args) { + IDistributionClient client = DistributionClientFactory + .createDistributionClient(); + + SdncUebConfiguration config = new SdncUebConfiguration(); + + SdncUebCallback cb = new SdncUebCallback(client, config); + + LOG.info("Scanning for local distribution artifacts before starting client"); + cb.deployDownloadedFiles(null, null, null); + + LOG.info("Initializing ASDC distribution client"); + + IDistributionClientResult result = client.init( + config, cb); + + LOG.info("Initialized ASDC distribution client - results = " + + result.getDistributionMessageResult()); + + if (result.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) { + LOG.info("Starting client..."); + IDistributionClientResult start = client.start(); + LOG.info("Client startup result = " + + start.getDistributionMessageResult()); + } + + + } + +} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebConfiguration.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebConfiguration.java new file mode 100644 index 000000000..7855b5ba4 --- /dev/null +++ b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebConfiguration.java @@ -0,0 +1,280 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.openecomp.sdnc.uebclient; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; + +import org.openecomp.sdc.api.consumer.IConfiguration; +import org.openecomp.sdc.utils.ArtifactTypeEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdncUebConfiguration implements IConfiguration{ + + private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; + private static final Logger LOG = LoggerFactory + .getLogger(SdncUebConfiguration.class); + + private String asdcAddress = null; + private String consumerGroup = null; + private String consumerID = null; + private String environmentName = null; + private String password = null; + private int pollingInterval = 30; + private int pollingTimeout = 15; + private List relevantArtifactTypes = null; + private String user = null; + + private String sdncUser = null; + private String sdncPasswd = null; + private String asdcApiBaseUrl = null; + private String asdcApiNamespace = null; + + private SdncArtifactMap artifactMap = SdncArtifactMap.getInstance(); + + public String getAsdcApiNamespace() { + return asdcApiNamespace; + } + + private String incomingDir = null; + + private String archiveDir = null; + + private String overrideFile = null; + + private boolean activateServerTLSAuth; + private String keyStorePassword; + private String keyStorePath; + + private String xsltPathList; + + public String getXsltPathList() { + return xsltPathList; + } + + public String getOverrideFile() { + return overrideFile; + } + + public SdncUebConfiguration() { + + try { + init(); + } catch (Exception e) { + LOG.error("Cannot initialize SdncUebConfiguration", e); + } + } + + public void init() throws IOException { + String propPath = null; + String propDir = System.getenv(SDNC_CONFIG_DIR); + if (propDir == null) { + + propDir = "/opt/sdnc/data/properties"; + } + propPath = propDir + "/ueb-listener.properties"; + File propFile = new File(propPath); + + + if (!propFile.exists()) { + + throw new FileNotFoundException( + "Missing configuration properties file : " + + propFile); + } + + Properties props = new Properties(); + props.load(new FileInputStream(propFile)); + + asdcAddress = props.getProperty("org.openecomp.sdnc.uebclient.asdc-address"); + consumerGroup = props.getProperty("org.openecomp.sdnc.uebclient.consumer-group"); + consumerID = props.getProperty("org.openecomp.sdnc.uebclient.consumer-id"); + environmentName = props.getProperty("org.openecomp.sdnc.uebclient.environment-name"); + password = props.getProperty("org.openecomp.sdnc.uebclient.password"); + user = props.getProperty("org.openecomp.sdnc.uebclient.user"); + + sdncUser = props.getProperty("org.openecomp.sdnc.uebclient.sdnc-user"); + sdncPasswd = props.getProperty("org.openecomp.sdnc.uebclient.sdnc-passwd"); + asdcApiBaseUrl = props.getProperty("org.openecomp.sdnc.uebclient.asdc-api-base-url"); + asdcApiNamespace = props.getProperty("org.openecomp.sdnc.uebclient.asdc-api-namespace"); + + incomingDir = props.getProperty("org.openecomp.sdnc.uebclient.spool.incoming"); + archiveDir = props.getProperty("org.openecomp.sdnc.uebclient.spool.archive"); + overrideFile = props.getProperty("org.openecomp.sdnc.uebclient.override-file"); + + String curval = props.getProperty("org.openecomp.sdnc.uebclient.polling-interval"); + if ((curval != null) && (curval.length() > 0)) { + try { + pollingInterval = Integer.parseInt(curval); + } catch (Exception e) { + LOG.warn("Illegal value for org.openecomp.sdnc.uebclient.polling-interval ("+curval+")"); + } + } + + curval = props.getProperty("org.openecomp.sdnc.uebclient.polling-timeout"); + if ((curval != null) && (curval.length() > 0)) { + try { + pollingTimeout = Integer.parseInt(curval); + } catch (Exception e) { + LOG.warn("Illegal value for org.openecomp.sdnc.uebclient.polling-timeout ("+curval+")"); + } + } + + curval = props.getProperty("org.openecomp.sdnc.uebclient.relevant-artifact-types"); + if ((curval != null) && (curval.length() > 0)) { + String[] artifactTypes = curval.split(","); + + relevantArtifactTypes = new LinkedList(); + + for (int i = 0 ; i < artifactTypes.length ; i++) { + try { + if (ArtifactTypeEnum.valueOf(artifactTypes[i]) != null) { + relevantArtifactTypes.add(artifactTypes[i]); + } else { + LOG.warn("Skipping unrecognized artifact type "+artifactTypes[i]); + } + } catch (Exception e) { + + LOG.warn("Caught exception validating artifact type "+artifactTypes[i], e); + } + + } + + } + + curval = props.getProperty("org.openecomp.sdnc.uebclient.activate-server-tls-auth", "false"); + activateServerTLSAuth = "true".equalsIgnoreCase(curval); + keyStorePath = props.getProperty("org.openecomp.sdnc.uebclient.keystore-path"); + keyStorePassword = props.getProperty("org.openecomp.sdnc.uebclient.keystore-password"); + xsltPathList = props.getProperty("org.openecomp.sdnc.uebclient.xslt-path-list"); + + + String artifactMapFile = props.getProperty("org.openecomp.sdnc.uebclient.artifact-map"); + if (artifactMapFile != null) { + artifactMap.load(artifactMapFile); + } + + } + + @Override + public String getAsdcAddress() { + return asdcAddress; + } + + @Override + public String getConsumerGroup() { + return consumerGroup; + } + + @Override + public String getConsumerID() { + return consumerID; + } + + @Override + public String getEnvironmentName() { + return environmentName; + } + + @Override + public String getPassword() { + return password; + } + + @Override + public int getPollingInterval() { + return pollingInterval; + } + + @Override + public int getPollingTimeout() { + return pollingTimeout; + } + + @Override + public List getRelevantArtifactTypes() { + return relevantArtifactTypes; + } + + @Override + public String getUser() { + return user; + } + + + public String getSdncUser() { + return sdncUser; + } + + public String getSdncPasswd() { + return sdncPasswd; + } + + public String getAsdcApiBaseUrl() { + return asdcApiBaseUrl; + } + + @Override + public boolean activateServerTLSAuth() { + return activateServerTLSAuth; + } + + @Override + public String getKeyStorePassword() { + return keyStorePassword; + } + + @Override + public String getKeyStorePath() { + return keyStorePath; + } + + public String getIncomingDir() { + return incomingDir; + } + + public String getArchiveDir() { + return archiveDir; + } + + public int getMaxPasses() { + return(artifactMap.getNumPasses()); + } + + public SdncArtifactMap.SdncArtifactType getMapping(String tag) { + return(artifactMap.getMapping(tag)); + } + + @Override + public boolean isFilterInEmptyResources() { + // TODO Auto-generated method stub + return false; + } + + +} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFCModel.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFCModel.java new file mode 100644 index 000000000..67b786896 --- /dev/null +++ b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFCModel.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.openecomp.sdnc.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 SdncVFCModel extends SdncBaseModel { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncVFCModel.class); + + private String vmType = null; + private String vmCount = null; + + public SdncVFCModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { + + super(sdcCsarHelper, nodeTemplate); + + // extract properties + vmType = extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VMTYPE); + //vmCount = extractValue (sdcCsarHelper, nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VMCOUNT); - need path to vm_count + vmCount = "1"; + addParameter("vm_type", vmType); + addParameter("vm_type_tag", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG)); + addParameter("ecomp_generated_naming", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VFCNAMING_ECOMPGENERATEDNAMING)); + addParameter("naming_policy", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VFCNAMING_NAMINGPOLICY)); + addParameter("nfc_naming_code", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFCCODE)); + } + + public String getVmType() { + return vmType; + } + + public void setVmType(String vmType) { + this.vmType = vmType; + } + + public String getVmCount() { + return vmCount; + } + + public void setVmCount(String vmCount) { + this.vmCount = vmCount; + } + +} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFModel.java new file mode 100644 index 000000000..4e95e46ba --- /dev/null +++ b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFModel.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.openecomp.sdnc.uebclient; + +import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; +import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames; +import org.openecomp.sdc.toscaparser.api.Metadata; +import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdncVFModel extends SdncBaseModel { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncVFModel.class); + + public SdncVFModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { + + super(sdcCsarHelper, nodeTemplate); + + // extract metadata + Metadata metadata = nodeTemplate.getMetadata(); + addParameter("name", extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_NAME)); + addParameter("vendor", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDOR)); + addParameter("vendor_version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDORRELEASE)); + + // extract properties + addParameter("ecomp_generated_naming", extractBooleanValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VNFECOMPNAMING_ECOMPGENERATEDNAMING)); + addParameter("naming_policy", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VNFECOMPNAMING_NAMINGPOLICY)); + addParameter("nf_type", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)); + addParameter("nf_role", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)); + addParameter("nf_code", extractValue( nodeTemplate, "nf_naming_code")); + addParameter("nf_function", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)); + addParameter("avail_zone_max_count", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONEMAXCOUNT)); + } + +} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFModuleModel.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFModuleModel.java new file mode 100644 index 000000000..86df8b2ab --- /dev/null +++ b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFModuleModel.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.openecomp.sdnc.uebclient; + +import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; +import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames; +import org.openecomp.sdc.toscaparser.api.Group; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdncVFModuleModel extends SdncBaseModel { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncVFModuleModel.class); + + public SdncVFModuleModel(ISdcCsarHelper sdcCsarHelper, Group group) { + + super(sdcCsarHelper, group); + + // extract properties + addParameter("vf_module_type", extractValue(group, SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE)); + addIntParameter("availability_zone_count", extractValue(group, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)); + addParameter("ecomp_generated_vm_assignments", extractBooleanValue(group, SdcPropertyNames.PROPERTY_NAME_ECOMPGENERATEDVMASSIGNMENTS)); + } + +} diff --git a/ueb-listener/src/main/resources/log4j.properties b/ueb-listener/src/main/resources/log4j.properties new file mode 100644 index 000000000..670e48e11 --- /dev/null +++ b/ueb-listener/src/main/resources/log4j.properties @@ -0,0 +1,37 @@ +### +# ============LICENSE_START======================================================= +# openECOMP : SDN-C +# ================================================================================ +# Copyright (C) 2017 ONAP 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========================================================= +### + +log4j.rootLogger=DEBUG,CONSOLE,LOGFILE + +# CONSOLE is set to be a ConsoleAppender using a PatternLayout. +log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +log4j.appender.CONSOLE.Threshold=ERROR +log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +log4j.appender.CONSOLE.layout.ConversionPattern=%p %d{yyyy-MM-dd HH:mm:ss.SSS Z} %c{1} - %m%n + +# LOGFILE is set to be a File appender using a PatternLayout. +log4j.appender.LOGFILE=org.apache.log4j.RollingFileAppender +log4j.appender.LOGFILE.File=/opt/app/ueb-listener/logs/ueb-listener.log +log4j.appender.LOGFILE.Append=true +log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout +log4j.appender.LOGFILE.layout.ConversionPattern=%p %d{yyyy-MM-dd HH:mm:ss.SSS Z} %c{1} - %m%n +log4j.appender.LOGFILE.MaxFileSize=10MB +log4j.appender.LOGFILE.MaxBackupIndex=10 diff --git a/ueb-listener/src/main/resources/normalizeTagNames.xslt b/ueb-listener/src/main/resources/normalizeTagNames.xslt new file mode 100755 index 000000000..6594ccfa0 --- /dev/null +++ b/ueb-listener/src/main/resources/normalizeTagNames.xslt @@ -0,0 +1,14 @@ + + + + + + + + + + num of software instances + + + diff --git a/ueb-listener/src/main/resources/removeNs.xslt b/ueb-listener/src/main/resources/removeNs.xslt new file mode 100755 index 000000000..7aa927b14 --- /dev/null +++ b/ueb-listener/src/main/resources/removeNs.xslt @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ueb-listener/src/main/scripts/start-ueb-listener.sh b/ueb-listener/src/main/scripts/start-ueb-listener.sh new file mode 100644 index 000000000..db00726be --- /dev/null +++ b/ueb-listener/src/main/scripts/start-ueb-listener.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +### +# ============LICENSE_START======================================================= +# openECOMP : SDN-C +# ================================================================================ +# Copyright (C) 2017 ONAP 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========================================================= +### + +PROPERTY_DIR=${PROPERTY_DIR:-/opt/sdnc/data/properties} + + +LISTENER=ueb-listener + +PIDFILE=/tmp/.${LISTENER}-pid +UEBLISTENERROOT=${UEBLISTENERROOT:-/opt/app/ueb-listener} +JAVA_HOME=${JAVA_HOME:-/usr/lib/jvm/java-7-oracle} +JAVA_OPTS=${JAVA_OPTS:--Dhttps.protocols=TLSv1.1,TLSv1.2} +JAVA=${JAVA:-${JAVA_HOME}/bin/java} + +# Redirect output from script to $LISTENER.out +exec >> ${UEBLISTENERROOT}/logs/$LISTENER.out +exec 2>&1 + +if [ -f $PIDFILE ] +then + pid=$(cat $PIDFILE) + if [ "$pid" != "" ] + then + if kill -0 $pid + then + echo "$LISTENER already running" + exit 0 + fi + fi +fi + +if [ ! -d ${UEBLISTENERROOT}/logs ] +then + mkdir ${UEBLISTENERROOT}/logs +fi + +for file in ${UEBLISTENERROOT}/lib/*.jar +do + LISTENERCLASSPATH=$LISTENERCLASSPATH:$file +done + +${JAVA} ${JAVA_OPTS} -jar ${UEBLISTENERROOT}/lib/ueb-listener*.jar -Dlog4j.configuration=file:${UEBLISTENERROOT}/lib/log4j.properties -cp ${LISTENERCLASSPATH} & + + +echo $! > $PIDFILE + +echo "$LISTENER started!" +exit 0 diff --git a/ueb-listener/src/main/scripts/stop-ueb-listener.sh b/ueb-listener/src/main/scripts/stop-ueb-listener.sh new file mode 100644 index 000000000..2e3b4dd2b --- /dev/null +++ b/ueb-listener/src/main/scripts/stop-ueb-listener.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +### +# ============LICENSE_START======================================================= +# openECOMP : SDN-C +# ================================================================================ +# Copyright (C) 2017 ONAP 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========================================================= +### + +PROPERTY_DIR=${PROPERTY_DIR:-/opt/sdnc/data/properties} + +if [ -f ${PROPERTY_DIR}/dmaap-listener.properties ] +then + LISTENER=dmaap-listener +else + LISTENER=ueb-listener +fi + +PIDFILE=/tmp/.${LISTENER}-pid +UEBLISTENERROOT=${UEBLISTENERROOT:-/opt/app/ueb-listener} + +if [ -f $PIDFILE ] +then + pid=$(cat $PIDFILE) + if [ "$pid" != "" ] + then + if kill -0 $pid + then + echo "Stopping $LISTENER" + kill $pid && rm $PIDFILE + exit 0 + else + echo "$LISTENER not running" + exit 1 + fi + else + echo "$LISTENER not running" + exit 1 + fi +fi + + diff --git a/ueb-listener/src/site/apt/index.apt b/ueb-listener/src/site/apt/index.apt new file mode 100644 index 000000000..dd9d3ec39 --- /dev/null +++ b/ueb-listener/src/site/apt/index.apt @@ -0,0 +1,46 @@ +~~~ +~~ ============LICENSE_START======================================================= +~~ openECOMP : SDN-C +~~ ================================================================================ +~~ Copyright (C) 2017 ONAP 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========================================================= +~~~ + + --- + UEB Listener + --- + + +UEB Listener + + The UEB Listener is a daemon that listens for notifications from SDC, posted to UEB (Universal Event Bus). + On receipt of an event, the UEB listener downloads any artifacts posted and examines them to determine if + the format (the outer XML tag) matches a supported format. If so, it posts the file to the ASDC-API REST + API in order to update the SDN-C database. + +File Locations + + * Root directory : /opt/app/ueb-listener + + * Log files : /opt/app/ueb-listener/logs + + * Incoming files to be processed : /opt/app/ueb-listener/spool/asdc/incoming + + * Files already processed : /opt/app/ueb-listener/spool/asdc/archive + + + + diff --git a/ueb-listener/src/site/site.xml b/ueb-listener/src/site/site.xml new file mode 100644 index 000000000..356c9c959 --- /dev/null +++ b/ueb-listener/src/site/site.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + -- cgit 1.2.3-korg From 41df62392ed3d1775c29b7cc1feb161108026c39 Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Tue, 15 Aug 2017 14:10:37 -0400 Subject: Refactor rest of sli/northbound Update remainder of sli/northbound to replace references to openECOMP with references to ONAP Change-Id: I2c321c9ec3f3138f3b7377ce1e0a8ff7e8f29bcc Issue-ID: CCSDK-25 Signed-off-by: Dan Timoney --- .../sli/northbound/dmaapclient/DmaapListener.java | 165 +++ .../northbound/dmaapclient/DummyDmaapConsumer.java | 37 + .../dmaapclient/InvalidMessageException.java | 37 + .../northbound/dmaapclient/SdncDmaapConsumer.java | 146 +++ .../dmaapclient/SdncFlatJsonDmaapConsumer.java | 196 ++++ .../northbound/dmaapclient/SdncOdlConnection.java | 159 +++ .../openecomp/sdnc/dmaapclient/DmaapListener.java | 165 --- .../sdnc/dmaapclient/DummyDmaapConsumer.java | 37 - .../sdnc/dmaapclient/InvalidMessageException.java | 37 - .../sdnc/dmaapclient/SdncDmaapConsumer.java | 146 --- .../dmaapclient/SdncFlatJsonDmaapConsumer.java | 196 ---- .../sdnc/dmaapclient/SdncOdlConnection.java | 159 --- example-settings.xml | 163 --- jenkins-settings.xml | 168 --- .../sli/northbound/uebclient/SdncARModel.java | 53 + .../sli/northbound/uebclient/SdncArtifactMap.java | 134 +++ .../sli/northbound/uebclient/SdncBaseModel.java | 297 ++++++ .../sli/northbound/uebclient/SdncNodeModel.java | 145 +++ .../northbound/uebclient/SdncOdlConnection.java | 158 +++ .../sli/northbound/uebclient/SdncServiceModel.java | 98 ++ .../sli/northbound/uebclient/SdncUebCallback.java | 1125 ++++++++++++++++++++ .../sli/northbound/uebclient/SdncUebClient.java | 65 ++ .../northbound/uebclient/SdncUebConfiguration.java | 280 +++++ .../sli/northbound/uebclient/SdncVFCModel.java | 69 ++ .../sli/northbound/uebclient/SdncVFModel.java | 56 + .../northbound/uebclient/SdncVFModuleModel.java | 45 + .../org/openecomp/sdnc/uebclient/SdncARModel.java | 53 - .../openecomp/sdnc/uebclient/SdncArtifactMap.java | 134 --- .../openecomp/sdnc/uebclient/SdncBaseModel.java | 297 ------ .../openecomp/sdnc/uebclient/SdncNodeModel.java | 145 --- .../sdnc/uebclient/SdncOdlConnection.java | 158 --- .../openecomp/sdnc/uebclient/SdncServiceModel.java | 98 -- .../openecomp/sdnc/uebclient/SdncUebCallback.java | 1125 -------------------- .../openecomp/sdnc/uebclient/SdncUebClient.java | 65 -- .../sdnc/uebclient/SdncUebConfiguration.java | 280 ----- .../org/openecomp/sdnc/uebclient/SdncVFCModel.java | 69 -- .../org/openecomp/sdnc/uebclient/SdncVFModel.java | 56 - .../sdnc/uebclient/SdncVFModuleModel.java | 45 - 38 files changed, 3265 insertions(+), 3596 deletions(-) create mode 100644 dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DmaapListener.java create mode 100644 dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DummyDmaapConsumer.java create mode 100644 dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/InvalidMessageException.java create mode 100644 dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDmaapConsumer.java create mode 100644 dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java create mode 100644 dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncOdlConnection.java delete mode 100644 dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/DmaapListener.java delete mode 100644 dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/DummyDmaapConsumer.java delete mode 100644 dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/InvalidMessageException.java delete mode 100644 dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/SdncDmaapConsumer.java delete mode 100644 dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/SdncFlatJsonDmaapConsumer.java delete mode 100644 dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/SdncOdlConnection.java delete mode 100644 example-settings.xml delete mode 100644 jenkins-settings.xml create mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java create mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java create mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java create mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java create mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java create mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java create mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java create mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java create mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java create mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java create mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java create mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java delete mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncARModel.java delete mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncArtifactMap.java delete mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncBaseModel.java delete mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncNodeModel.java delete mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncOdlConnection.java delete mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncServiceModel.java delete mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebCallback.java delete mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebClient.java delete mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebConfiguration.java delete mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFCModel.java delete mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFModel.java delete mode 100644 ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFModuleModel.java (limited to 'ueb-listener/src') diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DmaapListener.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DmaapListener.java new file mode 100644 index 000000000..b2976294b --- /dev/null +++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DmaapListener.java @@ -0,0 +1,165 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.dmaapclient; + +import java.io.File; +import java.io.FileInputStream; +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DmaapListener { + + private static final String DMAAP_LISTENER_PROPERTIES = "dmaap-listener.properties"; + private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; + private static final Logger LOG = LoggerFactory + .getLogger(DmaapListener.class); + + public static void main(String[] args) { + + Properties properties = new Properties(); + + + String propFileName = DMAAP_LISTENER_PROPERTIES; + + if (args.length > 0) { + propFileName = args[0]; + } + + String propPath = null; + String propDir = System.getenv(SDNC_CONFIG_DIR); + + List consumers = new LinkedList(); + + if (propDir == null) { + + propDir = "/opt/sdnc/data/properties"; + } + + if (!propFileName.startsWith("/")) { + propPath = propDir + "/" + propFileName; + } + + File propFile = new File(propPath); + + if (!propFile.canRead()) { + LOG.error("Cannot read properties file "+propPath); + System.exit(1); + } + + try { + properties.load(new FileInputStream(propFile)); + } catch (Exception e) { + LOG.error("Caught exception loading properties from "+propPath, e); + System.exit(1); + } + + String subscriptionStr = properties.getProperty("subscriptions"); + + boolean threadsRunning = false; + + LOG.debug("Dmaap subscriptions : "+subscriptionStr); + + if (subscriptionStr != null) { + String[] subscriptions = subscriptionStr.split(";"); + + for (int i = 0; i < subscriptions.length; i++) { + String[] subscription = subscriptions[i].split(":"); + String consumerClassName = subscription[0]; + String propertyPath = subscription[1]; + + LOG.debug("Handling subscription [" + consumerClassName + "," + propertyPath + "]"); + + if (propertyPath == null) { + LOG.error("Invalid subscription (" + subscriptions[i] + ") property file missing"); + continue; + } + + if (!propertyPath.startsWith("/")) { + propertyPath = propDir + "/" + propertyPath; + } + + Class consumerClass = null; + + try { + consumerClass = Class.forName(consumerClassName); + } catch (Exception e) { + LOG.error("Could not find DMaap consumer class " + consumerClassName); + } + + if (consumerClass != null) { + + SdncDmaapConsumer consumer = null; + + try { + consumer = (SdncDmaapConsumer) consumerClass.newInstance(); + } catch (Exception e) { + LOG.error("Could not create consumer from class " + consumerClassName, e); + } + + if (consumer != null) { + LOG.debug("Initializing consumer " + consumerClassName + "(" + propertyPath + ")"); + consumer.init(properties, propertyPath); + + if (consumer.isReady()) { + Thread consumerThread = new Thread(consumer); + consumerThread.start(); + consumers.add(consumer); + threadsRunning = true; + LOG.info("Started consumer thread (" + consumerClassName + " : " + propertyPath + ")"); + } else { + LOG.debug("Consumer " + consumerClassName + " is not ready"); + } + } + + } + + } + } + + while (threadsRunning) { + + threadsRunning = false; + for (SdncDmaapConsumer consumer : consumers) { + if (consumer.isRunning()) { + threadsRunning = true; + } + } + + if (!threadsRunning) { + break; + } + + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + + } + } + + LOG.info("No listener threads running - exitting"); + + } +} diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DummyDmaapConsumer.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DummyDmaapConsumer.java new file mode 100644 index 000000000..a3bc46153 --- /dev/null +++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DummyDmaapConsumer.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.dmaapclient; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DummyDmaapConsumer extends SdncDmaapConsumer { + + private static final Logger LOG = LoggerFactory + .getLogger(DummyDmaapConsumer.class); + + @Override + public void processMsg(String msg) { + LOG.info("Consumed message: \n"+msg); + } + +} diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/InvalidMessageException.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/InvalidMessageException.java new file mode 100644 index 000000000..b54adaf06 --- /dev/null +++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/InvalidMessageException.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.dmaapclient; + +public class InvalidMessageException extends Exception { + + public InvalidMessageException() { + super(); + } + + public InvalidMessageException(String msg) { + super(msg); + } + + public InvalidMessageException(String msg, Throwable t) { + super(msg, t); + } +} diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDmaapConsumer.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDmaapConsumer.java new file mode 100644 index 000000000..f6d8ff862 --- /dev/null +++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDmaapConsumer.java @@ -0,0 +1,146 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.dmaapclient; + +import java.io.File; +import java.io.FileInputStream; +import java.util.Properties; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.att.nsa.mr.client.MRClientFactory; +import com.att.nsa.mr.client.MRConsumer; +import com.att.nsa.mr.client.response.MRConsumerResponse; + +public abstract class SdncDmaapConsumer implements Runnable { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncDmaapConsumer.class); + + private String propertiesPath = ""; + private Properties properties = null; + MRConsumer consumer = null; + MRConsumerResponse consumerResponse = null; + boolean running = false; + boolean ready = false; + int fetchPause = 5000; // Default pause between fetchs - 5 seconds + + public boolean isReady() { + return ready; + } + + int timeout = 15000; // Default timeout - 15 seconds + + public boolean isRunning() { + return running; + } + + public SdncDmaapConsumer() { + + } + + public SdncDmaapConsumer(Properties properties, String propertiesPath) { + init(properties, propertiesPath); + } + + public String getProperty(String name) { + return(properties.getProperty(name, "")); + } + + public void init(Properties properties, String propertiesPath) { + + this.propertiesPath = propertiesPath; + + try { + + this.properties = (Properties) properties.clone(); + + this.properties.load(new FileInputStream(new File(propertiesPath))); + + String timeoutStr = properties.getProperty("timeout"); + + if ((timeoutStr != null) && (timeoutStr.length() > 0)) { + try { + timeout = Integer.parseInt(timeoutStr); + } catch (NumberFormatException e) { + LOG.error("Non-numeric value specified for timeout ("+timeoutStr+")"); + } + } + + String fetchPauseStr = properties.getProperty("fetchPause"); + if ((fetchPauseStr != null) && (fetchPauseStr.length() > 0)) { + try { + fetchPause = Integer.parseInt(fetchPauseStr); + } catch (NumberFormatException e) { + LOG.error("Non-numeric valud specified for fetchPause ("+fetchPauseStr+")"); + } + } + + this.consumer = MRClientFactory.createConsumer(propertiesPath); + ready = true; + } catch (Exception e) { + LOG.error("Error initializing DMaaP consumer from file "+propertiesPath, e); + } + } + + + @Override + public void run() { + if (ready) { + + running = true; + + while (running) { + + try { + boolean noData = true; + consumerResponse = consumer.fetchWithReturnConsumerResponse(timeout, -1); + for (String msg : consumerResponse.getActualMessages()) { + noData = false; + LOG.info("Received message from DMaaP:\n"+msg); + processMsg(msg); + } + + if (noData) { + if (fetchPause > 0) { + + LOG.info("No data received from fetch. Pausing "+fetchPause+" ms before retry"); + Thread.sleep(fetchPause); + } else { + + LOG.info("No data received from fetch. No fetch pause specified - retrying immediately"); + } + } + } catch (Exception e) { + LOG.error("Caught exception reading from DMaaP", e); + running = false; + } + + + } + } + + } + + abstract public void processMsg(String msg) throws InvalidMessageException; +} diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java new file mode 100644 index 000000000..0e2a32646 --- /dev/null +++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java @@ -0,0 +1,196 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.dmaapclient; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.Authenticator; +import java.net.HttpURLConnection; +import java.net.PasswordAuthentication; +import java.net.URL; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLSession; + +import org.apache.commons.codec.binary.Base64; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + + +public class SdncFlatJsonDmaapConsumer extends SdncDmaapConsumer { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncFlatJsonDmaapConsumer.class); + + private static final String DMAAPLISTENERROOT = "DMAAPLISTENERROOT"; + private static final String SDNC_ENDPOINT = "SDNC.endpoint"; + + + + @Override + public void processMsg(String msg) throws InvalidMessageException { + + processMsg(msg, null); + } + + public void processMsg(String msg, String mapDirName) throws InvalidMessageException { + + if (msg == null) { + throw new InvalidMessageException("Null message"); + } + + ObjectMapper oMapper = new ObjectMapper(); + JsonNode instarRootNode = null; + ObjectNode sdncRootNode = null; + + String instarMsgName = null; + + try { + instarRootNode = oMapper.readTree(msg); + } catch (Exception e) { + throw new InvalidMessageException("Cannot parse json object", e); + } + + Iterator> instarFields = instarRootNode.fields(); + + while (instarFields.hasNext()) { + Map.Entry entry = instarFields.next(); + + instarMsgName = entry.getKey(); + instarRootNode = entry.getValue(); + break; + } + + Map fieldMap = loadMap(instarMsgName, mapDirName); + + if (fieldMap == null) { + throw new InvalidMessageException("Unable to process message - cannot load field mappings"); + } + + if (!fieldMap.containsKey(SDNC_ENDPOINT)) { + throw new InvalidMessageException("No SDNC endpoint known for message "+instarMsgName); + } + + String sdncEndpoint = fieldMap.get(SDNC_ENDPOINT); + + sdncRootNode = oMapper.createObjectNode(); + ObjectNode inputNode = oMapper.createObjectNode(); + + + for (String fromField : fieldMap.keySet()) { + + if (!SDNC_ENDPOINT.equals(fromField)) { + JsonNode curNode = instarRootNode.get(fromField); + if (curNode != null) { + String fromValue = curNode.textValue(); + + inputNode.put(fieldMap.get(fromField), fromValue); + } + } + } + sdncRootNode.put("input", inputNode); + + try { + String rpcMsgbody = oMapper.writeValueAsString(sdncRootNode); + String odlUrlBase = getProperty("sdnc.odl.url-base"); + String odlUser = getProperty("sdnc.odl.user"); + String odlPassword = getProperty("sdnc.odl.password"); + + if ((odlUrlBase != null) && (odlUrlBase.length() > 0)) { + SdncOdlConnection conn = SdncOdlConnection.newInstance(odlUrlBase + sdncEndpoint, odlUser, odlPassword); + + conn.send("POST", "application/json", rpcMsgbody); + } else { + LOG.info("POST message body would be:\n"+rpcMsgbody); + } + } catch (Exception e) { + + } + + } + + private Map loadMap(String msgType, String mapDirName) { + Map results = new HashMap(); + + + if (mapDirName == null) { + String rootdir = System.getenv(DMAAPLISTENERROOT); + + if ((rootdir == null) || (rootdir.length() == 0)) { + rootdir = "/opt/app/dmaap-listener"; + } + + mapDirName = rootdir + "/lib"; + + } + + String mapFilename = mapDirName + "/" + msgType + ".map"; + + File mapFile = new File(mapFilename); + + if (!mapFile.canRead()) { + LOG.error("Cannot read map file ("+mapFilename+")"); + return(null); + } + + try { + BufferedReader mapReader = new BufferedReader(new FileReader(mapFile)); + + String curLine = null; + + while ((curLine = mapReader.readLine()) != null) { + curLine = curLine.trim(); + + if ((curLine.length() > 0) && (!curLine.startsWith("#"))) { + + if (curLine.contains("=>")) { + String[] entry = curLine.split("=>"); + if (entry.length == 2) { + results.put(entry[0].trim(), entry[1].trim()); + } + } + } + } + mapReader.close(); + } catch (Exception e) { + LOG.error("Caught exception reading map "+mapFilename, e); + return(null); + } + + return(results); + } + + + +} diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncOdlConnection.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncOdlConnection.java new file mode 100644 index 000000000..4d16dd2a0 --- /dev/null +++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncOdlConnection.java @@ -0,0 +1,159 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.dmaapclient; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.Authenticator; +import java.net.HttpURLConnection; +import java.net.PasswordAuthentication; +import java.net.ProtocolException; +import java.net.URL; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLSession; + +import org.apache.commons.codec.binary.Base64; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class SdncOdlConnection { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncOdlConnection.class); + + private HttpURLConnection httpConn = null; + + private String url = null; + private String user = null; + private String password = null; + + private class SdncAuthenticator extends Authenticator { + + private String user; + private String passwd; + + SdncAuthenticator(String user, String passwd) { + this.user = user; + this.passwd = passwd; + } + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(user, passwd.toCharArray()); + } + + } + + private SdncOdlConnection() { + + } + + private SdncOdlConnection(String url, String user, String password) { + this.url = url; + this.user = user; + this.password = password; + + try { + URL sdncUrl = new URL(url); + Authenticator.setDefault(new SdncAuthenticator(user, password)); + + this.httpConn = (HttpURLConnection) sdncUrl.openConnection(); + } catch (Exception e) { + LOG.error("Unable to create http connection", e); + } + } + + public static SdncOdlConnection newInstance(String url, String user, String password) throws IOException + { + return (new SdncOdlConnection(url, user, password)); + } + + + + public String send(String method, String contentType, String msg) throws IOException { + + LOG.info("Sending REST " + method + " to " + url); + LOG.info("Message body:\n" + msg); + String authStr = user + ":" + password; + String encodedAuthStr = new String(Base64.encodeBase64(authStr.getBytes())); + + httpConn.addRequestProperty("Authentication", "Basic " + encodedAuthStr); + + httpConn.setRequestMethod(method); + httpConn.setRequestProperty("Content-Type", contentType); + httpConn.setRequestProperty("Accept", contentType); + + httpConn.setDoInput(true); + httpConn.setDoOutput(true); + httpConn.setUseCaches(false); + + if (httpConn instanceof HttpsURLConnection) { + HostnameVerifier hostnameVerifier = new HostnameVerifier() { + @Override + public boolean verify(String hostname, SSLSession session) { + return true; + } + }; + ((HttpsURLConnection) httpConn).setHostnameVerifier(hostnameVerifier); + } + + // Write message + httpConn.setRequestProperty("Content-Length", "" + msg.length()); + DataOutputStream outStr = new DataOutputStream(httpConn.getOutputStream()); + outStr.write(msg.getBytes()); + outStr.close(); + + // Read response + BufferedReader respRdr; + + LOG.info("Response: " + httpConn.getResponseCode() + " " + httpConn.getResponseMessage()); + + if (httpConn.getResponseCode() < 300) { + + respRdr = new BufferedReader(new InputStreamReader(httpConn.getInputStream())); + } else { + respRdr = new BufferedReader(new InputStreamReader(httpConn.getErrorStream())); + } + + StringBuffer respBuff = new StringBuffer(); + + String respLn; + + while ((respLn = respRdr.readLine()) != null) { + respBuff.append(respLn + "\n"); + } + respRdr.close(); + + String respString = respBuff.toString(); + + LOG.info("Response body :\n" + respString); + + return (respString); + + } + + +} diff --git a/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/DmaapListener.java b/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/DmaapListener.java deleted file mode 100644 index 7096d83bf..000000000 --- a/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/DmaapListener.java +++ /dev/null @@ -1,165 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP 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.openecomp.sdnc.dmaapclient; - -import java.io.File; -import java.io.FileInputStream; -import java.util.LinkedList; -import java.util.List; -import java.util.Properties; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DmaapListener { - - private static final String DMAAP_LISTENER_PROPERTIES = "dmaap-listener.properties"; - private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; - private static final Logger LOG = LoggerFactory - .getLogger(DmaapListener.class); - - public static void main(String[] args) { - - Properties properties = new Properties(); - - - String propFileName = DMAAP_LISTENER_PROPERTIES; - - if (args.length > 0) { - propFileName = args[0]; - } - - String propPath = null; - String propDir = System.getenv(SDNC_CONFIG_DIR); - - List consumers = new LinkedList(); - - if (propDir == null) { - - propDir = "/opt/sdnc/data/properties"; - } - - if (!propFileName.startsWith("/")) { - propPath = propDir + "/" + propFileName; - } - - File propFile = new File(propPath); - - if (!propFile.canRead()) { - LOG.error("Cannot read properties file "+propPath); - System.exit(1); - } - - try { - properties.load(new FileInputStream(propFile)); - } catch (Exception e) { - LOG.error("Caught exception loading properties from "+propPath, e); - System.exit(1); - } - - String subscriptionStr = properties.getProperty("subscriptions"); - - boolean threadsRunning = false; - - LOG.debug("Dmaap subscriptions : "+subscriptionStr); - - if (subscriptionStr != null) { - String[] subscriptions = subscriptionStr.split(";"); - - for (int i = 0; i < subscriptions.length; i++) { - String[] subscription = subscriptions[i].split(":"); - String consumerClassName = subscription[0]; - String propertyPath = subscription[1]; - - LOG.debug("Handling subscription [" + consumerClassName + "," + propertyPath + "]"); - - if (propertyPath == null) { - LOG.error("Invalid subscription (" + subscriptions[i] + ") property file missing"); - continue; - } - - if (!propertyPath.startsWith("/")) { - propertyPath = propDir + "/" + propertyPath; - } - - Class consumerClass = null; - - try { - consumerClass = Class.forName(consumerClassName); - } catch (Exception e) { - LOG.error("Could not find DMaap consumer class " + consumerClassName); - } - - if (consumerClass != null) { - - SdncDmaapConsumer consumer = null; - - try { - consumer = (SdncDmaapConsumer) consumerClass.newInstance(); - } catch (Exception e) { - LOG.error("Could not create consumer from class " + consumerClassName, e); - } - - if (consumer != null) { - LOG.debug("Initializing consumer " + consumerClassName + "(" + propertyPath + ")"); - consumer.init(properties, propertyPath); - - if (consumer.isReady()) { - Thread consumerThread = new Thread(consumer); - consumerThread.start(); - consumers.add(consumer); - threadsRunning = true; - LOG.info("Started consumer thread (" + consumerClassName + " : " + propertyPath + ")"); - } else { - LOG.debug("Consumer " + consumerClassName + " is not ready"); - } - } - - } - - } - } - - while (threadsRunning) { - - threadsRunning = false; - for (SdncDmaapConsumer consumer : consumers) { - if (consumer.isRunning()) { - threadsRunning = true; - } - } - - if (!threadsRunning) { - break; - } - - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - - } - } - - LOG.info("No listener threads running - exitting"); - - } -} diff --git a/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/DummyDmaapConsumer.java b/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/DummyDmaapConsumer.java deleted file mode 100644 index 5edc1c908..000000000 --- a/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/DummyDmaapConsumer.java +++ /dev/null @@ -1,37 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP 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.openecomp.sdnc.dmaapclient; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DummyDmaapConsumer extends SdncDmaapConsumer { - - private static final Logger LOG = LoggerFactory - .getLogger(DummyDmaapConsumer.class); - - @Override - public void processMsg(String msg) { - LOG.info("Consumed message: \n"+msg); - } - -} diff --git a/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/InvalidMessageException.java b/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/InvalidMessageException.java deleted file mode 100644 index 3de5df6c2..000000000 --- a/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/InvalidMessageException.java +++ /dev/null @@ -1,37 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP 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.openecomp.sdnc.dmaapclient; - -public class InvalidMessageException extends Exception { - - public InvalidMessageException() { - super(); - } - - public InvalidMessageException(String msg) { - super(msg); - } - - public InvalidMessageException(String msg, Throwable t) { - super(msg, t); - } -} diff --git a/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/SdncDmaapConsumer.java b/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/SdncDmaapConsumer.java deleted file mode 100644 index 5b55bda5b..000000000 --- a/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/SdncDmaapConsumer.java +++ /dev/null @@ -1,146 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP 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.openecomp.sdnc.dmaapclient; - -import java.io.File; -import java.io.FileInputStream; -import java.util.Properties; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.att.nsa.mr.client.MRClientFactory; -import com.att.nsa.mr.client.MRConsumer; -import com.att.nsa.mr.client.response.MRConsumerResponse; - -public abstract class SdncDmaapConsumer implements Runnable { - - private static final Logger LOG = LoggerFactory - .getLogger(SdncDmaapConsumer.class); - - private String propertiesPath = ""; - private Properties properties = null; - MRConsumer consumer = null; - MRConsumerResponse consumerResponse = null; - boolean running = false; - boolean ready = false; - int fetchPause = 5000; // Default pause between fetchs - 5 seconds - - public boolean isReady() { - return ready; - } - - int timeout = 15000; // Default timeout - 15 seconds - - public boolean isRunning() { - return running; - } - - public SdncDmaapConsumer() { - - } - - public SdncDmaapConsumer(Properties properties, String propertiesPath) { - init(properties, propertiesPath); - } - - public String getProperty(String name) { - return(properties.getProperty(name, "")); - } - - public void init(Properties properties, String propertiesPath) { - - this.propertiesPath = propertiesPath; - - try { - - this.properties = (Properties) properties.clone(); - - this.properties.load(new FileInputStream(new File(propertiesPath))); - - String timeoutStr = properties.getProperty("timeout"); - - if ((timeoutStr != null) && (timeoutStr.length() > 0)) { - try { - timeout = Integer.parseInt(timeoutStr); - } catch (NumberFormatException e) { - LOG.error("Non-numeric value specified for timeout ("+timeoutStr+")"); - } - } - - String fetchPauseStr = properties.getProperty("fetchPause"); - if ((fetchPauseStr != null) && (fetchPauseStr.length() > 0)) { - try { - fetchPause = Integer.parseInt(fetchPauseStr); - } catch (NumberFormatException e) { - LOG.error("Non-numeric valud specified for fetchPause ("+fetchPauseStr+")"); - } - } - - this.consumer = MRClientFactory.createConsumer(propertiesPath); - ready = true; - } catch (Exception e) { - LOG.error("Error initializing DMaaP consumer from file "+propertiesPath, e); - } - } - - - @Override - public void run() { - if (ready) { - - running = true; - - while (running) { - - try { - boolean noData = true; - consumerResponse = consumer.fetchWithReturnConsumerResponse(timeout, -1); - for (String msg : consumerResponse.getActualMessages()) { - noData = false; - LOG.info("Received message from DMaaP:\n"+msg); - processMsg(msg); - } - - if (noData) { - if (fetchPause > 0) { - - LOG.info("No data received from fetch. Pausing "+fetchPause+" ms before retry"); - Thread.sleep(fetchPause); - } else { - - LOG.info("No data received from fetch. No fetch pause specified - retrying immediately"); - } - } - } catch (Exception e) { - LOG.error("Caught exception reading from DMaaP", e); - running = false; - } - - - } - } - - } - - abstract public void processMsg(String msg) throws InvalidMessageException; -} diff --git a/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/SdncFlatJsonDmaapConsumer.java b/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/SdncFlatJsonDmaapConsumer.java deleted file mode 100644 index 7e9c069ac..000000000 --- a/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/SdncFlatJsonDmaapConsumer.java +++ /dev/null @@ -1,196 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP 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.openecomp.sdnc.dmaapclient; - -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.Authenticator; -import java.net.HttpURLConnection; -import java.net.PasswordAuthentication; -import java.net.URL; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLSession; - -import org.apache.commons.codec.binary.Base64; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; - - -public class SdncFlatJsonDmaapConsumer extends SdncDmaapConsumer { - - private static final Logger LOG = LoggerFactory - .getLogger(SdncFlatJsonDmaapConsumer.class); - - private static final String DMAAPLISTENERROOT = "DMAAPLISTENERROOT"; - private static final String SDNC_ENDPOINT = "SDNC.endpoint"; - - - - @Override - public void processMsg(String msg) throws InvalidMessageException { - - processMsg(msg, null); - } - - public void processMsg(String msg, String mapDirName) throws InvalidMessageException { - - if (msg == null) { - throw new InvalidMessageException("Null message"); - } - - ObjectMapper oMapper = new ObjectMapper(); - JsonNode instarRootNode = null; - ObjectNode sdncRootNode = null; - - String instarMsgName = null; - - try { - instarRootNode = oMapper.readTree(msg); - } catch (Exception e) { - throw new InvalidMessageException("Cannot parse json object", e); - } - - Iterator> instarFields = instarRootNode.fields(); - - while (instarFields.hasNext()) { - Map.Entry entry = instarFields.next(); - - instarMsgName = entry.getKey(); - instarRootNode = entry.getValue(); - break; - } - - Map fieldMap = loadMap(instarMsgName, mapDirName); - - if (fieldMap == null) { - throw new InvalidMessageException("Unable to process message - cannot load field mappings"); - } - - if (!fieldMap.containsKey(SDNC_ENDPOINT)) { - throw new InvalidMessageException("No SDNC endpoint known for message "+instarMsgName); - } - - String sdncEndpoint = fieldMap.get(SDNC_ENDPOINT); - - sdncRootNode = oMapper.createObjectNode(); - ObjectNode inputNode = oMapper.createObjectNode(); - - - for (String fromField : fieldMap.keySet()) { - - if (!SDNC_ENDPOINT.equals(fromField)) { - JsonNode curNode = instarRootNode.get(fromField); - if (curNode != null) { - String fromValue = curNode.textValue(); - - inputNode.put(fieldMap.get(fromField), fromValue); - } - } - } - sdncRootNode.put("input", inputNode); - - try { - String rpcMsgbody = oMapper.writeValueAsString(sdncRootNode); - String odlUrlBase = getProperty("sdnc.odl.url-base"); - String odlUser = getProperty("sdnc.odl.user"); - String odlPassword = getProperty("sdnc.odl.password"); - - if ((odlUrlBase != null) && (odlUrlBase.length() > 0)) { - SdncOdlConnection conn = SdncOdlConnection.newInstance(odlUrlBase + sdncEndpoint, odlUser, odlPassword); - - conn.send("POST", "application/json", rpcMsgbody); - } else { - LOG.info("POST message body would be:\n"+rpcMsgbody); - } - } catch (Exception e) { - - } - - } - - private Map loadMap(String msgType, String mapDirName) { - Map results = new HashMap(); - - - if (mapDirName == null) { - String rootdir = System.getenv(DMAAPLISTENERROOT); - - if ((rootdir == null) || (rootdir.length() == 0)) { - rootdir = "/opt/app/dmaap-listener"; - } - - mapDirName = rootdir + "/lib"; - - } - - String mapFilename = mapDirName + "/" + msgType + ".map"; - - File mapFile = new File(mapFilename); - - if (!mapFile.canRead()) { - LOG.error("Cannot read map file ("+mapFilename+")"); - return(null); - } - - try { - BufferedReader mapReader = new BufferedReader(new FileReader(mapFile)); - - String curLine = null; - - while ((curLine = mapReader.readLine()) != null) { - curLine = curLine.trim(); - - if ((curLine.length() > 0) && (!curLine.startsWith("#"))) { - - if (curLine.contains("=>")) { - String[] entry = curLine.split("=>"); - if (entry.length == 2) { - results.put(entry[0].trim(), entry[1].trim()); - } - } - } - } - mapReader.close(); - } catch (Exception e) { - LOG.error("Caught exception reading map "+mapFilename, e); - return(null); - } - - return(results); - } - - - -} diff --git a/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/SdncOdlConnection.java b/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/SdncOdlConnection.java deleted file mode 100644 index 6c6f308fb..000000000 --- a/dmaap-listener/src/main/java/org/openecomp/sdnc/dmaapclient/SdncOdlConnection.java +++ /dev/null @@ -1,159 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP 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.openecomp.sdnc.dmaapclient; - -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.Authenticator; -import java.net.HttpURLConnection; -import java.net.PasswordAuthentication; -import java.net.ProtocolException; -import java.net.URL; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLSession; - -import org.apache.commons.codec.binary.Base64; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -public class SdncOdlConnection { - - private static final Logger LOG = LoggerFactory - .getLogger(SdncOdlConnection.class); - - private HttpURLConnection httpConn = null; - - private String url = null; - private String user = null; - private String password = null; - - private class SdncAuthenticator extends Authenticator { - - private String user; - private String passwd; - - SdncAuthenticator(String user, String passwd) { - this.user = user; - this.passwd = passwd; - } - @Override - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(user, passwd.toCharArray()); - } - - } - - private SdncOdlConnection() { - - } - - private SdncOdlConnection(String url, String user, String password) { - this.url = url; - this.user = user; - this.password = password; - - try { - URL sdncUrl = new URL(url); - Authenticator.setDefault(new SdncAuthenticator(user, password)); - - this.httpConn = (HttpURLConnection) sdncUrl.openConnection(); - } catch (Exception e) { - LOG.error("Unable to create http connection", e); - } - } - - public static SdncOdlConnection newInstance(String url, String user, String password) throws IOException - { - return (new SdncOdlConnection(url, user, password)); - } - - - - public String send(String method, String contentType, String msg) throws IOException { - - LOG.info("Sending REST " + method + " to " + url); - LOG.info("Message body:\n" + msg); - String authStr = user + ":" + password; - String encodedAuthStr = new String(Base64.encodeBase64(authStr.getBytes())); - - httpConn.addRequestProperty("Authentication", "Basic " + encodedAuthStr); - - httpConn.setRequestMethod(method); - httpConn.setRequestProperty("Content-Type", contentType); - httpConn.setRequestProperty("Accept", contentType); - - httpConn.setDoInput(true); - httpConn.setDoOutput(true); - httpConn.setUseCaches(false); - - if (httpConn instanceof HttpsURLConnection) { - HostnameVerifier hostnameVerifier = new HostnameVerifier() { - @Override - public boolean verify(String hostname, SSLSession session) { - return true; - } - }; - ((HttpsURLConnection) httpConn).setHostnameVerifier(hostnameVerifier); - } - - // Write message - httpConn.setRequestProperty("Content-Length", "" + msg.length()); - DataOutputStream outStr = new DataOutputStream(httpConn.getOutputStream()); - outStr.write(msg.getBytes()); - outStr.close(); - - // Read response - BufferedReader respRdr; - - LOG.info("Response: " + httpConn.getResponseCode() + " " + httpConn.getResponseMessage()); - - if (httpConn.getResponseCode() < 300) { - - respRdr = new BufferedReader(new InputStreamReader(httpConn.getInputStream())); - } else { - respRdr = new BufferedReader(new InputStreamReader(httpConn.getErrorStream())); - } - - StringBuffer respBuff = new StringBuffer(); - - String respLn; - - while ((respLn = respRdr.readLine()) != null) { - respBuff.append(respLn + "\n"); - } - respRdr.close(); - - String respString = respBuff.toString(); - - LOG.info("Response body :\n" + respString); - - return (respString); - - } - - -} diff --git a/example-settings.xml b/example-settings.xml deleted file mode 100644 index 2e7ce6445..000000000 --- a/example-settings.xml +++ /dev/null @@ -1,163 +0,0 @@ - - - - - - - - openecomp-release - - - openecomp-release - openecomp-release - https://ecomp-nexus:8443/repository/maven-releases/ - - true - never - - - false - - - - - - openecomp-release - openecomp-release - https://ecomp-nexus:8443/repository/maven-releases/ - - true - never - - - false - - - - - - - openecomp-snapshots - - - openecomp-snapshot - openecomp-snapshot - https://ecomp-nexus:8443/repository/maven-snapshots/ - - false - - - true - - - - - - openecomp-snapshot - openecomp-snapshot - https://ecomp-nexus:8443/repository/maven-snapshots/ - - false - - - true - - - - - - opendaylight-release - - - opendaylight-mirror - opendaylight-mirror - https://nexus.opendaylight.org/content/repositories/public/ - - true - never - - - false - - - - - - opendaylight-mirror - opendaylight-mirror - https://nexus.opendaylight.org/content/repositories/public/ - - true - never - - - false - - - - - - - opendaylight-snapshots - - - opendaylight-snapshot - opendaylight-snapshot - https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/ - - false - - - true - - - - - - opendaylight-snapshot - opendaylight-snapshot - https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/ - - false - - - true - - - - - - - - openecomp-release - openecomp-snapshots - opendaylight-release - opendaylight-snapshots - - - - - nexus - USERNAME - PASSWORD - - - openecomp-release - USERNAME - PASSWORD - - - openecomp-snapshot - USERNAME - PASSWORD - - - diff --git a/jenkins-settings.xml b/jenkins-settings.xml deleted file mode 100644 index 344994f85..000000000 --- a/jenkins-settings.xml +++ /dev/null @@ -1,168 +0,0 @@ - - - - - - - - openecomp-release - - - openecomp-release - openecomp-release - https://ecomp-nexus:8443/repository/maven-releases/ - - true - never - - - false - - - - - - openecomp-release - openecomp-release - https://ecomp-nexus:8443/repository/maven-releases/ - - true - never - - - false - - - - - - - openecomp-snapshots - - - openecomp-snapshot - openecomp-snapshot - https://ecomp-nexus:8443/repository/maven-snapshots/ - - false - - - true - - - - - - openecomp-snapshot - openecomp-snapshot - https://ecomp-nexus:8443/repository/maven-snapshots/ - - false - - - true - - - - - - opendaylight-release - - - opendaylight-mirror - opendaylight-mirror - https://nexus.opendaylight.org/content/repositories/public/ - - true - never - - - false - - - - - - opendaylight-mirror - opendaylight-mirror - https://nexus.opendaylight.org/content/repositories/public/ - - true - never - - - false - - - - - - - opendaylight-snapshots - - - opendaylight-snapshot - opendaylight-snapshot - https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/ - - false - - - true - - - - - - opendaylight-snapshot - opendaylight-snapshot - https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/ - - false - - - true - - - - - - - - openecomp-release - openecomp-snapshots - opendaylight-release - opendaylight-snapshots - - - - - nexus - ${ecomp.nexus.user} - ${ecomp.nexus.password} - - - openecomp-release - ${ecomp.nexus.user} - ${ecomp.nexus.password} - - - openecomp-snapshot - ${ecomp.nexus.user} - ${ecomp.nexus.password} - - - sdnc-javadoc - ${ecomp.nexus.user} - ${ecomp.nexus.password} - - - diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java new file mode 100644 index 000000000..3be906181 --- /dev/null +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.Metadata; +import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdncARModel extends SdncBaseModel { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncARModel.class); + + public SdncARModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { + + super(sdcCsarHelper, nodeTemplate); + + // extract metadata + Metadata metadata = nodeTemplate.getMetadata(); + addParameter("type", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_TYPE)); + + // extract properties + //addParameter("role", extractValue (sdcCsarHelper, nodeTemplate, SdcPropertyNames.PROPERTY_NAME_ROLE)); + //addParameter("type", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_TYPE)); - wrong location, get from metadata + addParameter("ecomp_generated_naming", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VFCNAMING_ECOMPGENERATEDNAMING)); + addParameter("naming_policy", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VFCNAMING_NAMINGPOLICY)); + //addParameter("depending_service", extractValue (sdcCsarHelper, nodeTemplate, SdcPropertyNames.PROPERTY_NAME_DEPENDINGSERVICE)); + //addParameter("service_dependency", extractValue (sdcCsarHelper, nodeTemplate, SdcPropertyNames.PROPERTY_NAME_SERVICEDEPENDENCY)); + } + +} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java new file mode 100644 index 000000000..d979a3206 --- /dev/null +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java @@ -0,0 +1,134 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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 java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdncArtifactMap { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncArtifactMap.class); + + public class SdncArtifactType { + private String tag; + private String artifactType; + private String rpc; + private int pass; + + public String getTag() { + return tag; + } + public String getArtifactType() { + return artifactType; + } + public String getRpc() { + return rpc; + } + + public int getPass() { + return pass; + } + + public String getRpcUrl(String base) { + return(base+rpc); + } + + private SdncArtifactType(String tag, String rpc, String pass) { + this.tag = tag; + this.rpc = rpc; + try { + this.pass = Integer.parseInt(pass); + } catch (Exception e) { + LOG.error("Invalid pass value for artifact map entry ("+tag+","+rpc+","+pass+")"); + } + } + } + + + + private Map mapItems = new HashMap(); + + private int NumPasses = 1; + + public int getNumPasses() { + return NumPasses; + } + + public void load(String fileName) { + + File mapFile = new File(fileName); + + if (mapFile.exists() && mapFile.canRead()) { + + BufferedReader rdr = null; + try { + + rdr = new BufferedReader(new FileReader(mapFile)); + + for (String ln ; (ln = rdr.readLine()) != null ; ) { + String[] lnFields = ln.split(","); + if (lnFields.length == 3) { + SdncArtifactType entry = new SdncArtifactType(lnFields[0], lnFields[1], lnFields[2]); + mapItems.put(entry.getTag(), entry); + if (entry.getPass() + 1 > NumPasses ) { + NumPasses = entry.getPass() + 1; + } + } + } + + + } catch (Exception e) { + LOG.error("Caught exception reading artifact map", e); + return; + } finally { + if (rdr != null) { + try { + rdr.close(); + } catch (IOException e) { + + } + } + } + } + } + + public SdncArtifactType getMapping(String tag) { + if (mapItems.containsKey(tag)) { + return(mapItems.get(tag)); + } else { + return(null); + } + } + + public static SdncArtifactMap getInstance() { + return new SdncArtifactMap(); + } + +} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java new file mode 100644 index 000000000..707eee7e4 --- /dev/null +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -0,0 +1,297 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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 java.util.HashMap; +import java.util.Map; + +import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; +import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames; +import org.openecomp.sdc.toscaparser.api.Group; +import org.openecomp.sdc.toscaparser.api.Metadata; +import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdncBaseModel { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncBaseModel.class); + + protected String customizationUUID = null; + protected String invariantUUID = null; + protected String model_yaml = null; + protected String version = null; + + protected Map params = null; + protected ISdcCsarHelper sdcCsarHelper = null; + + public SdncBaseModel() { + + } + + public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata) { + + params = new HashMap(); + this.sdcCsarHelper = sdcCsarHelper; + + // extract service metadata + invariantUUID = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID); + addParameter("invariant_uuid",invariantUUID); + addParameter("version",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_VERSION)); + addParameter("name",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_NAME)); + addParameter("description",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); + addParameter("type",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_TYPE)); + addParameter("category",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_CATEGORY)); + } + + public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { + + params = new HashMap(); + this.sdcCsarHelper = sdcCsarHelper; + + // extract nodeTemplate metadata + Metadata metadata = nodeTemplate.getMetadata(); + customizationUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); + addParameter("invariant_uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); + addParameter("uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_UUID)); + addParameter("version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VERSION)); + } + + public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Group group) { + + params = new HashMap(); + this.sdcCsarHelper = sdcCsarHelper; + + // extract group metadata + Metadata metadata = group.getMetadata(); + //customizationUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULECUSTOMIZATIONUUID); - returning null + customizationUUID = extractValue (metadata, "vfModuleModelCustomizationUUID"); + addParameter("invariant_uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)); + addParameter("uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)); + addParameter("version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)); + } + + protected void addParameter (String name, String value) { + if (value != null && !value.isEmpty()) { + params.put(name, "\"" + value + "\""); + } + } + + protected void addIntParameter (String name, String value) { + if (value != null && !value.isEmpty()) { + params.put(name, value); + } + } + + public static void addIntParameter (String name, String value, Map params) { + if (value != null && !value.isEmpty()) { + params.put(name, value); + } + } + + public static void addParameter (String name, String value, Map params) { + if (value != null && !value.isEmpty()) { + params.put(name, "\"" + value + "\""); + } + } + + protected String extractValue (Metadata metadata, String name) { + String value = sdcCsarHelper.getMetadataPropertyValue(metadata, name); + if (value != null) { + return value; + } else { + return ""; + } + } + + public static String extractValue (ISdcCsarHelper sdcCsarHelper, Metadata metadata, String name) { + String value = sdcCsarHelper.getMetadataPropertyValue(metadata, name); + if (value != null) { + return value; + } else { + return ""; + } + } + + protected String extractValue (NodeTemplate nodeTemplate, String name) { + String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); + if (value != null) { + return value; + } else { + return ""; + } + } + + public static String extractValue (ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, String name) { + String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); + if (value != null) { + return value; + } else { + return ""; + } + } + + protected String extractBooleanValue (NodeTemplate nodeTemplate, String name) { + String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); + if (value != null && !value.isEmpty()) { + return value.contains("true") ? "Y" : "N"; + } else { + return ""; + } + } + + public static String extractBooleanValue (ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, String name) { + String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); + if (value != null && !value.isEmpty()) { + return value.contains("true") ? "Y" : "N"; + } else { + return ""; + } + } + + protected String extractValue (Group group, String name) { + String value = sdcCsarHelper.getGroupPropertyLeafValue(group, name); + if (value != null) { + return value; + } else { + return ""; + } + } + + protected String extractBooleanValue (Group group, String name) { + String value = sdcCsarHelper.getGroupPropertyLeafValue(group, name); + if (value != null && !value.isEmpty()) { + return value.contains("true") ? "Y" : "N"; + } else { + return ""; + } + } + + protected String extractInputDefaultValue (String name) { + String value = sdcCsarHelper.getServiceInputLeafValueOfDefault(name); + if (value != null) { + return value; + } else { + return ""; + } + } + + protected String extractBooleanInputDefaultValue (String name) { + String value = sdcCsarHelper.getServiceInputLeafValueOfDefault(name); + if (value != null && !value.isEmpty()) { + return value.contains("true") ? "Y" : "N"; + } else { + return ""; + } + } + + public static String extractInputDefaultValue (ISdcCsarHelper sdcCsarHelper, String name) { + String value = sdcCsarHelper.getServiceInputLeafValueOfDefault(name); + if (value != null) { + return value; + } else { + return ""; + } + } + + public static String extractBooleanInputDefaultValue (ISdcCsarHelper sdcCsarHelper, String name) { + String value = sdcCsarHelper.getServiceInputLeafValueOfDefault(name); + if (value != null && !value.isEmpty()) { + return value.contains("true") ? "Y" : "N"; + } else { + return ""; + } + } + + public static String extractSubstitutionMappingTypeName (ISdcCsarHelper sdcCsarHelper) { + String value = sdcCsarHelper.getServiceSubstitutionMappingsTypeName(); + if (value != null) { + return value; + } else { + return ""; + } + } + + public String getCustomizationUUID() { + return ("\"" + customizationUUID + "\""); + } + public String getCustomizationUUIDNoQuotes() { + return (customizationUUID); + } + public void setCustomizationUUID(String customizationUUID) { + this.customizationUUID = customizationUUID; + } + + public String getSql(String tableName, String model_yaml) { + + StringBuilder sb = new StringBuilder(); + sb.append("INSERT into " + tableName + " (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 (" + 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 static String getSql(String tableName, String keyName, String keyValue, String model_yaml, Map params) { + + StringBuilder sb = new StringBuilder(); + sb.append("INSERT into " + tableName + " (" + keyName + ", "); + + int paramCount = 0; + for (String paramKey : params.keySet()) { + paramCount++; + sb.append(paramKey); + if (paramCount < params.size()) sb.append(", "); + } + + sb.append(") values (" + keyValue + ", "); + + 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(); + } + +} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java new file mode 100644 index 000000000..dcf668ed8 --- /dev/null +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java @@ -0,0 +1,145 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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 static final Logger LOG = LoggerFactory + .getLogger(SdncNodeModel.class); + + 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 inputs + 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(); + } + +} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java new file mode 100644 index 000000000..7bee801d2 --- /dev/null +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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 java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.Authenticator; +import java.net.HttpURLConnection; +import java.net.PasswordAuthentication; +import java.net.URL; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLSession; + +import org.apache.commons.codec.binary.Base64; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class SdncOdlConnection { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncOdlConnection.class); + + private HttpURLConnection httpConn = null; + + private String url = null; + private String user = null; + private String password = null; + + private class SdncAuthenticator extends Authenticator { + + private String user; + private String passwd; + + SdncAuthenticator(String user, String passwd) { + this.user = user; + this.passwd = passwd; + } + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(user, passwd.toCharArray()); + } + + } + + private SdncOdlConnection() { + + } + + private SdncOdlConnection(String url, String user, String password) { + this.url = url; + this.user = user; + this.password = password; + + try { + URL sdncUrl = new URL(url); + Authenticator.setDefault(new SdncAuthenticator(user, password)); + + this.httpConn = (HttpURLConnection) sdncUrl.openConnection(); + } catch (Exception e) { + LOG.error("Unable to create http connection", e); + } + } + + public static SdncOdlConnection newInstance(String url, String user, String password) throws IOException + { + return (new SdncOdlConnection(url, user, password)); + } + + + + public String send(String method, String contentType, String msg) throws IOException { + + LOG.info("Sending REST " + method + " to " + url); + LOG.info("Message body:\n" + msg); + String authStr = user + ":" + password; + String encodedAuthStr = new String(Base64.encodeBase64(authStr.getBytes())); + + httpConn.addRequestProperty("Authentication", "Basic " + encodedAuthStr); + + httpConn.setRequestMethod(method); + httpConn.setRequestProperty("Content-Type", contentType); + httpConn.setRequestProperty("Accept", contentType); + + httpConn.setDoInput(true); + httpConn.setDoOutput(true); + httpConn.setUseCaches(false); + + if (httpConn instanceof HttpsURLConnection) { + HostnameVerifier hostnameVerifier = new HostnameVerifier() { + @Override + public boolean verify(String hostname, SSLSession session) { + return true; + } + }; + ((HttpsURLConnection) httpConn).setHostnameVerifier(hostnameVerifier); + } + + // Write message + httpConn.setRequestProperty("Content-Length", "" + msg.length()); + DataOutputStream outStr = new DataOutputStream(httpConn.getOutputStream()); + outStr.write(msg.getBytes()); + outStr.close(); + + // Read response + BufferedReader respRdr; + + LOG.info("Response: " + httpConn.getResponseCode() + " " + httpConn.getResponseMessage()); + + if (httpConn.getResponseCode() < 300) { + + respRdr = new BufferedReader(new InputStreamReader(httpConn.getInputStream())); + } else { + respRdr = new BufferedReader(new InputStreamReader(httpConn.getErrorStream())); + } + + StringBuffer respBuff = new StringBuffer(); + + String respLn; + + while ((respLn = respRdr.readLine()) != null) { + respBuff.append(respLn + "\n"); + } + respRdr.close(); + + String respString = respBuff.toString(); + + LOG.info("Response body :\n" + respString); + + return (respString); + + } + + +} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java new file mode 100644 index 000000000..86a4d2a25 --- /dev/null +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java @@ -0,0 +1,98 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.Metadata; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdncServiceModel extends SdncBaseModel { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncServiceModel.class); + + private String UUID = null; + private String serviceInstanceNamePrefix = null; + private String filename = null; + + public SdncServiceModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata) { + + super(sdcCsarHelper, metadata); + + UUID = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_UUID); + + // extract service topology template input data + addParameter("ecomp_naming",extractBooleanInputDefaultValue(SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_ECOMPGENERATEDNAMING)); + addParameter("naming_policy",extractInputDefaultValue(SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_NAMINGPOLICY)); + } + + public String getServiceUUID() { + return ("\"" + UUID + "\""); + } + public void setServiceUUID(String serviceUUID) { + this.UUID = serviceUUID; + } + public String getServiceInstanceNamePrefix() { + return serviceInstanceNamePrefix; + } + public void setServiceInstanceNamePrefix(String serviceInstanceNamePrefix) { + if (serviceInstanceNamePrefix != null && !serviceInstanceNamePrefix.isEmpty()) { + this.serviceInstanceNamePrefix = serviceInstanceNamePrefix; + params.put("service_instance_name_prefix", "\"" + serviceInstanceNamePrefix + "\""); + } + } + public String getFilename() { + return filename; + } + public void setFilename(String filename) { + this.filename = filename; + } + + public String getSql(String model_yaml) { + + StringBuilder sb = new StringBuilder(); + sb.append("INSERT into SERVICE_MODEL (service_uuid, model_yaml, filename, "); + + int paramCount = 0; + for (String paramKey : params.keySet()) { + paramCount++; + sb.append(paramKey); + if (paramCount < params.size()) sb.append(", "); + } + + sb.append(") values (" + getServiceUUID() + ", \"" + model_yaml + "\", \"" + filename + "\", "); + + 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(); + } + +} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java new file mode 100644 index 000000000..fd304208c --- /dev/null +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -0,0 +1,1125 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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 java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.net.Authenticator; +import java.net.HttpURLConnection; +import java.net.PasswordAuthentication; +import java.net.URL; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import javax.sql.rowset.CachedRowSet; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathFactory; + +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.lang3.tuple.Pair; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; +import org.onap.ccsdk.sli.northbound.uebclient.SdncArtifactMap.SdncArtifactType; +import org.openecomp.sdc.api.IDistributionClient; +import org.openecomp.sdc.api.consumer.IDistributionStatusMessage; +import org.openecomp.sdc.api.consumer.INotificationCallback; +import org.openecomp.sdc.api.notification.IArtifactInfo; +import org.openecomp.sdc.api.notification.INotificationData; +import org.openecomp.sdc.api.notification.IResourceInstance; +import org.openecomp.sdc.api.results.IDistributionClientDownloadResult; +import org.openecomp.sdc.api.results.IDistributionClientResult; +import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; +import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames; +import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory; +import org.openecomp.sdc.toscaparser.api.Group; +import org.openecomp.sdc.toscaparser.api.Metadata; +import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.openecomp.sdc.utils.ArtifactTypeEnum; +import org.openecomp.sdc.utils.DistributionActionResultEnum; +import org.openecomp.sdc.utils.DistributionStatusEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class SdncUebCallback implements INotificationCallback { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncUebCallback.class); + + private static DBResourceManager jdbcDataSource = null; + private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; + + + private class SdncAuthenticator extends Authenticator { + + private final String user; + private final String passwd; + + SdncAuthenticator(String user, String passwd) { + this.user = user; + this.passwd = passwd; + } + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(user, passwd.toCharArray()); + } + + } + + private class DeployableArtifact { + SdncArtifactType type; + IArtifactInfo artifactInfo; + String svcName; + String resourceName; + String artifactName; + String artifactVersion; + File file; + + public String getArtifactName() { + return artifactName; + } + + + + public String getArtifactVersion() { + return artifactVersion; + } + + + public SdncArtifactType getType() { + return type; + } + + + + public IArtifactInfo getArtifactInfo() { + return artifactInfo; + } + + + public File getFile() { + return file; + } + + + + + public DeployableArtifact(SdncArtifactType type, String svcName, String resourceName, IArtifactInfo artifactInfo, File file) { + this.type = type; + this.artifactInfo = artifactInfo; + this.svcName = svcName; + this.resourceName = resourceName; + this.artifactName = artifactInfo.getArtifactName(); + this.artifactVersion = artifactInfo.getArtifactVersion(); + this.file = file; + } + + + public DeployableArtifact(SdncArtifactType type, String svcName, String resourceName, String artifactName, String artifactVersion, File file) { + this.type = type; + this.artifactInfo = null; + this.svcName = svcName; + this.resourceName = resourceName; + this.artifactName = artifactName; + this.artifactVersion = artifactVersion; + this.file = file; + } + + + + public String getSvcName() { + return svcName; + } + + + + public String getResourceName() { + return resourceName; + } + + } + + private final IDistributionClient client; + private final SdncUebConfiguration config; + + private LinkedList deployList[]; + + private static void setJdbcDataSource() throws IOException { + + String propPath = null; + String propDir = System.getenv(SDNC_CONFIG_DIR); + if (propDir == null) { + + propDir = "/opt/sdnc/data/properties"; + } + propPath = propDir + "/dblib.properties"; + File propFile = new File(propPath); + + if (!propFile.exists()) { + + throw new FileNotFoundException( + "Missing configuration properties file : " + + propFile); + } + + Properties props = new Properties(); + props.load(new FileInputStream(propFile)); + + try { + jdbcDataSource = DBResourceManager.create(props); + } catch(Throwable exc) { + LOG.error("", exc); + } + + if(((DBResourceManager)jdbcDataSource).isActive()){ + LOG.warn( "DBLIB: JDBC DataSource has been initialized."); + } else { + LOG.warn( "DBLIB: JDBC DataSource did not initialize successfully."); + } + } + + private static void loadArtifactMap() { + + } + + public SdncUebCallback(IDistributionClient client, SdncUebConfiguration config) { + this.client = client; + this.config = config; + + } + + @Override + public void activateCallback(INotificationData data) { + + LOG.info("Received notification : ("+data.getDistributionID()+","+data.getServiceName()+","+data.getServiceVersion()+ + ","+data.getServiceDescription() + ")"); + + String incomingDirName = config.getIncomingDir(); + String archiveDirName = config.getArchiveDir(); + + File incomingDir = null; + File archiveDir = null; + + if (!incomingDir.exists()) { + incomingDir.mkdirs(); + } + + + if (!archiveDir.exists()) { + archiveDir.mkdirs(); + } + + // Process service level artifacts + List artifactList = data.getServiceArtifacts(); + + if (artifactList != null) { + + incomingDir = new File(incomingDirName + "/" + escapeFilename(data.getServiceName())); + if (!incomingDir.exists()) { + incomingDir.mkdirs(); + } + + archiveDir = new File(archiveDirName + "/" + escapeFilename(data.getServiceName())); + if (!archiveDir.exists()) { + archiveDir.mkdirs(); + } + for (IArtifactInfo curArtifact : artifactList) + { + + LOG.info("Received artifact " + curArtifact.getArtifactName()); + + handleArtifact(data, data.getServiceName(), null, null, curArtifact, incomingDir, archiveDir); + } + } + + + // Process resource level artifacts + for (IResourceInstance curResource : data.getResources()) { + + LOG.info("Received resource : "+curResource.getResourceName()); + artifactList = curResource.getArtifacts(); + + if (artifactList != null) { + + incomingDir = new File(incomingDirName + "/" + escapeFilename(data.getServiceName()) + "/" + escapeFilename(curResource.getResourceName())); + if (!incomingDir.exists()) { + incomingDir.mkdirs(); + } + + archiveDir = new File(archiveDirName + "/" + escapeFilename(data.getServiceName()) + "/" + escapeFilename(curResource.getResourceName())); + if (!archiveDir.exists()) { + archiveDir.mkdirs(); + } + for (IArtifactInfo curArtifact : artifactList) + { + + LOG.info("Received artifact " + curArtifact.getArtifactName()); + + handleArtifact(data, data.getServiceName(), curResource.getResourceName(), curResource.getResourceType(), curArtifact, incomingDir, archiveDir); + } + } + } + + deployDownloadedFiles(incomingDir, archiveDir, data); + + + } + + + public void deployDownloadedFiles(File incomingDir, File archiveDir, INotificationData data) { + + if (incomingDir == null) { + incomingDir = new File(config.getIncomingDir()); + + if (!incomingDir.exists()) { + incomingDir.mkdirs(); + } + + } + + if (archiveDir == null) { + archiveDir = new File(config.getArchiveDir()); + + if (!archiveDir.exists()) { + archiveDir.mkdirs(); + } + } + + String curFileName = ""; + try (DirectoryStream stream = Files.newDirectoryStream(incomingDir.toPath())) { + for (Path file: stream) { + curFileName = file.toString(); + handleSuccessfulDownload(null,null, null, null, file.toFile(), archiveDir); + } + } catch (Exception x) { + // IOException can never be thrown by the iteration. + // In this snippet, it can only be thrown by newDirectoryStream. + LOG.warn("Cannot process spool file "+ curFileName, x); + } + + // Deploy scheduled deployments + int numPasses = config.getMaxPasses(); + + deployList = new LinkedList[numPasses]; + + for (int i = 0 ; i < numPasses ; i++) { + deployList[i] = new LinkedList(); + } + for (int pass = 0 ; pass < config.getMaxPasses() ; pass++) { + + if (deployList[pass] != null) { + while (! deployList[pass].isEmpty()) { + DeployableArtifact artifact = deployList[pass].pop(); + + DistributionStatusEnum deployResult = DistributionStatusEnum.DEPLOY_ERROR; + + + try { + + deployResult = deploySpoolFile(artifact); + } catch (Exception e) { + LOG.error("Caught exception trying to deploy file", e); + } + + + IArtifactInfo artifactInfo = artifact.getArtifactInfo(); + + if ((artifactInfo != null) && (data != null)) { + IDistributionClientResult deploymentStatus; + deploymentStatus = client.sendDeploymentStatus(buildStatusMessage( + client, data, artifactInfo, + deployResult)); + } + + } + } + } + } + + private void handleArtifact(INotificationData data, String svcName, String resourceName, String resourceType, IArtifactInfo artifact, File incomingDir, File archiveDir) { + + // Download Artifact + IDistributionClientDownloadResult downloadResult = client + .download(artifact); + + if (downloadResult == null) { + + handleFailedDownload(data, artifact); + return; + } + + byte[] payloadBytes = downloadResult.getArtifactPayload(); + + if (payloadBytes == null) { + handleFailedDownload(data, artifact); + return; + } + + String payload = new String(payloadBytes); + + + File spoolFile = new File(incomingDir.getAbsolutePath() + "/" + artifact.getArtifactName()); + + boolean writeSucceeded = false; + + try { + FileWriter spoolFileWriter = new FileWriter(spoolFile); + spoolFileWriter.write(payload); + spoolFileWriter.close(); + writeSucceeded = true; + } catch (Exception e) { + LOG.error("Unable to save downloaded file to spool directory ("+ incomingDir.getAbsolutePath() +")", e); + } + + + if (writeSucceeded && (downloadResult.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS)) { + handleSuccessfulDownload(data, svcName, resourceName, artifact, spoolFile, archiveDir); + + + } else { + handleFailedDownload(data, artifact); + } + + } + + private void handleFailedDownload(INotificationData data, + IArtifactInfo relevantArtifact) { + // Send Download Status + IDistributionClientResult sendDownloadStatus = client + .sendDownloadStatus(buildStatusMessage(client, data, + relevantArtifact, DistributionStatusEnum.DOWNLOAD_ERROR)); + } + + private void handleSuccessfulDownload(INotificationData data, String svcName, String resourceName, + IArtifactInfo artifact, File spoolFile, File archiveDir) { + + if ((data != null) && (artifact != null)) { + // Send Download Status + IDistributionClientResult sendDownloadStatus = client + .sendDownloadStatus(buildStatusMessage(client, data, artifact, DistributionStatusEnum.DOWNLOAD_OK)); + } + + // If an override file exists, read that instead of the file we just downloaded + ArtifactTypeEnum artifactEnum = ArtifactTypeEnum.YANG_XML; + + boolean toscaYamlType = false; + if (artifact != null) { + String artifactTypeString = artifact.getArtifactType(); + if (artifactTypeString.contains("TOSCA_TEMPLATE")) { + toscaYamlType = true; + } + } else { + if (spoolFile.toString().contains(".yml") || spoolFile.toString().contains(".csar")) { + toscaYamlType = true; + } + } + String overrideFileName = config.getOverrideFile(); + if ((overrideFileName != null) && (overrideFileName.length() > 0)) { + File overrideFile = new File(overrideFileName); + + if (overrideFile.exists()) { + artifactEnum = ArtifactTypeEnum.YANG_XML; + spoolFile = overrideFile; + } + + } + + if (toscaYamlType == true) { + processToscaYaml (data, svcName, resourceName, artifact, spoolFile, archiveDir); + + try { + Path source = spoolFile.toPath(); + Path targetDir = archiveDir.toPath(); + + Files.move(source, targetDir.resolve(source.getFileName()), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + LOG.warn("Could not move "+spoolFile.getAbsolutePath()+" to "+archiveDir.getAbsolutePath(), e); + } + + return; + } + + // Process spool file + Document spoolDoc = null; + File transformedFile = null; + + // Apply XSLTs and get Doc object + try { + if (!spoolFile.isDirectory()) { + transformedFile = applyXslts(spoolFile); + } + } catch (Exception e) { + LOG.error("Caught exception trying to parse XML file", e); + } + + if (transformedFile != null) { + try { + + try { + + DocumentBuilderFactory dbf = DocumentBuilderFactory + .newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + + spoolDoc = db.parse(transformedFile); + } catch (Exception e) { + LOG.error( + "Caught exception trying to parse transformed XML file " + + transformedFile.getAbsolutePath(), e); + } + + } catch (Exception e) { + LOG.error("Caught exception trying to deploy file", e); + } + } + + + if (spoolDoc != null) { + // Analyze file type + SdncArtifactType artifactType = analyzeFileType(artifactEnum, + spoolFile, spoolDoc); + + if (artifactType != null) { + + scheduleDeployment(artifactType, svcName, resourceName, artifact, spoolFile.getName(), transformedFile); + + } + + // SDNGC-2660 : Move file to archive directory even if it is an unrecognized type so that + // we do not keep trying and failing to process it. + try { + Path source = spoolFile.toPath(); + Path targetDir = archiveDir.toPath(); + + Files.move(source, targetDir.resolve(source.getFileName()), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + LOG.warn("Could not move "+spoolFile.getAbsolutePath()+" to "+archiveDir.getAbsolutePath(), e); + } + } + + + } + + + private void processToscaYaml(INotificationData data, String svcName, String resourceName, + IArtifactInfo artifact, File spoolFile, File archiveDir) { + + // Use ASDC Dist Client 1.1.5 with TOSCA parsing APIs to extract relevant TOSCA model data + + // TOSCA data extraction flow 1707: + // Use ASDC dist-client to get yaml string - not yet available + String model_yaml = null; + LOG.info("Process TOSCA YAML file: "+spoolFile.toString()); + + SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); + ISdcCsarHelper sdcCsarHelper = null; + try { + sdcCsarHelper = factory.getSdcCsarHelper(spoolFile.getAbsolutePath()); + } catch (SdcToscaParserException e) { + LOG.error("Could not create SDC TOSCA Parser ", e); + factory.close(); + return; + } + + // Ingest Service Data - 1707 + Metadata serviceMetadata = sdcCsarHelper.getServiceMetadata(); + SdncServiceModel serviceModel = new SdncServiceModel(sdcCsarHelper, serviceMetadata); + serviceModel.setFilename(spoolFile.toString().substring(spoolFile.toString().lastIndexOf("/")+1)); // will be csar file name + serviceModel.setServiceInstanceNamePrefix(SdncBaseModel.extractSubstitutionMappingTypeName(sdcCsarHelper).substring(SdncBaseModel.extractSubstitutionMappingTypeName(sdcCsarHelper).lastIndexOf(".")+1)); + + try { + cleanUpExistingToscaServiceData(serviceModel.getServiceUUID()); + LOG.info("Call insertToscaData for SERVICE_MODEL serviceUUID = " + serviceModel.getServiceUUID()); + insertToscaData(serviceModel.getSql(model_yaml)); + } catch (IOException e) { + LOG.error("Could not insert Tosca YAML data into the SERVICE_MODEL table ", e); + factory.close(); + return; + } + + // Ingest Network (VL) Data - 1707 + //List vlNodeTemplatesList = sdcCsarHelper.getServiceNodeTemplatesByType("VL"); + List vlNodeTemplatesList = sdcCsarHelper.getServiceVlList(); + + for (NodeTemplate nodeTemplate : vlNodeTemplatesList) { + SdncNodeModel nodeModel = new SdncNodeModel (sdcCsarHelper, nodeTemplate); + nodeModel.setServiceUUID(serviceModel.getServiceUUID()); + nodeModel.setEcompGeneratedNaming(SdncBaseModel.extractBooleanInputDefaultValue(sdcCsarHelper, SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_ECOMPGENERATEDNAMING));//service_naming#default#ecomp_generated_naming + + try { + cleanUpExistingToscaData("NETWORK_MODEL", "customization_uuid", nodeModel.getCustomizationUUID()); + cleanUpExistingToscaData("VPN_BINDINGS", "network_customization_uuid", nodeModel.getCustomizationUUID()); + LOG.info("Call insertToscaData for NETWORK_MODEL customizationUUID = " + nodeModel.getCustomizationUUID()); + // using ASDC dist-client use method for get yaml string + insertToscaData(nodeModel.getSql(model_yaml)); + insertToscaData(nodeModel.getVpnBindingsSql()); + } catch (IOException e) { + LOG.error("Could not insert Tosca YAML data into the NETWORK_MODEL table ", e); + } + } + + // Ingest Allotted Resource Data - 1707 + List arNodeTemplatesList = sdcCsarHelper.getAllottedResources(); + + for (NodeTemplate nodeTemplate : arNodeTemplatesList) { + SdncARModel nodeModel = new SdncARModel (sdcCsarHelper, nodeTemplate); + + try { + cleanUpExistingToscaData("ALLOTTED_RESOURCE_MODEL", "customization_uuid", nodeModel.getCustomizationUUID()); + LOG.info("Call insertToscaData for ALLOTTED_RESOURCE_MODEL customizationUUID = " + nodeModel.getCustomizationUUID()); + // using ASDC dist-client use method for get yaml string + insertToscaData(nodeModel.getSql("ALLOTTED_RESOURCE_MODEL", model_yaml)); + } catch (IOException e) { + LOG.error("Could not insert Tosca YAML data into the NETWORK_MODEL table ", e); + } + } + + // Ingest Network (VF) Data - 1707 + //List nodeTemplatesList = sdcCsarHelper.getServiceNodeTemplatesByType("VF"); + List vfNodeTemplatesList = sdcCsarHelper.getServiceVfList(); + + for (NodeTemplate nodeTemplate : vfNodeTemplatesList) { + SdncVFModel vfNodeModel = new SdncVFModel (sdcCsarHelper, nodeTemplate); + + try { + cleanUpExistingToscaData("VF_MODEL", "customization_uuid", vfNodeModel.getCustomizationUUID()) ; + LOG.info("Call insertToscaData for VF_MODEL customizationUUID = " + vfNodeModel.getCustomizationUUID()); + insertToscaData(vfNodeModel.getSql("VF_MODEL", model_yaml)); + } catch (IOException e) { + LOG.error("Could not insert Tosca YAML data into the VF_MODEL table ", e); + } + + // For each VF, insert VF_MODULE_MODEL data + List vfModules = sdcCsarHelper.getVfModulesByVf(vfNodeModel.getCustomizationUUIDNoQuotes()); + for (Group group : vfModules){ + SdncVFModuleModel vfModuleModel = new SdncVFModuleModel(sdcCsarHelper, group); + + try { + cleanUpExistingToscaData("VF_MODULE_MODEL", "customization_uuid", vfModuleModel.getCustomizationUUID()); + LOG.info("Call insertToscaData for VF_MODULE_MODEL customizationUUID = " + vfModuleModel.getCustomizationUUID()); + insertToscaData(vfModuleModel.getSql("VF_MODULE_MODEL", model_yaml)); + } catch (IOException e) { + LOG.error("Could not insert Tosca YAML data into the VF_MODULE_MODEL table ", e); + } + + // For each VF Module, get the VFC list, insert VF_MODULE_TO_VFC_MAPPING data + // List groupMembers = sdcCsarHelper.getMembersOfGroup(group); - old version + // For each vfcNode (group member) in the groupMembers list, extract vm_type and vm_count. + // Insert vf_module.customizationUUID, vfcNode.customizationUUID and vm_type and vm_count into VF_MODULE_TO_VFC_MAPPING + List groupMembers = sdcCsarHelper.getMembersOfVfModule(nodeTemplate, group); // not yet available + for (NodeTemplate vfcNode : groupMembers){ + SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, vfcNode); + + try { + cleanUpExistingToscaData("VF_MODULE_TO_VFC_MAPPING", "vf_module_customization_uuid", vfModuleModel.getCustomizationUUID()); + LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING customizationUUID = " + vfModuleModel.getCustomizationUUID()); + insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" + + vfModuleModel.getCustomizationUUID() + ", " + vfcModel.getCustomizationUUID() + ", \"" + vfcModel.getVmType() + "\", \"" + vfcModel.getVmCount() + "\")"); + } catch (IOException e) { + LOG.error("Could not insert Tosca YAML data into the VF_MODULE_TO_VFC_MAPPING table ", e); + } + + } + + } + + // For each VF, insert VFC_MODEL data + List vfcNodes = sdcCsarHelper.getVfcListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()); + for (NodeTemplate vfcNode : vfcNodes){ + SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, vfcNode); + + try { + cleanUpExistingToscaData("VFC_MODEL", "customization_uuid", vfcModel.getCustomizationUUID()); + LOG.info("Call insertToscaData for VFC_MODEL customizationUUID = " + vfcModel.getCustomizationUUID()); + insertToscaData(vfcModel.getSql("VFC_MODEL", model_yaml)); + } catch (IOException e) { + LOG.error("Could not insert Tosca YAML data into the VFC_MODEL table ", e); + } + + } + + // For each VF, insert VF_TO_NETWORK_ROLE_MAPPING data + List cpNodes = sdcCsarHelper.getCpListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()); + for (NodeTemplate cpNode : cpNodes){ + + // Insert into VF_TO_NETWORK_ROLE_MAPPING vf_customization_uuid and network_role + String cpNetworkRole = sdcCsarHelper.getNodeTemplatePropertyLeafValue(cpNode, "network_role_tag"); + + try { + cleanUpExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", "vf_customization_uuid", vfNodeModel.getCustomizationUUID()); + LOG.info("Call insertToscaData for VF_TO_NETWORK_ROLE_MAPPING vfCustomizationUUID = " + vfNodeModel.getCustomizationUUID()); + insertToscaData("insert into VF_TO_NETWORK_ROLE_MAPPING (vf_customization_uuid, network_role) values (" + + vfNodeModel.getCustomizationUUID() + ", \"" + cpNetworkRole + "\")"); + } catch (IOException e) { + LOG.error("Could not insert Tosca YAML data into the VF_TO_NETWORK_ROLE_MAPPING table ", e); + } + + // Insert VFC_TO_NETWORK_ROLE_MAPPING data + Map mappingParams = new HashMap(); + //String cpNetworkRoleTag = "\"" + sdcCsarHelper.getNodeTemplatePropertyLeafValue(cpNode, SdcPropertyNames.PROPERTY_NAME_NETWORKROLETAG) + "\""; + // extract network_role, network_role_tag and virtual_binding from this cpNode + SdncBaseModel.addParameter("network_role", SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "network_role"), mappingParams); + SdncBaseModel.addParameter("network_role_tag", SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "network_role_tag"), mappingParams); + String virtualBinding = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "requirements#virtualBinding") + "\""; + + // get list of cpNodes and vfcNodes with matching virtualBinding + List> matchList = sdcCsarHelper.getNodeTemplatePairsByReqName(sdcCsarHelper.getCpListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()), sdcCsarHelper.getVfcListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()), virtualBinding); + for (Pair match : matchList) { // should be 1 match? + + // extract values from the left "CP" Node + SdncBaseModel.addParameter("ipv4_use_dhcp", SdncBaseModel.extractBooleanValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_DHCPENABLED), mappingParams); + //SdncBaseModel.addParameter("ipv4_ip_version", SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_IPVERSION), mappingParams); + SdncBaseModel.addParameter("ipv4_ip_version", "dummy_ipv4_vers", mappingParams); + SdncBaseModel.addParameter("ipv6_use_dhcp", SdncBaseModel.extractBooleanValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_DHCPENABLED), mappingParams); + //SdncBaseModel.addParameter("ipv6_ip_version", SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_IPVERSION), mappingParams); + SdncBaseModel.addParameter("ipv6_ip_version", "dummy_ipv6_vers", mappingParams); + //String extcp_subnetpool_id = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_SUBNETPOOLID) + "\""; // need path to subnetpoolid + + // extract values from the right "VFC" Node + String vfcCustomizationUuid = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, match.getRight().getMetadata(), "customization_uuid") + "\""; + SdncBaseModel.addParameter("vm_type", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_VMTYPE), mappingParams); + SdncBaseModel.addIntParameter("ipv4_count", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT), mappingParams); + SdncBaseModel.addIntParameter("ipv6_count", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT), mappingParams); + + try { + cleanUpExistingToscaData("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", vfcCustomizationUuid); + LOG.info("Call insertToscaData for VFC_TO_NETWORK_ROLE_MAPPING vfcCustomizationUUID = " + vfcCustomizationUuid); + insertToscaData(SdncBaseModel.getSql("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", vfcCustomizationUuid, "", mappingParams)); + } catch (IOException e) { + LOG.error("Could not insert Tosca YAML data into the VFC_TO_NETWORK_ROLE_MAPPING table ", e); + } + + } + + } // CP loop + + } // VF loop + + // Close ASDC TOSCA Parser factory - we are done processing this distribution + factory.close(); + + if ((artifact != null) && (data != null)) { + LOG.info("Update to SDN-C succeeded"); + IDistributionClientResult deploymentStatus; + deploymentStatus = client.sendDeploymentStatus(buildStatusMessage( + client, data, artifact, + DistributionStatusEnum.DEPLOY_OK)); + } + + } + + private void cleanUpExistingToscaData(String tableName, String keyName, String keyValue) throws IOException + { + + if (jdbcDataSource == null) { + setJdbcDataSource(); + } + try { + int rowCount = 0; + CachedRowSet data = jdbcDataSource.getData("SELECT * from " + tableName + " where " + keyName + " = " + keyValue + ";", null, ""); + while(data.next()) { + rowCount ++; + } + if (rowCount != 0) { + LOG.info("cleanUpExistingToscaData: " + keyValue); + jdbcDataSource.writeData("DELETE from " + tableName + " where " + keyName + " = " + keyValue + ";", null, null); + } + + } catch (SQLException e) { + LOG.error("Could not clean up existing " + tableName + " for " + keyValue, e); + } + + } + + + private void cleanUpExistingToscaServiceData(String serviceUUID) throws IOException + { + + if (jdbcDataSource == null) { + setJdbcDataSource(); + } + try { + int rowCount = 0; + CachedRowSet data = jdbcDataSource.getData("SELECT * from SERVICE_MODEL where service_uuid = " + serviceUUID + ";", null, ""); + while(data.next()) { + rowCount ++; + } + if (rowCount != 0) { + LOG.info("cleanUpExistingToscaData: " + serviceUUID); + jdbcDataSource.writeData("DELETE from NETWORK_MODEL where service_uuid = " + serviceUUID + ";", null, null); + jdbcDataSource.writeData("DELETE from SERVICE_MODEL where service_uuid = " + serviceUUID + ";", null, null); + } + + } catch (SQLException e) { + LOG.error("Could not clean up existing NETWORK_MODEL and SERVICE_MODEL for service_UUID " + serviceUUID, e); + } + + } + + + private void insertToscaData(String toscaDataString) throws IOException + { + LOG.debug("insertToscaData: " + toscaDataString); + + if (jdbcDataSource == null) { + setJdbcDataSource(); + } + try { + + jdbcDataSource.writeData(toscaDataString, null, null); + + } catch (SQLException e) { + LOG.error("Could not insert Tosca YAML data into the database ", e); + } + + } + + + private SdncArtifactType analyzeFileType(ArtifactTypeEnum artifactType, File spoolFile, Document spoolDoc) { + + if (artifactType != ArtifactTypeEnum.YANG_XML) { + LOG.error("Unexpected artifact type - expecting YANG_XML, got "+artifactType); + return (null); + } + + // Examine outer tag + + try { + + + Element root = spoolDoc.getDocumentElement(); + + String rootName = root.getTagName(); + + if (rootName.contains(":")) { + String[] rootNameElems = rootName.split(":"); + rootName = rootNameElems[rootNameElems.length - 1]; + } + + if (rootName != null) { + SdncArtifactType mapEntry = config.getMapping(rootName); + + + if (mapEntry == null) { + + LOG.error("Unexpected file contents - root tag is "+rootName); + } + return(mapEntry); + } else { + LOG.error("Cannot get root tag from file"); + return(null); + } + + } catch (Exception e) { + LOG.error("Could not parse YANG_XML file "+spoolFile.getName(), e); + return(null); + } + } + + private void scheduleDeployment(SdncArtifactType type, String svcName, String resourceName, IArtifactInfo artifactInfo, String spoolFileName, File spoolFile) { + + if (type.getPass() < deployList.length) { + + if (artifactInfo != null) { + LOG.debug("Scheduling "+artifactInfo.getArtifactName()+" version "+artifactInfo.getArtifactVersion()+" for deployment"); + + deployList[type.getPass()].add(new DeployableArtifact(type, svcName, resourceName, artifactInfo, spoolFile)); + } else { + SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss.SSS");//dd/MM/yyyy + Date now = new Date(); + String artifactVersion = sdfDate.format(now); + LOG.debug("Scheduling "+spoolFileName+" version "+artifactVersion+" for deployment"); + String artifactName = spoolFileName; + if (artifactInfo != null) { + artifactName = artifactInfo.getArtifactName(); + } + deployList[type.getPass()].add(new DeployableArtifact(type, svcName, resourceName, artifactName, artifactVersion, spoolFile)); + } + } else { + LOG.info("Pass for type "+type.getTag()+" is "+type.getPass()+" which is not <= "+deployList.length); + } + } + + + private DistributionStatusEnum deploySpoolFile(DeployableArtifact artifact) { + + DistributionStatusEnum deployResult = DistributionStatusEnum.DEPLOY_OK; + + StringBuffer msgBuffer = new StringBuffer(); + + + String namespace = config.getAsdcApiNamespace(); + if ((namespace == null) || (namespace.length() == 0)) { + namespace="com:att:sdnctl:asdcapi"; + } + + msgBuffer.append("\n"); + + String svcName = artifact.getSvcName(); + String resourceName = artifact.getResourceName(); + String artifactName = artifact.getArtifactName(); + + if (svcName != null) { + if (resourceName != null) { + artifactName = svcName + "/" + resourceName + "/" + artifactName; + } else { + artifactName = svcName + "/" + artifactName; + } + } + + msgBuffer.append(""+artifactName+"\n"); + msgBuffer.append(""+artifact.getArtifactVersion()+"\n"); + + + try { + BufferedReader rdr = new BufferedReader(new FileReader(artifact.getFile())); + + String curLine = rdr.readLine(); + + while (curLine != null) { + + if (!curLine.startsWith("\n"); + + + byte[] msgBytes = msgBuffer.toString().getBytes(); + + Document results = postRestXml(artifact.getType().getRpcUrl(config.getAsdcApiBaseUrl()), msgBytes); + + if (results == null) { + + deployResult = DistributionStatusEnum.DEPLOY_ERROR; + } else { + + XPathFactory xpf = XPathFactory.newInstance(); + XPath xp = xpf.newXPath(); + + String asdcApiResponseCode = "500"; + + try { + + asdcApiResponseCode = xp.evaluate("//asdc-api-response-code[position()=1]/text()", results.getDocumentElement()); + } catch (Exception e) { + LOG.error("Caught exception retrying to evaluate xpath", e); + } + + if (asdcApiResponseCode.contains("200")) { + LOG.info("Update to SDN-C succeeded"); + deployResult = DistributionStatusEnum.DEPLOY_OK; + } else { + LOG.info("Update to SDN-C failed (response code "+asdcApiResponseCode+")"); + + if (asdcApiResponseCode.contains("409")) { + deployResult = DistributionStatusEnum.ALREADY_DEPLOYED; + } else { + + deployResult = DistributionStatusEnum.DEPLOY_ERROR; + } + } + } + + + + return(deployResult); + } + + + + + + public static IDistributionStatusMessage buildStatusMessage( + final IDistributionClient client, final INotificationData data, + final IArtifactInfo relevantArtifact, + final DistributionStatusEnum status) { + IDistributionStatusMessage statusMessage = new IDistributionStatusMessage() { + + @Override + public long getTimestamp() { + long currentTimeMillis = System.currentTimeMillis(); + return currentTimeMillis; + } + + @Override + public DistributionStatusEnum getStatus() { + return status; + } + + @Override + public String getDistributionID() { + return data.getDistributionID(); + } + + @Override + public String getConsumerID() { + return client.getConfiguration().getConsumerID(); + } + + @Override + public String getArtifactURL() { + return relevantArtifact.getArtifactURL(); + } + }; + return statusMessage; + + } + + private HttpURLConnection getRestXmlConnection(String urlString, String method) throws IOException + { + URL sdncUrl = new URL(urlString); + Authenticator.setDefault(new SdncAuthenticator(config.getSdncUser(), config.getSdncPasswd())); + + HttpURLConnection conn = (HttpURLConnection) sdncUrl.openConnection(); + + String authStr = config.getSdncUser()+":"+config.getSdncPasswd(); + String encodedAuthStr = new String(Base64.encodeBase64(authStr.getBytes())); + + conn.addRequestProperty("Authentication", "Basic "+encodedAuthStr); + + conn.setRequestMethod(method); + conn.setRequestProperty("Content-Type", "application/xml"); + conn.setRequestProperty("Accept", "application/xml"); + + conn.setDoInput(true); + conn.setDoOutput(true); + conn.setUseCaches(false); + + return(conn); + + } + + private Document postRestXml(String urlString, byte[] msgBytes) { + Document response = null; + + try { + SdncOdlConnection odlConn = SdncOdlConnection.newInstance(urlString, config.getSdncUser(), config.getSdncPasswd()); + + String sdncResp = odlConn.send("POST", "application/xml", new String(msgBytes)); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + + + response = db.parse(new ByteArrayInputStream(sdncResp.getBytes())); + } catch (Exception e) { + LOG.error("Caught exception posting to ODL tier", e); + } + + return(response); + + } + + private File applyXslts(File srcFile) { + + Document doc = null; + + + File inFile = srcFile; + File outFile = null; + + String xsltPathList = config.getXsltPathList(); + + if ((xsltPathList == null) || (xsltPathList.length() == 0)) { + outFile = inFile; + } else { + + String[] xsltPaths = xsltPathList.split(","); + + for (String xsltPath : xsltPaths) { + try{ + + outFile = File.createTempFile("tmp", "xml"); + TransformerFactory factory = TransformerFactory.newInstance(); + Source xslt = new StreamSource(new File(xsltPath)); + Transformer transformer = factory.newTransformer(xslt); + Source text = new StreamSource(inFile); + + + transformer.transform(text, new StreamResult(outFile)); + + inFile = outFile; + + } catch (Exception e) { + LOG.error("Caught exception trying to apply XSLT template "+xsltPath, e); + + } + + } + } + + // After transformations, parse transformed XML + + + return(outFile); + } + + private String escapeFilename(String str) { + StringBuffer retval = new StringBuffer(); + + for (int i = 0 ; i < str.length() ; i++) { + char curchar = str.charAt(i); + if (Character.isJavaIdentifierPart(curchar)) { + retval.append(curchar); + } + } + + return(retval.toString()); + + } + +} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java new file mode 100644 index 000000000..e8ffc3333 --- /dev/null +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.api.IDistributionClient; +import org.openecomp.sdc.api.results.IDistributionClientResult; +import org.openecomp.sdc.impl.DistributionClientFactory; +import org.openecomp.sdc.utils.DistributionActionResultEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdncUebClient { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncUebConfiguration.class); + + public static void main(String[] args) { + IDistributionClient client = DistributionClientFactory + .createDistributionClient(); + + SdncUebConfiguration config = new SdncUebConfiguration(); + + SdncUebCallback cb = new SdncUebCallback(client, config); + + LOG.info("Scanning for local distribution artifacts before starting client"); + cb.deployDownloadedFiles(null, null, null); + + LOG.info("Initializing ASDC distribution client"); + + IDistributionClientResult result = client.init( + config, cb); + + LOG.info("Initialized ASDC distribution client - results = " + + result.getDistributionMessageResult()); + + if (result.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) { + LOG.info("Starting client..."); + IDistributionClientResult start = client.start(); + LOG.info("Client startup result = " + + start.getDistributionMessageResult()); + } + + + } + +} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java new file mode 100644 index 000000000..bf0d5b823 --- /dev/null +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java @@ -0,0 +1,280 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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 java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; + +import org.openecomp.sdc.api.consumer.IConfiguration; +import org.openecomp.sdc.utils.ArtifactTypeEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdncUebConfiguration implements IConfiguration{ + + private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; + private static final Logger LOG = LoggerFactory + .getLogger(SdncUebConfiguration.class); + + private String asdcAddress = null; + private String consumerGroup = null; + private String consumerID = null; + private String environmentName = null; + private String password = null; + private int pollingInterval = 30; + private int pollingTimeout = 15; + private List relevantArtifactTypes = null; + private String user = null; + + private String sdncUser = null; + private String sdncPasswd = null; + private String asdcApiBaseUrl = null; + private String asdcApiNamespace = null; + + private SdncArtifactMap artifactMap = SdncArtifactMap.getInstance(); + + public String getAsdcApiNamespace() { + return asdcApiNamespace; + } + + private String incomingDir = null; + + private String archiveDir = null; + + private String overrideFile = null; + + private boolean activateServerTLSAuth; + private String keyStorePassword; + private String keyStorePath; + + private String xsltPathList; + + public String getXsltPathList() { + return xsltPathList; + } + + public String getOverrideFile() { + return overrideFile; + } + + public SdncUebConfiguration() { + + try { + init(); + } catch (Exception e) { + LOG.error("Cannot initialize SdncUebConfiguration", e); + } + } + + public void init() throws IOException { + String propPath = null; + String propDir = System.getenv(SDNC_CONFIG_DIR); + if (propDir == null) { + + propDir = "/opt/sdnc/data/properties"; + } + propPath = propDir + "/ueb-listener.properties"; + File propFile = new File(propPath); + + + if (!propFile.exists()) { + + throw new FileNotFoundException( + "Missing configuration properties file : " + + propFile); + } + + Properties props = new Properties(); + props.load(new FileInputStream(propFile)); + + asdcAddress = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.asdc-address"); + consumerGroup = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.consumer-group"); + consumerID = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.consumer-id"); + environmentName = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.environment-name"); + password = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.password"); + user = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.user"); + + sdncUser = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.sdnc-user"); + sdncPasswd = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.sdnc-passwd"); + asdcApiBaseUrl = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.asdc-api-base-url"); + asdcApiNamespace = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.asdc-api-namespace"); + + incomingDir = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.spool.incoming"); + archiveDir = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.spool.archive"); + overrideFile = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.override-file"); + + String curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.polling-interval"); + if ((curval != null) && (curval.length() > 0)) { + try { + pollingInterval = Integer.parseInt(curval); + } catch (Exception e) { + LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-interval ("+curval+")"); + } + } + + curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.polling-timeout"); + if ((curval != null) && (curval.length() > 0)) { + try { + pollingTimeout = Integer.parseInt(curval); + } catch (Exception e) { + LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-timeout ("+curval+")"); + } + } + + curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.relevant-artifact-types"); + if ((curval != null) && (curval.length() > 0)) { + String[] artifactTypes = curval.split(","); + + relevantArtifactTypes = new LinkedList(); + + for (int i = 0 ; i < artifactTypes.length ; i++) { + try { + if (ArtifactTypeEnum.valueOf(artifactTypes[i]) != null) { + relevantArtifactTypes.add(artifactTypes[i]); + } else { + LOG.warn("Skipping unrecognized artifact type "+artifactTypes[i]); + } + } catch (Exception e) { + + LOG.warn("Caught exception validating artifact type "+artifactTypes[i], e); + } + + } + + } + + curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.activate-server-tls-auth", "false"); + activateServerTLSAuth = "true".equalsIgnoreCase(curval); + keyStorePath = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.keystore-path"); + keyStorePassword = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.keystore-password"); + xsltPathList = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.xslt-path-list"); + + + String artifactMapFile = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.artifact-map"); + if (artifactMapFile != null) { + artifactMap.load(artifactMapFile); + } + + } + + @Override + public String getAsdcAddress() { + return asdcAddress; + } + + @Override + public String getConsumerGroup() { + return consumerGroup; + } + + @Override + public String getConsumerID() { + return consumerID; + } + + @Override + public String getEnvironmentName() { + return environmentName; + } + + @Override + public String getPassword() { + return password; + } + + @Override + public int getPollingInterval() { + return pollingInterval; + } + + @Override + public int getPollingTimeout() { + return pollingTimeout; + } + + @Override + public List getRelevantArtifactTypes() { + return relevantArtifactTypes; + } + + @Override + public String getUser() { + return user; + } + + + public String getSdncUser() { + return sdncUser; + } + + public String getSdncPasswd() { + return sdncPasswd; + } + + public String getAsdcApiBaseUrl() { + return asdcApiBaseUrl; + } + + @Override + public boolean activateServerTLSAuth() { + return activateServerTLSAuth; + } + + @Override + public String getKeyStorePassword() { + return keyStorePassword; + } + + @Override + public String getKeyStorePath() { + return keyStorePath; + } + + public String getIncomingDir() { + return incomingDir; + } + + public String getArchiveDir() { + return archiveDir; + } + + public int getMaxPasses() { + return(artifactMap.getNumPasses()); + } + + public SdncArtifactMap.SdncArtifactType getMapping(String tag) { + return(artifactMap.getMapping(tag)); + } + + @Override + public boolean isFilterInEmptyResources() { + // TODO Auto-generated method stub + return false; + } + + +} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java new file mode 100644 index 000000000..76f015f9a --- /dev/null +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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 SdncVFCModel extends SdncBaseModel { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncVFCModel.class); + + private String vmType = null; + private String vmCount = null; + + public SdncVFCModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { + + super(sdcCsarHelper, nodeTemplate); + + // extract properties + vmType = extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VMTYPE); + //vmCount = extractValue (sdcCsarHelper, nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VMCOUNT); - need path to vm_count + vmCount = "1"; + addParameter("vm_type", vmType); + addParameter("vm_type_tag", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG)); + addParameter("ecomp_generated_naming", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VFCNAMING_ECOMPGENERATEDNAMING)); + addParameter("naming_policy", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VFCNAMING_NAMINGPOLICY)); + addParameter("nfc_naming_code", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFCCODE)); + } + + public String getVmType() { + return vmType; + } + + public void setVmType(String vmType) { + this.vmType = vmType; + } + + public String getVmCount() { + return vmCount; + } + + public void setVmCount(String vmCount) { + this.vmCount = vmCount; + } + +} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java new file mode 100644 index 000000000..cd79689b4 --- /dev/null +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.Metadata; +import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdncVFModel extends SdncBaseModel { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncVFModel.class); + + public SdncVFModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { + + super(sdcCsarHelper, nodeTemplate); + + // extract metadata + Metadata metadata = nodeTemplate.getMetadata(); + addParameter("name", extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_NAME)); + addParameter("vendor", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDOR)); + addParameter("vendor_version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDORRELEASE)); + + // extract properties + addParameter("ecomp_generated_naming", extractBooleanValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VNFECOMPNAMING_ECOMPGENERATEDNAMING)); + addParameter("naming_policy", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VNFECOMPNAMING_NAMINGPOLICY)); + addParameter("nf_type", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)); + addParameter("nf_role", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)); + addParameter("nf_code", extractValue( nodeTemplate, "nf_naming_code")); + addParameter("nf_function", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)); + addParameter("avail_zone_max_count", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONEMAXCOUNT)); + } + +} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java new file mode 100644 index 000000000..7ae6c3107 --- /dev/null +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP 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.Group; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdncVFModuleModel extends SdncBaseModel { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncVFModuleModel.class); + + public SdncVFModuleModel(ISdcCsarHelper sdcCsarHelper, Group group) { + + super(sdcCsarHelper, group); + + // extract properties + addParameter("vf_module_type", extractValue(group, SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE)); + addIntParameter("availability_zone_count", extractValue(group, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)); + addParameter("ecomp_generated_vm_assignments", extractBooleanValue(group, SdcPropertyNames.PROPERTY_NAME_ECOMPGENERATEDVMASSIGNMENTS)); + } + +} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncARModel.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncARModel.java deleted file mode 100644 index 3472b443a..000000000 --- a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncARModel.java +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP 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.openecomp.sdnc.uebclient; - -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames; -import org.openecomp.sdc.toscaparser.api.Metadata; -import org.openecomp.sdc.toscaparser.api.NodeTemplate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SdncARModel extends SdncBaseModel { - - private static final Logger LOG = LoggerFactory - .getLogger(SdncARModel.class); - - public SdncARModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { - - super(sdcCsarHelper, nodeTemplate); - - // extract metadata - Metadata metadata = nodeTemplate.getMetadata(); - addParameter("type", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_TYPE)); - - // extract properties - //addParameter("role", extractValue (sdcCsarHelper, nodeTemplate, SdcPropertyNames.PROPERTY_NAME_ROLE)); - //addParameter("type", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_TYPE)); - wrong location, get from metadata - addParameter("ecomp_generated_naming", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VFCNAMING_ECOMPGENERATEDNAMING)); - addParameter("naming_policy", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VFCNAMING_NAMINGPOLICY)); - //addParameter("depending_service", extractValue (sdcCsarHelper, nodeTemplate, SdcPropertyNames.PROPERTY_NAME_DEPENDINGSERVICE)); - //addParameter("service_dependency", extractValue (sdcCsarHelper, nodeTemplate, SdcPropertyNames.PROPERTY_NAME_SERVICEDEPENDENCY)); - } - -} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncArtifactMap.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncArtifactMap.java deleted file mode 100644 index 4a9f02a8e..000000000 --- a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncArtifactMap.java +++ /dev/null @@ -1,134 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP 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.openecomp.sdnc.uebclient; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SdncArtifactMap { - - private static final Logger LOG = LoggerFactory - .getLogger(SdncArtifactMap.class); - - public class SdncArtifactType { - private String tag; - private String artifactType; - private String rpc; - private int pass; - - public String getTag() { - return tag; - } - public String getArtifactType() { - return artifactType; - } - public String getRpc() { - return rpc; - } - - public int getPass() { - return pass; - } - - public String getRpcUrl(String base) { - return(base+rpc); - } - - private SdncArtifactType(String tag, String rpc, String pass) { - this.tag = tag; - this.rpc = rpc; - try { - this.pass = Integer.parseInt(pass); - } catch (Exception e) { - LOG.error("Invalid pass value for artifact map entry ("+tag+","+rpc+","+pass+")"); - } - } - } - - - - private Map mapItems = new HashMap(); - - private int NumPasses = 1; - - public int getNumPasses() { - return NumPasses; - } - - public void load(String fileName) { - - File mapFile = new File(fileName); - - if (mapFile.exists() && mapFile.canRead()) { - - BufferedReader rdr = null; - try { - - rdr = new BufferedReader(new FileReader(mapFile)); - - for (String ln ; (ln = rdr.readLine()) != null ; ) { - String[] lnFields = ln.split(","); - if (lnFields.length == 3) { - SdncArtifactType entry = new SdncArtifactType(lnFields[0], lnFields[1], lnFields[2]); - mapItems.put(entry.getTag(), entry); - if (entry.getPass() + 1 > NumPasses ) { - NumPasses = entry.getPass() + 1; - } - } - } - - - } catch (Exception e) { - LOG.error("Caught exception reading artifact map", e); - return; - } finally { - if (rdr != null) { - try { - rdr.close(); - } catch (IOException e) { - - } - } - } - } - } - - public SdncArtifactType getMapping(String tag) { - if (mapItems.containsKey(tag)) { - return(mapItems.get(tag)); - } else { - return(null); - } - } - - public static SdncArtifactMap getInstance() { - return new SdncArtifactMap(); - } - -} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncBaseModel.java deleted file mode 100644 index 39c50aed0..000000000 --- a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncBaseModel.java +++ /dev/null @@ -1,297 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP 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.openecomp.sdnc.uebclient; - -import java.util.HashMap; -import java.util.Map; - -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames; -import org.openecomp.sdc.toscaparser.api.Group; -import org.openecomp.sdc.toscaparser.api.Metadata; -import org.openecomp.sdc.toscaparser.api.NodeTemplate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SdncBaseModel { - - private static final Logger LOG = LoggerFactory - .getLogger(SdncBaseModel.class); - - protected String customizationUUID = null; - protected String invariantUUID = null; - protected String model_yaml = null; - protected String version = null; - - protected Map params = null; - protected ISdcCsarHelper sdcCsarHelper = null; - - public SdncBaseModel() { - - } - - public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata) { - - params = new HashMap(); - this.sdcCsarHelper = sdcCsarHelper; - - // extract service metadata - invariantUUID = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID); - addParameter("invariant_uuid",invariantUUID); - addParameter("version",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_VERSION)); - addParameter("name",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_NAME)); - addParameter("description",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); - addParameter("type",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_TYPE)); - addParameter("category",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_CATEGORY)); - } - - public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { - - params = new HashMap(); - this.sdcCsarHelper = sdcCsarHelper; - - // extract nodeTemplate metadata - Metadata metadata = nodeTemplate.getMetadata(); - customizationUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); - addParameter("invariant_uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); - addParameter("uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_UUID)); - addParameter("version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VERSION)); - } - - public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Group group) { - - params = new HashMap(); - this.sdcCsarHelper = sdcCsarHelper; - - // extract group metadata - Metadata metadata = group.getMetadata(); - //customizationUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULECUSTOMIZATIONUUID); - returning null - customizationUUID = extractValue (metadata, "vfModuleModelCustomizationUUID"); - addParameter("invariant_uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)); - addParameter("uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)); - addParameter("version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)); - } - - protected void addParameter (String name, String value) { - if (value != null && !value.isEmpty()) { - params.put(name, "\"" + value + "\""); - } - } - - protected void addIntParameter (String name, String value) { - if (value != null && !value.isEmpty()) { - params.put(name, value); - } - } - - public static void addIntParameter (String name, String value, Map params) { - if (value != null && !value.isEmpty()) { - params.put(name, value); - } - } - - public static void addParameter (String name, String value, Map params) { - if (value != null && !value.isEmpty()) { - params.put(name, "\"" + value + "\""); - } - } - - protected String extractValue (Metadata metadata, String name) { - String value = sdcCsarHelper.getMetadataPropertyValue(metadata, name); - if (value != null) { - return value; - } else { - return ""; - } - } - - public static String extractValue (ISdcCsarHelper sdcCsarHelper, Metadata metadata, String name) { - String value = sdcCsarHelper.getMetadataPropertyValue(metadata, name); - if (value != null) { - return value; - } else { - return ""; - } - } - - protected String extractValue (NodeTemplate nodeTemplate, String name) { - String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); - if (value != null) { - return value; - } else { - return ""; - } - } - - public static String extractValue (ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, String name) { - String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); - if (value != null) { - return value; - } else { - return ""; - } - } - - protected String extractBooleanValue (NodeTemplate nodeTemplate, String name) { - String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); - if (value != null && !value.isEmpty()) { - return value.contains("true") ? "Y" : "N"; - } else { - return ""; - } - } - - public static String extractBooleanValue (ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, String name) { - String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); - if (value != null && !value.isEmpty()) { - return value.contains("true") ? "Y" : "N"; - } else { - return ""; - } - } - - protected String extractValue (Group group, String name) { - String value = sdcCsarHelper.getGroupPropertyLeafValue(group, name); - if (value != null) { - return value; - } else { - return ""; - } - } - - protected String extractBooleanValue (Group group, String name) { - String value = sdcCsarHelper.getGroupPropertyLeafValue(group, name); - if (value != null && !value.isEmpty()) { - return value.contains("true") ? "Y" : "N"; - } else { - return ""; - } - } - - protected String extractInputDefaultValue (String name) { - String value = sdcCsarHelper.getServiceInputLeafValueOfDefault(name); - if (value != null) { - return value; - } else { - return ""; - } - } - - protected String extractBooleanInputDefaultValue (String name) { - String value = sdcCsarHelper.getServiceInputLeafValueOfDefault(name); - if (value != null && !value.isEmpty()) { - return value.contains("true") ? "Y" : "N"; - } else { - return ""; - } - } - - public static String extractInputDefaultValue (ISdcCsarHelper sdcCsarHelper, String name) { - String value = sdcCsarHelper.getServiceInputLeafValueOfDefault(name); - if (value != null) { - return value; - } else { - return ""; - } - } - - public static String extractBooleanInputDefaultValue (ISdcCsarHelper sdcCsarHelper, String name) { - String value = sdcCsarHelper.getServiceInputLeafValueOfDefault(name); - if (value != null && !value.isEmpty()) { - return value.contains("true") ? "Y" : "N"; - } else { - return ""; - } - } - - public static String extractSubstitutionMappingTypeName (ISdcCsarHelper sdcCsarHelper) { - String value = sdcCsarHelper.getServiceSubstitutionMappingsTypeName(); - if (value != null) { - return value; - } else { - return ""; - } - } - - public String getCustomizationUUID() { - return ("\"" + customizationUUID + "\""); - } - public String getCustomizationUUIDNoQuotes() { - return (customizationUUID); - } - public void setCustomizationUUID(String customizationUUID) { - this.customizationUUID = customizationUUID; - } - - public String getSql(String tableName, String model_yaml) { - - StringBuilder sb = new StringBuilder(); - sb.append("INSERT into " + tableName + " (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 (" + 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 static String getSql(String tableName, String keyName, String keyValue, String model_yaml, Map params) { - - StringBuilder sb = new StringBuilder(); - sb.append("INSERT into " + tableName + " (" + keyName + ", "); - - int paramCount = 0; - for (String paramKey : params.keySet()) { - paramCount++; - sb.append(paramKey); - if (paramCount < params.size()) sb.append(", "); - } - - sb.append(") values (" + keyValue + ", "); - - 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(); - } - -} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncNodeModel.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncNodeModel.java deleted file mode 100644 index f8e5a5b8f..000000000 --- a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncNodeModel.java +++ /dev/null @@ -1,145 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP 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.openecomp.sdnc.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 static final Logger LOG = LoggerFactory - .getLogger(SdncNodeModel.class); - - 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 inputs - 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(); - } - -} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncOdlConnection.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncOdlConnection.java deleted file mode 100644 index 4e0cffab1..000000000 --- a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncOdlConnection.java +++ /dev/null @@ -1,158 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP 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.openecomp.sdnc.uebclient; - -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.Authenticator; -import java.net.HttpURLConnection; -import java.net.PasswordAuthentication; -import java.net.URL; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLSession; - -import org.apache.commons.codec.binary.Base64; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -public class SdncOdlConnection { - - private static final Logger LOG = LoggerFactory - .getLogger(SdncOdlConnection.class); - - private HttpURLConnection httpConn = null; - - private String url = null; - private String user = null; - private String password = null; - - private class SdncAuthenticator extends Authenticator { - - private String user; - private String passwd; - - SdncAuthenticator(String user, String passwd) { - this.user = user; - this.passwd = passwd; - } - @Override - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(user, passwd.toCharArray()); - } - - } - - private SdncOdlConnection() { - - } - - private SdncOdlConnection(String url, String user, String password) { - this.url = url; - this.user = user; - this.password = password; - - try { - URL sdncUrl = new URL(url); - Authenticator.setDefault(new SdncAuthenticator(user, password)); - - this.httpConn = (HttpURLConnection) sdncUrl.openConnection(); - } catch (Exception e) { - LOG.error("Unable to create http connection", e); - } - } - - public static SdncOdlConnection newInstance(String url, String user, String password) throws IOException - { - return (new SdncOdlConnection(url, user, password)); - } - - - - public String send(String method, String contentType, String msg) throws IOException { - - LOG.info("Sending REST " + method + " to " + url); - LOG.info("Message body:\n" + msg); - String authStr = user + ":" + password; - String encodedAuthStr = new String(Base64.encodeBase64(authStr.getBytes())); - - httpConn.addRequestProperty("Authentication", "Basic " + encodedAuthStr); - - httpConn.setRequestMethod(method); - httpConn.setRequestProperty("Content-Type", contentType); - httpConn.setRequestProperty("Accept", contentType); - - httpConn.setDoInput(true); - httpConn.setDoOutput(true); - httpConn.setUseCaches(false); - - if (httpConn instanceof HttpsURLConnection) { - HostnameVerifier hostnameVerifier = new HostnameVerifier() { - @Override - public boolean verify(String hostname, SSLSession session) { - return true; - } - }; - ((HttpsURLConnection) httpConn).setHostnameVerifier(hostnameVerifier); - } - - // Write message - httpConn.setRequestProperty("Content-Length", "" + msg.length()); - DataOutputStream outStr = new DataOutputStream(httpConn.getOutputStream()); - outStr.write(msg.getBytes()); - outStr.close(); - - // Read response - BufferedReader respRdr; - - LOG.info("Response: " + httpConn.getResponseCode() + " " + httpConn.getResponseMessage()); - - if (httpConn.getResponseCode() < 300) { - - respRdr = new BufferedReader(new InputStreamReader(httpConn.getInputStream())); - } else { - respRdr = new BufferedReader(new InputStreamReader(httpConn.getErrorStream())); - } - - StringBuffer respBuff = new StringBuffer(); - - String respLn; - - while ((respLn = respRdr.readLine()) != null) { - respBuff.append(respLn + "\n"); - } - respRdr.close(); - - String respString = respBuff.toString(); - - LOG.info("Response body :\n" + respString); - - return (respString); - - } - - -} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncServiceModel.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncServiceModel.java deleted file mode 100644 index 0f645d7a3..000000000 --- a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncServiceModel.java +++ /dev/null @@ -1,98 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP 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.openecomp.sdnc.uebclient; - -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames; -import org.openecomp.sdc.toscaparser.api.Metadata; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SdncServiceModel extends SdncBaseModel { - - private static final Logger LOG = LoggerFactory - .getLogger(SdncServiceModel.class); - - private String UUID = null; - private String serviceInstanceNamePrefix = null; - private String filename = null; - - public SdncServiceModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata) { - - super(sdcCsarHelper, metadata); - - UUID = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_UUID); - - // extract service topology template input data - addParameter("ecomp_naming",extractBooleanInputDefaultValue(SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_ECOMPGENERATEDNAMING)); - addParameter("naming_policy",extractInputDefaultValue(SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_NAMINGPOLICY)); - } - - public String getServiceUUID() { - return ("\"" + UUID + "\""); - } - public void setServiceUUID(String serviceUUID) { - this.UUID = serviceUUID; - } - public String getServiceInstanceNamePrefix() { - return serviceInstanceNamePrefix; - } - public void setServiceInstanceNamePrefix(String serviceInstanceNamePrefix) { - if (serviceInstanceNamePrefix != null && !serviceInstanceNamePrefix.isEmpty()) { - this.serviceInstanceNamePrefix = serviceInstanceNamePrefix; - params.put("service_instance_name_prefix", "\"" + serviceInstanceNamePrefix + "\""); - } - } - public String getFilename() { - return filename; - } - public void setFilename(String filename) { - this.filename = filename; - } - - public String getSql(String model_yaml) { - - StringBuilder sb = new StringBuilder(); - sb.append("INSERT into SERVICE_MODEL (service_uuid, model_yaml, filename, "); - - int paramCount = 0; - for (String paramKey : params.keySet()) { - paramCount++; - sb.append(paramKey); - if (paramCount < params.size()) sb.append(", "); - } - - sb.append(") values (" + getServiceUUID() + ", \"" + model_yaml + "\", \"" + filename + "\", "); - - 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(); - } - -} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebCallback.java deleted file mode 100644 index 496c2cef8..000000000 --- a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebCallback.java +++ /dev/null @@ -1,1125 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP 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.openecomp.sdnc.uebclient; - -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.net.Authenticator; -import java.net.HttpURLConnection; -import java.net.PasswordAuthentication; -import java.net.URL; -import java.nio.file.DirectoryStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.sql.SQLException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import javax.sql.rowset.CachedRowSet; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.stream.StreamResult; -import javax.xml.transform.stream.StreamSource; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathFactory; - -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.lang3.tuple.Pair; -import org.onap.ccsdk.sli.core.dblib.DBResourceManager; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.consumer.IDistributionStatusMessage; -import org.openecomp.sdc.api.consumer.INotificationCallback; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.notification.IResourceInstance; -import org.openecomp.sdc.api.results.IDistributionClientDownloadResult; -import org.openecomp.sdc.api.results.IDistributionClientResult; -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames; -import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory; -import org.openecomp.sdc.toscaparser.api.Group; -import org.openecomp.sdc.toscaparser.api.Metadata; -import org.openecomp.sdc.toscaparser.api.NodeTemplate; -import org.openecomp.sdc.utils.ArtifactTypeEnum; -import org.openecomp.sdc.utils.DistributionActionResultEnum; -import org.openecomp.sdc.utils.DistributionStatusEnum; -import org.openecomp.sdnc.uebclient.SdncArtifactMap.SdncArtifactType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -public class SdncUebCallback implements INotificationCallback { - - private static final Logger LOG = LoggerFactory - .getLogger(SdncUebCallback.class); - - private static DBResourceManager jdbcDataSource = null; - private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; - - - private class SdncAuthenticator extends Authenticator { - - private final String user; - private final String passwd; - - SdncAuthenticator(String user, String passwd) { - this.user = user; - this.passwd = passwd; - } - @Override - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(user, passwd.toCharArray()); - } - - } - - private class DeployableArtifact { - SdncArtifactType type; - IArtifactInfo artifactInfo; - String svcName; - String resourceName; - String artifactName; - String artifactVersion; - File file; - - public String getArtifactName() { - return artifactName; - } - - - - public String getArtifactVersion() { - return artifactVersion; - } - - - public SdncArtifactType getType() { - return type; - } - - - - public IArtifactInfo getArtifactInfo() { - return artifactInfo; - } - - - public File getFile() { - return file; - } - - - - - public DeployableArtifact(SdncArtifactType type, String svcName, String resourceName, IArtifactInfo artifactInfo, File file) { - this.type = type; - this.artifactInfo = artifactInfo; - this.svcName = svcName; - this.resourceName = resourceName; - this.artifactName = artifactInfo.getArtifactName(); - this.artifactVersion = artifactInfo.getArtifactVersion(); - this.file = file; - } - - - public DeployableArtifact(SdncArtifactType type, String svcName, String resourceName, String artifactName, String artifactVersion, File file) { - this.type = type; - this.artifactInfo = null; - this.svcName = svcName; - this.resourceName = resourceName; - this.artifactName = artifactName; - this.artifactVersion = artifactVersion; - this.file = file; - } - - - - public String getSvcName() { - return svcName; - } - - - - public String getResourceName() { - return resourceName; - } - - } - - private final IDistributionClient client; - private final SdncUebConfiguration config; - - private LinkedList deployList[]; - - private static void setJdbcDataSource() throws IOException { - - String propPath = null; - String propDir = System.getenv(SDNC_CONFIG_DIR); - if (propDir == null) { - - propDir = "/opt/sdnc/data/properties"; - } - propPath = propDir + "/dblib.properties"; - File propFile = new File(propPath); - - if (!propFile.exists()) { - - throw new FileNotFoundException( - "Missing configuration properties file : " - + propFile); - } - - Properties props = new Properties(); - props.load(new FileInputStream(propFile)); - - try { - jdbcDataSource = DBResourceManager.create(props); - } catch(Throwable exc) { - LOG.error("", exc); - } - - if(((DBResourceManager)jdbcDataSource).isActive()){ - LOG.warn( "DBLIB: JDBC DataSource has been initialized."); - } else { - LOG.warn( "DBLIB: JDBC DataSource did not initialize successfully."); - } - } - - private static void loadArtifactMap() { - - } - - public SdncUebCallback(IDistributionClient client, SdncUebConfiguration config) { - this.client = client; - this.config = config; - - } - - @Override - public void activateCallback(INotificationData data) { - - LOG.info("Received notification : ("+data.getDistributionID()+","+data.getServiceName()+","+data.getServiceVersion()+ - ","+data.getServiceDescription() + ")"); - - String incomingDirName = config.getIncomingDir(); - String archiveDirName = config.getArchiveDir(); - - File incomingDir = null; - File archiveDir = null; - - if (!incomingDir.exists()) { - incomingDir.mkdirs(); - } - - - if (!archiveDir.exists()) { - archiveDir.mkdirs(); - } - - // Process service level artifacts - List artifactList = data.getServiceArtifacts(); - - if (artifactList != null) { - - incomingDir = new File(incomingDirName + "/" + escapeFilename(data.getServiceName())); - if (!incomingDir.exists()) { - incomingDir.mkdirs(); - } - - archiveDir = new File(archiveDirName + "/" + escapeFilename(data.getServiceName())); - if (!archiveDir.exists()) { - archiveDir.mkdirs(); - } - for (IArtifactInfo curArtifact : artifactList) - { - - LOG.info("Received artifact " + curArtifact.getArtifactName()); - - handleArtifact(data, data.getServiceName(), null, null, curArtifact, incomingDir, archiveDir); - } - } - - - // Process resource level artifacts - for (IResourceInstance curResource : data.getResources()) { - - LOG.info("Received resource : "+curResource.getResourceName()); - artifactList = curResource.getArtifacts(); - - if (artifactList != null) { - - incomingDir = new File(incomingDirName + "/" + escapeFilename(data.getServiceName()) + "/" + escapeFilename(curResource.getResourceName())); - if (!incomingDir.exists()) { - incomingDir.mkdirs(); - } - - archiveDir = new File(archiveDirName + "/" + escapeFilename(data.getServiceName()) + "/" + escapeFilename(curResource.getResourceName())); - if (!archiveDir.exists()) { - archiveDir.mkdirs(); - } - for (IArtifactInfo curArtifact : artifactList) - { - - LOG.info("Received artifact " + curArtifact.getArtifactName()); - - handleArtifact(data, data.getServiceName(), curResource.getResourceName(), curResource.getResourceType(), curArtifact, incomingDir, archiveDir); - } - } - } - - deployDownloadedFiles(incomingDir, archiveDir, data); - - - } - - - public void deployDownloadedFiles(File incomingDir, File archiveDir, INotificationData data) { - - if (incomingDir == null) { - incomingDir = new File(config.getIncomingDir()); - - if (!incomingDir.exists()) { - incomingDir.mkdirs(); - } - - } - - if (archiveDir == null) { - archiveDir = new File(config.getArchiveDir()); - - if (!archiveDir.exists()) { - archiveDir.mkdirs(); - } - } - - String curFileName = ""; - try (DirectoryStream stream = Files.newDirectoryStream(incomingDir.toPath())) { - for (Path file: stream) { - curFileName = file.toString(); - handleSuccessfulDownload(null,null, null, null, file.toFile(), archiveDir); - } - } catch (Exception x) { - // IOException can never be thrown by the iteration. - // In this snippet, it can only be thrown by newDirectoryStream. - LOG.warn("Cannot process spool file "+ curFileName, x); - } - - // Deploy scheduled deployments - int numPasses = config.getMaxPasses(); - - deployList = new LinkedList[numPasses]; - - for (int i = 0 ; i < numPasses ; i++) { - deployList[i] = new LinkedList(); - } - for (int pass = 0 ; pass < config.getMaxPasses() ; pass++) { - - if (deployList[pass] != null) { - while (! deployList[pass].isEmpty()) { - DeployableArtifact artifact = deployList[pass].pop(); - - DistributionStatusEnum deployResult = DistributionStatusEnum.DEPLOY_ERROR; - - - try { - - deployResult = deploySpoolFile(artifact); - } catch (Exception e) { - LOG.error("Caught exception trying to deploy file", e); - } - - - IArtifactInfo artifactInfo = artifact.getArtifactInfo(); - - if ((artifactInfo != null) && (data != null)) { - IDistributionClientResult deploymentStatus; - deploymentStatus = client.sendDeploymentStatus(buildStatusMessage( - client, data, artifactInfo, - deployResult)); - } - - } - } - } - } - - private void handleArtifact(INotificationData data, String svcName, String resourceName, String resourceType, IArtifactInfo artifact, File incomingDir, File archiveDir) { - - // Download Artifact - IDistributionClientDownloadResult downloadResult = client - .download(artifact); - - if (downloadResult == null) { - - handleFailedDownload(data, artifact); - return; - } - - byte[] payloadBytes = downloadResult.getArtifactPayload(); - - if (payloadBytes == null) { - handleFailedDownload(data, artifact); - return; - } - - String payload = new String(payloadBytes); - - - File spoolFile = new File(incomingDir.getAbsolutePath() + "/" + artifact.getArtifactName()); - - boolean writeSucceeded = false; - - try { - FileWriter spoolFileWriter = new FileWriter(spoolFile); - spoolFileWriter.write(payload); - spoolFileWriter.close(); - writeSucceeded = true; - } catch (Exception e) { - LOG.error("Unable to save downloaded file to spool directory ("+ incomingDir.getAbsolutePath() +")", e); - } - - - if (writeSucceeded && (downloadResult.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS)) { - handleSuccessfulDownload(data, svcName, resourceName, artifact, spoolFile, archiveDir); - - - } else { - handleFailedDownload(data, artifact); - } - - } - - private void handleFailedDownload(INotificationData data, - IArtifactInfo relevantArtifact) { - // Send Download Status - IDistributionClientResult sendDownloadStatus = client - .sendDownloadStatus(buildStatusMessage(client, data, - relevantArtifact, DistributionStatusEnum.DOWNLOAD_ERROR)); - } - - private void handleSuccessfulDownload(INotificationData data, String svcName, String resourceName, - IArtifactInfo artifact, File spoolFile, File archiveDir) { - - if ((data != null) && (artifact != null)) { - // Send Download Status - IDistributionClientResult sendDownloadStatus = client - .sendDownloadStatus(buildStatusMessage(client, data, artifact, DistributionStatusEnum.DOWNLOAD_OK)); - } - - // If an override file exists, read that instead of the file we just downloaded - ArtifactTypeEnum artifactEnum = ArtifactTypeEnum.YANG_XML; - - boolean toscaYamlType = false; - if (artifact != null) { - String artifactTypeString = artifact.getArtifactType(); - if (artifactTypeString.contains("TOSCA_TEMPLATE")) { - toscaYamlType = true; - } - } else { - if (spoolFile.toString().contains(".yml") || spoolFile.toString().contains(".csar")) { - toscaYamlType = true; - } - } - String overrideFileName = config.getOverrideFile(); - if ((overrideFileName != null) && (overrideFileName.length() > 0)) { - File overrideFile = new File(overrideFileName); - - if (overrideFile.exists()) { - artifactEnum = ArtifactTypeEnum.YANG_XML; - spoolFile = overrideFile; - } - - } - - if (toscaYamlType == true) { - processToscaYaml (data, svcName, resourceName, artifact, spoolFile, archiveDir); - - try { - Path source = spoolFile.toPath(); - Path targetDir = archiveDir.toPath(); - - Files.move(source, targetDir.resolve(source.getFileName()), StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { - LOG.warn("Could not move "+spoolFile.getAbsolutePath()+" to "+archiveDir.getAbsolutePath(), e); - } - - return; - } - - // Process spool file - Document spoolDoc = null; - File transformedFile = null; - - // Apply XSLTs and get Doc object - try { - if (!spoolFile.isDirectory()) { - transformedFile = applyXslts(spoolFile); - } - } catch (Exception e) { - LOG.error("Caught exception trying to parse XML file", e); - } - - if (transformedFile != null) { - try { - - try { - - DocumentBuilderFactory dbf = DocumentBuilderFactory - .newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); - - spoolDoc = db.parse(transformedFile); - } catch (Exception e) { - LOG.error( - "Caught exception trying to parse transformed XML file " - + transformedFile.getAbsolutePath(), e); - } - - } catch (Exception e) { - LOG.error("Caught exception trying to deploy file", e); - } - } - - - if (spoolDoc != null) { - // Analyze file type - SdncArtifactType artifactType = analyzeFileType(artifactEnum, - spoolFile, spoolDoc); - - if (artifactType != null) { - - scheduleDeployment(artifactType, svcName, resourceName, artifact, spoolFile.getName(), transformedFile); - - } - - // SDNGC-2660 : Move file to archive directory even if it is an unrecognized type so that - // we do not keep trying and failing to process it. - try { - Path source = spoolFile.toPath(); - Path targetDir = archiveDir.toPath(); - - Files.move(source, targetDir.resolve(source.getFileName()), StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { - LOG.warn("Could not move "+spoolFile.getAbsolutePath()+" to "+archiveDir.getAbsolutePath(), e); - } - } - - - } - - - private void processToscaYaml(INotificationData data, String svcName, String resourceName, - IArtifactInfo artifact, File spoolFile, File archiveDir) { - - // Use ASDC Dist Client 1.1.5 with TOSCA parsing APIs to extract relevant TOSCA model data - - // TOSCA data extraction flow 1707: - // Use ASDC dist-client to get yaml string - not yet available - String model_yaml = null; - LOG.info("Process TOSCA YAML file: "+spoolFile.toString()); - - SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); - ISdcCsarHelper sdcCsarHelper = null; - try { - sdcCsarHelper = factory.getSdcCsarHelper(spoolFile.getAbsolutePath()); - } catch (SdcToscaParserException e) { - LOG.error("Could not create SDC TOSCA Parser ", e); - factory.close(); - return; - } - - // Ingest Service Data - 1707 - Metadata serviceMetadata = sdcCsarHelper.getServiceMetadata(); - SdncServiceModel serviceModel = new SdncServiceModel(sdcCsarHelper, serviceMetadata); - serviceModel.setFilename(spoolFile.toString().substring(spoolFile.toString().lastIndexOf("/")+1)); // will be csar file name - serviceModel.setServiceInstanceNamePrefix(SdncBaseModel.extractSubstitutionMappingTypeName(sdcCsarHelper).substring(SdncBaseModel.extractSubstitutionMappingTypeName(sdcCsarHelper).lastIndexOf(".")+1)); - - try { - cleanUpExistingToscaServiceData(serviceModel.getServiceUUID()); - LOG.info("Call insertToscaData for SERVICE_MODEL serviceUUID = " + serviceModel.getServiceUUID()); - insertToscaData(serviceModel.getSql(model_yaml)); - } catch (IOException e) { - LOG.error("Could not insert Tosca YAML data into the SERVICE_MODEL table ", e); - factory.close(); - return; - } - - // Ingest Network (VL) Data - 1707 - //List vlNodeTemplatesList = sdcCsarHelper.getServiceNodeTemplatesByType("VL"); - List vlNodeTemplatesList = sdcCsarHelper.getServiceVlList(); - - for (NodeTemplate nodeTemplate : vlNodeTemplatesList) { - SdncNodeModel nodeModel = new SdncNodeModel (sdcCsarHelper, nodeTemplate); - nodeModel.setServiceUUID(serviceModel.getServiceUUID()); - nodeModel.setEcompGeneratedNaming(SdncBaseModel.extractBooleanInputDefaultValue(sdcCsarHelper, SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_ECOMPGENERATEDNAMING));//service_naming#default#ecomp_generated_naming - - try { - cleanUpExistingToscaData("NETWORK_MODEL", "customization_uuid", nodeModel.getCustomizationUUID()); - cleanUpExistingToscaData("VPN_BINDINGS", "network_customization_uuid", nodeModel.getCustomizationUUID()); - LOG.info("Call insertToscaData for NETWORK_MODEL customizationUUID = " + nodeModel.getCustomizationUUID()); - // using ASDC dist-client use method for get yaml string - insertToscaData(nodeModel.getSql(model_yaml)); - insertToscaData(nodeModel.getVpnBindingsSql()); - } catch (IOException e) { - LOG.error("Could not insert Tosca YAML data into the NETWORK_MODEL table ", e); - } - } - - // Ingest Allotted Resource Data - 1707 - List arNodeTemplatesList = sdcCsarHelper.getAllottedResources(); - - for (NodeTemplate nodeTemplate : arNodeTemplatesList) { - SdncARModel nodeModel = new SdncARModel (sdcCsarHelper, nodeTemplate); - - try { - cleanUpExistingToscaData("ALLOTTED_RESOURCE_MODEL", "customization_uuid", nodeModel.getCustomizationUUID()); - LOG.info("Call insertToscaData for ALLOTTED_RESOURCE_MODEL customizationUUID = " + nodeModel.getCustomizationUUID()); - // using ASDC dist-client use method for get yaml string - insertToscaData(nodeModel.getSql("ALLOTTED_RESOURCE_MODEL", model_yaml)); - } catch (IOException e) { - LOG.error("Could not insert Tosca YAML data into the NETWORK_MODEL table ", e); - } - } - - // Ingest Network (VF) Data - 1707 - //List nodeTemplatesList = sdcCsarHelper.getServiceNodeTemplatesByType("VF"); - List vfNodeTemplatesList = sdcCsarHelper.getServiceVfList(); - - for (NodeTemplate nodeTemplate : vfNodeTemplatesList) { - SdncVFModel vfNodeModel = new SdncVFModel (sdcCsarHelper, nodeTemplate); - - try { - cleanUpExistingToscaData("VF_MODEL", "customization_uuid", vfNodeModel.getCustomizationUUID()) ; - LOG.info("Call insertToscaData for VF_MODEL customizationUUID = " + vfNodeModel.getCustomizationUUID()); - insertToscaData(vfNodeModel.getSql("VF_MODEL", model_yaml)); - } catch (IOException e) { - LOG.error("Could not insert Tosca YAML data into the VF_MODEL table ", e); - } - - // For each VF, insert VF_MODULE_MODEL data - List vfModules = sdcCsarHelper.getVfModulesByVf(vfNodeModel.getCustomizationUUIDNoQuotes()); - for (Group group : vfModules){ - SdncVFModuleModel vfModuleModel = new SdncVFModuleModel(sdcCsarHelper, group); - - try { - cleanUpExistingToscaData("VF_MODULE_MODEL", "customization_uuid", vfModuleModel.getCustomizationUUID()); - LOG.info("Call insertToscaData for VF_MODULE_MODEL customizationUUID = " + vfModuleModel.getCustomizationUUID()); - insertToscaData(vfModuleModel.getSql("VF_MODULE_MODEL", model_yaml)); - } catch (IOException e) { - LOG.error("Could not insert Tosca YAML data into the VF_MODULE_MODEL table ", e); - } - - // For each VF Module, get the VFC list, insert VF_MODULE_TO_VFC_MAPPING data - // List groupMembers = sdcCsarHelper.getMembersOfGroup(group); - old version - // For each vfcNode (group member) in the groupMembers list, extract vm_type and vm_count. - // Insert vf_module.customizationUUID, vfcNode.customizationUUID and vm_type and vm_count into VF_MODULE_TO_VFC_MAPPING - List groupMembers = sdcCsarHelper.getMembersOfVfModule(nodeTemplate, group); // not yet available - for (NodeTemplate vfcNode : groupMembers){ - SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, vfcNode); - - try { - cleanUpExistingToscaData("VF_MODULE_TO_VFC_MAPPING", "vf_module_customization_uuid", vfModuleModel.getCustomizationUUID()); - LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING customizationUUID = " + vfModuleModel.getCustomizationUUID()); - insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" + - vfModuleModel.getCustomizationUUID() + ", " + vfcModel.getCustomizationUUID() + ", \"" + vfcModel.getVmType() + "\", \"" + vfcModel.getVmCount() + "\")"); - } catch (IOException e) { - LOG.error("Could not insert Tosca YAML data into the VF_MODULE_TO_VFC_MAPPING table ", e); - } - - } - - } - - // For each VF, insert VFC_MODEL data - List vfcNodes = sdcCsarHelper.getVfcListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()); - for (NodeTemplate vfcNode : vfcNodes){ - SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, vfcNode); - - try { - cleanUpExistingToscaData("VFC_MODEL", "customization_uuid", vfcModel.getCustomizationUUID()); - LOG.info("Call insertToscaData for VFC_MODEL customizationUUID = " + vfcModel.getCustomizationUUID()); - insertToscaData(vfcModel.getSql("VFC_MODEL", model_yaml)); - } catch (IOException e) { - LOG.error("Could not insert Tosca YAML data into the VFC_MODEL table ", e); - } - - } - - // For each VF, insert VF_TO_NETWORK_ROLE_MAPPING data - List cpNodes = sdcCsarHelper.getCpListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()); - for (NodeTemplate cpNode : cpNodes){ - - // Insert into VF_TO_NETWORK_ROLE_MAPPING vf_customization_uuid and network_role - String cpNetworkRole = sdcCsarHelper.getNodeTemplatePropertyLeafValue(cpNode, "network_role_tag"); - - try { - cleanUpExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", "vf_customization_uuid", vfNodeModel.getCustomizationUUID()); - LOG.info("Call insertToscaData for VF_TO_NETWORK_ROLE_MAPPING vfCustomizationUUID = " + vfNodeModel.getCustomizationUUID()); - insertToscaData("insert into VF_TO_NETWORK_ROLE_MAPPING (vf_customization_uuid, network_role) values (" + - vfNodeModel.getCustomizationUUID() + ", \"" + cpNetworkRole + "\")"); - } catch (IOException e) { - LOG.error("Could not insert Tosca YAML data into the VF_TO_NETWORK_ROLE_MAPPING table ", e); - } - - // Insert VFC_TO_NETWORK_ROLE_MAPPING data - Map mappingParams = new HashMap(); - //String cpNetworkRoleTag = "\"" + sdcCsarHelper.getNodeTemplatePropertyLeafValue(cpNode, SdcPropertyNames.PROPERTY_NAME_NETWORKROLETAG) + "\""; - // extract network_role, network_role_tag and virtual_binding from this cpNode - SdncBaseModel.addParameter("network_role", SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "network_role"), mappingParams); - SdncBaseModel.addParameter("network_role_tag", SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "network_role_tag"), mappingParams); - String virtualBinding = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "requirements#virtualBinding") + "\""; - - // get list of cpNodes and vfcNodes with matching virtualBinding - List> matchList = sdcCsarHelper.getNodeTemplatePairsByReqName(sdcCsarHelper.getCpListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()), sdcCsarHelper.getVfcListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()), virtualBinding); - for (Pair match : matchList) { // should be 1 match? - - // extract values from the left "CP" Node - SdncBaseModel.addParameter("ipv4_use_dhcp", SdncBaseModel.extractBooleanValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_DHCPENABLED), mappingParams); - //SdncBaseModel.addParameter("ipv4_ip_version", SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_IPVERSION), mappingParams); - SdncBaseModel.addParameter("ipv4_ip_version", "dummy_ipv4_vers", mappingParams); - SdncBaseModel.addParameter("ipv6_use_dhcp", SdncBaseModel.extractBooleanValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_DHCPENABLED), mappingParams); - //SdncBaseModel.addParameter("ipv6_ip_version", SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_IPVERSION), mappingParams); - SdncBaseModel.addParameter("ipv6_ip_version", "dummy_ipv6_vers", mappingParams); - //String extcp_subnetpool_id = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_SUBNETPOOLID) + "\""; // need path to subnetpoolid - - // extract values from the right "VFC" Node - String vfcCustomizationUuid = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, match.getRight().getMetadata(), "customization_uuid") + "\""; - SdncBaseModel.addParameter("vm_type", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_VMTYPE), mappingParams); - SdncBaseModel.addIntParameter("ipv4_count", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT), mappingParams); - SdncBaseModel.addIntParameter("ipv6_count", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT), mappingParams); - - try { - cleanUpExistingToscaData("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", vfcCustomizationUuid); - LOG.info("Call insertToscaData for VFC_TO_NETWORK_ROLE_MAPPING vfcCustomizationUUID = " + vfcCustomizationUuid); - insertToscaData(SdncBaseModel.getSql("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", vfcCustomizationUuid, "", mappingParams)); - } catch (IOException e) { - LOG.error("Could not insert Tosca YAML data into the VFC_TO_NETWORK_ROLE_MAPPING table ", e); - } - - } - - } // CP loop - - } // VF loop - - // Close ASDC TOSCA Parser factory - we are done processing this distribution - factory.close(); - - if ((artifact != null) && (data != null)) { - LOG.info("Update to SDN-C succeeded"); - IDistributionClientResult deploymentStatus; - deploymentStatus = client.sendDeploymentStatus(buildStatusMessage( - client, data, artifact, - DistributionStatusEnum.DEPLOY_OK)); - } - - } - - private void cleanUpExistingToscaData(String tableName, String keyName, String keyValue) throws IOException - { - - if (jdbcDataSource == null) { - setJdbcDataSource(); - } - try { - int rowCount = 0; - CachedRowSet data = jdbcDataSource.getData("SELECT * from " + tableName + " where " + keyName + " = " + keyValue + ";", null, ""); - while(data.next()) { - rowCount ++; - } - if (rowCount != 0) { - LOG.info("cleanUpExistingToscaData: " + keyValue); - jdbcDataSource.writeData("DELETE from " + tableName + " where " + keyName + " = " + keyValue + ";", null, null); - } - - } catch (SQLException e) { - LOG.error("Could not clean up existing " + tableName + " for " + keyValue, e); - } - - } - - - private void cleanUpExistingToscaServiceData(String serviceUUID) throws IOException - { - - if (jdbcDataSource == null) { - setJdbcDataSource(); - } - try { - int rowCount = 0; - CachedRowSet data = jdbcDataSource.getData("SELECT * from SERVICE_MODEL where service_uuid = " + serviceUUID + ";", null, ""); - while(data.next()) { - rowCount ++; - } - if (rowCount != 0) { - LOG.info("cleanUpExistingToscaData: " + serviceUUID); - jdbcDataSource.writeData("DELETE from NETWORK_MODEL where service_uuid = " + serviceUUID + ";", null, null); - jdbcDataSource.writeData("DELETE from SERVICE_MODEL where service_uuid = " + serviceUUID + ";", null, null); - } - - } catch (SQLException e) { - LOG.error("Could not clean up existing NETWORK_MODEL and SERVICE_MODEL for service_UUID " + serviceUUID, e); - } - - } - - - private void insertToscaData(String toscaDataString) throws IOException - { - LOG.debug("insertToscaData: " + toscaDataString); - - if (jdbcDataSource == null) { - setJdbcDataSource(); - } - try { - - jdbcDataSource.writeData(toscaDataString, null, null); - - } catch (SQLException e) { - LOG.error("Could not insert Tosca YAML data into the database ", e); - } - - } - - - private SdncArtifactType analyzeFileType(ArtifactTypeEnum artifactType, File spoolFile, Document spoolDoc) { - - if (artifactType != ArtifactTypeEnum.YANG_XML) { - LOG.error("Unexpected artifact type - expecting YANG_XML, got "+artifactType); - return (null); - } - - // Examine outer tag - - try { - - - Element root = spoolDoc.getDocumentElement(); - - String rootName = root.getTagName(); - - if (rootName.contains(":")) { - String[] rootNameElems = rootName.split(":"); - rootName = rootNameElems[rootNameElems.length - 1]; - } - - if (rootName != null) { - SdncArtifactType mapEntry = config.getMapping(rootName); - - - if (mapEntry == null) { - - LOG.error("Unexpected file contents - root tag is "+rootName); - } - return(mapEntry); - } else { - LOG.error("Cannot get root tag from file"); - return(null); - } - - } catch (Exception e) { - LOG.error("Could not parse YANG_XML file "+spoolFile.getName(), e); - return(null); - } - } - - private void scheduleDeployment(SdncArtifactType type, String svcName, String resourceName, IArtifactInfo artifactInfo, String spoolFileName, File spoolFile) { - - if (type.getPass() < deployList.length) { - - if (artifactInfo != null) { - LOG.debug("Scheduling "+artifactInfo.getArtifactName()+" version "+artifactInfo.getArtifactVersion()+" for deployment"); - - deployList[type.getPass()].add(new DeployableArtifact(type, svcName, resourceName, artifactInfo, spoolFile)); - } else { - SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss.SSS");//dd/MM/yyyy - Date now = new Date(); - String artifactVersion = sdfDate.format(now); - LOG.debug("Scheduling "+spoolFileName+" version "+artifactVersion+" for deployment"); - String artifactName = spoolFileName; - if (artifactInfo != null) { - artifactName = artifactInfo.getArtifactName(); - } - deployList[type.getPass()].add(new DeployableArtifact(type, svcName, resourceName, artifactName, artifactVersion, spoolFile)); - } - } else { - LOG.info("Pass for type "+type.getTag()+" is "+type.getPass()+" which is not <= "+deployList.length); - } - } - - - private DistributionStatusEnum deploySpoolFile(DeployableArtifact artifact) { - - DistributionStatusEnum deployResult = DistributionStatusEnum.DEPLOY_OK; - - StringBuffer msgBuffer = new StringBuffer(); - - - String namespace = config.getAsdcApiNamespace(); - if ((namespace == null) || (namespace.length() == 0)) { - namespace="com:att:sdnctl:asdcapi"; - } - - msgBuffer.append("\n"); - - String svcName = artifact.getSvcName(); - String resourceName = artifact.getResourceName(); - String artifactName = artifact.getArtifactName(); - - if (svcName != null) { - if (resourceName != null) { - artifactName = svcName + "/" + resourceName + "/" + artifactName; - } else { - artifactName = svcName + "/" + artifactName; - } - } - - msgBuffer.append(""+artifactName+"\n"); - msgBuffer.append(""+artifact.getArtifactVersion()+"\n"); - - - try { - BufferedReader rdr = new BufferedReader(new FileReader(artifact.getFile())); - - String curLine = rdr.readLine(); - - while (curLine != null) { - - if (!curLine.startsWith("\n"); - - - byte[] msgBytes = msgBuffer.toString().getBytes(); - - Document results = postRestXml(artifact.getType().getRpcUrl(config.getAsdcApiBaseUrl()), msgBytes); - - if (results == null) { - - deployResult = DistributionStatusEnum.DEPLOY_ERROR; - } else { - - XPathFactory xpf = XPathFactory.newInstance(); - XPath xp = xpf.newXPath(); - - String asdcApiResponseCode = "500"; - - try { - - asdcApiResponseCode = xp.evaluate("//asdc-api-response-code[position()=1]/text()", results.getDocumentElement()); - } catch (Exception e) { - LOG.error("Caught exception retrying to evaluate xpath", e); - } - - if (asdcApiResponseCode.contains("200")) { - LOG.info("Update to SDN-C succeeded"); - deployResult = DistributionStatusEnum.DEPLOY_OK; - } else { - LOG.info("Update to SDN-C failed (response code "+asdcApiResponseCode+")"); - - if (asdcApiResponseCode.contains("409")) { - deployResult = DistributionStatusEnum.ALREADY_DEPLOYED; - } else { - - deployResult = DistributionStatusEnum.DEPLOY_ERROR; - } - } - } - - - - return(deployResult); - } - - - - - - public static IDistributionStatusMessage buildStatusMessage( - final IDistributionClient client, final INotificationData data, - final IArtifactInfo relevantArtifact, - final DistributionStatusEnum status) { - IDistributionStatusMessage statusMessage = new IDistributionStatusMessage() { - - @Override - public long getTimestamp() { - long currentTimeMillis = System.currentTimeMillis(); - return currentTimeMillis; - } - - @Override - public DistributionStatusEnum getStatus() { - return status; - } - - @Override - public String getDistributionID() { - return data.getDistributionID(); - } - - @Override - public String getConsumerID() { - return client.getConfiguration().getConsumerID(); - } - - @Override - public String getArtifactURL() { - return relevantArtifact.getArtifactURL(); - } - }; - return statusMessage; - - } - - private HttpURLConnection getRestXmlConnection(String urlString, String method) throws IOException - { - URL sdncUrl = new URL(urlString); - Authenticator.setDefault(new SdncAuthenticator(config.getSdncUser(), config.getSdncPasswd())); - - HttpURLConnection conn = (HttpURLConnection) sdncUrl.openConnection(); - - String authStr = config.getSdncUser()+":"+config.getSdncPasswd(); - String encodedAuthStr = new String(Base64.encodeBase64(authStr.getBytes())); - - conn.addRequestProperty("Authentication", "Basic "+encodedAuthStr); - - conn.setRequestMethod(method); - conn.setRequestProperty("Content-Type", "application/xml"); - conn.setRequestProperty("Accept", "application/xml"); - - conn.setDoInput(true); - conn.setDoOutput(true); - conn.setUseCaches(false); - - return(conn); - - } - - private Document postRestXml(String urlString, byte[] msgBytes) { - Document response = null; - - try { - SdncOdlConnection odlConn = SdncOdlConnection.newInstance(urlString, config.getSdncUser(), config.getSdncPasswd()); - - String sdncResp = odlConn.send("POST", "application/xml", new String(msgBytes)); - - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); - - - response = db.parse(new ByteArrayInputStream(sdncResp.getBytes())); - } catch (Exception e) { - LOG.error("Caught exception posting to ODL tier", e); - } - - return(response); - - } - - private File applyXslts(File srcFile) { - - Document doc = null; - - - File inFile = srcFile; - File outFile = null; - - String xsltPathList = config.getXsltPathList(); - - if ((xsltPathList == null) || (xsltPathList.length() == 0)) { - outFile = inFile; - } else { - - String[] xsltPaths = xsltPathList.split(","); - - for (String xsltPath : xsltPaths) { - try{ - - outFile = File.createTempFile("tmp", "xml"); - TransformerFactory factory = TransformerFactory.newInstance(); - Source xslt = new StreamSource(new File(xsltPath)); - Transformer transformer = factory.newTransformer(xslt); - Source text = new StreamSource(inFile); - - - transformer.transform(text, new StreamResult(outFile)); - - inFile = outFile; - - } catch (Exception e) { - LOG.error("Caught exception trying to apply XSLT template "+xsltPath, e); - - } - - } - } - - // After transformations, parse transformed XML - - - return(outFile); - } - - private String escapeFilename(String str) { - StringBuffer retval = new StringBuffer(); - - for (int i = 0 ; i < str.length() ; i++) { - char curchar = str.charAt(i); - if (Character.isJavaIdentifierPart(curchar)) { - retval.append(curchar); - } - } - - return(retval.toString()); - - } - -} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebClient.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebClient.java deleted file mode 100644 index df5dfc0a9..000000000 --- a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebClient.java +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP 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.openecomp.sdnc.uebclient; - -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.results.IDistributionClientResult; -import org.openecomp.sdc.impl.DistributionClientFactory; -import org.openecomp.sdc.utils.DistributionActionResultEnum; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SdncUebClient { - - private static final Logger LOG = LoggerFactory - .getLogger(SdncUebConfiguration.class); - - public static void main(String[] args) { - IDistributionClient client = DistributionClientFactory - .createDistributionClient(); - - SdncUebConfiguration config = new SdncUebConfiguration(); - - SdncUebCallback cb = new SdncUebCallback(client, config); - - LOG.info("Scanning for local distribution artifacts before starting client"); - cb.deployDownloadedFiles(null, null, null); - - LOG.info("Initializing ASDC distribution client"); - - IDistributionClientResult result = client.init( - config, cb); - - LOG.info("Initialized ASDC distribution client - results = " - + result.getDistributionMessageResult()); - - if (result.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) { - LOG.info("Starting client..."); - IDistributionClientResult start = client.start(); - LOG.info("Client startup result = " - + start.getDistributionMessageResult()); - } - - - } - -} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebConfiguration.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebConfiguration.java deleted file mode 100644 index 7855b5ba4..000000000 --- a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncUebConfiguration.java +++ /dev/null @@ -1,280 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP 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.openecomp.sdnc.uebclient; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.LinkedList; -import java.util.List; -import java.util.Properties; - -import org.openecomp.sdc.api.consumer.IConfiguration; -import org.openecomp.sdc.utils.ArtifactTypeEnum; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SdncUebConfiguration implements IConfiguration{ - - private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; - private static final Logger LOG = LoggerFactory - .getLogger(SdncUebConfiguration.class); - - private String asdcAddress = null; - private String consumerGroup = null; - private String consumerID = null; - private String environmentName = null; - private String password = null; - private int pollingInterval = 30; - private int pollingTimeout = 15; - private List relevantArtifactTypes = null; - private String user = null; - - private String sdncUser = null; - private String sdncPasswd = null; - private String asdcApiBaseUrl = null; - private String asdcApiNamespace = null; - - private SdncArtifactMap artifactMap = SdncArtifactMap.getInstance(); - - public String getAsdcApiNamespace() { - return asdcApiNamespace; - } - - private String incomingDir = null; - - private String archiveDir = null; - - private String overrideFile = null; - - private boolean activateServerTLSAuth; - private String keyStorePassword; - private String keyStorePath; - - private String xsltPathList; - - public String getXsltPathList() { - return xsltPathList; - } - - public String getOverrideFile() { - return overrideFile; - } - - public SdncUebConfiguration() { - - try { - init(); - } catch (Exception e) { - LOG.error("Cannot initialize SdncUebConfiguration", e); - } - } - - public void init() throws IOException { - String propPath = null; - String propDir = System.getenv(SDNC_CONFIG_DIR); - if (propDir == null) { - - propDir = "/opt/sdnc/data/properties"; - } - propPath = propDir + "/ueb-listener.properties"; - File propFile = new File(propPath); - - - if (!propFile.exists()) { - - throw new FileNotFoundException( - "Missing configuration properties file : " - + propFile); - } - - Properties props = new Properties(); - props.load(new FileInputStream(propFile)); - - asdcAddress = props.getProperty("org.openecomp.sdnc.uebclient.asdc-address"); - consumerGroup = props.getProperty("org.openecomp.sdnc.uebclient.consumer-group"); - consumerID = props.getProperty("org.openecomp.sdnc.uebclient.consumer-id"); - environmentName = props.getProperty("org.openecomp.sdnc.uebclient.environment-name"); - password = props.getProperty("org.openecomp.sdnc.uebclient.password"); - user = props.getProperty("org.openecomp.sdnc.uebclient.user"); - - sdncUser = props.getProperty("org.openecomp.sdnc.uebclient.sdnc-user"); - sdncPasswd = props.getProperty("org.openecomp.sdnc.uebclient.sdnc-passwd"); - asdcApiBaseUrl = props.getProperty("org.openecomp.sdnc.uebclient.asdc-api-base-url"); - asdcApiNamespace = props.getProperty("org.openecomp.sdnc.uebclient.asdc-api-namespace"); - - incomingDir = props.getProperty("org.openecomp.sdnc.uebclient.spool.incoming"); - archiveDir = props.getProperty("org.openecomp.sdnc.uebclient.spool.archive"); - overrideFile = props.getProperty("org.openecomp.sdnc.uebclient.override-file"); - - String curval = props.getProperty("org.openecomp.sdnc.uebclient.polling-interval"); - if ((curval != null) && (curval.length() > 0)) { - try { - pollingInterval = Integer.parseInt(curval); - } catch (Exception e) { - LOG.warn("Illegal value for org.openecomp.sdnc.uebclient.polling-interval ("+curval+")"); - } - } - - curval = props.getProperty("org.openecomp.sdnc.uebclient.polling-timeout"); - if ((curval != null) && (curval.length() > 0)) { - try { - pollingTimeout = Integer.parseInt(curval); - } catch (Exception e) { - LOG.warn("Illegal value for org.openecomp.sdnc.uebclient.polling-timeout ("+curval+")"); - } - } - - curval = props.getProperty("org.openecomp.sdnc.uebclient.relevant-artifact-types"); - if ((curval != null) && (curval.length() > 0)) { - String[] artifactTypes = curval.split(","); - - relevantArtifactTypes = new LinkedList(); - - for (int i = 0 ; i < artifactTypes.length ; i++) { - try { - if (ArtifactTypeEnum.valueOf(artifactTypes[i]) != null) { - relevantArtifactTypes.add(artifactTypes[i]); - } else { - LOG.warn("Skipping unrecognized artifact type "+artifactTypes[i]); - } - } catch (Exception e) { - - LOG.warn("Caught exception validating artifact type "+artifactTypes[i], e); - } - - } - - } - - curval = props.getProperty("org.openecomp.sdnc.uebclient.activate-server-tls-auth", "false"); - activateServerTLSAuth = "true".equalsIgnoreCase(curval); - keyStorePath = props.getProperty("org.openecomp.sdnc.uebclient.keystore-path"); - keyStorePassword = props.getProperty("org.openecomp.sdnc.uebclient.keystore-password"); - xsltPathList = props.getProperty("org.openecomp.sdnc.uebclient.xslt-path-list"); - - - String artifactMapFile = props.getProperty("org.openecomp.sdnc.uebclient.artifact-map"); - if (artifactMapFile != null) { - artifactMap.load(artifactMapFile); - } - - } - - @Override - public String getAsdcAddress() { - return asdcAddress; - } - - @Override - public String getConsumerGroup() { - return consumerGroup; - } - - @Override - public String getConsumerID() { - return consumerID; - } - - @Override - public String getEnvironmentName() { - return environmentName; - } - - @Override - public String getPassword() { - return password; - } - - @Override - public int getPollingInterval() { - return pollingInterval; - } - - @Override - public int getPollingTimeout() { - return pollingTimeout; - } - - @Override - public List getRelevantArtifactTypes() { - return relevantArtifactTypes; - } - - @Override - public String getUser() { - return user; - } - - - public String getSdncUser() { - return sdncUser; - } - - public String getSdncPasswd() { - return sdncPasswd; - } - - public String getAsdcApiBaseUrl() { - return asdcApiBaseUrl; - } - - @Override - public boolean activateServerTLSAuth() { - return activateServerTLSAuth; - } - - @Override - public String getKeyStorePassword() { - return keyStorePassword; - } - - @Override - public String getKeyStorePath() { - return keyStorePath; - } - - public String getIncomingDir() { - return incomingDir; - } - - public String getArchiveDir() { - return archiveDir; - } - - public int getMaxPasses() { - return(artifactMap.getNumPasses()); - } - - public SdncArtifactMap.SdncArtifactType getMapping(String tag) { - return(artifactMap.getMapping(tag)); - } - - @Override - public boolean isFilterInEmptyResources() { - // TODO Auto-generated method stub - return false; - } - - -} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFCModel.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFCModel.java deleted file mode 100644 index 67b786896..000000000 --- a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFCModel.java +++ /dev/null @@ -1,69 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP 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.openecomp.sdnc.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 SdncVFCModel extends SdncBaseModel { - - private static final Logger LOG = LoggerFactory - .getLogger(SdncVFCModel.class); - - private String vmType = null; - private String vmCount = null; - - public SdncVFCModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { - - super(sdcCsarHelper, nodeTemplate); - - // extract properties - vmType = extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VMTYPE); - //vmCount = extractValue (sdcCsarHelper, nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VMCOUNT); - need path to vm_count - vmCount = "1"; - addParameter("vm_type", vmType); - addParameter("vm_type_tag", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG)); - addParameter("ecomp_generated_naming", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VFCNAMING_ECOMPGENERATEDNAMING)); - addParameter("naming_policy", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VFCNAMING_NAMINGPOLICY)); - addParameter("nfc_naming_code", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFCCODE)); - } - - public String getVmType() { - return vmType; - } - - public void setVmType(String vmType) { - this.vmType = vmType; - } - - public String getVmCount() { - return vmCount; - } - - public void setVmCount(String vmCount) { - this.vmCount = vmCount; - } - -} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFModel.java deleted file mode 100644 index 4e95e46ba..000000000 --- a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFModel.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP 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.openecomp.sdnc.uebclient; - -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames; -import org.openecomp.sdc.toscaparser.api.Metadata; -import org.openecomp.sdc.toscaparser.api.NodeTemplate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SdncVFModel extends SdncBaseModel { - - private static final Logger LOG = LoggerFactory - .getLogger(SdncVFModel.class); - - public SdncVFModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { - - super(sdcCsarHelper, nodeTemplate); - - // extract metadata - Metadata metadata = nodeTemplate.getMetadata(); - addParameter("name", extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_NAME)); - addParameter("vendor", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDOR)); - addParameter("vendor_version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDORRELEASE)); - - // extract properties - addParameter("ecomp_generated_naming", extractBooleanValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VNFECOMPNAMING_ECOMPGENERATEDNAMING)); - addParameter("naming_policy", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VNFECOMPNAMING_NAMINGPOLICY)); - addParameter("nf_type", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)); - addParameter("nf_role", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)); - addParameter("nf_code", extractValue( nodeTemplate, "nf_naming_code")); - addParameter("nf_function", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)); - addParameter("avail_zone_max_count", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONEMAXCOUNT)); - } - -} diff --git a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFModuleModel.java b/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFModuleModel.java deleted file mode 100644 index 86df8b2ab..000000000 --- a/ueb-listener/src/main/java/org/openecomp/sdnc/uebclient/SdncVFModuleModel.java +++ /dev/null @@ -1,45 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 ONAP 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.openecomp.sdnc.uebclient; - -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames; -import org.openecomp.sdc.toscaparser.api.Group; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SdncVFModuleModel extends SdncBaseModel { - - private static final Logger LOG = LoggerFactory - .getLogger(SdncVFModuleModel.class); - - public SdncVFModuleModel(ISdcCsarHelper sdcCsarHelper, Group group) { - - super(sdcCsarHelper, group); - - // extract properties - addParameter("vf_module_type", extractValue(group, SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE)); - addIntParameter("availability_zone_count", extractValue(group, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)); - addParameter("ecomp_generated_vm_assignments", extractBooleanValue(group, SdcPropertyNames.PROPERTY_NAME_ECOMPGENERATEDVMASSIGNMENTS)); - } - -} -- cgit 1.2.3-korg From 1027b0c07b488bb5f4542bd38501f9a99da5c2cf Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Tue, 15 Aug 2017 15:18:54 -0400 Subject: Port sli/northbound to Carbon Updated sli/northbound repo to compile against OpenDaylight Carbon SR1 release Change-Id: I6aec68cf436e11f5fd5b7094eb5616536bead44f Issue-ID: CCSDK-25 Signed-off-by: Dan Timoney --- asdcApi/features/pom.xml | 2 +- asdcApi/features/src/main/resources/features.xml | 4 ++-- asdcApi/installer/pom.xml | 5 ++--- asdcApi/installer/src/assembly/assemble_installer_zip.xml | 4 ++-- asdcApi/installer/src/assembly/assemble_mvnrepo_zip.xml | 4 ++-- asdcApi/installer/src/main/resources/scripts/install-feature.sh | 4 ++-- asdcApi/model/pom.xml | 6 +++--- asdcApi/pom.xml | 4 ++-- asdcApi/provider/pom.xml | 4 ++-- .../org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java | 4 ++-- .../org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiSliClient.java | 4 ++-- .../java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiUtil.java | 4 ++-- .../asdcapi/provider/impl/rev140523/AsdcApiProviderModule.java | 4 ++-- .../provider/impl/rev140523/AsdcApiProviderModuleFactory.java | 4 ++-- asdcApi/provider/src/main/resources/initial/asdcApi-provider.xml | 4 ++-- dataChange/features/pom.xml | 4 ++-- dataChange/features/src/main/resources/features.xml | 4 ++-- dataChange/installer/pom.xml | 5 ++--- dataChange/installer/src/assembly/assemble_installer_zip.xml | 4 ++-- dataChange/installer/src/assembly/assemble_mvnrepo_zip.xml | 4 ++-- dataChange/installer/src/main/resources/scripts/install-feature.sh | 4 ++-- dataChange/model/pom.xml | 6 +++--- dataChange/pom.xml | 4 ++-- dataChange/provider/pom.xml | 7 +++---- .../main/java/org/onap/ccsdk/sli/northbound/DataChangeClient.java | 4 ++-- .../java/org/onap/ccsdk/sli/northbound/DataChangeProvider.java | 4 ++-- .../provider/impl/rev140523/DataChangeProviderModule.java | 4 ++-- .../provider/impl/rev140523/DataChangeProviderModuleFactory.java | 4 ++-- .../provider/src/main/resources/initial/dataChange-provider.xml | 4 ++-- dmaap-listener/pom.xml | 5 +++-- dmaap-listener/src/assembly/assemble_zip.xml | 4 ++-- .../org/onap/ccsdk/sli/northbound/dmaapclient/DmaapListener.java | 4 ++-- .../onap/ccsdk/sli/northbound/dmaapclient/DummyDmaapConsumer.java | 4 ++-- .../ccsdk/sli/northbound/dmaapclient/InvalidMessageException.java | 4 ++-- .../onap/ccsdk/sli/northbound/dmaapclient/SdncDmaapConsumer.java | 4 ++-- .../sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java | 4 ++-- .../onap/ccsdk/sli/northbound/dmaapclient/SdncOdlConnection.java | 4 ++-- dmaap-listener/src/main/resources/log4j.properties | 4 ++-- dmaap-listener/src/main/scripts/start-dmaap-listener.sh | 4 ++-- dmaap-listener/src/main/scripts/stop-dmaap-listener.sh | 4 ++-- dmaap-listener/src/site/apt/index.apt | 4 ++-- dmaap-listener/src/site/site.xml | 4 ++-- pom.xml | 7 +++---- ueb-listener/pom.xml | 5 +++-- ueb-listener/src/assembly/assemble_zip.xml | 4 ++-- .../java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java | 4 ++-- .../org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java | 4 ++-- .../org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java | 4 ++-- .../org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java | 4 ++-- .../org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java | 4 ++-- .../org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java | 4 ++-- .../org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java | 4 ++-- .../org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java | 4 ++-- .../onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java | 4 ++-- .../java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java | 4 ++-- .../java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java | 4 ++-- .../org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java | 4 ++-- ueb-listener/src/main/resources/log4j.properties | 4 ++-- ueb-listener/src/main/scripts/start-ueb-listener.sh | 4 ++-- ueb-listener/src/main/scripts/stop-ueb-listener.sh | 4 ++-- ueb-listener/src/site/apt/index.apt | 4 ++-- ueb-listener/src/site/site.xml | 4 ++-- 62 files changed, 129 insertions(+), 131 deletions(-) (limited to 'ueb-listener/src') diff --git a/asdcApi/features/pom.xml b/asdcApi/features/pom.xml index 774d9e529..e6af34c57 100755 --- a/asdcApi/features/pom.xml +++ b/asdcApi/features/pom.xml @@ -4,7 +4,7 @@ asdcApi org.onap.ccsdk.sli.northbound - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT asdcApi-features diff --git a/asdcApi/features/src/main/resources/features.xml b/asdcApi/features/src/main/resources/features.xml index f9aa81a66..9006f1b94 100644 --- a/asdcApi/features/src/main/resources/features.xml +++ b/asdcApi/features/src/main/resources/features.xml @@ -3,8 +3,8 @@ ============LICENSE_START======================================================= openECOMP : SDN-C ================================================================================ - Copyright (C) 2017 ONAP Intellectual Property. All rights - reserved. + 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. diff --git a/asdcApi/installer/pom.xml b/asdcApi/installer/pom.xml index b4f32934a..32f505053 100755 --- a/asdcApi/installer/pom.xml +++ b/asdcApi/installer/pom.xml @@ -1,11 +1,10 @@ - + 4.0.0 asdcApi org.onap.ccsdk.sli.northbound - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT asdcApi-installer asdcApi - Karaf Installer diff --git a/asdcApi/installer/src/assembly/assemble_installer_zip.xml b/asdcApi/installer/src/assembly/assemble_installer_zip.xml index e278872a1..3bed4b5ef 100644 --- a/asdcApi/installer/src/assembly/assemble_installer_zip.xml +++ b/asdcApi/installer/src/assembly/assemble_installer_zip.xml @@ -2,8 +2,8 @@ ============LICENSE_START======================================================= openECOMP : SDN-C ================================================================================ - Copyright (C) 2017 ONAP Intellectual Property. All rights - reserved. + 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. diff --git a/asdcApi/installer/src/assembly/assemble_mvnrepo_zip.xml b/asdcApi/installer/src/assembly/assemble_mvnrepo_zip.xml index 608200da1..5c24d73ff 100644 --- a/asdcApi/installer/src/assembly/assemble_mvnrepo_zip.xml +++ b/asdcApi/installer/src/assembly/assemble_mvnrepo_zip.xml @@ -2,8 +2,8 @@ ============LICENSE_START======================================================= openECOMP : SDN-C ================================================================================ - Copyright (C) 2017 ONAP Intellectual Property. All rights - reserved. + 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. diff --git a/asdcApi/installer/src/main/resources/scripts/install-feature.sh b/asdcApi/installer/src/main/resources/scripts/install-feature.sh index 9a47d2225..e986764b9 100644 --- a/asdcApi/installer/src/main/resources/scripts/install-feature.sh +++ b/asdcApi/installer/src/main/resources/scripts/install-feature.sh @@ -4,8 +4,8 @@ # ============LICENSE_START======================================================= # openECOMP : SDN-C # ================================================================================ -# Copyright (C) 2017 ONAP Intellectual Property. All rights -# reserved. +# 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. diff --git a/asdcApi/model/pom.xml b/asdcApi/model/pom.xml index b9f48326d..327b8627e 100755 --- a/asdcApi/model/pom.xml +++ b/asdcApi/model/pom.xml @@ -4,11 +4,11 @@ asdcApi org.onap.ccsdk.sli.northbound - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT org.onap.ccsdk.sli.northbound asdcApi-model - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT bundle @@ -45,7 +45,7 @@ ${yang.file.directory} - org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl + org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl ${salGeneratorPath} diff --git a/asdcApi/pom.xml b/asdcApi/pom.xml index b4d538abd..9f8d906c3 100755 --- a/asdcApi/pom.xml +++ b/asdcApi/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.sli.northbound sdnc-northbound - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT pom org.onap.ccsdk.sli.northbound asdcApi - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT asdcApi diff --git a/asdcApi/provider/pom.xml b/asdcApi/provider/pom.xml index e8769fd7d..7b7ed4bee 100755 --- a/asdcApi/provider/pom.xml +++ b/asdcApi/provider/pom.xml @@ -4,7 +4,7 @@ asdcApi org.onap.ccsdk.sli.northbound - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT asdcApi-provider bundle @@ -42,7 +42,7 @@ - org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl + org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl ${salGeneratorPath} diff --git a/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java index c6e1921b7..bd5f74a4f 100644 --- a/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java +++ b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiSliClient.java b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiSliClient.java index 0fa90ea7e..5b268bc28 100644 --- a/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiSliClient.java +++ b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiSliClient.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiUtil.java b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiUtil.java index 6498f13b5..602b389cb 100644 --- a/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiUtil.java +++ b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiUtil.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModule.java b/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModule.java index 0a2272d35..ddf8093fb 100644 --- a/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModule.java +++ b/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModule.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModuleFactory.java b/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModuleFactory.java index c2d15b890..513e61cff 100644 --- a/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModuleFactory.java +++ b/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModuleFactory.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/asdcApi/provider/src/main/resources/initial/asdcApi-provider.xml b/asdcApi/provider/src/main/resources/initial/asdcApi-provider.xml index 53f5a11d0..aefdec281 100644 --- a/asdcApi/provider/src/main/resources/initial/asdcApi-provider.xml +++ b/asdcApi/provider/src/main/resources/initial/asdcApi-provider.xml @@ -3,8 +3,8 @@ ============LICENSE_START======================================================= openECOMP : SDN-C ================================================================================ - Copyright (C) 2017 ONAP Intellectual Property. All rights - reserved. + 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. diff --git a/dataChange/features/pom.xml b/dataChange/features/pom.xml index 123404479..cd48d3f52 100755 --- a/dataChange/features/pom.xml +++ b/dataChange/features/pom.xml @@ -4,11 +4,11 @@ dataChange org.onap.ccsdk.sli.northbound - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT org.onap.ccsdk.sli.northbound dataChange-features - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT jar diff --git a/dataChange/features/src/main/resources/features.xml b/dataChange/features/src/main/resources/features.xml index 9cc8cc57b..47cdcfd9f 100644 --- a/dataChange/features/src/main/resources/features.xml +++ b/dataChange/features/src/main/resources/features.xml @@ -3,8 +3,8 @@ ============LICENSE_START======================================================= openECOMP : SDN-C ================================================================================ - Copyright (C) 2017 ONAP Intellectual Property. All rights - reserved. + 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. diff --git a/dataChange/installer/pom.xml b/dataChange/installer/pom.xml index 63fda23ab..940144f53 100755 --- a/dataChange/installer/pom.xml +++ b/dataChange/installer/pom.xml @@ -1,11 +1,10 @@ - + 4.0.0 dataChange org.onap.ccsdk.sli.northbound - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT dataChange-installer dataChange - Karaf Installer diff --git a/dataChange/installer/src/assembly/assemble_installer_zip.xml b/dataChange/installer/src/assembly/assemble_installer_zip.xml index e278872a1..3bed4b5ef 100644 --- a/dataChange/installer/src/assembly/assemble_installer_zip.xml +++ b/dataChange/installer/src/assembly/assemble_installer_zip.xml @@ -2,8 +2,8 @@ ============LICENSE_START======================================================= openECOMP : SDN-C ================================================================================ - Copyright (C) 2017 ONAP Intellectual Property. All rights - reserved. + 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. diff --git a/dataChange/installer/src/assembly/assemble_mvnrepo_zip.xml b/dataChange/installer/src/assembly/assemble_mvnrepo_zip.xml index 608200da1..5c24d73ff 100644 --- a/dataChange/installer/src/assembly/assemble_mvnrepo_zip.xml +++ b/dataChange/installer/src/assembly/assemble_mvnrepo_zip.xml @@ -2,8 +2,8 @@ ============LICENSE_START======================================================= openECOMP : SDN-C ================================================================================ - Copyright (C) 2017 ONAP Intellectual Property. All rights - reserved. + 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. diff --git a/dataChange/installer/src/main/resources/scripts/install-feature.sh b/dataChange/installer/src/main/resources/scripts/install-feature.sh index 9a47d2225..e986764b9 100644 --- a/dataChange/installer/src/main/resources/scripts/install-feature.sh +++ b/dataChange/installer/src/main/resources/scripts/install-feature.sh @@ -4,8 +4,8 @@ # ============LICENSE_START======================================================= # openECOMP : SDN-C # ================================================================================ -# Copyright (C) 2017 ONAP Intellectual Property. All rights -# reserved. +# 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. diff --git a/dataChange/model/pom.xml b/dataChange/model/pom.xml index 0d16ebfc0..20dddeb97 100755 --- a/dataChange/model/pom.xml +++ b/dataChange/model/pom.xml @@ -4,11 +4,11 @@ dataChange org.onap.ccsdk.sli.northbound - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT org.onap.ccsdk.sli.northbound dataChange-model - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT bundle @@ -45,7 +45,7 @@ ${yang.file.directory} - org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl + org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl ${salGeneratorPath} diff --git a/dataChange/pom.xml b/dataChange/pom.xml index 2e3d87494..90e22d219 100755 --- a/dataChange/pom.xml +++ b/dataChange/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.sli.northbound sdnc-northbound - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT pom org.onap.ccsdk.sli.northbound dataChange - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT dataChange diff --git a/dataChange/provider/pom.xml b/dataChange/provider/pom.xml index 5a7c7003d..c73c00980 100755 --- a/dataChange/provider/pom.xml +++ b/dataChange/provider/pom.xml @@ -1,11 +1,10 @@ - + 4.0.0 dataChange org.onap.ccsdk.sli.northbound - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT dataChange-provider bundle @@ -44,7 +43,7 @@ - org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl + org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl ${salGeneratorPath} diff --git a/dataChange/provider/src/main/java/org/onap/ccsdk/sli/northbound/DataChangeClient.java b/dataChange/provider/src/main/java/org/onap/ccsdk/sli/northbound/DataChangeClient.java index 81da74161..75cc0a02e 100644 --- a/dataChange/provider/src/main/java/org/onap/ccsdk/sli/northbound/DataChangeClient.java +++ b/dataChange/provider/src/main/java/org/onap/ccsdk/sli/northbound/DataChangeClient.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/dataChange/provider/src/main/java/org/onap/ccsdk/sli/northbound/DataChangeProvider.java b/dataChange/provider/src/main/java/org/onap/ccsdk/sli/northbound/DataChangeProvider.java index 40d30a792..dcfbf6ee2 100644 --- a/dataChange/provider/src/main/java/org/onap/ccsdk/sli/northbound/DataChangeProvider.java +++ b/dataChange/provider/src/main/java/org/onap/ccsdk/sli/northbound/DataChangeProvider.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/dataChange/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/datachange/provider/impl/rev140523/DataChangeProviderModule.java b/dataChange/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/datachange/provider/impl/rev140523/DataChangeProviderModule.java index f8267cf32..0655ae20a 100644 --- a/dataChange/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/datachange/provider/impl/rev140523/DataChangeProviderModule.java +++ b/dataChange/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/datachange/provider/impl/rev140523/DataChangeProviderModule.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/dataChange/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/datachange/provider/impl/rev140523/DataChangeProviderModuleFactory.java b/dataChange/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/datachange/provider/impl/rev140523/DataChangeProviderModuleFactory.java index 5852788c4..468989998 100644 --- a/dataChange/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/datachange/provider/impl/rev140523/DataChangeProviderModuleFactory.java +++ b/dataChange/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/datachange/provider/impl/rev140523/DataChangeProviderModuleFactory.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/dataChange/provider/src/main/resources/initial/dataChange-provider.xml b/dataChange/provider/src/main/resources/initial/dataChange-provider.xml index 3038201ba..2da0546aa 100644 --- a/dataChange/provider/src/main/resources/initial/dataChange-provider.xml +++ b/dataChange/provider/src/main/resources/initial/dataChange-provider.xml @@ -3,8 +3,8 @@ ============LICENSE_START======================================================= openECOMP : SDN-C ================================================================================ - Copyright (C) 2017 ONAP Intellectual Property. All rights - reserved. + 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. diff --git a/dmaap-listener/pom.xml b/dmaap-listener/pom.xml index 9ab23cdea..ac65c16f8 100755 --- a/dmaap-listener/pom.xml +++ b/dmaap-listener/pom.xml @@ -1,16 +1,17 @@ + 4.0.0 org.onap.ccsdk.sli.northbound jar dmaap-listener - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT DMAAP Listener DMAAP Listener org.onap.ccsdk.sli.northbound sdnc-northbound - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT 1.1.7-SNAPSHOT diff --git a/dmaap-listener/src/assembly/assemble_zip.xml b/dmaap-listener/src/assembly/assemble_zip.xml index 15f6bf4d2..f8873ab41 100644 --- a/dmaap-listener/src/assembly/assemble_zip.xml +++ b/dmaap-listener/src/assembly/assemble_zip.xml @@ -2,8 +2,8 @@ ============LICENSE_START======================================================= openECOMP : SDN-C ================================================================================ - Copyright (C) 2017 ONAP Intellectual Property. All rights - reserved. + 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. diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DmaapListener.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DmaapListener.java index b2976294b..91afe1d1a 100644 --- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DmaapListener.java +++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DmaapListener.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DummyDmaapConsumer.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DummyDmaapConsumer.java index a3bc46153..a8336342f 100644 --- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DummyDmaapConsumer.java +++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DummyDmaapConsumer.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/InvalidMessageException.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/InvalidMessageException.java index b54adaf06..cab8b901c 100644 --- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/InvalidMessageException.java +++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/InvalidMessageException.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDmaapConsumer.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDmaapConsumer.java index f6d8ff862..c1320d6b4 100644 --- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDmaapConsumer.java +++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDmaapConsumer.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java index 0e2a32646..abd395bfb 100644 --- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java +++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncOdlConnection.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncOdlConnection.java index 4d16dd2a0..e31219a23 100644 --- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncOdlConnection.java +++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncOdlConnection.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/dmaap-listener/src/main/resources/log4j.properties b/dmaap-listener/src/main/resources/log4j.properties index ba815871b..8db00762b 100644 --- a/dmaap-listener/src/main/resources/log4j.properties +++ b/dmaap-listener/src/main/resources/log4j.properties @@ -2,8 +2,8 @@ # ============LICENSE_START======================================================= # openECOMP : SDN-C # ================================================================================ -# Copyright (C) 2017 ONAP Intellectual Property. All rights -# reserved. +# 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. diff --git a/dmaap-listener/src/main/scripts/start-dmaap-listener.sh b/dmaap-listener/src/main/scripts/start-dmaap-listener.sh index 5eeb62bbf..805105863 100644 --- a/dmaap-listener/src/main/scripts/start-dmaap-listener.sh +++ b/dmaap-listener/src/main/scripts/start-dmaap-listener.sh @@ -4,8 +4,8 @@ # ============LICENSE_START======================================================= # openECOMP : SDN-C # ================================================================================ -# Copyright (C) 2017 ONAP Intellectual Property. All rights -# reserved. +# 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. diff --git a/dmaap-listener/src/main/scripts/stop-dmaap-listener.sh b/dmaap-listener/src/main/scripts/stop-dmaap-listener.sh index 42de474fb..61be1a141 100644 --- a/dmaap-listener/src/main/scripts/stop-dmaap-listener.sh +++ b/dmaap-listener/src/main/scripts/stop-dmaap-listener.sh @@ -4,8 +4,8 @@ # ============LICENSE_START======================================================= # openECOMP : SDN-C # ================================================================================ -# Copyright (C) 2017 ONAP Intellectual Property. All rights -# reserved. +# 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. diff --git a/dmaap-listener/src/site/apt/index.apt b/dmaap-listener/src/site/apt/index.apt index dd9d3ec39..370ddd4db 100644 --- a/dmaap-listener/src/site/apt/index.apt +++ b/dmaap-listener/src/site/apt/index.apt @@ -2,8 +2,8 @@ ~~ ============LICENSE_START======================================================= ~~ openECOMP : SDN-C ~~ ================================================================================ -~~ Copyright (C) 2017 ONAP Intellectual Property. All rights -~~ reserved. +~~ 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. diff --git a/dmaap-listener/src/site/site.xml b/dmaap-listener/src/site/site.xml index 356c9c959..6b97d925e 100644 --- a/dmaap-listener/src/site/site.xml +++ b/dmaap-listener/src/site/site.xml @@ -3,8 +3,8 @@ ============LICENSE_START======================================================= openECOMP : SDN-C ================================================================================ - Copyright (C) 2017 ONAP Intellectual Property. All rights - reserved. + 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. diff --git a/pom.xml b/pom.xml index 4d2bb2092..c0f7ac616 100644 --- a/pom.xml +++ b/pom.xml @@ -1,10 +1,9 @@ - + org.onap.ccsdk.parent - odlparent-boron-sr3 + odlparent-carbon-sr1 0.0.1-SNAPSHOT @@ -113,7 +112,7 @@ AT&T - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT diff --git a/ueb-listener/pom.xml b/ueb-listener/pom.xml index e0b96aaf4..5f8d5ca1b 100755 --- a/ueb-listener/pom.xml +++ b/ueb-listener/pom.xml @@ -1,16 +1,17 @@ + 4.0.0 org.onap.ccsdk.sli.northbound jar ueb-listener - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT UEB Listener UEB Listener org.onap.ccsdk.sli.northbound sdnc-northbound - 0.0.1-SNAPSHOT + 0.1.0-SNAPSHOT 1.1.7-SNAPSHOT diff --git a/ueb-listener/src/assembly/assemble_zip.xml b/ueb-listener/src/assembly/assemble_zip.xml index d1f6679e1..97a229d2c 100644 --- a/ueb-listener/src/assembly/assemble_zip.xml +++ b/ueb-listener/src/assembly/assemble_zip.xml @@ -2,8 +2,8 @@ ============LICENSE_START======================================================= openECOMP : SDN-C ================================================================================ - Copyright (C) 2017 ONAP Intellectual Property. All rights - reserved. + 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. diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java index 3be906181..75b19cd2e 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java index d979a3206..4c08949c0 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index 707eee7e4..1b6049278 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java index dcf668ed8..2fec84cb1 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java index 7bee801d2..821057ef3 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java index 86a4d2a25..3df27be6e 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index fd304208c..1e6b19db0 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java index e8ffc3333..e19646e39 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java index bf0d5b823..3c561118e 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java index 76f015f9a..55814ac3a 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java index cd79689b4..deed20cf4 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java index 7ae6c3107..3663c97c3 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. diff --git a/ueb-listener/src/main/resources/log4j.properties b/ueb-listener/src/main/resources/log4j.properties index 670e48e11..f2f4ed26b 100644 --- a/ueb-listener/src/main/resources/log4j.properties +++ b/ueb-listener/src/main/resources/log4j.properties @@ -2,8 +2,8 @@ # ============LICENSE_START======================================================= # openECOMP : SDN-C # ================================================================================ -# Copyright (C) 2017 ONAP Intellectual Property. All rights -# reserved. +# 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. diff --git a/ueb-listener/src/main/scripts/start-ueb-listener.sh b/ueb-listener/src/main/scripts/start-ueb-listener.sh index db00726be..80ede3c8b 100644 --- a/ueb-listener/src/main/scripts/start-ueb-listener.sh +++ b/ueb-listener/src/main/scripts/start-ueb-listener.sh @@ -4,8 +4,8 @@ # ============LICENSE_START======================================================= # openECOMP : SDN-C # ================================================================================ -# Copyright (C) 2017 ONAP Intellectual Property. All rights -# reserved. +# 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. diff --git a/ueb-listener/src/main/scripts/stop-ueb-listener.sh b/ueb-listener/src/main/scripts/stop-ueb-listener.sh index 2e3b4dd2b..cf110c5cc 100644 --- a/ueb-listener/src/main/scripts/stop-ueb-listener.sh +++ b/ueb-listener/src/main/scripts/stop-ueb-listener.sh @@ -4,8 +4,8 @@ # ============LICENSE_START======================================================= # openECOMP : SDN-C # ================================================================================ -# Copyright (C) 2017 ONAP Intellectual Property. All rights -# reserved. +# 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. diff --git a/ueb-listener/src/site/apt/index.apt b/ueb-listener/src/site/apt/index.apt index dd9d3ec39..370ddd4db 100644 --- a/ueb-listener/src/site/apt/index.apt +++ b/ueb-listener/src/site/apt/index.apt @@ -2,8 +2,8 @@ ~~ ============LICENSE_START======================================================= ~~ openECOMP : SDN-C ~~ ================================================================================ -~~ Copyright (C) 2017 ONAP Intellectual Property. All rights -~~ reserved. +~~ 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. diff --git a/ueb-listener/src/site/site.xml b/ueb-listener/src/site/site.xml index 356c9c959..6b97d925e 100644 --- a/ueb-listener/src/site/site.xml +++ b/ueb-listener/src/site/site.xml @@ -3,8 +3,8 @@ ============LICENSE_START======================================================= openECOMP : SDN-C ================================================================================ - Copyright (C) 2017 ONAP Intellectual Property. All rights - reserved. + 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. -- cgit 1.2.3-korg From 8881ebb497e9f35e5ea9d19923fd926db56e8f12 Mon Sep 17 00:00:00 2001 From: Ryan Goulding Date: Thu, 7 Sep 2017 12:10:08 -0400 Subject: Fix SDNC service registration This change converts AsdcApiProvider and AsdcApiSliClient to utilize Aries Blueprint for service instantiation instead of the ODL Config Subsystem. Change-Id: I5eaebe4c6e5b33fc8beb20b2cfe9acb6e8b6d808 Issue-Id: SDNC-54 Signed-off-by: Ryan Goulding --- asdcApi/features/pom.xml | 7 -- asdcApi/features/src/main/resources/features.xml | 1 - .../src/assembly/assemble_mvnrepo_zip.xml | 8 -- asdcApi/pom.xml | 8 +- asdcApi/provider/pom.xml | 70 ---------------- .../sli/northbound/asdcapi/AsdcApiProvider.java | 93 ++++++++-------------- .../sli/northbound/asdcapi/AsdcApiSliClient.java | 29 ++----- .../impl/rev140523/AsdcApiProviderModule.java | 59 -------------- .../rev140523/AsdcApiProviderModuleFactory.java | 34 -------- .../main/resources/initial/asdcApi-provider.xml | 70 ---------------- .../org/opendaylight/blueprint/asdc-blueprint.xml | 32 ++++++++ .../src/main/yang/asdcApi-provider-impl.yang | 61 -------------- .../sli/northbound/uebclient/SdncUebCallback.java | 2 +- 13 files changed, 73 insertions(+), 401 deletions(-) delete mode 100644 asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModule.java delete mode 100644 asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModuleFactory.java delete mode 100644 asdcApi/provider/src/main/resources/initial/asdcApi-provider.xml create mode 100644 asdcApi/provider/src/main/resources/org/opendaylight/blueprint/asdc-blueprint.xml delete mode 100755 asdcApi/provider/src/main/yang/asdcApi-provider-impl.yang (limited to 'ueb-listener/src') diff --git a/asdcApi/features/pom.xml b/asdcApi/features/pom.xml index e6af34c57..0f3a5ddd2 100755 --- a/asdcApi/features/pom.xml +++ b/asdcApi/features/pom.xml @@ -16,13 +16,6 @@ asdcApi-model ${project.version} - - org.onap.ccsdk.sli.northbound - asdcApi-provider - ${project.version} - config - xml - org.onap.ccsdk.sli.northbound asdcApi-provider diff --git a/asdcApi/features/src/main/resources/features.xml b/asdcApi/features/src/main/resources/features.xml index 9006f1b94..2048dc12a 100644 --- a/asdcApi/features/src/main/resources/features.xml +++ b/asdcApi/features/src/main/resources/features.xml @@ -33,7 +33,6 @@ mvn:org.onap.ccsdk.sli.northbound/asdcApi-provider/${project.version} sdnc-sli - mvn:org.onap.ccsdk.sli.northbound/asdcApi-provider/${project.version}/xml/config diff --git a/asdcApi/installer/src/assembly/assemble_mvnrepo_zip.xml b/asdcApi/installer/src/assembly/assemble_mvnrepo_zip.xml index 5c24d73ff..21e271d42 100644 --- a/asdcApi/installer/src/assembly/assemble_mvnrepo_zip.xml +++ b/asdcApi/installer/src/assembly/assemble_mvnrepo_zip.xml @@ -44,12 +44,4 @@ - - - ../provider/src/main/resources/initial/${feature-name}-provider.xml - ./etc/opendaylight/karaf/200-${feature-name}-provider.xml - - - - diff --git a/asdcApi/pom.xml b/asdcApi/pom.xml index d4990612e..0adc96e64 100755 --- a/asdcApi/pom.xml +++ b/asdcApi/pom.xml @@ -33,13 +33,7 @@ asdcApi-model ${project.version} - - org.onap.ccsdk.sli.northbound - asdcApi-provider - ${project.version} - config - xml - + org.onap.ccsdk.sli.northbound asdcApi-provider diff --git a/asdcApi/provider/pom.xml b/asdcApi/provider/pom.xml index 7b7ed4bee..329d6ef2a 100755 --- a/asdcApi/provider/pom.xml +++ b/asdcApi/provider/pom.xml @@ -15,76 +15,6 @@ org.apache.felix maven-bundle-plugin true - - - org.opendaylight.controller.config.yang.config.asdcApi_provider.impl - * - - - - - org.opendaylight.yangtools - yang-maven-plugin - ${odl.yangtools.yang.maven.plugin.version} - - - config - - generate-sources - - - - - org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator - ${jmxGeneratorPath} - - urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang - - - - org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl - ${salGeneratorPath} - - - true - - - - - - org.opendaylight.mdsal - maven-sal-api-gen-plugin - ${odl.sal.api.gen.plugin.version} - jar - - - org.opendaylight.controller - yang-jmx-generator-plugin - ${odl.yang.jmx.generator.version} - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - attach-artifacts - - attach-artifact - - package - - - - ${project.build.directory}/classes/initial/asdcApi-provider.xml - xml - config - - - - - diff --git a/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java index bd5f74a4f..13198d623 100644 --- a/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java +++ b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java @@ -95,32 +95,36 @@ import com.google.common.util.concurrent.Futures; */ public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { + private static final Logger LOG = LoggerFactory.getLogger(AsdcApiProvider.class); + private static final String ACTIVE_VERSION = "active"; - private final Logger log = LoggerFactory.getLogger( AsdcApiProvider.class ); - private final String appName = "asdcApi"; + private static final String APPLICATION_NAME = "asdcApi"; private final ExecutorService executor; protected DataBroker dataBroker; protected NotificationProviderService notificationService; protected RpcProviderRegistry rpcRegistry; + private final AsdcApiSliClient asdcApiSliClient; protected BindingAwareBroker.RpcRegistration rpcRegistration; - public AsdcApiProvider(DataBroker dataBroker2, - NotificationProviderService notificationProviderService, - RpcProviderRegistry rpcProviderRegistry) { - this.log.info( "Creating provider for " + appName ); + public AsdcApiProvider(final DataBroker dataBroker, + final NotificationProviderService notificationProviderService, + final RpcProviderRegistry rpcProviderRegistry, + final AsdcApiSliClient asdcApiSliClient) { + + LOG.info("Creating provider for {}", APPLICATION_NAME); executor = Executors.newFixedThreadPool(1); - dataBroker = dataBroker2; + this.dataBroker = dataBroker; notificationService = notificationProviderService; rpcRegistry = rpcProviderRegistry; + this.asdcApiSliClient= asdcApiSliClient; initialize(); } public void initialize(){ - log.info( "Initializing provider for " + appName ); - + LOG.info("Initializing {} for {}", this.getClass().getName(), APPLICATION_NAME); createContainers(); @@ -128,10 +132,9 @@ public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { if (rpcRegistry != null) { rpcRegistration = rpcRegistry.addRpcImplementation( ASDCAPIService.class, this); - log.info("Initialization complete for " + appName); + LOG.info("Initialization complete for {}", APPLICATION_NAME); } else { - log.warn("Error initializing " + appName - + " : rpcRegistry unset"); + LOG.warn("Error initializing {} : rpcRegistry unset", APPLICATION_NAME); } } } @@ -151,14 +154,14 @@ public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { try { CheckedFuture checkedFuture = t.submit(); checkedFuture.get(); - log.info("Create Containers succeeded!: "); + LOG.info("Create Containers succeeded!: "); } catch (InterruptedException | ExecutionException e) { - log.error("Create Containers Failed: " + e); + LOG.error("Create Containers Failed: " + e); e.printStackTrace(); } } else { - log.warn("createContainers : cannot find dataBroker to create containers"); + LOG.warn("createContainers : cannot find dataBroker to create containers"); } } protected void initializeChild() { @@ -167,38 +170,12 @@ public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { @Override public void close() throws Exception { - log.info( "Closing provider for " + appName ); + LOG.info( "Closing provider for " + APPLICATION_NAME); executor.shutdown(); rpcRegistration.close(); - log.info( "Successfully closed provider for " + appName ); - } - - public void setDataBroker(DataBroker dataBroker) { - this.dataBroker = dataBroker; - if( log.isDebugEnabled() ){ - log.debug( "DataBroker set to " + (dataBroker==null?"null":"non-null") + "." ); - } - } - - public void setNotificationService( - NotificationProviderService notificationService) { - this.notificationService = notificationService; - if( log.isDebugEnabled() ){ - log.debug( "Notification Service set to " + (notificationService==null?"null":"non-null") + "." ); - } - } - - public void setRpcRegistry(RpcProviderRegistry rpcRegistry) { - this.rpcRegistry = rpcRegistry; - - rpcRegistration = rpcRegistry.addRpcImplementation(ASDCAPIService.class, this); - - if( log.isDebugEnabled() ){ - log.debug( "RpcRegistry set to " + (rpcRegistry==null?"null":"non-null") + "." ); - } + LOG.info( "Successfully closed provider for " + APPLICATION_NAME); } - protected boolean artifactVersionExists(String aName, String aVersion) { InstanceIdentifier artifactInstanceId = InstanceIdentifier.builder(Artifacts.class) @@ -208,7 +185,7 @@ public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { try { data = (Optional) readTx.read(LogicalDatastoreType.CONFIGURATION, artifactInstanceId).get(); } catch (InterruptedException | ExecutionException e) { - log.error("Caught Exception reading MD-SAL for ["+aName+","+ aVersion+"] " ,e); + LOG.error("Caught Exception reading MD-SAL for ["+aName+","+ aVersion+"] " ,e); return false; } @@ -244,7 +221,7 @@ public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { artifact); tx.submit().checkedGet(); } catch (Exception e) { - log.error("Caught exception trying to add artifact entry", e); + LOG.error("Caught exception trying to add artifact entry", e); } } @@ -279,7 +256,7 @@ public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { version); tx.submit().checkedGet(); } catch (Exception e) { - log.error( + LOG.error( "Caught exception trying to save entry to MD-SAL", e); } @@ -307,7 +284,7 @@ public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { version); tx.submit().checkedGet(); } catch (Exception e) { - log.error( + LOG.error( "Caught exception trying to save entry to MD-SAL", e); } @@ -320,10 +297,10 @@ public Future> vfLicenseModelUpdate(VfLice Properties parms = new Properties(); - log.info( SVC_OPERATION +" called." ); + LOG.info( SVC_OPERATION +" called." ); if(input == null ) { - log.debug("exiting " +SVC_OPERATION+ " because of invalid input"); + LOG.debug("exiting " +SVC_OPERATION+ " because of invalid input"); return null; } @@ -339,28 +316,24 @@ public Future> vfLicenseModelUpdate(VfLice errorMessage = "Artifact version already exists"; } else { // Translate input object into SLI-consumable properties - log.info("Adding INPUT data for "+SVC_OPERATION+" input: " + input); + LOG.info("Adding INPUT data for "+SVC_OPERATION+" input: " + input); AsdcApiUtil.toProperties(parms, input); // Call directed graph - Properties respProps = null; - - - AsdcApiSliClient sliClient = new AsdcApiSliClient(); try { - if (sliClient.hasGraph("ASDC-API", SVC_OPERATION , null, "sync")) + if (asdcApiSliClient.hasGraph("ASDC-API", SVC_OPERATION , null, "sync")) { try { - respProps = sliClient.execute("ASDC-API", SVC_OPERATION, null, "sync", parms); + respProps = asdcApiSliClient.execute("ASDC-API", SVC_OPERATION, null, "sync", parms); } catch (Exception e) { - log.error("Caught exception executing service logic for "+ SVC_OPERATION, e); + LOG.error("Caught exception executing service logic for "+ SVC_OPERATION, e); } } else { errorMessage = "No service logic active for ASDC-API: '" + SVC_OPERATION + "'"; @@ -371,7 +344,7 @@ public Future> vfLicenseModelUpdate(VfLice { errorCode = "500"; errorMessage = e.getMessage(); - log.error("Caught exception looking for service logic", e); + LOG.error("Caught exception looking for service logic", e); } @@ -384,14 +357,14 @@ public Future> vfLicenseModelUpdate(VfLice if ("200".equals(errorCode)) { - log.info("ASDC update succeeded"); + LOG.info("ASDC update succeeded"); // Update config tree applyVfLicenseModelUpdate(input); addArtifactVersion(input.getArtifactName(), input.getArtifactVersion()); } else { - log.info("ASDC update failed ("+errorCode+" : "+errorMessage); + LOG.info("ASDC update failed ("+errorCode+" : "+errorMessage); } // Send response diff --git a/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiSliClient.java b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiSliClient.java index 5b268bc28..51fdd7002 100644 --- a/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiSliClient.java +++ b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiSliClient.java @@ -25,39 +25,22 @@ import java.util.Properties; import org.onap.ccsdk.sli.core.sli.SvcLogicException; import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class AsdcApiSliClient { - private static final Logger LOG = LoggerFactory - .getLogger(AsdcApiSliClient.class); + private static final Logger LOG = LoggerFactory.getLogger(AsdcApiSliClient.class); - private SvcLogicService svcLogic = null; + private final SvcLogicService svcLogicService; - public AsdcApiSliClient() - { - BundleContext bctx = FrameworkUtil.getBundle(SvcLogicService.class).getBundleContext(); - - // Get SvcLogicService reference - ServiceReference sref = bctx.getServiceReference(SvcLogicService.NAME); - if (sref != null) - { - svcLogic = (SvcLogicService) bctx.getService(sref); - } - else - { - LOG.warn("Cannot find service reference for "+SvcLogicService.NAME); - - } + public AsdcApiSliClient(final SvcLogicService svcLogicService) { + this.svcLogicService = svcLogicService; } public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException { - return(svcLogic.hasGraph(module, rpc, version, mode)); + return(svcLogicService.hasGraph(module, rpc, version, mode)); } @@ -78,7 +61,7 @@ public class AsdcApiSliClient { } } - Properties respProps = svcLogic.execute(module, rpc, version, mode, parms); + Properties respProps = svcLogicService.execute(module, rpc, version, mode, parms); if (LOG.isDebugEnabled()) { diff --git a/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModule.java b/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModule.java deleted file mode 100644 index 26dc94285..000000000 --- a/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModule.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============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.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.asdcapi.provider.impl.rev140523; - -import org.onap.ccsdk.sli.northbound.asdcapi.AsdcApiProvider; - -public class AsdcApiProviderModule extends org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.asdcapi.provider.impl.rev140523.AbstractAsdcApiProviderModule { - public AsdcApiProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { - super(identifier, dependencyResolver); - } - - public AsdcApiProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.asdcapi.provider.impl.rev140523.AsdcApiProviderModule oldModule, java.lang.AutoCloseable oldInstance) { - super(identifier, dependencyResolver, oldModule, oldInstance); - } - - @Override - public void customValidation() { - // add custom validation form module attributes here. - } - - @Override - public java.lang.AutoCloseable createInstance() { - - - final AsdcApiProvider provider = new AsdcApiProvider(getDataBrokerDependency() - , getNotificationServiceDependency() - , getRpcRegistryDependency()); - - return new AutoCloseable() { - - @Override - public void close() throws Exception { - - provider.close(); - } - }; - - } - -} diff --git a/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModuleFactory.java b/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModuleFactory.java deleted file mode 100644 index 513e61cff..000000000 --- a/asdcApi/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/ccsdk/sli/northbound/asdcapi/provider/impl/rev140523/AsdcApiProviderModuleFactory.java +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * ============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========================================================= - */ - -/* -* Generated file -* -* Generated from: yang module name: asdcApi-provider-impl yang module local name: asdcApi-provider-impl -* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator -* Generated at: Mon Aug 14 15:34:51 EDT 2017 -* -* Do not modify this file unless it is present under src/main directory -*/ -package org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.asdcapi.provider.impl.rev140523; -public class AsdcApiProviderModuleFactory extends org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.asdcapi.provider.impl.rev140523.AbstractAsdcApiProviderModuleFactory { - -} diff --git a/asdcApi/provider/src/main/resources/initial/asdcApi-provider.xml b/asdcApi/provider/src/main/resources/initial/asdcApi-provider.xml deleted file mode 100644 index aefdec281..000000000 --- a/asdcApi/provider/src/main/resources/initial/asdcApi-provider.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - - - prefix:asdcApi-provider-impl - - asdcApi-provider-impl - - - - binding:binding-rpc-registry - binding-rpc-broker - - - - binding:binding-async-data-broker - binding-data-broker - - - - - binding:binding-notification-service - - binding-notification-broker - - - - - - - - - - - org:onap:ccsdk:sli:northbound:asdcapi:provider:impl?module=asdcApi-provider-impl&revision=2014-05-23 - - - diff --git a/asdcApi/provider/src/main/resources/org/opendaylight/blueprint/asdc-blueprint.xml b/asdcApi/provider/src/main/resources/org/opendaylight/blueprint/asdc-blueprint.xml new file mode 100644 index 000000000..6229db1f6 --- /dev/null +++ b/asdcApi/provider/src/main/resources/org/opendaylight/blueprint/asdc-blueprint.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/asdcApi/provider/src/main/yang/asdcApi-provider-impl.yang b/asdcApi/provider/src/main/yang/asdcApi-provider-impl.yang deleted file mode 100755 index 7a1876cc1..000000000 --- a/asdcApi/provider/src/main/yang/asdcApi-provider-impl.yang +++ /dev/null @@ -1,61 +0,0 @@ -module asdcApi-provider-impl { - - yang-version 1; - namespace "org:onap:ccsdk:sli:northbound:asdcapi:provider:impl"; - prefix "asdcApi-provider-impl"; - - import config { prefix config; revision-date 2013-04-05; } - import opendaylight-md-sal-binding { prefix mdsal; revision-date 2013-10-28; } - - description - "This module contains the base YANG definitions for - asdcApi-provider impl implementation."; - - revision "2014-05-23" { - description - "Initial revision."; - } - - // This is the definition of the service implementation as a module identity. - identity asdcApi-provider-impl { - base config:module-type; - - // Specifies the prefix for generated java classes. - config:java-name-prefix AsdcApiProvider; - } - - // Augments the 'configuration' choice node under modules/module. - // We consume the three main services, RPCs, DataStore, and Notifications - augment "/config:modules/config:module/config:configuration" { - case asdcApi-provider-impl { - when "/config:modules/config:module/config:type = 'asdcApi-provider-impl'"; - - container rpc-registry { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity mdsal:binding-rpc-registry; - } - } - } - - container notification-service { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity mdsal:binding-notification-service; - } - } - } - - container data-broker { - uses config:service-ref { - refine type { - mandatory false; - config:required-identity mdsal:binding-async-data-broker; - } - } - } - } - } -} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index 1e6b19db0..73e8fe55b 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -209,7 +209,7 @@ public class SdncUebCallback implements INotificationCallback { props.load(new FileInputStream(propFile)); try { - jdbcDataSource = DBResourceManager.create(props); + jdbcDataSource = new DBResourceManager(props); } catch(Throwable exc) { LOG.error("", exc); } -- cgit 1.2.3-korg From ea0aabe54bc7b5d609b587e87ce85765f73fecbc Mon Sep 17 00:00:00 2001 From: Gaurav Agrawal Date: Fri, 8 Sep 2017 19:28:18 +0530 Subject: Fix few Blocker sonar issues Fix few Blocker sonar issues in CCSDK SLI Northbound https://sonar.onap.org/component_issues/index?id=org.onap.ccsdk.sli.northbound%3Accsdk-sli-northbound#resolved=false|severities=BLOCKER Change-Id: I8a2f2e9f3bc5bc5c007076e42f77fbf5da1304ac Issue-Id: CCSDK-67 Signed-off-by: Gaurav Agrawal --- .../northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java | 5 ++--- .../ccsdk/sli/northbound/uebclient/SdncArtifactMap.java | 13 +------------ 2 files changed, 3 insertions(+), 15 deletions(-) (limited to 'ueb-listener/src') diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java index abd395bfb..1754957da 100644 --- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java +++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java @@ -164,10 +164,9 @@ public class SdncFlatJsonDmaapConsumer extends SdncDmaapConsumer { return(null); } - try { - BufferedReader mapReader = new BufferedReader(new FileReader(mapFile)); + try (BufferedReader mapReader = new BufferedReader(new FileReader(mapFile))) { - String curLine = null; + String curLine; while ((curLine = mapReader.readLine()) != null) { curLine = curLine.trim(); diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java index 4c08949c0..dd9437ce9 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java @@ -87,10 +87,7 @@ public class SdncArtifactMap { if (mapFile.exists() && mapFile.canRead()) { - BufferedReader rdr = null; - try { - - rdr = new BufferedReader(new FileReader(mapFile)); + try (BufferedReader rdr = new BufferedReader(new FileReader(mapFile))) { for (String ln ; (ln = rdr.readLine()) != null ; ) { String[] lnFields = ln.split(","); @@ -107,14 +104,6 @@ public class SdncArtifactMap { } catch (Exception e) { LOG.error("Caught exception reading artifact map", e); return; - } finally { - if (rdr != null) { - try { - rdr.close(); - } catch (IOException e) { - - } - } } } } -- cgit 1.2.3-korg From c78bab01fa4667e840aad907ee37fa67b4fe8239 Mon Sep 17 00:00:00 2001 From: Gaurav Agrawal Date: Fri, 8 Sep 2017 19:58:55 +0530 Subject: Fix few Blocker sonar issues Fix few Blocker sonar issues in CCSDK SLI Northbound https://sonar.onap.org/component_issues/index?id=org.onap.ccsdk.sli.northbound%3Accsdk-sli-northbound#resolved=false|severities=BLOCKER Change-Id: I7229c7e2a0dabc0ff789b91ae413b9a15ef3cbad Issue-Id: CCSDK-67 Signed-off-by: Gaurav Agrawal --- .../sli/northbound/uebclient/SdncUebCallback.java | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index 73e8fe55b..e7a42bcb8 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -208,12 +208,8 @@ public class SdncUebCallback implements INotificationCallback { Properties props = new Properties(); props.load(new FileInputStream(propFile)); - try { - jdbcDataSource = new DBResourceManager(props); - } catch(Throwable exc) { - LOG.error("", exc); - } - + jdbcDataSource = new DBResourceManager(props); + if(((DBResourceManager)jdbcDataSource).isActive()){ LOG.warn( "DBLIB: JDBC DataSource has been initialized."); } else { @@ -405,8 +401,7 @@ public class SdncUebCallback implements INotificationCallback { boolean writeSucceeded = false; - try { - FileWriter spoolFileWriter = new FileWriter(spoolFile); + try (FileWriter spoolFileWriter = new FileWriter(spoolFile)) { spoolFileWriter.write(payload); spoolFileWriter.close(); writeSucceeded = true; @@ -916,11 +911,8 @@ public class SdncUebCallback implements INotificationCallback { msgBuffer.append(""+artifact.getArtifactVersion()+"\n"); - try { - BufferedReader rdr = new BufferedReader(new FileReader(artifact.getFile())); - + try (BufferedReader rdr = new BufferedReader(new FileReader(artifact.getFile()))){ String curLine = rdr.readLine(); - while (curLine != null) { if (!curLine.startsWith(" Date: Thu, 14 Sep 2017 15:25:10 +0530 Subject: Fix Sonar issues few major issues in sli/northbound module Issue-Id: CCSDK-87 Change-Id: I2c1a8b41266aae6941c5f2fdbb8b08ea91dde6ec Signed-off-by: surya-huawei --- .../onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index 1b6049278..32e51599e 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -51,7 +51,7 @@ public class SdncBaseModel { public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata) { - params = new HashMap(); + params = new HashMap<>(); this.sdcCsarHelper = sdcCsarHelper; // extract service metadata @@ -66,7 +66,7 @@ public class SdncBaseModel { public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { - params = new HashMap(); + params = new HashMap<>(); this.sdcCsarHelper = sdcCsarHelper; // extract nodeTemplate metadata @@ -79,7 +79,7 @@ public class SdncBaseModel { public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Group group) { - params = new HashMap(); + params = new HashMap<>(); this.sdcCsarHelper = sdcCsarHelper; // extract group metadata @@ -257,9 +257,9 @@ public class SdncBaseModel { sb.append(") values (" + getCustomizationUUID() + ", \"" + model_yaml + "\", "); paramCount = 0; - for (String paramKey : params.keySet()) { + for (Map.Entry entry : params.entrySet()) { paramCount++; - String paramValue = params.get(paramKey); + String paramValue = entry.getValue(); sb.append(paramValue); if (paramCount < params.size()) sb.append(", "); } @@ -283,9 +283,9 @@ public class SdncBaseModel { sb.append(") values (" + keyValue + ", "); paramCount = 0; - for (String paramKey : params.keySet()) { + for (Map.Entry entry : params.entrySet()) { paramCount++; - String paramValue = params.get(paramKey); + String paramValue = entry.getValue(); sb.append(paramValue); if (paramCount < params.size()) sb.append(", "); } -- cgit 1.2.3-korg From c0696b9b0ce62d3f10cd46eae8ac5a5ca99d3b1d Mon Sep 17 00:00:00 2001 From: Gaurav Agrawal Date: Tue, 19 Sep 2017 19:06:33 +0530 Subject: Fix critical sonar issues Fix critical sonar issues in CCSDK SLI Northbound by either logging or rethrowing the exception https://sonar.onap.org/component_issues/index?id=org.onap.ccsdk.sli.northbound%3Accsdk-sli-northbound#resolved=false|severities=CRITICAL Change-Id: I718f13b5801ea9d69b5c36f75b5387a0ae59cc6a Issue-Id: CCSDK-67 Signed-off-by: Gaurav Agrawal --- .../java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java | 3 +-- .../java/org/onap/ccsdk/sli/northbound/dmaapclient/DmaapListener.java | 2 +- .../ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java | 2 +- .../java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java | 2 +- .../org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java | 4 ++-- 5 files changed, 6 insertions(+), 7 deletions(-) (limited to 'ueb-listener/src') diff --git a/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java index b9c897ec0..cebcb9986 100644 --- a/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java +++ b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java @@ -157,8 +157,7 @@ public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { LOG.info("Create Containers succeeded!: "); } catch (InterruptedException | ExecutionException e) { - LOG.error("Create Containers Failed: " + e); - e.printStackTrace(); + LOG.error("Create Containers Failed: ", e); } } else { LOG.warn("createContainers : cannot find dataBroker to create containers"); diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DmaapListener.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DmaapListener.java index 91afe1d1a..ec34fe402 100644 --- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DmaapListener.java +++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/DmaapListener.java @@ -106,7 +106,7 @@ public class DmaapListener { try { consumerClass = Class.forName(consumerClassName); } catch (Exception e) { - LOG.error("Could not find DMaap consumer class " + consumerClassName); + LOG.error("Could not find DMaap consumer class {}", consumerClassName, e); } if (consumerClass != null) { diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java index 1754957da..7196c90a7 100644 --- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java +++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java @@ -135,7 +135,7 @@ public class SdncFlatJsonDmaapConsumer extends SdncDmaapConsumer { LOG.info("POST message body would be:\n"+rpcMsgbody); } } catch (Exception e) { - + LOG.error("Unable to process message", e); } } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java index dd9437ce9..9b36cb6b3 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java @@ -66,7 +66,7 @@ public class SdncArtifactMap { try { this.pass = Integer.parseInt(pass); } catch (Exception e) { - LOG.error("Invalid pass value for artifact map entry ("+tag+","+rpc+","+pass+")"); + LOG.error("Invalid pass value for artifact map entry ({} {} {})", tag, rpc, pass, e); } } } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java index 3c561118e..3ea092d47 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java @@ -132,7 +132,7 @@ public class SdncUebConfiguration implements IConfiguration{ try { pollingInterval = Integer.parseInt(curval); } catch (Exception e) { - LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-interval ("+curval+")"); + LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-interval ({}) ", curval, e); } } @@ -141,7 +141,7 @@ public class SdncUebConfiguration implements IConfiguration{ try { pollingTimeout = Integer.parseInt(curval); } catch (Exception e) { - LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-timeout ("+curval+")"); + LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-timeout ({}) ", curval, e); } } -- cgit 1.2.3-korg From a74ffcd839da0b212cc2bca502977f225682dc33 Mon Sep 17 00:00:00 2001 From: surya-huawei Date: Wed, 20 Sep 2017 16:18:41 +0530 Subject: Remove useless assigment to local variables *Removed dead stores This is done to avoid waste of resources Issue-Id: CCSDK-87 Change-Id: Ie36255c6583792e2535000ee1bd5b2a3018632ff Signed-off-by: surya-huawei --- .../ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java | 4 ++-- .../org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java | 5 ++--- .../onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'ueb-listener/src') diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java index aa3f7261a..60a508e51 100644 --- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java +++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumer.java @@ -59,8 +59,8 @@ public class SdncFlatJsonDmaapConsumer extends SdncDmaapConsumer { } ObjectMapper oMapper = new ObjectMapper(); - JsonNode instarRootNode = null; - ObjectNode sdncRootNode = null; + JsonNode instarRootNode ; + ObjectNode sdncRootNode; String instarMsgName = null; diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index e7a42bcb8..6a0c8c394 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -189,7 +189,7 @@ public class SdncUebCallback implements INotificationCallback { private static void setJdbcDataSource() throws IOException { - String propPath = null; + String propPath; String propDir = System.getenv(SDNC_CONFIG_DIR); if (propDir == null) { @@ -1056,8 +1056,7 @@ public class SdncUebCallback implements INotificationCallback { private File applyXslts(File srcFile) { - Document doc = null; - + Document doc; File inFile = srcFile; File outFile = null; diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java index 3ea092d47..fdae95d11 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java @@ -91,7 +91,7 @@ public class SdncUebConfiguration implements IConfiguration{ } public void init() throws IOException { - String propPath = null; + String propPath; String propDir = System.getenv(SDNC_CONFIG_DIR); if (propDir == null) { -- cgit 1.2.3-korg From 7359cb451fbc44afaf06be1754b10740e034472e Mon Sep 17 00:00:00 2001 From: "ramu.n" Date: Wed, 20 Sep 2017 17:14:38 +0530 Subject: Some minor refinements in CCSDK SLI Northbound Fix few Critical/Major sonar issues in CCSDK SLI Northbound module * Remove useless parentheses * Remove useless assignment to local variable * Use built-in logger method string formatting instead of string concatination * code indentation * Replace for loop with foreach Change-Id: I9a2e3345f23feb2d96045ac714d8acc528de464b Issue-Id: CCSDK-67 Signed-off-by: Ramu N --- .../sli/northbound/uebclient/SdncUebCallback.java | 162 +++++++++------------ .../sli/northbound/uebclient/SdncUebClient.java | 19 +-- .../northbound/uebclient/SdncUebConfiguration.java | 22 +-- 3 files changed, 90 insertions(+), 113 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index e7a42bcb8..8c59e0399 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -8,9 +8,9 @@ * 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. @@ -189,10 +189,9 @@ public class SdncUebCallback implements INotificationCallback { private static void setJdbcDataSource() throws IOException { - String propPath = null; + String propPath; String propDir = System.getenv(SDNC_CONFIG_DIR); if (propDir == null) { - propDir = "/opt/sdnc/data/properties"; } propPath = propDir + "/dblib.properties"; @@ -209,8 +208,8 @@ public class SdncUebCallback implements INotificationCallback { props.load(new FileInputStream(propFile)); jdbcDataSource = new DBResourceManager(props); - - if(((DBResourceManager)jdbcDataSource).isActive()){ + + if(jdbcDataSource.isActive()){ LOG.warn( "DBLIB: JDBC DataSource has been initialized."); } else { LOG.warn( "DBLIB: JDBC DataSource did not initialize successfully."); @@ -239,15 +238,6 @@ public class SdncUebCallback implements INotificationCallback { File incomingDir = null; File archiveDir = null; - if (!incomingDir.exists()) { - incomingDir.mkdirs(); - } - - - if (!archiveDir.exists()) { - archiveDir.mkdirs(); - } - // Process service level artifacts List artifactList = data.getServiceArtifacts(); @@ -280,12 +270,14 @@ public class SdncUebCallback implements INotificationCallback { if (artifactList != null) { - incomingDir = new File(incomingDirName + "/" + escapeFilename(data.getServiceName()) + "/" + escapeFilename(curResource.getResourceName())); + incomingDir = new File(incomingDirName + "/" + escapeFilename(data.getServiceName()) + "/" + + escapeFilename(curResource.getResourceName())); if (!incomingDir.exists()) { incomingDir.mkdirs(); } - archiveDir = new File(archiveDirName + "/" + escapeFilename(data.getServiceName()) + "/" + escapeFilename(curResource.getResourceName())); + archiveDir = new File(archiveDirName + "/" + escapeFilename(data.getServiceName()) + "/" + + escapeFilename(curResource.getResourceName())); if (!archiveDir.exists()) { archiveDir.mkdirs(); } @@ -300,8 +292,6 @@ public class SdncUebCallback implements INotificationCallback { } deployDownloadedFiles(incomingDir, archiveDir, data); - - } @@ -333,7 +323,7 @@ public class SdncUebCallback implements INotificationCallback { } catch (Exception x) { // IOException can never be thrown by the iteration. // In this snippet, it can only be thrown by newDirectoryStream. - LOG.warn("Cannot process spool file "+ curFileName, x); + LOG.warn("Cannot process spool file {}", curFileName, x); } // Deploy scheduled deployments @@ -375,11 +365,11 @@ public class SdncUebCallback implements INotificationCallback { } } - private void handleArtifact(INotificationData data, String svcName, String resourceName, String resourceType, IArtifactInfo artifact, File incomingDir, File archiveDir) { + private void handleArtifact(INotificationData data, String svcName, String resourceName, String resourceType, + IArtifactInfo artifact, File incomingDir, File archiveDir) { // Download Artifact - IDistributionClientDownloadResult downloadResult = client - .download(artifact); + IDistributionClientDownloadResult downloadResult = client.download(artifact); if (downloadResult == null) { @@ -412,8 +402,6 @@ public class SdncUebCallback implements INotificationCallback { if (writeSucceeded && (downloadResult.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS)) { handleSuccessfulDownload(data, svcName, resourceName, artifact, spoolFile, archiveDir); - - } else { handleFailedDownload(data, artifact); } @@ -495,15 +483,13 @@ public class SdncUebCallback implements INotificationCallback { try { - DocumentBuilderFactory dbf = DocumentBuilderFactory - .newInstance(); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); spoolDoc = db.parse(transformedFile); } catch (Exception e) { - LOG.error( - "Caught exception trying to parse transformed XML file " - + transformedFile.getAbsolutePath(), e); + LOG.error("Caught exception trying to parse transformed XML file {}", + transformedFile.getAbsolutePath(), e); } } catch (Exception e) { @@ -514,8 +500,7 @@ public class SdncUebCallback implements INotificationCallback { if (spoolDoc != null) { // Analyze file type - SdncArtifactType artifactType = analyzeFileType(artifactEnum, - spoolFile, spoolDoc); + SdncArtifactType artifactType = analyzeFileType(artifactEnum, spoolFile, spoolDoc); if (artifactType != null) { @@ -541,14 +526,14 @@ public class SdncUebCallback implements INotificationCallback { private void processToscaYaml(INotificationData data, String svcName, String resourceName, IArtifactInfo artifact, File spoolFile, File archiveDir) { - + // Use ASDC Dist Client 1.1.5 with TOSCA parsing APIs to extract relevant TOSCA model data - + // TOSCA data extraction flow 1707: // Use ASDC dist-client to get yaml string - not yet available String model_yaml = null; LOG.info("Process TOSCA YAML file: "+spoolFile.toString()); - + SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); ISdcCsarHelper sdcCsarHelper = null; try { @@ -573,7 +558,7 @@ public class SdncUebCallback implements INotificationCallback { LOG.error("Could not insert Tosca YAML data into the SERVICE_MODEL table ", e); factory.close(); return; - } + } // Ingest Network (VL) Data - 1707 //List vlNodeTemplatesList = sdcCsarHelper.getServiceNodeTemplatesByType("VL"); @@ -583,7 +568,7 @@ public class SdncUebCallback implements INotificationCallback { SdncNodeModel nodeModel = new SdncNodeModel (sdcCsarHelper, nodeTemplate); nodeModel.setServiceUUID(serviceModel.getServiceUUID()); nodeModel.setEcompGeneratedNaming(SdncBaseModel.extractBooleanInputDefaultValue(sdcCsarHelper, SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_ECOMPGENERATEDNAMING));//service_naming#default#ecomp_generated_naming - + try { cleanUpExistingToscaData("NETWORK_MODEL", "customization_uuid", nodeModel.getCustomizationUUID()); cleanUpExistingToscaData("VPN_BINDINGS", "network_customization_uuid", nodeModel.getCustomizationUUID()); @@ -595,13 +580,13 @@ public class SdncUebCallback implements INotificationCallback { LOG.error("Could not insert Tosca YAML data into the NETWORK_MODEL table ", e); } } - + // Ingest Allotted Resource Data - 1707 List arNodeTemplatesList = sdcCsarHelper.getAllottedResources(); for (NodeTemplate nodeTemplate : arNodeTemplatesList) { SdncARModel nodeModel = new SdncARModel (sdcCsarHelper, nodeTemplate); - + try { cleanUpExistingToscaData("ALLOTTED_RESOURCE_MODEL", "customization_uuid", nodeModel.getCustomizationUUID()); LOG.info("Call insertToscaData for ALLOTTED_RESOURCE_MODEL customizationUUID = " + nodeModel.getCustomizationUUID()); @@ -611,14 +596,14 @@ public class SdncUebCallback implements INotificationCallback { LOG.error("Could not insert Tosca YAML data into the NETWORK_MODEL table ", e); } } - + // Ingest Network (VF) Data - 1707 //List nodeTemplatesList = sdcCsarHelper.getServiceNodeTemplatesByType("VF"); List vfNodeTemplatesList = sdcCsarHelper.getServiceVfList(); for (NodeTemplate nodeTemplate : vfNodeTemplatesList) { SdncVFModel vfNodeModel = new SdncVFModel (sdcCsarHelper, nodeTemplate); - + try { cleanUpExistingToscaData("VF_MODEL", "customization_uuid", vfNodeModel.getCustomizationUUID()) ; LOG.info("Call insertToscaData for VF_MODEL customizationUUID = " + vfNodeModel.getCustomizationUUID()); @@ -626,12 +611,12 @@ public class SdncUebCallback implements INotificationCallback { } catch (IOException e) { LOG.error("Could not insert Tosca YAML data into the VF_MODEL table ", e); } - + // For each VF, insert VF_MODULE_MODEL data List vfModules = sdcCsarHelper.getVfModulesByVf(vfNodeModel.getCustomizationUUIDNoQuotes()); for (Group group : vfModules){ SdncVFModuleModel vfModuleModel = new SdncVFModuleModel(sdcCsarHelper, group); - + try { cleanUpExistingToscaData("VF_MODULE_MODEL", "customization_uuid", vfModuleModel.getCustomizationUUID()); LOG.info("Call insertToscaData for VF_MODULE_MODEL customizationUUID = " + vfModuleModel.getCustomizationUUID()); @@ -639,19 +624,19 @@ public class SdncUebCallback implements INotificationCallback { } catch (IOException e) { LOG.error("Could not insert Tosca YAML data into the VF_MODULE_MODEL table ", e); } - + // For each VF Module, get the VFC list, insert VF_MODULE_TO_VFC_MAPPING data // List groupMembers = sdcCsarHelper.getMembersOfGroup(group); - old version - // For each vfcNode (group member) in the groupMembers list, extract vm_type and vm_count. + // For each vfcNode (group member) in the groupMembers list, extract vm_type and vm_count. // Insert vf_module.customizationUUID, vfcNode.customizationUUID and vm_type and vm_count into VF_MODULE_TO_VFC_MAPPING List groupMembers = sdcCsarHelper.getMembersOfVfModule(nodeTemplate, group); // not yet available for (NodeTemplate vfcNode : groupMembers){ SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, vfcNode); - + try { cleanUpExistingToscaData("VF_MODULE_TO_VFC_MAPPING", "vf_module_customization_uuid", vfModuleModel.getCustomizationUUID()); LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING customizationUUID = " + vfModuleModel.getCustomizationUUID()); - insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" + + insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" + vfModuleModel.getCustomizationUUID() + ", " + vfcModel.getCustomizationUUID() + ", \"" + vfcModel.getVmType() + "\", \"" + vfcModel.getVmCount() + "\")"); } catch (IOException e) { LOG.error("Could not insert Tosca YAML data into the VF_MODULE_TO_VFC_MAPPING table ", e); @@ -660,12 +645,12 @@ public class SdncUebCallback implements INotificationCallback { } } - + // For each VF, insert VFC_MODEL data List vfcNodes = sdcCsarHelper.getVfcListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()); for (NodeTemplate vfcNode : vfcNodes){ SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, vfcNode); - + try { cleanUpExistingToscaData("VFC_MODEL", "customization_uuid", vfcModel.getCustomizationUUID()); LOG.info("Call insertToscaData for VFC_MODEL customizationUUID = " + vfcModel.getCustomizationUUID()); @@ -675,35 +660,35 @@ public class SdncUebCallback implements INotificationCallback { } } - + // For each VF, insert VF_TO_NETWORK_ROLE_MAPPING data List cpNodes = sdcCsarHelper.getCpListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()); for (NodeTemplate cpNode : cpNodes){ - + // Insert into VF_TO_NETWORK_ROLE_MAPPING vf_customization_uuid and network_role String cpNetworkRole = sdcCsarHelper.getNodeTemplatePropertyLeafValue(cpNode, "network_role_tag"); - + try { cleanUpExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", "vf_customization_uuid", vfNodeModel.getCustomizationUUID()); LOG.info("Call insertToscaData for VF_TO_NETWORK_ROLE_MAPPING vfCustomizationUUID = " + vfNodeModel.getCustomizationUUID()); - insertToscaData("insert into VF_TO_NETWORK_ROLE_MAPPING (vf_customization_uuid, network_role) values (" + + insertToscaData("insert into VF_TO_NETWORK_ROLE_MAPPING (vf_customization_uuid, network_role) values (" + vfNodeModel.getCustomizationUUID() + ", \"" + cpNetworkRole + "\")"); } catch (IOException e) { LOG.error("Could not insert Tosca YAML data into the VF_TO_NETWORK_ROLE_MAPPING table ", e); } - + // Insert VFC_TO_NETWORK_ROLE_MAPPING data Map mappingParams = new HashMap(); //String cpNetworkRoleTag = "\"" + sdcCsarHelper.getNodeTemplatePropertyLeafValue(cpNode, SdcPropertyNames.PROPERTY_NAME_NETWORKROLETAG) + "\""; // extract network_role, network_role_tag and virtual_binding from this cpNode SdncBaseModel.addParameter("network_role", SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "network_role"), mappingParams); SdncBaseModel.addParameter("network_role_tag", SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "network_role_tag"), mappingParams); - String virtualBinding = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "requirements#virtualBinding") + "\""; + String virtualBinding = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "requirements#virtualBinding") + "\""; // get list of cpNodes and vfcNodes with matching virtualBinding - List> matchList = sdcCsarHelper.getNodeTemplatePairsByReqName(sdcCsarHelper.getCpListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()), sdcCsarHelper.getVfcListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()), virtualBinding); + List> matchList = sdcCsarHelper.getNodeTemplatePairsByReqName(sdcCsarHelper.getCpListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()), sdcCsarHelper.getVfcListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()), virtualBinding); for (Pair match : matchList) { // should be 1 match? - + // extract values from the left "CP" Node SdncBaseModel.addParameter("ipv4_use_dhcp", SdncBaseModel.extractBooleanValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_DHCPENABLED), mappingParams); //SdncBaseModel.addParameter("ipv4_ip_version", SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_IPVERSION), mappingParams); @@ -711,14 +696,14 @@ public class SdncUebCallback implements INotificationCallback { SdncBaseModel.addParameter("ipv6_use_dhcp", SdncBaseModel.extractBooleanValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_DHCPENABLED), mappingParams); //SdncBaseModel.addParameter("ipv6_ip_version", SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_IPVERSION), mappingParams); SdncBaseModel.addParameter("ipv6_ip_version", "dummy_ipv6_vers", mappingParams); - //String extcp_subnetpool_id = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_SUBNETPOOLID) + "\""; // need path to subnetpoolid - + //String extcp_subnetpool_id = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_SUBNETPOOLID) + "\""; // need path to subnetpoolid + // extract values from the right "VFC" Node String vfcCustomizationUuid = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, match.getRight().getMetadata(), "customization_uuid") + "\""; SdncBaseModel.addParameter("vm_type", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_VMTYPE), mappingParams); SdncBaseModel.addIntParameter("ipv4_count", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT), mappingParams); SdncBaseModel.addIntParameter("ipv6_count", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT), mappingParams); - + try { cleanUpExistingToscaData("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", vfcCustomizationUuid); LOG.info("Call insertToscaData for VFC_TO_NETWORK_ROLE_MAPPING vfcCustomizationUUID = " + vfcCustomizationUuid); @@ -726,16 +711,16 @@ public class SdncUebCallback implements INotificationCallback { } catch (IOException e) { LOG.error("Could not insert Tosca YAML data into the VFC_TO_NETWORK_ROLE_MAPPING table ", e); } - - } - - } // CP loop - + + } + + } // CP loop + } // VF loop - + // Close ASDC TOSCA Parser factory - we are done processing this distribution factory.close(); - + if ((artifact != null) && (data != null)) { LOG.info("Update to SDN-C succeeded"); IDistributionClientResult deploymentStatus; @@ -743,58 +728,58 @@ public class SdncUebCallback implements INotificationCallback { client, data, artifact, DistributionStatusEnum.DEPLOY_OK)); } - + } - + private void cleanUpExistingToscaData(String tableName, String keyName, String keyValue) throws IOException { - + if (jdbcDataSource == null) { setJdbcDataSource(); } try { int rowCount = 0; CachedRowSet data = jdbcDataSource.getData("SELECT * from " + tableName + " where " + keyName + " = " + keyValue + ";", null, ""); - while(data.next()) { - rowCount ++; + while(data.next()) { + rowCount ++; } if (rowCount != 0) { LOG.info("cleanUpExistingToscaData: " + keyValue); jdbcDataSource.writeData("DELETE from " + tableName + " where " + keyName + " = " + keyValue + ";", null, null); } - - } catch (SQLException e) { + + } catch (SQLException e) { LOG.error("Could not clean up existing " + tableName + " for " + keyValue, e); - } - + } + } - + private void cleanUpExistingToscaServiceData(String serviceUUID) throws IOException { - + if (jdbcDataSource == null) { setJdbcDataSource(); } try { int rowCount = 0; CachedRowSet data = jdbcDataSource.getData("SELECT * from SERVICE_MODEL where service_uuid = " + serviceUUID + ";", null, ""); - while(data.next()) { - rowCount ++; + while(data.next()) { + rowCount ++; } if (rowCount != 0) { LOG.info("cleanUpExistingToscaData: " + serviceUUID); jdbcDataSource.writeData("DELETE from NETWORK_MODEL where service_uuid = " + serviceUUID + ";", null, null); jdbcDataSource.writeData("DELETE from SERVICE_MODEL where service_uuid = " + serviceUUID + ";", null, null); } - - } catch (SQLException e) { + + } catch (SQLException e) { LOG.error("Could not clean up existing NETWORK_MODEL and SERVICE_MODEL for service_UUID " + serviceUUID, e); - } - + } + } - + private void insertToscaData(String toscaDataString) throws IOException { LOG.debug("insertToscaData: " + toscaDataString); @@ -867,11 +852,8 @@ public class SdncUebCallback implements INotificationCallback { Date now = new Date(); String artifactVersion = sdfDate.format(now); LOG.debug("Scheduling "+spoolFileName+" version "+artifactVersion+" for deployment"); - String artifactName = spoolFileName; - if (artifactInfo != null) { - artifactName = artifactInfo.getArtifactName(); - } - deployList[type.getPass()].add(new DeployableArtifact(type, svcName, resourceName, artifactName, artifactVersion, spoolFile)); + deployList[type.getPass()].add(new DeployableArtifact(type, svcName, resourceName, spoolFileName, + artifactVersion, spoolFile)); } } else { LOG.info("Pass for type "+type.getTag()+" is "+type.getPass()+" which is not <= "+deployList.length); diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java index e19646e39..d29890486 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java @@ -8,9 +8,9 @@ * 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. @@ -30,12 +30,10 @@ import org.slf4j.LoggerFactory; public class SdncUebClient { - private static final Logger LOG = LoggerFactory - .getLogger(SdncUebConfiguration.class); + private static final Logger LOG = LoggerFactory.getLogger(SdncUebConfiguration.class); public static void main(String[] args) { - IDistributionClient client = DistributionClientFactory - .createDistributionClient(); + IDistributionClient client = DistributionClientFactory.createDistributionClient(); SdncUebConfiguration config = new SdncUebConfiguration(); @@ -46,17 +44,14 @@ public class SdncUebClient { LOG.info("Initializing ASDC distribution client"); - IDistributionClientResult result = client.init( - config, cb); + IDistributionClientResult result = client.init(config, cb); - LOG.info("Initialized ASDC distribution client - results = " - + result.getDistributionMessageResult()); + LOG.info("Initialized ASDC distribution client - results = {}", result.getDistributionMessageResult()); if (result.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) { LOG.info("Starting client..."); IDistributionClientResult start = client.start(); - LOG.info("Client startup result = " - + start.getDistributionMessageResult()); + LOG.info("Client startup result = {}", start.getDistributionMessageResult()); } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java index 3ea092d47..4d9c82464 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java @@ -8,9 +8,9 @@ * 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. @@ -91,7 +91,7 @@ public class SdncUebConfiguration implements IConfiguration{ } public void init() throws IOException { - String propPath = null; + String propPath; String propDir = System.getenv(SDNC_CONFIG_DIR); if (propDir == null) { @@ -149,18 +149,18 @@ public class SdncUebConfiguration implements IConfiguration{ if ((curval != null) && (curval.length() > 0)) { String[] artifactTypes = curval.split(","); - relevantArtifactTypes = new LinkedList(); + relevantArtifactTypes = new LinkedList<>(); - for (int i = 0 ; i < artifactTypes.length ; i++) { + for (String artifactType : artifactTypes) { try { - if (ArtifactTypeEnum.valueOf(artifactTypes[i]) != null) { - relevantArtifactTypes.add(artifactTypes[i]); + if (ArtifactTypeEnum.valueOf(artifactType) != null) { + relevantArtifactTypes.add(artifactType); } else { - LOG.warn("Skipping unrecognized artifact type "+artifactTypes[i]); + LOG.warn("Skipping unrecognized artifact type {}", artifactType); } } catch (Exception e) { - LOG.warn("Caught exception validating artifact type "+artifactTypes[i], e); + LOG.warn("Caught exception validating artifact type {}", artifactType, e); } } @@ -263,11 +263,11 @@ public class SdncUebConfiguration implements IConfiguration{ } public int getMaxPasses() { - return(artifactMap.getNumPasses()); + return artifactMap.getNumPasses(); } public SdncArtifactMap.SdncArtifactType getMapping(String tag) { - return(artifactMap.getMapping(tag)); + return artifactMap.getMapping(tag); } @Override -- cgit 1.2.3-korg From 862cac3e7b7b7bd835439d3a905d9c241a7ae742 Mon Sep 17 00:00:00 2001 From: surya-huawei Date: Fri, 22 Sep 2017 16:50:44 +0530 Subject: Remove unnecessary constructs *Remove unused imports *Remove useless paranthesis This is done as sometimes they can be misleading *Replace type specification with diamond operator(<>) This is done to reduce verbosity of generics code Issue-Id: CCSDK-87 Change-Id: Ic356859939fe40cecec2e65c96d79cd6a655787e Signed-off-by: surya-huawei --- .../org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java index 9b36cb6b3..3605465d4 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java @@ -24,7 +24,6 @@ package org.onap.ccsdk.sli.northbound.uebclient; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; -import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -57,7 +56,7 @@ public class SdncArtifactMap { } public String getRpcUrl(String base) { - return(base+rpc); + return base+rpc; } private SdncArtifactType(String tag, String rpc, String pass) { @@ -73,7 +72,7 @@ public class SdncArtifactMap { - private Map mapItems = new HashMap(); + private Map mapItems = new HashMap<>(); private int NumPasses = 1; @@ -110,9 +109,9 @@ public class SdncArtifactMap { public SdncArtifactType getMapping(String tag) { if (mapItems.containsKey(tag)) { - return(mapItems.get(tag)); + return mapItems.get(tag); } else { - return(null); + return null; } } -- cgit 1.2.3-korg From e5a46e5667e52c8bd8ceb4f322ff4d300223267c Mon Sep 17 00:00:00 2001 From: surya-huawei Date: Mon, 25 Sep 2017 17:31:57 +0530 Subject: Fix some sonar issues in sli/northbound *Replace type specification with diamond operator This is done to reduce the verbosity of generics code *Replace ("") with ('') in String.lastIndexOf() This is more efficient for single character *Remove temp variable which is immediately returned New variable is not necessary as the caller cannot see this Issue-Id: CCSDK-87 Change-Id: I353652de723a624935d819b2bc817b4907af98ed Signed-off-by: surya-huawei --- .../onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index 0664e8283..5d83c5d16 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -332,7 +332,7 @@ public class SdncUebCallback implements INotificationCallback { deployList = new LinkedList[numPasses]; for (int i = 0 ; i < numPasses ; i++) { - deployList[i] = new LinkedList(); + deployList[i] = new LinkedList<>(); } for (int pass = 0 ; pass < config.getMaxPasses() ; pass++) { @@ -450,7 +450,7 @@ public class SdncUebCallback implements INotificationCallback { } - if (toscaYamlType == true) { + if (toscaYamlType) { processToscaYaml (data, svcName, resourceName, artifact, spoolFile, archiveDir); try { @@ -547,7 +547,8 @@ public class SdncUebCallback implements INotificationCallback { // Ingest Service Data - 1707 Metadata serviceMetadata = sdcCsarHelper.getServiceMetadata(); SdncServiceModel serviceModel = new SdncServiceModel(sdcCsarHelper, serviceMetadata); - serviceModel.setFilename(spoolFile.toString().substring(spoolFile.toString().lastIndexOf("/")+1)); // will be csar file name + serviceModel.setFilename(spoolFile.toString().substring(spoolFile + .toString().lastIndexOf('/')+1)); // will be csar file name serviceModel.setServiceInstanceNamePrefix(SdncBaseModel.extractSubstitutionMappingTypeName(sdcCsarHelper).substring(SdncBaseModel.extractSubstitutionMappingTypeName(sdcCsarHelper).lastIndexOf(".")+1)); try { @@ -678,7 +679,7 @@ public class SdncUebCallback implements INotificationCallback { } // Insert VFC_TO_NETWORK_ROLE_MAPPING data - Map mappingParams = new HashMap(); + Map mappingParams = new HashMap<>(); //String cpNetworkRoleTag = "\"" + sdcCsarHelper.getNodeTemplatePropertyLeafValue(cpNode, SdcPropertyNames.PROPERTY_NAME_NETWORKROLETAG) + "\""; // extract network_role, network_role_tag and virtual_binding from this cpNode SdncBaseModel.addParameter("network_role", SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "network_role"), mappingParams); @@ -963,8 +964,7 @@ public class SdncUebCallback implements INotificationCallback { @Override public long getTimestamp() { - long currentTimeMillis = System.currentTimeMillis(); - return currentTimeMillis; + return System.currentTimeMillis(); } @Override -- cgit 1.2.3-korg From b720f1b77fe2c96e2afb1bafed5b02724ab50e37 Mon Sep 17 00:00:00 2001 From: shashikanth Date: Tue, 26 Sep 2017 14:56:41 +0530 Subject: Deleted redundant try catch block Extract this nested try block into a separate method. https://sonar.onap.org/component_issues?id=org.onap.ccsdk.sli.northbound%3Accsdk-sli-northbound#resolved=false|severities=MAJOR|rules=squid%3AS1141 Issue-Id: CCSDK-87 Change-Id: I989791d876b5a199f75983ba5137770f80995ef1 Signed-off-by: shashikanth.vh --- .../ccsdk/sli/northbound/uebclient/SdncUebCallback.java | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index 0664e8283..9723ed4d5 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -480,20 +480,13 @@ public class SdncUebCallback implements INotificationCallback { if (transformedFile != null) { try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); - try { - - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); - - spoolDoc = db.parse(transformedFile); - } catch (Exception e) { - LOG.error("Caught exception trying to parse transformed XML file {}", - transformedFile.getAbsolutePath(), e); - } - + spoolDoc = db.parse(transformedFile); } catch (Exception e) { - LOG.error("Caught exception trying to deploy file", e); + LOG.error("Caught exception trying to parse transformed XML file {}", + transformedFile.getAbsolutePath(), e); } } -- cgit 1.2.3-korg From 119808a2ded9ea8c4dd9d1eef96f39ab2e001ff7 Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Tue, 3 Oct 2017 04:04:30 -0400 Subject: Add unit test for ueb-listener Add unit test case for ueb-listener. Change-Id: Ia61f8e5bc0e817aa0f4a042d8e05b02ec9e2013b Issue-ID: CCSDK-106 Signed-off-by: Dan Timoney --- ueb-listener/pom.xml | 12 +++++++++ .../sli/northbound/uebclient/SdncUebCallback.java | 4 +++ .../northbound/uebclient/SdncUebConfiguration.java | 22 +++++++++++----- .../northbound/uebclient/TestSdncUebCallback.java | 30 ++++++++++++++++++++++ .../src/test/resources/ueb-listener.properties | 19 ++++++++++++++ 5 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java create mode 100755 ueb-listener/src/test/resources/ueb-listener.properties (limited to 'ueb-listener/src') diff --git a/ueb-listener/pom.xml b/ueb-listener/pom.xml index 84e407698..c00395d6e 100755 --- a/ueb-listener/pom.xml +++ b/ueb-listener/pom.xml @@ -63,6 +63,18 @@ ${junit.version} test + + org.testng + testng + 6.11 + test + + + org.mockito + mockito-core + ${mockito.version} + test + org.onap.ccsdk.sli.core dblib-provider diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index f25ce1458..f00d73724 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -1073,6 +1073,10 @@ public class SdncUebCallback implements INotificationCallback { } private String escapeFilename(String str) { + + if (str == null) { + str = ""; + } StringBuffer retval = new StringBuffer(); for (int i = 0 ; i < str.length() ; i++) { diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java index 4d9c82464..d97abacbd 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java @@ -82,21 +82,31 @@ public class SdncUebConfiguration implements IConfiguration{ } public SdncUebConfiguration() { + String propDir = System.getenv(SDNC_CONFIG_DIR); + if (propDir == null) { + + propDir = "/opt/sdnc/data/properties"; + } + try { + init(propDir); + } catch (Exception e) { + LOG.error("Cannot initialize SdncUebConfiguration", e); + } + } + public SdncUebConfiguration(String propDir) { try { - init(); + init(propDir); } catch (Exception e) { LOG.error("Cannot initialize SdncUebConfiguration", e); } } - public void init() throws IOException { + + public void init(String propDir) throws IOException { String propPath; - String propDir = System.getenv(SDNC_CONFIG_DIR); - if (propDir == null) { - propDir = "/opt/sdnc/data/properties"; - } + propPath = propDir + "/ueb-listener.properties"; File propFile = new File(propPath); diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java new file mode 100644 index 000000000..93fadc989 --- /dev/null +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java @@ -0,0 +1,30 @@ +package org.onap.ccsdk.sli.northbound.uebclient; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.openecomp.sdc.api.IDistributionClient; +import org.openecomp.sdc.api.notification.INotificationData; + +import static org.mockito.Mockito.mock; + +public class TestSdncUebCallback { + SdncUebConfiguration config; + + @Before + public void setUp() throws Exception { + config = new SdncUebConfiguration("src/test/resources"); + } + + @Test + public void test() { + + IDistributionClient iDistClient = mock(IDistributionClient.class); + SdncUebCallback cb = new SdncUebCallback(iDistClient, config); + + INotificationData iData = mock(INotificationData.class); + cb.activateCallback(iData); + } + +} diff --git a/ueb-listener/src/test/resources/ueb-listener.properties b/ueb-listener/src/test/resources/ueb-listener.properties new file mode 100755 index 000000000..7855b2116 --- /dev/null +++ b/ueb-listener/src/test/resources/ueb-listener.properties @@ -0,0 +1,19 @@ +org.openecomp.sdnc.uebclient.asdc-address=localhost:1234 +org.openecomp.sdnc.uebclient.consumer-group=ccsdk1 +org.openecomp.sdnc.uebclient.consumer-id=localhost_ccsdk1 +org.openecomp.sdnc.uebclient.environment-name=UNITTEST +org.openecomp.sdnc.uebclient.password=123456 +org.openecomp.sdnc.uebclient.user=test +org.openecomp.sdnc.uebclient.sdnc-user=test +org.openecomp.sdnc.uebclient.sdnc-passwd=test +org.openecomp.sdnc.uebclient.asdc-api-base-url=http://localhost:8282/restconf/operations/ +org.openecomp.sdnc.uebclient.asdc-api-namespace=org:onap:ccsdk +org.openecomp.sdnc.uebclient.spool.incoming=src/test/resources/incoming +org.openecomp.sdnc.uebclient.spool.archive=src/test/resources/archive +org.openecomp.sdnc.uebclient.polling-interval=30 +org.openecomp.sdnc.uebclient.polling-timeout=15 +org.openecomp.sdnc.uebclient.relevant-artifact-types=YANG_XML,VF_LICENSE,TOSCA_TEMPLATE,TOSCA_CSAR,UCPE_LAYER_2_CONFIGURATION +org.openecomp.sdnc.uebclient.activate-server-tls-auth=false +org.openecomp.sdnc.uebclient.keystore-path= +org.openecomp.sdnc.uebclient.keystore-password= +org.openecomp.sdnc.uebclient.xslt-path-list=src/main/resources/removeNs.xslt,src/main/resources/normalizeTagNames.xslt -- cgit 1.2.3-korg From fa9d764ef796f450f5f031a8c2a43ee60ab8b829 Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Tue, 3 Oct 2017 14:30:51 -0400 Subject: Add ueb-listener unit test Enhance ueb-listener unit test to verify TOSCA parse Change-Id: Iedc675ead3ef69e4fa7151c8c4c500990c0ee6a7 Issue-ID: CCSDK-106 Signed-off-by: Dan Timoney --- .../sli/northbound/asdcapi/TestAsdcApiApi.java | 107 +++++++++++++++++++++ .../sdnc/northbound/asdcapi/TestAsdcApiApi.java | 107 --------------------- ueb-listener/pom.xml | 9 +- .../sli/northbound/uebclient/SdncARModel.java | 14 +-- .../sli/northbound/uebclient/SdncBaseModel.java | 60 ++++++------ .../sli/northbound/uebclient/SdncServiceModel.java | 2 +- .../sli/northbound/uebclient/SdncUebCallback.java | 15 +-- .../northbound/uebclient/SdncUebConfiguration.java | 17 ++-- .../sli/northbound/uebclient/SdncVFModel.java | 16 +-- .../northbound/uebclient/TestSdncUebCallback.java | 35 ++++++- ...t_resources_csars_service-NfodService-csar.csar | Bin 0 -> 38938 bytes ueb-listener/src/test/resources/log4j.properties | 30 ++++++ .../src/test/resources/ueb-listener.properties | 38 ++++---- 13 files changed, 257 insertions(+), 193 deletions(-) create mode 100644 asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/TestAsdcApiApi.java delete mode 100644 asdcApi/provider/src/test/java/org/onap/sdnc/northbound/asdcapi/TestAsdcApiApi.java create mode 100644 ueb-listener/src/test/resources/incoming/src_test_resources_csars_service-NfodService-csar.csar create mode 100644 ueb-listener/src/test/resources/log4j.properties (limited to 'ueb-listener/src') diff --git a/asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/TestAsdcApiApi.java b/asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/TestAsdcApiApi.java new file mode 100644 index 000000000..f65bbc045 --- /dev/null +++ b/asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/TestAsdcApiApi.java @@ -0,0 +1,107 @@ +/*- + * ============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.asdcapi; + +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.northbound.asdcapi.AsdcApiProvider; +import org.onap.ccsdk.sli.northbound.asdcapi.AsdcApiSliClient; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest; +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.VfLicenseModelUpdateInputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.VfLicenseModelUpdateOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; + +public class TestAsdcApiApi extends AbstractConcurrentDataBrokerTest { + + private AsdcApiProvider asdcApiProvider; + private static final Logger LOG = LoggerFactory.getLogger(AsdcApiProvider.class); + + @Before + public void setUp() throws Exception { + if (null == asdcApiProvider) { + DataBroker dataBroker = getDataBroker(); + NotificationPublishService mockNotification = mock(NotificationPublishService.class); + RpcProviderRegistry mockRpcRegistry = mock(RpcProviderRegistry.class); + AsdcApiSliClient mockSliClient = mock(AsdcApiSliClient.class); + asdcApiProvider = new AsdcApiProvider(dataBroker, mockNotification, mockRpcRegistry, mockSliClient); + } + } + + //Testcase should return error 503 when No service logic active for ASDC-API. + @Test + public void testVfLicenseModelUpdate() { + + VfLicenseModelUpdateInputBuilder inputBuilder = new VfLicenseModelUpdateInputBuilder(); + + inputBuilder.setArtifactName("abc"); + inputBuilder.setArtifactVersion("1"); + + // TODO: currently initialize SvcLogicServiceClient is failing, need to fix + java.util.concurrent.Future> future = asdcApiProvider + .vfLicenseModelUpdate(inputBuilder.build()); + RpcResult rpcResult = null; + try { + rpcResult = future.get(); + } catch (Exception e) { + fail("Error : " + e); + } + LOG.info("result: {}", rpcResult); + assertEquals("503", rpcResult.getResult().getAsdcApiResponseCode()); + } + + //Input parameter validation + @Test + public void testVfLicenseModelUpdateInputValidation() { + + VfLicenseModelUpdateInputBuilder inputBuilder = new VfLicenseModelUpdateInputBuilder(); + + inputBuilder.setArtifactName("abc"); + inputBuilder.setArtifactVersion("1"); + + java.util.concurrent.Future> future = asdcApiProvider + .vfLicenseModelUpdate(null); + assertNull(future); + } + + @Test(expected = IllegalArgumentException.class) + public void testVfLicenseModelUpdateValidation1() { + + VfLicenseModelUpdateInputBuilder inputBuilder = new VfLicenseModelUpdateInputBuilder(); + + java.util.concurrent.Future> future = asdcApiProvider + .vfLicenseModelUpdate(inputBuilder.build()); + RpcResult rpcResult = null; + try { + rpcResult = future.get(); + } catch (Exception e) { + fail("Error : " + e); + } + } +} diff --git a/asdcApi/provider/src/test/java/org/onap/sdnc/northbound/asdcapi/TestAsdcApiApi.java b/asdcApi/provider/src/test/java/org/onap/sdnc/northbound/asdcapi/TestAsdcApiApi.java deleted file mode 100644 index c78abc8f7..000000000 --- a/asdcApi/provider/src/test/java/org/onap/sdnc/northbound/asdcapi/TestAsdcApiApi.java +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * ============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.sdnc.northbound.asdcapi; - -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.sli.northbound.asdcapi.AsdcApiProvider; -import org.onap.ccsdk.sli.northbound.asdcapi.AsdcApiSliClient; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; -import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest; -import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.VfLicenseModelUpdateInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev170201.VfLicenseModelUpdateOutput; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.mock; - -public class TestAsdcApiApi extends AbstractConcurrentDataBrokerTest { - - private AsdcApiProvider asdcApiProvider; - private static final Logger LOG = LoggerFactory.getLogger(AsdcApiProvider.class); - - @Before - public void setUp() throws Exception { - if (null == asdcApiProvider) { - DataBroker dataBroker = getDataBroker(); - NotificationPublishService mockNotification = mock(NotificationPublishService.class); - RpcProviderRegistry mockRpcRegistry = mock(RpcProviderRegistry.class); - AsdcApiSliClient mockSliClient = mock(AsdcApiSliClient.class); - asdcApiProvider = new AsdcApiProvider(dataBroker, mockNotification, mockRpcRegistry, mockSliClient); - } - } - - //Testcase should return error 503 when No service logic active for ASDC-API. - @Test - public void testVfLicenseModelUpdate() { - - VfLicenseModelUpdateInputBuilder inputBuilder = new VfLicenseModelUpdateInputBuilder(); - - inputBuilder.setArtifactName("abc"); - inputBuilder.setArtifactVersion("1"); - - // TODO: currently initialize SvcLogicServiceClient is failing, need to fix - java.util.concurrent.Future> future = asdcApiProvider - .vfLicenseModelUpdate(inputBuilder.build()); - RpcResult rpcResult = null; - try { - rpcResult = future.get(); - } catch (Exception e) { - fail("Error : " + e); - } - LOG.info("result: {}", rpcResult); - assertEquals("503", rpcResult.getResult().getAsdcApiResponseCode()); - } - - //Input parameter validation - @Test - public void testVfLicenseModelUpdateInputValidation() { - - VfLicenseModelUpdateInputBuilder inputBuilder = new VfLicenseModelUpdateInputBuilder(); - - inputBuilder.setArtifactName("abc"); - inputBuilder.setArtifactVersion("1"); - - java.util.concurrent.Future> future = asdcApiProvider - .vfLicenseModelUpdate(null); - assertNull(future); - } - - @Test(expected = IllegalArgumentException.class) - public void testVfLicenseModelUpdateValidation1() { - - VfLicenseModelUpdateInputBuilder inputBuilder = new VfLicenseModelUpdateInputBuilder(); - - java.util.concurrent.Future> future = asdcApiProvider - .vfLicenseModelUpdate(inputBuilder.build()); - RpcResult rpcResult = null; - try { - rpcResult = future.get(); - } catch (Exception e) { - fail("Error : " + e); - } - } -} diff --git a/ueb-listener/pom.xml b/ueb-listener/pom.xml index c00395d6e..68d8fc080 100755 --- a/ueb-listener/pom.xml +++ b/ueb-listener/pom.xml @@ -14,7 +14,8 @@ 0.1.0-SNAPSHOT - 1.1.7-SNAPSHOT + 1.1.32-SNAPSHOT + 1.1.34-SNAPSHOT 2.9.0.pr1 true /opt/app/ueb-listener @@ -31,6 +32,12 @@ ${sdc.client.version} compile + + org.openecomp.sdc.sdc-tosca + sdc-tosca + ${sdc.tosca.version} + compile + org.slf4j slf4j-api diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java index 75b19cd2e..8d480a4d1 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java @@ -8,9 +8,9 @@ * 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. @@ -23,24 +23,24 @@ 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.Metadata; import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.openecomp.sdc.toscaparser.api.elements.Metadata; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SdncARModel extends SdncBaseModel { - + private static final Logger LOG = LoggerFactory .getLogger(SdncARModel.class); public SdncARModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { super(sdcCsarHelper, nodeTemplate); - + // extract metadata - Metadata metadata = nodeTemplate.getMetadata(); + Metadata metadata = nodeTemplate.getMetaData(); addParameter("type", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_TYPE)); - + // extract properties //addParameter("role", extractValue (sdcCsarHelper, nodeTemplate, SdcPropertyNames.PROPERTY_NAME_ROLE)); //addParameter("type", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_TYPE)); - wrong location, get from metadata diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index 32e51599e..6128f288b 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -8,9 +8,9 @@ * 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. @@ -27,33 +27,33 @@ import java.util.Map; import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames; import org.openecomp.sdc.toscaparser.api.Group; -import org.openecomp.sdc.toscaparser.api.Metadata; import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.openecomp.sdc.toscaparser.api.elements.Metadata; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SdncBaseModel { - + private static final Logger LOG = LoggerFactory .getLogger(SdncBaseModel.class); - + protected String customizationUUID = null; protected String invariantUUID = null; - protected String model_yaml = null; - protected String version = null; - + protected String model_yaml = null; + protected String version = null; + protected Map params = null; protected ISdcCsarHelper sdcCsarHelper = null; public SdncBaseModel() { - + } - + public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata) { params = new HashMap<>(); this.sdcCsarHelper = sdcCsarHelper; - + // extract service metadata invariantUUID = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID); addParameter("invariant_uuid",invariantUUID); @@ -70,11 +70,11 @@ public class SdncBaseModel { this.sdcCsarHelper = sdcCsarHelper; // extract nodeTemplate metadata - Metadata metadata = nodeTemplate.getMetadata(); + Metadata metadata = nodeTemplate.getMetaData(); customizationUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); addParameter("invariant_uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); addParameter("uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_UUID)); - addParameter("version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VERSION)); + addParameter("version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VERSION)); } public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Group group) { @@ -86,9 +86,9 @@ public class SdncBaseModel { Metadata metadata = group.getMetadata(); //customizationUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULECUSTOMIZATIONUUID); - returning null customizationUUID = extractValue (metadata, "vfModuleModelCustomizationUUID"); - addParameter("invariant_uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)); - addParameter("uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)); - addParameter("version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)); + addParameter("invariant_uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)); + addParameter("uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)); + addParameter("version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)); } protected void addParameter (String name, String value) { @@ -102,26 +102,26 @@ public class SdncBaseModel { params.put(name, value); } } - + public static void addIntParameter (String name, String value, Map params) { if (value != null && !value.isEmpty()) { params.put(name, value); } } - + public static void addParameter (String name, String value, Map params) { if (value != null && !value.isEmpty()) { params.put(name, "\"" + value + "\""); } } - + protected String extractValue (Metadata metadata, String name) { String value = sdcCsarHelper.getMetadataPropertyValue(metadata, name); if (value != null) { return value; } else { return ""; - } + } } public static String extractValue (ISdcCsarHelper sdcCsarHelper, Metadata metadata, String name) { @@ -130,7 +130,7 @@ public class SdncBaseModel { return value; } else { return ""; - } + } } protected String extractValue (NodeTemplate nodeTemplate, String name) { @@ -241,19 +241,19 @@ public class SdncBaseModel { public void setCustomizationUUID(String customizationUUID) { this.customizationUUID = customizationUUID; } - + public String getSql(String tableName, String model_yaml) { - + StringBuilder sb = new StringBuilder(); sb.append("INSERT into " + tableName + " (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 (" + getCustomizationUUID() + ", \"" + model_yaml + "\", "); paramCount = 0; @@ -267,19 +267,19 @@ public class SdncBaseModel { sb.append(");"); return sb.toString(); } - + public static String getSql(String tableName, String keyName, String keyValue, String model_yaml, Map params) { - + StringBuilder sb = new StringBuilder(); sb.append("INSERT into " + tableName + " (" + keyName + ", "); - + int paramCount = 0; for (String paramKey : params.keySet()) { paramCount++; sb.append(paramKey); if (paramCount < params.size()) sb.append(", "); } - + sb.append(") values (" + keyValue + ", "); paramCount = 0; @@ -293,5 +293,5 @@ public class SdncBaseModel { sb.append(");"); return sb.toString(); } - + } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java index 3df27be6e..d3fd16791 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java @@ -23,7 +23,7 @@ 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.Metadata; +import org.openecomp.sdc.toscaparser.api.elements.Metadata; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index f00d73724..b3c96d9d8 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -74,8 +74,8 @@ import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames; import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory; import org.openecomp.sdc.toscaparser.api.Group; -import org.openecomp.sdc.toscaparser.api.Metadata; import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.openecomp.sdc.toscaparser.api.elements.Metadata; import org.openecomp.sdc.utils.ArtifactTypeEnum; import org.openecomp.sdc.utils.DistributionActionResultEnum; import org.openecomp.sdc.utils.DistributionStatusEnum; @@ -238,6 +238,8 @@ public class SdncUebCallback implements INotificationCallback { File incomingDir = null; File archiveDir = null; + LOG.debug("IncomingDirName is {}", incomingDirName); + // Process service level artifacts List artifactList = data.getServiceArtifacts(); @@ -298,12 +300,15 @@ public class SdncUebCallback implements INotificationCallback { public void deployDownloadedFiles(File incomingDir, File archiveDir, INotificationData data) { if (incomingDir == null) { + LOG.debug("incomingDir is null - using {}", config.getIncomingDir()); incomingDir = new File(config.getIncomingDir()); if (!incomingDir.exists()) { incomingDir.mkdirs(); } + } else { + LOG.debug("incomingDir is not null - it is {}", incomingDir.getPath()); } if (archiveDir == null) { @@ -315,6 +320,7 @@ public class SdncUebCallback implements INotificationCallback { } String curFileName = ""; + LOG.debug("Scanning {} - {} for downloaded files", incomingDir.getPath(), incomingDir.toPath()); try (DirectoryStream stream = Files.newDirectoryStream(incomingDir.toPath())) { for (Path file: stream) { curFileName = file.toString(); @@ -533,7 +539,6 @@ public class SdncUebCallback implements INotificationCallback { sdcCsarHelper = factory.getSdcCsarHelper(spoolFile.getAbsolutePath()); } catch (SdcToscaParserException e) { LOG.error("Could not create SDC TOSCA Parser ", e); - factory.close(); return; } @@ -550,7 +555,6 @@ public class SdncUebCallback implements INotificationCallback { insertToscaData(serviceModel.getSql(model_yaml)); } catch (IOException e) { LOG.error("Could not insert Tosca YAML data into the SERVICE_MODEL table ", e); - factory.close(); return; } @@ -693,7 +697,7 @@ public class SdncUebCallback implements INotificationCallback { //String extcp_subnetpool_id = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_SUBNETPOOLID) + "\""; // need path to subnetpoolid // extract values from the right "VFC" Node - String vfcCustomizationUuid = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, match.getRight().getMetadata(), "customization_uuid") + "\""; + String vfcCustomizationUuid = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, match.getRight().getMetaData(), "customization_uuid") + "\""; SdncBaseModel.addParameter("vm_type", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_VMTYPE), mappingParams); SdncBaseModel.addIntParameter("ipv4_count", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT), mappingParams); SdncBaseModel.addIntParameter("ipv6_count", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT), mappingParams); @@ -712,8 +716,7 @@ public class SdncUebCallback implements INotificationCallback { } // VF loop - // Close ASDC TOSCA Parser factory - we are done processing this distribution - factory.close(); + if ((artifact != null) && (data != null)) { LOG.info("Update to SDN-C succeeded"); diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java index d97abacbd..b49a66070 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java @@ -30,7 +30,6 @@ import java.util.List; import java.util.Properties; import org.openecomp.sdc.api.consumer.IConfiguration; -import org.openecomp.sdc.utils.ArtifactTypeEnum; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -162,16 +161,8 @@ public class SdncUebConfiguration implements IConfiguration{ relevantArtifactTypes = new LinkedList<>(); for (String artifactType : artifactTypes) { - try { - if (ArtifactTypeEnum.valueOf(artifactType) != null) { - relevantArtifactTypes.add(artifactType); - } else { - LOG.warn("Skipping unrecognized artifact type {}", artifactType); - } - } catch (Exception e) { - LOG.warn("Caught exception validating artifact type {}", artifactType, e); - } + relevantArtifactTypes.add(artifactType); } @@ -282,7 +273,11 @@ public class SdncUebConfiguration implements IConfiguration{ @Override public boolean isFilterInEmptyResources() { - // TODO Auto-generated method stub + return false; + } + + @Override + public Boolean isUseHttpsWithDmaap() { return false; } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java index deed20cf4..fd71527de 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java @@ -8,9 +8,9 @@ * 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. @@ -23,13 +23,13 @@ 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.Metadata; import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.openecomp.sdc.toscaparser.api.elements.Metadata; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SdncVFModel extends SdncBaseModel { - + private static final Logger LOG = LoggerFactory .getLogger(SdncVFModel.class); @@ -38,11 +38,11 @@ public class SdncVFModel extends SdncBaseModel { super(sdcCsarHelper, nodeTemplate); // extract metadata - Metadata metadata = nodeTemplate.getMetadata(); + Metadata metadata = nodeTemplate.getMetaData(); addParameter("name", extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_NAME)); - addParameter("vendor", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDOR)); - addParameter("vendor_version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDORRELEASE)); - + addParameter("vendor", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDOR)); + addParameter("vendor_version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDORRELEASE)); + // extract properties addParameter("ecomp_generated_naming", extractBooleanValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VNFECOMPNAMING_ECOMPGENERATEDNAMING)); addParameter("naming_policy", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VNFECOMPNAMING_NAMINGPOLICY)); diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java index 93fadc989..609d12011 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java @@ -1,15 +1,25 @@ package org.onap.ccsdk.sli.northbound.uebclient; -import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; + +import java.io.File; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openecomp.sdc.api.IDistributionClient; import org.openecomp.sdc.api.notification.INotificationData; - -import static org.mockito.Mockito.mock; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class TestSdncUebCallback { + + private static final Logger LOG = LoggerFactory + .getLogger(TestSdncUebCallback.class); SdncUebConfiguration config; @Before @@ -17,6 +27,25 @@ public class TestSdncUebCallback { config = new SdncUebConfiguration("src/test/resources"); } + @After + public void tearDown() throws Exception { + // Move anything in archive back to incoming + String curFileName = ""; + + Path incomingPath = new File(config.getIncomingDir()).toPath(); + File archiveDir = new File(config.getArchiveDir()); + try (DirectoryStream stream = Files.newDirectoryStream(archiveDir.toPath())) { + for (Path file: stream) { + Files.move(file, incomingPath.resolve(file.getFileName()), StandardCopyOption.REPLACE_EXISTING); + } + } catch (Exception x) { + // IOException can never be thrown by the iteration. + // In this snippet, it can only be thrown by newDirectoryStream. + LOG.warn("Cannot replace spool file {}", curFileName, x); + } + + } + @Test public void test() { diff --git a/ueb-listener/src/test/resources/incoming/src_test_resources_csars_service-NfodService-csar.csar b/ueb-listener/src/test/resources/incoming/src_test_resources_csars_service-NfodService-csar.csar new file mode 100644 index 000000000..329076a15 Binary files /dev/null and b/ueb-listener/src/test/resources/incoming/src_test_resources_csars_service-NfodService-csar.csar differ diff --git a/ueb-listener/src/test/resources/log4j.properties b/ueb-listener/src/test/resources/log4j.properties new file mode 100644 index 000000000..71849c3db --- /dev/null +++ b/ueb-listener/src/test/resources/log4j.properties @@ -0,0 +1,30 @@ +### +# ============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========================================================= +### + +log4j.rootLogger=DEBUG,CONSOLE + +# CONSOLE is set to be a ConsoleAppender using a PatternLayout. +log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +log4j.appender.CONSOLE.Threshold=DEBUG +log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +log4j.appender.CONSOLE.layout.ConversionPattern=%p %d{yyyy-MM-dd HH:mm:ss.SSS Z} %c{1} - %m%n + + diff --git a/ueb-listener/src/test/resources/ueb-listener.properties b/ueb-listener/src/test/resources/ueb-listener.properties index 7855b2116..548cc4c45 100755 --- a/ueb-listener/src/test/resources/ueb-listener.properties +++ b/ueb-listener/src/test/resources/ueb-listener.properties @@ -1,19 +1,19 @@ -org.openecomp.sdnc.uebclient.asdc-address=localhost:1234 -org.openecomp.sdnc.uebclient.consumer-group=ccsdk1 -org.openecomp.sdnc.uebclient.consumer-id=localhost_ccsdk1 -org.openecomp.sdnc.uebclient.environment-name=UNITTEST -org.openecomp.sdnc.uebclient.password=123456 -org.openecomp.sdnc.uebclient.user=test -org.openecomp.sdnc.uebclient.sdnc-user=test -org.openecomp.sdnc.uebclient.sdnc-passwd=test -org.openecomp.sdnc.uebclient.asdc-api-base-url=http://localhost:8282/restconf/operations/ -org.openecomp.sdnc.uebclient.asdc-api-namespace=org:onap:ccsdk -org.openecomp.sdnc.uebclient.spool.incoming=src/test/resources/incoming -org.openecomp.sdnc.uebclient.spool.archive=src/test/resources/archive -org.openecomp.sdnc.uebclient.polling-interval=30 -org.openecomp.sdnc.uebclient.polling-timeout=15 -org.openecomp.sdnc.uebclient.relevant-artifact-types=YANG_XML,VF_LICENSE,TOSCA_TEMPLATE,TOSCA_CSAR,UCPE_LAYER_2_CONFIGURATION -org.openecomp.sdnc.uebclient.activate-server-tls-auth=false -org.openecomp.sdnc.uebclient.keystore-path= -org.openecomp.sdnc.uebclient.keystore-password= -org.openecomp.sdnc.uebclient.xslt-path-list=src/main/resources/removeNs.xslt,src/main/resources/normalizeTagNames.xslt +org.onap.ccsdk.sli.northbound.uebclient.asdc-address=localhost:1234 +org.onap.ccsdk.sli.northbound.uebclient.consumer-group=ccsdk1 +org.onap.ccsdk.sli.northbound.uebclient.consumer-id=localhost_ccsdk1 +org.onap.ccsdk.sli.northbound.uebclient.environment-name=UNITTEST +org.onap.ccsdk.sli.northbound.uebclient.password=123456 +org.onap.ccsdk.sli.northbound.uebclient.user=test +org.onap.ccsdk.sli.northbound.uebclient.sdnc-user=test +org.onap.ccsdk.sli.northbound.uebclient.sdnc-passwd=test +org.onap.ccsdk.sli.northbound.uebclient.asdc-api-base-url=http://localhost:8282/restconf/operations/ +org.onap.ccsdk.sli.northbound.uebclient.asdc-api-namespace=org:onap:ccsdk +org.onap.ccsdk.sli.northbound.uebclient.spool.incoming=src/test/resources/incoming +org.onap.ccsdk.sli.northbound.uebclient.spool.archive=src/test/resources/archive +org.onap.ccsdk.sli.northbound.uebclient.polling-interval=30 +org.onap.ccsdk.sli.northbound.uebclient.polling-timeout=15 +org.onap.ccsdk.sli.northbound.uebclient.relevant-artifact-types=YANG_XML,VF_LICENSE,TOSCA_TEMPLATE,TOSCA_CSAR,UCPE_LAYER_2_CONFIGURATION +org.onap.ccsdk.sli.northbound.uebclient.activate-server-tls-auth=false +org.onap.ccsdk.sli.northbound.uebclient.keystore-path= +org.onap.ccsdk.sli.northbound.uebclient.keystore-password= +org.onap.ccsdk.sli.northbound.uebclient.xslt-path-list= \ No newline at end of file -- cgit 1.2.3-korg From 138a0022b67f9771d69b2c4e82bbce2a054d12cd Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Tue, 3 Oct 2017 20:04:32 -0400 Subject: Add ueb-listener test case Add test case for license-model parsing in ueb-listener. Change-Id: I279e269f7ba3c6f37c09f71b99b20d4e9e661e23 Issue-ID: CCSDK-106 Signed-off-by: Dan Timoney --- ueb-listener/src/test/resources/incoming/vf-license-model.xml | 1 + 1 file changed, 1 insertion(+) create mode 100644 ueb-listener/src/test/resources/incoming/vf-license-model.xml (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/test/resources/incoming/vf-license-model.xml b/ueb-listener/src/test/resources/incoming/vf-license-model.xml new file mode 100644 index 000000000..c5e33eeb5 --- /dev/null +++ b/ueb-listener/src/test/resources/incoming/vf-license-model.xml @@ -0,0 +1 @@ +BroadsoftE5A18BC3D2454091B02EA3F69EB1DB46Broadsoft EPtbp200728ad6b0-912e-432b-853e-373845d410adtbpVMAbsolute100Placeholder BS LPKtbpUniversal3be519b2-abf3-449f-9851-0ac70ccb5632tbpVMtbpasdfasfdsdfPlaceholder LPK4ACF252A84FA4FEC9C98AA0DFCFFFBCE \ No newline at end of file -- cgit 1.2.3-korg From 0df357bc4d684d13029d702312995659373fc711 Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Tue, 3 Oct 2017 20:34:31 -0400 Subject: Improve ueb-listener tests Use Maria4JDB to improve test coverage of ueb-listener. Change-Id: Ifb88916434bb1b293b4bbd6fae069cd1e88c9d8d Issue-ID: CCSDK-106 Signed-off-by: Dan Timoney --- ueb-listener/pom.xml | 8 ++++- .../sli/northbound/uebclient/SdncUebCallback.java | 8 ++++- .../northbound/uebclient/TestSdncUebCallback.java | 35 ++++++++++++++++++++ ueb-listener/src/test/resources/dblib.properties | 38 ++++++++++++++++++++++ 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 ueb-listener/src/test/resources/dblib.properties (limited to 'ueb-listener/src') diff --git a/ueb-listener/pom.xml b/ueb-listener/pom.xml index 68d8fc080..2241047f6 100755 --- a/ueb-listener/pom.xml +++ b/ueb-listener/pom.xml @@ -41,7 +41,7 @@ org.slf4j slf4j-api - 1.7.10 + 1.7.21 org.slf4j @@ -81,6 +81,12 @@ mockito-core ${mockito.version} test + + + ch.vorburger.mariaDB4j + mariaDB4j + 2.2.3 + test org.onap.ccsdk.sli.core diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index b3c96d9d8..2cc08e1ae 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -207,7 +207,13 @@ public class SdncUebCallback implements INotificationCallback { Properties props = new Properties(); props.load(new FileInputStream(propFile)); - jdbcDataSource = new DBResourceManager(props); + setJdbcDataSource(new DBResourceManager(props)); + + } + + static void setJdbcDataSource(DBResourceManager dbMgr) { + + jdbcDataSource = dbMgr; if(jdbcDataSource.isActive()){ LOG.warn( "DBLIB: JDBC DataSource has been initialized."); diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java index 609d12011..d62618c6d 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java @@ -3,28 +3,60 @@ package org.onap.ccsdk.sli.northbound.uebclient; import static org.mockito.Mockito.mock; import java.io.File; +import java.io.InputStream; +import java.net.URL; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; +import java.util.Properties; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; import org.openecomp.sdc.api.IDistributionClient; import org.openecomp.sdc.api.notification.INotificationData; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import ch.vorburger.mariadb4j.DB; +import ch.vorburger.mariadb4j.DBConfigurationBuilder; + public class TestSdncUebCallback { private static final Logger LOG = LoggerFactory .getLogger(TestSdncUebCallback.class); SdncUebConfiguration config; + DBResourceManager dblibSvc; + DB db; @Before public void setUp() throws Exception { config = new SdncUebConfiguration("src/test/resources"); + + URL propUrl = getClass().getResource("/dblib.properties"); + + InputStream propStr = getClass().getResourceAsStream("/dblib.properties"); + + Properties props = new Properties(); + + props.load(propStr); + + + // Start MariaDB4j database + DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder(); + config.setPort(0); // 0 => autom. detect free port + db = DB.newEmbeddedDB(config.build()); + db.start(); + + + // Override jdbc URL and database name + props.setProperty("org.onap.ccsdk.sli.jdbc.database", "test"); + props.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test")); + + + dblibSvc = new DBResourceManager(props); } @After @@ -44,6 +76,8 @@ public class TestSdncUebCallback { LOG.warn("Cannot replace spool file {}", curFileName, x); } + db.stop(); + } @Test @@ -51,6 +85,7 @@ public class TestSdncUebCallback { IDistributionClient iDistClient = mock(IDistributionClient.class); SdncUebCallback cb = new SdncUebCallback(iDistClient, config); + cb.setJdbcDataSource(dblibSvc); INotificationData iData = mock(INotificationData.class); cb.activateCallback(iData); diff --git a/ueb-listener/src/test/resources/dblib.properties b/ueb-listener/src/test/resources/dblib.properties new file mode 100644 index 000000000..9506ac8d1 --- /dev/null +++ b/ueb-listener/src/test/resources/dblib.properties @@ -0,0 +1,38 @@ +### +# ============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========================================================= +### + +# dblib.properrties +org.onap.ccsdk.sli.dbtype=jdbc + +org.onap.ccsdk.sli.jdbc.hosts=sdnctldb01 +org.onap.ccsdk.sli.jdbc.url=jdbc:mysql://dbhost:3306/sdnctl +org.onap.ccsdk.sli.jdbc.driver=org.mariadb.jdbc.Driver +org.onap.ccsdk.sli.jdbc.database=sdnctl +org.onap.ccsdk.sli.jdbc.user=sdnctl +org.onap.ccsdk.sli.jdbc.password=gamma +org.onap.ccsdk.sli.jdbc.connection.name=sdnctldb01 +org.onap.ccsdk.sli.jdbc.connection.timeout=50 +org.onap.ccsdk.sli.jdbc.request.timeout=100 +org.onap.ccsdk.sli.jdbc.limit.init=10 +org.onap.ccsdk.sli.jdbc.limit.min=10 +org.onap.ccsdk.sli.jdbc.limit.max=20 +org.onap.dblib.connection.recovery=false + -- cgit 1.2.3-korg From 70eb2ae5c2f87511a34aeab170b13a7d3bdae66a Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Wed, 4 Oct 2017 16:58:38 -0400 Subject: Test TOSCA table insertion Add code to create TOSCA tables in test driver to test TOSCA table insertion in ueb-listener TOSCA parser test. Change-Id: Ib8c3fcdb25fbdba39b4700553d8c01b684efa384 Issue-ID: CCSDK-102 Signed-off-by: Dan Timoney --- .../sli/northbound/uebclient/SdncArtifactMap.java | 6 +- .../sli/northbound/uebclient/SdncUebCallback.java | 2 +- .../northbound/uebclient/SdncUebConfiguration.java | 3 + .../northbound/uebclient/TestSdncUebCallback.java | 129 +++++++++++++++++++++ ueb-listener/src/test/resources/artifact.map | 2 + .../src/test/resources/ueb-listener.properties | 3 +- version.properties | 4 +- 7 files changed, 143 insertions(+), 6 deletions(-) create mode 100644 ueb-listener/src/test/resources/artifact.map (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java index 3605465d4..671d47a9f 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java @@ -8,9 +8,9 @@ * 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. @@ -104,6 +104,8 @@ public class SdncArtifactMap { LOG.error("Caught exception reading artifact map", e); return; } + } else { + LOG.info("Artifact map {} does not exist or is not readable", fileName); } } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index 2cc08e1ae..67e042b5d 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -561,7 +561,7 @@ public class SdncUebCallback implements INotificationCallback { insertToscaData(serviceModel.getSql(model_yaml)); } catch (IOException e) { LOG.error("Could not insert Tosca YAML data into the SERVICE_MODEL table ", e); - return; + // return; } // Ingest Network (VL) Data - 1707 diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java index b49a66070..75cb9c971 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java @@ -177,7 +177,10 @@ public class SdncUebConfiguration implements IConfiguration{ String artifactMapFile = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.artifact-map"); if (artifactMapFile != null) { + LOG.info("Loading artifactMapFile {}", artifactMapFile); artifactMap.load(artifactMapFile); + } else { + LOG.warn("artifact-map is unset"); } } diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java index d62618c6d..79a598ce5 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java @@ -25,6 +25,125 @@ import ch.vorburger.mariadb4j.DBConfigurationBuilder; public class TestSdncUebCallback { + + private static final String CRTBL_SERVICE_MODEL = "CREATE TABLE `SERVICE_MODEL` (\n" + + " `service_uuid` varchar(255) NOT NULL,\n" + + " `model_yaml` longblob,\n" + + " `invariant_uuid` varchar(255) DEFAULT NULL,\n" + + " `version` varchar(255) DEFAULT NULL,\n" + + " `name` varchar(255) DEFAULT NULL,\n" + + " `description` varchar(1024) DEFAULT NULL,\n" + + " `type` varchar(255) DEFAULT NULL,\n" + + " `category` varchar(255) DEFAULT NULL,\n" + + " `ecomp_naming` char(1) DEFAULT NULL,\n" + + " `service_instance_name_prefix` varchar(255) DEFAULT NULL,\n" + + " `filename` varchar(100) DEFAULT NULL,\n" + + " `naming_policy` varchar(255) DEFAULT NULL,\n" + + " PRIMARY KEY (`service_uuid`)\n" + + ") "; + + private static final String CRTBL_NETWORK_MODEL = "CREATE TABLE `NETWORK_MODEL` (\n" + + " `customization_uuid` varchar(255) NOT NULL,\n" + + " `service_uuid` varchar(255) NOT NULL,\n" + + " `model_yaml` longblob,\n" + + " `invariant_uuid` varchar(255) DEFAULT NULL,\n" + + " `uuid` varchar(255) DEFAULT NULL,\n" + + " `network_type` varchar(255) DEFAULT NULL,\n" + + " `network_role` varchar(255) DEFAULT NULL,\n" + + " `network_technology` varchar(255) DEFAULT NULL,\n" + + " `network_scope` varchar(255) DEFAULT NULL,\n" + + " `naming_policy` varchar(255) DEFAULT NULL,\n" + + " `ecomp_generated_naming` char(1) DEFAULT NULL,\n" + + " `is_shared_network` char(1) DEFAULT NULL,\n" + + " `is_external_network` char(1) DEFAULT NULL,\n" + + " `is_provider_network` char(1) DEFAULT NULL,\n" + + " `physical_network_name` varchar(255) DEFAULT NULL,\n" + + " `is_bound_to_vpn` char(1) DEFAULT NULL,\n" + + " `vpn_binding` varchar(255) DEFAULT NULL,\n" + + " `use_ipv4` char(1) DEFAULT NULL,\n" + + " `ipv4_dhcp_enabled` char(1) DEFAULT NULL,\n" + + " `ipv4_ip_version` char(1) DEFAULT NULL,\n" + + " `ipv4_cidr_mask` varchar(255) DEFAULT NULL,\n" + + " `eipam_v4_address_plan` varchar(255) DEFAULT NULL,\n" + + " `use_ipv6` char(1) DEFAULT NULL,\n" + + " `ipv6_dhcp_enabled` char(1) DEFAULT NULL,\n" + + " `ipv6_ip_version` char(1) DEFAULT NULL,\n" + + " `ipv6_cidr_mask` varchar(255) DEFAULT NULL,\n" + + " `eipam_v6_address_plan` varchar(255) DEFAULT NULL,\n" + + " `version` varchar(255) DEFAULT NULL,\n" + + " PRIMARY KEY (`customization_uuid`),\n" + + " KEY `FK_NETWORK_MODEL` (`service_uuid`),\n" + + " CONSTRAINT `FK_NETWORK_MODEL` FOREIGN KEY (`service_uuid`) REFERENCES `SERVICE_MODEL` (`service_uuid`) ON DELETE NO ACTION ON UPDATE NO ACTION\n" + + ")"; + + private static final String CRTBL_ALLOTTED_RESOURCE_MODEL = "CREATE TABLE `ALLOTTED_RESOURCE_MODEL` (\n" + + " `customization_uuid` varchar(255) NOT NULL,\n" + + " `model_yaml` longblob,\n" + + " `invariant_uuid` varchar(255) DEFAULT NULL,\n" + + " `uuid` varchar(255) DEFAULT NULL,\n" + + " `version` varchar(255) DEFAULT NULL,\n" + + " `naming_policy` varchar(255) DEFAULT NULL,\n" + + " `ecomp_generated_naming` char(1) DEFAULT NULL,\n" + + " `depending_service` varchar(255) DEFAULT NULL,\n" + + " `role` varchar(255) DEFAULT NULL,\n" + + " `type` varchar(255) DEFAULT NULL,\n" + + " `service_dependency` varchar(255) DEFAULT NULL,\n" + + " `allotted_resource_type` varchar(255) DEFAULT NULL,\n" + + " PRIMARY KEY (`customization_uuid`)\n" + + ") "; + + private static final String CRTBL_VFC_MODEL = "CREATE TABLE `VFC_MODEL` (\n" + + " `customization_uuid` varchar(255) NOT NULL,\n" + + " `model_yaml` longblob,\n" + + " `invariant_uuid` varchar(255) DEFAULT NULL,\n" + + " `uuid` varchar(255) DEFAULT NULL,\n" + + " `version` varchar(255) DEFAULT NULL,\n" + + " `naming_policy` varchar(255) DEFAULT NULL,\n" + + " `ecomp_generated_naming` char(1) DEFAULT NULL,\n" + + " `nfc_function` varchar(255) DEFAULT NULL,\n" + + " `nfc_naming_code` varchar(255) DEFAULT NULL,\n" + + " `vm_type` varchar(255) DEFAULT NULL,\n" + + " `vm_type_tag` varchar(255) DEFAULT NULL,\n" + + " `vm_image_name` varchar(255) DEFAULT NULL,\n" + + " `vm_flavor_name` varchar(255) DEFAULT NULL,\n" + + " `high_availability` varchar(255) DEFAULT NULL,\n" + + " `nfc_naming` varchar(255) DEFAULT NULL,\n" + + " `min_instances` int(11) DEFAULT NULL,\n" + + " `max_instances` int(11) DEFAULT NULL,\n" + + " PRIMARY KEY (`customization_uuid`)\n" + + ") "; + + private static final String CRTBL_VF_MODEL = "CREATE TABLE `VF_MODEL` (\n" + + " `customization_uuid` varchar(255) NOT NULL,\n" + + " `model_yaml` longblob,\n" + + " `invariant_uuid` varchar(255) DEFAULT NULL,\n" + + " `uuid` varchar(255) DEFAULT NULL,\n" + + " `version` varchar(255) DEFAULT NULL,\n" + + " `name` varchar(255) DEFAULT NULL,\n" + + " `naming_policy` varchar(255) DEFAULT NULL,\n" + + " `ecomp_generated_naming` char(1) DEFAULT NULL,\n" + + " `avail_zone_max_count` int(11) DEFAULT NULL,\n" + + " `nf_function` varchar(255) DEFAULT NULL,\n" + + " `nf_code` varchar(255) DEFAULT NULL,\n" + + " `nf_type` varchar(255) DEFAULT NULL,\n" + + " `nf_role` varchar(255) DEFAULT NULL,\n" + + " `vendor` varchar(255) DEFAULT NULL,\n" + + " `vendor_version` varchar(255) DEFAULT NULL,\n" + + " PRIMARY KEY (`customization_uuid`)\n" + + ")"; + + private static final String CRTBL_VF_MODULE_MODEL = "CREATE TABLE `VF_MODULE_MODEL` (\n" + + " `customization_uuid` varchar(255) NOT NULL,\n" + + " `model_yaml` longblob,\n" + + " `invariant_uuid` varchar(255) DEFAULT NULL,\n" + + " `uuid` varchar(255) DEFAULT NULL,\n" + + " `version` varchar(255) DEFAULT NULL,\n" + + " `vf_module_type` varchar(255) DEFAULT NULL,\n" + + " `availability_zone_count` int(11) DEFAULT NULL,\n" + + " `ecomp_generated_vm_assignments` char(1) DEFAULT NULL,\n" + + " PRIMARY KEY (`customization_uuid`)\n" + + ")"; + private static final Logger LOG = LoggerFactory .getLogger(TestSdncUebCallback.class); SdncUebConfiguration config; @@ -35,6 +154,7 @@ public class TestSdncUebCallback { public void setUp() throws Exception { config = new SdncUebConfiguration("src/test/resources"); + URL propUrl = getClass().getResource("/dblib.properties"); InputStream propStr = getClass().getResourceAsStream("/dblib.properties"); @@ -56,7 +176,16 @@ public class TestSdncUebCallback { props.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test")); + // Create dblib connection dblibSvc = new DBResourceManager(props); + + // Create TOSCA tables + dblibSvc.writeData(CRTBL_SERVICE_MODEL, null, null); + dblibSvc.writeData(CRTBL_NETWORK_MODEL, null, null); + dblibSvc.writeData(CRTBL_VFC_MODEL, null, null); + dblibSvc.writeData(CRTBL_VF_MODEL, null, null); + dblibSvc.writeData(CRTBL_VF_MODULE_MODEL, null, null); + dblibSvc.writeData(CRTBL_ALLOTTED_RESOURCE_MODEL, null, null); } @After diff --git a/ueb-listener/src/test/resources/artifact.map b/ueb-listener/src/test/resources/artifact.map new file mode 100644 index 000000000..0256515f0 --- /dev/null +++ b/ueb-listener/src/test/resources/artifact.map @@ -0,0 +1,2 @@ +vf-license-model,ASDC-API:vf-license-model-update,0 +bad-entry,0 diff --git a/ueb-listener/src/test/resources/ueb-listener.properties b/ueb-listener/src/test/resources/ueb-listener.properties index 548cc4c45..4b9886ee5 100755 --- a/ueb-listener/src/test/resources/ueb-listener.properties +++ b/ueb-listener/src/test/resources/ueb-listener.properties @@ -16,4 +16,5 @@ org.onap.ccsdk.sli.northbound.uebclient.relevant-artifact-types=YANG_XML,VF_LICE org.onap.ccsdk.sli.northbound.uebclient.activate-server-tls-auth=false org.onap.ccsdk.sli.northbound.uebclient.keystore-path= org.onap.ccsdk.sli.northbound.uebclient.keystore-password= -org.onap.ccsdk.sli.northbound.uebclient.xslt-path-list= \ No newline at end of file +org.onap.ccsdk.sli.northbound.uebclient.xslt-path-list= +org.onap.ccsdk.sli.northbound.uebclient.artifact-map=src/test/resources/artifact.map \ No newline at end of file diff --git a/version.properties b/version.properties index 709250395..3d3e5b582 100644 --- a/version.properties +++ b/version.properties @@ -4,8 +4,8 @@ # because they are used in Jenkins, whose plug-in doesn't support release_name=0 -sprint_number=0 -feature_revision=1 +sprint_number=1 +feature_revision=0 base_version=${release_name}.${sprint_number}.${feature_revision} -- cgit 1.2.3-korg From 73d1bd7ab120c112f0febbcfa5b549be7e9754ea Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Mon, 9 Oct 2017 10:02:22 -0400 Subject: Add retry to ueb-listener Added retry mechanism to ueb-listener to handle case where ueb-listener comes up before DMaap or SDC. Change-Id: I0d96bd1fe4d3d0fdb5e01d9f42304b54bea0a550 Issue-ID: CCSDK-112 Signed-off-by: Dan Timoney --- ueb-listener/src/assembly/assemble_zip.xml | 6 ++-- .../sli/northbound/uebclient/SdncUebClient.java | 35 +++++++++++++++++++--- .../northbound/uebclient/SdncUebConfiguration.java | 13 ++++++++ .../src/test/resources/ueb-listener.properties | 1 + 4 files changed, 48 insertions(+), 7 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/assembly/assemble_zip.xml b/ueb-listener/src/assembly/assemble_zip.xml index 97a229d2c..7a21aca48 100644 --- a/ueb-listener/src/assembly/assemble_zip.xml +++ b/ueb-listener/src/assembly/assemble_zip.xml @@ -8,9 +8,9 @@ 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. @@ -34,7 +34,7 @@ - src/main/bin + src/main/scripts bin diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java index d29890486..1d1f47634 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java @@ -39,6 +39,7 @@ public class SdncUebClient { SdncUebCallback cb = new SdncUebCallback(client, config); + LOG.info("Scanning for local distribution artifacts before starting client"); cb.deployDownloadedFiles(null, null, null); @@ -48,13 +49,39 @@ public class SdncUebClient { LOG.info("Initialized ASDC distribution client - results = {}", result.getDistributionMessageResult()); - if (result.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) { - LOG.info("Starting client..."); - IDistributionClientResult start = client.start(); - LOG.info("Client startup result = {}", start.getDistributionMessageResult()); + long startTm = System.currentTimeMillis(); + int sleepTm = config.getPollingInterval() * 1000; + long maxWaitTm = config.getClientStartupTimeout() * 1000; + + boolean keepWaiting = true; + + while (keepWaiting) { + if (result.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) { + LOG.info("Starting client..."); + try { + IDistributionClientResult start = client.start(); + LOG.info("Client startup result = {}", start.getDistributionMessageResult()); + keepWaiting = false; + } catch(Exception e) { + LOG.info("Client startup failure", e); + } + + if (System.currentTimeMillis() - startTm < maxWaitTm) { + keepWaiting = false; + } else { + + try { + Thread.sleep(sleepTm); + } catch (InterruptedException e) { + // Ignore + } + } + } + } + } } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java index 75cb9c971..bf7dc88a5 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java @@ -46,6 +46,7 @@ public class SdncUebConfiguration implements IConfiguration{ private String password = null; private int pollingInterval = 30; private int pollingTimeout = 15; + private int clientStartupTimeout = 900; private List relevantArtifactTypes = null; private String user = null; @@ -154,6 +155,14 @@ public class SdncUebConfiguration implements IConfiguration{ } } + curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.client-startup-timeout"); + if ((curval != null) && (curval.length() > 0)) { + try { + clientStartupTimeout = Integer.parseInt(curval); + } catch (Exception e) { + LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-timeout ({}) ", curval, e); + } + } curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.relevant-artifact-types"); if ((curval != null) && (curval.length() > 0)) { String[] artifactTypes = curval.split(","); @@ -225,6 +234,10 @@ public class SdncUebConfiguration implements IConfiguration{ return relevantArtifactTypes; } + public int getClientStartupTimeout() { + return clientStartupTimeout; + } + @Override public String getUser() { return user; diff --git a/ueb-listener/src/test/resources/ueb-listener.properties b/ueb-listener/src/test/resources/ueb-listener.properties index 4b9886ee5..35c380595 100755 --- a/ueb-listener/src/test/resources/ueb-listener.properties +++ b/ueb-listener/src/test/resources/ueb-listener.properties @@ -12,6 +12,7 @@ org.onap.ccsdk.sli.northbound.uebclient.spool.incoming=src/test/resources/incomi org.onap.ccsdk.sli.northbound.uebclient.spool.archive=src/test/resources/archive org.onap.ccsdk.sli.northbound.uebclient.polling-interval=30 org.onap.ccsdk.sli.northbound.uebclient.polling-timeout=15 +org.onap.ccsdk.sli.northbound.uebclient.client-startup-timeout=60 org.onap.ccsdk.sli.northbound.uebclient.relevant-artifact-types=YANG_XML,VF_LICENSE,TOSCA_TEMPLATE,TOSCA_CSAR,UCPE_LAYER_2_CONFIGURATION org.onap.ccsdk.sli.northbound.uebclient.activate-server-tls-auth=false org.onap.ccsdk.sli.northbound.uebclient.keystore-path= -- cgit 1.2.3-korg From da99eed5436f92eb2b4794cc0399bdb0eb400afc Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Mon, 6 Nov 2017 17:19:46 -0500 Subject: Ignore TOSCA YML TOSCA is passed in 2 formats : YML and CSAR. The SDC TOSCA parser only handles CSAR, so YML artifact cannot be passed to it. Since CSAR artifact all data needed (that is, there is nothing in YML that SDNC needs that is not in the CSAR), it can be safely ignored. Change-Id: I54aa2ae49e3ba0aa23b280fa106ada3d588897a0 Issue-ID: SDNC-169 Signed-off-by: Dan Timoney --- .../sli/northbound/uebclient/SdncUebCallback.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index 67e042b5d..d01b02589 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -440,15 +440,15 @@ public class SdncUebCallback implements INotificationCallback { // If an override file exists, read that instead of the file we just downloaded ArtifactTypeEnum artifactEnum = ArtifactTypeEnum.YANG_XML; - boolean toscaYamlType = false; + boolean toscaCsarType = false; if (artifact != null) { String artifactTypeString = artifact.getArtifactType(); - if (artifactTypeString.contains("TOSCA_TEMPLATE")) { - toscaYamlType = true; + if (artifactTypeString.contains("TOSCA_CSAR")) { + toscaCsarType = true; } } else { - if (spoolFile.toString().contains(".yml") || spoolFile.toString().contains(".csar")) { - toscaYamlType = true; + if (spoolFile.toString().contains(".csar")) { + toscaCsarType = true; } } String overrideFileName = config.getOverrideFile(); @@ -462,8 +462,8 @@ public class SdncUebCallback implements INotificationCallback { } - if (toscaYamlType) { - processToscaYaml (data, svcName, resourceName, artifact, spoolFile, archiveDir); + if (toscaCsarType) { + processToscaCsar (data, svcName, resourceName, artifact, spoolFile, archiveDir); try { Path source = spoolFile.toPath(); @@ -529,7 +529,7 @@ public class SdncUebCallback implements INotificationCallback { } - private void processToscaYaml(INotificationData data, String svcName, String resourceName, + private void processToscaCsar(INotificationData data, String svcName, String resourceName, IArtifactInfo artifact, File spoolFile, File archiveDir) { // Use ASDC Dist Client 1.1.5 with TOSCA parsing APIs to extract relevant TOSCA model data @@ -537,7 +537,7 @@ public class SdncUebCallback implements INotificationCallback { // TOSCA data extraction flow 1707: // Use ASDC dist-client to get yaml string - not yet available String model_yaml = null; - LOG.info("Process TOSCA YAML file: "+spoolFile.toString()); + LOG.info("Process TOSCA CSAR file: "+spoolFile.toString()); SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); ISdcCsarHelper sdcCsarHelper = null; -- cgit 1.2.3-korg From f1cdb6b4212168879f623abd4beb345dadf200dd Mon Sep 17 00:00:00 2001 From: Lalena Aria Date: Wed, 8 Nov 2017 16:25:41 +0000 Subject: Abstract Changes made: update AAI Service path list from the latest version published by AAI Team Change-Id: Ie6d5451777cfd45b528acdfe098e31f26ab3714c Issue-ID: SDC-564 Signed-off-by: lalena.aria --- .../sli/northbound/uebclient/SdncUebCallback.java | 33 ++++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index d01b02589..aa856b4fe 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -26,6 +26,7 @@ import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -396,21 +397,35 @@ public class SdncUebCallback implements INotificationCallback { return; } - String payload = new String(payloadBytes); - File spoolFile = new File(incomingDir.getAbsolutePath() + "/" + artifact.getArtifactName()); boolean writeSucceeded = false; - try (FileWriter spoolFileWriter = new FileWriter(spoolFile)) { - spoolFileWriter.write(payload); - spoolFileWriter.close(); - writeSucceeded = true; - } catch (Exception e) { - LOG.error("Unable to save downloaded file to spool directory ("+ incomingDir.getAbsolutePath() +")", e); - } + // Save zip if TOSCA_CSAR + if (artifact.getArtifactType().contains("TOSCA_CSAR") || artifact.getArtifactName().contains(".csar")) { + try { + FileOutputStream outFile = new FileOutputStream(incomingDir.getAbsolutePath() + "/" + artifact.getArtifactName()); + outFile.write(payloadBytes, 0, payloadBytes.length); + outFile.close(); + writeSucceeded = true; + } catch (Exception e) { + LOG.error("Unable to save downloaded zip file to spool directory ("+ incomingDir.getAbsolutePath() +")", e); + } + + } else { + String payload = new String(payloadBytes); + + try { + FileWriter spoolFileWriter = new FileWriter(spoolFile); + spoolFileWriter.write(payload); + spoolFileWriter.close(); + writeSucceeded = true; + } catch (Exception e) { + LOG.error("Unable to save downloaded file to spool directory ("+ incomingDir.getAbsolutePath() +")", e); + } + } if (writeSucceeded && (downloadResult.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS)) { handleSuccessfulDownload(data, svcName, resourceName, artifact, spoolFile, archiveDir); -- cgit 1.2.3-korg From 3a2b6ca0e3733f45485e2c9da2e6dfe95b77128a Mon Sep 17 00:00:00 2001 From: "lalena.aria" Date: Tue, 14 Nov 2017 19:04:51 +0000 Subject: Update CCSDK northbound ueb-listener Changes made: Corrected extraction locations for role, type, ecomp_generated_naming and naming_policy in ALLOTTED_RESOURCE_MODEL. Change-Id: I59d1625ee226e194ecba81c84ead964df6307676 Issue-ID: SDNC-194 Signed-off-by: lalena.aria --- .../java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java index 8d480a4d1..78225de40 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java @@ -42,10 +42,10 @@ public class SdncARModel extends SdncBaseModel { addParameter("type", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_TYPE)); // extract properties - //addParameter("role", extractValue (sdcCsarHelper, nodeTemplate, SdcPropertyNames.PROPERTY_NAME_ROLE)); - //addParameter("type", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_TYPE)); - wrong location, get from metadata - addParameter("ecomp_generated_naming", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VFCNAMING_ECOMPGENERATEDNAMING)); - addParameter("naming_policy", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VFCNAMING_NAMINGPOLICY)); + addParameter("role", extractValue (nodeTemplate, "nf_role")); + addParameter("type", extractValue (nodeTemplate, "nf_type")); + addParameter("ecomp_generated_naming", extractBooleanValue (nodeTemplate, "nf_naming#ecomp_generated_naming")); + addParameter("naming_policy", extractValue (nodeTemplate, "nf_naming#naming_policy")); //addParameter("depending_service", extractValue (sdcCsarHelper, nodeTemplate, SdcPropertyNames.PROPERTY_NAME_DEPENDINGSERVICE)); //addParameter("service_dependency", extractValue (sdcCsarHelper, nodeTemplate, SdcPropertyNames.PROPERTY_NAME_SERVICEDEPENDENCY)); } -- cgit 1.2.3-korg From bb266b8b2436841ed4b950df187f1fb88376bb22 Mon Sep 17 00:00:00 2001 From: "prakash.e" Date: Thu, 14 Dec 2017 15:11:04 +0530 Subject: Removal of unused parenthesis Change-Id: I5050503d1993e880851fb56f6b7c3ef8ece192b6 Issue-ID: CCSDK-151 Signed-off-by: prakash.e --- .../org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java | 2 +- .../org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java index 821057ef3..a2556b4ba 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java @@ -87,7 +87,7 @@ public class SdncOdlConnection { public static SdncOdlConnection newInstance(String url, String user, String password) throws IOException { - return (new SdncOdlConnection(url, user, password)); + return new SdncOdlConnection(url, user, password); } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java index d3fd16791..012c3d9e2 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java @@ -28,10 +28,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SdncServiceModel extends SdncBaseModel { - - private static final Logger LOG = LoggerFactory - .getLogger(SdncServiceModel.class); - + private String UUID = null; private String serviceInstanceNamePrefix = null; private String filename = null; @@ -48,7 +45,7 @@ public class SdncServiceModel extends SdncBaseModel { } public String getServiceUUID() { - return ("\"" + UUID + "\""); + return "\"" + UUID + "\""; } public void setServiceUUID(String serviceUUID) { this.UUID = serviceUUID; -- cgit 1.2.3-korg From e994e1ae5d445c649946ea7703f00e7e1b6adb55 Mon Sep 17 00:00:00 2001 From: "prakash.e" Date: Fri, 15 Dec 2017 18:54:34 +0530 Subject: Removal of unused variables Change-Id: I73dff3b51f1895fc0282e4d3d662bc9019a87e31 Issue-ID: CCSDK-151 Signed-off-by: prakash.e --- .../main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java | 3 --- .../java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java | 3 --- 2 files changed, 6 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java index 78225de40..b26c50fb2 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java @@ -30,9 +30,6 @@ import org.slf4j.LoggerFactory; public class SdncARModel extends SdncBaseModel { - private static final Logger LOG = LoggerFactory - .getLogger(SdncARModel.class); - public SdncARModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { super(sdcCsarHelper, nodeTemplate); diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index 6128f288b..4737f8508 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -34,9 +34,6 @@ import org.slf4j.LoggerFactory; public class SdncBaseModel { - private static final Logger LOG = LoggerFactory - .getLogger(SdncBaseModel.class); - protected String customizationUUID = null; protected String invariantUUID = null; protected String model_yaml = null; -- cgit 1.2.3-korg From 22a18f12b2338c15dc266289955efa94ba99c157 Mon Sep 17 00:00:00 2001 From: "prakash.e" Date: Thu, 14 Dec 2017 16:27:14 +0530 Subject: Removal of useless parenthesis Change-Id: Ida52e0fab68d33ef446378024441ca3af0762f70 Issue-ID: CCSDK-151 Signed-off-by: prakash.e --- .../org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java | 4 ++-- .../org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index 6128f288b..758f862ba 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -233,10 +233,10 @@ public class SdncBaseModel { } public String getCustomizationUUID() { - return ("\"" + customizationUUID + "\""); + return "\"" + customizationUUID + "\""; } public String getCustomizationUUIDNoQuotes() { - return (customizationUUID); + return customizationUUID; } public void setCustomizationUUID(String customizationUUID) { this.customizationUUID = customizationUUID; diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java index 2fec84cb1..0a4931715 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java @@ -28,10 +28,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SdncNodeModel extends SdncBaseModel { - - private static final Logger LOG = LoggerFactory - .getLogger(SdncNodeModel.class); - + private String serviceUUID = null; private String ecompGeneratedNaming = null; private String [] bindingUuids = null; @@ -41,7 +38,7 @@ public class SdncNodeModel extends SdncBaseModel { super(sdcCsarHelper, nodeTemplate); - // extract inputs + // 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)); -- cgit 1.2.3-korg From 6cf53198be74497668c3ed38f2127b26ae74bc69 Mon Sep 17 00:00:00 2001 From: "prakash.e" Date: Tue, 19 Dec 2017 19:23:28 +0530 Subject: typeCasting issue and useless assignment fix Change-Id: Iab98bdec347fc9b15afc78de1b99eab8fbff5ad1 Issue-ID: CCSDK-151 Signed-off-by: prakash.e --- .../java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java | 2 +- .../java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index aa856b4fe..39ed39676 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -881,7 +881,7 @@ public class SdncUebCallback implements INotificationCallback { private DistributionStatusEnum deploySpoolFile(DeployableArtifact artifact) { - DistributionStatusEnum deployResult = DistributionStatusEnum.DEPLOY_OK; + DistributionStatusEnum deployResult; StringBuffer msgBuffer = new StringBuffer(); diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java index 1d1f47634..0694a6da7 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java @@ -51,7 +51,7 @@ public class SdncUebClient { long startTm = System.currentTimeMillis(); int sleepTm = config.getPollingInterval() * 1000; - long maxWaitTm = config.getClientStartupTimeout() * 1000; + long maxWaitTm = config.getClientStartupTimeout() * 1000L; boolean keepWaiting = true; -- cgit 1.2.3-korg From 124fa28fffe41658dd9a7fc77c91b3279a7c92cd Mon Sep 17 00:00:00 2001 From: "prakash.e" Date: Thu, 21 Dec 2017 15:59:52 +0530 Subject: Impact on performance fix Change-Id: I36e82265087ebce69c7f01c8e75b7c932a969d0e Issue-ID: CCSDK-151 Signed-off-by: prakash.e --- .../org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java index a2556b4ba..78d9c5bc9 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java @@ -137,7 +137,7 @@ public class SdncOdlConnection { respRdr = new BufferedReader(new InputStreamReader(httpConn.getErrorStream())); } - StringBuffer respBuff = new StringBuffer(); + StringBuilder respBuff = new StringBuilder(); String respLn; @@ -150,7 +150,7 @@ public class SdncOdlConnection { LOG.info("Response body :\n" + respString); - return (respString); + return respString; } -- cgit 1.2.3-korg From ae93ec85ad6ee1a926309770bcf4b2d1607e420c Mon Sep 17 00:00:00 2001 From: SRINIVAS V Date: Thu, 28 Dec 2017 12:23:54 +0530 Subject: Removal of useless parenthesis Change-Id: I27289de2837414d45efcdd3f617d2b399a8f8ac6 Issue-ID: CCSDK-151 Signed-off-by: SRINIVAS V --- .../onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index 39ed39676..0db96f54b 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -845,15 +845,15 @@ public class SdncUebCallback implements INotificationCallback { LOG.error("Unexpected file contents - root tag is "+rootName); } - return(mapEntry); + return mapEntry; } else { LOG.error("Cannot get root tag from file"); - return(null); + return null; } } catch (Exception e) { LOG.error("Could not parse YANG_XML file "+spoolFile.getName(), e); - return(null); + return null; } } @@ -922,7 +922,7 @@ public class SdncUebCallback implements INotificationCallback { } } catch (Exception e) { LOG.error("Could not process spool file "+artifact.getFile().getName(), e); - return(DistributionStatusEnum.DEPLOY_ERROR); + return DistributionStatusEnum.DEPLOY_ERROR; } msgBuffer.append("\n"); @@ -966,7 +966,7 @@ public class SdncUebCallback implements INotificationCallback { - return(deployResult); + return deployResult; } @@ -977,7 +977,7 @@ public class SdncUebCallback implements INotificationCallback { final IDistributionClient client, final INotificationData data, final IArtifactInfo relevantArtifact, final DistributionStatusEnum status) { - IDistributionStatusMessage statusMessage = new IDistributionStatusMessage() { + IDistributionStatusMessage statusMessage = new IDistributionStatusMessage() { @Override public long getTimestamp() { -- cgit 1.2.3-korg From ed713dafb77bb57b62ed8eb7da4a1364dca0ad17 Mon Sep 17 00:00:00 2001 From: "prakash.e" Date: Tue, 2 Jan 2018 11:55:42 +0530 Subject: Removal of unused variable Change-Id: Idaf07c98ef0fef3923ddd7a9e185b727cb93b16f Issue-ID: CCSDK-151 Signed-off-by: prakash.e --- .../sli/northbound/uebclient/SdncUebCallback.java | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index 0db96f54b..89459bcdf 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -266,7 +266,7 @@ public class SdncUebCallback implements INotificationCallback { LOG.info("Received artifact " + curArtifact.getArtifactName()); - handleArtifact(data, data.getServiceName(), null, null, curArtifact, incomingDir, archiveDir); + handleArtifact(data, data.getServiceName(), null, curArtifact, incomingDir, archiveDir); } } @@ -295,7 +295,7 @@ public class SdncUebCallback implements INotificationCallback { LOG.info("Received artifact " + curArtifact.getArtifactName()); - handleArtifact(data, data.getServiceName(), curResource.getResourceName(), curResource.getResourceType(), curArtifact, incomingDir, archiveDir); + handleArtifact(data, data.getServiceName(), curResource.getResourceName(), curArtifact, incomingDir, archiveDir); } } } @@ -367,8 +367,7 @@ public class SdncUebCallback implements INotificationCallback { IArtifactInfo artifactInfo = artifact.getArtifactInfo(); if ((artifactInfo != null) && (data != null)) { - IDistributionClientResult deploymentStatus; - deploymentStatus = client.sendDeploymentStatus(buildStatusMessage( + client.sendDeploymentStatus(buildStatusMessage( client, data, artifactInfo, deployResult)); } @@ -378,7 +377,7 @@ public class SdncUebCallback implements INotificationCallback { } } - private void handleArtifact(INotificationData data, String svcName, String resourceName, String resourceType, + private void handleArtifact(INotificationData data, String svcName, String resourceName, IArtifactInfo artifact, File incomingDir, File archiveDir) { // Download Artifact @@ -438,22 +437,21 @@ public class SdncUebCallback implements INotificationCallback { private void handleFailedDownload(INotificationData data, IArtifactInfo relevantArtifact) { // Send Download Status - IDistributionClientResult sendDownloadStatus = client - .sendDownloadStatus(buildStatusMessage(client, data, + client.sendDownloadStatus(buildStatusMessage(client, data, relevantArtifact, DistributionStatusEnum.DOWNLOAD_ERROR)); } private void handleSuccessfulDownload(INotificationData data, String svcName, String resourceName, - IArtifactInfo artifact, File spoolFile, File archiveDir) { + IArtifactInfo artifact, File inpSpoolFile, File archiveDir) { if ((data != null) && (artifact != null)) { // Send Download Status - IDistributionClientResult sendDownloadStatus = client - .sendDownloadStatus(buildStatusMessage(client, data, artifact, DistributionStatusEnum.DOWNLOAD_OK)); + client.sendDownloadStatus(buildStatusMessage(client, data, artifact, DistributionStatusEnum.DOWNLOAD_OK)); } // If an override file exists, read that instead of the file we just downloaded ArtifactTypeEnum artifactEnum = ArtifactTypeEnum.YANG_XML; + File spoolFile = inpSpoolFile; boolean toscaCsarType = false; if (artifact != null) { @@ -478,7 +476,7 @@ public class SdncUebCallback implements INotificationCallback { } if (toscaCsarType) { - processToscaCsar (data, svcName, resourceName, artifact, spoolFile, archiveDir); + processToscaCsar (data, resourceName, artifact, spoolFile, archiveDir); try { Path source = spoolFile.toPath(); @@ -544,7 +542,7 @@ public class SdncUebCallback implements INotificationCallback { } - private void processToscaCsar(INotificationData data, String svcName, String resourceName, + private void processToscaCsar(INotificationData data, String resourceName, IArtifactInfo artifact, File spoolFile, File archiveDir) { // Use ASDC Dist Client 1.1.5 with TOSCA parsing APIs to extract relevant TOSCA model data -- cgit 1.2.3-korg From df299c18dc8c00878dccdf3086556a08ca202896 Mon Sep 17 00:00:00 2001 From: "prakash.e" Date: Tue, 2 Jan 2018 12:48:58 +0530 Subject: Exception issue fix Change-Id: I75eafe5267909dc1102287ef9bc8dffdb1d5dcba Issue-ID: CCSDK-151 Signed-off-by: prakash.e --- .../sli/northbound/uebclient/SdncUebCallback.java | 35 +++++++++++----------- 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index 89459bcdf..b9df86ef3 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -325,18 +325,16 @@ public class SdncUebCallback implements INotificationCallback { archiveDir.mkdirs(); } } - - String curFileName = ""; + LOG.debug("Scanning {} - {} for downloaded files", incomingDir.getPath(), incomingDir.toPath()); try (DirectoryStream stream = Files.newDirectoryStream(incomingDir.toPath())) { for (Path file: stream) { - curFileName = file.toString(); handleSuccessfulDownload(null,null, null, null, file.toFile(), archiveDir); } - } catch (Exception x) { + } catch (IOException x) { // IOException can never be thrown by the iteration. // In this snippet, it can only be thrown by newDirectoryStream. - LOG.warn("Cannot process spool file {}", curFileName, x); + LOG.warn("Cannot process spool file", x); } // Deploy scheduled deployments @@ -856,23 +854,24 @@ public class SdncUebCallback implements INotificationCallback { } private void scheduleDeployment(SdncArtifactType type, String svcName, String resourceName, IArtifactInfo artifactInfo, String spoolFileName, File spoolFile) { + if (deployList != null) { + if (type.getPass() < deployList.length) { - if (type.getPass() < deployList.length) { - - if (artifactInfo != null) { - LOG.debug("Scheduling "+artifactInfo.getArtifactName()+" version "+artifactInfo.getArtifactVersion()+" for deployment"); + if (artifactInfo != null) { + LOG.debug("Scheduling "+artifactInfo.getArtifactName()+" version "+artifactInfo.getArtifactVersion()+" for deployment"); - deployList[type.getPass()].add(new DeployableArtifact(type, svcName, resourceName, artifactInfo, spoolFile)); + deployList[type.getPass()].add(new DeployableArtifact(type, svcName, resourceName, artifactInfo, spoolFile)); + } else { + SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss.SSS");//dd/MM/yyyy + Date now = new Date(); + String artifactVersion = sdfDate.format(now); + LOG.debug("Scheduling "+spoolFileName+" version "+artifactVersion+" for deployment"); + deployList[type.getPass()].add(new DeployableArtifact(type, svcName, resourceName, spoolFileName, + artifactVersion, spoolFile)); + } } else { - SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss.SSS");//dd/MM/yyyy - Date now = new Date(); - String artifactVersion = sdfDate.format(now); - LOG.debug("Scheduling "+spoolFileName+" version "+artifactVersion+" for deployment"); - deployList[type.getPass()].add(new DeployableArtifact(type, svcName, resourceName, spoolFileName, - artifactVersion, spoolFile)); + LOG.info("Pass for type "+type.getTag()+" is "+type.getPass()+" which is not <= "+deployList.length); } - } else { - LOG.info("Pass for type "+type.getTag()+" is "+type.getPass()+" which is not <= "+deployList.length); } } -- cgit 1.2.3-korg From 3908e30b9e7dcabe942dc60a4894b332c028141b Mon Sep 17 00:00:00 2001 From: SRINIVAS V Date: Fri, 29 Dec 2017 16:11:33 +0530 Subject: Fixed as per Java Code Conventions Change-Id: I0b2315c4a48b5c1c267dec10ce22ded559c98192 Issue-ID: CCSDK-151 Signed-off-by: SRINIVAS V --- .../java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index b9df86ef3..36a3392ac 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -572,7 +572,7 @@ public class SdncUebCallback implements INotificationCallback { insertToscaData(serviceModel.getSql(model_yaml)); } catch (IOException e) { LOG.error("Could not insert Tosca YAML data into the SERVICE_MODEL table ", e); - // return; + } // Ingest Network (VL) Data - 1707 -- cgit 1.2.3-korg From 477fa7f6a778173e15aaf3cb2f795cdbec85e13a Mon Sep 17 00:00:00 2001 From: SRINIVAS V Date: Thu, 4 Jan 2018 21:57:52 +0530 Subject: Removed unused code *Deleted commented code Change-Id: I03ebfab9d66f2a9e51233ec6312698af7ed91584 Issue-ID: CCSDK-151 Signed-off-by: SRINIVAS V --- .../sli/northbound/uebclient/SdncUebCallback.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index 36a3392ac..a876ec524 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -576,7 +576,6 @@ public class SdncUebCallback implements INotificationCallback { } // Ingest Network (VL) Data - 1707 - //List vlNodeTemplatesList = sdcCsarHelper.getServiceNodeTemplatesByType("VL"); List vlNodeTemplatesList = sdcCsarHelper.getServiceVlList(); for (NodeTemplate nodeTemplate : vlNodeTemplatesList) { @@ -613,7 +612,6 @@ public class SdncUebCallback implements INotificationCallback { } // Ingest Network (VF) Data - 1707 - //List nodeTemplatesList = sdcCsarHelper.getServiceNodeTemplatesByType("VF"); List vfNodeTemplatesList = sdcCsarHelper.getServiceVfList(); for (NodeTemplate nodeTemplate : vfNodeTemplatesList) { @@ -641,7 +639,6 @@ public class SdncUebCallback implements INotificationCallback { } // For each VF Module, get the VFC list, insert VF_MODULE_TO_VFC_MAPPING data - // List groupMembers = sdcCsarHelper.getMembersOfGroup(group); - old version // For each vfcNode (group member) in the groupMembers list, extract vm_type and vm_count. // Insert vf_module.customizationUUID, vfcNode.customizationUUID and vm_type and vm_count into VF_MODULE_TO_VFC_MAPPING List groupMembers = sdcCsarHelper.getMembersOfVfModule(nodeTemplate, group); // not yet available @@ -706,12 +703,11 @@ public class SdncUebCallback implements INotificationCallback { // extract values from the left "CP" Node SdncBaseModel.addParameter("ipv4_use_dhcp", SdncBaseModel.extractBooleanValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_DHCPENABLED), mappingParams); - //SdncBaseModel.addParameter("ipv4_ip_version", SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_IPVERSION), mappingParams); + SdncBaseModel.addParameter("ipv4_ip_version", "dummy_ipv4_vers", mappingParams); SdncBaseModel.addParameter("ipv6_use_dhcp", SdncBaseModel.extractBooleanValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_DHCPENABLED), mappingParams); - //SdncBaseModel.addParameter("ipv6_ip_version", SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_IPVERSION), mappingParams); + SdncBaseModel.addParameter("ipv6_ip_version", "dummy_ipv6_vers", mappingParams); - //String extcp_subnetpool_id = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_SUBNETPOOLID) + "\""; // need path to subnetpoolid // extract values from the right "VFC" Node String vfcCustomizationUuid = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, match.getRight().getMetaData(), "customization_uuid") + "\""; @@ -816,7 +812,7 @@ public class SdncUebCallback implements INotificationCallback { if (artifactType != ArtifactTypeEnum.YANG_XML) { LOG.error("Unexpected artifact type - expecting YANG_XML, got "+artifactType); - return (null); + return null; } // Examine outer tag @@ -1025,7 +1021,7 @@ public class SdncUebCallback implements INotificationCallback { conn.setDoOutput(true); conn.setUseCaches(false); - return(conn); + return conn; } @@ -1046,7 +1042,7 @@ public class SdncUebCallback implements INotificationCallback { LOG.error("Caught exception posting to ODL tier", e); } - return(response); + return response; } @@ -1090,7 +1086,7 @@ public class SdncUebCallback implements INotificationCallback { // After transformations, parse transformed XML - return(outFile); + return outFile; } private String escapeFilename(String str) { @@ -1107,7 +1103,7 @@ public class SdncUebCallback implements INotificationCallback { } } - return(retval.toString()); + return retval.toString(); } -- cgit 1.2.3-korg From ef57280a782d3d009bcaa2481c9f26b2b7e1b877 Mon Sep 17 00:00:00 2001 From: SRINIVAS V Date: Sat, 6 Jan 2018 22:37:33 +0530 Subject: Fixed as per Java Code Conventions *Removed the commented code of addParameter function *Code optimized Change-Id: Ibd711561d1f94854df464d6e94de6ef2fc8b6cd6 Issue-ID: CCSDK-151 Signed-off-by: SRINIVAS V --- .../java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java | 6 +----- .../java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java | 2 -- 2 files changed, 1 insertion(+), 7 deletions(-) (limited to 'ueb-listener/src') diff --git a/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java index 7f830bcc8..0c2ce2fc2 100644 --- a/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java +++ b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java @@ -189,11 +189,7 @@ public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { } - if (data.isPresent()) { - return true; - } else { - return false; - } + return data.isPresent(); } protected void addArtifactVersion(String aName, String aVersion) { diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java index b26c50fb2..65215593a 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java @@ -43,8 +43,6 @@ public class SdncARModel extends SdncBaseModel { addParameter("type", extractValue (nodeTemplate, "nf_type")); addParameter("ecomp_generated_naming", extractBooleanValue (nodeTemplate, "nf_naming#ecomp_generated_naming")); addParameter("naming_policy", extractValue (nodeTemplate, "nf_naming#naming_policy")); - //addParameter("depending_service", extractValue (sdcCsarHelper, nodeTemplate, SdcPropertyNames.PROPERTY_NAME_DEPENDINGSERVICE)); - //addParameter("service_dependency", extractValue (sdcCsarHelper, nodeTemplate, SdcPropertyNames.PROPERTY_NAME_SERVICEDEPENDENCY)); } } -- cgit 1.2.3-korg From 25a55717cf3d16c3bbaf0efdf197e5ccd68123da Mon Sep 17 00:00:00 2001 From: "prakash.e" Date: Fri, 5 Jan 2018 12:15:29 +0530 Subject: Exception issue *deployList is used before initialization which results in NullPointer Exception. Change-Id: I53d43d7656577368ac35db78ba27c015a2c8ac52 Issue-ID: CCSDK-170 Signed-off-by: prakash.e --- .../sli/northbound/uebclient/SdncUebCallback.java | 43 +++++++++++----------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index b9df86ef3..35e62f88c 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -326,6 +326,15 @@ public class SdncUebCallback implements INotificationCallback { } } + // Deploy scheduled deployments + int numPasses = config.getMaxPasses(); + + deployList = new LinkedList[numPasses]; + + for (int i = 0 ; i < numPasses ; i++) { + deployList[i] = new LinkedList<>(); + } + LOG.debug("Scanning {} - {} for downloaded files", incomingDir.getPath(), incomingDir.toPath()); try (DirectoryStream stream = Files.newDirectoryStream(incomingDir.toPath())) { for (Path file: stream) { @@ -337,14 +346,6 @@ public class SdncUebCallback implements INotificationCallback { LOG.warn("Cannot process spool file", x); } - // Deploy scheduled deployments - int numPasses = config.getMaxPasses(); - - deployList = new LinkedList[numPasses]; - - for (int i = 0 ; i < numPasses ; i++) { - deployList[i] = new LinkedList<>(); - } for (int pass = 0 ; pass < config.getMaxPasses() ; pass++) { if (deployList[pass] != null) { @@ -854,24 +855,22 @@ public class SdncUebCallback implements INotificationCallback { } private void scheduleDeployment(SdncArtifactType type, String svcName, String resourceName, IArtifactInfo artifactInfo, String spoolFileName, File spoolFile) { - if (deployList != null) { - if (type.getPass() < deployList.length) { + if (type.getPass() < deployList.length) { - if (artifactInfo != null) { - LOG.debug("Scheduling "+artifactInfo.getArtifactName()+" version "+artifactInfo.getArtifactVersion()+" for deployment"); + if (artifactInfo != null) { + LOG.debug("Scheduling " + artifactInfo.getArtifactName() + " version " + artifactInfo.getArtifactVersion() + " for deployment"); - deployList[type.getPass()].add(new DeployableArtifact(type, svcName, resourceName, artifactInfo, spoolFile)); - } else { - SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss.SSS");//dd/MM/yyyy - Date now = new Date(); - String artifactVersion = sdfDate.format(now); - LOG.debug("Scheduling "+spoolFileName+" version "+artifactVersion+" for deployment"); - deployList[type.getPass()].add(new DeployableArtifact(type, svcName, resourceName, spoolFileName, - artifactVersion, spoolFile)); - } + deployList[type.getPass()].add(new org.onap.ccsdk.sli.northbound.uebclient.SdncUebCallback.DeployableArtifact(type, svcName, resourceName, artifactInfo, spoolFile)); } else { - LOG.info("Pass for type "+type.getTag()+" is "+type.getPass()+" which is not <= "+deployList.length); + SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss.SSS");//dd/MM/yyyy + Date now = new Date(); + String artifactVersion = sdfDate.format(now); + LOG.debug("Scheduling " + spoolFileName + " version " + artifactVersion + " for deployment"); + deployList[type.getPass()].add(new org.onap.ccsdk.sli.northbound.uebclient.SdncUebCallback.DeployableArtifact(type, svcName, resourceName, spoolFileName, + artifactVersion, spoolFile)); } + } else { + LOG.info("Pass for type " + type.getTag() + " is " + type.getPass() + " which is not <= " + deployList.length); } } -- cgit 1.2.3-korg From 8c449d91d0271d1119a40b1d693ef21154508ce1 Mon Sep 17 00:00:00 2001 From: "prakash.e" Date: Tue, 9 Jan 2018 21:14:18 +0530 Subject: Removal of unused variables *Romoved unused variables and code changes for performance improvement Change-Id: Ibe1993b750653d24379ffcc3638b71f6cefcaa6b Issue-ID: CCSDK-151 Signed-off-by: prakash.e --- .../org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index 5041b4dc3..7c4f35a6f 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -875,7 +875,7 @@ public class SdncUebCallback implements INotificationCallback { DistributionStatusEnum deployResult; - StringBuffer msgBuffer = new StringBuffer(); + StringBuilder msgBuffer = new StringBuilder(); String namespace = config.getAsdcApiNamespace(); @@ -1047,8 +1047,6 @@ public class SdncUebCallback implements INotificationCallback { private File applyXslts(File srcFile) { - Document doc; - File inFile = srcFile; File outFile = null; @@ -1093,7 +1091,7 @@ public class SdncUebCallback implements INotificationCallback { if (str == null) { str = ""; } - StringBuffer retval = new StringBuffer(); + StringBuilder retval = new StringBuilder(); for (int i = 0 ; i < str.length() ; i++) { char curchar = str.charAt(i); -- cgit 1.2.3-korg From 0b8794f5ef4c0d4bdd6fff4d8bb83bfebc6f8744 Mon Sep 17 00:00:00 2001 From: "prakash.e" Date: Tue, 9 Jan 2018 21:27:21 +0530 Subject: Removed of unused parameter *unused parameter and unused function is removed Change-Id: Ibf0f72d2948ad27313967ecadfb54f2a2bf0060b Issue-ID: CCSDK-151 Signed-off-by: prakash.e --- .../org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index 7c4f35a6f..cf6a2ab25 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -223,10 +223,6 @@ public class SdncUebCallback implements INotificationCallback { } } - private static void loadArtifactMap() { - - } - public SdncUebCallback(IDistributionClient client, SdncUebConfiguration config) { this.client = client; this.config = config; @@ -475,7 +471,7 @@ public class SdncUebCallback implements INotificationCallback { } if (toscaCsarType) { - processToscaCsar (data, resourceName, artifact, spoolFile, archiveDir); + processToscaCsar (data, artifact, spoolFile, archiveDir); try { Path source = spoolFile.toPath(); @@ -541,7 +537,7 @@ public class SdncUebCallback implements INotificationCallback { } - private void processToscaCsar(INotificationData data, String resourceName, + private void processToscaCsar(INotificationData data, IArtifactInfo artifact, File spoolFile, File archiveDir) { // Use ASDC Dist Client 1.1.5 with TOSCA parsing APIs to extract relevant TOSCA model data -- cgit 1.2.3-korg From 7dee0c8d2680888271da556fedc7ea0d0bc773f9 Mon Sep 17 00:00:00 2001 From: "shashikanth.vh" Date: Tue, 27 Mar 2018 19:17:33 +0530 Subject: SdncOdlConnection coverage Coverage improvement for SdncOdlConnection https://jira.onap.org/browse/CCSDK-213?jql=project%20%3D%20CCSDK%20AND%20text%20~%20coverage Issue-ID: CCSDK-213 Change-Id: I8045722de77e8884be485bd6f1ed2243c08d2d2b Signed-off-by: shashikanth.vh --- .../dmaapclient/TestSdncOdlConnection.java | 26 +++++++++++++ .../uebclient/TestSdncOdlConnection.java | 45 ++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncOdlConnection.java create mode 100644 ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncOdlConnection.java (limited to 'ueb-listener/src') diff --git a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncOdlConnection.java b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncOdlConnection.java new file mode 100644 index 000000000..db24a4545 --- /dev/null +++ b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncOdlConnection.java @@ -0,0 +1,26 @@ +package org.onap.ccsdk.sli.northbound.dmaapclient; + +import org.junit.Test; + +import java.io.IOException; +import java.net.ConnectException; + +public class TestSdncOdlConnection { + + @Test + public void test() { + + try { + SdncOdlConnection sdncOdlConnection = SdncOdlConnection.newInstance("https://127.0.0.1:8447/aai/v11/network/pnfs/pnf/a8098c1a-f86e-11da-bd1a-00112444be1e", "", ""); + sdncOdlConnection.send("PUT", "application/json", "{\n" + + " \"input\" : { \n" + + " }\n" + + "}"); + } catch (ConnectException e) { + //Connection exception + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncOdlConnection.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncOdlConnection.java new file mode 100644 index 000000000..1fac0c299 --- /dev/null +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncOdlConnection.java @@ -0,0 +1,45 @@ +package org.onap.ccsdk.sli.northbound.uebclient; + +import ch.vorburger.mariadb4j.DB; +import ch.vorburger.mariadb4j.DBConfigurationBuilder; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; +import org.openecomp.sdc.api.IDistributionClient; +import org.openecomp.sdc.api.notification.INotificationData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.ConnectException; +import java.net.URL; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.util.Properties; + +import static org.mockito.Mockito.mock; + +public class TestSdncOdlConnection { + + @Test + public void test() { + + try { + SdncOdlConnection sdncOdlConnection = SdncOdlConnection.newInstance("https://127.0.0.1:8447/aai/v11/network/pnfs/pnf/a8098c1a-f86e-11da-bd1a-00112444be1e", "", ""); + sdncOdlConnection.send("PUT", "application/json", "{\n" + + " \"input\" : { \n" + + " }\n" + + "}"); + } catch (ConnectException e) { + //Connection exception + } catch (IOException e) { + e.printStackTrace(); + } + } + +} -- cgit 1.2.3-korg From 7fc8f9fe913e35121c8e9f6e222c9b741beefdda Mon Sep 17 00:00:00 2001 From: "shashikanth.vh" Date: Wed, 28 Mar 2018 17:32:01 +0530 Subject: coverage SdncAaiDmaapConsumer Coverage improvement for SdncAaiDmaapConsumer https://jira.onap.org/browse/CCSDK-213?jql=project%20%3D%20CCSDK%20AND%20text%20~%20coverage Issue-ID: CCSDK-213 Change-Id: Icc9af3a9f27d4bae543525b5651d1f6485ef8857 Signed-off-by: shashikanth.vh --- .../dmaapclient/TestSdncPserverDmaapReceiver.java | 90 +++++++++++++++++++++ .../incoming/src_test_resources_csars_nsepc.csar | Bin 0 -> 42569 bytes 2 files changed, 90 insertions(+) create mode 100644 ueb-listener/src/test/resources/incoming/src_test_resources_csars_nsepc.csar (limited to 'ueb-listener/src') diff --git a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncPserverDmaapReceiver.java b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncPserverDmaapReceiver.java index db7cbd72c..963b20d68 100644 --- a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncPserverDmaapReceiver.java +++ b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncPserverDmaapReceiver.java @@ -10,8 +10,15 @@ package org.onap.ccsdk.sli.northbound.dmaapclient; import static org.junit.Assert.assertTrue; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.util.Map; import java.util.Properties; +import org.apache.commons.io.FileUtils; + import org.junit.Before; import org.junit.Test; @@ -81,5 +88,88 @@ public class TestSdncPserverDmaapReceiver { assertTrue(rpcMsgbody.indexOf("common-header") != -1); } + @Test + public void testProcessMsgFieldMap() throws Exception { + + + String DMAAPLISTENERROOT = "DMAAPLISTENERROOT"; + File directory = new File("lib"); + + if (! directory.exists()){ + directory.mkdir(); + } + + File source = new File("src/main/resources"); + File dest = new File("lib/"); + try { + FileUtils.copyDirectory(source, dest); + } catch (IOException e) { + e.printStackTrace(); + } + + try { + Map env = System.getenv(); + Class cl = env.getClass(); + Field field = cl.getDeclaredField("m"); + field.setAccessible(true); + Map writableEnv = (Map) field.get(env); + writableEnv.put(DMAAPLISTENERROOT, "."); + } catch (Exception e) { + throw new IllegalStateException("Failed to set environment variable", e); + } + Properties props = new Properties(); + + SdncAaiDmaapConsumer consumer = new SdncAaiDmaapConsumer(); + + InputStream propStr = TestSdncPserverDmaapReceiver.class.getResourceAsStream("/dmaap-consumer-pserver.properties"); + + + props.load(propStr); + + consumer.init(props, "src/test/resources/dmaap-consumer-pserver.properties"); + consumer.processMsg(aaiInput); + } + + @Test(expected = InvalidMessageException.class) + public void testProcessMsgNullMessage() throws Exception { + Properties props = new Properties(); + + SdncAaiDmaapConsumer consumer = new SdncAaiDmaapConsumer(); + consumer.processMsg(null); + } + + @Test(expected = InvalidMessageException.class) + public void testProcessMsgInvalidMessage() throws Exception { + Properties props = new Properties(); + + SdncAaiDmaapConsumer consumer = new SdncAaiDmaapConsumer(); + consumer.processMsg("test"); + } + + @Test + public void testProcessMsgMissingEventHeader() throws Exception { + Properties props = new Properties(); + + SdncAaiDmaapConsumer consumer = new SdncAaiDmaapConsumer(); + consumer.processMsg("{\n" + + " \"input\" : { \n" + + " }\n" + + "}"); + } + + @Test + public void testProcessMsgInvalidEventType() throws Exception { + Properties props = new Properties(); + + String msg = "{\"cambria.partition\": \"AAI\",\r\n" + + " \"event-header\": {\"event-type\": \"TEST-EVENT\"}}"; + + SdncAaiDmaapConsumer consumer = new SdncAaiDmaapConsumer(); + consumer.processMsg(msg); + } + + + + } diff --git a/ueb-listener/src/test/resources/incoming/src_test_resources_csars_nsepc.csar b/ueb-listener/src/test/resources/incoming/src_test_resources_csars_nsepc.csar new file mode 100644 index 000000000..087d8c3d8 Binary files /dev/null and b/ueb-listener/src/test/resources/incoming/src_test_resources_csars_nsepc.csar differ -- cgit 1.2.3-korg From c50170bc44f192a7c8e7efdfc773342d8b5c0437 Mon Sep 17 00:00:00 2001 From: Jeremy Wolf Date: Wed, 28 Mar 2018 17:22:09 +0000 Subject: coverage sli-northbound adding junit test files for AsdcApiSliClient, AsdcApiUtil, DataChangeClient, SdncFlatJsonDmaapConsumer, SdncARModel, SdncNodeModel, SdncVFCModel, SdncVFModuleModel, SdncUebCallback Change-Id: Ia7fb307b84957292f9080654c7ae31992434317f Issue-ID: CCSDK-230 Signed-off-by: Jeremy Wolf --- .../northbound/asdcapi/AsdcApiSliClientTest.java | 59 ++++++++++++++++ .../sli/northbound/asdcapi/AsdcApiUtilTest.java | 15 ++++ .../dataChange/DataChangeClientTest.java | 56 +++++++++++++++ .../dmaapclient/SdncFlatJsonDmaapConsumerTest.java | 41 +++++++++++ .../sli/northbound/uebclient/SdncARModelTest.java | 21 ++++++ .../northbound/uebclient/SdncNodeModelTest.java | 49 +++++++++++++ .../sli/northbound/uebclient/SdncVFCModelTest.java | 36 ++++++++++ .../uebclient/SdncVFModuleModelTest.java | 20 ++++++ .../northbound/uebclient/TestSdncUebCallback.java | 82 +++++++++++++++++++++- 9 files changed, 378 insertions(+), 1 deletion(-) create mode 100644 asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiSliClientTest.java create mode 100644 asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiUtilTest.java create mode 100644 dataChange/provider/src/test/java/org/onap/sdnc/northbound/dataChange/DataChangeClientTest.java create mode 100644 dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumerTest.java create mode 100644 ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java create mode 100644 ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java create mode 100644 ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java create mode 100644 ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java (limited to 'ueb-listener/src') diff --git a/asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiSliClientTest.java b/asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiSliClientTest.java new file mode 100644 index 000000000..5e6a9daf7 --- /dev/null +++ b/asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiSliClientTest.java @@ -0,0 +1,59 @@ +package org.onap.ccsdk.sli.northbound.asdcapi; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +import java.util.Properties; + +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService; + +public class AsdcApiSliClientTest { + Properties mockProp; + Properties propReturn; + AsdcApiSliClient testAsdcApiSliClient; + + @Before + public void setup() { + SvcLogicService mockSvcLogic = mock(SvcLogicService.class); + mockProp = new Properties(); + mockProp.setProperty("test-value1", "value1"); + propReturn = new Properties(); + propReturn.setProperty("SvcLogic.status", "Success"); + propReturn.setProperty("Object1", "value1"); + try { + when(mockSvcLogic.hasGraph("TestModule", "TestRPC", "TestVersion", "TestMode")).thenReturn(true); + when(mockSvcLogic.hasGraph("NotExist", "TestRPC", "TestVersion", "TestMode")).thenReturn(false); + when(mockSvcLogic.execute("TestModule", "TestRPC", "TestVersion", "TestMode", mockProp)).thenReturn(propReturn); + } catch (Exception e) { + System.out.println(e); + } + + testAsdcApiSliClient = new AsdcApiSliClient(mockSvcLogic); + } + + @Test + public void testhasGraphGraphExsists() throws SvcLogicException { + assertTrue(testAsdcApiSliClient.hasGraph("TestModule", "TestRPC", "TestVersion", "TestMode")); + } + + @Test + public void testhasGraphnoGraph() throws SvcLogicException { + assertFalse(testAsdcApiSliClient.hasGraph("NotExist", "TestRPC", "TestVersion", "TestMode")); + } + + @Test + public void testExecutewithSvcLogicSuccess() throws SvcLogicException { + Properties result = testAsdcApiSliClient.execute("TestModule", "TestRPC", "TestVersion", "TestMode", mockProp); + assertEquals(result.getProperty("error-code"), "200"); + } + + @Test + public void testExecutewithSvcLogicFailure500() throws SvcLogicException { + propReturn.setProperty("SvcLogic.status", "failure"); + Properties result = testAsdcApiSliClient.execute("TestModule", "TestRPC", "TestVersion", "TestMode", mockProp); + assertEquals(result.getProperty("error-code"), "500"); + } +} \ No newline at end of file diff --git a/asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiUtilTest.java b/asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiUtilTest.java new file mode 100644 index 000000000..463e5ea0b --- /dev/null +++ b/asdcApi/provider/src/test/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiUtilTest.java @@ -0,0 +1,15 @@ +package org.onap.ccsdk.sli.northbound.asdcapi; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class AsdcApiUtilTest { + + @Test + public void testAsdcApiUtilConstructor() { + AsdcApiUtil asdcApiUtilTest = new AsdcApiUtil(); + assertNotNull(asdcApiUtilTest); + } + +} \ No newline at end of file diff --git a/dataChange/provider/src/test/java/org/onap/sdnc/northbound/dataChange/DataChangeClientTest.java b/dataChange/provider/src/test/java/org/onap/sdnc/northbound/dataChange/DataChangeClientTest.java new file mode 100644 index 000000000..9ba6c8742 --- /dev/null +++ b/dataChange/provider/src/test/java/org/onap/sdnc/northbound/dataChange/DataChangeClientTest.java @@ -0,0 +1,56 @@ +package org.onap.sdnc.northbound.dataChange; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +import java.util.Properties; + +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper; +import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService; +import org.onap.ccsdk.sli.northbound.DataChangeClient; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.datachange.rev150519.DataChangeNotificationOutputBuilder; + +public class DataChangeClientTest { + + SvcLogicService mockSvcLogicService; + String module = "test-module"; + String rpc = "test-rpc"; + String version = "test-version"; + String mode = "test-mode"; + Properties localProp = new Properties(); + + @Before + public void setUp() throws Exception { + mockSvcLogicService = mock(SvcLogicService.class); + when(mockSvcLogicService.hasGraph(module, rpc, version, mode)).thenReturn(true); + } + + @Test + public void testDataChangeClientConstructor() { + DataChangeClient dataChangeClient = new DataChangeClient(mockSvcLogicService); + assertNotNull(dataChangeClient); + } + + @Test + public void testHasGraph() throws SvcLogicException { + DataChangeClient dataChangeClient = new DataChangeClient(mockSvcLogicService); + boolean result = dataChangeClient.hasGraph(module, rpc, version, mode); + assertTrue(result); + } + + @Test + public void testExecuteSvcLogicStatusFailure() throws SvcLogicException { + DataChangeNotificationOutputBuilder serviceData = mock(DataChangeNotificationOutputBuilder.class); + Properties parms = mock(Properties.class); + SvcLogicService svcLogicService = mock(SvcLogicService.class); + Properties properties = new Properties(); + properties.setProperty("SvcLogic.status", "failure"); + when(svcLogicService.execute(module, rpc, version, mode, properties)).thenReturn(properties); + DataChangeClient sliClient = new DataChangeClient(svcLogicService); + Properties prop = sliClient.execute(module, rpc, version, mode, serviceData, properties); + assertTrue(prop != null); + } +} \ No newline at end of file diff --git a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumerTest.java b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumerTest.java new file mode 100644 index 000000000..d1aee634d --- /dev/null +++ b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncFlatJsonDmaapConsumerTest.java @@ -0,0 +1,41 @@ +package org.onap.ccsdk.sli.northbound.dmaapclient; + +import static org.junit.Assert.*; + + +import java.io.File; + +import org.junit.Before; +import org.junit.Test; + +public class SdncFlatJsonDmaapConsumerTest { + + private static final String DMAAP_LISTENER_PROPERTIES = "dmaap-listener.properties"; + private static final String DMAAP_LISTENER_PROPERTIES_DIR = "src/test/resources"; + + SdncFlatJsonDmaapConsumer consumer; + + @Before + public void setUp() throws Exception { + consumer = new SdncFlatJsonDmaapConsumer(); + } + + @Test(expected = InvalidMessageException.class) + public void testProcessMsgString_NullInvalidMessageException() throws InvalidMessageException { + // expected = InvalidMessageException: Null message + consumer.processMsg(null); + } + + @Test(expected = InvalidMessageException.class) + public void testProcessMsgString_UnformatedMessageInvalidMessageException() throws InvalidMessageException { + // expected = InvalidMessageException: Cannot parse json object + consumer.processMsg("TESTING", null); + } + + @Test(expected = InvalidMessageException.class) + public void testing()throws InvalidMessageException { + // Expected = InvalidMessageException: Unable to process message - cannot load field mappings + String msg = "{\"test\":\"string\"}"; + consumer.processMsg(msg, null); + } +} \ No newline at end of file diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java new file mode 100644 index 000000000..0d152e5e0 --- /dev/null +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java @@ -0,0 +1,21 @@ +package org.onap.ccsdk.sli.northbound.uebclient; + + import static org.junit.Assert.*; + import static org.mockito.Mockito.*; + + import org.junit.Test; + import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; + import org.openecomp.sdc.toscaparser.api.NodeTemplate; + + public class SdncARModelTest { + + @Test + public void testSdncARModelConstructor() { + ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); + NodeTemplate nodeTemplate = mock(NodeTemplate.class); + SdncARModel testSdncARModel = new SdncARModel(mockCsarHelper,nodeTemplate); + assertNotNull(testSdncARModel); + } + + } + diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java new file mode 100644 index 000000000..4a66c0201 --- /dev/null +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java @@ -0,0 +1,49 @@ +package org.onap.ccsdk.sli.northbound.uebclient; + +import static org.junit.Assert.*; + +import static org.mockito.Mockito.*; + +import org.junit.Before; +import org.junit.Test; +import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; +import org.openecomp.sdc.toscaparser.api.NodeTemplate; + +public class SdncNodeModelTest { + + SdncNodeModel sdncNodeModel; + + @Before + public void setUp() throws Exception { + ISdcCsarHelper isdcCsarHelper = mock(ISdcCsarHelper.class); + NodeTemplate nodeTemplate = mock(NodeTemplate.class); + sdncNodeModel = new SdncNodeModel(isdcCsarHelper, nodeTemplate); + sdncNodeModel.setServiceUUID("0e8d757f-1c80-40af-85de-31d64f1f5af8"); + sdncNodeModel.setEcompGeneratedNaming("hello-world"); + } + + @Test + public void testGetServiceUUID() { + String result = sdncNodeModel.getServiceUUID(); + assertNotNull(result != null); + } + + @Test + public void testGetEcompGeneratedNaming() { + String result = sdncNodeModel.getEcompGeneratedNaming(); + assertEquals("hello-world", result); + } + + @Test + public void testGetSqlString() { + String result = sdncNodeModel.getSql("TEST-HELLO"); + String test = "INSERT into NETWORK_MODEL (service_uuid, customization_uuid, model_yaml, ecomp_generated_naming) values (0e8d757f-1c80-40af-85de-31d64f1f5af8, \"\", \"TEST-HELLO\", \"hello-world\");"; + assertEquals(test, result); + } + + @Test + public void testGetVpnBindingsSql() { + String result = sdncNodeModel.getVpnBindingsSql(); + assertNotNull(result); + } +} \ No newline at end of file diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java new file mode 100644 index 000000000..d2bafbf42 --- /dev/null +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java @@ -0,0 +1,36 @@ +package org.onap.ccsdk.sli.northbound.uebclient; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + + +import org.junit.Before; +import org.junit.Test; +import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; +import org.openecomp.sdc.toscaparser.api.NodeTemplate; + +public class SdncVFCModelTest { + + SdncVFCModel testSdncVFCModel; + + @Before + public void setup() { + ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); + NodeTemplate mockNodeTemplate = mock(NodeTemplate.class); + testSdncVFCModel = new SdncVFCModel(mockCsarHelper, mockNodeTemplate); + testSdncVFCModel.setVmType("Test-type"); + testSdncVFCModel.setVmCount("5"); + + } + + @Test + public void testSdncVFCModelGetVmType() { + assertEquals(testSdncVFCModel.getVmType(), "Test-type"); + } + + @Test + public void testSdncVFCModelGetVmCount() { + assertEquals(testSdncVFCModel.getVmCount(), "5"); + } + +} \ No newline at end of file diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java new file mode 100644 index 000000000..218554357 --- /dev/null +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java @@ -0,0 +1,20 @@ +package org.onap.ccsdk.sli.northbound.uebclient; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; + +import org.junit.Test; +import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; +import org.openecomp.sdc.toscaparser.api.Group; + +public class SdncVFModuleModelTest { + + @Test + public void testSdncVFModuleModelConstructor() { + Group mockGroup = mock(Group.class); + ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); + SdncVFModuleModel testSdncVFModel = new SdncVFModuleModel(mockCsarHelper, mockGroup); + assertNotNull(testSdncVFModel); + } + +} \ No newline at end of file diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java index 79a598ce5..21854f990 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java @@ -1,6 +1,7 @@ package org.onap.ccsdk.sli.northbound.uebclient; -import static org.mockito.Mockito.mock; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.*; import java.io.File; import java.io.InputStream; @@ -9,6 +10,8 @@ import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; +import java.util.ArrayList; +import java.util.List; import java.util.Properties; import org.junit.After; @@ -16,7 +19,9 @@ import org.junit.Before; import org.junit.Test; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; import org.openecomp.sdc.api.IDistributionClient; +import org.openecomp.sdc.api.notification.IArtifactInfo; import org.openecomp.sdc.api.notification.INotificationData; +import org.openecomp.sdc.api.notification.IResourceInstance; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -149,6 +154,15 @@ public class TestSdncUebCallback { SdncUebConfiguration config; DBResourceManager dblibSvc; DB db; + List processLevelArtifactList; + List serviceLevelArtifactList; + ArrayList resourceList; + IArtifactInfo mockProcessArtifact1; + IArtifactInfo mockProcessArtifact2; + IArtifactInfo mockProcessArtifact3; + IArtifactInfo mockServiceArtifact1; + IResourceInstance resource; + @Before public void setUp() throws Exception { @@ -186,6 +200,42 @@ public class TestSdncUebCallback { dblibSvc.writeData(CRTBL_VF_MODEL, null, null); dblibSvc.writeData(CRTBL_VF_MODULE_MODEL, null, null); dblibSvc.writeData(CRTBL_ALLOTTED_RESOURCE_MODEL, null, null); + + processLevelArtifactList = new ArrayList<>(); + serviceLevelArtifactList = new ArrayList<>(); + resourceList = new ArrayList<>(); + + + mockProcessArtifact1 = mock(IArtifactInfo.class); + when(mockProcessArtifact1.getArtifactName()).thenReturn("mockProcessArtifact1"); + when(mockProcessArtifact1.getArtifactType()).thenReturn("HEAT"); + when(mockProcessArtifact1.getArtifactURL()).thenReturn("https://asdc.sdc.com/v1/catalog/services/srv1/2.0/resources/aaa/1.0/artifacts/aaa.yml"); + when(mockProcessArtifact1.getArtifactChecksum()).thenReturn("123tfg123 1234ftg"); + when(mockProcessArtifact1.getArtifactTimeout()).thenReturn(110); + + mockProcessArtifact2 = mock(IArtifactInfo.class); + when(mockProcessArtifact1.getArtifactName()).thenReturn("mockProcessArtifact2"); + when(mockProcessArtifact1.getArtifactType()).thenReturn("DG_XML"); + when(mockProcessArtifact1.getArtifactURL()).thenReturn("https://asdc.sdc.com/v1/catalog/services/srv1/2.0/resources/aaa/1.0/artifacts/aaa.yml"); + when(mockProcessArtifact1.getArtifactChecksum()).thenReturn("456jhgt 1234ftg"); + when(mockProcessArtifact1.getArtifactTimeout()).thenReturn(110); + + mockProcessArtifact3 = mock(IArtifactInfo.class); + when(mockProcessArtifact1.getArtifactName()).thenReturn("mockProcessArtifact3"); + when(mockProcessArtifact1.getArtifactType()).thenReturn("HEAT"); + when(mockProcessArtifact1.getArtifactURL()).thenReturn("https://asdc.sdc.com/v1/catalog/services/srv1/2.0/resources/aaa/1.0/artifacts/aaa.yml"); + when(mockProcessArtifact1.getArtifactChecksum()).thenReturn("123tfg123 543gtd"); + when(mockProcessArtifact1.getArtifactTimeout()).thenReturn(110); + + + mockServiceArtifact1 = mock(IArtifactInfo.class); + when(mockServiceArtifact1.getArtifactName()).thenReturn("mockProcessArtifact4"); + when(mockServiceArtifact1.getArtifactType()).thenReturn("HEAT"); + when(mockServiceArtifact1.getArtifactURL()).thenReturn("https://asdc.sdc.com/v1/catalog/services/srv1/2.0/resources/aaa/1.0/artifacts/aaa.yml"); + when(mockServiceArtifact1.getArtifactChecksum()).thenReturn("123t3455 543gtd"); + when(mockServiceArtifact1.getArtifactTimeout()).thenReturn(110); + + resource = mock(IResourceInstance.class); } @After @@ -219,5 +269,35 @@ public class TestSdncUebCallback { INotificationData iData = mock(INotificationData.class); cb.activateCallback(iData); } + + + + @Test + public void testServiceAndProcessArtifactsactivateCallback() { + + try { + processLevelArtifactList.add(mockProcessArtifact1); + processLevelArtifactList.add(mockProcessArtifact2); + processLevelArtifactList.add(mockProcessArtifact3); + + resourceList.add(resource); + serviceLevelArtifactList.add(mockServiceArtifact1); + when(resource.getArtifacts()).thenReturn(serviceLevelArtifactList); + when(resource.getResourceName()).thenReturn("Resource_service_name"); + + + IDistributionClient iDistClient1 = mock(IDistributionClient.class); + INotificationData mockData = mock(INotificationData.class); + when(mockData.getResources()).thenReturn(resourceList); + when(mockData.getServiceName()).thenReturn("Test_service_name"); + when(mockData.getServiceArtifacts()).thenReturn(processLevelArtifactList); + + SdncUebCallback cb1 = new SdncUebCallback(iDistClient1, config); + cb1.activateCallback(mockData); + assertTrue(true); + } catch (Exception e) { + assertTrue(false); + } + } } -- cgit 1.2.3-korg From d0bfc56359e3d5a9663ba6e48b7e1d187373d737 Mon Sep 17 00:00:00 2001 From: "Timoney, Dan (dt5972)" Date: Wed, 28 Mar 2018 19:01:21 -0400 Subject: Update versions to resolve security issues Update versions of sdc distribution client and jackson to address security issues. Issue-ID: CCSDK-164 Change-Id: Id02d879e87bb1a957968482578818928b6e3c281 Signed-off-by: Timoney, Dan (dt5972) --- .gitignore | 1 + dmaap-listener/pom.xml | 2 +- ueb-listener/pom.xml | 10 +++--- .../sli/northbound/uebclient/SdncARModel.java | 8 ++--- .../sli/northbound/uebclient/SdncBaseModel.java | 10 +++--- .../sli/northbound/uebclient/SdncNodeModel.java | 6 ++-- .../sli/northbound/uebclient/SdncServiceModel.java | 6 ++-- .../sli/northbound/uebclient/SdncUebCallback.java | 36 +++++++++++----------- .../sli/northbound/uebclient/SdncUebClient.java | 8 ++--- .../northbound/uebclient/SdncUebConfiguration.java | 18 ++++++++++- .../sli/northbound/uebclient/SdncVFCModel.java | 6 ++-- .../sli/northbound/uebclient/SdncVFModel.java | 8 ++--- .../northbound/uebclient/SdncVFModuleModel.java | 6 ++-- .../sli/northbound/uebclient/SdncARModelTest.java | 4 +-- .../northbound/uebclient/SdncNodeModelTest.java | 6 ++-- .../sli/northbound/uebclient/SdncVFCModelTest.java | 6 ++-- .../uebclient/SdncVFModuleModelTest.java | 6 ++-- .../uebclient/TestSdncOdlConnection.java | 4 +-- .../northbound/uebclient/TestSdncUebCallback.java | 8 ++--- 19 files changed, 88 insertions(+), 71 deletions(-) (limited to 'ueb-listener/src') diff --git a/.gitignore b/.gitignore index 8b49fb2aa..d11ed581b 100755 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ MANIFEST.MF ## Misc Ignores (OS specific etc) ## bin/ +lib/ dist *~ *.ipr diff --git a/dmaap-listener/pom.xml b/dmaap-listener/pom.xml index 9c0ced010..75157318f 100755 --- a/dmaap-listener/pom.xml +++ b/dmaap-listener/pom.xml @@ -19,7 +19,7 @@ 1.2.0-SNAPSHOT - 2.9.0.pr1 + 2.9.4 2.0 true /opt/app/dmaap-listener diff --git a/ueb-listener/pom.xml b/ueb-listener/pom.xml index b8ec986c1..4cb118045 100755 --- a/ueb-listener/pom.xml +++ b/ueb-listener/pom.xml @@ -17,9 +17,9 @@ UEB Listener - 1.1.32 - 1.1.32 - 2.9.0.pr1 + 1.3.0 + 1.3.0 + 2.9.4 true /opt/app/ueb-listener yyMMdd-HHmmss @@ -30,13 +30,13 @@ - org.openecomp.sdc.sdc-distribution-client + org.onap.sdc.sdc-distribution-client sdc-distribution-client ${sdc.client.version} compile - org.openecomp.sdc.sdc-tosca + org.onap.sdc.sdc-tosca sdc-tosca ${sdc.tosca.version} compile diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java index 65215593a..f285db162 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java @@ -21,10 +21,10 @@ 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.openecomp.sdc.toscaparser.api.elements.Metadata; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.elements.Metadata; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index c77ad702a..315f3c381 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -24,11 +24,11 @@ package org.onap.ccsdk.sli.northbound.uebclient; import java.util.HashMap; import java.util.Map; -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames; -import org.openecomp.sdc.toscaparser.api.Group; -import org.openecomp.sdc.toscaparser.api.NodeTemplate; -import org.openecomp.sdc.toscaparser.api.elements.Metadata; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; +import org.onap.sdc.toscaparser.api.Group; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.elements.Metadata; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java index 0a4931715..69f378796 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java @@ -21,9 +21,9 @@ 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.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; +import org.onap.sdc.toscaparser.api.NodeTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java index 012c3d9e2..c1efadbdd 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java @@ -21,9 +21,9 @@ 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.elements.Metadata; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; +import org.onap.sdc.toscaparser.api.elements.Metadata; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index cf6a2ab25..8ea041e61 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -62,24 +62,24 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.tuple.Pair; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; import org.onap.ccsdk.sli.northbound.uebclient.SdncArtifactMap.SdncArtifactType; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.consumer.IDistributionStatusMessage; -import org.openecomp.sdc.api.consumer.INotificationCallback; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.notification.IResourceInstance; -import org.openecomp.sdc.api.results.IDistributionClientDownloadResult; -import org.openecomp.sdc.api.results.IDistributionClientResult; -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames; -import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory; -import org.openecomp.sdc.toscaparser.api.Group; -import org.openecomp.sdc.toscaparser.api.NodeTemplate; -import org.openecomp.sdc.toscaparser.api.elements.Metadata; -import org.openecomp.sdc.utils.ArtifactTypeEnum; -import org.openecomp.sdc.utils.DistributionActionResultEnum; -import org.openecomp.sdc.utils.DistributionStatusEnum; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.consumer.IDistributionStatusMessage; +import org.onap.sdc.api.consumer.INotificationCallback; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.notification.IResourceInstance; +import org.onap.sdc.api.results.IDistributionClientDownloadResult; +import org.onap.sdc.api.results.IDistributionClientResult; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; +import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; +import org.onap.sdc.toscaparser.api.Group; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.elements.Metadata; +import org.onap.sdc.utils.ArtifactTypeEnum; +import org.onap.sdc.utils.DistributionActionResultEnum; +import org.onap.sdc.utils.DistributionStatusEnum; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java index 0694a6da7..d37518f1b 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java @@ -21,10 +21,10 @@ package org.onap.ccsdk.sli.northbound.uebclient; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.results.IDistributionClientResult; -import org.openecomp.sdc.impl.DistributionClientFactory; -import org.openecomp.sdc.utils.DistributionActionResultEnum; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.results.IDistributionClientResult; +import org.onap.sdc.impl.DistributionClientFactory; +import org.onap.sdc.utils.DistributionActionResultEnum; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java index bf7dc88a5..0500954de 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java @@ -29,7 +29,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Properties; -import org.openecomp.sdc.api.consumer.IConfiguration; +import org.onap.sdc.api.consumer.IConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,6 +54,7 @@ public class SdncUebConfiguration implements IConfiguration{ private String sdncPasswd = null; private String asdcApiBaseUrl = null; private String asdcApiNamespace = null; + private List msgBusAddress = null; private SdncArtifactMap artifactMap = SdncArtifactMap.getInstance(); @@ -192,6 +193,16 @@ public class SdncUebConfiguration implements IConfiguration{ LOG.warn("artifact-map is unset"); } + msgBusAddress = new LinkedList<>(); + String msgBusAddressStr = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.msg-bus-address"); + if (msgBusAddressStr != null) { + String[] msgBusAddressArray = msgBusAddressStr.split(","); + for (int i = 0 ; i < msgBusAddressArray.length ; i++) { + msgBusAddress.add(msgBusAddressArray[i]); + } + } + + } @Override @@ -297,5 +308,10 @@ public class SdncUebConfiguration implements IConfiguration{ return false; } + @Override + public List getMsgBusAddress() { + return msgBusAddress; + } + } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java index 55814ac3a..d7ed19ea6 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java @@ -21,9 +21,9 @@ 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.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; +import org.onap.sdc.toscaparser.api.NodeTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java index fd71527de..32f25c51d 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java @@ -21,10 +21,10 @@ 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.openecomp.sdc.toscaparser.api.elements.Metadata; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.elements.Metadata; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java index 3663c97c3..60bc3c433 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java @@ -21,9 +21,9 @@ 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.Group; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; +import org.onap.sdc.toscaparser.api.Group; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java index 0d152e5e0..e8c7b1afd 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java @@ -4,8 +4,8 @@ package org.onap.ccsdk.sli.northbound.uebclient; import static org.mockito.Mockito.*; import org.junit.Test; - import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; - import org.openecomp.sdc.toscaparser.api.NodeTemplate; + import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; + import org.onap.sdc.toscaparser.api.NodeTemplate; public class SdncARModelTest { diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java index 4a66c0201..9df89fb24 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java @@ -6,8 +6,8 @@ import static org.mockito.Mockito.*; import org.junit.Before; import org.junit.Test; -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.toscaparser.api.NodeTemplate; public class SdncNodeModelTest { @@ -46,4 +46,4 @@ public class SdncNodeModelTest { String result = sdncNodeModel.getVpnBindingsSql(); assertNotNull(result); } -} \ No newline at end of file +} diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java index d2bafbf42..f03a09fcf 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java @@ -6,8 +6,8 @@ import static org.mockito.Mockito.*; import org.junit.Before; import org.junit.Test; -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.toscaparser.api.NodeTemplate; public class SdncVFCModelTest { @@ -33,4 +33,4 @@ public class SdncVFCModelTest { assertEquals(testSdncVFCModel.getVmCount(), "5"); } -} \ No newline at end of file +} diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java index 218554357..881018ef6 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java @@ -4,8 +4,8 @@ import static org.junit.Assert.*; import static org.mockito.Mockito.mock; import org.junit.Test; -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.toscaparser.api.Group; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.toscaparser.api.Group; public class SdncVFModuleModelTest { @@ -17,4 +17,4 @@ public class SdncVFModuleModelTest { assertNotNull(testSdncVFModel); } -} \ No newline at end of file +} diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncOdlConnection.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncOdlConnection.java index 1fac0c299..1b4b22f42 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncOdlConnection.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncOdlConnection.java @@ -6,8 +6,8 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.notification.INotificationData; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.notification.INotificationData; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java index 21854f990..b53bdb392 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java @@ -18,10 +18,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.notification.IResourceInstance; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.notification.IResourceInstance; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -- cgit 1.2.3-korg From 3afd9abafa26a57f9e7bba57b46c36752aac0280 Mon Sep 17 00:00:00 2001 From: "Timoney, Dan (dt5972)" Date: Tue, 8 May 2018 11:28:38 -0400 Subject: Remove unneeded document from csar Removed unnecessary document with proprietary marking from CSAR test file. Change-Id: I75e3ca5ab75f80bcd9fc21fb9460d833a3c9edb7 Issue-ID: CCSDK-270 Signed-off-by: Timoney, Dan (dt5972) --- .../incoming/src_test_resources_csars_nsepc.csar | Bin 42569 -> 43966 bytes 1 file changed, 0 insertions(+), 0 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/test/resources/incoming/src_test_resources_csars_nsepc.csar b/ueb-listener/src/test/resources/incoming/src_test_resources_csars_nsepc.csar index 087d8c3d8..bb09f1c2f 100644 Binary files a/ueb-listener/src/test/resources/incoming/src_test_resources_csars_nsepc.csar and b/ueb-listener/src/test/resources/incoming/src_test_resources_csars_nsepc.csar differ -- cgit 1.2.3-korg From 1562a37d9b0e5a58cb162c9480f5292ce94f866f Mon Sep 17 00:00:00 2001 From: "Timoney, Dan (dt5972)" Date: Wed, 9 May 2018 16:27:29 -0400 Subject: Add mapping for vm_type_tag If vm_type is not found in CSAR, use vm_type_tag value instead. Change-Id: Ifd73029446d465aad2d9d995559be837f29b97a4 Issue-ID: SDNC-305 Signed-off-by: Timoney, Dan (dt5972) --- .../onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java index d7ed19ea6..a3345c168 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java @@ -8,9 +8,9 @@ * 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. @@ -28,19 +28,22 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SdncVFCModel extends SdncBaseModel { - + private static final Logger LOG = LoggerFactory .getLogger(SdncVFCModel.class); - + private String vmType = null; private String vmCount = null; public SdncVFCModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { super(sdcCsarHelper, nodeTemplate); - + // extract properties vmType = extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VMTYPE); + if ((vmType == null) || (vmType.length() == 0)) { + vmType = extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG); + } //vmCount = extractValue (sdcCsarHelper, nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VMCOUNT); - need path to vm_count vmCount = "1"; addParameter("vm_type", vmType); -- cgit 1.2.3-korg From 12e42ca015ef09b84925cc39a20320ee330bf267 Mon Sep 17 00:00:00 2001 From: "lalena.aria" Date: Fri, 25 May 2018 11:25:37 -0400 Subject: Update ueb-listener VF Model extraction Changes made: Changed the location of extraction for ecomp_generated_naming when populating VF_MOEL table. Change-Id: I14982b4081013702c5e0023205363015199459f6 Issue-ID: SDNC-325 Signed-off-by: lalena.aria --- .../java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java index 32f25c51d..41b43c4c9 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java @@ -44,8 +44,8 @@ public class SdncVFModel extends SdncBaseModel { addParameter("vendor_version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDORRELEASE)); // extract properties - addParameter("ecomp_generated_naming", extractBooleanValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VNFECOMPNAMING_ECOMPGENERATEDNAMING)); - addParameter("naming_policy", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VNFECOMPNAMING_NAMINGPOLICY)); + addParameter("ecomp_generated_naming", extractBooleanValue(nodeTemplate, "nf_naming#ecomp_generated_naming")); + addParameter("naming_policy", extractValue(nodeTemplate, "nf_naming#naming_policy")); addParameter("nf_type", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)); addParameter("nf_role", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)); addParameter("nf_code", extractValue( nodeTemplate, "nf_naming_code")); -- cgit 1.2.3-korg From 16ecee44bc14dcb0a128cfdabf0ae8b17f1db057 Mon Sep 17 00:00:00 2001 From: Arindam Mondal Date: Tue, 10 Jul 2018 15:11:38 +0900 Subject: Sonar issue fix blocker, critical Issue-ID: CCSDK-332 Change-Id: I8741cb5bf68d71f0376105d2b1683ac05534a001 Signed-off-by: Arindam Mondal --- .../ccsdk/sli/northbound/dmaapclient/MessageRouterHttpClient.java | 1 + .../sli/northbound/dmaapclient/MessageRouterHttpClientJdk.java | 1 + .../org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java | 6 ++---- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'ueb-listener/src') diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/MessageRouterHttpClient.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/MessageRouterHttpClient.java index 13146e4ec..c02ec5df3 100644 --- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/MessageRouterHttpClient.java +++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/MessageRouterHttpClient.java @@ -97,6 +97,7 @@ public class MessageRouterHttpClient implements SdncDmaapConsumer { Thread.sleep(fetchPause); } catch (InterruptedException e) { Log.error("Could not sleep thread", e); + Thread.currentThread().interrupt(); } } } diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/MessageRouterHttpClientJdk.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/MessageRouterHttpClientJdk.java index 3336b81f6..a6744045d 100644 --- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/MessageRouterHttpClientJdk.java +++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/MessageRouterHttpClientJdk.java @@ -111,6 +111,7 @@ public class MessageRouterHttpClientJdk implements SdncDmaapConsumer { Thread.sleep(fetchPause); } catch (InterruptedException e) { Log.error("Could not sleep thread", e); + Thread.currentThread().interrupt(); } } } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index 8ea041e61..4ae5acd99 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -399,8 +399,7 @@ public class SdncUebCallback implements INotificationCallback { // Save zip if TOSCA_CSAR if (artifact.getArtifactType().contains("TOSCA_CSAR") || artifact.getArtifactName().contains(".csar")) { - try { - FileOutputStream outFile = new FileOutputStream(incomingDir.getAbsolutePath() + "/" + artifact.getArtifactName()); + try(FileOutputStream outFile = new FileOutputStream(incomingDir.getAbsolutePath() + "/" + artifact.getArtifactName())) { outFile.write(payloadBytes, 0, payloadBytes.length); outFile.close(); writeSucceeded = true; @@ -411,8 +410,7 @@ public class SdncUebCallback implements INotificationCallback { } else { String payload = new String(payloadBytes); - try { - FileWriter spoolFileWriter = new FileWriter(spoolFile); + try(FileWriter spoolFileWriter = new FileWriter(spoolFile)) { spoolFileWriter.write(payload); spoolFileWriter.close(); writeSucceeded = true; -- cgit 1.2.3-korg From 18cc5f6913e7a71df1945e5e29f394b285867cb3 Mon Sep 17 00:00:00 2001 From: "lalena.aria" Date: Wed, 18 Jul 2018 16:16:58 -0400 Subject: Refactor for CCSDK UEB Listener Changes made: Moved DB insertions into model classes. Added SdncGroupModel object. Added policy ingestion in SdncBaseModel. Cleanup in SdncUebCallback. Changed sdc.tosca.version to 1.3.5 in pom.xml. Issue-ID: CCSDK-360 Change-Id: If965c38275a1dc7fc63847d3aa944aed1a6bd1f9 Signed-off-by: lalena.aria --- ueb-listener/pom.xml | 2 +- .../sli/northbound/uebclient/SdncARModel.java | 35 +- .../sli/northbound/uebclient/SdncBaseModel.java | 822 ++++++++++++++++++++- .../sli/northbound/uebclient/SdncGroupModel.java | 81 ++ .../sli/northbound/uebclient/SdncNodeModel.java | 30 +- .../sli/northbound/uebclient/SdncServiceModel.java | 35 +- .../sli/northbound/uebclient/SdncUebCallback.java | 665 ++++++++++------- .../sli/northbound/uebclient/SdncVFCModel.java | 271 ++++++- .../sli/northbound/uebclient/SdncVFModel.java | 280 ++++++- .../northbound/uebclient/SdncVFModuleModel.java | 8 +- .../src/main/resources/normalizeTagNames.xslt | 1 - .../sli/northbound/uebclient/SdncARModelTest.java | 4 +- .../northbound/uebclient/SdncNodeModelTest.java | 4 +- .../sli/northbound/uebclient/SdncVFCModelTest.java | 4 +- .../uebclient/SdncVFModuleModelTest.java | 4 +- .../northbound/uebclient/TestSdncUebCallback.java | 39 +- 16 files changed, 1931 insertions(+), 354 deletions(-) create mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java (limited to 'ueb-listener/src') diff --git a/ueb-listener/pom.xml b/ueb-listener/pom.xml index 205c5c907..f0315a138 100755 --- a/ueb-listener/pom.xml +++ b/ueb-listener/pom.xml @@ -18,7 +18,7 @@ 1.3.0 - 1.3.0 + 1.3.5 2.9.4 true /opt/app/ueb-listener diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java index f285db162..adb82c6dd 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java @@ -21,21 +21,33 @@ package org.onap.ccsdk.sli.northbound.uebclient; +import java.io.IOException; +import java.util.List; + import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; import org.onap.sdc.toscaparser.api.NodeTemplate; import org.onap.sdc.toscaparser.api.elements.Metadata; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SdncARModel extends SdncBaseModel { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncARModel.class); - public SdncARModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { + private String type = null; + private String subcategory = null; - super(sdcCsarHelper, nodeTemplate); + public SdncARModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate,DBResourceManager jdbcDataSource) { + super(sdcCsarHelper, nodeTemplate, jdbcDataSource); + // extract metadata Metadata metadata = nodeTemplate.getMetaData(); + type = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_TYPE); + subcategory = extractValue (metadata, "subcategory"); addParameter("type", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_TYPE)); // extract properties @@ -45,4 +57,23 @@ public class SdncARModel extends SdncBaseModel { addParameter("naming_policy", extractValue (nodeTemplate, "nf_naming#naming_policy")); } + public void insertAllottedResourceModelData () throws IOException { + try { + cleanUpExistingToscaData("ALLOTTED_RESOURCE_MODEL", "customization_uuid", getCustomizationUUID()); + LOG.info("Call insertToscaData for ALLOTTED_RESOURCE_MODEL where customization_uuid = " + getCustomizationUUID()); + insertToscaData(buildSql("ALLOTTED_RESOURCE_MODEL", model_yaml), null); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the ALLOTTED_RESOURCE_MODEL table"); + throw new IOException (e); + } + } + + public String getSubcategory() { + return subcategory; + } + + public void setSubcategory(String subcategory) { + this.subcategory = subcategory; + } + } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index 315f3c381..fd5a29637 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -21,41 +21,78 @@ package org.onap.ccsdk.sli.northbound.uebclient; +import java.io.IOException; +import java.sql.SQLException; +import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; +import javax.sql.rowset.CachedRowSet; + import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; +import org.onap.sdc.toscaparser.api.CapabilityAssignment; +import org.onap.sdc.toscaparser.api.CapabilityAssignments; import org.onap.sdc.toscaparser.api.Group; import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.Policy; +import org.onap.sdc.toscaparser.api.Property; import org.onap.sdc.toscaparser.api.elements.Metadata; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SdncBaseModel { - + + private static final Logger LOG = LoggerFactory + .getLogger(SdncBaseModel.class); + protected String customizationUUID = null; protected String invariantUUID = null; - protected String model_yaml = null; - protected String version = null; + protected String UUID = null; + protected String model_yaml = null; + protected String version = null; + protected String name = null; protected Map params = null; + protected Map attributeValueParams = null; protected ISdcCsarHelper sdcCsarHelper = null; + protected static DBResourceManager jdbcDataSource = null; + protected static SdncUebConfiguration config = null; + protected NodeTemplate nodeTemplate = null; + + public SdncBaseModel(DBResourceManager jdbcDataSource) { + this.jdbcDataSource = jdbcDataSource; + } + + public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, DBResourceManager jdbcDataSource) { + this (sdcCsarHelper, nodeTemplate); + this.sdcCsarHelper = sdcCsarHelper; + this.nodeTemplate = nodeTemplate; + this.jdbcDataSource = jdbcDataSource; + } - public SdncBaseModel() { - + public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, DBResourceManager jdbcDataSource, SdncUebConfiguration config) throws IOException { + this (sdcCsarHelper, nodeTemplate); + this.sdcCsarHelper = sdcCsarHelper; + this.nodeTemplate = nodeTemplate; + this.jdbcDataSource = jdbcDataSource; + this.config = config; } public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata) { - params = new HashMap<>(); + params = new HashMap(); this.sdcCsarHelper = sdcCsarHelper; // extract service metadata invariantUUID = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID); addParameter("invariant_uuid",invariantUUID); addParameter("version",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_VERSION)); - addParameter("name",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_NAME)); + name = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_NAME); + addParameter("name",name); addParameter("description",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); addParameter("type",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_TYPE)); addParameter("category",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_CATEGORY)); @@ -63,34 +100,415 @@ public class SdncBaseModel { public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { - params = new HashMap<>(); + params = new HashMap(); + attributeValueParams = new HashMap(); this.sdcCsarHelper = sdcCsarHelper; + this.nodeTemplate = nodeTemplate; - // extract nodeTemplate metadata + // extract common nodeTemplate metadata Metadata metadata = nodeTemplate.getMetaData(); customizationUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); - addParameter("invariant_uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); - addParameter("uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_UUID)); - addParameter("version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VERSION)); + invariantUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID); + addParameter("invariant_uuid", invariantUUID); + UUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_UUID); + addParameter("uuid", UUID); + addParameter("version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VERSION)); + + // extract common nodeTemplate properties + //addParameter("ecomp_generated_naming", extractValue (nodeTemplate, "naming#ecompnaming")); // should be extractBooleanValue? + //addParameter("naming_policy", extractValue (nodeTemplate, "naming#namingpolicy")); + + } + + public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Group group, SdncUebConfiguration config, DBResourceManager jdbcDataSource) throws IOException { + this (sdcCsarHelper, group); + this.sdcCsarHelper = sdcCsarHelper; + this.config = config; + this.jdbcDataSource = jdbcDataSource; } public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Group group) { - params = new HashMap<>(); + params = new HashMap(); this.sdcCsarHelper = sdcCsarHelper; + attributeValueParams = new HashMap(); // extract group metadata Metadata metadata = group.getMetadata(); //customizationUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULECUSTOMIZATIONUUID); - returning null customizationUUID = extractValue (metadata, "vfModuleModelCustomizationUUID"); - addParameter("invariant_uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)); - addParameter("uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)); - addParameter("version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)); + addParameter("invariant_uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)); + addParameter("uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)); + addParameter("version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)); + } + +/* This is the generic approach Shoujit attempted for 18.06 but can't be implemented without parser API to + * get properties with substring match on the name + * protected void extractRelevantAttributeData(List propList, SdncUebConfiguration config) { + + //List propList = nodeTemplate.getPropertiesObjects(); + for (Property prop : propList) { + String propName = prop.getName(); + Object propValue = prop.getValue(); + + if (propValue instanceof Map) + + LOG.info("Property: propertyName: " + propName + " propertyValue: " + propValue.toString()); + + // Compare this property name with each config.relevant-attribute-name + List attributeNames = config.getRelevantAttributeNames(); + for (String attributeName : attributeNames) { + if (prop.getName().contains(attributeName)) + addParameter(prop.getName(), prop.getValue().toString(), attributeValueParams); + } + + } + + }*/ + + protected void insertRelevantAttributeData() throws IOException{ + + insertRelevantAttributeData(""); + } + + protected void insertRelevantAttributeData(String type) throws IOException{ + + // type can be passed as "group" or taken from the nodeTemplate + String metadataType = ""; + if (!type.isEmpty()) metadataType = type; + else { + Metadata metadata = nodeTemplate.getMetaData(); + metadataType = sdcCsarHelper.getMetadataPropertyValue(metadata, "type"); + } + + // Clean up all attributes for this resource + try { + cleanUpExistingToscaData("ATTRIBUTE_VALUE_PAIR", "resource_uuid", getUUID(), "resource_type", "\"" + metadataType + "\""); + } catch (IOException e) { + LOG.error("Could not cleanup Tosca CSAR data from the ATTRIBUTE_VALUE_PAIR table"); + throw new IOException (e); + } + + for (String paramName : attributeValueParams.keySet()) { + String paramValue = attributeValueParams.get(paramName); + + Map attributeParams = new HashMap(); + addParameter("attribute_name", paramName, attributeParams); + addParameter("attribute_value", paramValue, attributeParams); + addParameter("resource_type", metadataType, attributeParams); + addParameter("resource_customization_uuid", getCustomizationUUID(), attributeParams); + + LOG.info("Call insertToscaData for ATTRIBUTE_VALUE_PAIR where resource_uuid = " + getUUID() + " and attriubute_name = " + paramName); + try { + insertToscaData(buildSql("ATTRIBUTE_VALUE_PAIR", "resource_uuid", getUUID(), model_yaml, attributeParams), null); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the ATTRIBUTE_VALUE_PAIR table"); + throw new IOException (e); + } + } + } + + protected void insertGroupData (NodeTemplate nodeTemplate, NodeTemplate targetNode, String groupType) throws IOException { + + // Get the NetworkCollection groups of the node + Map groupParams = new HashMap(); + List groupList = sdcCsarHelper.getGroupsOfOriginOfNodeTemplateByToscaGroupType(nodeTemplate, groupType); + //List groupList2 = sdcCsarHelper.getGroupsOfTopologyTemplateByToscaGroupType(groupType); // returns nothing + + for (Group group : groupList) { + + // Insert into RESOURCE_GROUP/ATTRIBUTE_VALUE_PAIR and RESOURCE_GROUP_TO_TARGET_NODE_MAPPING + // RESOURCE_GROUP (group metadata): resource_uuid (CR node UUID), uuid, customization_uuid, invariant_uuid, name, version + // ATTRIBUTE_VALUE_PAIR (group properties): group_type, group_role, group_function + // RESOURCE_GROUP_TO_TARGET_NODE_MAPPING: group_uuid, parent_uuid (CR node UUID), target_node_uuid, target_type, table_name + + SdncGroupModel groupModel = new SdncGroupModel (sdcCsarHelper, group, nodeTemplate, config, jdbcDataSource); + groupModel.insertGroupData(nodeTemplate); + + // insert RESOURCE_GROUP_TO_TARGET_NODE_MAPPING + try { + Map mappingCleanupParams = new HashMap(); + addParameter("group_uuid", groupModel.getUUID(), mappingCleanupParams); + addParameter("parent_uuid", extractValue(nodeTemplate.getMetaData(), "UUID"), mappingCleanupParams); + addParameter("target_node_uuid", extractValue(targetNode.getMetaData(), "UUID"), mappingCleanupParams); + cleanupExistingToscaData("RESOURCE_GROUP_TO_TARGET_NODE_MAPPING", mappingCleanupParams); + + Map mappingParams = new HashMap(); + addParameter("parent_uuid", extractValue(nodeTemplate.getMetaData(), "UUID"), mappingParams); + addParameter("target_node_uuid", extractValue(targetNode.getMetaData(), "UUID"), mappingParams); + String targetType = extractValue(targetNode.getMetaData(), "type"); + addParameter("target_type", targetType, mappingParams); + String tableName = ""; + switch (targetType) { + case "CVFC": + tableName = "VFC_MODEL"; + break; + case "VL": + tableName = "NETWORK_MODEL"; + break; + } + addParameter("table_name", tableName, mappingParams); + LOG.info("Call insertToscaData for RESOURCE_GROUP_TO_TARGET_NODE_MAPPING where group_uuid = " + groupModel.getUUID()); + insertToscaData(buildSql("RESOURCE_GROUP_TO_TARGET_NODE_MAPPING", "group_uuid", groupModel.getUUID(), model_yaml, mappingParams), null); + + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the RESOURCE_GROUP_TO_TARGET_NODE_MAPPING"); + throw new IOException (e); + } + } + } + + protected void insertPolicyData (NodeTemplate nodeTemplate, NodeTemplate targetNode, String policyType) throws IOException { + + // Get External policies of the node + List policyList = sdcCsarHelper.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nodeTemplate, policyType); + //List policyList2 = sdcCsarHelper.getPoliciesOfTopologyTemplateByToscaPolicyType(policyType); // returns nothing + //List policyList3 = sdcCsarHelper.getPoliciesOfTargetByToscaPolicyType(nodeTemplate, policyType); // returns nothing + + for (Policy policy : policyList) { + + String resourceUuid = getUUID(); + // extract metadata + //policy.getmetadata(); - NPE + //Metadata metadata = policy.getMetadata(); + + //String policyUuid = extractValue(metadata, "UUID"); + String policyUuid = policy.getMetaData().getOrDefault("UUID", "").toString(); + //String policyInvariantUuid = extractValue(metadata, "invariantUUID"); + String policyInvariantUuid = policy.getMetaData().getOrDefault("invariantUUID", "").toString(); + //String policyCustomizationUuid = extractValue(metadata, "customizationUUID"); + String policyCustomizationUuid = policy.getMetaData().getOrDefault("customizationUUID", "").toString(); + + Map cleanupParams = new HashMap(); + addParameter("resource_uuid", resourceUuid, cleanupParams); + addParameter("policy_uuid", policyUuid, cleanupParams); + addParameter("policy_invariant_uuid", policyInvariantUuid, cleanupParams); + + Map policyParams = new HashMap(); + addParameter("policy_uuid", policyUuid, policyParams); + addParameter("policy_customization_uuid", policyCustomizationUuid, policyParams); + addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams); + //addParameter("policy_name", extractValue(metadata, "name"), policyParams); + addParameter("policy_name", policy.getMetaData().getOrDefault("name", "").toString(), policyParams); + //addParameter("version", extractValue(metadata, "version"), policyParams); + addParameter("version", policy.getMetaData().getOrDefault("version", "").toString(), policyParams); + //addParameter("policy_type", extractValue(metadata, "type"), policyParams); + addParameter("policy_type", policy.getMetaData().getOrDefault("type", "").toString(), policyParams); + + // extract properties + addParameter("property_type", extractValue(policy, "type"), policyParams); + addParameter("property_source", extractValue(policy, "source"), policyParams); + addParameter("property_name", extractValue(policy, "name"), policyParams); + + // Insert into RESOURCE_POLICY and RESOURCE_POLICY_TO_TARGET_NODE_MAPPING + // RESOURCE_POLICY: resource_uuid (CR node UUID), uuid, customization_uuid, invariant_uuid, name, version, policy_type, + // property_type, property_source, property_name + + try { + + // insert into RESOURCE_POLICY + cleanupExistingToscaData("RESOURCE_POLICY", cleanupParams); + LOG.info("Call insertToscaData for RESOURCE_POLICY where resource_uuid = " + resourceUuid + " and policy_uuid = " + policyUuid); + insertToscaData(buildSql("RESOURCE_POLICY", "resource_uuid", resourceUuid, model_yaml, policyParams), null); + + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY table"); + throw new IOException (e); + } + + // insert RESOURCE_POLICY_TO_TARGET_NODE_MAPPING: policy_uuid, parent_uuid (CR node UUID), target_node_uuid, target_type, table_name + try { + Map mappingCleanupParams = new HashMap(); + addParameter("policy_uuid", policyUuid, mappingCleanupParams); + addParameter("parent_uuid", nodeTemplate.getMetaData().getValue("UUID"), mappingCleanupParams); + addParameter("target_node_uuid", targetNode.getMetaData().getValue("UUID"), mappingCleanupParams); + cleanupExistingToscaData("RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", mappingCleanupParams); + + Map mappingParams = new HashMap(); + addParameter("parent_uuid", nodeTemplate.getMetaData().getValue("UUID"), mappingParams); + addParameter("target_node_uuid", targetNode.getMetaData().getValue("UUID"), mappingParams); + addParameter("target_node_customization_uuid", targetNode.getMetaData().getValue("customizationUUID"), mappingParams); + addParameter("policy_customization_uuid", policyCustomizationUuid, mappingParams); + addParameter("target_type", targetNode.getMetaData().getValue("type"), mappingParams); + LOG.info("Call insertToscaData for RESOURCE_POLICY_TO_TARGET_NODE_MAPPING where policy_uuid = " + policyUuid); + insertToscaData(buildSql("RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", "policy_uuid", "\"" + policyUuid + "\"", model_yaml, mappingParams), null); + + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY_TO_TARGET_NODE_MAPPING"); + throw new IOException (e); + } + } + } + + public static void insertPolicyData (ISdcCsarHelper sdcCsarHelper, DBResourceManager jdbcDataSource, String resourceUuid, String parentUuid, String policyType) throws IOException { + + // Get External policies of the node + List policyList = sdcCsarHelper.getPoliciesOfTopologyTemplateByToscaPolicyType(policyType); + + for (Policy policy : policyList) { + + // extract policy metadata + String policyUuid = policy.getMetaData().getOrDefault("UUID", "").toString(); + String policyInvariantUuid = policy.getMetaData().getOrDefault("invariantUUID", "").toString(); + + // insert into RESOURCE_POLICY + Map cleanupParams = new HashMap(); + SdncBaseModel.addParameter("resource_uuid", resourceUuid, cleanupParams); + SdncBaseModel.addParameter("policy_uuid", policyUuid, cleanupParams); + SdncBaseModel.addParameter("policy_invariant_uuid", policyInvariantUuid, cleanupParams); + + Map policyParams = new HashMap(); + SdncBaseModel.addParameter("policy_uuid", policyUuid, policyParams); + SdncBaseModel.addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams); + SdncBaseModel.addParameter("policy_name", policy.getMetaData().getOrDefault("name", "").toString(), policyParams); + SdncBaseModel.addParameter("version", policy.getMetaData().getOrDefault("version", "").toString(), policyParams); + SdncBaseModel.addParameter("policy_type", policy.getType(), policyParams); + + SdncBaseModel.addParameter("property_type", extractValueStatic(policy, "type"), policyParams); + SdncBaseModel.addParameter("property_source", extractValueStatic(policy, "source"), policyParams); + SdncBaseModel.addParameter("property_name", extractValueStatic(policy, "name"), policyParams); + + try { + + // insert into RESOURCE_POLICY + SdncBaseModel.cleanupExistingToscaData(jdbcDataSource, "RESOURCE_POLICY", cleanupParams); + LOG.info("Call insertToscaData for RESOURCE_POLICY where resource_uuid = " + resourceUuid); + insertToscaData(jdbcDataSource, getSql("RESOURCE_POLICY", "resource_uuid", resourceUuid, "", policyParams), null); + + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY table"); + throw new IOException (e); + } + + // insert into RESOURCE_POLICY_TO_TARGET_NODE_MAPPING + List policyTargetNameList = policy.getTargets(); + for (String targetName : policyTargetNameList) { + NodeTemplate targetNode = sdcCsarHelper.getNodeTemplateByName(targetName); + + // extract targetNode metadata UUID and customizationUUID + + // insert into RESOURCE_POLICY_TO_TARGET_NODE_MAPPING + try { + Map mappingCleanupParams = new HashMap(); + addParameter("policy_uuid", policyUuid, mappingCleanupParams); + addParameter("parent_uuid", parentUuid, mappingCleanupParams); + addParameter("target_node_uuid", targetNode.getMetaData().getValue("UUID"), mappingCleanupParams); + SdncBaseModel.cleanupExistingToscaData(jdbcDataSource, "RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", mappingCleanupParams); + + Map mappingParams = new HashMap(); + addParameter("parent_uuid", parentUuid, mappingParams); + addParameter("target_node_uuid", targetNode.getMetaData().getValue("UUID"), mappingParams); + addParameter("target_node_customization_uuid", targetNode.getMetaData().getValue("customizationUUID"), mappingParams); + addParameter("target_type", targetNode.getMetaData().getValue("type"), mappingParams); // type of the target node + LOG.info("Call insertToscaData for RESOURCE_POLICY_TO_TARGET_NODE_MAPPING where policy_uuid = " + policyUuid + " and target_node_uuid = " + targetNode.getMetaData().getValue("UUID")); + SdncBaseModel.insertToscaData(jdbcDataSource, getSql("RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", "policy_uuid", "\"" + policyUuid + "\"", "", mappingParams), null); + + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY_TO_TARGET_NODE_MAPPING"); + throw new IOException (e); + } + + } + } + } + + protected void insertNodeCapabilitiesData (CapabilityAssignments capabilities) throws IOException { + + // Process the capabilities on the node template + + List capabilityList = capabilities.getAll(); + + for (CapabilityAssignment capability : capabilities.getAll()) { + + // Insert into NODE_CAPABILITY: + // capability_id (generated) + // capability_provider_uuid - UUID of this node + // capability_provider_customization_uuid - customization UUID of this node + // capability_name - capability.getName() + // capability_type - ? + + // Check capability name against relevant capabilities + boolean capabilityIsRelevant = false; + /*List relevantCapabilities = config.getRelevantCapabilityNames(); + for (String relevantCapabilityName : relevantCapabilities ) { + + if (capability.getName().toLowerCase().contains(relevantCapabilityName.toLowerCase())) { + capabilityIsRelevant = true; + } + }*/ + + if (capabilityIsRelevant == false){ + continue; + } + + String capabilityProviderUuid = getUUID(); + + Map cleanupParams = new HashMap(); + addParameter("capability_provider_uuid", capabilityProviderUuid, cleanupParams); // node customization UUID + addParameter("capability_provider_customization_uuid", getCustomizationUUIDNoQuotes(), cleanupParams); // node customization UUID + addParameter("capability_name", capability.getName(), cleanupParams); + + Map nodeCapabilityParams = new HashMap(); + addParameter("capability_provider_customization_uuid", getCustomizationUUIDNoQuotes(), nodeCapabilityParams); // node customization UUID + addParameter("capability_name", capability.getName(), nodeCapabilityParams); + addParameter("capability_type", extractValue(capability, "type"), nodeCapabilityParams); + + // Insert NODE_CAPABILITY data for each capability + String capabilityId = ""; + try { + + cleanupExistingToscaData("NODE_CAPABILITY", cleanupParams); // will also delete NODE_CAPABILITY_PROPERTY with same capability_id + LOG.info("Call insertToscaData for NODE_CAPABILITY where capability_provider_uuid = " + capabilityProviderUuid + " and capability_name = " + capability.getName()); + insertToscaData(buildSql("NODE_CAPABILITY", "capability_provider_uuid", capabilityProviderUuid, model_yaml, nodeCapabilityParams), null); + + // Get capabilityId for capability just inserted + CachedRowSet rowData = getToscaData("NODE_CAPABILITY", nodeCapabilityParams); + rowData.first(); + int capabilityIdint = rowData.getInt("capability_id"); + capabilityId = capabilityId.valueOf(capabilityIdint); + + } catch (IOException | SQLException e) { + LOG.error("Could not insert Tosca CSAR data into the NODE_CAPABILITY table"); + throw new IOException (e); + } + + insertNodeCapabilityPropertyData (capability, capabilityId); + } + } + + protected void insertNodeCapabilityPropertyData(CapabilityAssignment capability, String capabilityId) throws IOException { + + // Insert property name / value into NODE_CAPABILITY_PROPERTY + LinkedHashMap propertiesMap = capability.getProperties(); + Map nodeCapabilityPropertyParams = new HashMap(); + + for (String propertyMapKey : propertiesMap.keySet() ) { + //LOG.info("property map key = " + propertyMapKey); + Property property = propertiesMap.get(propertyMapKey); + + addParameter ("capability_property_name", property.getName(), nodeCapabilityPropertyParams); + addParameter ("capability_property_type", property.getValue().toString(), nodeCapabilityPropertyParams); + + try { + // Data from NODE_CAPABILITY_PROPERTY is cleaned up via cascade delete on NODE_CAPABILITY + LOG.info("Call insertToscaData for NODE_CAPABILITY_PROPERTY where capability_id = " + capabilityId + " and property_name = " + property.getName() + ", property_value: " + property.getValue().toString()); + insertToscaData(buildSql("NODE_CAPABILITY_PROPERTY", "capability_id", capabilityId, model_yaml, nodeCapabilityPropertyParams), null); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the NODE_CAPABILITY_PROPERTY table"); + throw new IOException (e); + } + } + } protected void addParameter (String name, String value) { if (value != null && !value.isEmpty()) { - params.put(name, "\"" + value + "\""); + // check if value already contain quotes + if (value.startsWith("\"", 0) && value.endsWith("\"")) { + params.put(name, value); + } else { + params.put(name, "\"" + value + "\""); + } } } @@ -108,7 +526,15 @@ public class SdncBaseModel { public static void addParameter (String name, String value, Map params) { if (value != null && !value.isEmpty()) { - params.put(name, "\"" + value + "\""); + // remove any quotes within the string + String strippedValue = value.replace("\"",""); + + // check if value already contain quotes + if (strippedValue.startsWith("\"", 0) && value.endsWith("\"")) { + params.put(name, strippedValue); + } else { + params.put(name, "\"" + strippedValue + "\""); + } } } @@ -118,6 +544,15 @@ public class SdncBaseModel { return value; } else { return ""; + } + } + + protected String extractBooleanValue (Metadata metadata, String name) { + String value = sdcCsarHelper.getMetadataPropertyValue(metadata, name); + if (value != null && !value.isEmpty()) { + return value.contains("true") ? "Y" : "N"; + } else { + return ""; } } @@ -139,6 +574,78 @@ public class SdncBaseModel { } } + protected String extractGetInputValue (Group group, NodeTemplate nodeTemplate, String name) { + + String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, extractGetInputName (group, name)); + if (value != null) { + return value; + } else { + return ""; + } + } + + protected String extractGetInputName (Group group, String name) { + + String getInputName = name; + String groupProperty = sdcCsarHelper.getGroupPropertyLeafValue(group, name); + if (groupProperty != null) { + int getInputIndex = groupProperty.indexOf("{get_input="); + if (getInputIndex > -1) { + getInputName = groupProperty.substring(getInputIndex+11, groupProperty.length()-1); + } + } + + return getInputName; + + } + + protected String extractGetInputValue (Policy policy, NodeTemplate nodeTemplate, String name) { + + String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, extractGetInputName (policy, name)); + if (value != null) { + return value; + } else { + return ""; + } + } + + protected String extractGetInputName (Policy policy, String name) { + + String getInputName = name; + //String groupProperty = sdcCsarHelper.getPolicyPropertyLeafValue(policy, name); + Map propMap = policy.getPolicyProperties(); + String groupProperty = nullCheck(propMap.get(name)); + if (!groupProperty.isEmpty()) { + int getInputIndex = groupProperty.indexOf("{get_input="); + if (getInputIndex > -1) { + getInputName = groupProperty.substring(getInputIndex+11, groupProperty.length()-1); + } + } + + return getInputName; + + } + + protected String extractValue (Policy policy, String name) { + + Map propMap = policy.getPolicyProperties(); + if (propMap == null) { + return ""; + } else { + return nullCheck(propMap.get(name)); + } + } + + protected static String extractValueStatic (Policy policy, String name) { + + Map propMap = policy.getPolicyProperties(); + if (propMap == null) { + return ""; + } else { + return nullCheckStatic(propMap.get(name)); + } + } + public static String extractValue (ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, String name) { String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); if (value != null) { @@ -148,6 +655,15 @@ public class SdncBaseModel { } } + protected String extractValue (CapabilityAssignment capability, String name) { + String value = sdcCsarHelper.getCapabilityPropertyLeafValue(capability, name); + if (value != null) { + return value; + } else { + return ""; + } + } + protected String extractBooleanValue (NodeTemplate nodeTemplate, String name) { String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); if (value != null && !value.isEmpty()) { @@ -166,6 +682,15 @@ public class SdncBaseModel { } } + protected Object extractObjectValue (NodeTemplate nodeTemplate, String name) { + Object value = sdcCsarHelper.getNodeTemplatePropertyAsObject(nodeTemplate, name); + if (value != null) { + return value; + } else { + return ""; + } + } + protected String extractValue (Group group, String name) { String value = sdcCsarHelper.getGroupPropertyLeafValue(group, name); if (value != null) { @@ -229,18 +754,27 @@ public class SdncBaseModel { } } + protected String getUUID() { + return ("\"" + UUID + "\""); + } + public String getInvariantUUID() { + return ("\"" + invariantUUID + "\""); + } public String getCustomizationUUID() { - return "\"" + customizationUUID + "\""; + return ("\"" + customizationUUID + "\""); } public String getCustomizationUUIDNoQuotes() { - return customizationUUID; + return (customizationUUID); } public void setCustomizationUUID(String customizationUUID) { this.customizationUUID = customizationUUID; } - - public String getSql(String tableName, String model_yaml) { - + public String getName() { + return name; + } + + public String buildSql(String tableName, String model_yaml) { + StringBuilder sb = new StringBuilder(); sb.append("INSERT into " + tableName + " (customization_uuid, model_yaml, "); @@ -254,9 +788,9 @@ public class SdncBaseModel { sb.append(") values (" + getCustomizationUUID() + ", \"" + model_yaml + "\", "); paramCount = 0; - for (Map.Entry entry : params.entrySet()) { + for (String paramKey : params.keySet()) { paramCount++; - String paramValue = entry.getValue(); + String paramValue = params.get(paramKey); sb.append(paramValue); if (paramCount < params.size()) sb.append(", "); } @@ -264,7 +798,33 @@ public class SdncBaseModel { sb.append(");"); return sb.toString(); } + + public String buildSql(String tableName, String keyName, String keyValue, String model_yaml, Map params) { + + StringBuilder sb = new StringBuilder(); + sb.append("INSERT into " + tableName + " (" + keyName + ", "); + + int paramCount = 0; + for (String paramKey : params.keySet()) { + paramCount++; + sb.append(paramKey); + if (paramCount < params.size()) sb.append(", "); + } + + sb.append(") values (" + keyValue + ", "); + + 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 static String getSql(String tableName, String keyName, String keyValue, String model_yaml, Map params) { StringBuilder sb = new StringBuilder(); @@ -280,9 +840,9 @@ public class SdncBaseModel { sb.append(") values (" + keyValue + ", "); paramCount = 0; - for (Map.Entry entry : params.entrySet()) { + for (String paramKey : params.keySet()) { paramCount++; - String paramValue = entry.getValue(); + String paramValue = params.get(paramKey); sb.append(paramValue); if (paramCount < params.size()) sb.append(", "); } @@ -290,5 +850,213 @@ public class SdncBaseModel { sb.append(");"); return sb.toString(); } + + protected void insertToscaData(String toscaDataString, ArrayList arguments) throws IOException + { + LOG.debug("insertToscaData: " + toscaDataString); + + try { + + jdbcDataSource.writeData(toscaDataString, arguments, null); + + } catch (SQLException e) { + LOG.error("Could not insert Tosca data into the database"); + throw new IOException (e); + } + + } + + protected static void insertToscaData(DBResourceManager jdbcDataSource, String toscaDataString, ArrayList arguments) throws IOException + { + LOG.debug("insertToscaData: " + toscaDataString); + + try { + + jdbcDataSource.writeData(toscaDataString, arguments, null); + + } catch (SQLException e) { + LOG.error("Could not insert Tosca data into the database"); + throw new IOException (e); + } + + } + + protected void cleanUpExistingToscaData(String tableName, String keyName, String keyValue) throws IOException + { + + try { + int rowCount = 0; + CachedRowSet data = jdbcDataSource.getData("SELECT * from " + tableName + " where " + keyName + " = " + keyValue + ";", null, ""); + while(data.next()) { + rowCount ++; + } + if (rowCount != 0) { + LOG.debug("cleanUpExistingToscaData from: " + tableName + " for " + keyValue); + jdbcDataSource.writeData("DELETE from " + tableName + " where " + keyName + " = " + keyValue + ";", null, null); + } + + } catch (SQLException e) { + LOG.error("Could not clean up existing " + tableName + " for " + keyValue, e); + } + + } + + protected void cleanUpExistingToscaData(String tableName, String key1Name, String key1Value, String key2Name, String key2Value) throws IOException + { + + try { + int rowCount = 0; + CachedRowSet data = jdbcDataSource.getData("SELECT * from " + tableName + " where " + key1Name + " = " + key1Value + " AND " + key2Name + " = " + key2Value + ";", null, ""); + while(data.next()) { + rowCount ++; + } + if (rowCount != 0) { + LOG.debug("cleanUpExistingToscaData from : " + tableName + " for " + key1Value + " and " + key2Value); + jdbcDataSource.writeData("DELETE from " + tableName + " where " + key1Name + " = " + key1Value + " AND " + key2Name + " = " + key2Value + ";", null, null); + } + + } catch (SQLException e) { + LOG.error("Could not clean up existing " + tableName + " for " + key1Value + " and " + key2Value, e); + } + + } + + protected boolean cleanupExistingToscaData(String tableName, Map keyParams) throws IOException + { + return SdncBaseModel.cleanupExistingToscaData(this.jdbcDataSource, tableName, keyParams); + } + + public static boolean cleanupExistingToscaData(DBResourceManager jdbcDataSource, String tableName, Map keyParams) throws IOException + { + boolean dataExists = false; + StringBuilder sb = new StringBuilder(); + sb.append("SELECT * from " + tableName + " where "); + + int paramCount = 0; + for (String paramKey : keyParams.keySet()) { + paramCount++; + String paramValue = keyParams.get(paramKey); + sb.append(paramKey); + sb.append(" = "); + sb.append(paramValue); + if (paramCount < keyParams.size()) sb.append(" AND "); + } + + sb.append(";"); + + try { + int rowCount = 0; + CachedRowSet data = jdbcDataSource.getData(sb.toString(), null, ""); + while(data.next()) { + rowCount ++; + data.deleteRow(); + } + if (rowCount != 0) { + LOG.debug("cleanupExistingToscaData in " + tableName + ": Data FOUND"); + String deleteStmt = sb.replace(sb.indexOf("SELECT *"), sb.indexOf("SELECT")+8, "DELETE").toString(); + jdbcDataSource.writeData(deleteStmt, null, null); + dataExists = true; + } + + } catch (SQLException e) { + LOG.error("Could not get data in " + tableName, e); + } + + return dataExists; + } + + protected boolean checkForExistingToscaData(String tableName, Map keyParams) throws IOException + { + boolean dataExists = false; + StringBuilder sb = new StringBuilder(); + sb.append("SELECT * from " + tableName + " where "); + + int paramCount = 0; + for (String paramKey : keyParams.keySet()) { + paramCount++; + String paramValue = keyParams.get(paramKey); + sb.append(paramKey); + sb.append(" = "); + sb.append(paramValue); + if (paramCount < keyParams.size()) sb.append(" AND "); + } + + sb.append(";"); + + try { + int rowCount = 0; + CachedRowSet data = jdbcDataSource.getData(sb.toString(), null, ""); + while(data.next()) { + rowCount ++; + } + if (rowCount != 0) { + LOG.info("checkForExistingToscaData in " + tableName + ": Data FOUND"); + dataExists = true; + } + + } catch (SQLException e) { + LOG.error("Could not get data in " + tableName, e); + } + + return dataExists; + } + + protected CachedRowSet getToscaData(String tableName, Map keyParams) throws IOException + { + StringBuilder sb = new StringBuilder(); + sb.append("SELECT * from " + tableName + " where "); + + int paramCount = 0; + for (String paramKey : keyParams.keySet()) { + paramCount++; + String paramValue = keyParams.get(paramKey); + sb.append(paramKey); + sb.append(" = "); + sb.append(paramValue); + if (paramCount < keyParams.size()) sb.append(" AND "); + } + + sb.append(";"); + + CachedRowSet data = null; + try { + int rowCount = 0; + data = jdbcDataSource.getData(sb.toString(), null, ""); + while(data.next()) { + rowCount ++; + } + if (rowCount == 0) { + LOG.info("getToscaData in " + tableName + ": Data NOT found"); + } + + } catch (SQLException e) { + LOG.error("Could not get data in " + tableName, e); + } + + return data; + } + protected void addParamsToMap (Map fromMap, Map toMap) { + for (String key : fromMap.keySet()) { + if (!toMap.containsKey(key)) { + toMap.put(key, fromMap.get(key)); + } + } + } + + protected String nullCheck (Object extractedObject) { + String stringValue = ""; + if (extractedObject != null) { + return extractedObject.toString(); + } + return stringValue; + } + + protected static String nullCheckStatic (Object extractedObject) { + String stringValue = ""; + if (extractedObject != null) { + return extractedObject.toString(); + } + return stringValue; + } } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java new file mode 100644 index 000000000..95d1fcd20 --- /dev/null +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java @@ -0,0 +1,81 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 - 2018 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 java.io.IOException; + +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.toscaparser.api.Group; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.elements.Metadata; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdncGroupModel extends SdncBaseModel { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncVFModuleModel.class); + + public SdncGroupModel(ISdcCsarHelper sdcCsarHelper, Group group, NodeTemplate nodeTemplate, SdncUebConfiguration config, DBResourceManager jdbcDataSource) throws IOException { + + super(sdcCsarHelper, group); + + // Metadata for Resource group is not extracted in base class due to inconsistency in TOSCA model Group object + Metadata metadata = group.getMetadata(); + invariantUUID = extractValue (metadata, "invariantUUID"); + addParameter("group_invariant_uuid", invariantUUID); + UUID = extractValue (metadata, "UUID"); + addParameter("group_uuid", UUID); + addParameter("group_name", extractValue (metadata, "name")); + addParameter("group_type", group.getType()); + addParameter("version", extractValue (metadata, "version")); + + // extract properties + addParameter("vfc_parent_port_role", extractValue(group, "vfc_parent_port_role"), attributeValueParams); + addParameter("subinterface_role", extractValue(group, "subinterface_role"), attributeValueParams); + + // relevant complex group properties are extracted and inserted into ATTRIBUTE_VALUE_PAIR + addParameter(extractGetInputName (group, "group_type"), extractGetInputValue(group, nodeTemplate, "group_type"), attributeValueParams); + addParameter(extractGetInputName (group, "group_role"), extractGetInputValue(group, nodeTemplate, "group_role"), attributeValueParams); + addParameter(extractGetInputName (group, "group_function"), extractGetInputValue(group, nodeTemplate, "group_function"), attributeValueParams); + } + + public void insertGroupData(NodeTemplate resourceNodeTemplate) throws IOException { + + try { + + // insert into RESOURCE_GROUP/ATTRIBUTE_VALUE_PAIR + String resourceNodeUuid = "\"" + extractValue (resourceNodeTemplate.getMetaData(), "UUID") + "\""; + cleanUpExistingToscaData("RESOURCE_GROUP", "resource_uuid", resourceNodeUuid, "group_uuid", getUUID()) ; + LOG.info("Call insertToscaData for RESOURCE_GROUP where group_uuid = " + getUUID() + " and resource_uuid = " + resourceNodeUuid); + insertToscaData(buildSql("RESOURCE_GROUP", "resource_uuid", resourceNodeUuid, model_yaml, params), null); + insertRelevantAttributeData("group"); + + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the RESOURCE_GROUP table"); + throw new IOException (e); + } + + } + +} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java index 69f378796..d4b3344ca 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. + * Copyright (C) 2017 - 2018 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. @@ -21,22 +21,28 @@ package org.onap.ccsdk.sli.northbound.uebclient; +import java.io.IOException; + import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SdncNodeModel extends SdncBaseModel { - + + private static final Logger LOG = LoggerFactory + .getLogger(SdncNodeModel.class); + private String serviceUUID = null; private String ecompGeneratedNaming = null; private String [] bindingUuids = null; // Using ASDC TOSCA Parser 17.07 - public SdncNodeModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { + public SdncNodeModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, DBResourceManager jdbcDataSource) { - super(sdcCsarHelper, nodeTemplate); + super(sdcCsarHelper, nodeTemplate, jdbcDataSource); // extract inpuecompGeneratedNamingts String ecompGeneratedNaming = extractBooleanInputDefaultValue(SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_ECOMPGENERATEDNAMING); @@ -103,6 +109,20 @@ public class SdncNodeModel extends SdncBaseModel { } } + public void insertNetworkModelData () throws IOException { + try { + // Clean up NETWORK_MODEL data for this customization_uuid and service_uuid? + cleanUpExistingToscaData("NETWORK_MODEL", "customization_uuid", getCustomizationUUID()); + cleanUpExistingToscaData("VPN_BINDINGS", "network_customization_uuid", getCustomizationUUID()); + LOG.info("Call insertToscaData for NETWORK_MODEL customizationUUID = " + getCustomizationUUID()); + insertToscaData(getSql(model_yaml), null); + insertToscaData(getVpnBindingsSql(), null); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the NETWORK_MODEL table"); + throw new IOException (e); + } + } + public String getSql(String model_yaml) { StringBuilder sb = new StringBuilder(); diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java index c1efadbdd..4bed2fe76 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java @@ -30,6 +30,8 @@ import org.slf4j.LoggerFactory; public class SdncServiceModel extends SdncBaseModel { private String UUID = null; + private String resourceVendor = null; + private String resourceVendorRelease = null; private String serviceInstanceNamePrefix = null; private String filename = null; @@ -39,9 +41,17 @@ public class SdncServiceModel extends SdncBaseModel { UUID = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_UUID); - // extract service topology template input data - addParameter("ecomp_naming",extractBooleanInputDefaultValue(SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_ECOMPGENERATEDNAMING)); - addParameter("naming_policy",extractInputDefaultValue(SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_NAMINGPOLICY)); + // extract ecompGeneratedNaming and namingPolicy from Service Metadata + addParameter("ecomp_naming",extractBooleanValue(metadata, "ecompGeneratedNaming")); + addParameter("naming_policy",extractValue(metadata, "namingPolicy")); + + // extract service topology template input data - ecompGeneratedNaming and namingPolicy moved to Service Metadata + //addParameter("ecomp_naming",extractBooleanInputDefaultValue(SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_ECOMPGENERATEDNAMING)); + //addParameter("naming_policy",extractInputDefaultValue(SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_NAMINGPOLICY)); + + // extract resourceVendor and resourceVendorRelease for use in SdncServiceProxy class + resourceVendor = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDOR); + resourceVendorRelease = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDORRELEASE); } public String getServiceUUID() { @@ -50,6 +60,9 @@ public class SdncServiceModel extends SdncBaseModel { public void setServiceUUID(String serviceUUID) { this.UUID = serviceUUID; } + public String getServiceInvariantUUID() { + return "\"" + invariantUUID + "\""; + } public String getServiceInstanceNamePrefix() { return serviceInstanceNamePrefix; } @@ -92,4 +105,20 @@ public class SdncServiceModel extends SdncBaseModel { return sb.toString(); } + public String getResourceVendor() { + return resourceVendor; + } + + public void setResourceVendor(String resourceVendor) { + this.resourceVendor = resourceVendor; + } + + public String getResourceVendorRelease() { + return resourceVendorRelease; + } + + public void setResourceVendorRelease(String resourceVendorRelease) { + this.resourceVendorRelease = resourceVendorRelease; + } + } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index 4ae5acd99..866fd14d7 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -2,15 +2,15 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. + * Copyright (C) 2017 - 2018 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. @@ -40,6 +40,7 @@ import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.sql.SQLException; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.LinkedList; @@ -57,12 +58,11 @@ import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathFactory; +import javax.xml.XMLConstants; import org.apache.commons.codec.binary.Base64; -import org.apache.commons.lang3.tuple.Pair; -import org.onap.ccsdk.sli.core.dblib.DBResourceManager; -import org.onap.ccsdk.sli.northbound.uebclient.SdncArtifactMap.SdncArtifactType; import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.consumer.IComponentDoneStatusMessage; import org.onap.sdc.api.consumer.IDistributionStatusMessage; import org.onap.sdc.api.consumer.INotificationCallback; import org.onap.sdc.api.notification.IArtifactInfo; @@ -72,27 +72,37 @@ import org.onap.sdc.api.results.IDistributionClientDownloadResult; import org.onap.sdc.api.results.IDistributionClientResult; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; -import org.onap.sdc.toscaparser.api.Group; +import org.onap.sdc.tosca.parser.impl.SdcTypes; import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.Policy; import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.sdc.utils.ArtifactTypeEnum; import org.onap.sdc.utils.DistributionActionResultEnum; import org.onap.sdc.utils.DistributionStatusEnum; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; +import org.onap.ccsdk.sli.northbound.uebclient.SdncArtifactMap.SdncArtifactType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; + public class SdncUebCallback implements INotificationCallback { private static final Logger LOG = LoggerFactory .getLogger(SdncUebCallback.class); - private static DBResourceManager jdbcDataSource = null; + protected static DBResourceManager jdbcDataSource = null; private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; - + private static final String COMPONENT_NAME = "SDNC"; + private static final int NUM_PASSES = 2; + + // If any ASDC artifact in a distribution fails to download or deploy send SDC event COMPONENT_DONE_ERROR + // once after the entire distribution is processed. Otherwise, send COMPONENT_DONE_OK. + private static boolean COMPONENT_DOWNLOAD_ERROR = false; + private static boolean COMPONENT_DEPLOY_ERROR = false; + private static boolean CSAR_ARTIFACT_DEPLOY_ERROR = false; private class SdncAuthenticator extends Authenticator { @@ -188,11 +198,13 @@ public class SdncUebCallback implements INotificationCallback { private LinkedList deployList[]; + private static void setJdbcDataSource() throws IOException { - String propPath; + String propPath = null; String propDir = System.getenv(SDNC_CONFIG_DIR); if (propDir == null) { + propDir = "/opt/sdnc/data/properties"; } propPath = propDir + "/dblib.properties"; @@ -209,7 +221,6 @@ public class SdncUebCallback implements INotificationCallback { props.load(new FileInputStream(propFile)); setJdbcDataSource(new DBResourceManager(props)); - } static void setJdbcDataSource(DBResourceManager dbMgr) { @@ -223,10 +234,19 @@ public class SdncUebCallback implements INotificationCallback { } } + private static void loadArtifactMap() { + + } + public SdncUebCallback(IDistributionClient client, SdncUebConfiguration config) { this.client = client; this.config = config; + this.deployList = new LinkedList[NUM_PASSES]; + + for (int i = 0 ; i < NUM_PASSES ; i++) { + this.deployList[i] = new LinkedList(); + } } @Override @@ -234,14 +254,30 @@ public class SdncUebCallback implements INotificationCallback { LOG.info("Received notification : ("+data.getDistributionID()+","+data.getServiceName()+","+data.getServiceVersion()+ ","+data.getServiceDescription() + ")"); + + COMPONENT_DOWNLOAD_ERROR = false; + COMPONENT_DEPLOY_ERROR = false; + CSAR_ARTIFACT_DEPLOY_ERROR = false; + + // TOSCA_TEMPLATE artifact should only be downloaded if TOSCA_CSAR artifact fails due to version non-compliance + IArtifactInfo toscaTemplateArtifact = null; String incomingDirName = config.getIncomingDir(); String archiveDirName = config.getArchiveDir(); - File incomingDir = null; - File archiveDir = null; + File incomingDir = new File(incomingDirName); + File archiveDir = new File(archiveDirName); + + LOG.debug("IncomingDirName is {}", incomingDirName); + + if (!incomingDir.exists()) { + incomingDir.mkdirs(); + } + - LOG.debug("IncomingDirName is {}", incomingDirName); + if (!archiveDir.exists()) { + archiveDir.mkdirs(); + } // Process service level artifacts List artifactList = data.getServiceArtifacts(); @@ -261,8 +297,20 @@ public class SdncUebCallback implements INotificationCallback { { LOG.info("Received artifact " + curArtifact.getArtifactName()); - - handleArtifact(data, data.getServiceName(), null, curArtifact, incomingDir, archiveDir); + + // If artifact is TOSCA_TEMPLATE, don't handle it. We will handle if last TOSCA_CSAR ingestion fails. + if (curArtifact.getArtifactType().contains("TOSCA_TEMPLATE") || curArtifact.getArtifactName().contains(".yml")) { + toscaTemplateArtifact = curArtifact; + } else { + + handleArtifact(data, data.getServiceName(), null, null, curArtifact, incomingDir, archiveDir); + } + } + + // After all artifacts have been processed if CSAR_ARTIFACT_DEPLOY_ERROR is true, download and deploy the TOSCA_TEMPLATE artifact + if (CSAR_ARTIFACT_DEPLOY_ERROR == true) { + LOG.info("TOSCA_CSAR artifact deploy error encountered, downloading TOSCA_TEMPLATE artifact: " + toscaTemplateArtifact.getArtifactName()); + handleArtifact(data, data.getServiceName(), null, null, toscaTemplateArtifact, incomingDir, archiveDir); } } @@ -275,14 +323,12 @@ public class SdncUebCallback implements INotificationCallback { if (artifactList != null) { - incomingDir = new File(incomingDirName + "/" + escapeFilename(data.getServiceName()) + "/" - + escapeFilename(curResource.getResourceName())); + incomingDir = new File(incomingDirName + "/" + escapeFilename(data.getServiceName()) + "/" + escapeFilename(curResource.getResourceName())); if (!incomingDir.exists()) { incomingDir.mkdirs(); } - archiveDir = new File(archiveDirName + "/" + escapeFilename(data.getServiceName()) + "/" - + escapeFilename(curResource.getResourceName())); + archiveDir = new File(archiveDirName + "/" + escapeFilename(data.getServiceName()) + "/" + escapeFilename(curResource.getResourceName())); if (!archiveDir.exists()) { archiveDir.mkdirs(); } @@ -291,19 +337,42 @@ public class SdncUebCallback implements INotificationCallback { LOG.info("Received artifact " + curArtifact.getArtifactName()); - handleArtifact(data, data.getServiceName(), curResource.getResourceName(), curArtifact, incomingDir, archiveDir); + handleArtifact(data, data.getServiceName(), curResource.getResourceName(), curResource.getResourceType(), curArtifact, incomingDir, archiveDir); } } } deployDownloadedFiles(incomingDir, archiveDir, data); + + // Send Component Status: COMPONENT_DONE_ERROR or COMPONENT_DONE_OK + LOG.info("Sending Component Status for Distribution: ("+data.getDistributionID()+","+data.getServiceName()+","+data.getServiceVersion()+ + ","+data.getServiceDescription() + ")"); + IDistributionClientResult result = null; + if (COMPONENT_DOWNLOAD_ERROR == true || COMPONENT_DEPLOY_ERROR == true) { + + String errorReason = (COMPONENT_DEPLOY_ERROR == true ? "SDN-C encountered an error deploying an artifact in this distribution" : ""); + errorReason = (COMPONENT_DOWNLOAD_ERROR == true ? "SDN-C encountered an error downloading an artifact in this distribution" : errorReason); + result = client.sendComponentDoneStatus(buildComponentStatusMessage( + client, data, DistributionStatusEnum.COMPONENT_DONE_ERROR), errorReason); + if (result != null) { + LOG.info("Sending Component Status COMPONENT_DONE_ERROR for Distribution result: " + result.getDistributionMessageResult()); + } + } else { + + result = client.sendComponentDoneStatus(buildComponentStatusMessage( + client, data, DistributionStatusEnum.COMPONENT_DONE_OK)); + if (result != null) { + LOG.info("Sending Component Status COMPONENT_DONE_OK for Distribution result: " + result.getDistributionMessageResult()); + } + } + } public void deployDownloadedFiles(File incomingDir, File archiveDir, INotificationData data) { if (incomingDir == null) { - LOG.debug("incomingDir is null - using {}", config.getIncomingDir()); + LOG.debug("incomingDir is null - using {}", config.getIncomingDir()); incomingDir = new File(config.getIncomingDir()); if (!incomingDir.exists()) { @@ -311,8 +380,8 @@ public class SdncUebCallback implements INotificationCallback { } } else { - LOG.debug("incomingDir is not null - it is {}", incomingDir.getPath()); - } + LOG.debug("incomingDir is not null - it is {}", incomingDir.getPath()); + } if (archiveDir == null) { archiveDir = new File(config.getArchiveDir()); @@ -321,27 +390,40 @@ public class SdncUebCallback implements INotificationCallback { archiveDir.mkdirs(); } } - - // Deploy scheduled deployments - int numPasses = config.getMaxPasses(); - - deployList = new LinkedList[numPasses]; - - for (int i = 0 ; i < numPasses ; i++) { - deployList[i] = new LinkedList<>(); - } - LOG.debug("Scanning {} - {} for downloaded files", incomingDir.getPath(), incomingDir.toPath()); + String curFileName = ""; try (DirectoryStream stream = Files.newDirectoryStream(incomingDir.toPath())) { for (Path file: stream) { - handleSuccessfulDownload(null,null, null, null, file.toFile(), archiveDir); + curFileName = file.toString(); + // Skip TOSCA files (csar and yml) if we are deploying files that were downloaded from ASDC (data is not NULL), + // they have already been deployed. If they are still in the incoming directory there was an error during ingestion. + if (data != null && (curFileName.contains(".csar") || curFileName.contains(".yml"))) { + LOG.info("Skipping deploy of file TOSCA file: "+ curFileName + " it has already been handled"); + continue; + } + + try { + handleSuccessfulDownload(null,null, null, null, file.toFile(), archiveDir); + } catch (Exception x) { + COMPONENT_DEPLOY_ERROR = true; + LOG.error("Exception in handleSuccessfulDownload: Cannot process spool file "+ curFileName, x); + } + } - } catch (IOException x) { + } catch (Exception x) { // IOException can never be thrown by the iteration. // In this snippet, it can only be thrown by newDirectoryStream. - LOG.warn("Cannot process spool file", x); + LOG.warn("Cannot process spool file "+ curFileName, x); } + // Deploy scheduled deployments + /*int numPasses = config.getMaxPasses(); + + deployList = new LinkedList[numPasses]; + + for (int i = 0 ; i < numPasses ; i++) { + deployList[i] = new LinkedList(); + }*/ for (int pass = 0 ; pass < config.getMaxPasses() ; pass++) { if (deployList[pass] != null) { @@ -362,9 +444,13 @@ public class SdncUebCallback implements INotificationCallback { IArtifactInfo artifactInfo = artifact.getArtifactInfo(); if ((artifactInfo != null) && (data != null)) { - client.sendDeploymentStatus(buildStatusMessage( + IDistributionClientResult deploymentStatus; + deploymentStatus = client.sendDeploymentStatus(buildStatusMessage( client, data, artifactInfo, deployResult)); + if (deployResult == DistributionStatusEnum.DEPLOY_ERROR) { + COMPONENT_DEPLOY_ERROR = true; + } } } @@ -372,9 +458,8 @@ public class SdncUebCallback implements INotificationCallback { } } - private void handleArtifact(INotificationData data, String svcName, String resourceName, - IArtifactInfo artifact, File incomingDir, File archiveDir) { - + private void handleArtifact(INotificationData data, String svcName, String resourceName, String resourceType, IArtifactInfo artifact, File incomingDir, File archiveDir) { + // Download Artifact IDistributionClientDownloadResult downloadResult = client.download(artifact); @@ -391,26 +476,28 @@ public class SdncUebCallback implements INotificationCallback { return; } - - File spoolFile = new File(incomingDir.getAbsolutePath() + "/" + artifact.getArtifactName()); - boolean writeSucceeded = false; - + File spoolFile = new File(incomingDir.getAbsolutePath() + "/" + artifact.getArtifactName()); + // Save zip if TOSCA_CSAR if (artifact.getArtifactType().contains("TOSCA_CSAR") || artifact.getArtifactName().contains(".csar")) { - try(FileOutputStream outFile = new FileOutputStream(incomingDir.getAbsolutePath() + "/" + artifact.getArtifactName())) { - outFile.write(payloadBytes, 0, payloadBytes.length); - outFile.close(); + try { + + FileOutputStream outFile = new FileOutputStream(incomingDir.getAbsolutePath() + "/" + artifact.getArtifactName()); + outFile.write(payloadBytes, 0, payloadBytes.length); + outFile.close(); writeSucceeded = true; } catch (Exception e) { LOG.error("Unable to save downloaded zip file to spool directory ("+ incomingDir.getAbsolutePath() +")", e); } } else { - String payload = new String(payloadBytes); + + String payload = new String(payloadBytes); - try(FileWriter spoolFileWriter = new FileWriter(spoolFile)) { + try { + FileWriter spoolFileWriter = new FileWriter(spoolFile); spoolFileWriter.write(payload); spoolFileWriter.close(); writeSucceeded = true; @@ -419,8 +506,11 @@ public class SdncUebCallback implements INotificationCallback { } } + if (writeSucceeded && (downloadResult.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS)) { handleSuccessfulDownload(data, svcName, resourceName, artifact, spoolFile, archiveDir); + + } else { handleFailedDownload(data, artifact); } @@ -430,33 +520,22 @@ public class SdncUebCallback implements INotificationCallback { private void handleFailedDownload(INotificationData data, IArtifactInfo relevantArtifact) { // Send Download Status - client.sendDownloadStatus(buildStatusMessage(client, data, - relevantArtifact, DistributionStatusEnum.DOWNLOAD_ERROR)); + client.sendDownloadStatus(buildStatusMessage(client, data, relevantArtifact, DistributionStatusEnum.DOWNLOAD_ERROR)); + COMPONENT_DOWNLOAD_ERROR = true; } private void handleSuccessfulDownload(INotificationData data, String svcName, String resourceName, - IArtifactInfo artifact, File inpSpoolFile, File archiveDir) { + IArtifactInfo artifact, File spoolFile, File archiveDir) { if ((data != null) && (artifact != null)) { // Send Download Status - client.sendDownloadStatus(buildStatusMessage(client, data, artifact, DistributionStatusEnum.DOWNLOAD_OK)); + IDistributionClientResult sendDownloadStatus = client + .sendDownloadStatus(buildStatusMessage(client, data, artifact, DistributionStatusEnum.DOWNLOAD_OK)); } // If an override file exists, read that instead of the file we just downloaded ArtifactTypeEnum artifactEnum = ArtifactTypeEnum.YANG_XML; - File spoolFile = inpSpoolFile; - boolean toscaCsarType = false; - if (artifact != null) { - String artifactTypeString = artifact.getArtifactType(); - if (artifactTypeString.contains("TOSCA_CSAR")) { - toscaCsarType = true; - } - } else { - if (spoolFile.toString().contains(".csar")) { - toscaCsarType = true; - } - } String overrideFileName = config.getOverrideFile(); if ((overrideFileName != null) && (overrideFileName.length() > 0)) { File overrideFile = new File(overrideFileName); @@ -468,21 +547,20 @@ public class SdncUebCallback implements INotificationCallback { } - if (toscaCsarType) { - processToscaCsar (data, artifact, spoolFile, archiveDir); - - try { - Path source = spoolFile.toPath(); - Path targetDir = archiveDir.toPath(); - - Files.move(source, targetDir.resolve(source.getFileName()), StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { - LOG.warn("Could not move "+spoolFile.getAbsolutePath()+" to "+archiveDir.getAbsolutePath(), e); - } - + // If the artifact is a TOSCA artifact, don't schedule a deployment to SDN-C REST intfc, process it in ueb-listener + if (artifactIsTosca(artifact, spoolFile) == true) + { + handleToscaArtifact (data, svcName, resourceName, artifact, spoolFile, archiveDir); return; } + + processSpoolFile (data, svcName, resourceName, artifact, spoolFile, archiveDir); + } + + protected void processSpoolFile(INotificationData data, String svcName, String resourceName, + IArtifactInfo artifact, File spoolFile, File archiveDir) { + // Process spool file Document spoolDoc = null; File transformedFile = null; @@ -498,20 +576,33 @@ public class SdncUebCallback implements INotificationCallback { if (transformedFile != null) { try { - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); - spoolDoc = db.parse(transformedFile); + try { + + DocumentBuilderFactory dbf = DocumentBuilderFactory + .newInstance(); + dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); + dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); + DocumentBuilder db = dbf.newDocumentBuilder(); + + spoolDoc = db.parse(transformedFile); + } catch (Exception e) { + LOG.error( + "Caught exception trying to parse transformed XML file " + + transformedFile.getAbsolutePath(), e); + } + } catch (Exception e) { - LOG.error("Caught exception trying to parse transformed XML file {}", - transformedFile.getAbsolutePath(), e); + LOG.error("Caught exception trying to deploy file", e); } } - + ArtifactTypeEnum artifactEnum = ArtifactTypeEnum.YANG_XML; if (spoolDoc != null) { // Analyze file type - SdncArtifactType artifactType = analyzeFileType(artifactEnum, spoolFile, spoolDoc); + SdncArtifactType artifactType = analyzeFileType(artifactEnum, + spoolFile, spoolDoc); if (artifactType != null) { @@ -530,79 +621,115 @@ public class SdncUebCallback implements INotificationCallback { LOG.warn("Could not move "+spoolFile.getAbsolutePath()+" to "+archiveDir.getAbsolutePath(), e); } } + + } + private void handleToscaArtifact (INotificationData data, String svcName, String resourceName, IArtifactInfo artifact, + File spoolFile, File archiveDir) { + + DistributionStatusEnum deployStatus = DistributionStatusEnum.DEPLOY_ERROR; + if ((artifact != null && artifact.getArtifactType().contains("TOSCA_TEMPLATE")) || spoolFile.toString().contains(".yml")) { + deployStatus = processToscaYaml (spoolFile); + } else if ((artifact != null && artifact.getArtifactType().contains("TOSCA_CSAR")) || spoolFile.toString().contains(".csar")) { + deployStatus = processToscaCsar (data, svcName, resourceName, artifact, spoolFile, archiveDir); + // if parser error on CSAR, process the TOSCA_TEMPLATE artifact last + if (deployStatus.equals(DistributionStatusEnum.DEPLOY_ERROR)) { + CSAR_ARTIFACT_DEPLOY_ERROR = true; + } + + } else { + LOG.error("handleToscaArtifact: Encountered unknown TOSCA artifact"); + } + + if (deployStatus.equals(DistributionStatusEnum.DEPLOY_OK)) { + LOG.info("Update to SDN-C succeeded"); + + try { + Path source = spoolFile.toPath(); + Path targetDir = archiveDir.toPath(); + Files.move(source, targetDir.resolve(source.getFileName()), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + LOG.warn("Could not move "+spoolFile.getAbsolutePath()+" to "+archiveDir.getAbsolutePath(), e); + } + + } else { + LOG.info("Update to SDN-C failed"); + COMPONENT_DEPLOY_ERROR = true; + } + + // Send deployment status for ingestion + if ((artifact != null) && (data != null)) { + client.sendDeploymentStatus(buildStatusMessage(client, data, artifact,deployStatus)); + } } + + protected DistributionStatusEnum processToscaYaml(File spoolFile) { + return DistributionStatusEnum.DEPLOY_OK; + } - private void processToscaCsar(INotificationData data, - IArtifactInfo artifact, File spoolFile, File archiveDir) { + private DistributionStatusEnum processToscaCsar(INotificationData data, String svcName, String resourceName, IArtifactInfo artifact, + File spoolFile, File archiveDir) { + // Use ASDC Dist Client 1.1.5 with TOSCA parsing APIs to extract relevant TOSCA model data // TOSCA data extraction flow 1707: // Use ASDC dist-client to get yaml string - not yet available String model_yaml = null; LOG.info("Process TOSCA CSAR file: "+spoolFile.toString()); - - SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); ISdcCsarHelper sdcCsarHelper = null; + DistributionStatusEnum deployStatus = DistributionStatusEnum.DEPLOY_OK; + try { + SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); sdcCsarHelper = factory.getSdcCsarHelper(spoolFile.getAbsolutePath()); } catch (SdcToscaParserException e) { LOG.error("Could not create SDC TOSCA Parser ", e); - return; - } + return DistributionStatusEnum.DEPLOY_ERROR; + } // Ingest Service Data - 1707 Metadata serviceMetadata = sdcCsarHelper.getServiceMetadata(); SdncServiceModel serviceModel = new SdncServiceModel(sdcCsarHelper, serviceMetadata); - serviceModel.setFilename(spoolFile.toString().substring(spoolFile - .toString().lastIndexOf('/')+1)); // will be csar file name + serviceModel.setFilename(spoolFile.toString().substring(spoolFile.toString().lastIndexOf("/")+1)); // will be csar file name serviceModel.setServiceInstanceNamePrefix(SdncBaseModel.extractSubstitutionMappingTypeName(sdcCsarHelper).substring(SdncBaseModel.extractSubstitutionMappingTypeName(sdcCsarHelper).lastIndexOf(".")+1)); try { cleanUpExistingToscaServiceData(serviceModel.getServiceUUID()); - LOG.info("Call insertToscaData for SERVICE_MODEL serviceUUID = " + serviceModel.getServiceUUID()); - insertToscaData(serviceModel.getSql(model_yaml)); + LOG.info("Call insertToscaData for SERVICE_MODEL where service_uuid = " + serviceModel.getServiceUUID()); + insertToscaData(serviceModel.getSql(model_yaml), null); } catch (IOException e) { - LOG.error("Could not insert Tosca YAML data into the SERVICE_MODEL table ", e); - + LOG.error("Could not insert Tosca CSAR data into the SERVICE_MODEL table ", e); + return DistributionStatusEnum.DEPLOY_ERROR; + } - + // Ingest Network (VL) Data - 1707 List vlNodeTemplatesList = sdcCsarHelper.getServiceVlList(); for (NodeTemplate nodeTemplate : vlNodeTemplatesList) { - SdncNodeModel nodeModel = new SdncNodeModel (sdcCsarHelper, nodeTemplate); + SdncNodeModel nodeModel = new SdncNodeModel (sdcCsarHelper, nodeTemplate, jdbcDataSource); nodeModel.setServiceUUID(serviceModel.getServiceUUID()); - nodeModel.setEcompGeneratedNaming(SdncBaseModel.extractBooleanInputDefaultValue(sdcCsarHelper, SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_ECOMPGENERATEDNAMING));//service_naming#default#ecomp_generated_naming try { - cleanUpExistingToscaData("NETWORK_MODEL", "customization_uuid", nodeModel.getCustomizationUUID()); - cleanUpExistingToscaData("VPN_BINDINGS", "network_customization_uuid", nodeModel.getCustomizationUUID()); - LOG.info("Call insertToscaData for NETWORK_MODEL customizationUUID = " + nodeModel.getCustomizationUUID()); - // using ASDC dist-client use method for get yaml string - insertToscaData(nodeModel.getSql(model_yaml)); - insertToscaData(nodeModel.getVpnBindingsSql()); + nodeModel.insertNetworkModelData(); } catch (IOException e) { - LOG.error("Could not insert Tosca YAML data into the NETWORK_MODEL table ", e); + deployStatus = DistributionStatusEnum.DEPLOY_ERROR; } } - + // Ingest Allotted Resource Data - 1707 List arNodeTemplatesList = sdcCsarHelper.getAllottedResources(); for (NodeTemplate nodeTemplate : arNodeTemplatesList) { - SdncARModel nodeModel = new SdncARModel (sdcCsarHelper, nodeTemplate); - + try { - cleanUpExistingToscaData("ALLOTTED_RESOURCE_MODEL", "customization_uuid", nodeModel.getCustomizationUUID()); - LOG.info("Call insertToscaData for ALLOTTED_RESOURCE_MODEL customizationUUID = " + nodeModel.getCustomizationUUID()); - // using ASDC dist-client use method for get yaml string - insertToscaData(nodeModel.getSql("ALLOTTED_RESOURCE_MODEL", model_yaml)); + SdncARModel nodeModel = new SdncARModel (sdcCsarHelper, nodeTemplate, jdbcDataSource); + nodeModel.insertAllottedResourceModelData (); } catch (IOException e) { - LOG.error("Could not insert Tosca YAML data into the NETWORK_MODEL table ", e); + deployStatus = DistributionStatusEnum.DEPLOY_ERROR; } } @@ -610,133 +737,47 @@ public class SdncUebCallback implements INotificationCallback { List vfNodeTemplatesList = sdcCsarHelper.getServiceVfList(); for (NodeTemplate nodeTemplate : vfNodeTemplatesList) { - SdncVFModel vfNodeModel = new SdncVFModel (sdcCsarHelper, nodeTemplate); - + + SdncVFModel vfNodeModel = null; try { - cleanUpExistingToscaData("VF_MODEL", "customization_uuid", vfNodeModel.getCustomizationUUID()) ; - LOG.info("Call insertToscaData for VF_MODEL customizationUUID = " + vfNodeModel.getCustomizationUUID()); - insertToscaData(vfNodeModel.getSql("VF_MODEL", model_yaml)); - } catch (IOException e) { - LOG.error("Could not insert Tosca YAML data into the VF_MODEL table ", e); - } - - // For each VF, insert VF_MODULE_MODEL data - List vfModules = sdcCsarHelper.getVfModulesByVf(vfNodeModel.getCustomizationUUIDNoQuotes()); - for (Group group : vfModules){ - SdncVFModuleModel vfModuleModel = new SdncVFModuleModel(sdcCsarHelper, group); - - try { - cleanUpExistingToscaData("VF_MODULE_MODEL", "customization_uuid", vfModuleModel.getCustomizationUUID()); - LOG.info("Call insertToscaData for VF_MODULE_MODEL customizationUUID = " + vfModuleModel.getCustomizationUUID()); - insertToscaData(vfModuleModel.getSql("VF_MODULE_MODEL", model_yaml)); - } catch (IOException e) { - LOG.error("Could not insert Tosca YAML data into the VF_MODULE_MODEL table ", e); - } - - // For each VF Module, get the VFC list, insert VF_MODULE_TO_VFC_MAPPING data - // For each vfcNode (group member) in the groupMembers list, extract vm_type and vm_count. - // Insert vf_module.customizationUUID, vfcNode.customizationUUID and vm_type and vm_count into VF_MODULE_TO_VFC_MAPPING - List groupMembers = sdcCsarHelper.getMembersOfVfModule(nodeTemplate, group); // not yet available - for (NodeTemplate vfcNode : groupMembers){ - SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, vfcNode); - - try { - cleanUpExistingToscaData("VF_MODULE_TO_VFC_MAPPING", "vf_module_customization_uuid", vfModuleModel.getCustomizationUUID()); - LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING customizationUUID = " + vfModuleModel.getCustomizationUUID()); - insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" + - vfModuleModel.getCustomizationUUID() + ", " + vfcModel.getCustomizationUUID() + ", \"" + vfcModel.getVmType() + "\", \"" + vfcModel.getVmCount() + "\")"); - } catch (IOException e) { - LOG.error("Could not insert Tosca YAML data into the VF_MODULE_TO_VFC_MAPPING table ", e); - } - - } - - } - - // For each VF, insert VFC_MODEL data - List vfcNodes = sdcCsarHelper.getVfcListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()); - for (NodeTemplate vfcNode : vfcNodes){ - SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, vfcNode); - - try { - cleanUpExistingToscaData("VFC_MODEL", "customization_uuid", vfcModel.getCustomizationUUID()); - LOG.info("Call insertToscaData for VFC_MODEL customizationUUID = " + vfcModel.getCustomizationUUID()); - insertToscaData(vfcModel.getSql("VFC_MODEL", model_yaml)); - } catch (IOException e) { - LOG.error("Could not insert Tosca YAML data into the VFC_MODEL table ", e); - } + vfNodeModel = new SdncVFModel (sdcCsarHelper, nodeTemplate, jdbcDataSource, config); + vfNodeModel.setServiceUUID(serviceModel.getServiceUUID()); + vfNodeModel.setServiceInvariantUUID(serviceModel.getServiceInvariantUUID()); + vfNodeModel.insertData(); + } catch (IOException e) { + deployStatus = DistributionStatusEnum.DEPLOY_ERROR; + } + + // For each VF, insert VNF Configuration data + DistributionStatusEnum vnfConfigDeployStatus = customProcessVnfConfig(sdcCsarHelper, vfNodeModel, jdbcDataSource); + if (vnfConfigDeployStatus == DistributionStatusEnum.DEPLOY_ERROR) { + deployStatus = DistributionStatusEnum.DEPLOY_ERROR; } - // For each VF, insert VF_TO_NETWORK_ROLE_MAPPING data - List cpNodes = sdcCsarHelper.getCpListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()); - for (NodeTemplate cpNode : cpNodes){ - - // Insert into VF_TO_NETWORK_ROLE_MAPPING vf_customization_uuid and network_role - String cpNetworkRole = sdcCsarHelper.getNodeTemplatePropertyLeafValue(cpNode, "network_role_tag"); - - try { - cleanUpExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", "vf_customization_uuid", vfNodeModel.getCustomizationUUID()); - LOG.info("Call insertToscaData for VF_TO_NETWORK_ROLE_MAPPING vfCustomizationUUID = " + vfNodeModel.getCustomizationUUID()); - insertToscaData("insert into VF_TO_NETWORK_ROLE_MAPPING (vf_customization_uuid, network_role) values (" + - vfNodeModel.getCustomizationUUID() + ", \"" + cpNetworkRole + "\")"); - } catch (IOException e) { - LOG.error("Could not insert Tosca YAML data into the VF_TO_NETWORK_ROLE_MAPPING table ", e); - } - - // Insert VFC_TO_NETWORK_ROLE_MAPPING data - Map mappingParams = new HashMap<>(); - //String cpNetworkRoleTag = "\"" + sdcCsarHelper.getNodeTemplatePropertyLeafValue(cpNode, SdcPropertyNames.PROPERTY_NAME_NETWORKROLETAG) + "\""; - // extract network_role, network_role_tag and virtual_binding from this cpNode - SdncBaseModel.addParameter("network_role", SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "network_role"), mappingParams); - SdncBaseModel.addParameter("network_role_tag", SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "network_role_tag"), mappingParams); - String virtualBinding = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "requirements#virtualBinding") + "\""; - - // get list of cpNodes and vfcNodes with matching virtualBinding - List> matchList = sdcCsarHelper.getNodeTemplatePairsByReqName(sdcCsarHelper.getCpListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()), sdcCsarHelper.getVfcListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()), virtualBinding); - for (Pair match : matchList) { // should be 1 match? - - // extract values from the left "CP" Node - SdncBaseModel.addParameter("ipv4_use_dhcp", SdncBaseModel.extractBooleanValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_DHCPENABLED), mappingParams); - - SdncBaseModel.addParameter("ipv4_ip_version", "dummy_ipv4_vers", mappingParams); - SdncBaseModel.addParameter("ipv6_use_dhcp", SdncBaseModel.extractBooleanValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_DHCPENABLED), mappingParams); - - SdncBaseModel.addParameter("ipv6_ip_version", "dummy_ipv6_vers", mappingParams); - - // extract values from the right "VFC" Node - String vfcCustomizationUuid = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, match.getRight().getMetaData(), "customization_uuid") + "\""; - SdncBaseModel.addParameter("vm_type", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_VMTYPE), mappingParams); - SdncBaseModel.addIntParameter("ipv4_count", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT), mappingParams); - SdncBaseModel.addIntParameter("ipv6_count", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT), mappingParams); - - try { - cleanUpExistingToscaData("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", vfcCustomizationUuid); - LOG.info("Call insertToscaData for VFC_TO_NETWORK_ROLE_MAPPING vfcCustomizationUUID = " + vfcCustomizationUuid); - insertToscaData(SdncBaseModel.getSql("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", vfcCustomizationUuid, "", mappingParams)); - } catch (IOException e) { - LOG.error("Could not insert Tosca YAML data into the VFC_TO_NETWORK_ROLE_MAPPING table ", e); - } - - } - - } // CP loop - } // VF loop - - - - if ((artifact != null) && (data != null)) { - LOG.info("Update to SDN-C succeeded"); - IDistributionClientResult deploymentStatus; - deploymentStatus = client.sendDeploymentStatus(buildStatusMessage( - client, data, artifact, - DistributionStatusEnum.DEPLOY_OK)); + + DistributionStatusEnum complexToscaDeployStatus = customProcessComplexTosca(sdcCsarHelper, config, jdbcDataSource, serviceModel, + data, svcName, resourceName, artifact, archiveDir); + if (complexToscaDeployStatus == DistributionStatusEnum.DEPLOY_ERROR) { + deployStatus = DistributionStatusEnum.DEPLOY_ERROR; } - + + return deployStatus; } - private void cleanUpExistingToscaData(String tableName, String keyName, String keyValue) throws IOException + protected DistributionStatusEnum customProcessVnfConfig(ISdcCsarHelper sdcCsarHelper, + SdncVFModel vfNodeModel, DBResourceManager jdbcDataSource2) { + return DistributionStatusEnum.DEPLOY_OK; + } + + protected DistributionStatusEnum customProcessComplexTosca(ISdcCsarHelper sdcCsarHelper, + SdncUebConfiguration config, DBResourceManager jdbcDataSource2, SdncServiceModel serviceModelINotification, + INotificationData data, String svcName, String resourceName, IArtifactInfo artifact, File archiveDir) { + return DistributionStatusEnum.DEPLOY_OK; + } + + protected void cleanUpExistingToscaData(String tableName, String keyName, String keyValue) throws IOException { if (jdbcDataSource == null) { @@ -760,7 +801,7 @@ public class SdncUebCallback implements INotificationCallback { } - private void cleanUpExistingToscaServiceData(String serviceUUID) throws IOException + protected void cleanUpExistingToscaServiceData(String serviceUUID) throws IOException { if (jdbcDataSource == null) { @@ -785,7 +826,7 @@ public class SdncUebCallback implements INotificationCallback { } - private void insertToscaData(String toscaDataString) throws IOException + protected void insertToscaData(String toscaDataString, ArrayList arguments) throws IOException { LOG.debug("insertToscaData: " + toscaDataString); @@ -794,10 +835,11 @@ public class SdncUebCallback implements INotificationCallback { } try { - jdbcDataSource.writeData(toscaDataString, null, null); + jdbcDataSource.writeData(toscaDataString, arguments, null); } catch (SQLException e) { - LOG.error("Could not insert Tosca YAML data into the database ", e); + LOG.error("Could not insert Tosca YAML data into the database "); + throw new IOException (e); } } @@ -845,37 +887,39 @@ public class SdncUebCallback implements INotificationCallback { } private void scheduleDeployment(SdncArtifactType type, String svcName, String resourceName, IArtifactInfo artifactInfo, String spoolFileName, File spoolFile) { + if (type.getPass() < deployList.length) { if (artifactInfo != null) { - LOG.debug("Scheduling " + artifactInfo.getArtifactName() + " version " + artifactInfo.getArtifactVersion() + " for deployment"); + LOG.debug("Scheduling "+artifactInfo.getArtifactName()+" version "+artifactInfo.getArtifactVersion()+" for deployment"); - deployList[type.getPass()].add(new org.onap.ccsdk.sli.northbound.uebclient.SdncUebCallback.DeployableArtifact(type, svcName, resourceName, artifactInfo, spoolFile)); + deployList[type.getPass()].add(new DeployableArtifact(type, svcName, resourceName, artifactInfo, spoolFile)); } else { SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss.SSS");//dd/MM/yyyy Date now = new Date(); String artifactVersion = sdfDate.format(now); - LOG.debug("Scheduling " + spoolFileName + " version " + artifactVersion + " for deployment"); - deployList[type.getPass()].add(new org.onap.ccsdk.sli.northbound.uebclient.SdncUebCallback.DeployableArtifact(type, svcName, resourceName, spoolFileName, - artifactVersion, spoolFile)); + LOG.debug("Scheduling "+spoolFileName+" version "+artifactVersion+" for deployment"); + String artifactName = spoolFileName; + if (artifactInfo != null) { + artifactName = artifactInfo.getArtifactName(); + } + deployList[type.getPass()].add(new DeployableArtifact(type, svcName, resourceName, artifactName, artifactVersion, spoolFile)); } } else { - LOG.info("Pass for type " + type.getTag() + " is " + type.getPass() + " which is not <= " + deployList.length); + LOG.info("Pass for type "+type.getTag()+" is "+type.getPass()+" which is not <= "+deployList.length); } } private DistributionStatusEnum deploySpoolFile(DeployableArtifact artifact) { - DistributionStatusEnum deployResult; + DistributionStatusEnum deployResult = DistributionStatusEnum.DEPLOY_OK; - StringBuilder msgBuffer = new StringBuilder(); + StringBuffer msgBuffer = new StringBuffer(); String namespace = config.getAsdcApiNamespace(); - if ((namespace == null) || (namespace.length() == 0)) { - namespace="com:att:sdnctl:asdcapi"; - } + //String namespace = artifact.getType().getNamespace(); msgBuffer.append(""+artifactName+"\n"); + msgBuffer.append(""+artifact.getArtifactVersion()+"\n"); + } + + try { + BufferedReader rdr = new BufferedReader(new FileReader(artifact.getFile())); - try (BufferedReader rdr = new BufferedReader(new FileReader(artifact.getFile()))){ String curLine = rdr.readLine(); - while (curLine != null) { + while (curLine != null) { + if (!curLine.startsWith("") || curLine.contains("")) { + skipThisLine = true; + } + } + + if (!skipThisLine) { + msgBuffer.append(curLine+"\n"); + } } curLine = rdr.readLine(); } + rdr.close(); + } catch (Exception e) { LOG.error("Could not process spool file "+artifact.getFile().getName(), e); - return DistributionStatusEnum.DEPLOY_ERROR; + return(DistributionStatusEnum.DEPLOY_ERROR); } msgBuffer.append("\n"); @@ -963,11 +1025,12 @@ public class SdncUebCallback implements INotificationCallback { final IDistributionClient client, final INotificationData data, final IArtifactInfo relevantArtifact, final DistributionStatusEnum status) { - IDistributionStatusMessage statusMessage = new IDistributionStatusMessage() { + IDistributionStatusMessage statusMessage = new IDistributionStatusMessage() { @Override public long getTimestamp() { - return System.currentTimeMillis(); + long currentTimeMillis = System.currentTimeMillis(); + return currentTimeMillis; } @Override @@ -994,6 +1057,42 @@ public class SdncUebCallback implements INotificationCallback { } + public static IComponentDoneStatusMessage buildComponentStatusMessage( + final IDistributionClient client, final INotificationData data, + final DistributionStatusEnum status) { + IComponentDoneStatusMessage statusMessage = new IComponentDoneStatusMessage() { + + @Override + public long getTimestamp() { + long currentTimeMillis = System.currentTimeMillis(); + return currentTimeMillis; + } + + @Override + public DistributionStatusEnum getStatus() { + return status; + } + + @Override + public String getDistributionID() { + return data.getDistributionID(); + } + + @Override + public String getConsumerID() { + return client.getConfiguration().getConsumerID(); + } + + @Override + public String getComponentName() { + // TODO Auto-generated method stub + return COMPONENT_NAME; + } + }; + return statusMessage; + + } + private HttpURLConnection getRestXmlConnection(String urlString, String method) throws IOException { URL sdncUrl = new URL(urlString); @@ -1027,20 +1126,27 @@ public class SdncUebCallback implements INotificationCallback { String sdncResp = odlConn.send("POST", "application/xml", new String(msgBytes)); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + + dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); + dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); + DocumentBuilder db = dbf.newDocumentBuilder(); - response = db.parse(new ByteArrayInputStream(sdncResp.getBytes())); } catch (Exception e) { LOG.error("Caught exception posting to ODL tier", e); } - return response; + return(response); } private File applyXslts(File srcFile) { + Document doc = null; + + File inFile = srcFile; File outFile = null; @@ -1057,6 +1163,9 @@ public class SdncUebCallback implements INotificationCallback { outFile = File.createTempFile("tmp", "xml"); TransformerFactory factory = TransformerFactory.newInstance(); + factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + //factory.setFeature("http://xml.org/sax/features/external-general-entities", false); -- breaks transform + //factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); Source xslt = new StreamSource(new File(xsltPath)); Transformer transformer = factory.newTransformer(xslt); Source text = new StreamSource(inFile); @@ -1081,12 +1190,12 @@ public class SdncUebCallback implements INotificationCallback { } private String escapeFilename(String str) { + if (str == null) { + str = ""; + } - if (str == null) { - str = ""; - } - StringBuilder retval = new StringBuilder(); - + StringBuffer retval = new StringBuffer(); + for (int i = 0 ; i < str.length() ; i++) { char curchar = str.charAt(i); if (Character.isJavaIdentifierPart(curchar)) { @@ -1098,4 +1207,26 @@ public class SdncUebCallback implements INotificationCallback { } + private boolean artifactIsTosca(IArtifactInfo artifact, File spoolFile) { + + boolean toscaYamlType = false; + boolean toscaCsarType = false; + if (artifact != null) { + String artifactTypeString = artifact.getArtifactType(); + if (artifactTypeString.contains("TOSCA_TEMPLATE")) { + toscaYamlType = true; + } else if (artifactTypeString.contains("TOSCA_CSAR")) { + toscaCsarType = true; + } + } else { + if (spoolFile.toString().contains(".yml")) { + toscaYamlType = true; + } else if (spoolFile.toString().contains(".csar")) { + toscaCsarType = true; + } + } + + return (toscaYamlType||toscaCsarType ? true : false); + } + } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java index a3345c168..35639b366 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java @@ -2,15 +2,15 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. + * Copyright (C) 2017 - 2018 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. @@ -21,38 +21,271 @@ package org.onap.ccsdk.sli.northbound.uebclient; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SdncVFCModel extends SdncBaseModel { - + private static final Logger LOG = LoggerFactory .getLogger(SdncVFCModel.class); - + private String vmType = null; private String vmCount = null; - public SdncVFCModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { - - super(sdcCsarHelper, nodeTemplate); + public SdncVFCModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, DBResourceManager jdbcDataSource) { + super(sdcCsarHelper, nodeTemplate, jdbcDataSource); + // extract properties - vmType = extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VMTYPE); - if ((vmType == null) || (vmType.length() == 0)) { - vmType = extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG); + addParameter("ecomp_generated_naming", extractBooleanValue (nodeTemplate, "nfc_naming#ecomp_generated_naming")); + addParameter("naming_policy", extractValue (nodeTemplate, "nfc_naming#naming_policy")); + vmCount = extractValue (nodeTemplate, "service_template_filter#count"); // need path to vm_count, extracted as service_template_filter#count + if (vmCount.isEmpty()) { + vmCount = "0"; // vm_count can not be null } - //vmCount = extractValue (sdcCsarHelper, nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VMCOUNT); - need path to vm_count - vmCount = "1"; - addParameter("vm_type", vmType); - addParameter("vm_type_tag", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG)); - addParameter("ecomp_generated_naming", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VFCNAMING_ECOMPGENERATEDNAMING)); - addParameter("naming_policy", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VFCNAMING_NAMINGPOLICY)); - addParameter("nfc_naming_code", extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFCCODE)); + vmType = extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG); + addParameter("vm_type", vmType); // populate vm_type with vm_type_tag value + addParameter("vm_type_tag", vmType); + addParameter("nfc_naming_code", extractValue (nodeTemplate, "nfc_naming_code")); + addParameter("nfc_function", extractValue (nodeTemplate, "nfc_function")); + addParameter("high_availability", extractValue (nodeTemplate, "high_availablity")); + addParameter("vm_image_name", extractValue (nodeTemplate, "vm_image_name")); + addParameter("vm_flavor_name", extractValue (nodeTemplate, "vm_flavor_name")); + addParameter("nfc_naming", extractValue (nodeTemplate, "nfc_naming")); + addParameter("min_instances", extractValue (nodeTemplate, "min_instances")); + addParameter("max_instances", extractValue (nodeTemplate, "max_instances")); } + public void insertVFCModelData () throws IOException { + try { + cleanUpExistingToscaData("VFC_MODEL", "customization_uuid", getCustomizationUUID()); + LOG.info("Call insertToscaData for VFC_MODEL where customization_uuid = " + getCustomizationUUID()); + insertToscaData(buildSql("VFC_MODEL", model_yaml), null); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the VFC_MODEL table"); + throw new IOException (e); + } + + } + + public void insertVFCtoNetworkRoleMappingData (NodeTemplate vfcNode) throws IOException { + + // For each VFC node, get CP properties to insert into VFC_TO_NETWORK_ROLE_MAPPING + // VFC_TO_NETWORK_ROLE_MAPPING: vfc_customization_uuid, network_role, network_role_tag, vm_type, ipv4_count, ipv6_count, + // ipv4_use_dhcp, ipv6_use_dhcp, ipv4_ip_version, ipv6_ip_version, extcp_subnetpool_id + Map> cpPropertiesMap = sdcCsarHelper.getCpPropertiesFromVfcAsObject(vfcNode); + + // DEBUG only + if (cpPropertiesMap != null && !cpPropertiesMap.toString().contentEquals("{}")) { + LOG.info("getCpPropertiesFromVfcAsObject for vfc_customization_uuid " + this.getCustomizationUUID() + ": " + cpPropertiesMap.toString()); + } + + // Clean up all VFC_TO_NETWORK_ROLE_MAPPING data for this VFC node + try { + cleanUpExistingToscaData("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", getCustomizationUUID()); + } catch (IOException e) { + LOG.error("Could not clean up data in VFC_TO_NETWORK_ROLE_MAPPING table ", e); + } + + // There will be a cpPropertiesMap entry for each CP which will contain a map of properties to be inserted into VFC_TO_NETWORK_ROLE_MAPPING + // There can be multiple insertions per CP: + // Insert once for each unique IP Version / Subnet Role combination per CP (network_role) + // If there are IPV4 and IPV6 ip_requirements elements that have the same subnet_role (within a CP) combine those parameters for one insert + for (String nodeMapKey : cpPropertiesMap.keySet()) { // there will be one entry in this map per CP (network_role) + LOG.debug("node key = " + nodeMapKey); + Map propsMap = cpPropertiesMap.get(nodeMapKey); + Map commonParams = new HashMap(); // non-IP Version specific parameters + + // Get vm_type from VFC node + SdncBaseModel.addParameter("vm_type", getVmType(), commonParams); + + // Extract non-IP Version specific parameters + String networkRole = nullCheck(propsMap.get("network_role")).isEmpty() ? "default-network-role" : nullCheck(propsMap.get("network_role")); + SdncBaseModel.addParameter("network_role", networkRole, commonParams); // can not be null + SdncBaseModel.addParameter("network_role_tag", nullCheck(propsMap.get("network_role_tag")), commonParams); + SdncBaseModel.addParameter("extcp_subnetpool_id", nullCheck(propsMap.get("subnetpoolid")), commonParams); + String subinterfaceIndicator = nullCheck(propsMap.get("subinterface_indicator")); + if (!subinterfaceIndicator.isEmpty()) { + SdncBaseModel.addParameter("subinterface_indicator", subinterfaceIndicator.contains("true") ? "Y" : "N", commonParams); // boolean Y|N + } + + // Extract IP Version specific parameters + String ipRequirementsString = nullCheck(propsMap.get("ip_requirements")); + //ArrayList> ipPropsList = (ArrayList>) propsMap.get("ip_requirements"); + ArrayList> ipPropsList = new ArrayList>(); + + if (!ipRequirementsString.equals("{}")) { + ipPropsList = (ArrayList>) propsMap.get("ip_requirements"); + } + + // Build lists of all IPV4 and IPV6 ip_requirements elements + ArrayList> ipv4PropParamsList = new ArrayList>(); + ArrayList> ipv6PropParamsList = new ArrayList>(); + + if (ipPropsList != null) { + for (Map ipPropMap : ipPropsList) { + //LOG.info("ip_requirements prop map = " + nullCheck(ipPropMap)); + + String ipVersion = nullCheck(ipPropMap.get("ip_version")); + if (ipVersion == null) { + LOG.error("SdncVFCModel: ipVersion not included in ip_requirements element"); + continue; + } + + String subnetRole = nullCheck(ipPropMap.get("subnet_role")); + + if (ipVersion.contains("4")) { + + // If we have already encountered this subnetRole for IPV4, skip this ip_requirements element + if (!ipPropParamsMapContainsSubnetRole (ipv4PropParamsList, subnetRole)) { + + Map ipv4PropParams = new HashMap(); + SdncBaseModel.addParameter("ipv4_ip_version", ipVersion, ipv4PropParams); + SdncBaseModel.addParameter("ipv4_use_dhcp", nullCheck(ipPropMap.get("dhcp_enabled")).contains("true") ? "Y" : "N", ipv4PropParams); + Map ipCountRequired = (Map)ipPropMap.get("ip_count_required"); + if (ipCountRequired != null && ipCountRequired.get("count") != null) { + SdncBaseModel.addParameter("ipv4_count", nullCheck(ipCountRequired.get("count")), ipv4PropParams); + } + Map floatingIpCountRequired = (Map)ipPropMap.get("floating_ip_count_required"); + if (floatingIpCountRequired != null && floatingIpCountRequired.get("count") != null) { + SdncBaseModel.addParameter("ipv4_floating_count", nullCheck(floatingIpCountRequired.get("count")), ipv4PropParams); + } + SdncBaseModel.addParameter("ipv4_address_plan_name", nullCheck(ipPropMap.get("ip_address_plan_name")), ipv4PropParams); + SdncBaseModel.addParameter("ipv4_vrf_name", nullCheck(ipPropMap.get("vrf_name")), ipv4PropParams); + SdncBaseModel.addParameter("subnet_role", nullCheck(ipPropMap.get("subnet_role")), ipv4PropParams); + + ipv4PropParamsList.add(ipv4PropParams); + + } else { + LOG.error("SdncVFCModel: Additional V4 ip-requirements element encountered for this subnet_role: ", subnetRole); + } + + } else if (ipVersion.contains("6")) { + + // If we have already encountered this subnetRole for IPV6, skip this ip_requirements element + if (!ipPropParamsMapContainsSubnetRole (ipv6PropParamsList, subnetRole)) { + + Map ipv6PropParams = new HashMap(); + SdncBaseModel.addParameter("ipv6_ip_version", ipVersion, ipv6PropParams); + SdncBaseModel.addParameter("ipv6_use_dhcp", nullCheck(ipPropMap.get("dhcp_enabled")).contains("true") ? "Y" : "N", ipv6PropParams); + Map ipCountRequired = (Map)ipPropMap.get("ip_count_required"); + if (ipCountRequired != null && ipCountRequired.get("count") != null) { + SdncBaseModel.addParameter("ipv6_count", nullCheck(ipCountRequired.get("count")), ipv6PropParams); + } + Map floatingIpCountRequired = (Map)ipPropMap.get("floating_ip_count_required"); + if (floatingIpCountRequired != null && floatingIpCountRequired.get("count") != null) { + SdncBaseModel.addParameter("ipv6_floating_count", nullCheck(floatingIpCountRequired.get("count")), ipv6PropParams); + } + SdncBaseModel.addParameter("ipv6_address_plan_name", nullCheck(ipPropMap.get("ip_address_plan_name")), ipv6PropParams); + SdncBaseModel.addParameter("ipv6_vrf_name", nullCheck(ipPropMap.get("vrf_name")), ipv6PropParams); + SdncBaseModel.addParameter("subnet_role", nullCheck(ipPropMap.get("subnet_role")), ipv6PropParams); + + ipv6PropParamsList.add(ipv6PropParams); + + } else { + LOG.error("SdncVFCModel: Additional V6 ip-requirements element encountered for this subnetRole: ", subnetRole); + } + + } else { + LOG.error("SdncVFCModel: invalid IP version encountered: ", ipVersion); + } + + } // for each ip-requirements element + + } // ipPropsList null check + + // After all Common and IP Version specific parameters are extracted, insert IPV4 and IPV6 data separately + // Insert IPV4 data + for (Map ipv4PropParams: ipv4PropParamsList) { + + Map mappingParams = new HashMap(); // final list for single insertion + addParamsToMap(commonParams, mappingParams); + addParamsToMap(ipv4PropParams, mappingParams); + + // Insert ipv4PropParams into VFC_TO_NETWORK_ROLE_MAPPING + try { + LOG.info("Call insertToscaData for VFC_TO_NETWORK_ROLE_MAPPING where vfc_customization_uuid = " + getCustomizationUUID()); + addRequiredParameters(mappingParams); + insertToscaData(SdncBaseModel.getSql("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", getCustomizationUUID(), "", mappingParams), null); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the VFC_TO_NETWORK_ROLE_MAPPING table"); + throw new IOException (e); + } + + } + + // Insert IPV6 data + for (Map ipv6PropParams: ipv6PropParamsList) { + + Map mappingParams = new HashMap(); // final list for single insertion + addParamsToMap(commonParams, mappingParams); + addParamsToMap(ipv6PropParams, mappingParams); + + // Insert ipv6PropParams into VFC_TO_NETWORK_ROLE_MAPPING + try { + LOG.info("Call insertToscaData for VFC_TO_NETWORK_ROLE_MAPPING where vfc_customization_uuid = " + getCustomizationUUID()); + addRequiredParameters(mappingParams); + insertToscaData(SdncBaseModel.getSql("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", getCustomizationUUID(), "", mappingParams), null); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the VFC_TO_NETWORK_ROLE_MAPPING table"); + throw new IOException (e); + } + + } + + } // Outer map loop - one per ExtCP + + } + + protected boolean ipPropParamsMapContainsSubnetRole (ArrayList> ipPropParamsList, String subnetRole) { + + boolean subnetRoleFound = false; + + if (subnetRole != null && !subnetRole.isEmpty()) { + for (Map ipPropMap : ipPropParamsList) { + if (ipPropMap.get("subnet_role").contentEquals(subnetRole)) { + return true; + } + } + } + return subnetRoleFound; + } + + private Map getIpPropMapWithMatchingSubnetRole (ArrayList> ipPropParamsList, String subnetRole) { + + Map ipPropMapMatch = new HashMap(); + + if (subnetRole != null) { + for (Map ipPropMap : ipPropParamsList) { + if (nullCheck(ipPropMap.get("subnet_role")) == subnetRole) { + return ipPropMap; + } + } + } + return ipPropMapMatch; + } + + private void addRequiredParameters (Map mappingParams) { + + // Add parameters which can not be null if they have not already been added - network_role, ipv4_count, ipv6_count + String ipvCountDefault = "0"; + if (!mappingParams.containsKey("ipv4_count")) { + SdncBaseModel.addParameter("ipv4_count", ipvCountDefault, mappingParams); + } + if (!mappingParams.containsKey("ipv6_count")) { + SdncBaseModel.addParameter("ipv6_count", ipvCountDefault, mappingParams); + } + } + public String getVmType() { return vmType; } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java index 41b43c4c9..95f9a0d31 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java @@ -2,15 +2,15 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. + * Copyright (C) 2017 - 2018 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. @@ -21,36 +21,292 @@ package org.onap.ccsdk.sli.northbound.uebclient; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; +import org.onap.sdc.toscaparser.api.Group; import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.Policy; import org.onap.sdc.toscaparser.api.elements.Metadata; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SdncVFModel extends SdncBaseModel { - + private static final Logger LOG = LoggerFactory .getLogger(SdncVFModel.class); - public SdncVFModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { + private String vendor = null; + private String vendorModelDescription = null; + private String nfNamingCode = null; + private String serviceUUID = null; + private String serviceInvariantUUID = null; + + public SdncVFModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, DBResourceManager jdbcDataSource, SdncUebConfiguration config) throws IOException { - super(sdcCsarHelper, nodeTemplate); + super(sdcCsarHelper, nodeTemplate, jdbcDataSource, config); // extract metadata Metadata metadata = nodeTemplate.getMetaData(); addParameter("name", extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_NAME)); - addParameter("vendor", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDOR)); - addParameter("vendor_version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDORRELEASE)); - + vendor = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDOR); + addParameter("vendor", vendor); + vendorModelDescription = extractValue (metadata, "description"); + addParameter("vendor_version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDORRELEASE)); + // extract properties addParameter("ecomp_generated_naming", extractBooleanValue(nodeTemplate, "nf_naming#ecomp_generated_naming")); addParameter("naming_policy", extractValue(nodeTemplate, "nf_naming#naming_policy")); addParameter("nf_type", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)); addParameter("nf_role", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)); - addParameter("nf_code", extractValue( nodeTemplate, "nf_naming_code")); + nfNamingCode = extractValue(nodeTemplate, "nf_naming_code"); + addParameter("nf_code", nfNamingCode); addParameter("nf_function", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)); - addParameter("avail_zone_max_count", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONEMAXCOUNT)); + addIntParameter("avail_zone_max_count", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONEMAXCOUNT)); + addParameter("sdnc_model_name", extractValue(nodeTemplate, "sdnc_model_name")); + addParameter("sdnc_model_version", extractValue(nodeTemplate, "sdnc_model_version")); + addParameter("sdnc_artifact_name", extractValue(nodeTemplate, "sdnc_artifact_name")); + + // store additional properties in ATTRIBUTE_VALUE_PAIR + // additional complex properties are extracted via VfcInstanceGroup + + List vfcInstanceGroupListForVf = sdcCsarHelper.getGroupsOfOriginOfNodeTemplateByToscaGroupType(nodeTemplate, "org.openecomp.groups.VfcInstanceGroup"); + for (Group group : vfcInstanceGroupListForVf){ + + String vfcInstanceGroupFunction = extractGetInputValue(group, nodeTemplate, "vfc_instance_group_function"); + addParameter(extractGetInputName (group, "vfc_instance_group_function"), vfcInstanceGroupFunction, attributeValueParams); + String networkCollectionFunction = extractGetInputValue(group, nodeTemplate, "network_collection_function"); + addParameter(extractGetInputName (group, "network_collection_function"), networkCollectionFunction, attributeValueParams); + String initSubinterfaceQuantity = extractGetInputValue(group, nodeTemplate, "init_subinterface_quantity"); + addParameter(extractGetInputName (group, "init_subinterface_quantity"), initSubinterfaceQuantity, attributeValueParams); + } + } + + public void insertData() throws IOException { + + insertVFModelData(); + insertVFModuleData(nodeTemplate, jdbcDataSource); + insertVFtoNetworkRoleMappingData(); + insertVFCData(); + insertVFCInstanceGroupData(); + //insertVFPolicyData(); - insert Policy data for VF? + } + + private void insertVFModelData () throws IOException { + + try { + cleanUpExistingToscaData("VF_MODEL", "customization_uuid", getCustomizationUUID()) ; + //cleanUpExistingToscaData("SERVICE_MODEL_TO_VF_MODEL_MAPPING", "service_uuid", serviceUUID, "vf_uuid", getUUID()); + + // insert into VF_MODEL/ATTRIBUTE_VALUE_PAIR and SERVICE_MODEL_TO_VF_MODEL_MAPPING + LOG.info("Call insertToscaData for VF_MODEL where customization_uuid = " + getCustomizationUUID()); + insertToscaData(buildSql("VF_MODEL", model_yaml), null); + //insertRelevantAttributeData(); + + Map mappingParams = new HashMap(); + addParameter("service_invariant_uuid", serviceInvariantUUID, mappingParams); + addParameter("vf_uuid", getUUID(), mappingParams); + addParameter("vf_customization_uuid", getCustomizationUUIDNoQuotes(), mappingParams); + //insertToscaData(buildSql("SERVICE_MODEL_TO_VF_MODEL_MAPPING", "service_uuid", serviceUUID, model_yaml, mappingParams), null); + + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the VF_MODEL table"); + throw new IOException (e); + } + + } + + private void insertVFModuleData (NodeTemplate nodeTemplate, DBResourceManager jdbcDataSource) throws IOException { + + List vfModules = sdcCsarHelper.getVfModulesByVf(getCustomizationUUIDNoQuotes()); + for (Group group : vfModules){ + SdncVFModuleModel vfModuleModel = new SdncVFModuleModel(sdcCsarHelper, group, this); + + try { + cleanUpExistingToscaData("VF_MODULE_MODEL", "customization_uuid", vfModuleModel.getCustomizationUUID()); + cleanUpExistingToscaData("VF_MODULE_TO_VFC_MAPPING", "vf_module_customization_uuid", vfModuleModel.getCustomizationUUID()); + LOG.info("Call insertToscaData for VF_MODULE_MODEL where vf_module_customization_uuid = " + vfModuleModel.getCustomizationUUID()); + insertToscaData(vfModuleModel.buildSql("VF_MODULE_MODEL", model_yaml), null); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_MODEL table "); + throw new IOException (e); + } + + // For each VF Module, get the VFC list, insert VF_MODULE_TO_VFC_MAPPING data + // List groupMembers = sdcCsarHelper.getMembersOfGroup(group); - old version + // For each vfcNode (group member) in the groupMembers list, extract vm_type and vm_count. + // Insert vf_module.customizationUUID, vfcNode.customizationUUID and vm_type and vm_count into VF_MODULE_TO_VFC_MAPPING + List groupMembers = sdcCsarHelper.getMembersOfVfModule(nodeTemplate, group); + for (NodeTemplate vfcNode : groupMembers){ + SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, vfcNode, jdbcDataSource); + + try { + LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING where vf_module_customization_uuid = " + vfModuleModel.getCustomizationUUID()); + insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" + + vfModuleModel.getCustomizationUUID() + ", " + vfcModel.getCustomizationUUID() + ", \"" + vfcModel.getVmType() + "\", \"" + vfcModel.getVmCount() + "\")", null); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_TO_VFC_MAPPING table"); + throw new IOException (e); + } + + } + + } + + } + + private void insertVFtoNetworkRoleMappingData () throws IOException { + + // For each VF, insert VF_TO_NETWORK_ROLE_MAPPING data + List cpNodes = sdcCsarHelper.getCpListByVf(getCustomizationUUIDNoQuotes()); + for (NodeTemplate cpNode : cpNodes){ + + // Insert into VF_TO_NETWORK_ROLE_MAPPING vf_customization_uuid and network_role + String cpNetworkRole = sdcCsarHelper.getNodeTemplatePropertyLeafValue(cpNode, "network_role"); + + try { + cleanUpExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", "vf_customization_uuid", getCustomizationUUID()); + LOG.info("Call insertToscaData for VF_TO_NETWORK_ROLE_MAPPING where vf_customization_uuid = " + getCustomizationUUID()); + insertToscaData("insert into VF_TO_NETWORK_ROLE_MAPPING (vf_customization_uuid, network_role) values (" + + getCustomizationUUID() + ", \"" + cpNetworkRole + "\")", null); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the VF_TO_NETWORK_ROLE_MAPPING table"); + throw new IOException (e); + } + + } // CP loop + + } + + private void insertVFCData() throws IOException { + + // For each VF, insert VFC_MODEL data + List vfcNodes = sdcCsarHelper.getVfcListByVf(getCustomizationUUIDNoQuotes()); + for (NodeTemplate vfcNode : vfcNodes){ + + try { + SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, vfcNode, jdbcDataSource); + + vfcModel.insertVFCModelData(); + vfcModel.insertVFCtoNetworkRoleMappingData(vfcNode); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR VFC data"); + throw new IOException (e); + } + } + } + + public void insertVFCInstanceGroupData () throws IOException { + + // Insert Group data in RESOURCE_GROUP + // Store group capabilities and capability properties in NODE_CAPABILITY and NODE_CAPABILITY_PROPERTY table + + // For each VF, insert CFVC data - 1806 + List vfcInstanceGroupListForVf = sdcCsarHelper.getGroupsOfOriginOfNodeTemplateByToscaGroupType(nodeTemplate, "org.openecomp.groups.VfcInstanceGroup"); + for (Group group : vfcInstanceGroupListForVf){ + + SdncGroupModel groupModel = new SdncGroupModel (sdcCsarHelper, group, nodeTemplate, config, jdbcDataSource); + groupModel.insertGroupData(nodeTemplate); + + // For each group, populate NODE_CAPABILITY/NODE_CAPABILITY_PROPERTY + insertNodeCapabilitiesData(group.getCapabilities()); + + // Store relationship between VfcInstanceGroup and node-type=VFC in RESOURCE_GROUP_TO_TARGET_NODE_MAPPING table + // target is each VFC in targets section of group + List targetNodeList = group.getMemberNodes(); + for (NodeTemplate targetNode : targetNodeList) { + + String targetNodeUuid = targetNode.getMetaData().getValue("UUID"); + + // insert RESOURCE_GROUP_TO_TARGET_NODE_MAPPING + try { + Map mappingCleanupParams = new HashMap(); + addParameter("group_uuid", groupModel.getUUID(), mappingCleanupParams); + addParameter("parent_uuid", getUUID(), mappingCleanupParams); + addParameter("target_node_uuid", targetNodeUuid, mappingCleanupParams); + cleanupExistingToscaData("RESOURCE_GROUP_TO_TARGET_NODE_MAPPING", mappingCleanupParams); + + Map mappingParams = new HashMap(); + addParameter("parent_uuid", getUUID(), mappingParams); + addParameter("target_node_uuid", targetNodeUuid, mappingParams); + String targetType = extractValue(targetNode.getMetaData(), "type"); + addParameter("target_type", targetType, mappingParams); + String tableName = ""; + switch (targetType) { + case "CVFC": + tableName = "VFC_MODEL"; + break; + case "VL": + tableName = "NETWORK_MODEL"; + break; + } + addParameter("table_name", tableName, mappingParams); + LOG.info("Call insertToscaData for RESOURCE_GROUP_TO_TARGET_NODE_MAPPING where group_uuid = " + groupModel.getUUID() + " and target_node_uuid = " + targetNodeUuid); + insertToscaData(buildSql("RESOURCE_GROUP_TO_TARGET_NODE_MAPPING", "group_uuid", groupModel.getUUID(), model_yaml, mappingParams), null); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the RESOURCE_GROUP_TO_TARGET_NODE_MAPPING"); + throw new IOException (e); + } + + // For each target node, get External policies + insertPolicyData(nodeTemplate, targetNode, "org.openecomp.policies.External"); + } + } + } + + private void insertVFPolicyData() throws IOException { + + // For each VF node, get Policy data (is VFC the origin or target?) + List policyList = sdcCsarHelper.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nodeTemplate, "org.openecomp.policies.External"); + for (Policy policy : policyList){ + + policy.getmetadata(); + Map propMap = policy.getPolicyProperties(); + } + } + + public String getVendor() { + return vendor; + } + + public void setVendor(String vendor) { + this.vendor = vendor; + } + + public String getVendorModelDescription() { + return vendorModelDescription; + } + + public void setVendorModelDescription(String vendorModelDescription) { + this.vendorModelDescription = vendorModelDescription; + } + + public String getNfNamingCode() { + return nfNamingCode; + } + + public void setNfNamingCode(String nfNamingCode) { + this.nfNamingCode = nfNamingCode; + } + + public String getServiceUUID() { + return serviceUUID; + } + public void setServiceUUID(String serviceUUID) { + this.serviceUUID = serviceUUID; + } + + public String getServiceInvariantUUID() { + return serviceInvariantUUID; + } + + public void setServiceInvariantUUID(String serviceInvariantUUID) { + this.serviceInvariantUUID = serviceInvariantUUID; } } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java index 60bc3c433..64bceb8cd 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. + * Copyright (C) 2017 - 2018 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. @@ -32,12 +32,14 @@ public class SdncVFModuleModel extends SdncBaseModel { private static final Logger LOG = LoggerFactory .getLogger(SdncVFModuleModel.class); - public SdncVFModuleModel(ISdcCsarHelper sdcCsarHelper, Group group) { + public SdncVFModuleModel(ISdcCsarHelper sdcCsarHelper, Group group, SdncVFModel vfNodeModel) { super(sdcCsarHelper, group); + //addParameter("vf_customization_uuid", vfNodeModel.getCustomizationUUIDNoQuotes()); // extract properties addParameter("vf_module_type", extractValue(group, SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE)); + //addParameter("vf_module_label", extractValue(group, "vf_module_label")); addIntParameter("availability_zone_count", extractValue(group, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)); addParameter("ecomp_generated_vm_assignments", extractBooleanValue(group, SdcPropertyNames.PROPERTY_NAME_ECOMPGENERATEDVMASSIGNMENTS)); } diff --git a/ueb-listener/src/main/resources/normalizeTagNames.xslt b/ueb-listener/src/main/resources/normalizeTagNames.xslt index 6594ccfa0..c37a5e049 100755 --- a/ueb-listener/src/main/resources/normalizeTagNames.xslt +++ b/ueb-listener/src/main/resources/normalizeTagNames.xslt @@ -11,4 +11,3 @@ num of software instances - diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java index e8c7b1afd..360c36c9f 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java @@ -6,6 +6,7 @@ package org.onap.ccsdk.sli.northbound.uebclient; import org.junit.Test; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.toscaparser.api.NodeTemplate; + import org.onap.ccsdk.sli.core.dblib.DBResourceManager; public class SdncARModelTest { @@ -13,7 +14,8 @@ package org.onap.ccsdk.sli.northbound.uebclient; public void testSdncARModelConstructor() { ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); NodeTemplate nodeTemplate = mock(NodeTemplate.class); - SdncARModel testSdncARModel = new SdncARModel(mockCsarHelper,nodeTemplate); + DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); + SdncARModel testSdncARModel = new SdncARModel(mockCsarHelper,nodeTemplate,mockDBResourceManager); assertNotNull(testSdncARModel); } diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java index 9df89fb24..d50c47a40 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java @@ -8,6 +8,7 @@ import org.junit.Before; import org.junit.Test; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; public class SdncNodeModelTest { @@ -17,7 +18,8 @@ public class SdncNodeModelTest { public void setUp() throws Exception { ISdcCsarHelper isdcCsarHelper = mock(ISdcCsarHelper.class); NodeTemplate nodeTemplate = mock(NodeTemplate.class); - sdncNodeModel = new SdncNodeModel(isdcCsarHelper, nodeTemplate); + DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); + sdncNodeModel = new SdncNodeModel(isdcCsarHelper, nodeTemplate, mockDBResourceManager); sdncNodeModel.setServiceUUID("0e8d757f-1c80-40af-85de-31d64f1f5af8"); sdncNodeModel.setEcompGeneratedNaming("hello-world"); } diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java index f03a09fcf..a09c5a2ba 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java @@ -8,6 +8,7 @@ import org.junit.Before; import org.junit.Test; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; public class SdncVFCModelTest { @@ -17,7 +18,8 @@ public class SdncVFCModelTest { public void setup() { ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); NodeTemplate mockNodeTemplate = mock(NodeTemplate.class); - testSdncVFCModel = new SdncVFCModel(mockCsarHelper, mockNodeTemplate); + DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); + testSdncVFCModel = new SdncVFCModel(mockCsarHelper, mockNodeTemplate, mockDBResourceManager); testSdncVFCModel.setVmType("Test-type"); testSdncVFCModel.setVmCount("5"); diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java index 881018ef6..1fd10104c 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java @@ -6,6 +6,7 @@ import static org.mockito.Mockito.mock; import org.junit.Test; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.toscaparser.api.Group; +import org.onap.ccsdk.sli.northbound.uebclient.SdncVFModel; public class SdncVFModuleModelTest { @@ -13,7 +14,8 @@ public class SdncVFModuleModelTest { public void testSdncVFModuleModelConstructor() { Group mockGroup = mock(Group.class); ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); - SdncVFModuleModel testSdncVFModel = new SdncVFModuleModel(mockCsarHelper, mockGroup); + SdncVFModel mockSdncVFModel = mock(SdncVFModel.class); + SdncVFModuleModel testSdncVFModel = new SdncVFModuleModel(mockCsarHelper, mockGroup, mockSdncVFModel); assertNotNull(testSdncVFModel); } diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java index b53bdb392..d0a94d4bd 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java @@ -214,18 +214,18 @@ public class TestSdncUebCallback { when(mockProcessArtifact1.getArtifactTimeout()).thenReturn(110); mockProcessArtifact2 = mock(IArtifactInfo.class); - when(mockProcessArtifact1.getArtifactName()).thenReturn("mockProcessArtifact2"); - when(mockProcessArtifact1.getArtifactType()).thenReturn("DG_XML"); - when(mockProcessArtifact1.getArtifactURL()).thenReturn("https://asdc.sdc.com/v1/catalog/services/srv1/2.0/resources/aaa/1.0/artifacts/aaa.yml"); - when(mockProcessArtifact1.getArtifactChecksum()).thenReturn("456jhgt 1234ftg"); - when(mockProcessArtifact1.getArtifactTimeout()).thenReturn(110); + when(mockProcessArtifact2.getArtifactName()).thenReturn("mockProcessArtifact2"); + when(mockProcessArtifact2.getArtifactType()).thenReturn("DG_XML"); + when(mockProcessArtifact2.getArtifactURL()).thenReturn("https://asdc.sdc.com/v1/catalog/services/srv1/2.0/resources/aaa/1.0/artifacts/aaa.yml"); + when(mockProcessArtifact2.getArtifactChecksum()).thenReturn("456jhgt 1234ftg"); + when(mockProcessArtifact2.getArtifactTimeout()).thenReturn(110); mockProcessArtifact3 = mock(IArtifactInfo.class); - when(mockProcessArtifact1.getArtifactName()).thenReturn("mockProcessArtifact3"); - when(mockProcessArtifact1.getArtifactType()).thenReturn("HEAT"); - when(mockProcessArtifact1.getArtifactURL()).thenReturn("https://asdc.sdc.com/v1/catalog/services/srv1/2.0/resources/aaa/1.0/artifacts/aaa.yml"); - when(mockProcessArtifact1.getArtifactChecksum()).thenReturn("123tfg123 543gtd"); - when(mockProcessArtifact1.getArtifactTimeout()).thenReturn(110); + when(mockProcessArtifact3.getArtifactName()).thenReturn("mockProcessArtifact3"); + when(mockProcessArtifact3.getArtifactType()).thenReturn("HEAT"); + when(mockProcessArtifact3.getArtifactURL()).thenReturn("https://asdc.sdc.com/v1/catalog/services/srv1/2.0/resources/aaa/1.0/artifacts/aaa.yml"); + when(mockProcessArtifact3.getArtifactChecksum()).thenReturn("123tfg123 543gtd"); + when(mockProcessArtifact3.getArtifactTimeout()).thenReturn(110); mockServiceArtifact1 = mock(IArtifactInfo.class); @@ -267,7 +267,16 @@ public class TestSdncUebCallback { cb.setJdbcDataSource(dblibSvc); INotificationData iData = mock(INotificationData.class); + /*IArtifactInfo iArtifactInfo = mock(IArtifactInfo.class); + when(iArtifactInfo.getArtifactName()).thenReturn("testArtifact1"); + when(iArtifactInfo.getArtifactType()).thenReturn("TOSCA_CSAR"); + List artifactInfoList = new ArrayList(); + artifactInfoList.add(iArtifactInfo);*/ + + when(iData.getServiceName()).thenReturn("testServiceName"); + //when(iData.getServiceArtifacts()).thenReturn(artifactInfoList); cb.activateCallback(iData); + } @@ -292,6 +301,16 @@ public class TestSdncUebCallback { when(mockData.getServiceName()).thenReturn("Test_service_name"); when(mockData.getServiceArtifacts()).thenReturn(processLevelArtifactList); + /*IArtifactInfo iArtifactInfo = mock(IArtifactInfo.class); + when(iArtifactInfo.getArtifactName()).thenReturn("testArtifact1"); + when(iArtifactInfo.getArtifactType()).thenReturn("TOSCA_CSAR"); + List artifactInfoList = new ArrayList(); + artifactInfoList.add(iArtifactInfo); + + //when(mockData.getServiceName()).thenReturn("testServiceName"); + when(mockData.getServiceArtifacts()).thenReturn(artifactInfoList);*/ + + SdncUebCallback cb1 = new SdncUebCallback(iDistClient1, config); cb1.activateCallback(mockData); assertTrue(true); -- cgit 1.2.3-korg From 7e6d57e2c6dcf22567b7ef130d2a3c3a6866fe5f Mon Sep 17 00:00:00 2001 From: "lalena.aria" Date: Tue, 24 Jul 2018 09:28:47 -0400 Subject: Adding junits for refactored UEB Listener Changes made: Added null check in SdncBaseModel.java Cleaned up in SdncVFCModel.java Added tests in SdncARModelTest.java, SdncNodeModelTest and SdncVFCModelTest Added files SdncGroupModelTest, SdncServiceModelTest and SdncVFModelTest Change-Id: If0261c94d67a61b0b19db51cbbbff7ae32912d06 Issue-ID: CCSDK-360 Signed-off-by: lalena.aria --- .../sli/northbound/uebclient/SdncBaseModel.java | 28 ++++--- .../sli/northbound/uebclient/SdncVFCModel.java | 14 ---- .../sli/northbound/uebclient/SdncARModelTest.java | 33 ++++++-- .../northbound/uebclient/SdncGroupModelTest.java | 34 ++++++++ .../northbound/uebclient/SdncNodeModelTest.java | 28 ++++++- .../northbound/uebclient/SdncServiceModelTest.java | 77 ++++++++++++++++++ .../sli/northbound/uebclient/SdncVFCModelTest.java | 79 ++++++++++++++++-- .../sli/northbound/uebclient/SdncVFModelTest.java | 95 ++++++++++++++++++++++ 8 files changed, 343 insertions(+), 45 deletions(-) create mode 100644 ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModelTest.java create mode 100644 ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModelTest.java create mode 100644 ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModelTest.java (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index fd5a29637..7f0e9398f 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -887,13 +887,15 @@ public class SdncBaseModel { try { int rowCount = 0; CachedRowSet data = jdbcDataSource.getData("SELECT * from " + tableName + " where " + keyName + " = " + keyValue + ";", null, ""); - while(data.next()) { + if (data != null) { + while(data.next()) { rowCount ++; - } - if (rowCount != 0) { - LOG.debug("cleanUpExistingToscaData from: " + tableName + " for " + keyValue); - jdbcDataSource.writeData("DELETE from " + tableName + " where " + keyName + " = " + keyValue + ";", null, null); - } + } + if (rowCount != 0) { + LOG.debug("cleanUpExistingToscaData from: " + tableName + " for " + keyValue); + jdbcDataSource.writeData("DELETE from " + tableName + " where " + keyName + " = " + keyValue + ";", null, null); + } + } } catch (SQLException e) { LOG.error("Could not clean up existing " + tableName + " for " + keyValue, e); @@ -907,13 +909,15 @@ public class SdncBaseModel { try { int rowCount = 0; CachedRowSet data = jdbcDataSource.getData("SELECT * from " + tableName + " where " + key1Name + " = " + key1Value + " AND " + key2Name + " = " + key2Value + ";", null, ""); - while(data.next()) { + if (data != null) { + while(data.next()) { rowCount ++; - } - if (rowCount != 0) { - LOG.debug("cleanUpExistingToscaData from : " + tableName + " for " + key1Value + " and " + key2Value); - jdbcDataSource.writeData("DELETE from " + tableName + " where " + key1Name + " = " + key1Value + " AND " + key2Name + " = " + key2Value + ";", null, null); - } + } + if (rowCount != 0) { + LOG.debug("cleanUpExistingToscaData from : " + tableName + " for " + key1Value + " and " + key2Value); + jdbcDataSource.writeData("DELETE from " + tableName + " where " + key1Name + " = " + key1Value + " AND " + key2Name + " = " + key2Value + ";", null, null); + } + } } catch (SQLException e) { LOG.error("Could not clean up existing " + tableName + " for " + key1Value + " and " + key2Value, e); diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java index 35639b366..5977e2888 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java @@ -260,20 +260,6 @@ public class SdncVFCModel extends SdncBaseModel { return subnetRoleFound; } - private Map getIpPropMapWithMatchingSubnetRole (ArrayList> ipPropParamsList, String subnetRole) { - - Map ipPropMapMatch = new HashMap(); - - if (subnetRole != null) { - for (Map ipPropMap : ipPropParamsList) { - if (nullCheck(ipPropMap.get("subnet_role")) == subnetRole) { - return ipPropMap; - } - } - } - return ipPropMapMatch; - } - private void addRequiredParameters (Map mappingParams) { // Add parameters which can not be null if they have not already been added - network_role, ipv4_count, ipv6_count diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java index 360c36c9f..ea6499cd3 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java @@ -2,22 +2,43 @@ package org.onap.ccsdk.sli.northbound.uebclient; import static org.junit.Assert.*; import static org.mockito.Mockito.*; - - import org.junit.Test; + +import java.io.IOException; + +import org.junit.Before; +import org.junit.Test; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.toscaparser.api.NodeTemplate; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; public class SdncARModelTest { - @Test - public void testSdncARModelConstructor() { + SdncARModel testSdncARModel = null; + + @Before + public void setUp() throws Exception { ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); NodeTemplate nodeTemplate = mock(NodeTemplate.class); DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); - SdncARModel testSdncARModel = new SdncARModel(mockCsarHelper,nodeTemplate,mockDBResourceManager); + testSdncARModel = new SdncARModel(mockCsarHelper,nodeTemplate,mockDBResourceManager); assertNotNull(testSdncARModel); } + @Test + public void testSetGetSubcategory() { + String subcategory = "test-subcategory"; + testSdncARModel.setSubcategory(subcategory); + String result = testSdncARModel.getSubcategory(); + assertEquals(subcategory, result); + } + + @Test + public void testInsertAllottedResourceModelData() { + try { + testSdncARModel.insertAllottedResourceModelData(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } - diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModelTest.java new file mode 100644 index 000000000..0c6030b44 --- /dev/null +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModelTest.java @@ -0,0 +1,34 @@ +package org.onap.ccsdk.sli.northbound.uebclient; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +import java.io.IOException; + +import org.junit.Test; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.Group; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; + + public class SdncGroupModelTest { + + @Test + public void testSdncGroupModelConstructor() { + ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); + NodeTemplate nodeTemplate = mock(NodeTemplate.class); + Group group = mock(Group.class); + DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); + SdncUebConfiguration mockSdncUebConfiguration = mock(SdncUebConfiguration.class); + SdncGroupModel testSdncGroupModel = null; + try { + testSdncGroupModel = new SdncGroupModel(mockCsarHelper,group,nodeTemplate,mockSdncUebConfiguration,mockDBResourceManager); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertNotNull(testSdncGroupModel); + } + + } + diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java index d50c47a40..a77c5adbf 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java @@ -2,12 +2,15 @@ package org.onap.ccsdk.sli.northbound.uebclient; import static org.junit.Assert.*; -import static org.mockito.Mockito.*; - +import static org.mockito.Mockito.*; + +import java.io.IOException; + import org.junit.Before; import org.junit.Test; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; public class SdncNodeModelTest { @@ -18,7 +21,13 @@ public class SdncNodeModelTest { public void setUp() throws Exception { ISdcCsarHelper isdcCsarHelper = mock(ISdcCsarHelper.class); NodeTemplate nodeTemplate = mock(NodeTemplate.class); + Metadata mockMetadata = mock(Metadata.class); DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); + + when(nodeTemplate.getMetaData()).thenReturn(mockMetadata); + when(isdcCsarHelper.getMetadataPropertyValue(mockMetadata, "customizationUUID")).thenReturn("aaaa-bbbb-cccc-dddd"); + when(isdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "network_type")).thenReturn("test-network-type"); + sdncNodeModel = new SdncNodeModel(isdcCsarHelper, nodeTemplate, mockDBResourceManager); sdncNodeModel.setServiceUUID("0e8d757f-1c80-40af-85de-31d64f1f5af8"); sdncNodeModel.setEcompGeneratedNaming("hello-world"); @@ -39,7 +48,7 @@ public class SdncNodeModelTest { @Test public void testGetSqlString() { String result = sdncNodeModel.getSql("TEST-HELLO"); - String test = "INSERT into NETWORK_MODEL (service_uuid, customization_uuid, model_yaml, ecomp_generated_naming) values (0e8d757f-1c80-40af-85de-31d64f1f5af8, \"\", \"TEST-HELLO\", \"hello-world\");"; + String test = "INSERT into NETWORK_MODEL (service_uuid, customization_uuid, model_yaml, ecomp_generated_naming, network_type) values (0e8d757f-1c80-40af-85de-31d64f1f5af8, \"aaaa-bbbb-cccc-dddd\", \"TEST-HELLO\", \"hello-world\", \"test-network-type\");"; assertEquals(test, result); } @@ -48,4 +57,15 @@ public class SdncNodeModelTest { String result = sdncNodeModel.getVpnBindingsSql(); assertNotNull(result); } + + @Test + public void testInsertNetworkModelData() { + try { + sdncNodeModel.insertNetworkModelData(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModelTest.java new file mode 100644 index 000000000..95f5a75ec --- /dev/null +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModelTest.java @@ -0,0 +1,77 @@ +package org.onap.ccsdk.sli.northbound.uebclient; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +import java.io.IOException; + +import org.junit.Before; +import org.junit.Test; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.toscaparser.api.elements.Metadata; + + public class SdncServiceModelTest { + + SdncServiceModel testSdncServiceModel = null; + + @Before + public void setUp() throws Exception { + ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); + Metadata mockMetadata = mock(Metadata.class); + + when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "UUID")).thenReturn("aaaa-bbbb-cccc-dddd"); + when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "invariantUUID")).thenReturn("bbbb-cccc-dddd-eeee"); + when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "namingPolicy")).thenReturn("test-naming-policy"); + + testSdncServiceModel = new SdncServiceModel(mockCsarHelper,mockMetadata); + + assertNotNull(testSdncServiceModel); + } + + @Test + public void testSetGetServiceUUID() { + String newServiceUuid = "cccc-dddd-eeee-ffff"; + testSdncServiceModel.setServiceUUID(newServiceUuid); + String result = testSdncServiceModel.getServiceUUID(); + assertEquals("\"" + newServiceUuid + "\"", result); + } + + @Test + public void testSetGetServiceInvariantUUID() { + String result = testSdncServiceModel.getServiceInvariantUUID(); + assertEquals(result, "\"bbbb-cccc-dddd-eeee\""); + } + + @Test + public void testSetGeServiceInstanceNamePrefix() { + String serviceInstanceNamePrefix = "test-service-instance-name-prefix"; + testSdncServiceModel.setServiceInstanceNamePrefix(serviceInstanceNamePrefix); + String result = testSdncServiceModel.getServiceInstanceNamePrefix(); + assertEquals(serviceInstanceNamePrefix, result); + } + + @Test + public void testSetGetResourceVendor() { + String resourceVendor = "Fortinet"; + testSdncServiceModel.setResourceVendor(resourceVendor); + String result = testSdncServiceModel.getResourceVendor(); + assertEquals(resourceVendor, result); + } + + @Test + public void testSetGetResourceVendorRelease() { + String resourceVendorRelease = "1.0.0"; + testSdncServiceModel.setResourceVendorRelease(resourceVendorRelease); + String result = testSdncServiceModel.getResourceVendorRelease(); + assertEquals(resourceVendorRelease, result); + } + + @Test + public void testGetSqlString() { + String result = testSdncServiceModel.getSql("TEST-HELLO"); + String test = "INSERT into SERVICE_MODEL (service_uuid, model_yaml, filename, naming_policy, invariant_uuid) values (\"aaaa-bbbb-cccc-dddd\", \"TEST-HELLO\", \"null\", \"test-naming-policy\", \"bbbb-cccc-dddd-eeee\");"; + assertEquals(test, result); + } + + + } diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java index a09c5a2ba..469312359 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java @@ -1,24 +1,55 @@ package org.onap.ccsdk.sli.northbound.uebclient; import static org.junit.Assert.*; -import static org.mockito.Mockito.*; - - +import static org.mockito.Mockito.*; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.ArrayList; + import org.junit.Before; import org.junit.Test; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; public class SdncVFCModelTest { SdncVFCModel testSdncVFCModel; + NodeTemplate mockVFCNodeTemplate = null; @Before public void setup() { ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); NodeTemplate mockNodeTemplate = mock(NodeTemplate.class); + mockVFCNodeTemplate = mock(NodeTemplate.class); + Metadata mockMetadata = mock(Metadata.class); DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); + + when(mockNodeTemplate.getMetaData()).thenReturn(mockMetadata); + when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "customizationUUID")).thenReturn("aaaa-bbbb-cccc-dddd"); + when(mockCsarHelper.getNodeTemplatePropertyLeafValue(mockNodeTemplate, "nfc_naming_code")).thenReturn("test-nfc-naming-code"); + + Map> cpPropertiesMap = new HashMap>(); + Map propertiesMap = new HashMap(); + propertiesMap.put("network-role", "test-network-role"); + propertiesMap.put("network-role-tag", "test-network-role-tag"); + + ArrayList> ipRequirementsList = new ArrayList>(); + Map ip4Prop = new HashMap(); + ip4Prop.put("ip_version", "4"); + ipRequirementsList.add(ip4Prop); + Map ip6Prop = new HashMap(); + ip4Prop.put("ip_version", "6"); + ipRequirementsList.add(ip4Prop); + + propertiesMap.put("ip_requirements", ipRequirementsList); + cpPropertiesMap.put("cp-node-1", propertiesMap); + when(mockCsarHelper.getCpPropertiesFromVfcAsObject(mockVFCNodeTemplate)).thenReturn(cpPropertiesMap); + testSdncVFCModel = new SdncVFCModel(mockCsarHelper, mockNodeTemplate, mockDBResourceManager); testSdncVFCModel.setVmType("Test-type"); testSdncVFCModel.setVmCount("5"); @@ -26,13 +57,43 @@ public class SdncVFCModelTest { } @Test - public void testSdncVFCModelGetVmType() { - assertEquals(testSdncVFCModel.getVmType(), "Test-type"); + public void testSdncVFCModelSetGetVmType() { + String newVMtype = "new-vm-type"; + testSdncVFCModel.setVmType(newVMtype); + assertEquals(testSdncVFCModel.getVmType(), "new-vm-type"); } @Test - public void testSdncVFCModelGetVmCount() { - assertEquals(testSdncVFCModel.getVmCount(), "5"); + public void testSdncVFCModelSetGetVmCount() { + String newVMcount = "4"; + testSdncVFCModel.setVmCount(newVMcount); + assertEquals(testSdncVFCModel.getVmCount(), "4"); } - + + @Test + public void testInsertVFCModelData() { + try { + testSdncVFCModel.insertVFCModelData(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testInsertVFCtoNetworkRoleMappingData() { + try { + testSdncVFCModel.insertVFCtoNetworkRoleMappingData(mockVFCNodeTemplate); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testIpPropParamsMapContainsSubnetRole() { + ArrayList> testList = new ArrayList>(); + testSdncVFCModel.ipPropParamsMapContainsSubnetRole(testList, "test-subnet-role"); + } + } diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModelTest.java new file mode 100644 index 000000000..3f795a354 --- /dev/null +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModelTest.java @@ -0,0 +1,95 @@ +package org.onap.ccsdk.sli.northbound.uebclient; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +import java.io.IOException; + +import org.junit.Before; +import org.junit.Test; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.elements.Metadata; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; + + public class SdncVFModelTest { + + SdncVFModel testSdncVFModel = null; + + @Before + public void setUp() throws Exception { + ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); + NodeTemplate nodeTemplate = mock(NodeTemplate.class); + Metadata mockMetadata = mock(Metadata.class); + DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); + SdncUebConfiguration mockSdncUebConfiguration = mock(SdncUebConfiguration.class); + + when(nodeTemplate.getMetaData()).thenReturn(mockMetadata); + when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "customizationUUID")).thenReturn("aaaa-bbbb-cccc-dddd"); + when(mockCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming_code")).thenReturn("test-nf-naming-code"); + + try { + testSdncVFModel = new SdncVFModel(mockCsarHelper,nodeTemplate,mockDBResourceManager,mockSdncUebConfiguration); + testSdncVFModel.setServiceUUID("bbbb-cccc-dddd-eeee"); + testSdncVFModel.setServiceInvariantUUID("cccc-dddd-eeee-ffff"); + testSdncVFModel.setVendor("Cisco"); + testSdncVFModel.setVendorModelDescription("Cisco Equipment Model"); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + assertNotNull(testSdncVFModel); + } + + @Test + public void testSetGetVendor() { + String newVendorModel = "new-vendor-model"; + testSdncVFModel.setVendor(newVendorModel); + String result = testSdncVFModel.getVendor(); + assertEquals(result, newVendorModel); + } + + @Test + public void testSetGetVendorModelDescription() { + String newVendorModelDescription = "new-vendor-model-description"; + testSdncVFModel.setVendorModelDescription(newVendorModelDescription); + String result = testSdncVFModel.getVendorModelDescription(); + assertEquals(result, newVendorModelDescription); + } + + @Test + public void testSetGetNfNamingCode() { + String newNfNamingCode = "new-nf-naming-code"; + testSdncVFModel.setNfNamingCode(newNfNamingCode); + String result = testSdncVFModel.getNfNamingCode(); + assertEquals(result, newNfNamingCode); + } + + @Test + public void testSetGetServiceUUID() { + String newServiceUuid = "cccc-dddd-eeee-ffff"; + testSdncVFModel.setServiceUUID(newServiceUuid); + String result = testSdncVFModel.getServiceUUID(); + assertEquals(newServiceUuid, result); + } + + @Test + public void testSetGetServiceInvariantUUID() { + String newServiceInvariantUuid = "dddd-eeee-ffff-eeee"; + testSdncVFModel.setServiceInvariantUUID(newServiceInvariantUuid); + String result = testSdncVFModel.getServiceInvariantUUID(); + assertEquals(result, newServiceInvariantUuid); + } + + @Test + public void testInsertData() { + try { + testSdncVFModel.insertData(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + } -- cgit 1.2.3-korg From 75a7aa446b04504739cc2249d81116811a136111 Mon Sep 17 00:00:00 2001 From: Parshad Patel Date: Tue, 24 Jul 2018 19:58:14 +0900 Subject: Fix sonar issues Fix use try-with-resources issues in ccsdk/sli/northbound Issue-ID: CCSDK-332 Change-Id: Ibc61e6b3ec81e774556172c63c0ca062b6bd6a26 Signed-off-by: Parshad Patel --- .../sli/northbound/asdcapi/AsdcApiProvider.java | 4 +--- .../sli/northbound/uebclient/SdncUebCallback.java | 26 ++++++++-------------- 2 files changed, 10 insertions(+), 20 deletions(-) (limited to 'ueb-listener/src') diff --git a/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java index 0c2ce2fc2..27280d2d3 100644 --- a/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java +++ b/asdcApi/provider/src/main/java/org/onap/ccsdk/sli/northbound/asdcapi/AsdcApiProvider.java @@ -179,14 +179,12 @@ public class AsdcApiProvider implements AutoCloseable, ASDCAPIService { InstanceIdentifier artifactInstanceId = InstanceIdentifier.builder(Artifacts.class) .child(Artifact.class, new ArtifactKey(aName, aVersion)).build(); - ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction(); Optional data = null; - try { + try(ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction()) { data = (Optional) readTx.read(LogicalDatastoreType.CONFIGURATION, artifactInstanceId).get(); } catch (InterruptedException | ExecutionException e) { LOG.error("Caught Exception reading MD-SAL for ["+aName+","+ aVersion+"] " ,e); return false; - } return data.isPresent(); diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index 866fd14d7..224a51998 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -482,24 +482,19 @@ public class SdncUebCallback implements INotificationCallback { // Save zip if TOSCA_CSAR if (artifact.getArtifactType().contains("TOSCA_CSAR") || artifact.getArtifactName().contains(".csar")) { - try { - - FileOutputStream outFile = new FileOutputStream(incomingDir.getAbsolutePath() + "/" + artifact.getArtifactName()); - outFile.write(payloadBytes, 0, payloadBytes.length); - outFile.close(); - writeSucceeded = true; - } catch (Exception e) { - LOG.error("Unable to save downloaded zip file to spool directory ("+ incomingDir.getAbsolutePath() +")", e); - } + try(FileOutputStream outFile = new FileOutputStream(incomingDir.getAbsolutePath() + "/" + artifact.getArtifactName())) { + outFile.write(payloadBytes, 0, payloadBytes.length); + writeSucceeded = true; + } catch (Exception e) { + LOG.error("Unable to save downloaded zip file to spool directory ("+ incomingDir.getAbsolutePath() +")", e); + } } else { String payload = new String(payloadBytes); - try { - FileWriter spoolFileWriter = new FileWriter(spoolFile); + try(FileWriter spoolFileWriter = new FileWriter(spoolFile)) { spoolFileWriter.write(payload); - spoolFileWriter.close(); writeSucceeded = true; } catch (Exception e) { LOG.error("Unable to save downloaded file to spool directory ("+ incomingDir.getAbsolutePath() +")", e); @@ -943,9 +938,8 @@ public class SdncUebCallback implements INotificationCallback { msgBuffer.append(""+artifact.getArtifactVersion()+"\n"); } - try { - BufferedReader rdr = new BufferedReader(new FileReader(artifact.getFile())); - + try(BufferedReader rdr = new BufferedReader(new FileReader(artifact.getFile()))) { + String curLine = rdr.readLine(); while (curLine != null) { @@ -966,8 +960,6 @@ public class SdncUebCallback implements INotificationCallback { } curLine = rdr.readLine(); } - rdr.close(); - } catch (Exception e) { LOG.error("Could not process spool file "+artifact.getFile().getName(), e); return(DistributionStatusEnum.DEPLOY_ERROR); -- cgit 1.2.3-korg From f6e8db81573312f7b1085f6b55ad2bd4b7eba20d Mon Sep 17 00:00:00 2001 From: "lalena.aria" Date: Mon, 30 Jul 2018 14:55:25 -0400 Subject: Add external policy ingestion for VF nodes Changes made: Added SdncBaseModel.insertPolicyData for VF nodes. Added call to insertPolicyData from VF node ingestion. Change-Id: I0df1217352354068f11b0cc01923b564c730a149 Issue-ID: CCSDK-404 Signed-off-by: lalena.aria --- .../sli/northbound/uebclient/SdncBaseModel.java | 124 ++++++++++++++++----- .../sli/northbound/uebclient/SdncVFModel.java | 11 +- 2 files changed, 101 insertions(+), 34 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index 7f0e9398f..57be926bc 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -264,35 +264,29 @@ public class SdncBaseModel { List policyList = sdcCsarHelper.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nodeTemplate, policyType); //List policyList2 = sdcCsarHelper.getPoliciesOfTopologyTemplateByToscaPolicyType(policyType); // returns nothing //List policyList3 = sdcCsarHelper.getPoliciesOfTargetByToscaPolicyType(nodeTemplate, policyType); // returns nothing - + + String resourceUuid = getUUID(); + for (Policy policy : policyList) { - String resourceUuid = getUUID(); - // extract metadata - //policy.getmetadata(); - NPE - //Metadata metadata = policy.getMetadata(); - - //String policyUuid = extractValue(metadata, "UUID"); + // extract policy metadata String policyUuid = policy.getMetaData().getOrDefault("UUID", "").toString(); - //String policyInvariantUuid = extractValue(metadata, "invariantUUID"); String policyInvariantUuid = policy.getMetaData().getOrDefault("invariantUUID", "").toString(); - //String policyCustomizationUuid = extractValue(metadata, "customizationUUID"); String policyCustomizationUuid = policy.getMetaData().getOrDefault("customizationUUID", "").toString(); + // cleanup existing RESOURCE_POLICY data Map cleanupParams = new HashMap(); addParameter("resource_uuid", resourceUuid, cleanupParams); addParameter("policy_uuid", policyUuid, cleanupParams); addParameter("policy_invariant_uuid", policyInvariantUuid, cleanupParams); + // insert into RESOURCE_POLICY Map policyParams = new HashMap(); addParameter("policy_uuid", policyUuid, policyParams); addParameter("policy_customization_uuid", policyCustomizationUuid, policyParams); addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams); - //addParameter("policy_name", extractValue(metadata, "name"), policyParams); addParameter("policy_name", policy.getMetaData().getOrDefault("name", "").toString(), policyParams); - //addParameter("version", extractValue(metadata, "version"), policyParams); addParameter("version", policy.getMetaData().getOrDefault("version", "").toString(), policyParams); - //addParameter("policy_type", extractValue(metadata, "type"), policyParams); addParameter("policy_type", policy.getMetaData().getOrDefault("type", "").toString(), policyParams); // extract properties @@ -351,22 +345,24 @@ public class SdncBaseModel { String policyUuid = policy.getMetaData().getOrDefault("UUID", "").toString(); String policyInvariantUuid = policy.getMetaData().getOrDefault("invariantUUID", "").toString(); - // insert into RESOURCE_POLICY + // cleanup existing RESOURCE_POLICY data Map cleanupParams = new HashMap(); - SdncBaseModel.addParameter("resource_uuid", resourceUuid, cleanupParams); - SdncBaseModel.addParameter("policy_uuid", policyUuid, cleanupParams); - SdncBaseModel.addParameter("policy_invariant_uuid", policyInvariantUuid, cleanupParams); + addParameter("resource_uuid", resourceUuid, cleanupParams); + addParameter("policy_uuid", policyUuid, cleanupParams); + addParameter("policy_invariant_uuid", policyInvariantUuid, cleanupParams); + // insert into RESOURCE_POLICY Map policyParams = new HashMap(); - SdncBaseModel.addParameter("policy_uuid", policyUuid, policyParams); - SdncBaseModel.addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams); - SdncBaseModel.addParameter("policy_name", policy.getMetaData().getOrDefault("name", "").toString(), policyParams); - SdncBaseModel.addParameter("version", policy.getMetaData().getOrDefault("version", "").toString(), policyParams); - SdncBaseModel.addParameter("policy_type", policy.getType(), policyParams); + addParameter("policy_uuid", policyUuid, policyParams); + addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams); + addParameter("policy_name", policy.getMetaData().getOrDefault("name", "").toString(), policyParams); + addParameter("version", policy.getMetaData().getOrDefault("version", "").toString(), policyParams); + addParameter("policy_type", policy.getType(), policyParams); - SdncBaseModel.addParameter("property_type", extractValueStatic(policy, "type"), policyParams); - SdncBaseModel.addParameter("property_source", extractValueStatic(policy, "source"), policyParams); - SdncBaseModel.addParameter("property_name", extractValueStatic(policy, "name"), policyParams); + // extract properties + addParameter("property_type", extractValueStatic(policy, "type"), policyParams); + addParameter("property_source", extractValueStatic(policy, "source"), policyParams); + addParameter("property_name", extractValueStatic(policy, "name"), policyParams); try { @@ -385,8 +381,6 @@ public class SdncBaseModel { for (String targetName : policyTargetNameList) { NodeTemplate targetNode = sdcCsarHelper.getNodeTemplateByName(targetName); - // extract targetNode metadata UUID and customizationUUID - // insert into RESOURCE_POLICY_TO_TARGET_NODE_MAPPING try { Map mappingCleanupParams = new HashMap(); @@ -412,6 +406,84 @@ public class SdncBaseModel { } } + protected void insertPolicyData (NodeTemplate nodeTemplate, DBResourceManager jdbcDataSource, String parentUuid, String policyType) throws IOException { + + // Get External policies of the node + List policyList = sdcCsarHelper.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nodeTemplate, policyType); + String resourceUuid = "\"" + extractValue (nodeTemplate.getMetaData(), SdcPropertyNames.PROPERTY_NAME_UUID) + "\""; + + for (Policy policy : policyList) { + + // extract policy metadata + String policyUuid = policy.getMetaData().getOrDefault("UUID", "").toString(); + String policyInvariantUuid = policy.getMetaData().getOrDefault("invariantUUID", "").toString(); + + // cleanup existing RESOURCE_POLICY data + Map cleanupParams = new HashMap(); + addParameter("resource_uuid", resourceUuid, cleanupParams); + addParameter("policy_uuid", policyUuid, cleanupParams); + addParameter("policy_invariant_uuid", policyInvariantUuid, cleanupParams); + + // insert into RESOURCE_POLICY + Map policyParams = new HashMap(); + addParameter("policy_uuid", policyUuid, policyParams); + addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams); + String policyName = policy.getMetaData().getOrDefault("name", "").toString(); + addParameter("policy_name", policyName, policyParams); + addParameter("version", policy.getMetaData().getOrDefault("version", "").toString(), policyParams); + addParameter("policy_type", policy.getType(), policyParams); + + // extract properties + addParameter("property_type", extractValue(policy, "type"), policyParams); + addParameter("property_source", extractValue(policy, "source"), policyParams); + addParameter("property_name", extractValue(policy, "name"), policyParams); + + try { + + // insert into RESOURCE_POLICY + cleanupExistingToscaData(jdbcDataSource, "RESOURCE_POLICY", cleanupParams); + LOG.info("Call insertToscaData for RESOURCE_POLICY where resource_uuid = " + resourceUuid); + insertToscaData(jdbcDataSource, getSql("RESOURCE_POLICY", "resource_uuid", resourceUuid, "", policyParams), null); + + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY table"); + throw new IOException (e); + } + + // insert into RESOURCE_POLICY_TO_TARGET_NODE_MAPPING + List targetNodeList = sdcCsarHelper.getPolicyTargetsFromOrigin(nodeTemplate, policyName); + for (NodeTemplate targetNode : targetNodeList) { + //NodeTemplate targetNode = sdcCsarHelper.getNodeTemplateByName(targetName); + if (targetNode == null) { + LOG.error("Target node for policy " + policyName + " is NULL. Can't insert into RESOURCE_POLICY_TO_TARGET_NODE_MAPPING"); + continue; + } + + // insert into RESOURCE_POLICY_TO_TARGET_NODE_MAPPING + try { + Map mappingCleanupParams = new HashMap(); + addParameter("policy_uuid", policyUuid, mappingCleanupParams); + addParameter("parent_uuid", parentUuid, mappingCleanupParams); + addParameter("target_node_uuid", targetNode.getMetaData().getValue("UUID"), mappingCleanupParams); + SdncBaseModel.cleanupExistingToscaData(jdbcDataSource, "RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", mappingCleanupParams); + + Map mappingParams = new HashMap(); + addParameter("parent_uuid", parentUuid, mappingParams); + addParameter("target_node_uuid", targetNode.getMetaData().getValue("UUID"), mappingParams); + addParameter("target_node_customization_uuid", targetNode.getMetaData().getValue("customizationUUID"), mappingParams); + addParameter("target_type", targetNode.getMetaData().getValue("type"), mappingParams); // type of the target node + LOG.info("Call insertToscaData for RESOURCE_POLICY_TO_TARGET_NODE_MAPPING where policy_uuid = " + policyUuid + " and target_node_uuid = " + targetNode.getMetaData().getValue("UUID")); + SdncBaseModel.insertToscaData(jdbcDataSource, getSql("RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", "policy_uuid", "\"" + policyUuid + "\"", "", mappingParams), null); + + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY_TO_TARGET_NODE_MAPPING table"); + throw new IOException (e); + } + + } + } + } + protected void insertNodeCapabilitiesData (CapabilityAssignments capabilities) throws IOException { // Process the capabilities on the node template diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java index 95f9a0d31..84f8296c9 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java @@ -94,7 +94,7 @@ public class SdncVFModel extends SdncBaseModel { insertVFtoNetworkRoleMappingData(); insertVFCData(); insertVFCInstanceGroupData(); - //insertVFPolicyData(); - insert Policy data for VF? + insertVFPolicyData(); } private void insertVFModelData () throws IOException { @@ -261,13 +261,8 @@ public class SdncVFModel extends SdncBaseModel { private void insertVFPolicyData() throws IOException { - // For each VF node, get Policy data (is VFC the origin or target?) - List policyList = sdcCsarHelper.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nodeTemplate, "org.openecomp.policies.External"); - for (Policy policy : policyList){ - - policy.getmetadata(); - Map propMap = policy.getPolicyProperties(); - } + // For each VF node, ingest External Policy data + insertPolicyData (nodeTemplate, jdbcDataSource, serviceUUID, "org.openecomp.policies.External"); } public String getVendor() { -- cgit 1.2.3-korg From 117b08faba226c79484572516efe3b6e861c1e48 Mon Sep 17 00:00:00 2001 From: Ganesh Chandrasekaran Date: Fri, 17 Aug 2018 14:15:59 +0900 Subject: Increase coverage and quality Issue-ID: CCSDK-470 Change-Id: Id847c9a79af795dd80a5fc22341ed2e385e53943 Signed-off-by: Ganesh Chandrasekaran --- .../northbound/TestLcmRpcInvocationException.java | 20 +++++++ .../sli/northbound/uebclient/SdncBaseModel.java | 64 ++++++++++++---------- 2 files changed, 56 insertions(+), 28 deletions(-) create mode 100644 lcm/provider/src/test/java/org/onap/ccsdk/sli/northbound/TestLcmRpcInvocationException.java (limited to 'ueb-listener/src') diff --git a/lcm/provider/src/test/java/org/onap/ccsdk/sli/northbound/TestLcmRpcInvocationException.java b/lcm/provider/src/test/java/org/onap/ccsdk/sli/northbound/TestLcmRpcInvocationException.java new file mode 100644 index 000000000..f95e83250 --- /dev/null +++ b/lcm/provider/src/test/java/org/onap/ccsdk/sli/northbound/TestLcmRpcInvocationException.java @@ -0,0 +1,20 @@ +package org.onap.ccsdk.sli.northbound; + +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.lcm.rev180329.common.header.CommonHeader; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.lcm.rev180329.status.Status; + +public class TestLcmRpcInvocationException { + + @Test(expected = SvcLogicException.class) + public void testLcmRpcInvocationException() throws SvcLogicException{ + Status status = null; + CommonHeader commonHeader = null; + LcmRpcInvocationException exception = new LcmRpcInvocationException(status, commonHeader); + assert(exception.getStatus() == status); + assert(exception.getCommonHeader() == commonHeader); + throw exception; + } +} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index 57be926bc..b1e065e25 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -54,7 +54,15 @@ public class SdncBaseModel { protected String UUID = null; protected String model_yaml = null; protected String version = null; - protected String name = null; + protected String name = null; + + protected String PARAM_INVARIANT_UUID_KEY = "invariant_uuid"; + protected String PARAM_UUID_KEY = "uuid"; + protected String PARAM_VERSION_KEY = "version"; + protected String PARAM_NAME_KEY = "name"; + protected String PARAM_DESCRIPTION_KEY = "description"; + protected String PARAM_TYPE_KEY = "type"; + protected String PARAM_CATEGORY_KEY = "category"; protected Map params = null; protected Map attributeValueParams = null; @@ -89,13 +97,13 @@ public class SdncBaseModel { // extract service metadata invariantUUID = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID); - addParameter("invariant_uuid",invariantUUID); - addParameter("version",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_VERSION)); + addParameter(PARAM_INVARIANT_UUID_KEY,invariantUUID); + addParameter(PARAM_VERSION_KEY,extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_VERSION)); name = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_NAME); - addParameter("name",name); - addParameter("description",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); - addParameter("type",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_TYPE)); - addParameter("category",extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_CATEGORY)); + addParameter(PARAM_NAME_KEY,name); + addParameter(PARAM_DESCRIPTION_KEY,extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); + addParameter(PARAM_TYPE_KEY,extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_TYPE)); + addParameter(PARAM_CATEGORY_KEY,extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_CATEGORY)); } public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { @@ -109,10 +117,10 @@ public class SdncBaseModel { Metadata metadata = nodeTemplate.getMetaData(); customizationUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); invariantUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID); - addParameter("invariant_uuid", invariantUUID); + addParameter(PARAM_INVARIANT_UUID_KEY, invariantUUID); UUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_UUID); - addParameter("uuid", UUID); - addParameter("version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VERSION)); + addParameter(PARAM_UUID_KEY, UUID); + addParameter(PARAM_VERSION_KEY, extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VERSION)); // extract common nodeTemplate properties //addParameter("ecomp_generated_naming", extractValue (nodeTemplate, "naming#ecompnaming")); // should be extractBooleanValue? @@ -137,9 +145,9 @@ public class SdncBaseModel { Metadata metadata = group.getMetadata(); //customizationUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULECUSTOMIZATIONUUID); - returning null customizationUUID = extractValue (metadata, "vfModuleModelCustomizationUUID"); - addParameter("invariant_uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)); - addParameter("uuid", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)); - addParameter("version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)); + addParameter(PARAM_INVARIANT_UUID_KEY, extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)); + addParameter(PARAM_UUID_KEY, extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)); + addParameter(PARAM_VERSION_KEY, extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)); } /* This is the generic approach Shoujit attempted for 18.06 but can't be implemented without parser API to @@ -178,7 +186,7 @@ public class SdncBaseModel { if (!type.isEmpty()) metadataType = type; else { Metadata metadata = nodeTemplate.getMetaData(); - metadataType = sdcCsarHelper.getMetadataPropertyValue(metadata, "type"); + metadataType = sdcCsarHelper.getMetadataPropertyValue(metadata, PARAM_TYPE_KEY); } // Clean up all attributes for this resource @@ -236,7 +244,7 @@ public class SdncBaseModel { Map mappingParams = new HashMap(); addParameter("parent_uuid", extractValue(nodeTemplate.getMetaData(), "UUID"), mappingParams); addParameter("target_node_uuid", extractValue(targetNode.getMetaData(), "UUID"), mappingParams); - String targetType = extractValue(targetNode.getMetaData(), "type"); + String targetType = extractValue(targetNode.getMetaData(), PARAM_TYPE_KEY); addParameter("target_type", targetType, mappingParams); String tableName = ""; switch (targetType) { @@ -285,14 +293,14 @@ public class SdncBaseModel { addParameter("policy_uuid", policyUuid, policyParams); addParameter("policy_customization_uuid", policyCustomizationUuid, policyParams); addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams); - addParameter("policy_name", policy.getMetaData().getOrDefault("name", "").toString(), policyParams); - addParameter("version", policy.getMetaData().getOrDefault("version", "").toString(), policyParams); - addParameter("policy_type", policy.getMetaData().getOrDefault("type", "").toString(), policyParams); + addParameter("policy_name", policy.getMetaData().getOrDefault(PARAM_NAME_KEY, "").toString(), policyParams); + addParameter(PARAM_VERSION_KEY, policy.getMetaData().getOrDefault(PARAM_VERSION_KEY, "").toString(), policyParams); + addParameter("policy_type", policy.getMetaData().getOrDefault(PARAM_TYPE_KEY, "").toString(), policyParams); // extract properties - addParameter("property_type", extractValue(policy, "type"), policyParams); + addParameter("property_type", extractValue(policy, PARAM_TYPE_KEY), policyParams); addParameter("property_source", extractValue(policy, "source"), policyParams); - addParameter("property_name", extractValue(policy, "name"), policyParams); + addParameter("property_name", extractValue(policy, PARAM_NAME_KEY), policyParams); // Insert into RESOURCE_POLICY and RESOURCE_POLICY_TO_TARGET_NODE_MAPPING // RESOURCE_POLICY: resource_uuid (CR node UUID), uuid, customization_uuid, invariant_uuid, name, version, policy_type, @@ -323,7 +331,7 @@ public class SdncBaseModel { addParameter("target_node_uuid", targetNode.getMetaData().getValue("UUID"), mappingParams); addParameter("target_node_customization_uuid", targetNode.getMetaData().getValue("customizationUUID"), mappingParams); addParameter("policy_customization_uuid", policyCustomizationUuid, mappingParams); - addParameter("target_type", targetNode.getMetaData().getValue("type"), mappingParams); + addParameter("target_type", targetNode.getMetaData().getValue(PARAM_TYPE_KEY), mappingParams); LOG.info("Call insertToscaData for RESOURCE_POLICY_TO_TARGET_NODE_MAPPING where policy_uuid = " + policyUuid); insertToscaData(buildSql("RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", "policy_uuid", "\"" + policyUuid + "\"", model_yaml, mappingParams), null); @@ -362,7 +370,7 @@ public class SdncBaseModel { // extract properties addParameter("property_type", extractValueStatic(policy, "type"), policyParams); addParameter("property_source", extractValueStatic(policy, "source"), policyParams); - addParameter("property_name", extractValueStatic(policy, "name"), policyParams); + addParameter("property_name", extractValueStatic(policy, "name"), policyParams); try { @@ -428,15 +436,15 @@ public class SdncBaseModel { Map policyParams = new HashMap(); addParameter("policy_uuid", policyUuid, policyParams); addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams); - String policyName = policy.getMetaData().getOrDefault("name", "").toString(); + String policyName = policy.getMetaData().getOrDefault(PARAM_NAME_KEY, "").toString(); addParameter("policy_name", policyName, policyParams); - addParameter("version", policy.getMetaData().getOrDefault("version", "").toString(), policyParams); + addParameter(PARAM_VERSION_KEY, policy.getMetaData().getOrDefault(PARAM_VERSION_KEY, "").toString(), policyParams); addParameter("policy_type", policy.getType(), policyParams); // extract properties - addParameter("property_type", extractValue(policy, "type"), policyParams); + addParameter("property_type", extractValue(policy, PARAM_TYPE_KEY), policyParams); addParameter("property_source", extractValue(policy, "source"), policyParams); - addParameter("property_name", extractValue(policy, "name"), policyParams); + addParameter("property_name", extractValue(policy, PARAM_NAME_KEY), policyParams); try { @@ -471,7 +479,7 @@ public class SdncBaseModel { addParameter("parent_uuid", parentUuid, mappingParams); addParameter("target_node_uuid", targetNode.getMetaData().getValue("UUID"), mappingParams); addParameter("target_node_customization_uuid", targetNode.getMetaData().getValue("customizationUUID"), mappingParams); - addParameter("target_type", targetNode.getMetaData().getValue("type"), mappingParams); // type of the target node + addParameter("target_type", targetNode.getMetaData().getValue(PARAM_TYPE_KEY), mappingParams); // type of the target node LOG.info("Call insertToscaData for RESOURCE_POLICY_TO_TARGET_NODE_MAPPING where policy_uuid = " + policyUuid + " and target_node_uuid = " + targetNode.getMetaData().getValue("UUID")); SdncBaseModel.insertToscaData(jdbcDataSource, getSql("RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", "policy_uuid", "\"" + policyUuid + "\"", "", mappingParams), null); @@ -523,7 +531,7 @@ public class SdncBaseModel { Map nodeCapabilityParams = new HashMap(); addParameter("capability_provider_customization_uuid", getCustomizationUUIDNoQuotes(), nodeCapabilityParams); // node customization UUID addParameter("capability_name", capability.getName(), nodeCapabilityParams); - addParameter("capability_type", extractValue(capability, "type"), nodeCapabilityParams); + addParameter("capability_type", extractValue(capability, PARAM_TYPE_KEY), nodeCapabilityParams); // Insert NODE_CAPABILITY data for each capability String capabilityId = ""; -- cgit 1.2.3-korg From 4ea2182f617e8e4d80469d96a76128de72be7ee2 Mon Sep 17 00:00:00 2001 From: "lalena.aria" Date: Mon, 17 Sep 2018 16:52:32 -0400 Subject: VF Module ingestion add and parser vers update Changes made: Add vf_customization_uuid and vf_module_label in VF Module ingestion. Update sdc-tosca dependency version to 1.4.3 in pom.xml. Change-Id: I5b03e8ff72a74448901f1d5f6d9ed8b7688a6f15 Issue-ID: CCSDK-540 Signed-off-by: lalena.aria --- ueb-listener/pom.xml | 2 +- .../org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/pom.xml b/ueb-listener/pom.xml index 2fff94e8e..66437e47c 100755 --- a/ueb-listener/pom.xml +++ b/ueb-listener/pom.xml @@ -18,7 +18,7 @@ 1.3.0 - 1.4.1 + 1.4.3 2.9.4 true /opt/app/ueb-listener diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java index 64bceb8cd..2ba8de0f1 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java @@ -35,11 +35,11 @@ public class SdncVFModuleModel extends SdncBaseModel { public SdncVFModuleModel(ISdcCsarHelper sdcCsarHelper, Group group, SdncVFModel vfNodeModel) { super(sdcCsarHelper, group); - //addParameter("vf_customization_uuid", vfNodeModel.getCustomizationUUIDNoQuotes()); + addParameter("vf_customization_uuid", vfNodeModel.getCustomizationUUIDNoQuotes()); // extract properties addParameter("vf_module_type", extractValue(group, SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE)); - //addParameter("vf_module_label", extractValue(group, "vf_module_label")); + addParameter("vf_module_label", extractValue(group, "vf_module_label")); addIntParameter("availability_zone_count", extractValue(group, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)); addParameter("ecomp_generated_vm_assignments", extractBooleanValue(group, SdcPropertyNames.PROPERTY_NAME_ECOMPGENERATEDVMASSIGNMENTS)); } -- cgit 1.2.3-korg From b913c3d3bd3eadf4e5a16d006f220272c7426bd9 Mon Sep 17 00:00:00 2001 From: "Timoney, Dan (dt5972)" Date: Tue, 9 Oct 2018 13:03:09 -0400 Subject: Fix UEB client error handling Changed ueb-listener to retry start of client if it returns failure Change-Id: Ieda78615a38925824cb78d63939da00818bf4452 Issue-ID: SDNC-472 Signed-off-by: Timoney, Dan (dt5972) --- .../org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java index d37518f1b..c025f3b05 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java @@ -27,6 +27,7 @@ import org.onap.sdc.impl.DistributionClientFactory; import org.onap.sdc.utils.DistributionActionResultEnum; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.onap.sdc.utils.DistributionActionResultEnum; public class SdncUebClient { @@ -61,7 +62,12 @@ public class SdncUebClient { try { IDistributionClientResult start = client.start(); LOG.info("Client startup result = {}", start.getDistributionMessageResult()); - keepWaiting = false; + + // Only stop waiting if the result is success + if (start.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) { + + keepWaiting = false; + } } catch(Exception e) { LOG.info("Client startup failure", e); } -- cgit 1.2.3-korg From 25bb156451b5603f53f3db125c7876a7de571bd8 Mon Sep 17 00:00:00 2001 From: "Timoney, Dan (dt5972)" Date: Wed, 31 Oct 2018 15:50:33 -0400 Subject: Fix error handling Recreate client objects after failure is returned by SDC before retrying. Change-Id: Ib165fc1220a010a0443a7dab4014aaba8c9f29f8 Issue-ID: SDNC-472 Signed-off-by: Timoney, Dan (dt5972) --- .../ccsdk/sli/northbound/uebclient/SdncUebClient.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java index c025f3b05..4f2de1cc1 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java @@ -34,13 +34,12 @@ public class SdncUebClient { private static final Logger LOG = LoggerFactory.getLogger(SdncUebConfiguration.class); public static void main(String[] args) { - IDistributionClient client = DistributionClientFactory.createDistributionClient(); SdncUebConfiguration config = new SdncUebConfiguration(); + IDistributionClient client = DistributionClientFactory.createDistributionClient(); SdncUebCallback cb = new SdncUebCallback(client, config); - LOG.info("Scanning for local distribution artifacts before starting client"); cb.deployDownloadedFiles(null, null, null); @@ -67,6 +66,21 @@ public class SdncUebClient { if (start.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) { keepWaiting = false; + } else { + LOG.info("SDC returned "+start.getDistributionActionResult().toString()+" - will retry"); + try { + client.stop(); + } catch(Exception e1) { + // Ignore exception on stop + } + client = DistributionClientFactory.createDistributionClient(); + cb = new SdncUebCallback(client, config); + LOG.info("Initializing ASDC distribution client"); + + result = client.init(config, cb); + + LOG.info("Initialized ASDC distribution client - results = {}", result.getDistributionMessageResult()); + } } catch(Exception e) { LOG.info("Client startup failure", e); -- cgit 1.2.3-korg From 29e7063b7f1832d14fd92642914e6917da45c18c Mon Sep 17 00:00:00 2001 From: "Timoney, Dan (dt5972)" Date: Fri, 2 Nov 2018 10:11:48 -0400 Subject: Explicitly exit on timeout Previously, when timeout occurs trying to connect successfully to SDC, code just dropped out of loop in main() method, expecting to exit. However, if the SDC client left any threads hanging, that might not cause process to exit. Instead, process should explicitly exit via System.exit(). Change-Id: I28316550cbfc2bbddeaadf080c0afa52a1eae350 Issue-ID: SDNC-472 Signed-off-by: Timoney, Dan (dt5972) --- .../onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java index 4f2de1cc1..2078a798f 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java @@ -54,6 +54,7 @@ public class SdncUebClient { long maxWaitTm = config.getClientStartupTimeout() * 1000L; boolean keepWaiting = true; + boolean listenerStarted = false; while (keepWaiting) { if (result.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) { @@ -66,8 +67,9 @@ public class SdncUebClient { if (start.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) { keepWaiting = false; + listenerStarted = true; } else { - LOG.info("SDC returned "+start.getDistributionActionResult().toString()+" - will retry"); + LOG.info("SDC returned {} - exitting",start.getDistributionActionResult().toString()); try { client.stop(); } catch(Exception e1) { @@ -99,8 +101,13 @@ public class SdncUebClient { } } - - + + if (!listenerStarted) { + LOG.info("Timed out waiting to connect to SDC"); + System.exit(0); + } + + } -- cgit 1.2.3-korg From b62880bebaafab43294739bb2c867f271d760db1 Mon Sep 17 00:00:00 2001 From: "lalena.aria" Date: Tue, 6 Nov 2018 11:09:55 -0500 Subject: Replace logic for subinterface_indicator ingestion Changes made: Replace ingestion logic for VFC_TO_NETWORK_ROLE_MAPPING.subinterface_indicator with alternate logic suggested by ASDC. Change-Id: Ied21e9361091c3fe4c05c6d9a2ee35c6491a7e10 Issue-ID: CCSDK-630 Signed-off-by: lalena.aria --- .../onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java index 5977e2888..db5004309 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java @@ -24,6 +24,7 @@ package org.onap.ccsdk.sli.northbound.uebclient; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; @@ -113,9 +114,17 @@ public class SdncVFCModel extends SdncBaseModel { SdncBaseModel.addParameter("network_role", networkRole, commonParams); // can not be null SdncBaseModel.addParameter("network_role_tag", nullCheck(propsMap.get("network_role_tag")), commonParams); SdncBaseModel.addParameter("extcp_subnetpool_id", nullCheck(propsMap.get("subnetpoolid")), commonParams); - String subinterfaceIndicator = nullCheck(propsMap.get("subinterface_indicator")); - if (!subinterfaceIndicator.isEmpty()) { - SdncBaseModel.addParameter("subinterface_indicator", subinterfaceIndicator.contains("true") ? "Y" : "N", commonParams); // boolean Y|N + + // Loop thru all CPs using getNodeTemplateChildren and match the network_role on the CP with network_role from + // getCpPropertiesFromVfcAsObject output, then get subinterface_indicator for this CP + List cpNodesList = sdcCsarHelper.getNodeTemplateChildren(vfcNode); + for (NodeTemplate cpNode : cpNodesList){ + String cpNetworkRole = extractValue(cpNode, "network_role"); + + if (cpNetworkRole == networkRole) { + String subinterfaceIndicator = extractBooleanValue (cpNode, "subinterface_indicator"); + addParameter("subinterface_indicator", subinterfaceIndicator, commonParams); + } } // Extract IP Version specific parameters -- cgit 1.2.3-korg From d411beeeb5b407c170a98ad98c18ab85d5281833 Mon Sep 17 00:00:00 2001 From: "Timoney, Dan (dt5972)" Date: Tue, 6 Nov 2018 11:30:49 -0500 Subject: Fix misplaced if Updated main loop of ueb-listener to recreate client on each iteration rather than using client created outside loop. Change-Id: I5c5b9f26e472dfbffefdd49a870a293159f72b10 Issue-ID: SDNC-472 Signed-off-by: Timoney, Dan (dt5972) --- .../sli/northbound/uebclient/SdncUebClient.java | 59 ++++++++++------------ 1 file changed, 26 insertions(+), 33 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java index 2078a798f..e5dec14c7 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java @@ -37,66 +37,59 @@ public class SdncUebClient { SdncUebConfiguration config = new SdncUebConfiguration(); - IDistributionClient client = DistributionClientFactory.createDistributionClient(); - SdncUebCallback cb = new SdncUebCallback(client, config); - - LOG.info("Scanning for local distribution artifacts before starting client"); - cb.deployDownloadedFiles(null, null, null); - - LOG.info("Initializing ASDC distribution client"); - - IDistributionClientResult result = client.init(config, cb); - - LOG.info("Initialized ASDC distribution client - results = {}", result.getDistributionMessageResult()); - long startTm = System.currentTimeMillis(); int sleepTm = config.getPollingInterval() * 1000; long maxWaitTm = config.getClientStartupTimeout() * 1000L; boolean keepWaiting = true; boolean listenerStarted = false; + boolean processDownloads = true; while (keepWaiting) { + LOG.info("Initializing ASDC distribution client"); + + IDistributionClient client = DistributionClientFactory.createDistributionClient(); + SdncUebCallback cb = new SdncUebCallback(client, config); + IDistributionClientResult result = client.init(config, cb); + LOG.info("Initialized ASDC distribution client - results = {}", result.getDistributionMessageResult()); + if (result.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) { + if (processDownloads) { + LOG.info("Scanning for local distribution artifacts before starting client"); + cb.deployDownloadedFiles(null, null, null); + processDownloads = false; + } LOG.info("Starting client..."); try { IDistributionClientResult start = client.start(); LOG.info("Client startup result = {}", start.getDistributionMessageResult()); - + // Only stop waiting if the result is success if (start.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) { - + keepWaiting = false; listenerStarted = true; } else { - LOG.info("SDC returned {} - exitting",start.getDistributionActionResult().toString()); + LOG.info("SDC returned {} - exitting", start.getDistributionActionResult().toString()); try { client.stop(); - } catch(Exception e1) { + } catch (Exception e1) { // Ignore exception on stop } - client = DistributionClientFactory.createDistributionClient(); - cb = new SdncUebCallback(client, config); - LOG.info("Initializing ASDC distribution client"); - - result = client.init(config, cb); - - LOG.info("Initialized ASDC distribution client - results = {}", result.getDistributionMessageResult()); - } - } catch(Exception e) { + } catch (Exception e) { LOG.info("Client startup failure", e); } + } - if (System.currentTimeMillis() - startTm < maxWaitTm) { - keepWaiting = false; - } else { + if (System.currentTimeMillis() - startTm < maxWaitTm) { + keepWaiting = false; + } else { - try { - Thread.sleep(sleepTm); - } catch (InterruptedException e) { - // Ignore - } + try { + Thread.sleep(sleepTm); + } catch (InterruptedException e) { + // Ignore } } -- cgit 1.2.3-korg From be41042f4c01a8ae642862879af019af1cae18a3 Mon Sep 17 00:00:00 2001 From: "lalena.aria" Date: Tue, 6 Nov 2018 15:56:35 -0500 Subject: Add logic for ingesting related_network_role data Changes made: Add ingestion for related_network_role data at VL, FV and VFC. Add ingestion for trunk_network_indicator on VL. Fix ATTRIBUTE_VALUE_PAIR insertion for VFC Instance Group properties. Change-Id: Ifd46bad5963a430ed55aacad369ab64b723a11fd Issue-ID: CCSDK-649 Signed-off-by: lalena.aria --- .../sli/northbound/uebclient/SdncNodeModel.java | 49 ++++++++++++++++ .../sli/northbound/uebclient/SdncUebCallback.java | 1 + .../sli/northbound/uebclient/SdncVFCModel.java | 67 ++++++++++++++++++++++ .../sli/northbound/uebclient/SdncVFModel.java | 16 +++++- 4 files changed, 130 insertions(+), 3 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java index d4b3344ca..667f95aae 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java @@ -22,6 +22,9 @@ package org.onap.ccsdk.sli.northbound.uebclient; import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; @@ -58,6 +61,8 @@ public class SdncNodeModel extends SdncBaseModel { // 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)); + String trunkNetworkIndicator = extractBooleanValue(nodeTemplate, "network_assignments#is_trunked"); + addParameter("trunk_network_indicator", trunkNetworkIndicator); // extract properties - network_assignments - ipv4_subnet_default_assignment String useIpv4 = extractBooleanValue(nodeTemplate, "network_assignments#ipv4_subnet_default_assignment#use_ipv4"); @@ -122,6 +127,50 @@ public class SdncNodeModel extends SdncBaseModel { throw new IOException (e); } } + + public void insertRelatedNetworkRoleData () throws IOException { + + Object propertyValue = sdcCsarHelper.getNodeTemplatePropertyAsObject(nodeTemplate, "network_assignments#related_networks"); + ArrayList> relatedNetworkList = (ArrayList)propertyValue; + + String networkModelCustomizationUUID = getCustomizationUUID(); + + if (relatedNetworkList != null) { + + try { + cleanUpExistingToscaData("RELATED_NETWORK_ROLE", "network_model_customization_uuid", networkModelCustomizationUUID); + } catch (IOException e) { + LOG.error("Could not clean up Tosca CSAR data in the RELATED_NETWORK_ROLE table"); + throw new IOException (e); + } + + for (Map relatedNetworkValue : relatedNetworkList) { + LOG.debug("Node Template [" + nodeTemplate.getName() + "], property [" + "related_network_role" + "] property value: " + relatedNetworkValue.get("related_network_role")); + + String relatedNetworkRoleValue = relatedNetworkValue.get("related_network_role"); + + try { + // Table cleanup RELATED_NETWORK_ROLE occurs per network + // If related_network_role for this service already exist in RELATED_NETWORK_ROLE, don't attempt insertion + Map relatedNetworkRoleParamsCheck = new HashMap(); + addParameter("related_network_role", relatedNetworkRoleValue, relatedNetworkRoleParamsCheck); + addParameter("network_model_customization_uuid", networkModelCustomizationUUID, relatedNetworkRoleParamsCheck); + if (checkForExistingToscaData("RELATED_NETWORK_ROLE", relatedNetworkRoleParamsCheck) == false) { + relatedNetworkRoleParamsCheck.remove("related_network_role"); + LOG.info("Call insertToscaData for RELATED_NETWORK_ROLE where network_model_customization_uuid = " + networkModelCustomizationUUID); + insertToscaData(buildSql("RELATED_NETWORK_ROLE", "related_network_role", "\"" + relatedNetworkRoleValue + "\"", model_yaml, relatedNetworkRoleParamsCheck), null); + } + } catch (IOException e) { + LOG.debug("Could not insert Tosca CSAR data into the RELATED_NETWORK_ROLE table"); + throw new IOException (e); + } + } + } + else { + LOG.debug("Node Template [" + nodeTemplate.getName() + "], property [" + "related_networks" + "] property value: " + null); + } + + } public String getSql(String model_yaml) { diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index 224a51998..3903eb414 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -710,6 +710,7 @@ public class SdncUebCallback implements INotificationCallback { try { nodeModel.insertNetworkModelData(); + nodeModel.insertRelatedNetworkRoleData(); } catch (IOException e) { deployStatus = DistributionStatusEnum.DEPLOY_ERROR; } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java index 5977e2888..b23a913ff 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java @@ -24,6 +24,7 @@ package org.onap.ccsdk.sli.northbound.uebclient; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; @@ -272,6 +273,72 @@ public class SdncVFCModel extends SdncBaseModel { } } + public void insertVFCRelatedNetworkRoleData (String vfCustomizationUUID, NodeTemplate vfcNode) throws IOException { + + // Get the CPs on this VFC - ASDC suggests getNodeTemplateChildren + List cpNodesList = sdcCsarHelper.getNodeTemplateChildren(vfcNode); + + String vfcCustomizationUuid = getCustomizationUUID(); + + try { + cleanUpExistingToscaData("VFC_RELATED_NETWORK_ROLE", "vfc_customization_uuid", vfcCustomizationUuid); + } catch (IOException e) { + LOG.error("Could not clean up Tosca CSAR data in the VFC_RELATED_NETWORK_ROLE table"); + throw new IOException (e); + } + + for (NodeTemplate cpNode : cpNodesList){ + String networkRole = extractValue(cpNode, "network_role"); + Map relatedNetworkRoleParams = new HashMap(); + addParameter("vfc_customization_uuid", vfcCustomizationUuid, relatedNetworkRoleParams); + addParameter("vm_type", vmType, relatedNetworkRoleParams); + addParameter("network_role", networkRole, relatedNetworkRoleParams); + + final Object relatedNetworksPropertyValue = cpNode.getPropertyValue("related_networks"); + + ArrayList> relatedNetworkList = (ArrayList)relatedNetworksPropertyValue; + if (relatedNetworkList != null) { + for (Map relatedNetworkValue : relatedNetworkList) { + LOG.debug("CP [" + cpNode.getName() + "], property [" + "related_network_role" + "] property value: " + relatedNetworkValue.get("related_network_role")); + String relatedNetworkRoleValue = relatedNetworkValue.get("related_network_role"); + + try { + // Table cleanup for VFC_RELATED_NETWORK_ROLE occurs per vfc + // If cp related_network_role, cp network_role and vm_type for this vfc already exist in VFC_RELATED_NETWORK_ROLE, + // don't attempt insertion + Map relatedNetworkRoleParamsCheck = new HashMap(); + addParamsToMap(relatedNetworkRoleParams, relatedNetworkRoleParamsCheck); + addParameter("related_network_role", relatedNetworkRoleValue, relatedNetworkRoleParamsCheck); + if (checkForExistingToscaData("VFC_RELATED_NETWORK_ROLE", relatedNetworkRoleParamsCheck) == false) { + LOG.info("Call insertToscaData for VFC_RELATED_NETWORK_ROLE where vfc_customization_uuid = " + vfcCustomizationUuid); + insertToscaData(buildSql("VFC_RELATED_NETWORK_ROLE", "related_network_role", "\"" + relatedNetworkRoleValue + "\"", model_yaml, relatedNetworkRoleParams), null); + } + + // Table cleanup for VNF_RELATED_NETWORK_ROLE occurs per vf (up one level) + // Insert same related_network_role data into VNF_RELATED_NETWORK_ROLE + Map vfRelatedNetworkRoleParamsCheck = new HashMap(); + addParameter("vnf_customization_uuid", vfCustomizationUUID, vfRelatedNetworkRoleParamsCheck); + addParameter("network_role", networkRole, vfRelatedNetworkRoleParamsCheck); + addParameter("related_network_role", relatedNetworkRoleValue, vfRelatedNetworkRoleParamsCheck); + if (checkForExistingToscaData("VNF_RELATED_NETWORK_ROLE", vfRelatedNetworkRoleParamsCheck) == false) { + vfRelatedNetworkRoleParamsCheck.remove("related_network_role"); + LOG.info("Call insertToscaData for VNF_RELATED_NETWORK_ROLE where vnf_customization_uuid = " + vfCustomizationUUID); + insertToscaData(buildSql("VNF_RELATED_NETWORK_ROLE", "related_network_role", "\"" + relatedNetworkRoleValue + "\"", model_yaml, vfRelatedNetworkRoleParamsCheck), null); + } + + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the VFC_RELATED_NETWORK_ROLE table"); + throw new IOException (e); + } + } + } + else { + LOG.debug("CP [" + cpNode.getName() + "], property [" + "related_networks" + "] property value: " + null); + } + } + + } + public String getVmType() { return vmType; } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java index 84f8296c9..850a34fa0 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java @@ -79,11 +79,11 @@ public class SdncVFModel extends SdncBaseModel { for (Group group : vfcInstanceGroupListForVf){ String vfcInstanceGroupFunction = extractGetInputValue(group, nodeTemplate, "vfc_instance_group_function"); - addParameter(extractGetInputName (group, "vfc_instance_group_function"), vfcInstanceGroupFunction, attributeValueParams); + addParameter("vfc_instance_group_function", vfcInstanceGroupFunction, attributeValueParams); String networkCollectionFunction = extractGetInputValue(group, nodeTemplate, "network_collection_function"); - addParameter(extractGetInputName (group, "network_collection_function"), networkCollectionFunction, attributeValueParams); + addParameter("network_collection_function", networkCollectionFunction, attributeValueParams); String initSubinterfaceQuantity = extractGetInputValue(group, nodeTemplate, "init_subinterface_quantity"); - addParameter(extractGetInputName (group, "init_subinterface_quantity"), initSubinterfaceQuantity, attributeValueParams); + addParameter("init_subinterface_quantity", initSubinterfaceQuantity, attributeValueParams); } } @@ -185,6 +185,15 @@ public class SdncVFModel extends SdncBaseModel { private void insertVFCData() throws IOException { + /* For each VF, insert VFC_MODEL, VFC_TO_NETWORK_ROLE_MAPPING, VNF_RELATED_NETWORK_ROLE and VFC_RELATED_NETWORK_ROLE data + + try { + cleanUpExistingToscaData("VNF_RELATED_NETWORK_ROLE", "vnf_customization_uuid", getCustomizationUUID()); + } catch (IOException e) { + LOG.error("Could not clean up Tosca CSAR data in the VNF_RELATED_NETWORK_ROLE table"); + throw new IOException (e); + }*/ + // For each VF, insert VFC_MODEL data List vfcNodes = sdcCsarHelper.getVfcListByVf(getCustomizationUUIDNoQuotes()); for (NodeTemplate vfcNode : vfcNodes){ @@ -194,6 +203,7 @@ public class SdncVFModel extends SdncBaseModel { vfcModel.insertVFCModelData(); vfcModel.insertVFCtoNetworkRoleMappingData(vfcNode); + //vfcModel.insertVFCRelatedNetworkRoleData(getCustomizationUUID(), vfcNode); } catch (IOException e) { LOG.error("Could not insert Tosca CSAR VFC data"); throw new IOException (e); -- cgit 1.2.3-korg From b348e62904cfa3687d5cbe062e56cf99c0f7fde2 Mon Sep 17 00:00:00 2001 From: "lalena.aria" Date: Tue, 27 Nov 2018 15:55:14 -0500 Subject: Update sdc-tosca version to 1.4.7 Changes made: Update sdc-tosca version to 1.4.7. Replace org.onap.sdc.tosca.parser.impl.SdcTypes with org.onap.sdc.tosca.parser.enums.SdcTypes. Replace getNodeTemplatePropertyAsObject with getNodeTemplatePropertyValueAsObject. Change-Id: I9482cad49e2baae1c1383afabff9377c72441246 Issue-ID: CCSDK-758 Signed-off-by: lalena.aria --- ueb-listener/pom.xml | 2 +- .../java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java | 2 +- .../java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java | 2 +- .../java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java | 2 -- 4 files changed, 3 insertions(+), 5 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/pom.xml b/ueb-listener/pom.xml index 1a97b1811..d91a5746b 100755 --- a/ueb-listener/pom.xml +++ b/ueb-listener/pom.xml @@ -20,7 +20,7 @@ 1.3.0 - 1.4.4 + 1.4.7 2.9.4 true /opt/app/ueb-listener diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index b1e065e25..0d5e9d6dd 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -763,7 +763,7 @@ public class SdncBaseModel { } protected Object extractObjectValue (NodeTemplate nodeTemplate, String name) { - Object value = sdcCsarHelper.getNodeTemplatePropertyAsObject(nodeTemplate, name); + Object value = sdcCsarHelper.getNodeTemplatePropertyValueAsObject(nodeTemplate, name); if (value != null) { return value; } else { diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java index 667f95aae..4870f29e3 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java @@ -130,7 +130,7 @@ public class SdncNodeModel extends SdncBaseModel { public void insertRelatedNetworkRoleData () throws IOException { - Object propertyValue = sdcCsarHelper.getNodeTemplatePropertyAsObject(nodeTemplate, "network_assignments#related_networks"); + Object propertyValue = sdcCsarHelper.getNodeTemplatePropertyValueAsObject(nodeTemplate, "network_assignments#related_networks"); ArrayList> relatedNetworkList = (ArrayList)propertyValue; String networkModelCustomizationUUID = getCustomizationUUID(); diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index 3903eb414..ba644f302 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -73,9 +73,7 @@ import org.onap.sdc.api.results.IDistributionClientResult; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; -import org.onap.sdc.tosca.parser.impl.SdcTypes; import org.onap.sdc.toscaparser.api.NodeTemplate; -import org.onap.sdc.toscaparser.api.Policy; import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.sdc.utils.ArtifactTypeEnum; import org.onap.sdc.utils.DistributionActionResultEnum; -- cgit 1.2.3-korg From 9695472daa4664caaeef0ef0d64101caf7d9e0e2 Mon Sep 17 00:00:00 2001 From: Arundathi Patil Date: Tue, 18 Dec 2018 15:29:09 +0530 Subject: Sonar fix: SdncARModel.java Fixed sonar issues/code-smells across this file Issue-ID: CCSDK-855 Change-Id: I5aa4859f2b30fb1efadd6d772cc5d80e00281c42 Signed-off-by: Arundathi Patil --- .../java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java index adb82c6dd..9cac459d7 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights * reserved. + * Modifications Copyright © 2018 IBM. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +23,6 @@ package org.onap.ccsdk.sli.northbound.uebclient; import java.io.IOException; -import java.util.List; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; @@ -37,7 +37,7 @@ public class SdncARModel extends SdncBaseModel { private static final Logger LOG = LoggerFactory .getLogger(SdncARModel.class); - private String type = null; + private String type = null; private String subcategory = null; public SdncARModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate,DBResourceManager jdbcDataSource) { -- cgit 1.2.3-korg From d50289489133cae368cddd71cd32550e8244a342 Mon Sep 17 00:00:00 2001 From: Arundathi Patil Date: Thu, 20 Dec 2018 17:10:51 +0530 Subject: Sonar fix: SdncArtifactMap.java Fixed sonar issues/code-smells across this file Issue-ID: CCSDK-863 Change-Id: I8c471ab3cdca84427fe88f33a82117200d916b3d Signed-off-by: Arundathi Patil --- .../sli/northbound/uebclient/SdncArtifactMap.java | 29 +++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java index 671d47a9f..601569a19 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights * reserved. + * Modifications Copyright © 2018 IBM. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,6 +42,16 @@ public class SdncArtifactMap { private String rpc; private int pass; + private SdncArtifactType(String tag, String rpc, String pass) { + this.tag = tag; + this.rpc = rpc; + try { + this.pass = Integer.parseInt(pass); + } catch (Exception e) { + LOG.error("Invalid pass value for artifact map entry ({} {} {})", tag, rpc, pass, e); + } + } + public String getTag() { return tag; } @@ -58,26 +69,16 @@ public class SdncArtifactMap { public String getRpcUrl(String base) { return base+rpc; } - - private SdncArtifactType(String tag, String rpc, String pass) { - this.tag = tag; - this.rpc = rpc; - try { - this.pass = Integer.parseInt(pass); - } catch (Exception e) { - LOG.error("Invalid pass value for artifact map entry ({} {} {})", tag, rpc, pass, e); - } - } } private Map mapItems = new HashMap<>(); - private int NumPasses = 1; + private int numPasses = 1; public int getNumPasses() { - return NumPasses; + return numPasses; } public void load(String fileName) { @@ -93,8 +94,8 @@ public class SdncArtifactMap { if (lnFields.length == 3) { SdncArtifactType entry = new SdncArtifactType(lnFields[0], lnFields[1], lnFields[2]); mapItems.put(entry.getTag(), entry); - if (entry.getPass() + 1 > NumPasses ) { - NumPasses = entry.getPass() + 1; + if (entry.getPass() + 1 > numPasses ) { + numPasses = entry.getPass() + 1; } } } -- cgit 1.2.3-korg From 7643a4addb45ffed94adc3bc9257f3fc9619e56f Mon Sep 17 00:00:00 2001 From: Arundathi Patil Date: Thu, 20 Dec 2018 22:41:19 +0530 Subject: Sonar fix: SdncUebConfiguration.java Fixed sonar issues/code-smells across this file Issue-ID: CCSDK-866 Change-Id: Icac8e0347d068902217e813a302db69b1bf5cc47 Signed-off-by: Arundathi Patil --- .../northbound/uebclient/SdncUebConfiguration.java | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java index 0500954de..0088a14a8 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights * reserved. + * Modifications Copyright © 2018 IBM. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,10 +59,6 @@ public class SdncUebConfiguration implements IConfiguration{ private SdncArtifactMap artifactMap = SdncArtifactMap.getInstance(); - public String getAsdcApiNamespace() { - return asdcApiNamespace; - } - private String incomingDir = null; private String archiveDir = null; @@ -74,14 +71,6 @@ public class SdncUebConfiguration implements IConfiguration{ private String xsltPathList; - public String getXsltPathList() { - return xsltPathList; - } - - public String getOverrideFile() { - return overrideFile; - } - public SdncUebConfiguration() { String propDir = System.getenv(SDNC_CONFIG_DIR); if (propDir == null) { @@ -103,6 +92,17 @@ public class SdncUebConfiguration implements IConfiguration{ } } + public String getAsdcApiNamespace() { + return asdcApiNamespace; + } + + public String getXsltPathList() { + return xsltPathList; + } + + public String getOverrideFile() { + return overrideFile; + } public void init(String propDir) throws IOException { String propPath; -- cgit 1.2.3-korg From 7575004a8ad0d1f017f9a13dac3c45188f0fa4be Mon Sep 17 00:00:00 2001 From: Arundathi Patil Date: Thu, 20 Dec 2018 22:52:13 +0530 Subject: Sonar fix: SdncVFModuleModel.java Fixed sonar issues/code-smells across this file Issue-ID: CCSDK-867 Change-Id: I20c5214ce9ab3c2821e58b0c6e2530a0881ccc1d Signed-off-by: Arundathi Patil --- .../org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java index 2ba8de0f1..914401ff1 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights * reserved. + * Modifications Copyright © 2018 IBM. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,14 +25,9 @@ package org.onap.ccsdk.sli.northbound.uebclient; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; import org.onap.sdc.toscaparser.api.Group; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class SdncVFModuleModel extends SdncBaseModel { - private static final Logger LOG = LoggerFactory - .getLogger(SdncVFModuleModel.class); - public SdncVFModuleModel(ISdcCsarHelper sdcCsarHelper, Group group, SdncVFModel vfNodeModel) { super(sdcCsarHelper, group); -- cgit 1.2.3-korg From 05b7bddc79ddaf128a5397bfb3582bbf7f4ae4f1 Mon Sep 17 00:00:00 2001 From: Arundathi Patil Date: Thu, 20 Dec 2018 21:54:31 +0530 Subject: Sonar fix: SdncGroupModel.java Fixed sonar issues/code-smells across this file Issue-ID: CCSDK-865 Change-Id: I29a2badf731506c4abfa908345ccc72c465c8fb0 Signed-off-by: Arundathi Patil --- .../org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java index 95d1fcd20..ea62abe9c 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights * reserved. + * Modifications Copyright © 2018 IBM. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +36,8 @@ public class SdncGroupModel extends SdncBaseModel { private static final Logger LOG = LoggerFactory .getLogger(SdncVFModuleModel.class); + + private static final String groupType = "group_type"; public SdncGroupModel(ISdcCsarHelper sdcCsarHelper, Group group, NodeTemplate nodeTemplate, SdncUebConfiguration config, DBResourceManager jdbcDataSource) throws IOException { @@ -47,7 +50,7 @@ public class SdncGroupModel extends SdncBaseModel { UUID = extractValue (metadata, "UUID"); addParameter("group_uuid", UUID); addParameter("group_name", extractValue (metadata, "name")); - addParameter("group_type", group.getType()); + addParameter(groupType, group.getType()); addParameter("version", extractValue (metadata, "version")); // extract properties @@ -55,7 +58,7 @@ public class SdncGroupModel extends SdncBaseModel { addParameter("subinterface_role", extractValue(group, "subinterface_role"), attributeValueParams); // relevant complex group properties are extracted and inserted into ATTRIBUTE_VALUE_PAIR - addParameter(extractGetInputName (group, "group_type"), extractGetInputValue(group, nodeTemplate, "group_type"), attributeValueParams); + addParameter(extractGetInputName (group, groupType), extractGetInputValue(group, nodeTemplate, groupType), attributeValueParams); addParameter(extractGetInputName (group, "group_role"), extractGetInputValue(group, nodeTemplate, "group_role"), attributeValueParams); addParameter(extractGetInputName (group, "group_function"), extractGetInputValue(group, nodeTemplate, "group_function"), attributeValueParams); } -- cgit 1.2.3-korg From d6375ac33711eadd11f08017072e0552f819cac2 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 26 Feb 2019 19:51:20 +0000 Subject: Use getEntity to populate network_role Changes made: Update sdc-tosca version to 1.5.0. Replace getCpListByVf with equivalent getEntity call in SdncVFModel.java. Replace policy.getMetaData with getMetaDataObj to work around parser issue. Change-Id: I1d972f75cc5ca1c8dc0e5d58880a3bb306608ca2 Issue-ID: CCSDK-1089 Signed-off-by: Ubuntu --- ueb-listener/pom.xml | 2 +- .../sli/northbound/uebclient/SdncBaseModel.java | 36 ++++++++----- .../sli/northbound/uebclient/SdncVFModel.java | 61 ++++++++++++++++------ 3 files changed, 69 insertions(+), 30 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/pom.xml b/ueb-listener/pom.xml index 87a9dfe97..df20a01cf 100755 --- a/ueb-listener/pom.xml +++ b/ueb-listener/pom.xml @@ -18,7 +18,7 @@ 1.3.0 - 1.4.7 + 1.5.0 2.9.4 true /opt/app/ueb-listener diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index 0d5e9d6dd..37b100ca4 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -278,9 +278,9 @@ public class SdncBaseModel { for (Policy policy : policyList) { // extract policy metadata - String policyUuid = policy.getMetaData().getOrDefault("UUID", "").toString(); - String policyInvariantUuid = policy.getMetaData().getOrDefault("invariantUUID", "").toString(); - String policyCustomizationUuid = policy.getMetaData().getOrDefault("customizationUUID", "").toString(); + String policyUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("UUID", "").toString(); + String policyInvariantUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("invariantUUID", "").toString(); + String policyCustomizationUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("customizationUUID", "").toString(); // cleanup existing RESOURCE_POLICY data Map cleanupParams = new HashMap(); @@ -293,9 +293,9 @@ public class SdncBaseModel { addParameter("policy_uuid", policyUuid, policyParams); addParameter("policy_customization_uuid", policyCustomizationUuid, policyParams); addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams); - addParameter("policy_name", policy.getMetaData().getOrDefault(PARAM_NAME_KEY, "").toString(), policyParams); - addParameter(PARAM_VERSION_KEY, policy.getMetaData().getOrDefault(PARAM_VERSION_KEY, "").toString(), policyParams); - addParameter("policy_type", policy.getMetaData().getOrDefault(PARAM_TYPE_KEY, "").toString(), policyParams); + addParameter("policy_name", policy.getMetaDataObj().getAllProperties().getOrDefault(PARAM_NAME_KEY, "").toString(), policyParams); + addParameter(PARAM_VERSION_KEY, policy.getMetaDataObj().getAllProperties().getOrDefault(PARAM_VERSION_KEY, "").toString(), policyParams); + addParameter("policy_type", policy.getType(), policyParams); // extract properties addParameter("property_type", extractValue(policy, PARAM_TYPE_KEY), policyParams); @@ -350,8 +350,8 @@ public class SdncBaseModel { for (Policy policy : policyList) { // extract policy metadata - String policyUuid = policy.getMetaData().getOrDefault("UUID", "").toString(); - String policyInvariantUuid = policy.getMetaData().getOrDefault("invariantUUID", "").toString(); + String policyUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("UUID", "").toString(); + String policyInvariantUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("invariantUUID", "").toString(); // cleanup existing RESOURCE_POLICY data Map cleanupParams = new HashMap(); @@ -363,8 +363,8 @@ public class SdncBaseModel { Map policyParams = new HashMap(); addParameter("policy_uuid", policyUuid, policyParams); addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams); - addParameter("policy_name", policy.getMetaData().getOrDefault("name", "").toString(), policyParams); - addParameter("version", policy.getMetaData().getOrDefault("version", "").toString(), policyParams); + addParameter("policy_name", policy.getMetaDataObj().getAllProperties().getOrDefault("name", "").toString(), policyParams); + addParameter("version", policy.getMetaDataObj().getAllProperties().getOrDefault("version", "").toString(), policyParams); addParameter("policy_type", policy.getType(), policyParams); // extract properties @@ -386,6 +386,10 @@ public class SdncBaseModel { // insert into RESOURCE_POLICY_TO_TARGET_NODE_MAPPING List policyTargetNameList = policy.getTargets(); + if (policyTargetNameList == null) { + continue; + } + for (String targetName : policyTargetNameList) { NodeTemplate targetNode = sdcCsarHelper.getNodeTemplateByName(targetName); @@ -423,8 +427,8 @@ public class SdncBaseModel { for (Policy policy : policyList) { // extract policy metadata - String policyUuid = policy.getMetaData().getOrDefault("UUID", "").toString(); - String policyInvariantUuid = policy.getMetaData().getOrDefault("invariantUUID", "").toString(); + String policyUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("UUID", "").toString(); + String policyInvariantUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("invariantUUID", "").toString(); // cleanup existing RESOURCE_POLICY data Map cleanupParams = new HashMap(); @@ -436,9 +440,9 @@ public class SdncBaseModel { Map policyParams = new HashMap(); addParameter("policy_uuid", policyUuid, policyParams); addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams); - String policyName = policy.getMetaData().getOrDefault(PARAM_NAME_KEY, "").toString(); + String policyName = policy.getMetaDataObj().getAllProperties().getOrDefault(PARAM_NAME_KEY, "").toString(); addParameter("policy_name", policyName, policyParams); - addParameter(PARAM_VERSION_KEY, policy.getMetaData().getOrDefault(PARAM_VERSION_KEY, "").toString(), policyParams); + addParameter(PARAM_VERSION_KEY, policy.getMetaDataObj().getAllProperties().getOrDefault(PARAM_VERSION_KEY, "").toString(), policyParams); addParameter("policy_type", policy.getType(), policyParams); // extract properties @@ -460,6 +464,10 @@ public class SdncBaseModel { // insert into RESOURCE_POLICY_TO_TARGET_NODE_MAPPING List targetNodeList = sdcCsarHelper.getPolicyTargetsFromOrigin(nodeTemplate, policyName); + if (targetNodeList == null) { + continue; + } + for (NodeTemplate targetNode : targetNodeList) { //NodeTemplate targetNode = sdcCsarHelper.getNodeTemplateByName(targetName); if (targetNode == null) { diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java index 850a34fa0..a42f03d8e 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java @@ -27,10 +27,14 @@ import java.util.List; import java.util.Map; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.enums.SdcTypes; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; +import org.onap.sdc.tosca.parser.api.IEntityDetails; +import org.onap.sdc.tosca.parser.elements.queries.EntityQuery; +import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery; import org.onap.sdc.toscaparser.api.Group; import org.onap.sdc.toscaparser.api.NodeTemplate; -import org.onap.sdc.toscaparser.api.Policy; +import org.onap.sdc.toscaparser.api.Property; import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; import org.slf4j.Logger; @@ -162,21 +166,48 @@ public class SdncVFModel extends SdncBaseModel { private void insertVFtoNetworkRoleMappingData () throws IOException { - // For each VF, insert VF_TO_NETWORK_ROLE_MAPPING data - List cpNodes = sdcCsarHelper.getCpListByVf(getCustomizationUUIDNoQuotes()); - for (NodeTemplate cpNode : cpNodes){ - - // Insert into VF_TO_NETWORK_ROLE_MAPPING vf_customization_uuid and network_role - String cpNetworkRole = sdcCsarHelper.getNodeTemplatePropertyLeafValue(cpNode, "network_role"); + // Cleanup existing VF_TO_NETWORK_ROLE_MAPPING for this VF + try { + cleanUpExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", "vf_customization_uuid", getCustomizationUUID()); + } catch (IOException e) { + LOG.error("Could not cleanup Tosca CSAR data into the VF_TO_NETWORK_ROLE_MAPPING table"); + throw new IOException (e); + } + + // For this VF, insert VF_TO_NETWORK_ROLE_MAPPING data + EntityQuery entityQueryCP = EntityQuery.newBuilder(SdcTypes.CP).build(); + TopologyTemplateQuery topologyTemplateQueryVF = TopologyTemplateQuery.newBuilder(SdcTypes.VF).customizationUUID(getCustomizationUUIDNoQuotes()).build(); + List cpEntities = sdcCsarHelper.getEntity(entityQueryCP, topologyTemplateQueryVF, true); + + for (IEntityDetails entity: cpEntities ) { + + Map properties = entity.getProperties(); + if (properties.containsKey("network_role")) { - try { - cleanUpExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", "vf_customization_uuid", getCustomizationUUID()); - LOG.info("Call insertToscaData for VF_TO_NETWORK_ROLE_MAPPING where vf_customization_uuid = " + getCustomizationUUID()); - insertToscaData("insert into VF_TO_NETWORK_ROLE_MAPPING (vf_customization_uuid, network_role) values (" + - getCustomizationUUID() + ", \"" + cpNetworkRole + "\")", null); - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the VF_TO_NETWORK_ROLE_MAPPING table"); - throw new IOException (e); + Property networkRoleProperty = properties.get("network_role"); + if (networkRoleProperty != null && networkRoleProperty.getValue() != null) { + String cpNetworkRole = networkRoleProperty.getValue().toString(); + LOG.debug("insertVFtoNetworkRoleMappingData: " + "VF: " + getCustomizationUUID() + ", networkRole = " + cpNetworkRole); + + // Only insert unique network_role values for this VF + boolean networkRoleExists = false; + Map networkRoleyKeys = new HashMap(); + networkRoleyKeys.put("vf_customization_uuid", getCustomizationUUID()); + networkRoleyKeys.put("network_role", "\"" + cpNetworkRole + "\""); + networkRoleExists = checkForExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", networkRoleyKeys); + + if (networkRoleExists == false) { + try { + //cleanUpExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", "vf_customization_uuid", getCustomizationUUID()); + LOG.info("Call insertToscaData for VF_TO_NETWORK_ROLE_MAPPING where vf_customization_uuid = " + getCustomizationUUID()); + insertToscaData("insert into VF_TO_NETWORK_ROLE_MAPPING (vf_customization_uuid, network_role) values (" + + getCustomizationUUID() + ", \"" + cpNetworkRole + "\")", null); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the VF_TO_NETWORK_ROLE_MAPPING table"); + throw new IOException (e); + } + } + } } } // CP loop -- cgit 1.2.3-korg From d91b57fd11c55a93ff0f55bb35aa4071eb7c0b61 Mon Sep 17 00:00:00 2001 From: "Timoney, Dan (dt5972)" Date: Mon, 4 Mar 2019 20:04:27 -0500 Subject: Improve ueb-listener test coverage Add missing initialization code in test case to trigger testing of pre-staged artifacts. Change-Id: I707ad708e461867b1dea79e11df13460262b6818 Issue-ID: CCSDK-1124 Signed-off-by: Timoney, Dan (dt5972) --- .../org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java | 1 + 1 file changed, 1 insertion(+) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java index d0a94d4bd..5b4637ea7 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java @@ -275,6 +275,7 @@ public class TestSdncUebCallback { when(iData.getServiceName()).thenReturn("testServiceName"); //when(iData.getServiceArtifacts()).thenReturn(artifactInfoList); + cb.deployDownloadedFiles(null, null, null); cb.activateCallback(iData); } -- cgit 1.2.3-korg From e8941385a6b0353236884fb183ef9e198b6560f5 Mon Sep 17 00:00:00 2001 From: "Aria, Lalena (la505a)" Date: Wed, 13 Mar 2019 18:18:14 +0000 Subject: Use getEnitity API for ingestion of TOSCA PNF Changes made: Update SdncUebCallback.processToscaCsar to ingest PNF entities. Add methods in SdncBaseModel.java to support processing of IEntityDetails. Add SdncPNFModel.java to populate VF_MODEL with PNF data. Add SdncPNFModelTest.java junit coverage. Change-Id: I9a82a94e8198d629395a60779f74178e4f8f065e Issue-ID: SDNC-675 Signed-off-by: Aria, Lalena (la505a) --- .../sli/northbound/uebclient/SdncBaseModel.java | 59 +++++++++ .../sli/northbound/uebclient/SdncPNFModel.java | 142 +++++++++++++++++++++ .../sli/northbound/uebclient/SdncUebCallback.java | 26 ++++ .../sli/northbound/uebclient/SdncPNFModelTest.java | 102 +++++++++++++++ 4 files changed, 329 insertions(+) create mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncPNFModel.java create mode 100644 ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncPNFModelTest.java (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index 37b100ca4..4824d9f2d 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -31,6 +31,7 @@ import java.util.Map; import javax.sql.rowset.CachedRowSet; +import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; import org.onap.sdc.toscaparser.api.CapabilityAssignment; @@ -70,6 +71,7 @@ public class SdncBaseModel { protected static DBResourceManager jdbcDataSource = null; protected static SdncUebConfiguration config = null; protected NodeTemplate nodeTemplate = null; + protected IEntityDetails entityDetails = null; public SdncBaseModel(DBResourceManager jdbcDataSource) { this.jdbcDataSource = jdbcDataSource; @@ -89,6 +91,14 @@ public class SdncBaseModel { this.jdbcDataSource = jdbcDataSource; this.config = config; } + + public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails entityDetails, DBResourceManager jdbcDataSource, SdncUebConfiguration config) throws IOException { + this (sdcCsarHelper, entityDetails); + this.sdcCsarHelper = sdcCsarHelper; + this.entityDetails = entityDetails; + this.jdbcDataSource = jdbcDataSource; + this.config = config; + } public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata) { @@ -128,6 +138,23 @@ public class SdncBaseModel { } + public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails entityDetails) { + + params = new HashMap(); + attributeValueParams = new HashMap(); + this.sdcCsarHelper = sdcCsarHelper; + this.entityDetails = entityDetails; + + // extract common nodeTemplate metadata + Metadata metadata = entityDetails.getMetadata(); + customizationUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); + invariantUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID); + addParameter(PARAM_INVARIANT_UUID_KEY, invariantUUID); + UUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_UUID); + addParameter(PARAM_UUID_KEY, UUID); + addParameter(PARAM_VERSION_KEY, extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VERSION)); + } + public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Group group, SdncUebConfiguration config, DBResourceManager jdbcDataSource) throws IOException { this (sdcCsarHelper, group); this.sdcCsarHelper = sdcCsarHelper; @@ -662,6 +689,22 @@ public class SdncBaseModel { } } + protected String extractValue (IEntityDetails entityDetails, String name) { + String value = null; + if (entityDetails.getProperties().containsKey(name)) { + Property property = entityDetails.getProperties().get(name); + if (property != null && property.getValue() != null) { + value = property.getValue().toString(); + } + } + + if (value != null) { + return value; + } else { + return ""; + } + } + protected String extractGetInputValue (Group group, NodeTemplate nodeTemplate, String name) { String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, extractGetInputName (group, name)); @@ -761,6 +804,22 @@ public class SdncBaseModel { } } + protected String extractBooleanValue (IEntityDetails entityDetails, String name) { + String value = null; + if (entityDetails.getProperties().containsKey(name)) { + Property property = entityDetails.getProperties().get(name); + if (property != null && property.getValue() != null) { + value = property.getValue().toString(); + } + } + + if (value != null && !value.isEmpty()) { + return value.contains("true") ? "Y" : "N"; + } else { + return ""; + } + } + public static String extractBooleanValue (ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, String name) { String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); if (value != null && !value.isEmpty()) { diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncPNFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncPNFModel.java new file mode 100644 index 000000000..296b13819 --- /dev/null +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncPNFModel.java @@ -0,0 +1,142 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 - 2018 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 java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; +import org.onap.sdc.tosca.parser.api.IEntityDetails; +import org.onap.sdc.toscaparser.api.elements.Metadata; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdncPNFModel extends SdncBaseModel { + + private static final Logger LOG = LoggerFactory + .getLogger(SdncVFModel.class); + + private String vendor = null; + private String vendorModelDescription = null; + private String nfNamingCode = null; + private String serviceUUID = null; + private String serviceInvariantUUID = null; + + public SdncPNFModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails entityDetails, DBResourceManager jdbcDataSource, SdncUebConfiguration config) throws IOException { + + super(sdcCsarHelper, entityDetails, jdbcDataSource, config); + + // extract metadata + Metadata metadata = entityDetails.getMetadata(); + addParameter("name", extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_NAME)); + vendor = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDOR); + addParameter("vendor", vendor); + vendorModelDescription = extractValue (metadata, "description"); + addParameter("vendor_version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDORRELEASE)); + + // extract properties + addParameter("ecomp_generated_naming", extractBooleanValue(entityDetails, "nf_naming#ecomp_generated_naming")); + addParameter("naming_policy", extractValue(entityDetails, "nf_naming#naming_policy")); + addParameter("nf_type", extractValue(entityDetails, SdcPropertyNames.PROPERTY_NAME_NFTYPE)); + addParameter("nf_role", extractValue(entityDetails, SdcPropertyNames.PROPERTY_NAME_NFROLE)); + nfNamingCode = extractValue(entityDetails, "nf_naming_code"); + addParameter("nf_code", nfNamingCode); + addParameter("nf_function", extractValue(entityDetails, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)); + addIntParameter("avail_zone_max_count", extractValue(entityDetails, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONEMAXCOUNT)); + addParameter("sdnc_model_name", extractValue(entityDetails, "sdnc_model_name")); + addParameter("sdnc_model_version", extractValue(entityDetails, "sdnc_model_version")); + addParameter("sdnc_artifact_name", extractValue(entityDetails, "sdnc_artifact_name")); + + } + + public void insertData() throws IOException { + + insertPNFModelData(); + } + + private void insertPNFModelData () throws IOException { + + try { + cleanUpExistingToscaData("VF_MODEL", "customization_uuid", getCustomizationUUID()) ; + cleanUpExistingToscaData("SERVICE_MODEL_TO_VF_MODEL_MAPPING", "service_uuid", serviceUUID, "vf_customization_uuid", getCustomizationUUID()); + + // insert into VF_MODEL/ATTRIBUTE_VALUE_PAIR and SERVICE_MODEL_TO_VF_MODEL_MAPPING + LOG.info("Call insertToscaData for VF_MODEL where customization_uuid = " + getCustomizationUUID()); + insertToscaData(buildSql("VF_MODEL", model_yaml), null); + //insertRelevantAttributeData(); + + Map mappingParams = new HashMap(); + addParameter("service_invariant_uuid", serviceInvariantUUID, mappingParams); + addParameter("vf_uuid", getUUID(), mappingParams); + addParameter("vf_customization_uuid", getCustomizationUUIDNoQuotes(), mappingParams); + insertToscaData(buildSql("SERVICE_MODEL_TO_VF_MODEL_MAPPING", "service_uuid", serviceUUID, model_yaml, mappingParams), null); + + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the VF_MODEL table"); + throw new IOException (e); + } + + } + + public String getVendor() { + return vendor; + } + + public void setVendor(String vendor) { + this.vendor = vendor; + } + + public String getVendorModelDescription() { + return vendorModelDescription; + } + + public void setVendorModelDescription(String vendorModelDescription) { + this.vendorModelDescription = vendorModelDescription; + } + + public String getNfNamingCode() { + return nfNamingCode; + } + + public void setNfNamingCode(String nfNamingCode) { + this.nfNamingCode = nfNamingCode; + } + + public String getServiceUUID() { + return serviceUUID; + } + public void setServiceUUID(String serviceUUID) { + this.serviceUUID = serviceUUID; + } + + public String getServiceInvariantUUID() { + return serviceInvariantUUID; + } + + public void setServiceInvariantUUID(String serviceInvariantUUID) { + this.serviceInvariantUUID = serviceInvariantUUID; + } + +} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index ba644f302..4d9dbda96 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -70,7 +70,11 @@ import org.onap.sdc.api.notification.INotificationData; import org.onap.sdc.api.notification.IResourceInstance; import org.onap.sdc.api.results.IDistributionClientDownloadResult; import org.onap.sdc.api.results.IDistributionClientResult; +import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.elements.queries.EntityQuery; +import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery; +import org.onap.sdc.tosca.parser.enums.SdcTypes; import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; import org.onap.sdc.toscaparser.api.NodeTemplate; @@ -751,6 +755,28 @@ public class SdncUebCallback implements INotificationCallback { } // VF loop + + // Ingest Network (PNF) Data - Dublin/1906 + EntityQuery entityQuery = EntityQuery.newBuilder(SdcTypes.PNF).build(); + TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).build(); + + List pnfs = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false); + if (!pnfs.isEmpty()) { + + for (IEntityDetails pnf : pnfs) { + + try { + SdncPNFModel pnfModel = new SdncPNFModel(sdcCsarHelper, pnf, jdbcDataSource, config); + pnfModel.setServiceUUID(serviceModel.getServiceUUID()); + pnfModel.setServiceInvariantUUID(serviceModel.getServiceInvariantUUID()); + pnfModel.insertData(); + + } catch (IOException e) { + deployStatus = DistributionStatusEnum.DEPLOY_ERROR; + } + } // PNF loop + } + DistributionStatusEnum complexToscaDeployStatus = customProcessComplexTosca(sdcCsarHelper, config, jdbcDataSource, serviceModel, data, svcName, resourceName, artifact, archiveDir); if (complexToscaDeployStatus == DistributionStatusEnum.DEPLOY_ERROR) { diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncPNFModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncPNFModelTest.java new file mode 100644 index 000000000..d4c06b049 --- /dev/null +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncPNFModelTest.java @@ -0,0 +1,102 @@ +package org.onap.ccsdk.sli.northbound.uebclient; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.onap.sdc.tosca.parser.api.IEntityDetails; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.toscaparser.api.elements.Metadata; +import org.onap.sdc.toscaparser.api.Property; + +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; + + public class SdncPNFModelTest { + + SdncPNFModel testSdncPNFModel = null; + + @Before + public void setUp() throws Exception { + ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); + IEntityDetails mockEntityDetails = mock(IEntityDetails.class); + Metadata mockMetadata = mock(Metadata.class); + Property mockProperty = mock(Property.class); + Map mockProperties = new HashMap(); + DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); + SdncUebConfiguration mockSdncUebConfiguration = mock(SdncUebConfiguration.class); + + when(mockEntityDetails.getMetadata()).thenReturn(mockMetadata); + when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "customizationUUID")).thenReturn("aaaa-bbbb-cccc-dddd"); + mockProperty.setValue("test-nf-naming-code"); + when(mockProperties.get("nf_naming_code")).thenReturn(mockProperty); + + try { + testSdncPNFModel = new SdncPNFModel(mockCsarHelper,mockEntityDetails,mockDBResourceManager,mockSdncUebConfiguration); + testSdncPNFModel.setServiceUUID("bbbb-cccc-dddd-eeee"); + testSdncPNFModel.setServiceInvariantUUID("cccc-dddd-eeee-ffff"); + testSdncPNFModel.setVendor("Cisco"); + testSdncPNFModel.setVendorModelDescription("Cisco Equipment Model"); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + assertNotNull(testSdncPNFModel); + } + + @Test + public void testSetGetVendor() { + String newVendorModel = "new-vendor-model"; + testSdncPNFModel.setVendor(newVendorModel); + String result = testSdncPNFModel.getVendor(); + assertEquals(result, newVendorModel); + } + + @Test + public void testSetGetVendorModelDescription() { + String newVendorModelDescription = "new-vendor-model-description"; + testSdncPNFModel.setVendorModelDescription(newVendorModelDescription); + String result = testSdncPNFModel.getVendorModelDescription(); + assertEquals(result, newVendorModelDescription); + } + + @Test + public void testSetGetNfNamingCode() { + String newNfNamingCode = "new-nf-naming-code"; + testSdncPNFModel.setNfNamingCode(newNfNamingCode); + String result = testSdncPNFModel.getNfNamingCode(); + assertEquals(result, newNfNamingCode); + } + + @Test + public void testSetGetServiceUUID() { + String newServiceUuid = "cccc-dddd-eeee-ffff"; + testSdncPNFModel.setServiceUUID(newServiceUuid); + String result = testSdncPNFModel.getServiceUUID(); + assertEquals(newServiceUuid, result); + } + + @Test + public void testSetGetServiceInvariantUUID() { + String newServiceInvariantUuid = "dddd-eeee-ffff-eeee"; + testSdncPNFModel.setServiceInvariantUUID(newServiceInvariantUuid); + String result = testSdncPNFModel.getServiceInvariantUUID(); + assertEquals(result, newServiceInvariantUuid); + } + + @Test + public void testInsertData() { + try { + testSdncPNFModel.insertData(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + } -- cgit 1.2.3-korg From 3a86df02c0c53b9c4c1138084a18bb724d22c4ef Mon Sep 17 00:00:00 2001 From: "Agarwal, Ruchira (ra1926)" Date: Mon, 20 May 2019 22:02:34 +0000 Subject: Use getEntity to populate VF Module tables Changes made: Update SdncVFModel.insertVFModuleData to use getEntity. Update SdncVFModule to use IEntityDetails instead of Group. Issue-ID: CCSDK-1347 Change-Id: I319d4b56b7d1e9bfb6a2d7601a24cd5c192477d7 Signed-off-by: Aria, Lalena (la505a) --- .../sli/northbound/uebclient/SdncBaseModel.java | 1 + .../sli/northbound/uebclient/SdncGroupModel.java | 2 +- .../sli/northbound/uebclient/SdncVFModel.java | 137 +++++++++++++++++---- .../northbound/uebclient/SdncVFModuleModel.java | 16 ++- .../uebclient/SdncVFModuleModelTest.java | 7 +- 5 files changed, 127 insertions(+), 36 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index 4824d9f2d..a5de97fc2 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -58,6 +58,7 @@ public class SdncBaseModel { protected String name = null; protected String PARAM_INVARIANT_UUID_KEY = "invariant_uuid"; + protected String PARAM_CUSTOMIZATION_UUID_KEY = "customization_uuid"; protected String PARAM_UUID_KEY = "uuid"; protected String PARAM_VERSION_KEY = "version"; protected String PARAM_NAME_KEY = "name"; diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java index ea62abe9c..dedaa9a2a 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java @@ -35,7 +35,7 @@ import org.slf4j.LoggerFactory; public class SdncGroupModel extends SdncBaseModel { private static final Logger LOG = LoggerFactory - .getLogger(SdncVFModuleModel.class); + .getLogger(SdncGroupModel.class); private static final String groupType = "group_type"; diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java index a42f03d8e..12eccf213 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java @@ -22,6 +22,7 @@ package org.onap.ccsdk.sli.northbound.uebclient; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -94,7 +95,7 @@ public class SdncVFModel extends SdncBaseModel { public void insertData() throws IOException { insertVFModelData(); - insertVFModuleData(nodeTemplate, jdbcDataSource); + insertVFModuleData(); insertVFtoNetworkRoleMappingData(); insertVFCData(); insertVFCInstanceGroupData(); @@ -125,12 +126,29 @@ public class SdncVFModel extends SdncBaseModel { } - private void insertVFModuleData (NodeTemplate nodeTemplate, DBResourceManager jdbcDataSource) throws IOException { + private void insertVFModuleData () throws IOException { - List vfModules = sdcCsarHelper.getVfModulesByVf(getCustomizationUUIDNoQuotes()); - for (Group group : vfModules){ - SdncVFModuleModel vfModuleModel = new SdncVFModuleModel(sdcCsarHelper, group, this); - + // Step 1: Get all the VF Module groups (entities) in this Service + EntityQuery entityQuery = EntityQuery.newBuilder("org.openecomp.groups.VfModule").build(); + String vfCustomizationUuid = getCustomizationUUIDNoQuotes(); + TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE) + .build(); + List vfModules = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false); + if (vfModules == null) { + return; + } + + // Insert each VF Module group (entity) into VF_MODULE_MODEL if its name is prefixed with the VF name + for (IEntityDetails vfModule : vfModules){ + + // If this vfModule name is prefixed with the VF name of the VF bing processed, insert this VF Module in VF_MODULE_MODEL + String normailizedVfName = nodeTemplate.getName().toLowerCase().replace(" ", ""); + if (!vfModule.getName().startsWith(normailizedVfName)) { + continue; + } + + SdncVFModuleModel vfModuleModel = new SdncVFModuleModel(sdcCsarHelper, vfModule, this); + try { cleanUpExistingToscaData("VF_MODULE_MODEL", "customization_uuid", vfModuleModel.getCustomizationUUID()); cleanUpExistingToscaData("VF_MODULE_TO_VFC_MAPPING", "vf_module_customization_uuid", vfModuleModel.getCustomizationUUID()); @@ -140,28 +158,95 @@ public class SdncVFModel extends SdncBaseModel { LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_MODEL table "); throw new IOException (e); } - - // For each VF Module, get the VFC list, insert VF_MODULE_TO_VFC_MAPPING data - // List groupMembers = sdcCsarHelper.getMembersOfGroup(group); - old version - // For each vfcNode (group member) in the groupMembers list, extract vm_type and vm_count. - // Insert vf_module.customizationUUID, vfcNode.customizationUUID and vm_type and vm_count into VF_MODULE_TO_VFC_MAPPING - List groupMembers = sdcCsarHelper.getMembersOfVfModule(nodeTemplate, group); - for (NodeTemplate vfcNode : groupMembers){ - SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, vfcNode, jdbcDataSource); - - try { - LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING where vf_module_customization_uuid = " + vfModuleModel.getCustomizationUUID()); - insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" + - vfModuleModel.getCustomizationUUID() + ", " + vfcModel.getCustomizationUUID() + ", \"" + vfcModel.getVmType() + "\", \"" + vfcModel.getVmCount() + "\")", null); - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_TO_VFC_MAPPING table"); - throw new IOException (e); - } - + + // Step 2: Get the non-catalog VF Module in order to get the group members + String vfModuleUuid = vfModuleModel.getUUID().replace("\"", ""); + EntityQuery entityQuery2 = EntityQuery.newBuilder("org.openecomp.groups.VfModule") + .uUID(vfModuleUuid) + .build(); + TopologyTemplateQuery topologyTemplateQuery2 = TopologyTemplateQuery.newBuilder(SdcTypes.VF) + .customizationUUID(vfCustomizationUuid) // customization UUID of the VF if exists + .build(); + List vfModulesNonCatalog = sdcCsarHelper.getEntity(entityQuery2, topologyTemplateQuery2, false); + if (vfModulesNonCatalog == null || vfModulesNonCatalog.isEmpty()) { + LOG.info("insertVFModuleDataGetEntity2: Could not find the non-catelog VF Module for: " + vfModuleModel.getCustomizationUUID() + ". Unable to insert members into VF_MODULE_TO_VFC_MAPPING"); + continue; + } + + List vfModuleMembers = vfModulesNonCatalog.get(0).getMemberNodes(); + + // Find all members for each VF Module that are of type CVFC and insert it and any nested CFVCs into VF_MODULE_TO_VFC_MAPPING + for (IEntityDetails vfModuleMember: vfModuleMembers) { + if (vfModuleMember.getMetadata().getValue("type").equals(SdcTypes.CVFC.getValue())) { + + // Insert this CVFC data into VF_MODULE_TO_VFC_MAPPING + String cvfcCustomizationUuid = extractValue(vfModuleMember.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); + String vfcVmType = extractValue (vfModuleMember, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG); // extracted as vm_type_tag + String vfcVmCount = ""; + if (vfModuleMember.getProperties().containsKey("service_template_filter")) { + Property property = vfModuleMember.getProperties().get("service_template_filter"); + if (property != null && property.getLeafPropertyValue("count") != null) { + vfcVmCount = property.getLeafPropertyValue("count").get(0); + } + } + if (vfcVmCount.isEmpty()) { + vfcVmCount = "0"; // vm_count can not be null + } + + try { + LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING where vf_module_customization_uuid = " + vfModuleModel.getCustomizationUUID()); + insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" + + vfModuleModel.getCustomizationUUID() + ", \"" + cvfcCustomizationUuid + "\", \"" + vfcVmType + "\", \"" + vfcVmCount + "\")", null); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_TO_VFC_MAPPING table"); + throw new IOException (e); + } + + // Step 3: Get any nested CVFCs under this CVFC + EntityQuery entityQuery3 = EntityQuery.newBuilder(SdcTypes.CVFC) + .build(); + TopologyTemplateQuery topologyTemplateQuery3 = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC) + .customizationUUID(cvfcCustomizationUuid) // customization UUID of the CVFC if exists + .build(); + List nestedCvfcs = sdcCsarHelper.getEntity(entityQuery3, topologyTemplateQuery3, true); // true allows for nested search + if (nestedCvfcs == null || nestedCvfcs.isEmpty()) { + LOG.info("insertVFModuleDataGetEntity2: Could not find the nested CVFCs for: " + cvfcCustomizationUuid); + continue; + } + + for (IEntityDetails nestedCvfc: nestedCvfcs) { + + // Insert this CVFC data into VF_MODULE_TO_VFC_MAPPING + String nestedCvfcCustomizationUuid = extractValue(nestedCvfc.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); + String nestedVfcVmType = extractValue (nestedCvfc, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG); // extracted as vm_type_tag + String nestedVfcVmCount = ""; + if (nestedCvfc.getProperties().containsKey("service_template_filter")) { + Property property = nestedCvfc.getProperties().get("service_template_filter"); + if (property != null && property.getLeafPropertyValue("count") != null) { + nestedVfcVmCount = property.getLeafPropertyValue("count").get(0); + } + } + if (nestedVfcVmCount.isEmpty()) { + nestedVfcVmCount = "0"; // vm_count can not be null + } + + try { + LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING where vf_module_customization_uuid = " + vfModuleModel.getCustomizationUUID()); + insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" + + vfModuleModel.getCustomizationUUID() + ", \"" + nestedCvfcCustomizationUuid + "\", \"" + nestedVfcVmType + "\", \"" + nestedVfcVmCount + "\")", null); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_TO_VFC_MAPPING table"); + throw new IOException (e); + } + + } + + } + } - + } - + } private void insertVFtoNetworkRoleMappingData () throws IOException { diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java index 914401ff1..f9a03b3f3 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java @@ -22,22 +22,26 @@ package org.onap.ccsdk.sli.northbound.uebclient; +import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; import org.onap.sdc.toscaparser.api.Group; public class SdncVFModuleModel extends SdncBaseModel { - public SdncVFModuleModel(ISdcCsarHelper sdcCsarHelper, Group group, SdncVFModel vfNodeModel) { + public SdncVFModuleModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails vfModule, SdncVFModel vfNodeModel) { - super(sdcCsarHelper, group); + super(sdcCsarHelper, vfModule); + // override base implementation for setting customizationUUID because customizationUUID is called differently for Groups + customizationUUID = extractValue (vfModule.getMetadata(), "vfModuleModelCustomizationUUID"); + UUID = extractValue (vfModule.getMetadata(), "vfModuleModelUUID"); addParameter("vf_customization_uuid", vfNodeModel.getCustomizationUUIDNoQuotes()); // extract properties - addParameter("vf_module_type", extractValue(group, SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE)); - addParameter("vf_module_label", extractValue(group, "vf_module_label")); - addIntParameter("availability_zone_count", extractValue(group, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)); - addParameter("ecomp_generated_vm_assignments", extractBooleanValue(group, SdcPropertyNames.PROPERTY_NAME_ECOMPGENERATEDVMASSIGNMENTS)); + addParameter("vf_module_type", extractValue(vfModule, SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE)); + addParameter("vf_module_label", extractValue(vfModule, "vf_module_label")); + addIntParameter("availability_zone_count", extractValue(vfModule, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)); + addParameter("ecomp_generated_vm_assignments", extractBooleanValue(vfModule, SdcPropertyNames.PROPERTY_NAME_ECOMPGENERATEDVMASSIGNMENTS)); } } diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java index 1fd10104c..846b79b49 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java @@ -3,7 +3,8 @@ package org.onap.ccsdk.sli.northbound.uebclient; import static org.junit.Assert.*; import static org.mockito.Mockito.mock; -import org.junit.Test; +import org.junit.Test; +import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.toscaparser.api.Group; import org.onap.ccsdk.sli.northbound.uebclient.SdncVFModel; @@ -12,10 +13,10 @@ public class SdncVFModuleModelTest { @Test public void testSdncVFModuleModelConstructor() { - Group mockGroup = mock(Group.class); + IEntityDetails mockEntity = mock(IEntityDetails.class); ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); SdncVFModel mockSdncVFModel = mock(SdncVFModel.class); - SdncVFModuleModel testSdncVFModel = new SdncVFModuleModel(mockCsarHelper, mockGroup, mockSdncVFModel); + SdncVFModuleModel testSdncVFModel = new SdncVFModuleModel(mockCsarHelper, mockEntity, mockSdncVFModel); assertNotNull(testSdncVFModel); } -- cgit 1.2.3-korg From 69a61e338d5e528870085f6d365ae41bfd2cd9a4 Mon Sep 17 00:00:00 2001 From: "Aria, Lalena (la505a)" Date: Fri, 14 Jun 2019 14:58:13 +0000 Subject: Use getEntity to populate VFC and AR tables Changes made: Update SdncARModel to use IEntityDetails instead of NodeTemplate. Update SdncVFCModel to use IEntityDetails instead of Group. Small fixes in SdncVFModuleModel. Corresponding junit changes for getEntity migration. Issue-ID: CCSDK-1367 Change-Id: Ifaf57e9fb22ef87be80bad39948f07bb0a78a6bc Signed-off-by: lalena.aria --- .../sli/northbound/uebclient/SdncARModel.java | 43 ++- .../sli/northbound/uebclient/SdncBaseModel.java | 75 ++++ .../sli/northbound/uebclient/SdncUebCallback.java | 30 +- .../sli/northbound/uebclient/SdncVFCModel.java | 414 ++++++++++----------- .../sli/northbound/uebclient/SdncVFModel.java | 69 ++-- .../northbound/uebclient/SdncVFModuleModel.java | 8 +- .../sli/northbound/uebclient/SdncARModelTest.java | 12 +- .../sli/northbound/uebclient/SdncVFCModelTest.java | 20 +- 8 files changed, 401 insertions(+), 270 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java index 9cac459d7..f1e514da4 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java @@ -23,10 +23,14 @@ package org.onap.ccsdk.sli.northbound.uebclient; import java.io.IOException; +import java.util.List; +import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.elements.queries.EntityQuery; +import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery; +import org.onap.sdc.tosca.parser.enums.SdcTypes; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; -import org.onap.sdc.toscaparser.api.NodeTemplate; import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; import org.slf4j.Logger; @@ -40,21 +44,21 @@ public class SdncARModel extends SdncBaseModel { private String type = null; private String subcategory = null; - public SdncARModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate,DBResourceManager jdbcDataSource) { + public SdncARModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails arEntity, DBResourceManager jdbcDataSource, SdncUebConfiguration config) throws IOException { - super(sdcCsarHelper, nodeTemplate, jdbcDataSource); + super(sdcCsarHelper, arEntity, jdbcDataSource, config); // extract metadata - Metadata metadata = nodeTemplate.getMetaData(); + Metadata metadata = arEntity.getMetadata(); type = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_TYPE); subcategory = extractValue (metadata, "subcategory"); addParameter("type", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_TYPE)); // extract properties - addParameter("role", extractValue (nodeTemplate, "nf_role")); - addParameter("type", extractValue (nodeTemplate, "nf_type")); - addParameter("ecomp_generated_naming", extractBooleanValue (nodeTemplate, "nf_naming#ecomp_generated_naming")); - addParameter("naming_policy", extractValue (nodeTemplate, "nf_naming#naming_policy")); + addParameter("role", extractValue (arEntity, "nf_role")); + addParameter("type", extractValue (arEntity, "nf_type")); + addParameter("ecomp_generated_naming", extractBooleanValue (arEntity, "nf_naming", "ecomp_generated_naming")); + addParameter("naming_policy", extractValue (arEntity, "nf_naming", "naming_policy")); } public void insertAllottedResourceModelData () throws IOException { @@ -67,6 +71,29 @@ public class SdncARModel extends SdncBaseModel { throw new IOException (e); } } + + public void insertAllottedResourceVfcModelData () throws IOException { + + // Insert the child VFCs (not CVFC) into VFC_MODEL + String vfCustomizationUuid = getCustomizationUUID().replace("\"", ""); + EntityQuery vfcEntityQuery = EntityQuery.newBuilder(SdcTypes.VFC).build(); + TopologyTemplateQuery vfcTopologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF) + .customizationUUID(vfCustomizationUuid) + .build(); + List nestedVfcs = sdcCsarHelper.getEntity(vfcEntityQuery, vfcTopologyTemplateQuery, true); // true allows for nested search + if (nestedVfcs == null || nestedVfcs.isEmpty()) { + LOG.info("Could not find the nested VFCs for: " + vfCustomizationUuid); + } + + for (IEntityDetails nestedVfc: nestedVfcs) { + try { + SdncVFCModel arVfcModel = new SdncVFCModel (sdcCsarHelper, nestedVfc, jdbcDataSource, config); + arVfcModel.insertVFCModelData(); + } catch (IOException e) { + LOG.info("Could not find the nested VFCs for: " + vfCustomizationUuid); + } + } + } public String getSubcategory() { return subcategory; diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index a5de97fc2..245911250 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -706,6 +706,65 @@ public class SdncBaseModel { } } + protected String extractValue (IEntityDetails entityDetails, String path, String name) { + String value = null; + + if (entityDetails.getProperties().containsKey(path)) { + Property property = entityDetails.getProperties().get(path); + if (property != null && property.getLeafPropertyValue(name) != null) { + value = property.getLeafPropertyValue(name).get(0); + } + } + + if (value != null) { + return value; + } else { + return ""; + } + } + + protected String extractValue (Property property, String name) { + String value = null; + + if (!property.getLeafPropertyValue(name).isEmpty()) { + value = property.getLeafPropertyValue(name).get(0); + } + + if (value != null) { + return value; + } else { + return ""; + } + } + + protected String extractBooleanValue (Property property, String name) { + String value = null; + + if (!property.getLeafPropertyValue(name).isEmpty()) { + value = property.getLeafPropertyValue(name).get(0); + } + + if (value != null) { + return value.contains("true") ? "Y" : "N"; + } else { + return ""; + } + } + + protected String extractIntegerValue (Property property, String name) { + String value = null; + + if (!property.getLeafPropertyValue(name).isEmpty()) { + value = property.getLeafPropertyValue(name).get(0); + } + + if (value != null && !value.isEmpty() && !value.contains("null")) { + return value; + } else { + return ""; + } + } + protected String extractGetInputValue (Group group, NodeTemplate nodeTemplate, String name) { String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, extractGetInputName (group, name)); @@ -821,6 +880,22 @@ public class SdncBaseModel { } } + protected String extractBooleanValue (IEntityDetails entityDetails, String path, String name) { + String value = null; + if (entityDetails.getProperties().containsKey(path)) { + Property property = entityDetails.getProperties().get(path); + if (property != null && property.getLeafPropertyValue(name) != null) { + value = property.getLeafPropertyValue(name).get(0); + } + } + + if (value != null && !value.isEmpty()) { + return value.contains("true") ? "Y" : "N"; + } else { + return ""; + } + } + public static String extractBooleanValue (ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, String name) { String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); if (value != null && !value.isEmpty()) { diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index 4d9dbda96..95672ea5f 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -718,16 +718,26 @@ public class SdncUebCallback implements INotificationCallback { } } - // Ingest Allotted Resource Data - 1707 - List arNodeTemplatesList = sdcCsarHelper.getAllottedResources(); - - for (NodeTemplate nodeTemplate : arNodeTemplatesList) { - - try { - SdncARModel nodeModel = new SdncARModel (sdcCsarHelper, nodeTemplate, jdbcDataSource); - nodeModel.insertAllottedResourceModelData (); - } catch (IOException e) { - deployStatus = DistributionStatusEnum.DEPLOY_ERROR; + // Ingest Allotted Resource Data - 1707 / migrate to getEntity - 1908 + // Use getEntity to get all VFs in the service filter by metadata Category = Allotted Resource + EntityQuery vfEntityQuery = EntityQuery.newBuilder(SdcTypes.VF).build(); + TopologyTemplateQuery vfTopologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).build(); + List vfEntities = sdcCsarHelper.getEntity(vfEntityQuery, vfTopologyTemplateQuery, true); + if (vfEntities != null) { + for (IEntityDetails vfEntity : vfEntities){ + + // If this VF has metadata Category: Allotted Resource, insert it into ALLOTTED_RESOURCE_MODEL table + String vfCategory = SdncBaseModel.extractValue(sdcCsarHelper, vfEntity.getMetadata(), "category"); + if (vfCategory.contains("Allotted Resource")) { + + try { + SdncARModel arModel = new SdncARModel (sdcCsarHelper, vfEntity, jdbcDataSource, config); + arModel.insertAllottedResourceModelData (); + arModel.insertAllottedResourceVfcModelData(); + } catch (IOException e) { + deployStatus = DistributionStatusEnum.DEPLOY_ERROR; + } + } } } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java index 94392262e..bd71c0240 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java @@ -27,9 +27,13 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.elements.queries.EntityQuery; +import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery; +import org.onap.sdc.tosca.parser.enums.SdcTypes; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; -import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.Property; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,28 +46,28 @@ public class SdncVFCModel extends SdncBaseModel { private String vmType = null; private String vmCount = null; - public SdncVFCModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, DBResourceManager jdbcDataSource) { + public SdncVFCModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails entityDetails, DBResourceManager jdbcDataSource, SdncUebConfiguration config) throws IOException { - super(sdcCsarHelper, nodeTemplate, jdbcDataSource); + super(sdcCsarHelper, entityDetails, jdbcDataSource, config); // extract properties - addParameter("ecomp_generated_naming", extractBooleanValue (nodeTemplate, "nfc_naming#ecomp_generated_naming")); - addParameter("naming_policy", extractValue (nodeTemplate, "nfc_naming#naming_policy")); - vmCount = extractValue (nodeTemplate, "service_template_filter#count"); // need path to vm_count, extracted as service_template_filter#count + addParameter("ecomp_generated_naming", extractBooleanValue (entityDetails, "nfc_naming", "ecomp_generated_naming")); + addParameter("naming_policy", extractValue (entityDetails, "nfc_naming", "naming_policy")); + vmCount = extractValue (entityDetails, "service_template_filter", "count"); // need path to vm_count, extracted as service_template_filter#count if (vmCount.isEmpty()) { vmCount = "0"; // vm_count can not be null } - vmType = extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG); + vmType = extractValue (entityDetails, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG); addParameter("vm_type", vmType); // populate vm_type with vm_type_tag value addParameter("vm_type_tag", vmType); - addParameter("nfc_naming_code", extractValue (nodeTemplate, "nfc_naming_code")); - addParameter("nfc_function", extractValue (nodeTemplate, "nfc_function")); - addParameter("high_availability", extractValue (nodeTemplate, "high_availablity")); - addParameter("vm_image_name", extractValue (nodeTemplate, "vm_image_name")); - addParameter("vm_flavor_name", extractValue (nodeTemplate, "vm_flavor_name")); - addParameter("nfc_naming", extractValue (nodeTemplate, "nfc_naming")); - addParameter("min_instances", extractValue (nodeTemplate, "min_instances")); - addParameter("max_instances", extractValue (nodeTemplate, "max_instances")); + addParameter("nfc_naming_code", extractValue (entityDetails, "nfc_naming_code")); + addParameter("nfc_function", extractValue (entityDetails, "nfc_function")); + addParameter("high_availability", extractValue (entityDetails, "high_availablity")); + addParameter("vm_image_name", extractValue (entityDetails, "vm_image_name")); + addParameter("vm_flavor_name", extractValue (entityDetails, "vm_flavor_name")); + addParameter("nfc_naming", extractValue (entityDetails, "nfc_naming")); + addParameter("min_instances", extractValue (entityDetails, "min_instances")); + addParameter("max_instances", extractValue (entityDetails, "max_instances")); } public void insertVFCModelData () throws IOException { @@ -78,16 +82,20 @@ public class SdncVFCModel extends SdncBaseModel { } - public void insertVFCtoNetworkRoleMappingData (NodeTemplate vfcNode) throws IOException { - + public void insertVFCtoNetworkRoleMappingData (IEntityDetails cvfcEntity) throws IOException { + + // Get the CPs on this VFC - using getEntity // For each VFC node, get CP properties to insert into VFC_TO_NETWORK_ROLE_MAPPING // VFC_TO_NETWORK_ROLE_MAPPING: vfc_customization_uuid, network_role, network_role_tag, vm_type, ipv4_count, ipv6_count, // ipv4_use_dhcp, ipv6_use_dhcp, ipv4_ip_version, ipv6_ip_version, extcp_subnetpool_id - Map> cpPropertiesMap = sdcCsarHelper.getCpPropertiesFromVfcAsObject(vfcNode); - // DEBUG only - if (cpPropertiesMap != null && !cpPropertiesMap.toString().contentEquals("{}")) { - LOG.info("getCpPropertiesFromVfcAsObject for vfc_customization_uuid " + this.getCustomizationUUID() + ": " + cpPropertiesMap.toString()); + String vfcCustomizationUuid = getCustomizationUUID().replace("\"", ""); + EntityQuery entityQueryCP = EntityQuery.newBuilder(SdcTypes.CP).build(); + TopologyTemplateQuery topologyTemplateQueryVFC = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC).customizationUUID(vfcCustomizationUuid).build(); + List cpEntities = sdcCsarHelper.getEntity(entityQueryCP, topologyTemplateQueryVFC, true); + if (cpEntities == null || cpEntities.isEmpty()) { + LOG.info("insertVFCtoNetworkRoleMappingData: Could not find the nested CVFCs for: " + vfcCustomizationUuid); + return; } // Clean up all VFC_TO_NETWORK_ROLE_MAPPING data for this VFC node @@ -96,165 +104,147 @@ public class SdncVFCModel extends SdncBaseModel { } catch (IOException e) { LOG.error("Could not clean up data in VFC_TO_NETWORK_ROLE_MAPPING table ", e); } - - // There will be a cpPropertiesMap entry for each CP which will contain a map of properties to be inserted into VFC_TO_NETWORK_ROLE_MAPPING + // There can be multiple insertions per CP: // Insert once for each unique IP Version / Subnet Role combination per CP (network_role) - // If there are IPV4 and IPV6 ip_requirements elements that have the same subnet_role (within a CP) combine those parameters for one insert - for (String nodeMapKey : cpPropertiesMap.keySet()) { // there will be one entry in this map per CP (network_role) - LOG.debug("node key = " + nodeMapKey); - Map propsMap = cpPropertiesMap.get(nodeMapKey); - Map commonParams = new HashMap(); // non-IP Version specific parameters + for (IEntityDetails cpEntity : cpEntities) { + // Extract common parameters + Map commonParams = new HashMap(); // non-IP Version specific parameters // Get vm_type from VFC node - SdncBaseModel.addParameter("vm_type", getVmType(), commonParams); + addParameter("vm_type", getVmType(), commonParams); - // Extract non-IP Version specific parameters - String networkRole = nullCheck(propsMap.get("network_role")).isEmpty() ? "default-network-role" : nullCheck(propsMap.get("network_role")); - SdncBaseModel.addParameter("network_role", networkRole, commonParams); // can not be null - SdncBaseModel.addParameter("network_role_tag", nullCheck(propsMap.get("network_role_tag")), commonParams); - SdncBaseModel.addParameter("extcp_subnetpool_id", nullCheck(propsMap.get("subnetpoolid")), commonParams); - - // Loop thru all CPs using getNodeTemplateChildren and match the network_role on the CP with network_role from - // getCpPropertiesFromVfcAsObject output, then get subinterface_indicator for this CP - List cpNodesList = sdcCsarHelper.getNodeTemplateChildren(vfcNode); - for (NodeTemplate cpNode : cpNodesList){ - String cpNetworkRole = extractValue(cpNode, "network_role"); - - if (cpNetworkRole == networkRole) { - String subinterfaceIndicator = extractBooleanValue (cpNode, "subinterface_indicator"); - addParameter("subinterface_indicator", subinterfaceIndicator, commonParams); - } - } - - // Extract IP Version specific parameters - String ipRequirementsString = nullCheck(propsMap.get("ip_requirements")); - //ArrayList> ipPropsList = (ArrayList>) propsMap.get("ip_requirements"); - ArrayList> ipPropsList = new ArrayList>(); - - if (!ipRequirementsString.equals("{}")) { - ipPropsList = (ArrayList>) propsMap.get("ip_requirements"); - } + // Extract non-IP Version specific parameters - outside the ip_requirements block + String networkRole = extractValue(cpEntity, "network_role").isEmpty() ? "default-network-role" : extractValue(cpEntity, "network_role"); // set default-network-role? + addParameter("network_role", networkRole, commonParams); // can not be null + addParameter("network_role_tag", nullCheck(extractValue(cpEntity, "network_role_tag")), commonParams); + addParameter("extcp_subnetpool_id", nullCheck(extractValue(cpEntity, "subnetpoolid")), commonParams); + String subinterfaceIndicator = extractBooleanValue (cpEntity, "subinterface_indicator"); + addParameter("subinterface_indicator", subinterfaceIndicator, commonParams); // Build lists of all IPV4 and IPV6 ip_requirements elements ArrayList> ipv4PropParamsList = new ArrayList>(); ArrayList> ipv6PropParamsList = new ArrayList>(); - - if (ipPropsList != null) { - for (Map ipPropMap : ipPropsList) { - //LOG.info("ip_requirements prop map = " + nullCheck(ipPropMap)); - - String ipVersion = nullCheck(ipPropMap.get("ip_version")); - if (ipVersion == null) { - LOG.error("SdncVFCModel: ipVersion not included in ip_requirements element"); - continue; - } - - String subnetRole = nullCheck(ipPropMap.get("subnet_role")); - - if (ipVersion.contains("4")) { + + // Extract IP Version specific parameters + if (cpEntity.getProperties().containsKey("ip_requirements")) { + + ArrayList> ipPropsList = new ArrayList>(); + ipPropsList = (ArrayList>) cpEntity.getProperties().get("ip_requirements").getValue(); + + if (ipPropsList != null) { + for (Map ipPropMap : ipPropsList) { + //LOG.info("ip_requirements prop map = " + nullCheck(ipPropMap)); + + String ipVersion = nullCheck(ipPropMap.get("ip_version")); + if (ipVersion == null) { + LOG.error("SdncVFCModel: ipVersion not included in ip_requirements element"); + continue; + } - // If we have already encountered this subnetRole for IPV4, skip this ip_requirements element - if (!ipPropParamsMapContainsSubnetRole (ipv4PropParamsList, subnetRole)) { + String subnetRole = nullCheck(ipPropMap.get("subnet_role")); - Map ipv4PropParams = new HashMap(); - SdncBaseModel.addParameter("ipv4_ip_version", ipVersion, ipv4PropParams); - SdncBaseModel.addParameter("ipv4_use_dhcp", nullCheck(ipPropMap.get("dhcp_enabled")).contains("true") ? "Y" : "N", ipv4PropParams); - Map ipCountRequired = (Map)ipPropMap.get("ip_count_required"); - if (ipCountRequired != null && ipCountRequired.get("count") != null) { - SdncBaseModel.addParameter("ipv4_count", nullCheck(ipCountRequired.get("count")), ipv4PropParams); - } - Map floatingIpCountRequired = (Map)ipPropMap.get("floating_ip_count_required"); - if (floatingIpCountRequired != null && floatingIpCountRequired.get("count") != null) { - SdncBaseModel.addParameter("ipv4_floating_count", nullCheck(floatingIpCountRequired.get("count")), ipv4PropParams); - } - SdncBaseModel.addParameter("ipv4_address_plan_name", nullCheck(ipPropMap.get("ip_address_plan_name")), ipv4PropParams); - SdncBaseModel.addParameter("ipv4_vrf_name", nullCheck(ipPropMap.get("vrf_name")), ipv4PropParams); - SdncBaseModel.addParameter("subnet_role", nullCheck(ipPropMap.get("subnet_role")), ipv4PropParams); - - ipv4PropParamsList.add(ipv4PropParams); + if (ipVersion.contains("4")) { + + // If we have already encountered this subnetRole for IPV4, skip this ip_requirements element + if (!ipPropParamsMapContainsSubnetRole (ipv4PropParamsList, subnetRole)) { - } else { - LOG.error("SdncVFCModel: Additional V4 ip-requirements element encountered for this subnet_role: ", subnetRole); - } + Map ipv4PropParams = new HashMap(); + SdncBaseModel.addParameter("ipv4_ip_version", ipVersion, ipv4PropParams); + SdncBaseModel.addParameter("ipv4_use_dhcp", nullCheck(ipPropMap.get("dhcp_enabled")).contains("true") ? "Y" : "N", ipv4PropParams); + Map ipCountRequired = (Map)ipPropMap.get("ip_count_required"); + if (ipCountRequired != null && ipCountRequired.get("count") != null) { + SdncBaseModel.addParameter("ipv4_count", nullCheck(ipCountRequired.get("count")), ipv4PropParams); + } + Map floatingIpCountRequired = (Map)ipPropMap.get("floating_ip_count_required"); + if (floatingIpCountRequired != null && floatingIpCountRequired.get("count") != null) { + SdncBaseModel.addParameter("ipv4_floating_count", nullCheck(floatingIpCountRequired.get("count")), ipv4PropParams); + } + SdncBaseModel.addParameter("ipv4_address_plan_name", nullCheck(ipPropMap.get("ip_address_plan_name")), ipv4PropParams); + SdncBaseModel.addParameter("ipv4_vrf_name", nullCheck(ipPropMap.get("vrf_name")), ipv4PropParams); + SdncBaseModel.addParameter("subnet_role", nullCheck(ipPropMap.get("subnet_role")), ipv4PropParams); + + ipv4PropParamsList.add(ipv4PropParams); + + } else { + LOG.error("SdncVFCModel: Additional V4 ip-requirements element encountered for this subnet_role: ", subnetRole); + } - } else if (ipVersion.contains("6")) { + } else if (ipVersion.contains("6")) { - // If we have already encountered this subnetRole for IPV6, skip this ip_requirements element - if (!ipPropParamsMapContainsSubnetRole (ipv6PropParamsList, subnetRole)) { - - Map ipv6PropParams = new HashMap(); - SdncBaseModel.addParameter("ipv6_ip_version", ipVersion, ipv6PropParams); - SdncBaseModel.addParameter("ipv6_use_dhcp", nullCheck(ipPropMap.get("dhcp_enabled")).contains("true") ? "Y" : "N", ipv6PropParams); - Map ipCountRequired = (Map)ipPropMap.get("ip_count_required"); - if (ipCountRequired != null && ipCountRequired.get("count") != null) { - SdncBaseModel.addParameter("ipv6_count", nullCheck(ipCountRequired.get("count")), ipv6PropParams); - } - Map floatingIpCountRequired = (Map)ipPropMap.get("floating_ip_count_required"); - if (floatingIpCountRequired != null && floatingIpCountRequired.get("count") != null) { - SdncBaseModel.addParameter("ipv6_floating_count", nullCheck(floatingIpCountRequired.get("count")), ipv6PropParams); - } - SdncBaseModel.addParameter("ipv6_address_plan_name", nullCheck(ipPropMap.get("ip_address_plan_name")), ipv6PropParams); - SdncBaseModel.addParameter("ipv6_vrf_name", nullCheck(ipPropMap.get("vrf_name")), ipv6PropParams); - SdncBaseModel.addParameter("subnet_role", nullCheck(ipPropMap.get("subnet_role")), ipv6PropParams); + // If we have already encountered this subnetRole for IPV6, skip this ip_requirements element + if (!ipPropParamsMapContainsSubnetRole (ipv6PropParamsList, subnetRole)) { - ipv6PropParamsList.add(ipv6PropParams); - - } else { - LOG.error("SdncVFCModel: Additional V6 ip-requirements element encountered for this subnetRole: ", subnetRole); - } - - } else { - LOG.error("SdncVFCModel: invalid IP version encountered: ", ipVersion); - } - - } // for each ip-requirements element - - } // ipPropsList null check - - // After all Common and IP Version specific parameters are extracted, insert IPV4 and IPV6 data separately - // Insert IPV4 data - for (Map ipv4PropParams: ipv4PropParamsList) { - - Map mappingParams = new HashMap(); // final list for single insertion - addParamsToMap(commonParams, mappingParams); - addParamsToMap(ipv4PropParams, mappingParams); + Map ipv6PropParams = new HashMap(); + SdncBaseModel.addParameter("ipv6_ip_version", ipVersion, ipv6PropParams); + SdncBaseModel.addParameter("ipv6_use_dhcp", nullCheck(ipPropMap.get("dhcp_enabled")).contains("true") ? "Y" : "N", ipv6PropParams); + Map ipCountRequired = (Map)ipPropMap.get("ip_count_required"); + if (ipCountRequired != null && ipCountRequired.get("count") != null) { + SdncBaseModel.addParameter("ipv6_count", nullCheck(ipCountRequired.get("count")), ipv6PropParams); + } + Map floatingIpCountRequired = (Map)ipPropMap.get("floating_ip_count_required"); + if (floatingIpCountRequired != null && floatingIpCountRequired.get("count") != null) { + SdncBaseModel.addParameter("ipv6_floating_count", nullCheck(floatingIpCountRequired.get("count")), ipv6PropParams); + } + SdncBaseModel.addParameter("ipv6_address_plan_name", nullCheck(ipPropMap.get("ip_address_plan_name")), ipv6PropParams); + SdncBaseModel.addParameter("ipv6_vrf_name", nullCheck(ipPropMap.get("vrf_name")), ipv6PropParams); + SdncBaseModel.addParameter("subnet_role", nullCheck(ipPropMap.get("subnet_role")), ipv6PropParams); - // Insert ipv4PropParams into VFC_TO_NETWORK_ROLE_MAPPING - try { - LOG.info("Call insertToscaData for VFC_TO_NETWORK_ROLE_MAPPING where vfc_customization_uuid = " + getCustomizationUUID()); - addRequiredParameters(mappingParams); - insertToscaData(SdncBaseModel.getSql("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", getCustomizationUUID(), "", mappingParams), null); - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the VFC_TO_NETWORK_ROLE_MAPPING table"); - throw new IOException (e); - } - - } + ipv6PropParamsList.add(ipv6PropParams); + + } else { + LOG.error("SdncVFCModel: Additional V6 ip-requirements element encountered for this subnetRole: ", subnetRole); + } + + } else { + LOG.error("SdncVFCModel: invalid IP version encountered: ", ipVersion); + } + + } // for each ip-requirements element + + } // ipPropsList null check - // Insert IPV6 data - for (Map ipv6PropParams: ipv6PropParamsList) { - - Map mappingParams = new HashMap(); // final list for single insertion - addParamsToMap(commonParams, mappingParams); - addParamsToMap(ipv6PropParams, mappingParams); - - // Insert ipv6PropParams into VFC_TO_NETWORK_ROLE_MAPPING - try { - LOG.info("Call insertToscaData for VFC_TO_NETWORK_ROLE_MAPPING where vfc_customization_uuid = " + getCustomizationUUID()); - addRequiredParameters(mappingParams); - insertToscaData(SdncBaseModel.getSql("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", getCustomizationUUID(), "", mappingParams), null); - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the VFC_TO_NETWORK_ROLE_MAPPING table"); - throw new IOException (e); - } + // After all Common and IP Version specific parameters are extracted, insert IPV4 and IPV6 data separately + // Insert IPV4 data + for (Map ipv4PropParams: ipv4PropParamsList) { + + Map mappingParams = new HashMap(); // final list for single insertion + addParamsToMap(commonParams, mappingParams); + addParamsToMap(ipv4PropParams, mappingParams); + + // Insert ipv4PropParams into VFC_TO_NETWORK_ROLE_MAPPING + try { + LOG.info("Call insertToscaData for VFC_TO_NETWORK_ROLE_MAPPING where vfc_customization_uuid = " + getCustomizationUUID()); + addRequiredParameters(mappingParams); + insertToscaData(SdncBaseModel.getSql("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", getCustomizationUUID(), "", mappingParams), null); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the VFC_TO_NETWORK_ROLE_MAPPING table"); + throw new IOException (e); + } + + } - } - - } // Outer map loop - one per ExtCP - + // Insert IPV6 data + for (Map ipv6PropParams: ipv6PropParamsList) { + + Map mappingParams = new HashMap(); // final list for single insertion + addParamsToMap(commonParams, mappingParams); + addParamsToMap(ipv6PropParams, mappingParams); + + // Insert ipv6PropParams into VFC_TO_NETWORK_ROLE_MAPPING + try { + LOG.info("Call insertToscaData for VFC_TO_NETWORK_ROLE_MAPPING where vfc_customization_uuid = " + getCustomizationUUID()); + addRequiredParameters(mappingParams); + insertToscaData(SdncBaseModel.getSql("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", getCustomizationUUID(), "", mappingParams), null); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the VFC_TO_NETWORK_ROLE_MAPPING table"); + throw new IOException (e); + } + } + } + } } - + protected boolean ipPropParamsMapContainsSubnetRole (ArrayList> ipPropParamsList, String subnetRole) { boolean subnetRoleFound = false; @@ -281,70 +271,74 @@ public class SdncVFCModel extends SdncBaseModel { } } - public void insertVFCRelatedNetworkRoleData (String vfCustomizationUUID, NodeTemplate vfcNode) throws IOException { + public void insertVFCRelatedNetworkRoleData (String vfCustomizationUUID, IEntityDetails cvfcEntity) throws IOException { - // Get the CPs on this VFC - ASDC suggests getNodeTemplateChildren - List cpNodesList = sdcCsarHelper.getNodeTemplateChildren(vfcNode); + // Get the CPs on this VFC - using getEntity - String vfcCustomizationUuid = getCustomizationUUID(); + String vfcCustomizationUuid = getCustomizationUUID().replace("\"", ""); + // Get the CPs on this VFC - ASDC suggests getNodeTemplateChildren + //List cpNodesList = sdcCsarHelper.getNodeTemplateChildren(vfcNode); + EntityQuery entityQueryCP = EntityQuery.newBuilder(SdcTypes.CP).build(); + TopologyTemplateQuery topologyTemplateQueryVFC = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC).customizationUUID(vfcCustomizationUuid).build(); + List cpEntities = sdcCsarHelper.getEntity(entityQueryCP, topologyTemplateQueryVFC, true); + if (cpEntities == null || cpEntities.isEmpty()) { + LOG.info("insertVFCRelatedNetworkRoleData: Could not find the nested CVFCs for: " + vfcCustomizationUuid); + return; + } try { - cleanUpExistingToscaData("VFC_RELATED_NETWORK_ROLE", "vfc_customization_uuid", vfcCustomizationUuid); + cleanUpExistingToscaData("VFC_RELATED_NETWORK_ROLE", "vfc_customization_uuid", getCustomizationUUID()); } catch (IOException e) { LOG.error("Could not clean up Tosca CSAR data in the VFC_RELATED_NETWORK_ROLE table"); throw new IOException (e); } - for (NodeTemplate cpNode : cpNodesList){ - String networkRole = extractValue(cpNode, "network_role"); + for (IEntityDetails cpEntity : cpEntities){ + String networkRole = extractValue(cpEntity, "network_role"); Map relatedNetworkRoleParams = new HashMap(); - addParameter("vfc_customization_uuid", vfcCustomizationUuid, relatedNetworkRoleParams); + addParameter("vfc_customization_uuid", getCustomizationUUID(), relatedNetworkRoleParams); addParameter("vm_type", vmType, relatedNetworkRoleParams); addParameter("network_role", networkRole, relatedNetworkRoleParams); - - final Object relatedNetworksPropertyValue = cpNode.getPropertyValue("related_networks"); - - ArrayList> relatedNetworkList = (ArrayList)relatedNetworksPropertyValue; - if (relatedNetworkList != null) { - for (Map relatedNetworkValue : relatedNetworkList) { - LOG.debug("CP [" + cpNode.getName() + "], property [" + "related_network_role" + "] property value: " + relatedNetworkValue.get("related_network_role")); - String relatedNetworkRoleValue = relatedNetworkValue.get("related_network_role"); - - try { - // Table cleanup for VFC_RELATED_NETWORK_ROLE occurs per vfc - // If cp related_network_role, cp network_role and vm_type for this vfc already exist in VFC_RELATED_NETWORK_ROLE, - // don't attempt insertion - Map relatedNetworkRoleParamsCheck = new HashMap(); - addParamsToMap(relatedNetworkRoleParams, relatedNetworkRoleParamsCheck); - addParameter("related_network_role", relatedNetworkRoleValue, relatedNetworkRoleParamsCheck); - if (checkForExistingToscaData("VFC_RELATED_NETWORK_ROLE", relatedNetworkRoleParamsCheck) == false) { - LOG.info("Call insertToscaData for VFC_RELATED_NETWORK_ROLE where vfc_customization_uuid = " + vfcCustomizationUuid); - insertToscaData(buildSql("VFC_RELATED_NETWORK_ROLE", "related_network_role", "\"" + relatedNetworkRoleValue + "\"", model_yaml, relatedNetworkRoleParams), null); - } + + if (cpEntity.getProperties().containsKey("related_networks")) { + + Property relatedNetworksProperty = cpEntity.getProperties().get("related_networks"); + List relatedNetworkRoles = relatedNetworksProperty.getLeafPropertyValue("related_network_role"); + + for (String relatedNetworkRole : relatedNetworkRoles) { + LOG.debug("CP [" + cpEntity.getName() + "], property [" + "related_network_role" + "] property value: " + relatedNetworkRole); + + try { + // Table cleanup for VFC_RELATED_NETWORK_ROLE occurs per vfc + // If cp related_network_role, cp network_role and vm_type for this vfc already exist in VFC_RELATED_NETWORK_ROLE, + // don't attempt insertion + Map relatedNetworkRoleParamsCheck = new HashMap(); + addParamsToMap(relatedNetworkRoleParams, relatedNetworkRoleParamsCheck); + addParameter("related_network_role", relatedNetworkRole, relatedNetworkRoleParamsCheck); + if (checkForExistingToscaData("VFC_RELATED_NETWORK_ROLE", relatedNetworkRoleParamsCheck) == false) { + LOG.info("Call insertToscaData for VFC_RELATED_NETWORK_ROLE where vfc_customization_uuid = " + getCustomizationUUID()); + insertToscaData(buildSql("VFC_RELATED_NETWORK_ROLE", "related_network_role", "\"" + relatedNetworkRole + "\"", model_yaml, relatedNetworkRoleParams), null); + } - // Table cleanup for VNF_RELATED_NETWORK_ROLE occurs per vf (up one level) - // Insert same related_network_role data into VNF_RELATED_NETWORK_ROLE - Map vfRelatedNetworkRoleParamsCheck = new HashMap(); - addParameter("vnf_customization_uuid", vfCustomizationUUID, vfRelatedNetworkRoleParamsCheck); - addParameter("network_role", networkRole, vfRelatedNetworkRoleParamsCheck); - addParameter("related_network_role", relatedNetworkRoleValue, vfRelatedNetworkRoleParamsCheck); - if (checkForExistingToscaData("VNF_RELATED_NETWORK_ROLE", vfRelatedNetworkRoleParamsCheck) == false) { - vfRelatedNetworkRoleParamsCheck.remove("related_network_role"); - LOG.info("Call insertToscaData for VNF_RELATED_NETWORK_ROLE where vnf_customization_uuid = " + vfCustomizationUUID); - insertToscaData(buildSql("VNF_RELATED_NETWORK_ROLE", "related_network_role", "\"" + relatedNetworkRoleValue + "\"", model_yaml, vfRelatedNetworkRoleParamsCheck), null); - } + // Table cleanup for VNF_RELATED_NETWORK_ROLE occurs per vf (up one level) + // Insert same related_network_role data into VNF_RELATED_NETWORK_ROLE + Map vfRelatedNetworkRoleParamsCheck = new HashMap(); + addParameter("vnf_customization_uuid", vfCustomizationUUID, vfRelatedNetworkRoleParamsCheck); + addParameter("network_role", networkRole, vfRelatedNetworkRoleParamsCheck); + addParameter("related_network_role", relatedNetworkRole, vfRelatedNetworkRoleParamsCheck); + if (checkForExistingToscaData("VNF_RELATED_NETWORK_ROLE", vfRelatedNetworkRoleParamsCheck) == false) { + vfRelatedNetworkRoleParamsCheck.remove("related_network_role"); + LOG.info("Call insertToscaData for VNF_RELATED_NETWORK_ROLE where vnf_customization_uuid = " + vfCustomizationUUID); + insertToscaData(buildSql("VNF_RELATED_NETWORK_ROLE", "related_network_role", "\"" + relatedNetworkRole + "\"", model_yaml, vfRelatedNetworkRoleParamsCheck), null); + } - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the VFC_RELATED_NETWORK_ROLE table"); - throw new IOException (e); - } - } - } - else { - LOG.debug("CP [" + cpNode.getName() + "], property [" + "related_networks" + "] property value: " + null); - } + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the VFC_RELATED_NETWORK_ROLE table"); + throw new IOException (e); + } + } + } } - } public String getVmType() { diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java index 12eccf213..d6a09317a 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java @@ -22,7 +22,6 @@ package org.onap.ccsdk.sli.northbound.uebclient; import java.io.IOException; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -141,8 +140,8 @@ public class SdncVFModel extends SdncBaseModel { // Insert each VF Module group (entity) into VF_MODULE_MODEL if its name is prefixed with the VF name for (IEntityDetails vfModule : vfModules){ - // If this vfModule name is prefixed with the VF name of the VF bing processed, insert this VF Module in VF_MODULE_MODEL - String normailizedVfName = nodeTemplate.getName().toLowerCase().replace(" ", ""); + // If this vfModule name is prefixed with the VF name of the VF being processed, insert this VF Module in VF_MODULE_MODEL + String normailizedVfName = nodeTemplate.getName().toLowerCase().replace(" ", "").replace("-", ""); // need full set of normalization rules from ASDC if (!vfModule.getName().startsWith(normailizedVfName)) { continue; } @@ -169,7 +168,7 @@ public class SdncVFModel extends SdncBaseModel { .build(); List vfModulesNonCatalog = sdcCsarHelper.getEntity(entityQuery2, topologyTemplateQuery2, false); if (vfModulesNonCatalog == null || vfModulesNonCatalog.isEmpty()) { - LOG.info("insertVFModuleDataGetEntity2: Could not find the non-catelog VF Module for: " + vfModuleModel.getCustomizationUUID() + ". Unable to insert members into VF_MODULE_TO_VFC_MAPPING"); + LOG.info("insertVFModuleData: Could not find the non-catelog VF Module for: " + vfModuleModel.getCustomizationUUID() + ". Unable to insert members into VF_MODULE_TO_VFC_MAPPING"); continue; } @@ -184,10 +183,7 @@ public class SdncVFModel extends SdncBaseModel { String vfcVmType = extractValue (vfModuleMember, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG); // extracted as vm_type_tag String vfcVmCount = ""; if (vfModuleMember.getProperties().containsKey("service_template_filter")) { - Property property = vfModuleMember.getProperties().get("service_template_filter"); - if (property != null && property.getLeafPropertyValue("count") != null) { - vfcVmCount = property.getLeafPropertyValue("count").get(0); - } + vfcVmCount = extractIntegerValue (vfModuleMember.getProperties().get("service_template_filter"), "count"); } if (vfcVmCount.isEmpty()) { vfcVmCount = "0"; // vm_count can not be null @@ -210,7 +206,7 @@ public class SdncVFModel extends SdncBaseModel { .build(); List nestedCvfcs = sdcCsarHelper.getEntity(entityQuery3, topologyTemplateQuery3, true); // true allows for nested search if (nestedCvfcs == null || nestedCvfcs.isEmpty()) { - LOG.info("insertVFModuleDataGetEntity2: Could not find the nested CVFCs for: " + cvfcCustomizationUuid); + LOG.info("insertVFModuleData: Could not find the nested CVFCs for: " + cvfcCustomizationUuid); continue; } @@ -221,10 +217,7 @@ public class SdncVFModel extends SdncBaseModel { String nestedVfcVmType = extractValue (nestedCvfc, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG); // extracted as vm_type_tag String nestedVfcVmCount = ""; if (nestedCvfc.getProperties().containsKey("service_template_filter")) { - Property property = nestedCvfc.getProperties().get("service_template_filter"); - if (property != null && property.getLeafPropertyValue("count") != null) { - nestedVfcVmCount = property.getLeafPropertyValue("count").get(0); - } + nestedVfcVmCount = extractIntegerValue (nestedCvfc.getProperties().get("service_template_filter"), "count"); } if (nestedVfcVmCount.isEmpty()) { nestedVfcVmCount = "0"; // vm_count can not be null @@ -237,16 +230,11 @@ public class SdncVFModel extends SdncBaseModel { } catch (IOException e) { LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_TO_VFC_MAPPING table"); throw new IOException (e); - } - - } - - } - - } - - } - + } + } + } + } // For each VF Module member + } // For each VF Module } private void insertVFtoNetworkRoleMappingData () throws IOException { @@ -259,11 +247,16 @@ public class SdncVFModel extends SdncBaseModel { throw new IOException (e); } - // For this VF, insert VF_TO_NETWORK_ROLE_MAPPING data + // For this VF, insert VF_TO_NETWORK_ROLE_MAPPING data. network_role is a property on the CPs for this VF. + // Use getEntity to extract all the CPs on this VF EntityQuery entityQueryCP = EntityQuery.newBuilder(SdcTypes.CP).build(); TopologyTemplateQuery topologyTemplateQueryVF = TopologyTemplateQuery.newBuilder(SdcTypes.VF).customizationUUID(getCustomizationUUIDNoQuotes()).build(); List cpEntities = sdcCsarHelper.getEntity(entityQueryCP, topologyTemplateQueryVF, true); - + if (cpEntities == null || cpEntities.isEmpty()) { + LOG.info("insertVFtoNetworkRoleMappingData: Could not find CPs for VF: " + getCustomizationUUIDNoQuotes()); + return; + } + for (IEntityDetails entity: cpEntities ) { Map properties = entity.getProperties(); @@ -310,21 +303,35 @@ public class SdncVFModel extends SdncBaseModel { throw new IOException (e); }*/ - // For each VF, insert VFC_MODEL data - List vfcNodes = sdcCsarHelper.getVfcListByVf(getCustomizationUUIDNoQuotes()); - for (NodeTemplate vfcNode : vfcNodes){ + // Get any CVFCs under this VF (top-level and nested) + String vfCustomizationUid = customizationUUID; + EntityQuery entityQuery = EntityQuery.newBuilder(SdcTypes.CVFC) + .build(); + TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF) + .customizationUUID(vfCustomizationUid) // customization UUID of the VF if exists + .build(); + List cvfcEntities = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, true); // true allows for nested search + if (cvfcEntities == null || cvfcEntities.isEmpty()) { + LOG.info("insertVFCDataEntity: Could not find the CVFCs for: " + vfCustomizationUid); + } + + for (IEntityDetails cvfcEntity: cvfcEntities) { + // Insert this CVFC data into VFC_MODEL try { - SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, vfcNode, jdbcDataSource); + + SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, cvfcEntity, jdbcDataSource, config); vfcModel.insertVFCModelData(); - vfcModel.insertVFCtoNetworkRoleMappingData(vfcNode); - //vfcModel.insertVFCRelatedNetworkRoleData(getCustomizationUUID(), vfcNode); + vfcModel.insertVFCtoNetworkRoleMappingData(cvfcEntity); + //vfcModel.insertVFCRelatedNetworkRoleData(getCustomizationUUID(), cvfcEntity); + } catch (IOException e) { LOG.error("Could not insert Tosca CSAR VFC data"); throw new IOException (e); } } + } public void insertVFCInstanceGroupData () throws IOException { diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java index f9a03b3f3..ef815d027 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java @@ -25,17 +25,21 @@ package org.onap.ccsdk.sli.northbound.uebclient; import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; -import org.onap.sdc.toscaparser.api.Group; public class SdncVFModuleModel extends SdncBaseModel { public SdncVFModuleModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails vfModule, SdncVFModel vfNodeModel) { super(sdcCsarHelper, vfModule); - // override base implementation for setting customizationUUID because customizationUUID is called differently for Groups + // override base implementation for setting metadata because properties are called differently for Groups customizationUUID = extractValue (vfModule.getMetadata(), "vfModuleModelCustomizationUUID"); + invariantUUID = extractValue (vfModule.getMetadata(), "vfModuleModelInvariantUUID"); UUID = extractValue (vfModule.getMetadata(), "vfModuleModelUUID"); + version = extractValue (vfModule.getMetadata(), "vfModuleModelVersion"); addParameter("vf_customization_uuid", vfNodeModel.getCustomizationUUIDNoQuotes()); + addParameter("invariant_uuid", invariantUUID); + addParameter("uuid", UUID); + addParameter("version", version); // extract properties addParameter("vf_module_type", extractValue(vfModule, SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE)); diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java index ea6499cd3..734dee229 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java @@ -7,9 +7,10 @@ import java.io.IOException; import org.junit.Before; import org.junit.Test; - import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; - import org.onap.sdc.toscaparser.api.NodeTemplate; - import org.onap.ccsdk.sli.core.dblib.DBResourceManager; +import org.onap.sdc.tosca.parser.api.IEntityDetails; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; public class SdncARModelTest { @@ -19,8 +20,11 @@ import org.junit.Test; public void setUp() throws Exception { ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); NodeTemplate nodeTemplate = mock(NodeTemplate.class); + IEntityDetails mockEntityDetails = mock(IEntityDetails.class); DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); - testSdncARModel = new SdncARModel(mockCsarHelper,nodeTemplate,mockDBResourceManager); + SdncUebConfiguration mockSdncUebConfiguration = mock(SdncUebConfiguration.class); + + testSdncARModel = new SdncARModel(mockCsarHelper,mockEntityDetails,mockDBResourceManager,mockSdncUebConfiguration); assertNotNull(testSdncARModel); } diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java index 469312359..768eed86c 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java @@ -10,7 +10,8 @@ import java.util.HashMap; import java.util.ArrayList; import org.junit.Before; -import org.junit.Test; +import org.junit.Test; +import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.toscaparser.api.NodeTemplate; import org.onap.sdc.toscaparser.api.elements.Metadata; @@ -20,16 +21,20 @@ public class SdncVFCModelTest { SdncVFCModel testSdncVFCModel; NodeTemplate mockVFCNodeTemplate = null; + IEntityDetails mockEntityDetails = null; @Before public void setup() { ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); NodeTemplate mockNodeTemplate = mock(NodeTemplate.class); + mockEntityDetails = mock(IEntityDetails.class); mockVFCNodeTemplate = mock(NodeTemplate.class); Metadata mockMetadata = mock(Metadata.class); DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); + SdncUebConfiguration mockSdncUebConfiguration = mock(SdncUebConfiguration.class); when(mockNodeTemplate.getMetaData()).thenReturn(mockMetadata); + when(mockEntityDetails.getMetadata()).thenReturn(mockMetadata); when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "customizationUUID")).thenReturn("aaaa-bbbb-cccc-dddd"); when(mockCsarHelper.getNodeTemplatePropertyLeafValue(mockNodeTemplate, "nfc_naming_code")).thenReturn("test-nfc-naming-code"); @@ -50,9 +55,14 @@ public class SdncVFCModelTest { cpPropertiesMap.put("cp-node-1", propertiesMap); when(mockCsarHelper.getCpPropertiesFromVfcAsObject(mockVFCNodeTemplate)).thenReturn(cpPropertiesMap); - testSdncVFCModel = new SdncVFCModel(mockCsarHelper, mockNodeTemplate, mockDBResourceManager); - testSdncVFCModel.setVmType("Test-type"); - testSdncVFCModel.setVmCount("5"); + try { + testSdncVFCModel = new SdncVFCModel(mockCsarHelper, mockEntityDetails, mockDBResourceManager, mockSdncUebConfiguration); + testSdncVFCModel.setVmType("Test-type"); + testSdncVFCModel.setVmCount("5"); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } @@ -83,7 +93,7 @@ public class SdncVFCModelTest { @Test public void testInsertVFCtoNetworkRoleMappingData() { try { - testSdncVFCModel.insertVFCtoNetworkRoleMappingData(mockVFCNodeTemplate); + testSdncVFCModel.insertVFCtoNetworkRoleMappingData(mockEntityDetails); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); -- cgit 1.2.3-korg From 1ce6dbdae9d7a354ceb82e56b8d88b33753c6a5d Mon Sep 17 00:00:00 2001 From: "lalena.aria" Date: Fri, 28 Jun 2019 20:31:32 +0000 Subject: Logic change for insertion in to VF_MODULE_TO_VFC_MAPPING Changes made: Update SdncVFModel.insertVFModuleData to insert only CVFCs that contain VFC. Add check for empty and string null in SdncBaseModel extractValue methods. Issue-ID: CCSDK-1442 Change-Id: I058154e2e64e7123a13be5542021e7ca0187afe0 Signed-off-by: lalena.aria --- .../sli/northbound/uebclient/SdncBaseModel.java | 24 ++--- .../sli/northbound/uebclient/SdncVFModel.java | 105 +++++++++++++-------- 2 files changed, 80 insertions(+), 49 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index 245911250..0c05b3dc8 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -691,7 +691,7 @@ public class SdncBaseModel { } protected String extractValue (IEntityDetails entityDetails, String name) { - String value = null; + String value = ""; if (entityDetails.getProperties().containsKey(name)) { Property property = entityDetails.getProperties().get(name); if (property != null && property.getValue() != null) { @@ -699,7 +699,7 @@ public class SdncBaseModel { } } - if (value != null) { + if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { return value; } else { return ""; @@ -707,7 +707,7 @@ public class SdncBaseModel { } protected String extractValue (IEntityDetails entityDetails, String path, String name) { - String value = null; + String value = ""; if (entityDetails.getProperties().containsKey(path)) { Property property = entityDetails.getProperties().get(path); @@ -716,7 +716,7 @@ public class SdncBaseModel { } } - if (value != null) { + if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { return value; } else { return ""; @@ -724,13 +724,13 @@ public class SdncBaseModel { } protected String extractValue (Property property, String name) { - String value = null; + String value = ""; if (!property.getLeafPropertyValue(name).isEmpty()) { value = property.getLeafPropertyValue(name).get(0); } - if (value != null) { + if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { return value; } else { return ""; @@ -738,13 +738,13 @@ public class SdncBaseModel { } protected String extractBooleanValue (Property property, String name) { - String value = null; + String value = ""; if (!property.getLeafPropertyValue(name).isEmpty()) { value = property.getLeafPropertyValue(name).get(0); } - if (value != null) { + if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { return value.contains("true") ? "Y" : "N"; } else { return ""; @@ -752,13 +752,13 @@ public class SdncBaseModel { } protected String extractIntegerValue (Property property, String name) { - String value = null; + String value = ""; if (!property.getLeafPropertyValue(name).isEmpty()) { value = property.getLeafPropertyValue(name).get(0); } - if (value != null && !value.isEmpty() && !value.contains("null")) { + if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { return value; } else { return ""; @@ -873,7 +873,7 @@ public class SdncBaseModel { } } - if (value != null && !value.isEmpty()) { + if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { return value.contains("true") ? "Y" : "N"; } else { return ""; @@ -889,7 +889,7 @@ public class SdncBaseModel { } } - if (value != null && !value.isEmpty()) { + if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { return value.contains("true") ? "Y" : "N"; } else { return ""; diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java index d6a09317a..ac59eafa3 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java @@ -127,11 +127,18 @@ public class SdncVFModel extends SdncBaseModel { private void insertVFModuleData () throws IOException { + // Pre-Step: Get all CVFC with VFC inside use this list to filter before insert into VF_MODULE_TO_VFC_MAPPING + // Get all VFC in all CFVC in entire model (getEntity VFC, CVFC, true) and then check resulting entity has parent that matches member + // if parent of VFC has customizationUUID that matches customizationUUID of group member, then insert into VF_MODULE_TO_VFC_MAPPING + // then get count property + EntityQuery vfcEntityQuery = EntityQuery.newBuilder(SdcTypes.VFC).build(); + TopologyTemplateQuery cvfcTopologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC).build(); + List allVfcsInsideAllCvfcs = sdcCsarHelper.getEntity(vfcEntityQuery, cvfcTopologyTemplateQuery, true); + // Step 1: Get all the VF Module groups (entities) in this Service EntityQuery entityQuery = EntityQuery.newBuilder("org.openecomp.groups.VfModule").build(); String vfCustomizationUuid = getCustomizationUUIDNoQuotes(); - TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE) - .build(); + TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).build(); List vfModules = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false); if (vfModules == null) { return; @@ -172,23 +179,27 @@ public class SdncVFModel extends SdncBaseModel { continue; } - List vfModuleMembers = vfModulesNonCatalog.get(0).getMemberNodes(); - + List vfModuleMembers = vfModulesNonCatalog.get(0).getMemberNodes(); // does getMemberNodes give nested CFVCs? + // Find all members for each VF Module that are of type CVFC and insert it and any nested CFVCs into VF_MODULE_TO_VFC_MAPPING for (IEntityDetails vfModuleMember: vfModuleMembers) { - if (vfModuleMember.getMetadata().getValue("type").equals(SdcTypes.CVFC.getValue())) { - - // Insert this CVFC data into VF_MODULE_TO_VFC_MAPPING + if (vfModuleMember.getMetadata().getValue("type").equals(SdcTypes.CVFC.getValue())) { + String cvfcCustomizationUuid = extractValue(vfModuleMember.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); - String vfcVmType = extractValue (vfModuleMember, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG); // extracted as vm_type_tag - String vfcVmCount = ""; + + // Additional check to see if this CVFC has a VFC in it? We only are to map CVFCs with VFC in it. + if (cvfcContainsVfc(allVfcsInsideAllCvfcs, vfModuleMember) == true) { + + // Insert this CVFC data into VF_MODULE_TO_VFC_MAPPING + String vfcVmType = extractValue (vfModuleMember, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG); // extracted as vm_type_tag + String vfcVmCount = ""; if (vfModuleMember.getProperties().containsKey("service_template_filter")) { vfcVmCount = extractIntegerValue (vfModuleMember.getProperties().get("service_template_filter"), "count"); } if (vfcVmCount.isEmpty()) { vfcVmCount = "0"; // vm_count can not be null } - + try { LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING where vf_module_customization_uuid = " + vfModuleModel.getCustomizationUUID()); insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" + @@ -196,47 +207,67 @@ public class SdncVFModel extends SdncBaseModel { } catch (IOException e) { LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_TO_VFC_MAPPING table"); throw new IOException (e); - } + } + } // Step 3: Get any nested CVFCs under this CVFC - EntityQuery entityQuery3 = EntityQuery.newBuilder(SdcTypes.CVFC) - .build(); - TopologyTemplateQuery topologyTemplateQuery3 = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC) - .customizationUUID(cvfcCustomizationUuid) // customization UUID of the CVFC if exists - .build(); - List nestedCvfcs = sdcCsarHelper.getEntity(entityQuery3, topologyTemplateQuery3, true); // true allows for nested search - if (nestedCvfcs == null || nestedCvfcs.isEmpty()) { - LOG.info("insertVFModuleData: Could not find the nested CVFCs for: " + cvfcCustomizationUuid); - continue; - } + EntityQuery entityQuery3 = EntityQuery.newBuilder(SdcTypes.CVFC).build(); + TopologyTemplateQuery topologyTemplateQuery3 = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC) + .customizationUUID(cvfcCustomizationUuid) // customization UUID of the CVFC if exists + .build(); + List nestedCvfcs = sdcCsarHelper.getEntity(entityQuery3, topologyTemplateQuery3, true); // true allows for nested search + if (nestedCvfcs == null || nestedCvfcs.isEmpty()) { + LOG.info("insertVFModuleData: Could not find the nested CVFCs for: " + cvfcCustomizationUuid); + continue; + } - for (IEntityDetails nestedCvfc: nestedCvfcs) { + for (IEntityDetails nestedCvfc: nestedCvfcs) { + + // Additional check to see if this CVFC has a VFC in it? We only are to map CVFCs with VFC in it. + if (cvfcContainsVfc(allVfcsInsideAllCvfcs, nestedCvfc) == false) { + continue; // continue to next CVFC + } // Insert this CVFC data into VF_MODULE_TO_VFC_MAPPING - String nestedCvfcCustomizationUuid = extractValue(nestedCvfc.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); + String nestedCvfcCustomizationUuid = extractValue(nestedCvfc.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); String nestedVfcVmType = extractValue (nestedCvfc, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG); // extracted as vm_type_tag String nestedVfcVmCount = ""; - if (nestedCvfc.getProperties().containsKey("service_template_filter")) { - nestedVfcVmCount = extractIntegerValue (nestedCvfc.getProperties().get("service_template_filter"), "count"); - } - if (nestedVfcVmCount.isEmpty()) { - nestedVfcVmCount = "0"; // vm_count can not be null - } + if (nestedCvfc.getProperties().containsKey("service_template_filter")) { + nestedVfcVmCount = extractIntegerValue (nestedCvfc.getProperties().get("service_template_filter"), "count"); + } + if (nestedVfcVmCount.isEmpty()) { + nestedVfcVmCount = "0"; // vm_count can not be null + } - try { - LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING where vf_module_customization_uuid = " + vfModuleModel.getCustomizationUUID()); - insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" + - vfModuleModel.getCustomizationUUID() + ", \"" + nestedCvfcCustomizationUuid + "\", \"" + nestedVfcVmType + "\", \"" + nestedVfcVmCount + "\")", null); - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_TO_VFC_MAPPING table"); - throw new IOException (e); - } + try { + LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING where vf_module_customization_uuid = " + vfModuleModel.getCustomizationUUID()); + insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" + + vfModuleModel.getCustomizationUUID() + ", \"" + nestedCvfcCustomizationUuid + "\", \"" + nestedVfcVmType + "\", \"" + nestedVfcVmCount + "\")", null); + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_TO_VFC_MAPPING table"); + throw new IOException (e); } + } } } // For each VF Module member } // For each VF Module } + private boolean cvfcContainsVfc (List allVfcsInsideAllCvfcs, IEntityDetails cvfcEntity) { + boolean containsVfc = false; + + for (IEntityDetails vfcEntity: allVfcsInsideAllCvfcs) { + IEntityDetails vfcParentEntity = vfcEntity.getParent(); + String parentCustomizationUuid = extractValue (vfcParentEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); + String cvfcEntityCustomizationUuid = extractValue (cvfcEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); + if (parentCustomizationUuid == cvfcEntityCustomizationUuid) { + return true; + } + } + + return containsVfc; + } + private void insertVFtoNetworkRoleMappingData () throws IOException { // Cleanup existing VF_TO_NETWORK_ROLE_MAPPING for this VF -- cgit 1.2.3-korg From c84f0cf17122c65faad639c37028fd99e6594939 Mon Sep 17 00:00:00 2001 From: "lalena.aria" Date: Tue, 9 Jul 2019 15:34:57 +0000 Subject: Use getEntity to populate Policy-Related tables Changes made: Update SdncBaseModel policy data methods to use getEntity. Update SdncVFModel to call updated SdncBaseModel policy data methods. Minor changes in SdncServiceModel.java. Corresponding junit changes for getEntity migration. Issue-ID: CCSDK-1456 Change-Id: Idf000bb48896ca4c57d6d1659730e2aea7f49ec4 Signed-off-by: lalena.aria --- .../sli/northbound/uebclient/SdncBaseModel.java | 317 +++++++-------------- .../sli/northbound/uebclient/SdncServiceModel.java | 5 +- .../sli/northbound/uebclient/SdncUebCallback.java | 2 +- .../sli/northbound/uebclient/SdncVFModel.java | 16 +- .../northbound/uebclient/SdncServiceModelTest.java | 4 +- 5 files changed, 126 insertions(+), 218 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index 0c05b3dc8..27814c358 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -33,6 +33,9 @@ import javax.sql.rowset.CachedRowSet; import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.elements.queries.EntityQuery; +import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery; +import org.onap.sdc.tosca.parser.enums.SdcTypes; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; import org.onap.sdc.toscaparser.api.CapabilityAssignment; import org.onap.sdc.toscaparser.api.CapabilityAssignments; @@ -101,10 +104,11 @@ public class SdncBaseModel { this.config = config; } - public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata) { + public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata, DBResourceManager jdbcDataSource) { params = new HashMap(); this.sdcCsarHelper = sdcCsarHelper; + this.jdbcDataSource = jdbcDataSource; // extract service metadata invariantUUID = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID); @@ -294,240 +298,139 @@ public class SdncBaseModel { } } - protected void insertPolicyData (NodeTemplate nodeTemplate, NodeTemplate targetNode, String policyType) throws IOException { + protected void insertEntityPolicyData (String nodeTemplateCustomizationUuid, String nodeTemplateUuid, SdcTypes queryType, String targetCustomizationUuid, String targetUuid, String targetType, String policyType) throws IOException { + + EntityQuery policyEntityQuery = EntityQuery.newBuilder(policyType).build(); + TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(queryType).customizationUUID(nodeTemplateCustomizationUuid).build(); + List policyEntities = sdcCsarHelper.getEntity(policyEntityQuery, topologyTemplateQuery, false); + if (policyEntities == null || policyEntities.isEmpty()) { + LOG.info("insertPolicyData: Could not find policy data for: " + nodeTemplateCustomizationUuid); + return; + } - // Get External policies of the node - List policyList = sdcCsarHelper.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nodeTemplate, policyType); - //List policyList2 = sdcCsarHelper.getPoliciesOfTopologyTemplateByToscaPolicyType(policyType); // returns nothing - //List policyList3 = sdcCsarHelper.getPoliciesOfTargetByToscaPolicyType(nodeTemplate, policyType); // returns nothing - String resourceUuid = getUUID(); - for (Policy policy : policyList) { + for (IEntityDetails policyEntity : policyEntities) { // extract policy metadata - String policyUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("UUID", "").toString(); - String policyInvariantUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("invariantUUID", "").toString(); - String policyCustomizationUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("customizationUUID", "").toString(); - - // cleanup existing RESOURCE_POLICY data - Map cleanupParams = new HashMap(); - addParameter("resource_uuid", resourceUuid, cleanupParams); - addParameter("policy_uuid", policyUuid, cleanupParams); - addParameter("policy_invariant_uuid", policyInvariantUuid, cleanupParams); - - // insert into RESOURCE_POLICY - Map policyParams = new HashMap(); - addParameter("policy_uuid", policyUuid, policyParams); - addParameter("policy_customization_uuid", policyCustomizationUuid, policyParams); - addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams); - addParameter("policy_name", policy.getMetaDataObj().getAllProperties().getOrDefault(PARAM_NAME_KEY, "").toString(), policyParams); - addParameter(PARAM_VERSION_KEY, policy.getMetaDataObj().getAllProperties().getOrDefault(PARAM_VERSION_KEY, "").toString(), policyParams); - addParameter("policy_type", policy.getType(), policyParams); - - // extract properties - addParameter("property_type", extractValue(policy, PARAM_TYPE_KEY), policyParams); - addParameter("property_source", extractValue(policy, "source"), policyParams); - addParameter("property_name", extractValue(policy, PARAM_NAME_KEY), policyParams); - - // Insert into RESOURCE_POLICY and RESOURCE_POLICY_TO_TARGET_NODE_MAPPING - // RESOURCE_POLICY: resource_uuid (CR node UUID), uuid, customization_uuid, invariant_uuid, name, version, policy_type, - // property_type, property_source, property_name - - try { - - // insert into RESOURCE_POLICY - cleanupExistingToscaData("RESOURCE_POLICY", cleanupParams); - LOG.info("Call insertToscaData for RESOURCE_POLICY where resource_uuid = " + resourceUuid + " and policy_uuid = " + policyUuid); - insertToscaData(buildSql("RESOURCE_POLICY", "resource_uuid", resourceUuid, model_yaml, policyParams), null); - - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY table"); - throw new IOException (e); - } - - // insert RESOURCE_POLICY_TO_TARGET_NODE_MAPPING: policy_uuid, parent_uuid (CR node UUID), target_node_uuid, target_type, table_name - try { - Map mappingCleanupParams = new HashMap(); - addParameter("policy_uuid", policyUuid, mappingCleanupParams); - addParameter("parent_uuid", nodeTemplate.getMetaData().getValue("UUID"), mappingCleanupParams); - addParameter("target_node_uuid", targetNode.getMetaData().getValue("UUID"), mappingCleanupParams); - cleanupExistingToscaData("RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", mappingCleanupParams); - - Map mappingParams = new HashMap(); - addParameter("parent_uuid", nodeTemplate.getMetaData().getValue("UUID"), mappingParams); - addParameter("target_node_uuid", targetNode.getMetaData().getValue("UUID"), mappingParams); - addParameter("target_node_customization_uuid", targetNode.getMetaData().getValue("customizationUUID"), mappingParams); - addParameter("policy_customization_uuid", policyCustomizationUuid, mappingParams); - addParameter("target_type", targetNode.getMetaData().getValue(PARAM_TYPE_KEY), mappingParams); - LOG.info("Call insertToscaData for RESOURCE_POLICY_TO_TARGET_NODE_MAPPING where policy_uuid = " + policyUuid); - insertToscaData(buildSql("RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", "policy_uuid", "\"" + policyUuid + "\"", model_yaml, mappingParams), null); + String policyUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID); + String policyCustomizationUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY_TO_TARGET_NODE_MAPPING"); - throw new IOException (e); - } + insertResourcePolicyData(policyEntity, resourceUuid); + insertResourcePolicyToTargetNodeMappingData(policyUuid, nodeTemplateUuid, targetUuid, targetCustomizationUuid, policyCustomizationUuid, targetType); } } - public static void insertPolicyData (ISdcCsarHelper sdcCsarHelper, DBResourceManager jdbcDataSource, String resourceUuid, String parentUuid, String policyType) throws IOException { + public void insertEntityPolicyData (String resourceCustomizationUuid, String resourceUuid, String parentUuid, String policyType, SdcTypes queryType) throws IOException { - // Get External policies of the node - List policyList = sdcCsarHelper.getPoliciesOfTopologyTemplateByToscaPolicyType(policyType); + EntityQuery policyEntityQuery = EntityQuery.newBuilder(policyType).build(); + TopologyTemplateQuery topologyTemplateQuery; + if (queryType == SdcTypes.VF) { + topologyTemplateQuery = TopologyTemplateQuery.newBuilder(queryType).customizationUUID(resourceCustomizationUuid).build(); + } else { + topologyTemplateQuery = TopologyTemplateQuery.newBuilder(queryType).build(); + } - for (Policy policy : policyList) { + List policyEntities = sdcCsarHelper.getEntity(policyEntityQuery, topologyTemplateQuery, false); + if (policyEntities == null || policyEntities.isEmpty()) { + LOG.info("insertPolicyData: Could not find policy data for Service/VF: " + resourceUuid); + return; + } + + for (IEntityDetails policyEntity : policyEntities) { // extract policy metadata - String policyUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("UUID", "").toString(); - String policyInvariantUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("invariantUUID", "").toString(); - - // cleanup existing RESOURCE_POLICY data - Map cleanupParams = new HashMap(); - addParameter("resource_uuid", resourceUuid, cleanupParams); - addParameter("policy_uuid", policyUuid, cleanupParams); - addParameter("policy_invariant_uuid", policyInvariantUuid, cleanupParams); - - // insert into RESOURCE_POLICY - Map policyParams = new HashMap(); - addParameter("policy_uuid", policyUuid, policyParams); - addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams); - addParameter("policy_name", policy.getMetaDataObj().getAllProperties().getOrDefault("name", "").toString(), policyParams); - addParameter("version", policy.getMetaDataObj().getAllProperties().getOrDefault("version", "").toString(), policyParams); - addParameter("policy_type", policy.getType(), policyParams); - - // extract properties - addParameter("property_type", extractValueStatic(policy, "type"), policyParams); - addParameter("property_source", extractValueStatic(policy, "source"), policyParams); - addParameter("property_name", extractValueStatic(policy, "name"), policyParams); - - try { - - // insert into RESOURCE_POLICY - SdncBaseModel.cleanupExistingToscaData(jdbcDataSource, "RESOURCE_POLICY", cleanupParams); - LOG.info("Call insertToscaData for RESOURCE_POLICY where resource_uuid = " + resourceUuid); - insertToscaData(jdbcDataSource, getSql("RESOURCE_POLICY", "resource_uuid", resourceUuid, "", policyParams), null); + String policyUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID); + String policyCustomizationUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY table"); - throw new IOException (e); - } - - // insert into RESOURCE_POLICY_TO_TARGET_NODE_MAPPING - List policyTargetNameList = policy.getTargets(); - if (policyTargetNameList == null) { + insertResourcePolicyData(policyEntity, resourceUuid); + List targetEntities = policyEntity.getTargetEntities(); + if (targetEntities == null || targetEntities.isEmpty()) { + LOG.info("insertPolicyData: Could not find targetEntites for policy: " + policyUuid); continue; - } - - for (String targetName : policyTargetNameList) { - NodeTemplate targetNode = sdcCsarHelper.getNodeTemplateByName(targetName); - - // insert into RESOURCE_POLICY_TO_TARGET_NODE_MAPPING - try { - Map mappingCleanupParams = new HashMap(); - addParameter("policy_uuid", policyUuid, mappingCleanupParams); - addParameter("parent_uuid", parentUuid, mappingCleanupParams); - addParameter("target_node_uuid", targetNode.getMetaData().getValue("UUID"), mappingCleanupParams); - SdncBaseModel.cleanupExistingToscaData(jdbcDataSource, "RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", mappingCleanupParams); - - Map mappingParams = new HashMap(); - addParameter("parent_uuid", parentUuid, mappingParams); - addParameter("target_node_uuid", targetNode.getMetaData().getValue("UUID"), mappingParams); - addParameter("target_node_customization_uuid", targetNode.getMetaData().getValue("customizationUUID"), mappingParams); - addParameter("target_type", targetNode.getMetaData().getValue("type"), mappingParams); // type of the target node - LOG.info("Call insertToscaData for RESOURCE_POLICY_TO_TARGET_NODE_MAPPING where policy_uuid = " + policyUuid + " and target_node_uuid = " + targetNode.getMetaData().getValue("UUID")); - SdncBaseModel.insertToscaData(jdbcDataSource, getSql("RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", "policy_uuid", "\"" + policyUuid + "\"", "", mappingParams), null); - - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY_TO_TARGET_NODE_MAPPING"); - throw new IOException (e); - } + } + for (IEntityDetails targetEntity : targetEntities) { + + String targetUuid = extractValue(targetEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID); + String targetCustomizationUuid = extractValue(targetEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); + String targetType = extractValue(targetEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_TYPE); + insertResourcePolicyToTargetNodeMappingData(policyUuid, parentUuid, targetUuid, targetCustomizationUuid, policyCustomizationUuid, targetType); } } } - protected void insertPolicyData (NodeTemplate nodeTemplate, DBResourceManager jdbcDataSource, String parentUuid, String policyType) throws IOException { + protected void insertResourcePolicyData (IEntityDetails policyEntity, String resourceUuid) throws IOException { - // Get External policies of the node - List policyList = sdcCsarHelper.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nodeTemplate, policyType); - String resourceUuid = "\"" + extractValue (nodeTemplate.getMetaData(), SdcPropertyNames.PROPERTY_NAME_UUID) + "\""; + // extract policy metadata + String policyUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID); + String policyInvariantUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID); + String policyCustomizationUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); - for (Policy policy : policyList) { - - // extract policy metadata - String policyUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("UUID", "").toString(); - String policyInvariantUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("invariantUUID", "").toString(); - - // cleanup existing RESOURCE_POLICY data - Map cleanupParams = new HashMap(); - addParameter("resource_uuid", resourceUuid, cleanupParams); - addParameter("policy_uuid", policyUuid, cleanupParams); - addParameter("policy_invariant_uuid", policyInvariantUuid, cleanupParams); + // cleanup existing RESOURCE_POLICY data + Map cleanupParams = new HashMap(); + addParameter("resource_uuid", resourceUuid, cleanupParams); + addParameter("policy_uuid", policyUuid, cleanupParams); + addParameter("policy_invariant_uuid", policyInvariantUuid, cleanupParams); + + // insert into RESOURCE_POLICY + Map policyParams = new HashMap(); + addParameter("policy_uuid", policyUuid, policyParams); + addParameter("policy_customization_uuid", policyCustomizationUuid, policyParams); + addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams); + addParameter("policy_name", extractValue(policyEntity.getMetadata(), PARAM_NAME_KEY), policyParams); + addParameter(PARAM_VERSION_KEY, extractValue(policyEntity.getMetadata(), PARAM_VERSION_KEY), policyParams); + addParameter("policy_type", policyEntity.getToscaType(), policyParams); + + // extract properties + addParameter("property_type", extractValue(policyEntity, PARAM_TYPE_KEY), policyParams); + addParameter("property_source", extractValue(policyEntity, "source"), policyParams); + addParameter("property_name", extractValue(policyEntity, PARAM_NAME_KEY), policyParams); + + // Insert into RESOURCE_POLICY and RESOURCE_POLICY_TO_TARGET_NODE_MAPPING + // RESOURCE_POLICY: resource_uuid (CR node UUID), uuid, customization_uuid, invariant_uuid, name, version, policy_type, + // property_type, property_source, property_name + + try { // insert into RESOURCE_POLICY - Map policyParams = new HashMap(); - addParameter("policy_uuid", policyUuid, policyParams); - addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams); - String policyName = policy.getMetaDataObj().getAllProperties().getOrDefault(PARAM_NAME_KEY, "").toString(); - addParameter("policy_name", policyName, policyParams); - addParameter(PARAM_VERSION_KEY, policy.getMetaDataObj().getAllProperties().getOrDefault(PARAM_VERSION_KEY, "").toString(), policyParams); - addParameter("policy_type", policy.getType(), policyParams); - - // extract properties - addParameter("property_type", extractValue(policy, PARAM_TYPE_KEY), policyParams); - addParameter("property_source", extractValue(policy, "source"), policyParams); - addParameter("property_name", extractValue(policy, PARAM_NAME_KEY), policyParams); - - try { - - // insert into RESOURCE_POLICY - cleanupExistingToscaData(jdbcDataSource, "RESOURCE_POLICY", cleanupParams); - LOG.info("Call insertToscaData for RESOURCE_POLICY where resource_uuid = " + resourceUuid); - insertToscaData(jdbcDataSource, getSql("RESOURCE_POLICY", "resource_uuid", resourceUuid, "", policyParams), null); + cleanupExistingToscaData("RESOURCE_POLICY", cleanupParams); + LOG.info("Call insertToscaData for RESOURCE_POLICY where resource_uuid = " + resourceUuid + " and policy_uuid = " + "\"" + policyUuid + "\"" ); + insertToscaData(buildSql("RESOURCE_POLICY", "resource_uuid", resourceUuid, model_yaml, policyParams), null); - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY table"); - throw new IOException (e); - } - - // insert into RESOURCE_POLICY_TO_TARGET_NODE_MAPPING - List targetNodeList = sdcCsarHelper.getPolicyTargetsFromOrigin(nodeTemplate, policyName); - if (targetNodeList == null) { - continue; - } - - for (NodeTemplate targetNode : targetNodeList) { - //NodeTemplate targetNode = sdcCsarHelper.getNodeTemplateByName(targetName); - if (targetNode == null) { - LOG.error("Target node for policy " + policyName + " is NULL. Can't insert into RESOURCE_POLICY_TO_TARGET_NODE_MAPPING"); - continue; - } - - // insert into RESOURCE_POLICY_TO_TARGET_NODE_MAPPING - try { - Map mappingCleanupParams = new HashMap(); - addParameter("policy_uuid", policyUuid, mappingCleanupParams); - addParameter("parent_uuid", parentUuid, mappingCleanupParams); - addParameter("target_node_uuid", targetNode.getMetaData().getValue("UUID"), mappingCleanupParams); - SdncBaseModel.cleanupExistingToscaData(jdbcDataSource, "RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", mappingCleanupParams); - - Map mappingParams = new HashMap(); - addParameter("parent_uuid", parentUuid, mappingParams); - addParameter("target_node_uuid", targetNode.getMetaData().getValue("UUID"), mappingParams); - addParameter("target_node_customization_uuid", targetNode.getMetaData().getValue("customizationUUID"), mappingParams); - addParameter("target_type", targetNode.getMetaData().getValue(PARAM_TYPE_KEY), mappingParams); // type of the target node - LOG.info("Call insertToscaData for RESOURCE_POLICY_TO_TARGET_NODE_MAPPING where policy_uuid = " + policyUuid + " and target_node_uuid = " + targetNode.getMetaData().getValue("UUID")); - SdncBaseModel.insertToscaData(jdbcDataSource, getSql("RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", "policy_uuid", "\"" + policyUuid + "\"", "", mappingParams), null); - - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY_TO_TARGET_NODE_MAPPING table"); - throw new IOException (e); - } - - } + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY table"); + throw new IOException (e); } + } + protected void insertResourcePolicyToTargetNodeMappingData(String policyUuid, String parentUuid, String targetUuid, String targetCustomizationUuid, String policyCustomizationUuid, String targetType) throws IOException { + + // insert RESOURCE_POLICY_TO_TARGET_NODE_MAPPING: policy_uuid, parent_uuid (CR node UUID), target_node_uuid, target_type, table_name + try { + Map mappingCleanupParams = new HashMap(); + addParameter("policy_uuid", policyUuid, mappingCleanupParams); + addParameter("parent_uuid", parentUuid, mappingCleanupParams); + addParameter("target_node_uuid", targetUuid, mappingCleanupParams); + cleanupExistingToscaData("RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", mappingCleanupParams); + + Map mappingParams = new HashMap(); + addParameter("parent_uuid", parentUuid, mappingParams); + addParameter("target_node_uuid", targetUuid, mappingParams); + addParameter("target_node_customization_uuid", targetCustomizationUuid, mappingParams); + addParameter("policy_customization_uuid", policyCustomizationUuid, mappingParams); + addParameter("target_type", targetType, mappingParams); + LOG.info("Call insertToscaData for RESOURCE_POLICY_TO_TARGET_NODE_MAPPING where policy_uuid = " + "\"" + policyUuid + "\" and parent_uuid = " + "\"" + parentUuid + "\" and target_node_uuid = " + "\"" + targetUuid + "\""); + insertToscaData(buildSql("RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", "policy_uuid", "\"" + policyUuid + "\"", model_yaml, mappingParams), null); + + } catch (IOException e) { + LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY_TO_TARGET_NODE_MAPPING"); + throw new IOException (e); + } + } + + protected void insertNodeCapabilitiesData (CapabilityAssignments capabilities) throws IOException { // Process the capabilities on the node template diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java index 4bed2fe76..52e38624a 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java @@ -21,6 +21,7 @@ package org.onap.ccsdk.sli.northbound.uebclient; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; import org.onap.sdc.toscaparser.api.elements.Metadata; @@ -35,9 +36,9 @@ public class SdncServiceModel extends SdncBaseModel { private String serviceInstanceNamePrefix = null; private String filename = null; - public SdncServiceModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata) { + public SdncServiceModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata, DBResourceManager jdbcDataSource) { - super(sdcCsarHelper, metadata); + super(sdcCsarHelper, metadata, jdbcDataSource); UUID = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_UUID); diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index 95672ea5f..d39622621 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -689,7 +689,7 @@ public class SdncUebCallback implements INotificationCallback { // Ingest Service Data - 1707 Metadata serviceMetadata = sdcCsarHelper.getServiceMetadata(); - SdncServiceModel serviceModel = new SdncServiceModel(sdcCsarHelper, serviceMetadata); + SdncServiceModel serviceModel = new SdncServiceModel(sdcCsarHelper, serviceMetadata, jdbcDataSource); serviceModel.setFilename(spoolFile.toString().substring(spoolFile.toString().lastIndexOf("/")+1)); // will be csar file name serviceModel.setServiceInstanceNamePrefix(SdncBaseModel.extractSubstitutionMappingTypeName(sdcCsarHelper).substring(SdncBaseModel.extractSubstitutionMappingTypeName(sdcCsarHelper).lastIndexOf(".")+1)); diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java index ac59eafa3..750cb72a3 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java @@ -385,7 +385,9 @@ public class SdncVFModel extends SdncBaseModel { List targetNodeList = group.getMemberNodes(); for (NodeTemplate targetNode : targetNodeList) { - String targetNodeUuid = targetNode.getMetaData().getValue("UUID"); + String targetNodeUuid = extractValue(targetNode.getMetaData(), SdcPropertyNames.PROPERTY_NAME_UUID); + String targetNodeCustomizationUuid = extractValue(targetNode.getMetaData(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); + String targetNodeType = extractValue(targetNode.getMetaData(), SdcPropertyNames.PROPERTY_NAME_TYPE); // insert RESOURCE_GROUP_TO_TARGET_NODE_MAPPING try { @@ -398,10 +400,9 @@ public class SdncVFModel extends SdncBaseModel { Map mappingParams = new HashMap(); addParameter("parent_uuid", getUUID(), mappingParams); addParameter("target_node_uuid", targetNodeUuid, mappingParams); - String targetType = extractValue(targetNode.getMetaData(), "type"); - addParameter("target_type", targetType, mappingParams); + addParameter("target_type", targetNodeType, mappingParams); String tableName = ""; - switch (targetType) { + switch (targetNodeType) { case "CVFC": tableName = "VFC_MODEL"; break; @@ -417,8 +418,9 @@ public class SdncVFModel extends SdncBaseModel { throw new IOException (e); } - // For each target node, get External policies - insertPolicyData(nodeTemplate, targetNode, "org.openecomp.policies.External"); + // For each target node, get External policies + SdcTypes queryType = SdcTypes.valueOf(extractValue(nodeTemplate.getMetaData(), SdcPropertyNames.PROPERTY_NAME_TYPE)); + insertEntityPolicyData(getCustomizationUUIDNoQuotes(), getUUID().replace("\"", ""), queryType, targetNodeCustomizationUuid, targetNodeUuid, targetNodeType, "org.openecomp.policies.External"); // AFTER getEntity } } } @@ -426,7 +428,7 @@ public class SdncVFModel extends SdncBaseModel { private void insertVFPolicyData() throws IOException { // For each VF node, ingest External Policy data - insertPolicyData (nodeTemplate, jdbcDataSource, serviceUUID, "org.openecomp.policies.External"); + insertEntityPolicyData (getCustomizationUUIDNoQuotes(), getUUID(), serviceUUID.replace("\"", ""), "org.openecomp.policies.External", SdcTypes.VF); } public String getVendor() { diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModelTest.java index 95f5a75ec..af17e2291 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModelTest.java @@ -7,6 +7,7 @@ import java.io.IOException; import org.junit.Before; import org.junit.Test; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.toscaparser.api.elements.Metadata; @@ -17,13 +18,14 @@ import org.onap.sdc.toscaparser.api.elements.Metadata; @Before public void setUp() throws Exception { ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); + DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); Metadata mockMetadata = mock(Metadata.class); when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "UUID")).thenReturn("aaaa-bbbb-cccc-dddd"); when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "invariantUUID")).thenReturn("bbbb-cccc-dddd-eeee"); when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "namingPolicy")).thenReturn("test-naming-policy"); - testSdncServiceModel = new SdncServiceModel(mockCsarHelper,mockMetadata); + testSdncServiceModel = new SdncServiceModel(mockCsarHelper,mockMetadata,mockDBResourceManager); assertNotNull(testSdncServiceModel); } -- cgit 1.2.3-korg From 9f93347d67850bc68072216a3dc8448c83c0d214 Mon Sep 17 00:00:00 2001 From: "lalena.aria" Date: Mon, 22 Jul 2019 14:08:24 +0000 Subject: Use getEntity to populate Group-Related tables Changes made: Convert SdncGroupModel to entity. Convert SdncVFModel.insertVFCInstanceGroupData to entity. Corresponding SdncBaseModel changes for getEntity migration. Corresponding junit changes for getEntity migration. Issue-ID: CCSDK-1501 Change-Id: I8a8938dc1b1e7bf37212799277aef60ffff5edb1 Signed-off-by: lalena.aria --- .../sli/northbound/uebclient/SdncBaseModel.java | 86 +++++++++++++++++++--- .../sli/northbound/uebclient/SdncGroupModel.java | 18 +++-- .../sli/northbound/uebclient/SdncVFModel.java | 26 ++++--- .../northbound/uebclient/SdncGroupModelTest.java | 3 +- 4 files changed, 108 insertions(+), 25 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index 27814c358..84918ab10 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -250,12 +250,18 @@ public class SdncBaseModel { protected void insertGroupData (NodeTemplate nodeTemplate, NodeTemplate targetNode, String groupType) throws IOException { - // Get the NetworkCollection groups of the node - Map groupParams = new HashMap(); - List groupList = sdcCsarHelper.getGroupsOfOriginOfNodeTemplateByToscaGroupType(nodeTemplate, groupType); - //List groupList2 = sdcCsarHelper.getGroupsOfTopologyTemplateByToscaGroupType(groupType); // returns nothing + // Get the Groups on a node - Convert to use getEntity in 19.08 + EntityQuery entityQuery = EntityQuery.newBuilder(groupType).build(); + String customizationUuid = getCustomizationUUIDNoQuotes(); + SdcTypes nodeTemplateSdcType = SdcTypes.valueOf(extractValue(nodeTemplate.getMetaData(), SdcPropertyNames.PROPERTY_NAME_TYPE)); + TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(nodeTemplateSdcType) + .customizationUUID(customizationUuid).build(); + List groupList = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false); + if (groupList == null) { + return; + } - for (Group group : groupList) { + for (IEntityDetails group : groupList){ // Insert into RESOURCE_GROUP/ATTRIBUTE_VALUE_PAIR and RESOURCE_GROUP_TO_TARGET_NODE_MAPPING // RESOURCE_GROUP (group metadata): resource_uuid (CR node UUID), uuid, customization_uuid, invariant_uuid, name, version @@ -269,13 +275,13 @@ public class SdncBaseModel { try { Map mappingCleanupParams = new HashMap(); addParameter("group_uuid", groupModel.getUUID(), mappingCleanupParams); - addParameter("parent_uuid", extractValue(nodeTemplate.getMetaData(), "UUID"), mappingCleanupParams); - addParameter("target_node_uuid", extractValue(targetNode.getMetaData(), "UUID"), mappingCleanupParams); + addParameter("parent_uuid", extractValue(nodeTemplate.getMetaData(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingCleanupParams); + addParameter("target_node_uuid", extractValue(targetNode.getMetaData(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingCleanupParams); cleanupExistingToscaData("RESOURCE_GROUP_TO_TARGET_NODE_MAPPING", mappingCleanupParams); Map mappingParams = new HashMap(); - addParameter("parent_uuid", extractValue(nodeTemplate.getMetaData(), "UUID"), mappingParams); - addParameter("target_node_uuid", extractValue(targetNode.getMetaData(), "UUID"), mappingParams); + addParameter("parent_uuid", extractValue(nodeTemplate.getMetaData(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingParams); + addParameter("target_node_uuid", extractValue(targetNode.getMetaData(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingParams); String targetType = extractValue(targetNode.getMetaData(), PARAM_TYPE_KEY); addParameter("target_type", targetType, mappingParams); String tableName = ""; @@ -495,6 +501,68 @@ public class SdncBaseModel { } } + protected void insertNodeCapabilitiesEntityData (Map capabilities) throws IOException { + + // Process the capabilities + for (Map.Entry entry : capabilities.entrySet()) { + CapabilityAssignment capability = entry.getValue(); + + // Insert into NODE_CAPABILITY: + // capability_id (generated) + // capability_provider_uuid - UUID of this node + // capability_provider_customization_uuid - customization UUID of this node + // capability_name - capability.getName() + // capability_type - ? + + // Check capability name against relevant capabilities + boolean capabilityIsRelevant = false; + /*List relevantCapabilities = config.getRelevantCapabilityNames(); + for (String relevantCapabilityName : relevantCapabilities ) { + + if (capability.getName().toLowerCase().contains(relevantCapabilityName.toLowerCase())) { + capabilityIsRelevant = true; + } + }*/ + + if (capabilityIsRelevant == false){ + continue; + } + + String capabilityProviderUuid = getUUID(); + + Map cleanupParams = new HashMap(); + addParameter("capability_provider_uuid", capabilityProviderUuid, cleanupParams); // node customization UUID + addParameter("capability_provider_customization_uuid", getCustomizationUUIDNoQuotes(), cleanupParams); // node customization UUID + addParameter("capability_name", capability.getName(), cleanupParams); + + Map nodeCapabilityParams = new HashMap(); + addParameter("capability_provider_customization_uuid", getCustomizationUUIDNoQuotes(), nodeCapabilityParams); // node customization UUID + addParameter("capability_name", capability.getName(), nodeCapabilityParams); + addParameter("capability_type", extractValue(capability, PARAM_TYPE_KEY), nodeCapabilityParams); + + // Insert NODE_CAPABILITY data for each capability + String capabilityId = ""; + try { + + cleanupExistingToscaData("NODE_CAPABILITY", cleanupParams); // will also delete NODE_CAPABILITY_PROPERTY with same capability_id + LOG.info("Call insertToscaData for NODE_CAPABILITY where capability_provider_uuid = " + capabilityProviderUuid + " and capability_name = " + capability.getName()); + insertToscaData(buildSql("NODE_CAPABILITY", "capability_provider_uuid", capabilityProviderUuid, model_yaml, nodeCapabilityParams), null); + + // Get capabilityId for capability just inserted + CachedRowSet rowData = getToscaData("NODE_CAPABILITY", nodeCapabilityParams); + rowData.first(); + int capabilityIdint = rowData.getInt("capability_id"); + capabilityId = capabilityId.valueOf(capabilityIdint); + + } catch (IOException | SQLException e) { + LOG.error("Could not insert Tosca CSAR data into the NODE_CAPABILITY table"); + throw new IOException (e); + } + + insertNodeCapabilityPropertyData (capability, capabilityId); + } + } + protected void insertNodeCapabilityPropertyData(CapabilityAssignment capability, String capabilityId) throws IOException { // Insert property name / value into NODE_CAPABILITY_PROPERTY diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java index dedaa9a2a..268590feb 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java @@ -25,6 +25,7 @@ package org.onap.ccsdk.sli.northbound.uebclient; import java.io.IOException; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; +import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.toscaparser.api.Group; import org.onap.sdc.toscaparser.api.NodeTemplate; @@ -39,28 +40,33 @@ public class SdncGroupModel extends SdncBaseModel { private static final String groupType = "group_type"; - public SdncGroupModel(ISdcCsarHelper sdcCsarHelper, Group group, NodeTemplate nodeTemplate, SdncUebConfiguration config, DBResourceManager jdbcDataSource) throws IOException { + public SdncGroupModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails group, NodeTemplate nodeTemplate, SdncUebConfiguration config, DBResourceManager jdbcDataSource) throws IOException { super(sdcCsarHelper, group); // Metadata for Resource group is not extracted in base class due to inconsistency in TOSCA model Group object Metadata metadata = group.getMetadata(); + params.remove("invariant_uuid"); // remove invariant_uuid which is added by base class, it does not apply for groups invariantUUID = extractValue (metadata, "invariantUUID"); addParameter("group_invariant_uuid", invariantUUID); + params.remove("uuid"); // remove uuid which is added by base class, it does not apply for groups UUID = extractValue (metadata, "UUID"); addParameter("group_uuid", UUID); addParameter("group_name", extractValue (metadata, "name")); - addParameter(groupType, group.getType()); + addParameter(groupType, group.getToscaType()); addParameter("version", extractValue (metadata, "version")); // extract properties addParameter("vfc_parent_port_role", extractValue(group, "vfc_parent_port_role"), attributeValueParams); addParameter("subinterface_role", extractValue(group, "subinterface_role"), attributeValueParams); - // relevant complex group properties are extracted and inserted into ATTRIBUTE_VALUE_PAIR - addParameter(extractGetInputName (group, groupType), extractGetInputValue(group, nodeTemplate, groupType), attributeValueParams); - addParameter(extractGetInputName (group, "group_role"), extractGetInputValue(group, nodeTemplate, "group_role"), attributeValueParams); - addParameter(extractGetInputName (group, "group_function"), extractGetInputValue(group, nodeTemplate, "group_function"), attributeValueParams); + // relevant complex group properties are extracted and inserted into ATTRIBUTE_VALUE_PAIR + String extractedGroupType = extractValue (group, groupType); + String extractedGroupRole = extractValue (group, "group_role"); + String extractedGroupFunction = extractValue (group, "group_function"); + addParameter(groupType, extractedGroupType, attributeValueParams); + addParameter("group_role", extractedGroupRole, attributeValueParams); + addParameter("group_function", extractedGroupFunction, attributeValueParams); } public void insertGroupData(NodeTemplate resourceNodeTemplate) throws IOException { diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java index 750cb72a3..2b2d078f7 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java @@ -370,24 +370,32 @@ public class SdncVFModel extends SdncBaseModel { // Insert Group data in RESOURCE_GROUP // Store group capabilities and capability properties in NODE_CAPABILITY and NODE_CAPABILITY_PROPERTY table - // For each VF, insert CFVC data - 1806 - List vfcInstanceGroupListForVf = sdcCsarHelper.getGroupsOfOriginOfNodeTemplateByToscaGroupType(nodeTemplate, "org.openecomp.groups.VfcInstanceGroup"); - for (Group group : vfcInstanceGroupListForVf){ + // For each VF, insert VFC Instance Group data (convert to use getEntity in 19.08) + EntityQuery entityQuery = EntityQuery.newBuilder("org.openecomp.groups.VfcInstanceGroup").build(); + String vfCustomizationUuid = getCustomizationUUIDNoQuotes(); + TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF) + .customizationUUID(vfCustomizationUuid).build(); + List vfcInstanceGroupListForVf = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false); + if (vfcInstanceGroupListForVf == null) { + return; + } + + for (IEntityDetails group : vfcInstanceGroupListForVf){ SdncGroupModel groupModel = new SdncGroupModel (sdcCsarHelper, group, nodeTemplate, config, jdbcDataSource); groupModel.insertGroupData(nodeTemplate); // For each group, populate NODE_CAPABILITY/NODE_CAPABILITY_PROPERTY - insertNodeCapabilitiesData(group.getCapabilities()); + insertNodeCapabilitiesEntityData(group.getCapabilities()); // Store relationship between VfcInstanceGroup and node-type=VFC in RESOURCE_GROUP_TO_TARGET_NODE_MAPPING table // target is each VFC in targets section of group - List targetNodeList = group.getMemberNodes(); - for (NodeTemplate targetNode : targetNodeList) { + List targetNodeList = group.getMemberNodes(); + for (IEntityDetails targetNode : targetNodeList) { - String targetNodeUuid = extractValue(targetNode.getMetaData(), SdcPropertyNames.PROPERTY_NAME_UUID); - String targetNodeCustomizationUuid = extractValue(targetNode.getMetaData(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); - String targetNodeType = extractValue(targetNode.getMetaData(), SdcPropertyNames.PROPERTY_NAME_TYPE); + String targetNodeUuid = extractValue(targetNode.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID); + String targetNodeCustomizationUuid = extractValue(targetNode.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); + String targetNodeType = extractValue(targetNode.getMetadata(), SdcPropertyNames.PROPERTY_NAME_TYPE); // insert RESOURCE_GROUP_TO_TARGET_NODE_MAPPING try { diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModelTest.java index 0c6030b44..8bf3c9145 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModelTest.java @@ -6,6 +6,7 @@ import static org.mockito.Mockito.*; import java.io.IOException; import org.junit.Test; +import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.toscaparser.api.NodeTemplate; import org.onap.sdc.toscaparser.api.Group; @@ -17,7 +18,7 @@ import org.onap.ccsdk.sli.core.dblib.DBResourceManager; public void testSdncGroupModelConstructor() { ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); NodeTemplate nodeTemplate = mock(NodeTemplate.class); - Group group = mock(Group.class); + IEntityDetails group = mock(IEntityDetails.class); DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); SdncUebConfiguration mockSdncUebConfiguration = mock(SdncUebConfiguration.class); SdncGroupModel testSdncGroupModel = null; -- cgit 1.2.3-korg From 3f336cecddbc7adf45489e0d4a0b1b19deeee1ef Mon Sep 17 00:00:00 2001 From: "lalena.aria" Date: Wed, 7 Aug 2019 19:59:04 +0000 Subject: Use getEntity to populate Complex Resource-Related tables Changes made: Clean up in SdncBaseModel for unused methods. Fixes in SdncGroupModel. Convert SdncNodeModel to entity. Corrected logging in SdncVFCModel. Corresponding Group-related and logging fixes in SdncVFModel. Corresponding SdncBaseModel changes for getEntity migration. Corresponding junit changes for getEntity migration. Issue-ID: CCSDK-1578 Change-Id: Ic7f7ec38325aeddcad2d86c8f8425ec825512714 Signed-off-by: lalena.aria --- artifacts/pom.xml | 4 +- asdcApi/features/ccsdk-asdcApi/pom.xml | 4 +- asdcApi/features/features-asdcApi/pom.xml | 4 +- asdcApi/features/pom.xml | 4 +- asdcApi/installer/pom.xml | 4 +- asdcApi/model/pom.xml | 4 +- asdcApi/pom.xml | 4 +- asdcApi/provider/pom.xml | 4 +- .../features/ccsdk-daexim-offsite-backup/pom.xml | 4 +- .../features-daexim-offsite-backup/pom.xml | 4 +- daexim-offsite-backup/features/pom.xml | 4 +- daexim-offsite-backup/installer/pom.xml | 4 +- daexim-offsite-backup/model/pom.xml | 4 +- daexim-offsite-backup/pom.xml | 4 +- daexim-offsite-backup/provider/pom.xml | 4 +- dataChange/features/ccsdk-dataChange/pom.xml | 4 +- dataChange/features/features-dataChange/pom.xml | 4 +- dataChange/features/pom.xml | 4 +- dataChange/installer/pom.xml | 4 +- dataChange/model/pom.xml | 4 +- dataChange/pom.xml | 4 +- dataChange/provider/pom.xml | 4 +- dmaap-listener/pom.xml | 4 +- features/ccsdk-sli-northbound-all/pom.xml | 4 +- features/features-sli-northbound/pom.xml | 4 +- features/installer/pom.xml | 4 +- features/pom.xml | 4 +- lcm/features/ccsdk-lcm/pom.xml | 4 +- lcm/features/features-lcm/pom.xml | 4 +- lcm/features/pom.xml | 4 +- lcm/installer/pom.xml | 4 +- lcm/model/pom.xml | 4 +- lcm/pom.xml | 4 +- lcm/provider/pom.xml | 4 +- pom.xml | 4 +- ueb-listener/pom.xml | 4 +- .../sli/northbound/uebclient/SdncBaseModel.java | 281 ++++++--------------- .../sli/northbound/uebclient/SdncGroupModel.java | 24 +- .../sli/northbound/uebclient/SdncNodeModel.java | 126 ++++----- .../sli/northbound/uebclient/SdncUebCallback.java | 24 +- .../sli/northbound/uebclient/SdncVFCModel.java | 4 +- .../sli/northbound/uebclient/SdncVFModel.java | 25 +- .../northbound/uebclient/SdncGroupModelTest.java | 6 +- .../northbound/uebclient/SdncNodeModelTest.java | 18 +- .../northbound/uebclient/TestSdncUebCallback.java | 152 +++++++++++ .../src/test/resources/ueb-listener.properties | 3 +- version.properties | 2 +- 47 files changed, 428 insertions(+), 381 deletions(-) (limited to 'ueb-listener/src') diff --git a/artifacts/pom.xml b/artifacts/pom.xml index 1ca2f7276..42eeb71f6 100755 --- a/artifacts/pom.xml +++ b/artifacts/pom.xml @@ -4,7 +4,7 @@ org.onap.ccsdk.sli.northbound sli-northbound-artifacts - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT pom ccsdk-sli-northbound :: sli-northbound-artifacts @@ -17,7 +17,7 @@ org.onap.ccsdk.parent parent - 1.3.2 + 1.3.3-SNAPSHOT diff --git a/asdcApi/features/ccsdk-asdcApi/pom.xml b/asdcApi/features/ccsdk-asdcApi/pom.xml index 5cb47d9c5..be3dee2b5 100644 --- a/asdcApi/features/ccsdk-asdcApi/pom.xml +++ b/asdcApi/features/ccsdk-asdcApi/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent single-feature-parent - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound ccsdk-asdcApi - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT feature ccsdk-sli-northbound :: asdcApi :: ${project.artifactId} diff --git a/asdcApi/features/features-asdcApi/pom.xml b/asdcApi/features/features-asdcApi/pom.xml index 4c0762b59..2917abd74 100644 --- a/asdcApi/features/features-asdcApi/pom.xml +++ b/asdcApi/features/features-asdcApi/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent feature-repo-parent - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound features-asdcApi - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT feature ccsdk-sli-northbound :: asdcApi :: ${project.artifactId} diff --git a/asdcApi/features/pom.xml b/asdcApi/features/pom.xml index 37929d871..6f6ac13f6 100755 --- a/asdcApi/features/pom.xml +++ b/asdcApi/features/pom.xml @@ -5,12 +5,12 @@ org.onap.ccsdk.parent odlparent-lite - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound asdcApi-features - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT pom ccsdk-sli-northbound :: asdcApi :: ${project.artifactId} diff --git a/asdcApi/installer/pom.xml b/asdcApi/installer/pom.xml index 70b8ad896..33af1bd52 100755 --- a/asdcApi/installer/pom.xml +++ b/asdcApi/installer/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent odlparent-lite - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound asdcApi-installer - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT pom ccsdk-sli-northbound :: asdcApi :: ${project.artifactId} diff --git a/asdcApi/model/pom.xml b/asdcApi/model/pom.xml index 5c11f7fe1..a5bb371c6 100755 --- a/asdcApi/model/pom.xml +++ b/asdcApi/model/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent binding-parent - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound asdcApi-model - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT bundle ccsdk-sli-northbound :: asdcApi :: ${project.artifactId} diff --git a/asdcApi/pom.xml b/asdcApi/pom.xml index 7909602c2..d00afcb41 100755 --- a/asdcApi/pom.xml +++ b/asdcApi/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent odlparent-lite - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound asdcApi - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT pom ccsdk-sli-northbound :: asdcApi diff --git a/asdcApi/provider/pom.xml b/asdcApi/provider/pom.xml index fff19f630..34f65285f 100755 --- a/asdcApi/provider/pom.xml +++ b/asdcApi/provider/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent binding-parent - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound asdcApi-provider - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT bundle ccsdk-sli-northbound :: asdcApi :: ${project.artifactId} diff --git a/daexim-offsite-backup/features/ccsdk-daexim-offsite-backup/pom.xml b/daexim-offsite-backup/features/ccsdk-daexim-offsite-backup/pom.xml index 6e5e39854..d54eb208a 100644 --- a/daexim-offsite-backup/features/ccsdk-daexim-offsite-backup/pom.xml +++ b/daexim-offsite-backup/features/ccsdk-daexim-offsite-backup/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent single-feature-parent - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound ccsdk-daexim-offsite-backup - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT feature ccsdk-sli-northbound :: daexim-offsite-backup :: ${project.artifactId} diff --git a/daexim-offsite-backup/features/features-daexim-offsite-backup/pom.xml b/daexim-offsite-backup/features/features-daexim-offsite-backup/pom.xml index fa5fce035..632cad587 100644 --- a/daexim-offsite-backup/features/features-daexim-offsite-backup/pom.xml +++ b/daexim-offsite-backup/features/features-daexim-offsite-backup/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent feature-repo-parent - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound features-daexim-offsite-backup - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT feature ccsdk-sli-northbound :: daexim-offsite-backup :: ${project.artifactId} diff --git a/daexim-offsite-backup/features/pom.xml b/daexim-offsite-backup/features/pom.xml index 904aa5a06..d23a039c1 100755 --- a/daexim-offsite-backup/features/pom.xml +++ b/daexim-offsite-backup/features/pom.xml @@ -5,12 +5,12 @@ org.onap.ccsdk.parent odlparent-lite - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound daexim-offsite-backup-features - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT pom ccsdk-sli-northbound :: daexim-offsite-backup :: ${project.artifactId} diff --git a/daexim-offsite-backup/installer/pom.xml b/daexim-offsite-backup/installer/pom.xml index 3b48a5356..d58467bb0 100755 --- a/daexim-offsite-backup/installer/pom.xml +++ b/daexim-offsite-backup/installer/pom.xml @@ -4,14 +4,14 @@ org.onap.ccsdk.parent odlparent-lite - 1.3.2 + 1.3.3-SNAPSHOT ccsdk-sli-northbound :: daexim-offsite-backup :: ${project.artifactId} org.onap.ccsdk.sli.northbound daexim-offsite-backup-installer - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT pom ccsdk-daexim-offsite-backup diff --git a/daexim-offsite-backup/model/pom.xml b/daexim-offsite-backup/model/pom.xml index b842ee670..e0702fee5 100755 --- a/daexim-offsite-backup/model/pom.xml +++ b/daexim-offsite-backup/model/pom.xml @@ -4,14 +4,14 @@ org.onap.ccsdk.parent binding-parent - 1.3.2 + 1.3.3-SNAPSHOT ccsdk-sli-northbound :: daexim-offsite-backup :: ${project.artifactId} org.onap.ccsdk.sli.northbound daexim-offsite-backup-model - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT bundle diff --git a/daexim-offsite-backup/pom.xml b/daexim-offsite-backup/pom.xml index a2c624e8e..34e4e1953 100755 --- a/daexim-offsite-backup/pom.xml +++ b/daexim-offsite-backup/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent odlparent-lite - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound daexim-offsite-backup - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT pom ccsdk-sli-northbound :: daexim-offsite-backup diff --git a/daexim-offsite-backup/provider/pom.xml b/daexim-offsite-backup/provider/pom.xml index e91fc6b11..49bd6e7ec 100755 --- a/daexim-offsite-backup/provider/pom.xml +++ b/daexim-offsite-backup/provider/pom.xml @@ -4,14 +4,14 @@ org.onap.ccsdk.parent binding-parent - 1.3.2 + 1.3.3-SNAPSHOT ccsdk-sli-northbound :: daexim-offsite-backup :: ${project.artifactId} org.onap.ccsdk.sli.northbound daexim-offsite-backup-provider - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT bundle diff --git a/dataChange/features/ccsdk-dataChange/pom.xml b/dataChange/features/ccsdk-dataChange/pom.xml index 7aca371c2..635cbe5f7 100644 --- a/dataChange/features/ccsdk-dataChange/pom.xml +++ b/dataChange/features/ccsdk-dataChange/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent single-feature-parent - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound ccsdk-dataChange - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT feature ccsdk-sli-northbound :: dataChange :: ${project.artifactId} diff --git a/dataChange/features/features-dataChange/pom.xml b/dataChange/features/features-dataChange/pom.xml index a55235507..5a50ef10a 100644 --- a/dataChange/features/features-dataChange/pom.xml +++ b/dataChange/features/features-dataChange/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent feature-repo-parent - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound features-dataChange - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT feature ccsdk-sli-northbound :: dataChange :: ${project.artifactId} diff --git a/dataChange/features/pom.xml b/dataChange/features/pom.xml index b9652a11b..d4fab812c 100755 --- a/dataChange/features/pom.xml +++ b/dataChange/features/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent odlparent-lite - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound dataChange-features - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT pom ccsdk-sli-northbound :: dataChange :: ${project.artifactId} diff --git a/dataChange/installer/pom.xml b/dataChange/installer/pom.xml index c778296f2..d3e7cb2b4 100755 --- a/dataChange/installer/pom.xml +++ b/dataChange/installer/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent odlparent-lite - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound dataChange-installer - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT pom ccsdk-sli-northbound :: dataChange :: ${project.artifactId} diff --git a/dataChange/model/pom.xml b/dataChange/model/pom.xml index 5aa0825b1..57a8a8774 100755 --- a/dataChange/model/pom.xml +++ b/dataChange/model/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent binding-parent - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound dataChange-model - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT bundle ccsdk-sli-northbound :: dataChange :: ${project.artifactId} diff --git a/dataChange/pom.xml b/dataChange/pom.xml index a8def686e..1419661b2 100755 --- a/dataChange/pom.xml +++ b/dataChange/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent odlparent-lite - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound dataChange - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT pom ccsdk-sli-northbound :: dataChange diff --git a/dataChange/provider/pom.xml b/dataChange/provider/pom.xml index db1f3aff3..204e9158a 100755 --- a/dataChange/provider/pom.xml +++ b/dataChange/provider/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent binding-parent - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound dataChange-provider - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT bundle ccsdk-sli-northbound :: dataChange :: ${project.artifactId} diff --git a/dmaap-listener/pom.xml b/dmaap-listener/pom.xml index a6c6cdfe8..d07f8111d 100755 --- a/dmaap-listener/pom.xml +++ b/dmaap-listener/pom.xml @@ -5,12 +5,12 @@ org.onap.ccsdk.parent standalone-parent - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound dmaap-listener - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT jar ccsdk-sli-northbound :: dmaap-listener diff --git a/features/ccsdk-sli-northbound-all/pom.xml b/features/ccsdk-sli-northbound-all/pom.xml index 0835eff1d..c5c1b914c 100644 --- a/features/ccsdk-sli-northbound-all/pom.xml +++ b/features/ccsdk-sli-northbound-all/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent single-feature-parent - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound ccsdk-sli-northbound-all - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT feature ccsdk-sli-northbound :: features :: ${project.artifactId} diff --git a/features/features-sli-northbound/pom.xml b/features/features-sli-northbound/pom.xml index e2cb8cf00..fce265bbe 100644 --- a/features/features-sli-northbound/pom.xml +++ b/features/features-sli-northbound/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent feature-repo-parent - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound features-sli-northbound - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT feature ccsdk-sli-northbound :: features :: ${project.artifactId} diff --git a/features/installer/pom.xml b/features/installer/pom.xml index fa17f17c2..46bdfdf3f 100755 --- a/features/installer/pom.xml +++ b/features/installer/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent odlparent-lite - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound slinorthbound-features-installer - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT pom ccsdk-sli-northbound :: features :: ${project.artifactId} diff --git a/features/pom.xml b/features/pom.xml index d20d77be4..486ff093c 100755 --- a/features/pom.xml +++ b/features/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent odlparent-lite - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound slinorthbound-feature-aggregator - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT pom ccsdk-sli-northbound :: features diff --git a/lcm/features/ccsdk-lcm/pom.xml b/lcm/features/ccsdk-lcm/pom.xml index 1bc3a1e77..cd80fb34d 100644 --- a/lcm/features/ccsdk-lcm/pom.xml +++ b/lcm/features/ccsdk-lcm/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent single-feature-parent - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound ccsdk-lcm - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT feature ccsdk-sli-northbound :: lcm :: ${project.artifactId} diff --git a/lcm/features/features-lcm/pom.xml b/lcm/features/features-lcm/pom.xml index 54315d1cf..cb7126187 100644 --- a/lcm/features/features-lcm/pom.xml +++ b/lcm/features/features-lcm/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent feature-repo-parent - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound features-lcm - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT feature ccsdk-sli-northbound :: lcm :: ${project.artifactId} diff --git a/lcm/features/pom.xml b/lcm/features/pom.xml index f177a06a8..b59d2b92c 100755 --- a/lcm/features/pom.xml +++ b/lcm/features/pom.xml @@ -5,12 +5,12 @@ org.onap.ccsdk.parent odlparent-lite - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound lcm-features - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT pom ccsdk-sli-northbound :: lcm :: ${project.artifactId} diff --git a/lcm/installer/pom.xml b/lcm/installer/pom.xml index 3625134c8..3966c9d2f 100755 --- a/lcm/installer/pom.xml +++ b/lcm/installer/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent odlparent-lite - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound lcm-installer - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT pom ccsdk-sli-northbound :: lcm :: ${project.artifactId} diff --git a/lcm/model/pom.xml b/lcm/model/pom.xml index f79e5718b..6f41820c3 100755 --- a/lcm/model/pom.xml +++ b/lcm/model/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent binding-parent - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound lcm-model - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT bundle ccsdk-sli-northbound :: lcm :: ${project.artifactId} diff --git a/lcm/pom.xml b/lcm/pom.xml index b9d1a770a..455beb899 100755 --- a/lcm/pom.xml +++ b/lcm/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent odlparent-lite - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound lcm - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT pom ccsdk-sli-northbound :: lcm diff --git a/lcm/provider/pom.xml b/lcm/provider/pom.xml index 7734d929c..def00a9b3 100755 --- a/lcm/provider/pom.xml +++ b/lcm/provider/pom.xml @@ -5,13 +5,13 @@ org.onap.ccsdk.parent binding-parent - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound lcm-provider - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT bundle ccsdk-sli-northbound :: lcm :: ${project.artifactId} diff --git a/pom.xml b/pom.xml index 120548d9b..76ad8082c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.onap.ccsdk.parent odlparent-lite - 1.3.2 + 1.3.3-SNAPSHOT 4.0.0 @@ -104,7 +104,7 @@ ONAP - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT diff --git a/ueb-listener/pom.xml b/ueb-listener/pom.xml index e31603106..63b849ec6 100755 --- a/ueb-listener/pom.xml +++ b/ueb-listener/pom.xml @@ -5,12 +5,12 @@ org.onap.ccsdk.parent standalone-parent - 1.3.2 + 1.3.3-SNAPSHOT org.onap.ccsdk.sli.northbound ueb-listener - 0.5.1-SNAPSHOT + 0.5.2-SNAPSHOT jar ccsdk-sli-northbound :: ueb-listener diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index 84918ab10..d3fef173f 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -77,10 +77,6 @@ public class SdncBaseModel { protected NodeTemplate nodeTemplate = null; protected IEntityDetails entityDetails = null; - public SdncBaseModel(DBResourceManager jdbcDataSource) { - this.jdbcDataSource = jdbcDataSource; - } - public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, DBResourceManager jdbcDataSource) { this (sdcCsarHelper, nodeTemplate); this.sdcCsarHelper = sdcCsarHelper; @@ -159,28 +155,7 @@ public class SdncBaseModel { addParameter(PARAM_UUID_KEY, UUID); addParameter(PARAM_VERSION_KEY, extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VERSION)); } - - public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Group group, SdncUebConfiguration config, DBResourceManager jdbcDataSource) throws IOException { - this (sdcCsarHelper, group); - this.sdcCsarHelper = sdcCsarHelper; - this.config = config; - this.jdbcDataSource = jdbcDataSource; - } - - public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Group group) { - - params = new HashMap(); - this.sdcCsarHelper = sdcCsarHelper; - attributeValueParams = new HashMap(); - // extract group metadata - Metadata metadata = group.getMetadata(); - //customizationUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULECUSTOMIZATIONUUID); - returning null - customizationUUID = extractValue (metadata, "vfModuleModelCustomizationUUID"); - addParameter(PARAM_INVARIANT_UUID_KEY, extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)); - addParameter(PARAM_UUID_KEY, extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)); - addParameter(PARAM_VERSION_KEY, extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)); - } /* This is the generic approach Shoujit attempted for 18.06 but can't be implemented without parser API to * get properties with substring match on the name @@ -238,7 +213,7 @@ public class SdncBaseModel { addParameter("resource_type", metadataType, attributeParams); addParameter("resource_customization_uuid", getCustomizationUUID(), attributeParams); - LOG.info("Call insertToscaData for ATTRIBUTE_VALUE_PAIR where resource_uuid = " + getUUID() + " and attriubute_name = " + paramName); + LOG.info("Call insertToscaData for ATTRIBUTE_VALUE_PAIR where resource_uuid = " + getUUID() + " and attribute_name = \"" + paramName + "\""); try { insertToscaData(buildSql("ATTRIBUTE_VALUE_PAIR", "resource_uuid", getUUID(), model_yaml, attributeParams), null); } catch (IOException e) { @@ -248,13 +223,13 @@ public class SdncBaseModel { } } - protected void insertGroupData (NodeTemplate nodeTemplate, NodeTemplate targetNode, String groupType) throws IOException { + protected void insertEntityGroupData (IEntityDetails entityDetails, IEntityDetails targetNode, String groupType) throws IOException { // Get the Groups on a node - Convert to use getEntity in 19.08 EntityQuery entityQuery = EntityQuery.newBuilder(groupType).build(); String customizationUuid = getCustomizationUUIDNoQuotes(); - SdcTypes nodeTemplateSdcType = SdcTypes.valueOf(extractValue(nodeTemplate.getMetaData(), SdcPropertyNames.PROPERTY_NAME_TYPE)); - TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(nodeTemplateSdcType) + SdcTypes entitySdcType = SdcTypes.valueOf(extractValue(entityDetails.getMetadata(), SdcPropertyNames.PROPERTY_NAME_TYPE)); + TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(entitySdcType) .customizationUUID(customizationUuid).build(); List groupList = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false); if (groupList == null) { @@ -268,21 +243,22 @@ public class SdncBaseModel { // ATTRIBUTE_VALUE_PAIR (group properties): group_type, group_role, group_function // RESOURCE_GROUP_TO_TARGET_NODE_MAPPING: group_uuid, parent_uuid (CR node UUID), target_node_uuid, target_type, table_name - SdncGroupModel groupModel = new SdncGroupModel (sdcCsarHelper, group, nodeTemplate, config, jdbcDataSource); - groupModel.insertGroupData(nodeTemplate); + SdncGroupModel groupModel = new SdncGroupModel (sdcCsarHelper, group, entityDetails, config, jdbcDataSource); + String resourceUuid = getUUID(); + groupModel.insertGroupData(resourceUuid); // insert RESOURCE_GROUP_TO_TARGET_NODE_MAPPING try { Map mappingCleanupParams = new HashMap(); addParameter("group_uuid", groupModel.getUUID(), mappingCleanupParams); - addParameter("parent_uuid", extractValue(nodeTemplate.getMetaData(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingCleanupParams); - addParameter("target_node_uuid", extractValue(targetNode.getMetaData(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingCleanupParams); + addParameter("parent_uuid", extractValue(entityDetails.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingCleanupParams); + addParameter("target_node_uuid", extractValue(targetNode.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingCleanupParams); cleanupExistingToscaData("RESOURCE_GROUP_TO_TARGET_NODE_MAPPING", mappingCleanupParams); Map mappingParams = new HashMap(); - addParameter("parent_uuid", extractValue(nodeTemplate.getMetaData(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingParams); - addParameter("target_node_uuid", extractValue(targetNode.getMetaData(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingParams); - String targetType = extractValue(targetNode.getMetaData(), PARAM_TYPE_KEY); + addParameter("parent_uuid", extractValue(entityDetails.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingParams); + addParameter("target_node_uuid", extractValue(targetNode.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingParams); + String targetType = extractValue(targetNode.getMetadata(), PARAM_TYPE_KEY); addParameter("target_type", targetType, mappingParams); String tableName = ""; switch (targetType) { @@ -310,7 +286,7 @@ public class SdncBaseModel { TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(queryType).customizationUUID(nodeTemplateCustomizationUuid).build(); List policyEntities = sdcCsarHelper.getEntity(policyEntityQuery, topologyTemplateQuery, false); if (policyEntities == null || policyEntities.isEmpty()) { - LOG.info("insertPolicyData: Could not find policy data for: " + nodeTemplateCustomizationUuid); + LOG.debug("insertPolicyData: Could not find policy data for: " + nodeTemplateCustomizationUuid); return; } @@ -339,7 +315,7 @@ public class SdncBaseModel { List policyEntities = sdcCsarHelper.getEntity(policyEntityQuery, topologyTemplateQuery, false); if (policyEntities == null || policyEntities.isEmpty()) { - LOG.info("insertPolicyData: Could not find policy data for Service/VF: " + resourceUuid); + LOG.debug("insertPolicyData: Could not find policy data for Service/VF: " + resourceUuid); return; } @@ -352,7 +328,7 @@ public class SdncBaseModel { insertResourcePolicyData(policyEntity, resourceUuid); List targetEntities = policyEntity.getTargetEntities(); if (targetEntities == null || targetEntities.isEmpty()) { - LOG.info("insertPolicyData: Could not find targetEntites for policy: " + policyUuid); + LOG.debug("insertPolicyData: Could not find targetEntites for policy: " + policyUuid); continue; } @@ -483,7 +459,7 @@ public class SdncBaseModel { try { cleanupExistingToscaData("NODE_CAPABILITY", cleanupParams); // will also delete NODE_CAPABILITY_PROPERTY with same capability_id - LOG.info("Call insertToscaData for NODE_CAPABILITY where capability_provider_uuid = " + capabilityProviderUuid + " and capability_name = " + capability.getName()); + LOG.info("Call insertToscaData for NODE_CAPABILITY where capability_provider_uuid = " + capabilityProviderUuid + " and capability_name = \"" + capability.getName() + "\""); insertToscaData(buildSql("NODE_CAPABILITY", "capability_provider_uuid", capabilityProviderUuid, model_yaml, nodeCapabilityParams), null); // Get capabilityId for capability just inserted @@ -545,7 +521,7 @@ public class SdncBaseModel { try { cleanupExistingToscaData("NODE_CAPABILITY", cleanupParams); // will also delete NODE_CAPABILITY_PROPERTY with same capability_id - LOG.info("Call insertToscaData for NODE_CAPABILITY where capability_provider_uuid = " + capabilityProviderUuid + " and capability_name = " + capability.getName()); + LOG.info("Call insertToscaData for NODE_CAPABILITY where capability_provider_uuid = " + capabilityProviderUuid + " and capability_name = \"" + capability.getName()+ "\""); insertToscaData(buildSql("NODE_CAPABILITY", "capability_provider_uuid", capabilityProviderUuid, model_yaml, nodeCapabilityParams), null); // Get capabilityId for capability just inserted @@ -578,7 +554,7 @@ public class SdncBaseModel { try { // Data from NODE_CAPABILITY_PROPERTY is cleaned up via cascade delete on NODE_CAPABILITY - LOG.info("Call insertToscaData for NODE_CAPABILITY_PROPERTY where capability_id = " + capabilityId + " and property_name = " + property.getName() + ", property_value: " + property.getValue().toString()); + LOG.info("Call insertToscaData for NODE_CAPABILITY_PROPERTY where capability_id = \"" + capabilityId + "\" and capability_property_name = \"" + property.getName() + "\" and capability_property_type = \"" + property.getValue().toString() + "\""); insertToscaData(buildSql("NODE_CAPABILITY_PROPERTY", "capability_id", capabilityId, model_yaml, nodeCapabilityPropertyParams), null); } catch (IOException e) { LOG.error("Could not insert Tosca CSAR data into the NODE_CAPABILITY_PROPERTY table"); @@ -605,12 +581,6 @@ public class SdncBaseModel { } } - public static void addIntParameter (String name, String value, Map params) { - if (value != null && !value.isEmpty()) { - params.put(name, value); - } - } - public static void addParameter (String name, String value, Map params) { if (value != null && !value.isEmpty()) { // remove any quotes within the string @@ -682,7 +652,7 @@ public class SdncBaseModel { if (entityDetails.getProperties().containsKey(path)) { Property property = entityDetails.getProperties().get(path); - if (property != null && property.getLeafPropertyValue(name) != null) { + if (property != null && !property.getLeafPropertyValue(name).isEmpty()) { value = property.getLeafPropertyValue(name).get(0); } } @@ -693,34 +663,49 @@ public class SdncBaseModel { return ""; } } - - protected String extractValue (Property property, String name) { + + protected String extractValue (IEntityDetails entityDetails, String path1, String path2, String name) { String value = ""; - if (!property.getLeafPropertyValue(name).isEmpty()) { - value = property.getLeafPropertyValue(name).get(0); - } - + value = extractNestedValue (entityDetails, path1, path2, name); + if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { return value; } else { return ""; } } - - protected String extractBooleanValue (Property property, String name) { + + protected String extractBooleanValue (IEntityDetails entityDetails, String path1, String path2, String name) { String value = ""; - if (!property.getLeafPropertyValue(name).isEmpty()) { - value = property.getLeafPropertyValue(name).get(0); - } + value = extractNestedValue (entityDetails, path1, path2, name); - if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { + if (value != null && !value.isEmpty()) { return value.contains("true") ? "Y" : "N"; } else { return ""; } } + + protected String extractNestedValue (IEntityDetails entityDetails, String path1, String path2, String name) { + String value = ""; + + if (entityDetails.getProperties().containsKey(path1)) { + Property path1Property = entityDetails.getProperties().get(path1); + if (path1Property != null) { + Map path1PropertyValue = (Map) path1Property.getValue(); + if (path1PropertyValue.containsKey(path2)) { + Map path2PropertyValue = (Map) path1PropertyValue.get(path2); + if (path2PropertyValue != null && path2PropertyValue.containsKey(name)) { + value = path2PropertyValue.get(name).toString(); + } + } + } + } + + return value; + } protected String extractIntegerValue (Property property, String name) { String value = ""; @@ -735,35 +720,48 @@ public class SdncBaseModel { return ""; } } + + protected String extractGetInputValue (IEntityDetails group, IEntityDetails entityDetails, String name) { - protected String extractGetInputValue (Group group, NodeTemplate nodeTemplate, String name) { - - String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, extractGetInputName (group, name)); - if (value != null) { - return value; + // Extract the property on entityDetails after getting the property name from the group + String getInputName = extractGetInputName (group, name); + String entityPropertyValue = ""; + + if (entityDetails.getProperties().containsKey(getInputName)) { + Property entityProperty = entityDetails.getProperties().get(getInputName); + entityPropertyValue = entityProperty.getValue().toString(); + } + + if (!entityPropertyValue.isEmpty()) { + return entityPropertyValue; } else { return ""; } } - protected String extractGetInputName (Group group, String name) { + protected String extractGetInputName (IEntityDetails group, String name) { String getInputName = name; - String groupProperty = sdcCsarHelper.getGroupPropertyLeafValue(group, name); - if (groupProperty != null) { - int getInputIndex = groupProperty.indexOf("{get_input="); + String groupPropertyValue = ""; + if (group.getProperties().containsKey(name)) { + Property groupProperty = group.getProperties().get(name); + groupPropertyValue = groupProperty.getValue().toString(); + } + if (!groupPropertyValue.isEmpty()) { + int getInputIndex = groupPropertyValue.indexOf("{get_input="); if (getInputIndex > -1) { - getInputName = groupProperty.substring(getInputIndex+11, groupProperty.length()-1); + getInputName = groupPropertyValue.substring(getInputIndex+11, groupPropertyValue.length()-1); } } return getInputName; } - - protected String extractGetInputValue (Policy policy, NodeTemplate nodeTemplate, String name) { - String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, extractGetInputName (policy, name)); + // Remove this after migrate SdncVFModel to getEntity + protected String extractGetInputValue (Group group, NodeTemplate nodeTemplate, String name) { + + String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, extractGetInputName (group, name)); if (value != null) { return value; } else { @@ -771,13 +769,12 @@ public class SdncBaseModel { } } - protected String extractGetInputName (Policy policy, String name) { + // Remove this after migrate SdncVFModel to getEntity + protected String extractGetInputName (Group group, String name) { String getInputName = name; - //String groupProperty = sdcCsarHelper.getPolicyPropertyLeafValue(policy, name); - Map propMap = policy.getPolicyProperties(); - String groupProperty = nullCheck(propMap.get(name)); - if (!groupProperty.isEmpty()) { + String groupProperty = sdcCsarHelper.getGroupPropertyLeafValue(group, name); + if (groupProperty != null) { int getInputIndex = groupProperty.indexOf("{get_input="); if (getInputIndex > -1) { getInputName = groupProperty.substring(getInputIndex+11, groupProperty.length()-1); @@ -787,36 +784,7 @@ public class SdncBaseModel { return getInputName; } - - protected String extractValue (Policy policy, String name) { - - Map propMap = policy.getPolicyProperties(); - if (propMap == null) { - return ""; - } else { - return nullCheck(propMap.get(name)); - } - } - - protected static String extractValueStatic (Policy policy, String name) { - - Map propMap = policy.getPolicyProperties(); - if (propMap == null) { - return ""; - } else { - return nullCheckStatic(propMap.get(name)); - } - } - - public static String extractValue (ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, String name) { - String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); - if (value != null) { - return value; - } else { - return ""; - } - } - + protected String extractValue (CapabilityAssignment capability, String name) { String value = sdcCsarHelper.getCapabilityPropertyLeafValue(capability, name); if (value != null) { @@ -855,8 +823,10 @@ public class SdncBaseModel { String value = null; if (entityDetails.getProperties().containsKey(path)) { Property property = entityDetails.getProperties().get(path); - if (property != null && property.getLeafPropertyValue(name) != null) { - value = property.getLeafPropertyValue(name).get(0); + if (property != null) { + if (property != null && !property.getLeafPropertyValue(name).isEmpty()) { + value = property.getLeafPropertyValue(name).get(0); + } } } @@ -867,15 +837,6 @@ public class SdncBaseModel { } } - public static String extractBooleanValue (ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, String name) { - String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); - if (value != null && !value.isEmpty()) { - return value.contains("true") ? "Y" : "N"; - } else { - return ""; - } - } - protected Object extractObjectValue (NodeTemplate nodeTemplate, String name) { Object value = sdcCsarHelper.getNodeTemplatePropertyValueAsObject(nodeTemplate, name); if (value != null) { @@ -885,60 +846,6 @@ public class SdncBaseModel { } } - protected String extractValue (Group group, String name) { - String value = sdcCsarHelper.getGroupPropertyLeafValue(group, name); - if (value != null) { - return value; - } else { - return ""; - } - } - - protected String extractBooleanValue (Group group, String name) { - String value = sdcCsarHelper.getGroupPropertyLeafValue(group, name); - if (value != null && !value.isEmpty()) { - return value.contains("true") ? "Y" : "N"; - } else { - return ""; - } - } - - protected String extractInputDefaultValue (String name) { - String value = sdcCsarHelper.getServiceInputLeafValueOfDefault(name); - if (value != null) { - return value; - } else { - return ""; - } - } - - protected String extractBooleanInputDefaultValue (String name) { - String value = sdcCsarHelper.getServiceInputLeafValueOfDefault(name); - if (value != null && !value.isEmpty()) { - return value.contains("true") ? "Y" : "N"; - } else { - return ""; - } - } - - public static String extractInputDefaultValue (ISdcCsarHelper sdcCsarHelper, String name) { - String value = sdcCsarHelper.getServiceInputLeafValueOfDefault(name); - if (value != null) { - return value; - } else { - return ""; - } - } - - public static String extractBooleanInputDefaultValue (ISdcCsarHelper sdcCsarHelper, String name) { - String value = sdcCsarHelper.getServiceInputLeafValueOfDefault(name); - if (value != null && !value.isEmpty()) { - return value.contains("true") ? "Y" : "N"; - } else { - return ""; - } - } - public static String extractSubstitutionMappingTypeName (ISdcCsarHelper sdcCsarHelper) { String value = sdcCsarHelper.getServiceSubstitutionMappingsTypeName(); if (value != null) { @@ -1058,21 +965,6 @@ public class SdncBaseModel { throw new IOException (e); } - } - - protected static void insertToscaData(DBResourceManager jdbcDataSource, String toscaDataString, ArrayList arguments) throws IOException - { - LOG.debug("insertToscaData: " + toscaDataString); - - try { - - jdbcDataSource.writeData(toscaDataString, arguments, null); - - } catch (SQLException e) { - LOG.error("Could not insert Tosca data into the database"); - throw new IOException (e); - } - } protected void cleanUpExistingToscaData(String tableName, String keyName, String keyValue) throws IOException @@ -1188,7 +1080,7 @@ public class SdncBaseModel { rowCount ++; } if (rowCount != 0) { - LOG.info("checkForExistingToscaData in " + tableName + ": Data FOUND"); + LOG.debug("checkForExistingToscaData in " + tableName + ": Data FOUND"); dataExists = true; } @@ -1233,6 +1125,7 @@ public class SdncBaseModel { return data; } + protected void addParamsToMap (Map fromMap, Map toMap) { for (String key : fromMap.keySet()) { if (!toMap.containsKey(key)) { @@ -1249,12 +1142,4 @@ public class SdncBaseModel { return stringValue; } - protected static String nullCheckStatic (Object extractedObject) { - String stringValue = ""; - if (extractedObject != null) { - return extractedObject.toString(); - } - return stringValue; - } - } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java index 268590feb..622936652 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java @@ -27,8 +27,6 @@ import java.io.IOException; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.toscaparser.api.Group; -import org.onap.sdc.toscaparser.api.NodeTemplate; import org.onap.sdc.toscaparser.api.elements.Metadata; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,7 +38,7 @@ public class SdncGroupModel extends SdncBaseModel { private static final String groupType = "group_type"; - public SdncGroupModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails group, NodeTemplate nodeTemplate, SdncUebConfiguration config, DBResourceManager jdbcDataSource) throws IOException { + public SdncGroupModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails group, IEntityDetails entityDetails, SdncUebConfiguration config, DBResourceManager jdbcDataSource) throws IOException { super(sdcCsarHelper, group); @@ -60,24 +58,20 @@ public class SdncGroupModel extends SdncBaseModel { addParameter("vfc_parent_port_role", extractValue(group, "vfc_parent_port_role"), attributeValueParams); addParameter("subinterface_role", extractValue(group, "subinterface_role"), attributeValueParams); - // relevant complex group properties are extracted and inserted into ATTRIBUTE_VALUE_PAIR - String extractedGroupType = extractValue (group, groupType); - String extractedGroupRole = extractValue (group, "group_role"); - String extractedGroupFunction = extractValue (group, "group_function"); - addParameter(groupType, extractedGroupType, attributeValueParams); - addParameter("group_role", extractedGroupRole, attributeValueParams); - addParameter("group_function", extractedGroupFunction, attributeValueParams); + // relevant complex group properties are extracted and inserted into ATTRIBUTE_VALUE_PAIR + addParameter(extractGetInputName (group, groupType), extractGetInputValue(group, entityDetails, groupType), attributeValueParams); + addParameter(extractGetInputName (group, "group_role"), extractGetInputValue(group, entityDetails, "group_role"), attributeValueParams); + addParameter(extractGetInputName (group, "group_function"), extractGetInputValue(group, entityDetails, "group_function"), attributeValueParams); } - public void insertGroupData(NodeTemplate resourceNodeTemplate) throws IOException { + public void insertGroupData(String resourceUuid) throws IOException { try { // insert into RESOURCE_GROUP/ATTRIBUTE_VALUE_PAIR - String resourceNodeUuid = "\"" + extractValue (resourceNodeTemplate.getMetaData(), "UUID") + "\""; - cleanUpExistingToscaData("RESOURCE_GROUP", "resource_uuid", resourceNodeUuid, "group_uuid", getUUID()) ; - LOG.info("Call insertToscaData for RESOURCE_GROUP where group_uuid = " + getUUID() + " and resource_uuid = " + resourceNodeUuid); - insertToscaData(buildSql("RESOURCE_GROUP", "resource_uuid", resourceNodeUuid, model_yaml, params), null); + cleanUpExistingToscaData("RESOURCE_GROUP", "resource_uuid", resourceUuid, "group_uuid", getUUID()) ; + LOG.info("Call insertToscaData for RESOURCE_GROUP where group_uuid = " + getUUID() + " and resource_uuid = " + resourceUuid); + insertToscaData(buildSql("RESOURCE_GROUP", "resource_uuid", resourceUuid, model_yaml, params), null); insertRelevantAttributeData("group"); } catch (IOException e) { diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java index 4870f29e3..cf81b3cae 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java @@ -24,11 +24,13 @@ package org.onap.ccsdk.sli.northbound.uebclient; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; -import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.Property; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,59 +45,53 @@ public class SdncNodeModel extends SdncBaseModel { private String [] bindingUuids = null; // Using ASDC TOSCA Parser 17.07 - public SdncNodeModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, DBResourceManager jdbcDataSource) { + public SdncNodeModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails nodeEntity, DBResourceManager jdbcDataSource, SdncUebConfiguration config) throws IOException { - super(sdcCsarHelper, nodeTemplate, jdbcDataSource); + super(sdcCsarHelper, nodeEntity, jdbcDataSource, config); - // 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)); + addParameter("ecomp_generated_naming", extractBooleanValue (nodeEntity, "exVL_naming", "ecomp_generated_naming")); // should be extractBooleanValue? + addParameter("naming_policy", extractValue (nodeEntity, "exVL_naming", "naming_policy")); + + addParameter("network_type", extractValue (nodeEntity, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE)); + addParameter("network_role", extractValue (nodeEntity, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE)); + addParameter("network_scope", extractValue (nodeEntity, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE)); + addParameter("network_technology", extractValue (nodeEntity, 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)); - String trunkNetworkIndicator = extractBooleanValue(nodeTemplate, "network_assignments#is_trunked"); + addParameter("is_shared_network", extractBooleanValue (nodeEntity, "network_assignments", "is_shared_network")); + addParameter("is_external_network", extractBooleanValue (nodeEntity, "network_assignments", "is_external_network")); + String trunkNetworkIndicator = extractBooleanValue(nodeEntity, "network_assignments", "is_trunked"); addParameter("trunk_network_indicator", trunkNetworkIndicator); // extract properties - network_assignments - ipv4_subnet_default_assignment - String useIpv4 = extractBooleanValue(nodeTemplate, "network_assignments#ipv4_subnet_default_assignment#use_ipv4"); + String useIpv4 = extractBooleanValue(nodeEntity, "network_assignments", "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")); + addParameter("ipv4_dhcp_enabled", extractBooleanValue(nodeEntity, "network_assignments", "ipv4_subnet_default_assignment", "dhcp_enabled")); + addParameter("ipv4_ip_version", extractValue(nodeEntity, "network_assignments", "ipv4_subnet_default_assignment", "ip_version")); + addParameter("ipv4_cidr_mask", extractValue(nodeEntity, "network_assignments", "ipv4_subnet_default_assignment", "cidr_mask")); + addParameter("eipam_v4_address_plan", extractValue(nodeEntity, "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"); + String useIpv6 = extractBooleanValue(nodeEntity, "network_assignments", "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")); + addParameter("ipv6_dhcp_enabled", extractBooleanValue(nodeEntity, "network_assignments", "ipv6_subnet_default_assignment", "dhcp_enabled")); + addParameter("ipv6_ip_version", extractValue(nodeEntity, "network_assignments", "ipv6_subnet_default_assignment", "ip_version")); + addParameter("ipv6_cidr_mask", extractValue(nodeEntity, "network_assignments", "ipv6_subnet_default_assignment", "cidr_mask")); + addParameter("eipam_v6_address_plan", extractValue(nodeEntity, "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)); + addParameter("is_provider_network", extractBooleanValue (nodeEntity, "provider_network", "is_provider_network")); + addParameter("physical_network_name", extractValue(nodeEntity, "provider_network", "physical_network_name")); // extract properties - network_flows - addParameter("is_bound_to_vpn", extractBooleanValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKFLOWS_ISBOUNDTOVPN)); + addParameter("is_bound_to_vpn", extractBooleanValue (nodeEntity, "network_flows", "is_bound_to_vpn")); // extract properties - network_flows - vpn_bindings - String vpnBindingString = extractValue (nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKFLOWS_VPNBINDING); + String vpnBindingString = extractValue (nodeEntity, "network_flows", "vpn_binding"); bindingUuids = vpnBindingString.split(","); -} + } public String getServiceUUID() { return serviceUUID; @@ -113,13 +109,24 @@ public class SdncNodeModel extends SdncBaseModel { params.put("ecomp_generated_naming", "\"" + ecompGeneratedNaming + "\""); } } + public void setComplexResourceUUID(String complexResourceUuid) { + if (complexResourceUuid != null && !complexResourceUuid.isEmpty()) { + params.put("complex_resource_uuid", complexResourceUuid); + } + } + + public void setComplexResourceCustomizationUUID(String complexResourceCustomizationUuid) { + if (complexResourceCustomizationUuid != null && !complexResourceCustomizationUuid.isEmpty()) { + params.put("complex_resource_customization_uuid", complexResourceCustomizationUuid); + } + } public void insertNetworkModelData () throws IOException { try { // Clean up NETWORK_MODEL data for this customization_uuid and service_uuid? cleanUpExistingToscaData("NETWORK_MODEL", "customization_uuid", getCustomizationUUID()); cleanUpExistingToscaData("VPN_BINDINGS", "network_customization_uuid", getCustomizationUUID()); - LOG.info("Call insertToscaData for NETWORK_MODEL customizationUUID = " + getCustomizationUUID()); + LOG.info("Call insertToscaData for NETWORK_MODEL where customization_uuid = " + getCustomizationUUID()); insertToscaData(getSql(model_yaml), null); insertToscaData(getVpnBindingsSql(), null); } catch (IOException e) { @@ -127,48 +134,47 @@ public class SdncNodeModel extends SdncBaseModel { throw new IOException (e); } } - + public void insertRelatedNetworkRoleData () throws IOException { - Object propertyValue = sdcCsarHelper.getNodeTemplatePropertyValueAsObject(nodeTemplate, "network_assignments#related_networks"); - ArrayList> relatedNetworkList = (ArrayList)propertyValue; - - String networkModelCustomizationUUID = getCustomizationUUID(); + if (entityDetails.getProperties().containsKey("related_networks")) { + + Property relatedNetworksProperty = entityDetails.getProperties().get("related_networks"); + List relatedNetworkRoles = relatedNetworksProperty.getLeafPropertyValue("related_network_role"); + + String networkModelCustomizationUUID = getCustomizationUUID(); - if (relatedNetworkList != null) { - - try { - cleanUpExistingToscaData("RELATED_NETWORK_ROLE", "network_model_customization_uuid", networkModelCustomizationUUID); - } catch (IOException e) { - LOG.error("Could not clean up Tosca CSAR data in the RELATED_NETWORK_ROLE table"); - throw new IOException (e); - } - - for (Map relatedNetworkValue : relatedNetworkList) { - LOG.debug("Node Template [" + nodeTemplate.getName() + "], property [" + "related_network_role" + "] property value: " + relatedNetworkValue.get("related_network_role")); + try { + cleanUpExistingToscaData("RELATED_NETWORK_ROLE", "network_model_customization_uuid", networkModelCustomizationUUID); + } catch (IOException e) { + LOG.error("Could not clean up Tosca CSAR data in the RELATED_NETWORK_ROLE table"); + throw new IOException (e); + } + + for (String relatedNetworkRole : relatedNetworkRoles) { + + LOG.debug("Node Template [" + entityDetails.getName() + "], property [" + "related_network_role" + "] property value: " + relatedNetworkRole); - String relatedNetworkRoleValue = relatedNetworkValue.get("related_network_role"); - try { // Table cleanup RELATED_NETWORK_ROLE occurs per network // If related_network_role for this service already exist in RELATED_NETWORK_ROLE, don't attempt insertion Map relatedNetworkRoleParamsCheck = new HashMap(); - addParameter("related_network_role", relatedNetworkRoleValue, relatedNetworkRoleParamsCheck); + addParameter("related_network_role", relatedNetworkRole, relatedNetworkRoleParamsCheck); addParameter("network_model_customization_uuid", networkModelCustomizationUUID, relatedNetworkRoleParamsCheck); if (checkForExistingToscaData("RELATED_NETWORK_ROLE", relatedNetworkRoleParamsCheck) == false) { relatedNetworkRoleParamsCheck.remove("related_network_role"); LOG.info("Call insertToscaData for RELATED_NETWORK_ROLE where network_model_customization_uuid = " + networkModelCustomizationUUID); - insertToscaData(buildSql("RELATED_NETWORK_ROLE", "related_network_role", "\"" + relatedNetworkRoleValue + "\"", model_yaml, relatedNetworkRoleParamsCheck), null); + insertToscaData(buildSql("RELATED_NETWORK_ROLE", "related_network_role", "\"" + relatedNetworkRole + "\"", model_yaml, relatedNetworkRoleParamsCheck), null); } } catch (IOException e) { LOG.debug("Could not insert Tosca CSAR data into the RELATED_NETWORK_ROLE table"); throw new IOException (e); } - } - } - else { - LOG.debug("Node Template [" + nodeTemplate.getName() + "], property [" + "related_networks" + "] property value: " + null); - } + } + } + else { + LOG.debug("Node Template [" + entityDetails.getName() + "], property [" + "related_networks" + "] property value: " + null); + } } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index d39622621..d7418824b 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -703,18 +703,22 @@ public class SdncUebCallback implements INotificationCallback { } - // Ingest Network (VL) Data - 1707 - List vlNodeTemplatesList = sdcCsarHelper.getServiceVlList(); + // Ingest Network (VL) Data - 1707 / migrate to getEntity - 1908 + EntityQuery vlEntityQuery = EntityQuery.newBuilder(SdcTypes.VL).build(); + TopologyTemplateQuery vlTopologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).build(); + List vlEntities = sdcCsarHelper.getEntity(vlEntityQuery, vlTopologyTemplateQuery, false); // false to not recurse + if (vlEntities != null && !vlEntities.isEmpty()) { + for (IEntityDetails vlEntity : vlEntities){ - for (NodeTemplate nodeTemplate : vlNodeTemplatesList) { - SdncNodeModel nodeModel = new SdncNodeModel (sdcCsarHelper, nodeTemplate, jdbcDataSource); - nodeModel.setServiceUUID(serviceModel.getServiceUUID()); + try { + SdncNodeModel nodeModel = new SdncNodeModel (sdcCsarHelper, vlEntity, jdbcDataSource, config); + nodeModel.setServiceUUID(serviceModel.getServiceUUID()); - try { - nodeModel.insertNetworkModelData(); - nodeModel.insertRelatedNetworkRoleData(); - } catch (IOException e) { - deployStatus = DistributionStatusEnum.DEPLOY_ERROR; + nodeModel.insertNetworkModelData(); + nodeModel.insertRelatedNetworkRoleData(); + } catch (IOException e) { + deployStatus = DistributionStatusEnum.DEPLOY_ERROR; + } } } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java index bd71c0240..fc288aaa9 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java @@ -94,7 +94,7 @@ public class SdncVFCModel extends SdncBaseModel { TopologyTemplateQuery topologyTemplateQueryVFC = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC).customizationUUID(vfcCustomizationUuid).build(); List cpEntities = sdcCsarHelper.getEntity(entityQueryCP, topologyTemplateQueryVFC, true); if (cpEntities == null || cpEntities.isEmpty()) { - LOG.info("insertVFCtoNetworkRoleMappingData: Could not find the nested CVFCs for: " + vfcCustomizationUuid); + LOG.debug("insertVFCtoNetworkRoleMappingData: Could not find the nested CVFCs for: " + vfcCustomizationUuid); return; } @@ -282,7 +282,7 @@ public class SdncVFCModel extends SdncBaseModel { TopologyTemplateQuery topologyTemplateQueryVFC = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC).customizationUUID(vfcCustomizationUuid).build(); List cpEntities = sdcCsarHelper.getEntity(entityQueryCP, topologyTemplateQueryVFC, true); if (cpEntities == null || cpEntities.isEmpty()) { - LOG.info("insertVFCRelatedNetworkRoleData: Could not find the nested CVFCs for: " + vfcCustomizationUuid); + LOG.debug("insertVFCRelatedNetworkRoleData: Could not find the nested CVFCs for: " + vfcCustomizationUuid); return; } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java index 2b2d078f7..dd93f45db 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java @@ -54,7 +54,14 @@ public class SdncVFModel extends SdncBaseModel { public SdncVFModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, DBResourceManager jdbcDataSource, SdncUebConfiguration config) throws IOException { super(sdcCsarHelper, nodeTemplate, jdbcDataSource, config); - + + // Since SdncVFModel is not yet converted for getEntity, find the entity for this nodeTemplate + EntityQuery vfEntityQuery = EntityQuery.newBuilder(SdcTypes.VF).customizationUUID(getCustomizationUUIDNoQuotes()).build(); + TopologyTemplateQuery vfTopologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).build(); + List vfEntities = sdcCsarHelper.getEntity(vfEntityQuery, vfTopologyTemplateQuery, true); + if (vfEntities != null && !vfEntities.isEmpty()) { + entityDetails = vfEntities.get(0); + } // extract metadata Metadata metadata = nodeTemplate.getMetaData(); addParameter("name", extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_NAME)); @@ -158,7 +165,7 @@ public class SdncVFModel extends SdncBaseModel { try { cleanUpExistingToscaData("VF_MODULE_MODEL", "customization_uuid", vfModuleModel.getCustomizationUUID()); cleanUpExistingToscaData("VF_MODULE_TO_VFC_MAPPING", "vf_module_customization_uuid", vfModuleModel.getCustomizationUUID()); - LOG.info("Call insertToscaData for VF_MODULE_MODEL where vf_module_customization_uuid = " + vfModuleModel.getCustomizationUUID()); + LOG.info("Call insertToscaData for VF_MODULE_MODEL where customization_uuid = " + vfModuleModel.getCustomizationUUID()); insertToscaData(vfModuleModel.buildSql("VF_MODULE_MODEL", model_yaml), null); } catch (IOException e) { LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_MODEL table "); @@ -175,7 +182,7 @@ public class SdncVFModel extends SdncBaseModel { .build(); List vfModulesNonCatalog = sdcCsarHelper.getEntity(entityQuery2, topologyTemplateQuery2, false); if (vfModulesNonCatalog == null || vfModulesNonCatalog.isEmpty()) { - LOG.info("insertVFModuleData: Could not find the non-catelog VF Module for: " + vfModuleModel.getCustomizationUUID() + ". Unable to insert members into VF_MODULE_TO_VFC_MAPPING"); + LOG.debug("insertVFModuleData: Could not find the non-catelog VF Module for: " + vfModuleModel.getCustomizationUUID() + ". Unable to insert members into VF_MODULE_TO_VFC_MAPPING"); continue; } @@ -217,7 +224,7 @@ public class SdncVFModel extends SdncBaseModel { .build(); List nestedCvfcs = sdcCsarHelper.getEntity(entityQuery3, topologyTemplateQuery3, true); // true allows for nested search if (nestedCvfcs == null || nestedCvfcs.isEmpty()) { - LOG.info("insertVFModuleData: Could not find the nested CVFCs for: " + cvfcCustomizationUuid); + LOG.debug("insertVFModuleData: Could not find the nested CVFCs for: " + cvfcCustomizationUuid); continue; } @@ -284,7 +291,7 @@ public class SdncVFModel extends SdncBaseModel { TopologyTemplateQuery topologyTemplateQueryVF = TopologyTemplateQuery.newBuilder(SdcTypes.VF).customizationUUID(getCustomizationUUIDNoQuotes()).build(); List cpEntities = sdcCsarHelper.getEntity(entityQueryCP, topologyTemplateQueryVF, true); if (cpEntities == null || cpEntities.isEmpty()) { - LOG.info("insertVFtoNetworkRoleMappingData: Could not find CPs for VF: " + getCustomizationUUIDNoQuotes()); + LOG.debug("insertVFtoNetworkRoleMappingData: Could not find CPs for VF: " + getCustomizationUUIDNoQuotes()); return; } @@ -343,7 +350,7 @@ public class SdncVFModel extends SdncBaseModel { .build(); List cvfcEntities = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, true); // true allows for nested search if (cvfcEntities == null || cvfcEntities.isEmpty()) { - LOG.info("insertVFCDataEntity: Could not find the CVFCs for: " + vfCustomizationUid); + LOG.debug("insertVFCDataEntity: Could not find the CVFCs for: " + vfCustomizationUid); } for (IEntityDetails cvfcEntity: cvfcEntities) { @@ -382,8 +389,8 @@ public class SdncVFModel extends SdncBaseModel { for (IEntityDetails group : vfcInstanceGroupListForVf){ - SdncGroupModel groupModel = new SdncGroupModel (sdcCsarHelper, group, nodeTemplate, config, jdbcDataSource); - groupModel.insertGroupData(nodeTemplate); + SdncGroupModel groupModel = new SdncGroupModel (sdcCsarHelper, group, entityDetails, config, jdbcDataSource); + groupModel.insertGroupData(getUUID()); // For each group, populate NODE_CAPABILITY/NODE_CAPABILITY_PROPERTY insertNodeCapabilitiesEntityData(group.getCapabilities()); @@ -419,7 +426,7 @@ public class SdncVFModel extends SdncBaseModel { break; } addParameter("table_name", tableName, mappingParams); - LOG.info("Call insertToscaData for RESOURCE_GROUP_TO_TARGET_NODE_MAPPING where group_uuid = " + groupModel.getUUID() + " and target_node_uuid = " + targetNodeUuid); + LOG.info("Call insertToscaData for RESOURCE_GROUP_TO_TARGET_NODE_MAPPING where group_uuid = " + groupModel.getUUID() + " and target_node_uuid = \"" + targetNodeUuid + "\""); insertToscaData(buildSql("RESOURCE_GROUP_TO_TARGET_NODE_MAPPING", "group_uuid", groupModel.getUUID(), model_yaml, mappingParams), null); } catch (IOException e) { LOG.error("Could not insert Tosca CSAR data into the RESOURCE_GROUP_TO_TARGET_NODE_MAPPING"); diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModelTest.java index 8bf3c9145..3b2cd96a1 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModelTest.java @@ -8,8 +8,6 @@ import java.io.IOException; import org.junit.Test; import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.toscaparser.api.NodeTemplate; -import org.onap.sdc.toscaparser.api.Group; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; public class SdncGroupModelTest { @@ -17,13 +15,13 @@ import org.onap.ccsdk.sli.core.dblib.DBResourceManager; @Test public void testSdncGroupModelConstructor() { ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); - NodeTemplate nodeTemplate = mock(NodeTemplate.class); IEntityDetails group = mock(IEntityDetails.class); + IEntityDetails entityDetails = mock(IEntityDetails.class); DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); SdncUebConfiguration mockSdncUebConfiguration = mock(SdncUebConfiguration.class); SdncGroupModel testSdncGroupModel = null; try { - testSdncGroupModel = new SdncGroupModel(mockCsarHelper,group,nodeTemplate,mockSdncUebConfiguration,mockDBResourceManager); + testSdncGroupModel = new SdncGroupModel(mockCsarHelper,group,entityDetails,mockSdncUebConfiguration,mockDBResourceManager); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java index a77c5adbf..9f859e793 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java @@ -7,9 +7,9 @@ import static org.mockito.Mockito.*; import java.io.IOException; import org.junit.Before; -import org.junit.Test; -import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.junit.Test; +import org.onap.sdc.tosca.parser.api.IEntityDetails; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; @@ -18,17 +18,17 @@ public class SdncNodeModelTest { SdncNodeModel sdncNodeModel; @Before - public void setUp() throws Exception { + public void setUp() throws Exception { + SdncUebConfiguration config = mock(SdncUebConfiguration.class); ISdcCsarHelper isdcCsarHelper = mock(ISdcCsarHelper.class); - NodeTemplate nodeTemplate = mock(NodeTemplate.class); + IEntityDetails entityDetails = mock(IEntityDetails.class); Metadata mockMetadata = mock(Metadata.class); DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); - when(nodeTemplate.getMetaData()).thenReturn(mockMetadata); + when(entityDetails.getMetadata()).thenReturn(mockMetadata); when(isdcCsarHelper.getMetadataPropertyValue(mockMetadata, "customizationUUID")).thenReturn("aaaa-bbbb-cccc-dddd"); - when(isdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "network_type")).thenReturn("test-network-type"); - sdncNodeModel = new SdncNodeModel(isdcCsarHelper, nodeTemplate, mockDBResourceManager); + sdncNodeModel = new SdncNodeModel(isdcCsarHelper, entityDetails, mockDBResourceManager, config); sdncNodeModel.setServiceUUID("0e8d757f-1c80-40af-85de-31d64f1f5af8"); sdncNodeModel.setEcompGeneratedNaming("hello-world"); } @@ -48,7 +48,7 @@ public class SdncNodeModelTest { @Test public void testGetSqlString() { String result = sdncNodeModel.getSql("TEST-HELLO"); - String test = "INSERT into NETWORK_MODEL (service_uuid, customization_uuid, model_yaml, ecomp_generated_naming, network_type) values (0e8d757f-1c80-40af-85de-31d64f1f5af8, \"aaaa-bbbb-cccc-dddd\", \"TEST-HELLO\", \"hello-world\", \"test-network-type\");"; + String test = "INSERT into NETWORK_MODEL (service_uuid, customization_uuid, model_yaml, ecomp_generated_naming) values (0e8d757f-1c80-40af-85de-31d64f1f5af8, \"aaaa-bbbb-cccc-dddd\", \"TEST-HELLO\", \"hello-world\");"; assertEquals(test, result); } diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java index 5b4637ea7..2c44ba732 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java @@ -46,6 +46,23 @@ public class TestSdncUebCallback { " `naming_policy` varchar(255) DEFAULT NULL,\n" + " PRIMARY KEY (`service_uuid`)\n" + ") "; + + private static final String CRTBL_SERVICE_MODEL_TO_VF_MODEL_MAPPING = "CREATE TABLE `SERVICE_MODEL_TO_VF_MODEL_MAPPING` (\n" + + " `service_uuid` varchar(255) NOT NULL,\n" + + " `vf_uuid` varchar(255) DEFAULT NULL,\n" + + " `vf_customization_uuid` varchar(255) DEFAULT NULL,\n" + + " `service_invariant_uuid` varchar(255) DEFAULT NULL,\n" + + " PRIMARY KEY (`service_uuid`)\n" + + ") "; + + private static final String CRTBL_ATTRIBUTE_VALUE_PAIR = "CREATE TABLE `ATTRIBUTE_VALUE_PAIR` (\n" + + " `resource_uuid` varchar(255) NOT NULL,\n" + + " `attribute_name` varchar(255) NOT NULL,\n" + + " `resource_type` varchar(255) NOT NULL,\n" + + " `attribute_value` varchar(255) DEFAULT NULL,\n" + + " `resource_customization_uuid` varchar(255) DEFAULT NULL,\n" + + " PRIMARY KEY (`resource_uuid`,`attribute_name`,`resource_type`)\n" + + ") "; private static final String CRTBL_NETWORK_MODEL = "CREATE TABLE `NETWORK_MODEL` (\n" + " `customization_uuid` varchar(255) NOT NULL,\n" + @@ -118,6 +135,39 @@ public class TestSdncUebCallback { " PRIMARY KEY (`customization_uuid`)\n" + ") "; + private static final String CRTBL_VFC_RELATED_NETWORK_ROLE = "CREATE TABLE `VFC_RELATED_NETWORK_ROLE` (\n" + + " `vfc_customization_uuid` varchar(255) NOT NULL,\n" + + " `vm_type` varchar(255) NOT NULL,\n" + + " `network_role` varchar(255) NOT NULL,\n" + + " `related_network_role` varchar(255) NOT NULL,\n" + + " PRIMARY KEY (`vfc_customization_uuid`,`vm_type`,`network_role`,`related_network_role`)\n" + + ") "; + + private static final String CRTBL_VFC_TO_NETWORK_ROLE_MAPPING = "CREATE TABLE `VFC_TO_NETWORK_ROLE_MAPPING` (\n" + + " `seq` int(11) NOT NULL AUTO_INCREMENT,\n" + + " `vfc_customization_uuid` varchar(255) NOT NULL,\n" + + " `network_role` varchar(255) NOT NULL,\n" + + " `vm_type` varchar(255) DEFAULT NULL,\n" + + " `network_role_tag` varchar(255) DEFAULT NULL,\n" + + " `ipv4_count` int(11) NOT NULL,\n" + + " `ipv6_count` int(11) NOT NULL,\n" + + " `ipv4_use_dhcp` char(1) DEFAULT NULL,\n" + + " `ipv6_use_dhcp` char(1) DEFAULT NULL,\n" + + " `ipv4_ip_version` char(1) DEFAULT NULL,\n" + + " `ipv6_ip_version` char(1) DEFAULT NULL,\n" + + " `extcp_subnetpool_id` varchar(512) DEFAULT NULL,\n" + + " `ipv4_floating_count` int(11) DEFAULT NULL,\n" + + " `ipv6_floating_count` int(11) DEFAULT NULL,\n" + + " `ipv4_address_plan_name` varchar(512) DEFAULT NULL,\n" + + " `ipv6_address_plan_name` varchar(512) DEFAULT NULL,\n" + + " `ipv4_vrf_name` varchar(512) DEFAULT NULL,\n" + + " `ipv6_vrf_name` varchar(512) DEFAULT NULL,\n" + + " `subnet_role` varchar(255) DEFAULT NULL,\n" + + " `subinterface_indicator` char(1) DEFAULT NULL,\n" + + " PRIMARY KEY (`seq`),\n" + + " KEY `IX1_VFC_TO_NETWORK_ROLE_MAPPING` (`vfc_customization_uuid`)\n" + + ") "; + private static final String CRTBL_VF_MODEL = "CREATE TABLE `VF_MODEL` (\n" + " `customization_uuid` varchar(255) NOT NULL,\n" + " `model_yaml` longblob,\n" + @@ -137,6 +187,21 @@ public class TestSdncUebCallback { " PRIMARY KEY (`customization_uuid`)\n" + ")"; + private static final String CRTBL_VNF_RELATED_NETWORK_ROLE = "CREATE TABLE `VNF_RELATED_NETWORK_ROLE` (\n" + + " `vnf_customization_uuid` varchar(255) NOT NULL,\n" + + " `network_role` varchar(255) NOT NULL,\n" + + " `related_network_role` varchar(255) NOT NULL,\n" + + " PRIMARY KEY (`vnf_customization_uuid`,`network_role`,`related_network_role`)\n" + + ")"; + + private static final String CRTBL_VF_TO_NETWORK_ROLE_MAPPING = "CREATE TABLE `VF_TO_NETWORK_ROLE_MAPPING` (\n" + + " `seq` int(11) NOT NULL AUTO_INCREMENT,\n" + + " `vf_customization_uuid` varchar(255) NOT NULL,\n" + + " `network_role` varchar(255) NOT NULL,\n" + + " PRIMARY KEY (`seq`),\n" + + " KEY `IX1_VF_TO_NETWORK_ROLE_MAPPING` (`vf_customization_uuid`)\n" + + ")"; + private static final String CRTBL_VF_MODULE_MODEL = "CREATE TABLE `VF_MODULE_MODEL` (\n" + " `customization_uuid` varchar(255) NOT NULL,\n" + " `model_yaml` longblob,\n" + @@ -146,8 +211,82 @@ public class TestSdncUebCallback { " `vf_module_type` varchar(255) DEFAULT NULL,\n" + " `availability_zone_count` int(11) DEFAULT NULL,\n" + " `ecomp_generated_vm_assignments` char(1) DEFAULT NULL,\n" + + " `vf_customization_uuid` char(255) DEFAULT NULL,\n" + + " `vf_module_label` char(255) DEFAULT NULL,\n" + " PRIMARY KEY (`customization_uuid`)\n" + ")"; + + private static final String CRTBL_VF_MODULE_TO_VFC_MAPPING = "CREATE TABLE `VF_MODULE_TO_VFC_MAPPING` (\n" + + " `seq` int(11) NOT NULL AUTO_INCREMENT,\n" + + " `vf_module_customization_uuid` varchar(255) NOT NULL,\n" + + " `vfc_customization_uuid` varchar(255) NOT NULL,\n" + + " `vm_type` varchar(255) NOT NULL,\n" + + " `vm_count` int(11) NOT NULL,\n" + + " PRIMARY KEY (`seq`),\n" + + " KEY `IX1_VF_MODULE_TO_VFC_MAPPING` (`vf_module_customization_uuid`)\n" + + ")"; + + private static final String CRTBL_RESOURCE_GROUP = "CREATE TABLE `RESOURCE_GROUP` (\n" + + " `resource_uuid` varchar(255) NOT NULL,\n" + + " `group_uuid` varchar(255) NOT NULL,\n" + + " `group_customization_uuid` varchar(255) DEFAULT NULL,\n" + + " `group_invariant_uuid` varchar(255) DEFAULT NULL,\n" + + " `group_name` varchar(255) DEFAULT NULL,\n" + + " `version` varchar(255) DEFAULT NULL,\n" + + " `group_type` varchar(255) DEFAULT NULL,\n" + + " PRIMARY KEY (`resource_uuid`,`group_uuid`)\n" + + ")"; + + private static final String CRTBL_RESOURCE_GROUP_TO_TARGET_NODE_MAPPING = "CREATE TABLE `RESOURCE_GROUP_TO_TARGET_NODE_MAPPING` (\n" + + " `group_uuid` varchar(255) NOT NULL,\n" + + " `parent_uuid` varchar(255) NOT NULL,\n" + + " `target_node_uuid` varchar(255) NOT NULL,\n" + + " `target_type` varchar(255) DEFAULT NULL,\n" + + " `table_name` varchar(255) DEFAULT NULL,\n" + + " PRIMARY KEY (`group_uuid`,`parent_uuid`,`target_node_uuid`)\n" + + ")"; + + private static final String CRTBL_RESOURCE_POLICY = "CREATE TABLE `RESOURCE_POLICY` (\n" + + " `resource_uuid` varchar(255) NOT NULL,\n" + + " `policy_uuid` varchar(255) NOT NULL,\n" + + " `policy_invariant_uuid` varchar(255) NOT NULL,\n" + + " `policy_name` varchar(255) DEFAULT NULL,\n" + + " `version` varchar(255) DEFAULT NULL,\n" + + " `policy_type` varchar(255) DEFAULT NULL,\n" + + " `property_type` varchar(255) DEFAULT NULL,\n" + + " `property_source` varchar(255) DEFAULT NULL,\n" + + " `property_name` varchar(255) DEFAULT NULL,\n" + + " `policy_customization_uuid` varchar(255) DEFAULT NULL,\n" + + " PRIMARY KEY (`resource_uuid`,`policy_uuid`)\n" + + ")"; + + private static final String CRTBL_RESOURCE_POLICY_TO_TARGET_NODE_MAPPING = "CREATE TABLE `RESOURCE_POLICY_TO_TARGET_NODE_MAPPING` (\n" + + " `policy_uuid` varchar(255) NOT NULL,\n" + + " `parent_uuid` varchar(255) NOT NULL,\n" + + " `target_node_uuid` varchar(255) NOT NULL,\n" + + " `target_type` varchar(255) DEFAULT NULL,\n" + + " `target_node_customization_uuid` varchar(255) DEFAULT NULL,\n" + + " `policy_customization_uuid` varchar(255) DEFAULT NULL,\n" + + " PRIMARY KEY (`policy_uuid`,`parent_uuid`,`target_node_uuid`)\n" + + ")"; + + private static final String CRTBL_NODE_CAPABILITY = "CREATE TABLE `NODE_CAPABILITY` (\n" + + " `capability_id` int(11) NOT NULL AUTO_INCREMENT,\n" + + " `capability_provider_uuid` varchar(255) NOT NULL,\n" + + " `capability_provider_customization_uuid` varchar(255) NOT NULL,\n" + + " `capability_name` varchar(255) DEFAULT NULL,\n" + + " `capability_type` varchar(255) DEFAULT NULL,\n" + + " PRIMARY KEY (`capability_id`)\n" + + ")"; + + private static final String CRTBL_NODE_CAPABILITY_PROPERTY = "CREATE TABLE `NODE_CAPABILITY_PROPERTY` (\n" + + " `capability_id` int(11) NOT NULL AUTO_INCREMENT,\n" + + " `capability_property_name` varchar(255) NOT NULL,\n" + + " `capability_property_type` varchar(255) DEFAULT NULL,\n" + + " PRIMARY KEY (`capability_id`,`capability_property_name`),\n" + + " CONSTRAINT `NODE_CAPABILITY_PROPERTY_TO_NODE_CAPABILITY` FOREIGN KEY (`capability_id`) REFERENCES `NODE_CAPABILITY` (`capability_id`) ON DELETE CASCADE\n" + + ")"; + private static final Logger LOG = LoggerFactory .getLogger(TestSdncUebCallback.class); @@ -195,11 +334,24 @@ public class TestSdncUebCallback { // Create TOSCA tables dblibSvc.writeData(CRTBL_SERVICE_MODEL, null, null); + dblibSvc.writeData(CRTBL_SERVICE_MODEL_TO_VF_MODEL_MAPPING, null, null); + dblibSvc.writeData(CRTBL_ATTRIBUTE_VALUE_PAIR, null, null); dblibSvc.writeData(CRTBL_NETWORK_MODEL, null, null); dblibSvc.writeData(CRTBL_VFC_MODEL, null, null); + dblibSvc.writeData(CRTBL_VFC_RELATED_NETWORK_ROLE, null, null); + dblibSvc.writeData(CRTBL_VFC_TO_NETWORK_ROLE_MAPPING, null, null); dblibSvc.writeData(CRTBL_VF_MODEL, null, null); + dblibSvc.writeData(CRTBL_VNF_RELATED_NETWORK_ROLE, null, null); + dblibSvc.writeData(CRTBL_VF_TO_NETWORK_ROLE_MAPPING, null, null); dblibSvc.writeData(CRTBL_VF_MODULE_MODEL, null, null); + dblibSvc.writeData(CRTBL_VF_MODULE_TO_VFC_MAPPING, null, null); dblibSvc.writeData(CRTBL_ALLOTTED_RESOURCE_MODEL, null, null); + dblibSvc.writeData(CRTBL_RESOURCE_GROUP, null, null); + dblibSvc.writeData(CRTBL_RESOURCE_GROUP_TO_TARGET_NODE_MAPPING, null, null); + dblibSvc.writeData(CRTBL_RESOURCE_POLICY, null, null); + dblibSvc.writeData(CRTBL_RESOURCE_POLICY_TO_TARGET_NODE_MAPPING, null, null); + dblibSvc.writeData(CRTBL_NODE_CAPABILITY, null, null); + dblibSvc.writeData(CRTBL_NODE_CAPABILITY_PROPERTY, null, null); processLevelArtifactList = new ArrayList<>(); serviceLevelArtifactList = new ArrayList<>(); diff --git a/ueb-listener/src/test/resources/ueb-listener.properties b/ueb-listener/src/test/resources/ueb-listener.properties index 35c380595..c017cbd7b 100755 --- a/ueb-listener/src/test/resources/ueb-listener.properties +++ b/ueb-listener/src/test/resources/ueb-listener.properties @@ -14,8 +14,9 @@ org.onap.ccsdk.sli.northbound.uebclient.polling-interval=30 org.onap.ccsdk.sli.northbound.uebclient.polling-timeout=15 org.onap.ccsdk.sli.northbound.uebclient.client-startup-timeout=60 org.onap.ccsdk.sli.northbound.uebclient.relevant-artifact-types=YANG_XML,VF_LICENSE,TOSCA_TEMPLATE,TOSCA_CSAR,UCPE_LAYER_2_CONFIGURATION +org.onap.ccsdk.sli.northbound.uebclient.relevant-capability-names=RoutingConfiguration,routing_configuration,VLANAssignment,vlan_assignment org.onap.ccsdk.sli.northbound.uebclient.activate-server-tls-auth=false org.onap.ccsdk.sli.northbound.uebclient.keystore-path= org.onap.ccsdk.sli.northbound.uebclient.keystore-password= org.onap.ccsdk.sli.northbound.uebclient.xslt-path-list= -org.onap.ccsdk.sli.northbound.uebclient.artifact-map=src/test/resources/artifact.map \ No newline at end of file +org.onap.ccsdk.sli.northbound.uebclient.artifact-map=src/test/resources/artifact.map diff --git a/version.properties b/version.properties index 71ba554ca..74fd99918 100644 --- a/version.properties +++ b/version.properties @@ -5,7 +5,7 @@ release_name=0 sprint_number=5 -feature_revision=1 +feature_revision=2 base_version=${release_name}.${sprint_number}.${feature_revision} -- cgit 1.2.3-korg From 944a56af64c77e67a2a11a3d963efb18f0c26ab8 Mon Sep 17 00:00:00 2001 From: "lalena.aria" Date: Wed, 14 Aug 2019 19:41:59 +0000 Subject: ASDC lib version updates and 2 bug fixes Changes made: Added remove dots to normalized VF name in SdncVFModel.insertVFModuleData. Fixed path to use_ipv4 and use_ipv6 in SdncNodeModel. Issue-ID: CCSDK-1424 Change-Id: Ib60fb652ee695025a6b505b750667c9c8ff1ab2d Signed-off-by: lalena.aria --- .../java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java | 4 ++-- .../java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java index cf81b3cae..65b20e61f 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java @@ -65,7 +65,7 @@ public class SdncNodeModel extends SdncBaseModel { addParameter("trunk_network_indicator", trunkNetworkIndicator); // extract properties - network_assignments - ipv4_subnet_default_assignment - String useIpv4 = extractBooleanValue(nodeEntity, "network_assignments", "use_ipv4"); + String useIpv4 = extractBooleanValue(nodeEntity, "network_assignments", "ipv4_subnet_default_assignment", "use_ipv4"); addParameter("use_ipv4", useIpv4); addParameter("ipv4_dhcp_enabled", extractBooleanValue(nodeEntity, "network_assignments", "ipv4_subnet_default_assignment", "dhcp_enabled")); addParameter("ipv4_ip_version", extractValue(nodeEntity, "network_assignments", "ipv4_subnet_default_assignment", "ip_version")); @@ -73,7 +73,7 @@ public class SdncNodeModel extends SdncBaseModel { addParameter("eipam_v4_address_plan", extractValue(nodeEntity, "network_assignments", "ipv4_subnet_default_assignment", "ip_network_address_plan")); // extract properties - network_assignments - ipv6_subnet_default_assignment - String useIpv6 = extractBooleanValue(nodeEntity, "network_assignments", "use_ipv6"); + String useIpv6 = extractBooleanValue(nodeEntity, "network_assignments", "ipv6_subnet_default_assignment", "use_ipv6"); addParameter("use_ipv6", useIpv6); addParameter("ipv6_dhcp_enabled", extractBooleanValue(nodeEntity, "network_assignments", "ipv6_subnet_default_assignment", "dhcp_enabled")); addParameter("ipv6_ip_version", extractValue(nodeEntity, "network_assignments", "ipv6_subnet_default_assignment", "ip_version")); diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java index dd93f45db..76e208635 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java @@ -155,7 +155,7 @@ public class SdncVFModel extends SdncBaseModel { for (IEntityDetails vfModule : vfModules){ // If this vfModule name is prefixed with the VF name of the VF being processed, insert this VF Module in VF_MODULE_MODEL - String normailizedVfName = nodeTemplate.getName().toLowerCase().replace(" ", "").replace("-", ""); // need full set of normalization rules from ASDC + String normailizedVfName = nodeTemplate.getName().toLowerCase().replace(" ", "").replace("-", "").replace(".", ""); // need full set of normalization rules from ASDC if (!vfModule.getName().startsWith(normailizedVfName)) { continue; } -- cgit 1.2.3-korg From ab4d7bb7087197977c464031239c202b220e6ad4 Mon Sep 17 00:00:00 2001 From: "lalena.aria" Date: Mon, 16 Sep 2019 18:43:54 +0000 Subject: Migrate SdncVFModel to getEntity Changes made: Replace deprecated APIs with getEntity for processing VF nodes in a model. Replace nodeTemplate with entityDetails in SdncVFModel. Corresponding changes in SdncVFModelTest. Issue-ID: CCSDK-1425 Change-Id: I2175af818c80f4526e0a57a196d03c9fba73bdbf Signed-off-by: lalena.aria --- .../sli/northbound/uebclient/SdncUebCallback.java | 46 +++++++-------- .../sli/northbound/uebclient/SdncVFModel.java | 65 +++++++++++----------- .../sli/northbound/uebclient/SdncVFModelTest.java | 23 +++++--- 3 files changed, 70 insertions(+), 64 deletions(-) (limited to 'ueb-listener/src') diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index d7418824b..a3662604e 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -77,7 +77,6 @@ import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery; import org.onap.sdc.tosca.parser.enums.SdcTypes; import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; -import org.onap.sdc.toscaparser.api.NodeTemplate; import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.sdc.utils.ArtifactTypeEnum; import org.onap.sdc.utils.DistributionActionResultEnum; @@ -745,29 +744,30 @@ public class SdncUebCallback implements INotificationCallback { } } - // Ingest Network (VF) Data - 1707 - List vfNodeTemplatesList = sdcCsarHelper.getServiceVfList(); - - for (NodeTemplate nodeTemplate : vfNodeTemplatesList) { - - SdncVFModel vfNodeModel = null; - try { - vfNodeModel = new SdncVFModel (sdcCsarHelper, nodeTemplate, jdbcDataSource, config); - vfNodeModel.setServiceUUID(serviceModel.getServiceUUID()); - vfNodeModel.setServiceInvariantUUID(serviceModel.getServiceInvariantUUID()); - vfNodeModel.insertData(); - - } catch (IOException e) { - deployStatus = DistributionStatusEnum.DEPLOY_ERROR; - } + // Ingest Network (VF) Data - 1707 / migrate to getEntity - 1911 + // Use getEntity to get all VFs in the service + if (vfEntities != null) { + for (IEntityDetails vfEntity : vfEntities){ - // For each VF, insert VNF Configuration data - DistributionStatusEnum vnfConfigDeployStatus = customProcessVnfConfig(sdcCsarHelper, vfNodeModel, jdbcDataSource); - if (vnfConfigDeployStatus == DistributionStatusEnum.DEPLOY_ERROR) { - deployStatus = DistributionStatusEnum.DEPLOY_ERROR; - } - - } // VF loop + SdncVFModel vfNodeModel = null; + try { + vfNodeModel = new SdncVFModel (sdcCsarHelper, vfEntity, jdbcDataSource, config); + vfNodeModel.setServiceUUID(serviceModel.getServiceUUID()); + vfNodeModel.setServiceInvariantUUID(serviceModel.getServiceInvariantUUID()); + vfNodeModel.insertData(); + + } catch (IOException e) { + deployStatus = DistributionStatusEnum.DEPLOY_ERROR; + } + + // For each VF, insert VNF Configuration data + DistributionStatusEnum vnfConfigDeployStatus = customProcessVnfConfig(sdcCsarHelper, vfNodeModel, jdbcDataSource); + if (vnfConfigDeployStatus == DistributionStatusEnum.DEPLOY_ERROR) { + deployStatus = DistributionStatusEnum.DEPLOY_ERROR; + } + + } // VF loop + } // Ingest Network (PNF) Data - Dublin/1906 diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java index 76e208635..fa54c7c41 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java @@ -32,8 +32,6 @@ import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.elements.queries.EntityQuery; import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery; -import org.onap.sdc.toscaparser.api.Group; -import org.onap.sdc.toscaparser.api.NodeTemplate; import org.onap.sdc.toscaparser.api.Property; import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; @@ -51,19 +49,12 @@ public class SdncVFModel extends SdncBaseModel { private String serviceUUID = null; private String serviceInvariantUUID = null; - public SdncVFModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, DBResourceManager jdbcDataSource, SdncUebConfiguration config) throws IOException { + public SdncVFModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails entityDetails, DBResourceManager jdbcDataSource, SdncUebConfiguration config) throws IOException { - super(sdcCsarHelper, nodeTemplate, jdbcDataSource, config); + super(sdcCsarHelper, entityDetails, jdbcDataSource, config); - // Since SdncVFModel is not yet converted for getEntity, find the entity for this nodeTemplate - EntityQuery vfEntityQuery = EntityQuery.newBuilder(SdcTypes.VF).customizationUUID(getCustomizationUUIDNoQuotes()).build(); - TopologyTemplateQuery vfTopologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).build(); - List vfEntities = sdcCsarHelper.getEntity(vfEntityQuery, vfTopologyTemplateQuery, true); - if (vfEntities != null && !vfEntities.isEmpty()) { - entityDetails = vfEntities.get(0); - } // extract metadata - Metadata metadata = nodeTemplate.getMetaData(); + Metadata metadata = entityDetails.getMetadata(); addParameter("name", extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_NAME)); vendor = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDOR); addParameter("vendor", vendor); @@ -71,30 +62,36 @@ public class SdncVFModel extends SdncBaseModel { addParameter("vendor_version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDORRELEASE)); // extract properties - addParameter("ecomp_generated_naming", extractBooleanValue(nodeTemplate, "nf_naming#ecomp_generated_naming")); - addParameter("naming_policy", extractValue(nodeTemplate, "nf_naming#naming_policy")); - addParameter("nf_type", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)); - addParameter("nf_role", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)); - nfNamingCode = extractValue(nodeTemplate, "nf_naming_code"); + addParameter("ecomp_generated_naming", extractBooleanValue(entityDetails, "nf_naming", "ecomp_generated_naming")); + addParameter("naming_policy", extractValue(entityDetails, "nf_naming", "naming_policy")); + addParameter("nf_type", extractValue(entityDetails, SdcPropertyNames.PROPERTY_NAME_NFTYPE)); + addParameter("nf_role", extractValue(entityDetails, SdcPropertyNames.PROPERTY_NAME_NFROLE)); + nfNamingCode = extractValue(entityDetails, "nf_naming_code"); addParameter("nf_code", nfNamingCode); - addParameter("nf_function", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)); - addIntParameter("avail_zone_max_count", extractValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONEMAXCOUNT)); - addParameter("sdnc_model_name", extractValue(nodeTemplate, "sdnc_model_name")); - addParameter("sdnc_model_version", extractValue(nodeTemplate, "sdnc_model_version")); - addParameter("sdnc_artifact_name", extractValue(nodeTemplate, "sdnc_artifact_name")); + addParameter("nf_function", extractValue(entityDetails, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)); + addIntParameter("avail_zone_max_count", extractValue(entityDetails, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONEMAXCOUNT)); + addParameter("sdnc_model_name", extractValue(entityDetails, "sdnc_model_name")); + addParameter("sdnc_model_version", extractValue(entityDetails, "sdnc_model_version")); + addParameter("sdnc_artifact_name", extractValue(entityDetails, "sdnc_artifact_name")); // store additional properties in ATTRIBUTE_VALUE_PAIR // additional complex properties are extracted via VfcInstanceGroup - - List vfcInstanceGroupListForVf = sdcCsarHelper.getGroupsOfOriginOfNodeTemplateByToscaGroupType(nodeTemplate, "org.openecomp.groups.VfcInstanceGroup"); - for (Group group : vfcInstanceGroupListForVf){ - - String vfcInstanceGroupFunction = extractGetInputValue(group, nodeTemplate, "vfc_instance_group_function"); - addParameter("vfc_instance_group_function", vfcInstanceGroupFunction, attributeValueParams); - String networkCollectionFunction = extractGetInputValue(group, nodeTemplate, "network_collection_function"); - addParameter("network_collection_function", networkCollectionFunction, attributeValueParams); - String initSubinterfaceQuantity = extractGetInputValue(group, nodeTemplate, "init_subinterface_quantity"); - addParameter("init_subinterface_quantity", initSubinterfaceQuantity, attributeValueParams); + EntityQuery entityQuery = EntityQuery.newBuilder("org.openecomp.groups.VfcInstanceGroup").build(); + String vfCustomizationUuid = getCustomizationUUIDNoQuotes(); + TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF) + .customizationUUID(vfCustomizationUuid).build(); + List vfcInstanceGroupListForVf = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false); + if (vfcInstanceGroupListForVf != null) { + + for (IEntityDetails group : vfcInstanceGroupListForVf){ + + String vfcInstanceGroupFunction = extractGetInputValue(group, entityDetails, "vfc_instance_group_function"); + addParameter("vfc_instance_group_function", vfcInstanceGroupFunction, attributeValueParams); + String networkCollectionFunction = extractGetInputValue(group, entityDetails, "network_collection_function"); + addParameter("network_collection_function", networkCollectionFunction, attributeValueParams); + String initSubinterfaceQuantity = extractGetInputValue(group, entityDetails, "init_subinterface_quantity"); + addParameter("init_subinterface_quantity", initSubinterfaceQuantity, attributeValueParams); + } } } @@ -155,7 +152,7 @@ public class SdncVFModel extends SdncBaseModel { for (IEntityDetails vfModule : vfModules){ // If this vfModule name is prefixed with the VF name of the VF being processed, insert this VF Module in VF_MODULE_MODEL - String normailizedVfName = nodeTemplate.getName().toLowerCase().replace(" ", "").replace("-", "").replace(".", ""); // need full set of normalization rules from ASDC + String normailizedVfName = entityDetails.getName().toLowerCase().replace(" ", "").replace("-", "").replace(".", ""); // need full set of normalization rules from ASDC if (!vfModule.getName().startsWith(normailizedVfName)) { continue; } @@ -434,7 +431,7 @@ public class SdncVFModel extends SdncBaseModel { } // For each target node, get External policies - SdcTypes queryType = SdcTypes.valueOf(extractValue(nodeTemplate.getMetaData(), SdcPropertyNames.PROPERTY_NAME_TYPE)); + SdcTypes queryType = SdcTypes.valueOf(extractValue(entityDetails.getMetadata(), SdcPropertyNames.PROPERTY_NAME_TYPE)); insertEntityPolicyData(getCustomizationUUIDNoQuotes(), getUUID().replace("\"", ""), queryType, targetNodeCustomizationUuid, targetNodeUuid, targetNodeType, "org.openecomp.policies.External"); // AFTER getEntity } } diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModelTest.java index 3f795a354..f20c1edbf 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModelTest.java @@ -4,11 +4,15 @@ import static org.junit.Assert.*; import static org.mockito.Mockito.*; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import org.junit.Before; import org.junit.Test; +import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; +import org.onap.sdc.toscaparser.api.Property; import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; @@ -19,17 +23,22 @@ import org.onap.ccsdk.sli.core.dblib.DBResourceManager; @Before public void setUp() throws Exception { ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); - NodeTemplate nodeTemplate = mock(NodeTemplate.class); + IEntityDetails mockEntityDetails = mock(IEntityDetails.class); Metadata mockMetadata = mock(Metadata.class); - DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); + DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); SdncUebConfiguration mockSdncUebConfiguration = mock(SdncUebConfiguration.class); - when(nodeTemplate.getMetaData()).thenReturn(mockMetadata); - when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "customizationUUID")).thenReturn("aaaa-bbbb-cccc-dddd"); - when(mockCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming_code")).thenReturn("test-nf-naming-code"); + Property mockProperty = mock(Property.class); + Map mockProperties = new HashMap(); + when(mockEntityDetails.getMetadata()).thenReturn(mockMetadata); + when(mockEntityDetails.getProperties()).thenReturn(mockProperties); + when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "customizationUUID")).thenReturn("aaaa-bbbb-cccc-dddd"); + when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn("VF"); + mockProperty.setValue("test-nf-naming-code"); + when(mockProperties.get("nf_naming_code")).thenReturn(mockProperty); try { - testSdncVFModel = new SdncVFModel(mockCsarHelper,nodeTemplate,mockDBResourceManager,mockSdncUebConfiguration); + testSdncVFModel = new SdncVFModel(mockCsarHelper,mockEntityDetails,mockDBResourceManager,mockSdncUebConfiguration); testSdncVFModel.setServiceUUID("bbbb-cccc-dddd-eeee"); testSdncVFModel.setServiceInvariantUUID("cccc-dddd-eeee-ffff"); testSdncVFModel.setVendor("Cisco"); -- cgit 1.2.3-korg From 2e7e531a8d80178410a1c4e78e62443c9d9a7684 Mon Sep 17 00:00:00 2001 From: "lalena.aria" Date: Tue, 8 Oct 2019 20:57:16 +0000 Subject: UEB Listener SdncBaseModel add extractValue for CapabilityAssignment Changes made: Add UEB Listener SdncBaseModel add extractValue for extracting properties on CapabilityAssignment objects. Issue-ID: CCSDK-1820 Change-Id: I10bbced5e9279bc8ef2bf48a87b2e2de0cb74942 Signed-off-by: lalena.aria --- dmaap-listener/pom.xml | 2 +- ueb-listener/pom.xml | 2 +- .../ccsdk/sli/northbound/uebclient/SdncBaseModel.java | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) (limited to 'ueb-listener/src') diff --git a/dmaap-listener/pom.xml b/dmaap-listener/pom.xml index f403fc3df..4d2395a8e 100755 --- a/dmaap-listener/pom.xml +++ b/dmaap-listener/pom.xml @@ -24,7 +24,7 @@ ${maven.build.timestamp} ${project.version}-${build.number} - 0.6.1-SNAPSHOT + 0.7.0-SNAPSHOT ${project.version} diff --git a/ueb-listener/pom.xml b/ueb-listener/pom.xml index 00d7ead93..9e7e41691 100755 --- a/ueb-listener/pom.xml +++ b/ueb-listener/pom.xml @@ -22,7 +22,7 @@ yyyyMMdd'T'HHmmss'Z' ${maven.build.timestamp} ${project.version}-${build.number} - 0.6.1-SNAPSHOT + 0.7.0-SNAPSHOT ${project.version} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index d3fef173f..7ab431dac 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -794,6 +794,23 @@ public class SdncBaseModel { } } + protected String extractValue (CapabilityAssignment capability, String path, String name) { + String value = ""; + + if (capability.getProperties().containsKey(path)) { + Property property = capability.getProperties().get(path); + if (property != null && !property.getLeafPropertyValue(name).isEmpty()) { + value = property.getLeafPropertyValue(name).get(0); + } + } + + if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { + return value; + } else { + return ""; + } + } + protected String extractBooleanValue (NodeTemplate nodeTemplate, String name) { String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); if (value != null && !value.isEmpty()) { -- cgit 1.2.3-korg From 84db6f1d6b4c975eba30dc45556ada876c262a87 Mon Sep 17 00:00:00 2001 From: "lalena.aria" Date: Fri, 1 Nov 2019 18:19:55 +0000 Subject: UEB Listener Final cleanup of deprecated sdc-tosca parser APIs Changes made: Replace references to all deprecated sdc-tosca parser APIs and replace with Entity-based equivalent. Changes are primarily in SdncBaseModel and junit test files. Issue-ID: CCSDK-1880 Change-Id: I5d7f12cdbebcfcb7d2487b6474cd7eb92eb32b9b Signed-off-by: lalena.aria --- .../onap/ccsdk/sli/northbound/TestLcmProvider.java | 3 +- ueb-listener/pom.xml | 6 + .../sli/northbound/uebclient/SdncBaseModel.java | 167 ++++++++------------- .../sli/northbound/uebclient/SdncNodeModel.java | 73 ++++----- .../sli/northbound/uebclient/SdncUebCallback.java | 2 +- .../sli/northbound/uebclient/SdncARModelTest.java | 6 +- .../northbound/uebclient/SdncGroupModelTest.java | 6 + .../northbound/uebclient/SdncNodeModelTest.java | 2 +- .../sli/northbound/uebclient/SdncPNFModelTest.java | 2 +- .../northbound/uebclient/SdncServiceModelTest.java | 9 +- .../sli/northbound/uebclient/SdncVFCModelTest.java | 10 +- .../sli/northbound/uebclient/SdncVFModelTest.java | 4 +- .../uebclient/SdncVFModuleModelTest.java | 11 +- .../northbound/uebclient/TestSdncUebCallback.java | 2 +- 14 files changed, 138 insertions(+), 165 deletions(-) (limited to 'ueb-listener/src') diff --git a/lcm/provider/src/test/java/org/onap/ccsdk/sli/northbound/TestLcmProvider.java b/lcm/provider/src/test/java/org/onap/ccsdk/sli/northbound/TestLcmProvider.java index 002e05ed4..0e4413a64 100644 --- a/lcm/provider/src/test/java/org/onap/ccsdk/sli/northbound/TestLcmProvider.java +++ b/lcm/provider/src/test/java/org/onap/ccsdk/sli/northbound/TestLcmProvider.java @@ -22,6 +22,7 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicLoader; import org.onap.ccsdk.sli.core.sli.SvcLogicParser; import org.onap.ccsdk.sli.core.sli.SvcLogicStore; import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory; +import org.onap.ccsdk.sli.core.sli.provider.SvcLogicClassResolver; import org.onap.ccsdk.sli.core.sli.provider.base.BlockNodeExecutor; import org.onap.ccsdk.sli.core.sli.provider.base.CallNodeExecutor; import org.onap.ccsdk.sli.core.sli.provider.base.ConfigureNodeExecutor; @@ -171,7 +172,7 @@ public class TestLcmProvider { loader.loadAndActivate(); // Create a ServiceLogicService - SvcLogicServiceImpl svc = new SvcLogicServiceImpl(new SvcLogicPropertiesProviderImpl()); + SvcLogicServiceImpl svc = new SvcLogicServiceImpl(new SvcLogicPropertiesProviderImpl(), new SvcLogicClassResolver()); // Finally ready to create sliapiProvider LcmSliClient client = new LcmSliClient(svc); diff --git a/ueb-listener/pom.xml b/ueb-listener/pom.xml index 9e7e41691..8bd81fee5 100755 --- a/ueb-listener/pom.xml +++ b/ueb-listener/pom.xml @@ -44,6 +44,7 @@ org.onap.sdc.sdc-distribution-client sdc-distribution-client + 1.4.1-SNAPSHOT compile @@ -91,6 +92,11 @@ org.onap.ccsdk.sli.core dblib-provider + + commons-codec + commons-codec + 1.13 + diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java index 7ab431dac..bced6a830 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java @@ -39,9 +39,6 @@ import org.onap.sdc.tosca.parser.enums.SdcTypes; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; import org.onap.sdc.toscaparser.api.CapabilityAssignment; import org.onap.sdc.toscaparser.api.CapabilityAssignments; -import org.onap.sdc.toscaparser.api.Group; -import org.onap.sdc.toscaparser.api.NodeTemplate; -import org.onap.sdc.toscaparser.api.Policy; import org.onap.sdc.toscaparser.api.Property; import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; @@ -74,37 +71,22 @@ public class SdncBaseModel { protected ISdcCsarHelper sdcCsarHelper = null; protected static DBResourceManager jdbcDataSource = null; protected static SdncUebConfiguration config = null; - protected NodeTemplate nodeTemplate = null; protected IEntityDetails entityDetails = null; - - public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, DBResourceManager jdbcDataSource) { - this (sdcCsarHelper, nodeTemplate); - this.sdcCsarHelper = sdcCsarHelper; - this.nodeTemplate = nodeTemplate; - this.jdbcDataSource = jdbcDataSource; - } - public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate, DBResourceManager jdbcDataSource, SdncUebConfiguration config) throws IOException { - this (sdcCsarHelper, nodeTemplate); - this.sdcCsarHelper = sdcCsarHelper; - this.nodeTemplate = nodeTemplate; - this.jdbcDataSource = jdbcDataSource; - this.config = config; - } public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails entityDetails, DBResourceManager jdbcDataSource, SdncUebConfiguration config) throws IOException { this (sdcCsarHelper, entityDetails); this.sdcCsarHelper = sdcCsarHelper; this.entityDetails = entityDetails; - this.jdbcDataSource = jdbcDataSource; - this.config = config; + SdncBaseModel.jdbcDataSource = jdbcDataSource; + SdncBaseModel.config = config; } public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata, DBResourceManager jdbcDataSource) { params = new HashMap(); this.sdcCsarHelper = sdcCsarHelper; - this.jdbcDataSource = jdbcDataSource; + SdncBaseModel.jdbcDataSource = jdbcDataSource; // extract service metadata invariantUUID = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID); @@ -116,28 +98,6 @@ public class SdncBaseModel { addParameter(PARAM_TYPE_KEY,extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_TYPE)); addParameter(PARAM_CATEGORY_KEY,extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_CATEGORY)); } - - public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { - - params = new HashMap(); - attributeValueParams = new HashMap(); - this.sdcCsarHelper = sdcCsarHelper; - this.nodeTemplate = nodeTemplate; - - // extract common nodeTemplate metadata - Metadata metadata = nodeTemplate.getMetaData(); - customizationUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); - invariantUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID); - addParameter(PARAM_INVARIANT_UUID_KEY, invariantUUID); - UUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_UUID); - addParameter(PARAM_UUID_KEY, UUID); - addParameter(PARAM_VERSION_KEY, extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VERSION)); - - // extract common nodeTemplate properties - //addParameter("ecomp_generated_naming", extractValue (nodeTemplate, "naming#ecompnaming")); // should be extractBooleanValue? - //addParameter("naming_policy", extractValue (nodeTemplate, "naming#namingpolicy")); - - } public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails entityDetails) { @@ -192,8 +152,8 @@ public class SdncBaseModel { String metadataType = ""; if (!type.isEmpty()) metadataType = type; else { - Metadata metadata = nodeTemplate.getMetaData(); - metadataType = sdcCsarHelper.getMetadataPropertyValue(metadata, PARAM_TYPE_KEY); + Metadata metadata = entityDetails.getMetadata(); + metadataType = extractValue (metadata, PARAM_TYPE_KEY); } // Clean up all attributes for this resource @@ -466,7 +426,7 @@ public class SdncBaseModel { CachedRowSet rowData = getToscaData("NODE_CAPABILITY", nodeCapabilityParams); rowData.first(); int capabilityIdint = rowData.getInt("capability_id"); - capabilityId = capabilityId.valueOf(capabilityIdint); + capabilityId = String.valueOf(capabilityIdint); } catch (IOException | SQLException e) { LOG.error("Could not insert Tosca CSAR data into the NODE_CAPABILITY table"); @@ -477,12 +437,11 @@ public class SdncBaseModel { } } - protected void insertNodeCapabilitiesEntityData (Map capabilities) throws IOException { + protected void insertNodeCapabilitiesEntityData (List capabilities) throws IOException { // Process the capabilities - for (Map.Entry entry : capabilities.entrySet()) { - CapabilityAssignment capability = entry.getValue(); - + for (CapabilityAssignment capability : capabilities) { + // Insert into NODE_CAPABILITY: // capability_id (generated) // capability_provider_uuid - UUID of this node @@ -528,7 +487,7 @@ public class SdncBaseModel { CachedRowSet rowData = getToscaData("NODE_CAPABILITY", nodeCapabilityParams); rowData.first(); int capabilityIdint = rowData.getInt("capability_id"); - capabilityId = capabilityId.valueOf(capabilityIdint); + capabilityId = String.valueOf(capabilityIdint); } catch (IOException | SQLException e) { LOG.error("Could not insert Tosca CSAR data into the NODE_CAPABILITY table"); @@ -596,7 +555,7 @@ public class SdncBaseModel { } protected String extractValue (Metadata metadata, String name) { - String value = sdcCsarHelper.getMetadataPropertyValue(metadata, name); + String value = metadata.getValue(name); if (value != null) { return value; } else { @@ -605,7 +564,7 @@ public class SdncBaseModel { } protected String extractBooleanValue (Metadata metadata, String name) { - String value = sdcCsarHelper.getMetadataPropertyValue(metadata, name); + String value = metadata.getValue(name); if (value != null && !value.isEmpty()) { return value.contains("true") ? "Y" : "N"; } else { @@ -614,16 +573,7 @@ public class SdncBaseModel { } public static String extractValue (ISdcCsarHelper sdcCsarHelper, Metadata metadata, String name) { - String value = sdcCsarHelper.getMetadataPropertyValue(metadata, name); - if (value != null) { - return value; - } else { - return ""; - } - } - - protected String extractValue (NodeTemplate nodeTemplate, String name) { - String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); + String value = metadata.getValue(name); if (value != null) { return value; } else { @@ -676,6 +626,18 @@ public class SdncBaseModel { } } + protected String extractValue (IEntityDetails entityDetails, String path1, String path2, String path3, String name) { + String value = ""; + + value = extractNestedValue (entityDetails, path1, path2, path3, name); + + if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { + return value; + } else { + return ""; + } + } + protected String extractBooleanValue (IEntityDetails entityDetails, String path1, String path2, String name) { String value = ""; @@ -707,6 +669,28 @@ public class SdncBaseModel { return value; } + protected String extractNestedValue (IEntityDetails entityDetails, String path1, String path2, String path3, String name) { + String value = ""; + + if (entityDetails.getProperties().containsKey(path1)) { + Property path1Property = entityDetails.getProperties().get(path1); + if (path1Property != null) { + Map path1PropertyValue = (Map) path1Property.getValue(); + if (path1PropertyValue.containsKey(path2)) { + Map path2PropertyValue = (Map) path1PropertyValue.get(path2); + if (path2PropertyValue != null && path2PropertyValue.containsKey(path3)) { + Map path3PropertyValue = (Map) path2PropertyValue.get(path3); + if (path3PropertyValue != null && path3PropertyValue.containsKey(name)) { + value = path3PropertyValue.get(name).toString(); + } + } + } + } + } + + return value; + } + protected String extractIntegerValue (Property property, String name) { String value = ""; @@ -758,36 +742,15 @@ public class SdncBaseModel { } - // Remove this after migrate SdncVFModel to getEntity - protected String extractGetInputValue (Group group, NodeTemplate nodeTemplate, String name) { - - String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, extractGetInputName (group, name)); - if (value != null) { - return value; - } else { - return ""; - } - } - - // Remove this after migrate SdncVFModel to getEntity - protected String extractGetInputName (Group group, String name) { + protected String extractValue (CapabilityAssignment capability, String name) { + String value = ""; - String getInputName = name; - String groupProperty = sdcCsarHelper.getGroupPropertyLeafValue(group, name); - if (groupProperty != null) { - int getInputIndex = groupProperty.indexOf("{get_input="); - if (getInputIndex > -1) { - getInputName = groupProperty.substring(getInputIndex+11, groupProperty.length()-1); - } - } + if (capability.getProperties().containsKey(name)) { + Property property = capability.getProperties().get(name); + value = property.getLeafPropertyValue(name).get(0); + } - return getInputName; - - } - - protected String extractValue (CapabilityAssignment capability, String name) { - String value = sdcCsarHelper.getCapabilityPropertyLeafValue(capability, name); - if (value != null) { + if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { return value; } else { return ""; @@ -810,15 +773,6 @@ public class SdncBaseModel { return ""; } } - - protected String extractBooleanValue (NodeTemplate nodeTemplate, String name) { - String value = sdcCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, name); - if (value != null && !value.isEmpty()) { - return value.contains("true") ? "Y" : "N"; - } else { - return ""; - } - } protected String extractBooleanValue (IEntityDetails entityDetails, String name) { String value = null; @@ -854,8 +808,15 @@ public class SdncBaseModel { } } - protected Object extractObjectValue (NodeTemplate nodeTemplate, String name) { - Object value = sdcCsarHelper.getNodeTemplatePropertyValueAsObject(nodeTemplate, name); + protected Object extractObjectValue (IEntityDetails entityDetails, String name) { + Object value = ""; + if (entityDetails.getProperties().containsKey(name)) { + Property property = entityDetails.getProperties().get(name); + if (property != null && property.getValue() != null) { + value = property.getValue(); + } + } + if (value != null) { return value; } else { @@ -1030,7 +991,7 @@ public class SdncBaseModel { protected boolean cleanupExistingToscaData(String tableName, Map keyParams) throws IOException { - return SdncBaseModel.cleanupExistingToscaData(this.jdbcDataSource, tableName, keyParams); + return SdncBaseModel.cleanupExistingToscaData(SdncBaseModel.jdbcDataSource, tableName, keyParams); } public static boolean cleanupExistingToscaData(DBResourceManager jdbcDataSource, String tableName, Map keyParams) throws IOException diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java index 65b20e61f..8e790d9be 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java @@ -137,44 +137,47 @@ public class SdncNodeModel extends SdncBaseModel { public void insertRelatedNetworkRoleData () throws IOException { - if (entityDetails.getProperties().containsKey("related_networks")) { + if (entityDetails.getProperties().containsKey("network_assignments")) { - Property relatedNetworksProperty = entityDetails.getProperties().get("related_networks"); - List relatedNetworkRoles = relatedNetworksProperty.getLeafPropertyValue("related_network_role"); + Map networkAssignmentsPropertyValue = (Map) entityDetails.getProperties().get("network_assignments").getValue(); - String networkModelCustomizationUUID = getCustomizationUUID(); - - try { - cleanUpExistingToscaData("RELATED_NETWORK_ROLE", "network_model_customization_uuid", networkModelCustomizationUUID); - } catch (IOException e) { - LOG.error("Could not clean up Tosca CSAR data in the RELATED_NETWORK_ROLE table"); - throw new IOException (e); - } - - for (String relatedNetworkRole : relatedNetworkRoles) { - - LOG.debug("Node Template [" + entityDetails.getName() + "], property [" + "related_network_role" + "] property value: " + relatedNetworkRole); - - try { - // Table cleanup RELATED_NETWORK_ROLE occurs per network - // If related_network_role for this service already exist in RELATED_NETWORK_ROLE, don't attempt insertion - Map relatedNetworkRoleParamsCheck = new HashMap(); - addParameter("related_network_role", relatedNetworkRole, relatedNetworkRoleParamsCheck); - addParameter("network_model_customization_uuid", networkModelCustomizationUUID, relatedNetworkRoleParamsCheck); - if (checkForExistingToscaData("RELATED_NETWORK_ROLE", relatedNetworkRoleParamsCheck) == false) { - relatedNetworkRoleParamsCheck.remove("related_network_role"); - LOG.info("Call insertToscaData for RELATED_NETWORK_ROLE where network_model_customization_uuid = " + networkModelCustomizationUUID); - insertToscaData(buildSql("RELATED_NETWORK_ROLE", "related_network_role", "\"" + relatedNetworkRole + "\"", model_yaml, relatedNetworkRoleParamsCheck), null); + if (networkAssignmentsPropertyValue != null && networkAssignmentsPropertyValue.containsKey("related_networks")) { + + ArrayList> relatedNetworkList = (ArrayList) networkAssignmentsPropertyValue.get("related_networks"); + String networkModelCustomizationUUID = getCustomizationUUID(); + + try { + cleanUpExistingToscaData("RELATED_NETWORK_ROLE", "network_model_customization_uuid", networkModelCustomizationUUID); + } catch (IOException e) { + LOG.error("Could not clean up Tosca CSAR data in the RELATED_NETWORK_ROLE table"); + throw new IOException (e); + } + + for (Map relatedNetworkValue : relatedNetworkList) { + String relatedNetworkRoleValue = relatedNetworkValue.get("related_network_role"); + LOG.debug("Node Template [" + entityDetails.getName() + "], property [" + "related_network_role" + "] property value: " + relatedNetworkRoleValue); + + try { + // Table cleanup RELATED_NETWORK_ROLE occurs per network + // If related_network_role for this service already exist in RELATED_NETWORK_ROLE, don't attempt insertion + Map relatedNetworkRoleParamsCheck = new HashMap(); + addParameter("related_network_role", relatedNetworkRoleValue, relatedNetworkRoleParamsCheck); + addParameter("network_model_customization_uuid", networkModelCustomizationUUID, relatedNetworkRoleParamsCheck); + if (checkForExistingToscaData("RELATED_NETWORK_ROLE", relatedNetworkRoleParamsCheck) == false) { + relatedNetworkRoleParamsCheck.remove("related_network_role"); + LOG.info("Call insertToscaData for RELATED_NETWORK_ROLE where network_model_customization_uuid = " + networkModelCustomizationUUID); + insertToscaData(buildSql("RELATED_NETWORK_ROLE", "related_network_role", "\"" + relatedNetworkRoleValue + "\"", model_yaml, relatedNetworkRoleParamsCheck), null); + } + } catch (IOException e) { + LOG.debug("Could not insert Tosca CSAR data into the RELATED_NETWORK_ROLE table"); + throw new IOException (e); } - } catch (IOException e) { - LOG.debug("Could not insert Tosca CSAR data into the RELATED_NETWORK_ROLE table"); - throw new IOException (e); - } - } - } - else { - LOG.debug("Node Template [" + entityDetails.getName() + "], property [" + "related_networks" + "] property value: " + null); - } + } + } + else { + LOG.debug("Node Template [" + entityDetails.getName() + "], property [" + "related_networks" + "] property value: " + null); + } + } } diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java index a3662604e..8c3a290e0 100644 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java @@ -195,7 +195,7 @@ public class SdncUebCallback implements INotificationCallback { } private final IDistributionClient client; - private final SdncUebConfiguration config; + protected final SdncUebConfiguration config; private LinkedList deployList[]; diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java index 734dee229..11556df1b 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java @@ -9,7 +9,7 @@ import org.junit.Before; import org.junit.Test; import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; public class SdncARModelTest { @@ -19,10 +19,12 @@ import org.onap.ccsdk.sli.core.dblib.DBResourceManager; @Before public void setUp() throws Exception { ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); - NodeTemplate nodeTemplate = mock(NodeTemplate.class); + Metadata mockMetadata = mock(Metadata.class); IEntityDetails mockEntityDetails = mock(IEntityDetails.class); DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); SdncUebConfiguration mockSdncUebConfiguration = mock(SdncUebConfiguration.class); + + when(mockEntityDetails.getMetadata()).thenReturn(mockMetadata); testSdncARModel = new SdncARModel(mockCsarHelper,mockEntityDetails,mockDBResourceManager,mockSdncUebConfiguration); assertNotNull(testSdncARModel); diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModelTest.java index 3b2cd96a1..0dfbf087f 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModelTest.java @@ -8,6 +8,7 @@ import java.io.IOException; import org.junit.Test; import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; public class SdncGroupModelTest { @@ -17,8 +18,13 @@ import org.onap.ccsdk.sli.core.dblib.DBResourceManager; ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); IEntityDetails group = mock(IEntityDetails.class); IEntityDetails entityDetails = mock(IEntityDetails.class); + Metadata mockMetadata = mock(Metadata.class); DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); SdncUebConfiguration mockSdncUebConfiguration = mock(SdncUebConfiguration.class); + + when(entityDetails.getMetadata()).thenReturn(mockMetadata); + when(group.getMetadata()).thenReturn(mockMetadata); + SdncGroupModel testSdncGroupModel = null; try { testSdncGroupModel = new SdncGroupModel(mockCsarHelper,group,entityDetails,mockSdncUebConfiguration,mockDBResourceManager); diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java index 9f859e793..3f4728f07 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java @@ -26,7 +26,7 @@ public class SdncNodeModelTest { DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); when(entityDetails.getMetadata()).thenReturn(mockMetadata); - when(isdcCsarHelper.getMetadataPropertyValue(mockMetadata, "customizationUUID")).thenReturn("aaaa-bbbb-cccc-dddd"); + when(mockMetadata.getValue("customizationUUID")).thenReturn("aaaa-bbbb-cccc-dddd"); sdncNodeModel = new SdncNodeModel(isdcCsarHelper, entityDetails, mockDBResourceManager, config); sdncNodeModel.setServiceUUID("0e8d757f-1c80-40af-85de-31d64f1f5af8"); diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncPNFModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncPNFModelTest.java index d4c06b049..97c3942dc 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncPNFModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncPNFModelTest.java @@ -31,7 +31,7 @@ import org.onap.ccsdk.sli.core.dblib.DBResourceManager; SdncUebConfiguration mockSdncUebConfiguration = mock(SdncUebConfiguration.class); when(mockEntityDetails.getMetadata()).thenReturn(mockMetadata); - when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "customizationUUID")).thenReturn("aaaa-bbbb-cccc-dddd"); + when(mockMetadata.getValue("customizationUUID")).thenReturn("aaaa-bbbb-cccc-dddd"); mockProperty.setValue("test-nf-naming-code"); when(mockProperties.get("nf_naming_code")).thenReturn(mockProperty); diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModelTest.java index af17e2291..b86a8e131 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModelTest.java @@ -3,8 +3,6 @@ package org.onap.ccsdk.sli.northbound.uebclient; import static org.junit.Assert.*; import static org.mockito.Mockito.*; -import java.io.IOException; - import org.junit.Before; import org.junit.Test; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; @@ -21,10 +19,9 @@ import org.onap.sdc.toscaparser.api.elements.Metadata; DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); Metadata mockMetadata = mock(Metadata.class); - when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "UUID")).thenReturn("aaaa-bbbb-cccc-dddd"); - when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "invariantUUID")).thenReturn("bbbb-cccc-dddd-eeee"); - when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "namingPolicy")).thenReturn("test-naming-policy"); - + when(mockMetadata.getValue("UUID")).thenReturn("aaaa-bbbb-cccc-dddd"); + when(mockMetadata.getValue("invariantUUID")).thenReturn("bbbb-cccc-dddd-eeee"); + when(mockMetadata.getValue("namingPolicy")).thenReturn("test-naming-policy"); testSdncServiceModel = new SdncServiceModel(mockCsarHelper,mockMetadata,mockDBResourceManager); assertNotNull(testSdncServiceModel); diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java index 768eed86c..f8680522f 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java @@ -7,36 +7,29 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Map; import java.util.HashMap; -import java.util.ArrayList; import org.junit.Before; import org.junit.Test; import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.toscaparser.api.NodeTemplate; import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.ccsdk.sli.core.dblib.DBResourceManager; public class SdncVFCModelTest { SdncVFCModel testSdncVFCModel; - NodeTemplate mockVFCNodeTemplate = null; IEntityDetails mockEntityDetails = null; @Before public void setup() { ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); - NodeTemplate mockNodeTemplate = mock(NodeTemplate.class); mockEntityDetails = mock(IEntityDetails.class); - mockVFCNodeTemplate = mock(NodeTemplate.class); Metadata mockMetadata = mock(Metadata.class); DBResourceManager mockDBResourceManager = mock(DBResourceManager.class); SdncUebConfiguration mockSdncUebConfiguration = mock(SdncUebConfiguration.class); - when(mockNodeTemplate.getMetaData()).thenReturn(mockMetadata); when(mockEntityDetails.getMetadata()).thenReturn(mockMetadata); - when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "customizationUUID")).thenReturn("aaaa-bbbb-cccc-dddd"); - when(mockCsarHelper.getNodeTemplatePropertyLeafValue(mockNodeTemplate, "nfc_naming_code")).thenReturn("test-nfc-naming-code"); + when(mockMetadata.getValue("customizationUUID")).thenReturn("aaaa-bbbb-cccc-dddd"); Map> cpPropertiesMap = new HashMap>(); Map propertiesMap = new HashMap(); @@ -53,7 +46,6 @@ public class SdncVFCModelTest { propertiesMap.put("ip_requirements", ipRequirementsList); cpPropertiesMap.put("cp-node-1", propertiesMap); - when(mockCsarHelper.getCpPropertiesFromVfcAsObject(mockVFCNodeTemplate)).thenReturn(cpPropertiesMap); try { testSdncVFCModel = new SdncVFCModel(mockCsarHelper, mockEntityDetails, mockDBResourceManager, mockSdncUebConfiguration); diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModelTest.java index f20c1edbf..93f7d3467 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModelTest.java @@ -33,8 +33,8 @@ import org.onap.ccsdk.sli.core.dblib.DBResourceManager; when(mockEntityDetails.getMetadata()).thenReturn(mockMetadata); when(mockEntityDetails.getProperties()).thenReturn(mockProperties); - when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "customizationUUID")).thenReturn("aaaa-bbbb-cccc-dddd"); - when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn("VF"); + when(mockMetadata.getValue("customizationUUID")).thenReturn("aaaa-bbbb-cccc-dddd"); + when(mockMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn("VF"); mockProperty.setValue("test-nf-naming-code"); when(mockProperties.get("nf_naming_code")).thenReturn(mockProperty); try { diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java index 846b79b49..e19e8dfa9 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java @@ -1,12 +1,13 @@ package org.onap.ccsdk.sli.northbound.uebclient; import static org.junit.Assert.*; -import static org.mockito.Mockito.mock; - +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import org.junit.Test; import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.toscaparser.api.Group; +import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.ccsdk.sli.northbound.uebclient.SdncVFModel; public class SdncVFModuleModelTest { @@ -14,8 +15,12 @@ public class SdncVFModuleModelTest { @Test public void testSdncVFModuleModelConstructor() { IEntityDetails mockEntity = mock(IEntityDetails.class); + Metadata mockMetadata = mock(Metadata.class); ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class); SdncVFModel mockSdncVFModel = mock(SdncVFModel.class); + + when(mockEntity.getMetadata()).thenReturn(mockMetadata); + SdncVFModuleModel testSdncVFModel = new SdncVFModuleModel(mockCsarHelper, mockEntity, mockSdncVFModel); assertNotNull(testSdncVFModel); } diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java index 2c44ba732..24dfd36b1 100644 --- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java +++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java @@ -416,7 +416,7 @@ public class TestSdncUebCallback { IDistributionClient iDistClient = mock(IDistributionClient.class); SdncUebCallback cb = new SdncUebCallback(iDistClient, config); - cb.setJdbcDataSource(dblibSvc); + SdncUebCallback.setJdbcDataSource(dblibSvc); INotificationData iData = mock(INotificationData.class); /*IArtifactInfo iArtifactInfo = mock(IArtifactInfo.class); -- cgit 1.2.3-korg From b39dc2b5bc842824b6bc2b85bc4f92eedb6d454b Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Fri, 15 May 2020 10:10:57 -0400 Subject: Change log4j2 configuration Changed log4j2 configuration from using properties files to using XML, which corrected the issue we were seeing with log files being created but empty. Also updated sdc.client.version to use released version 1.4.2 instead of 1.4.2-SNAPSHOT, which no longer exists - causing a compile error. Change-Id: I7040453ccbc3b3fd246a07fa3287c7d4d331fb34 Issue-ID: SDNC-1167 Signed-off-by: Dan Timoney --- dmaap-listener/src/main/resources/log4j.properties | 37 ---------------------- dmaap-listener/src/main/resources/log4j2.xml | 26 +++++++++++++++ ueb-listener/pom.xml | 4 +-- ueb-listener/src/main/resources/log4j.properties | 37 ---------------------- ueb-listener/src/main/resources/log4j2.xml | 26 +++++++++++++++ 5 files changed, 54 insertions(+), 76 deletions(-) delete mode 100644 dmaap-listener/src/main/resources/log4j.properties create mode 100644 dmaap-listener/src/main/resources/log4j2.xml delete mode 100644 ueb-listener/src/main/resources/log4j.properties create mode 100644 ueb-listener/src/main/resources/log4j2.xml (limited to 'ueb-listener/src') diff --git a/dmaap-listener/src/main/resources/log4j.properties b/dmaap-listener/src/main/resources/log4j.properties deleted file mode 100644 index 8db00762b..000000000 --- a/dmaap-listener/src/main/resources/log4j.properties +++ /dev/null @@ -1,37 +0,0 @@ -### -# ============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========================================================= -### - -log4j.rootLogger=DEBUG,CONSOLE,LOGFILE - -# CONSOLE is set to be a ConsoleAppender using a PatternLayout. -log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender -log4j.appender.CONSOLE.Threshold=ERROR -log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout -log4j.appender.CONSOLE.layout.ConversionPattern=%p %d{yyyy-MM-dd HH:mm:ss.SSS Z} %c{1} - %m%n - -# LOGFILE is set to be a File appender using a PatternLayout. -log4j.appender.LOGFILE=org.apache.log4j.RollingFileAppender -log4j.appender.LOGFILE.File=/opt/app/dmaap-listener/logs/dmaap-listener.log -log4j.appender.LOGFILE.Append=true -log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout -log4j.appender.LOGFILE.layout.ConversionPattern=%p %d{yyyy-MM-dd HH:mm:ss.SSS Z} %c{1} - %m%n -log4j.appender.LOGFILE.MaxFileSize=10MB -log4j.appender.LOGFILE.MaxBackupIndex=10 diff --git a/dmaap-listener/src/main/resources/log4j2.xml b/dmaap-listener/src/main/resources/log4j2.xml new file mode 100644 index 000000000..01ee93714 --- /dev/null +++ b/dmaap-listener/src/main/resources/log4j2.xml @@ -0,0 +1,26 @@ + + + + + $${env:LOGDIR:-logs} + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ueb-listener/pom.xml b/ueb-listener/pom.xml index 42546fd7b..1df9f35b2 100755 --- a/ueb-listener/pom.xml +++ b/ueb-listener/pom.xml @@ -24,8 +24,8 @@ ${project.version}-${build.number} ${project.version} ${project.version} - 1.4.1-SNAPSHOT - 1.6.5 + 1.4.1 + 1.6.5 diff --git a/ueb-listener/src/main/resources/log4j.properties b/ueb-listener/src/main/resources/log4j.properties deleted file mode 100644 index f2f4ed26b..000000000 --- a/ueb-listener/src/main/resources/log4j.properties +++ /dev/null @@ -1,37 +0,0 @@ -### -# ============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========================================================= -### - -log4j.rootLogger=DEBUG,CONSOLE,LOGFILE - -# CONSOLE is set to be a ConsoleAppender using a PatternLayout. -log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender -log4j.appender.CONSOLE.Threshold=ERROR -log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout -log4j.appender.CONSOLE.layout.ConversionPattern=%p %d{yyyy-MM-dd HH:mm:ss.SSS Z} %c{1} - %m%n - -# LOGFILE is set to be a File appender using a PatternLayout. -log4j.appender.LOGFILE=org.apache.log4j.RollingFileAppender -log4j.appender.LOGFILE.File=/opt/app/ueb-listener/logs/ueb-listener.log -log4j.appender.LOGFILE.Append=true -log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout -log4j.appender.LOGFILE.layout.ConversionPattern=%p %d{yyyy-MM-dd HH:mm:ss.SSS Z} %c{1} - %m%n -log4j.appender.LOGFILE.MaxFileSize=10MB -log4j.appender.LOGFILE.MaxBackupIndex=10 diff --git a/ueb-listener/src/main/resources/log4j2.xml b/ueb-listener/src/main/resources/log4j2.xml new file mode 100644 index 000000000..23ab908a5 --- /dev/null +++ b/ueb-listener/src/main/resources/log4j2.xml @@ -0,0 +1,26 @@ + + + + + $${env:LOGDIR:-logs} + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit 1.2.3-korg