summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlalena.aria <lalena.aria@att.com>2018-07-18 16:16:58 -0400
committerlalena.aria <lalena.aria@att.com>2018-07-19 13:06:54 -0400
commit18cc5f6913e7a71df1945e5e29f394b285867cb3 (patch)
tree37546fd7ac7ca88d17474f1980eaa1b71a0b22c1
parent16ecee44bc14dcb0a128cfdabf0ae8b17f1db057 (diff)
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 <lalena.aria@att.com>
-rwxr-xr-xueb-listener/pom.xml2
-rw-r--r--ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java35
-rw-r--r--ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java822
-rw-r--r--ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java81
-rw-r--r--ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java30
-rw-r--r--ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java35
-rw-r--r--ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java665
-rw-r--r--ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java271
-rw-r--r--ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java280
-rw-r--r--ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java8
-rwxr-xr-xueb-listener/src/main/resources/normalizeTagNames.xslt1
-rw-r--r--ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModelTest.java4
-rw-r--r--ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModelTest.java4
-rw-r--r--ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModelTest.java4
-rw-r--r--ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModelTest.java4
-rw-r--r--ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/TestSdncUebCallback.java39
16 files changed, 1931 insertions, 354 deletions
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 @@
<properties>
<sdc.client.version>1.3.0</sdc.client.version>
- <sdc.tosca.version>1.3.0</sdc.tosca.version>
+ <sdc.tosca.version>1.3.5</sdc.tosca.version>
<fasterxml.jackson.version>2.9.4</fasterxml.jackson.version>
<skip.SWM>true</skip.SWM>
<ueb.listener.base>/opt/app/ueb-listener</ueb.listener.base>
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<String, String> params = null;
+ protected Map<String, String> 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<String, String>();
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<String, String>();
+ attributeValueParams = new HashMap<String, String>();
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<String, String>();
this.sdcCsarHelper = sdcCsarHelper;
+ attributeValueParams = new HashMap<String, String>();
// 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<Property> propList, SdncUebConfiguration config) {
+
+ //List<Property> 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<String> 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<String, String> attributeParams = new HashMap<String, String>();
+ 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<String, String> groupParams = new HashMap<String, String>();
+ List<Group> groupList = sdcCsarHelper.getGroupsOfOriginOfNodeTemplateByToscaGroupType(nodeTemplate, groupType);
+ //List<Group> 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<String, String> mappingCleanupParams = new HashMap<String, String>();
+ 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<String, String> mappingParams = new HashMap<String, String>();
+ 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<Policy> policyList = sdcCsarHelper.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nodeTemplate, policyType);
+ //List<Policy> policyList2 = sdcCsarHelper.getPoliciesOfTopologyTemplateByToscaPolicyType(policyType); // returns nothing
+ //List<Policy> 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<String, String> cleanupParams = new HashMap<String, String>();
+ addParameter("resource_uuid", resourceUuid, cleanupParams);
+ addParameter("policy_uuid", policyUuid, cleanupParams);
+ addParameter("policy_invariant_uuid", policyInvariantUuid, cleanupParams);
+
+ Map<String, String> policyParams = new HashMap<String, String>();
+ 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<String, String> mappingCleanupParams = new HashMap<String, String>();
+ 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<String, String> mappingParams = new HashMap<String, String>();
+ 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<Policy> 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<String, String> cleanupParams = new HashMap<String, String>();
+ SdncBaseModel.addParameter("resource_uuid", resourceUuid, cleanupParams);
+ SdncBaseModel.addParameter("policy_uuid", policyUuid, cleanupParams);
+ SdncBaseModel.addParameter("policy_invariant_uuid", policyInvariantUuid, cleanupParams);
+
+ Map<String, String> policyParams = new HashMap<String, String>();
+ 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<String> 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<String, String> mappingCleanupParams = new HashMap<String, String>();
+ 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<String, String> mappingParams = new HashMap<String, String>();
+ 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<CapabilityAssignment> 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<String> relevantCapabilities = config.getRelevantCapabilityNames();
+ for (String relevantCapabilityName : relevantCapabilities ) {
+
+ if (capability.getName().toLowerCase().contains(relevantCapabilityName.toLowerCase())) {
+ capabilityIsRelevant = true;
+ }
+ }*/
+
+ if (capabilityIsRelevant == false){
+ continue;
+ }
+
+ String capabilityProviderUuid = getUUID();
+
+ Map<String, String> cleanupParams = new HashMap<String, String>();
+ 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<String, String> nodeCapabilityParams = new HashMap<String, String>();
+ 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<String, Property> propertiesMap = capability.getProperties();
+ Map<String, String> nodeCapabilityPropertyParams = new HashMap<String, String>();
+
+ 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<String, String> 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<String, Object> 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<String, Object> propMap = policy.getPolicyProperties();
+ if (propMap == null) {
+ return "";
+ } else {
+ return nullCheck(propMap.get(name));
+ }
+ }
+
+ protected static String extractValueStatic (Policy policy, String name) {
+
+ Map<String, Object> 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<String,String> 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<String, String> 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<String, String> params) {
StringBuilder sb = new StringBuilder();
@@ -280,9 +840,9 @@ public class SdncBaseModel {
sb.append(") values (" + keyValue + ", ");
paramCount = 0;
- for (Map.Entry<String,String> 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<String> 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<String> 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<String, String> keyParams) throws IOException
+ {
+ return SdncBaseModel.cleanupExistingToscaData(this.jdbcDataSource, tableName, keyParams);
+ }
+
+ public static boolean cleanupExistingToscaData(DBResourceManager jdbcDataSource, String tableName, Map<String, String> 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<String, String> 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<String, String> 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<String, String> fromMap, Map<String, String> 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<DeployableArtifact> 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<DeployableArtifact>();
+ }
}
@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<IArtifactInfo> 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<Path> 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<DeployableArtifact>();
+ }*/
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<NodeTemplate> 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<NodeTemplate> 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<NodeTemplate> 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<Group> 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<NodeTemplate> 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<NodeTemplate> 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<NodeTemplate> 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<String, String> 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<Pair<NodeTemplate, NodeTemplate>> matchList = sdcCsarHelper.getNodeTemplatePairsByReqName(sdcCsarHelper.getCpListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()), sdcCsarHelper.getVfcListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()), virtualBinding);
- for (Pair<NodeTemplate, NodeTemplate> 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<String> 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("<input xmlns='");
msgBuffer.append(namespace);
@@ -893,22 +937,40 @@ public class SdncUebCallback implements INotificationCallback {
}
}
- msgBuffer.append("<artifact-name>"+artifactName+"</artifact-name>\n");
- msgBuffer.append("<artifact-version>"+artifact.getArtifactVersion()+"</artifact-version>\n");
-
+ // don't add artifact name/version for get-path-segments
+ if (!artifactName.contains("get-path-segments")) {
+ msgBuffer.append("<artifact-name>"+artifactName+"</artifact-name>\n");
+ msgBuffer.append("<artifact-version>"+artifact.getArtifactVersion()+"</artifact-version>\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("<?")) {
- msgBuffer.append(curLine+"\n");
+
+ // skip get-path-segments tags
+ boolean skipThisLine = false;
+ if (artifactName.contains("get-path-segments")) {
+ if (curLine.contains("<get-path-segments>") || curLine.contains("</get-path-segments>")) {
+ 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("</input>\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<String,Map<String,Object>> 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<String,Object> propsMap = cpPropertiesMap.get(nodeMapKey);
+ Map<String, String> commonParams = new HashMap<String, String>(); // 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<Map<String, Object>> ipPropsList = (ArrayList<Map<String, Object>>) propsMap.get("ip_requirements");
+ ArrayList<Map<String, Object>> ipPropsList = new ArrayList<Map<String, Object>>();
+
+ if (!ipRequirementsString.equals("{}")) {
+ ipPropsList = (ArrayList<Map<String, Object>>) propsMap.get("ip_requirements");
+ }
+
+ // Build lists of all IPV4 and IPV6 ip_requirements elements
+ ArrayList<Map<String, String>> ipv4PropParamsList = new ArrayList<Map<String, String>>();
+ ArrayList<Map<String, String>> ipv6PropParamsList = new ArrayList<Map<String, String>>();
+
+ if (ipPropsList != null) {
+ for (Map<String, Object> 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<String, String> ipv4PropParams = new HashMap<String, String>();
+ SdncBaseModel.addParameter("ipv4_ip_version", ipVersion, ipv4PropParams);
+ SdncBaseModel.addParameter("ipv4_use_dhcp", nullCheck(ipPropMap.get("dhcp_enabled")).contains("true") ? "Y" : "N", ipv4PropParams);
+ Map<String, Object> ipCountRequired = (Map<String, Object>)ipPropMap.get("ip_count_required");
+ if (ipCountRequired != null && ipCountRequired.get("count") != null) {
+ SdncBaseModel.addParameter("ipv4_count", nullCheck(ipCountRequired.get("count")), ipv4PropParams);
+ }
+ Map<String, Object> floatingIpCountRequired = (Map<String, Object>)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<String, String> ipv6PropParams = new HashMap<String, String>();
+ SdncBaseModel.addParameter("ipv6_ip_version", ipVersion, ipv6PropParams);
+ SdncBaseModel.addParameter("ipv6_use_dhcp", nullCheck(ipPropMap.get("dhcp_enabled")).contains("true") ? "Y" : "N", ipv6PropParams);
+ Map<String, Object> ipCountRequired = (Map<String, Object>)ipPropMap.get("ip_count_required");
+ if (ipCountRequired != null && ipCountRequired.get("count") != null) {
+ SdncBaseModel.addParameter("ipv6_count", nullCheck(ipCountRequired.get("count")), ipv6PropParams);
+ }
+ Map<String, Object> floatingIpCountRequired = (Map<String, Object>)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<String, String> ipv4PropParams: ipv4PropParamsList) {
+
+ Map<String, String> mappingParams = new HashMap<String, String>(); // 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<String, String> ipv6PropParams: ipv6PropParamsList) {
+
+ Map<String, String> mappingParams = new HashMap<String, String>(); // 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<Map<String, String>> ipPropParamsList, String subnetRole) {
+
+ boolean subnetRoleFound = false;
+
+ if (subnetRole != null && !subnetRole.isEmpty()) {
+ for (Map<String, String> ipPropMap : ipPropParamsList) {
+ if (ipPropMap.get("subnet_role").contentEquals(subnetRole)) {
+ return true;
+ }
+ }
+ }
+ return subnetRoleFound;
+ }
+
+ private Map<String, String> getIpPropMapWithMatchingSubnetRole (ArrayList<Map<String, String>> ipPropParamsList, String subnetRole) {
+
+ Map<String, String> ipPropMapMatch = new HashMap<String, String>();
+
+ if (subnetRole != null) {
+ for (Map<String, String> ipPropMap : ipPropParamsList) {
+ if (nullCheck(ipPropMap.get("subnet_role")) == subnetRole) {
+ return ipPropMap;
+ }
+ }
+ }
+ return ipPropMapMatch;
+ }
+
+ private void addRequiredParameters (Map<String, String> 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<Group> 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<String, String> mappingParams = new HashMap<String, String>();
+ 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<Group> 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<NodeTemplate> 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<NodeTemplate> 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<NodeTemplate> 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<NodeTemplate> 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<Group> 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<NodeTemplate> targetNodeList = group.getMemberNodes();
+ for (NodeTemplate targetNode : targetNodeList) {
+
+ String targetNodeUuid = targetNode.getMetaData().getValue("UUID");
+
+ // insert RESOURCE_GROUP_TO_TARGET_NODE_MAPPING
+ try {
+ Map<String, String> mappingCleanupParams = new HashMap<String, String>();
+ 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<String, String> mappingParams = new HashMap<String, String>();
+ 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<Policy> policyList = sdcCsarHelper.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nodeTemplate, "org.openecomp.policies.External");
+ for (Policy policy : policyList){
+
+ policy.getmetadata();
+ Map<String, Object> 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 @@
<xsl:template match="vf-license-model/feature-group-list/feature-group/entitlement-pool-list/entitlement-pool/entitlement-metric/value/text()[.='# of software instances']">num of software instances</xsl:template>
<xsl:template match="vf-license-model/feature-group-list/feature-group/entitlement-pool-list/entitlement-pool/firstClassCitizenId"/>
</xsl:stylesheet>
-
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);