summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlalena.aria <lalena.aria@att.com>2019-07-09 15:34:57 +0000
committerlalena.aria <lalena.aria@att.com>2019-07-09 15:35:26 +0000
commitc84f0cf17122c65faad639c37028fd99e6594939 (patch)
tree68371122269c2aa07a5d52e9545a67109ca9f838
parent1ce6dbdae9d7a354ceb82e56b8d88b33753c6a5d (diff)
Use getEntity to populate Policy-Related tables
Changes made: Update SdncBaseModel policy data methods to use getEntity. Update SdncVFModel to call updated SdncBaseModel policy data methods. Minor changes in SdncServiceModel.java. Corresponding junit changes for getEntity migration. Issue-ID: CCSDK-1456 Change-Id: Idf000bb48896ca4c57d6d1659730e2aea7f49ec4 Signed-off-by: lalena.aria <lalena.aria@att.com>
-rw-r--r--ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java317
-rw-r--r--ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java5
-rw-r--r--ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java2
-rw-r--r--ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java16
-rw-r--r--ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModelTest.java4
5 files changed, 126 insertions, 218 deletions
diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java
index 0c05b3dc8..27814c358 100644
--- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java
+++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java
@@ -33,6 +33,9 @@ import javax.sql.rowset.CachedRowSet;
import org.onap.sdc.tosca.parser.api.IEntityDetails;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.onap.sdc.tosca.parser.elements.queries.EntityQuery;
+import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery;
+import org.onap.sdc.tosca.parser.enums.SdcTypes;
import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
import org.onap.sdc.toscaparser.api.CapabilityAssignment;
import org.onap.sdc.toscaparser.api.CapabilityAssignments;
@@ -101,10 +104,11 @@ public class SdncBaseModel {
this.config = config;
}
- public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata) {
+ public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata, DBResourceManager jdbcDataSource) {
params = new HashMap<String, String>();
this.sdcCsarHelper = sdcCsarHelper;
+ this.jdbcDataSource = jdbcDataSource;
// extract service metadata
invariantUUID = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID);
@@ -294,240 +298,139 @@ public class SdncBaseModel {
}
}
- protected void insertPolicyData (NodeTemplate nodeTemplate, NodeTemplate targetNode, String policyType) throws IOException {
+ protected void insertEntityPolicyData (String nodeTemplateCustomizationUuid, String nodeTemplateUuid, SdcTypes queryType, String targetCustomizationUuid, String targetUuid, String targetType, String policyType) throws IOException {
+
+ EntityQuery policyEntityQuery = EntityQuery.newBuilder(policyType).build();
+ TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(queryType).customizationUUID(nodeTemplateCustomizationUuid).build();
+ List<IEntityDetails> policyEntities = sdcCsarHelper.getEntity(policyEntityQuery, topologyTemplateQuery, false);
+ if (policyEntities == null || policyEntities.isEmpty()) {
+ LOG.info("insertPolicyData: Could not find policy data for: " + nodeTemplateCustomizationUuid);
+ return;
+ }
- // Get External policies of the node
- List<Policy> policyList = sdcCsarHelper.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nodeTemplate, policyType);
- //List<Policy> policyList2 = sdcCsarHelper.getPoliciesOfTopologyTemplateByToscaPolicyType(policyType); // returns nothing
- //List<Policy> policyList3 = sdcCsarHelper.getPoliciesOfTargetByToscaPolicyType(nodeTemplate, policyType); // returns nothing
-
String resourceUuid = getUUID();
- for (Policy policy : policyList) {
+ for (IEntityDetails policyEntity : policyEntities) {
// extract policy metadata
- String policyUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("UUID", "").toString();
- String policyInvariantUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("invariantUUID", "").toString();
- String policyCustomizationUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("customizationUUID", "").toString();
-
- // cleanup existing RESOURCE_POLICY data
- Map<String, String> cleanupParams = new HashMap<String, String>();
- addParameter("resource_uuid", resourceUuid, cleanupParams);
- addParameter("policy_uuid", policyUuid, cleanupParams);
- addParameter("policy_invariant_uuid", policyInvariantUuid, cleanupParams);
-
- // insert into RESOURCE_POLICY
- 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", policy.getMetaDataObj().getAllProperties().getOrDefault(PARAM_NAME_KEY, "").toString(), policyParams);
- addParameter(PARAM_VERSION_KEY, policy.getMetaDataObj().getAllProperties().getOrDefault(PARAM_VERSION_KEY, "").toString(), policyParams);
- addParameter("policy_type", policy.getType(), policyParams);
-
- // extract properties
- addParameter("property_type", extractValue(policy, PARAM_TYPE_KEY), policyParams);
- addParameter("property_source", extractValue(policy, "source"), policyParams);
- addParameter("property_name", extractValue(policy, PARAM_NAME_KEY), policyParams);
-
- // Insert into RESOURCE_POLICY and RESOURCE_POLICY_TO_TARGET_NODE_MAPPING
- // RESOURCE_POLICY: resource_uuid (CR node UUID), uuid, customization_uuid, invariant_uuid, name, version, policy_type,
- // property_type, property_source, property_name
-
- try {
-
- // insert into RESOURCE_POLICY
- cleanupExistingToscaData("RESOURCE_POLICY", cleanupParams);
- LOG.info("Call insertToscaData for RESOURCE_POLICY where resource_uuid = " + resourceUuid + " and policy_uuid = " + policyUuid);
- insertToscaData(buildSql("RESOURCE_POLICY", "resource_uuid", resourceUuid, model_yaml, policyParams), null);
-
- } catch (IOException e) {
- LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY table");
- throw new IOException (e);
- }
-
- // insert RESOURCE_POLICY_TO_TARGET_NODE_MAPPING: policy_uuid, parent_uuid (CR node UUID), target_node_uuid, target_type, table_name
- try {
- Map<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(PARAM_TYPE_KEY), mappingParams);
- LOG.info("Call insertToscaData for RESOURCE_POLICY_TO_TARGET_NODE_MAPPING where policy_uuid = " + policyUuid);
- insertToscaData(buildSql("RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", "policy_uuid", "\"" + policyUuid + "\"", model_yaml, mappingParams), null);
+ String policyUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID);
+ String policyCustomizationUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
- } catch (IOException e) {
- LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY_TO_TARGET_NODE_MAPPING");
- throw new IOException (e);
- }
+ insertResourcePolicyData(policyEntity, resourceUuid);
+ insertResourcePolicyToTargetNodeMappingData(policyUuid, nodeTemplateUuid, targetUuid, targetCustomizationUuid, policyCustomizationUuid, targetType);
}
}
- public static void insertPolicyData (ISdcCsarHelper sdcCsarHelper, DBResourceManager jdbcDataSource, String resourceUuid, String parentUuid, String policyType) throws IOException {
+ public void insertEntityPolicyData (String resourceCustomizationUuid, String resourceUuid, String parentUuid, String policyType, SdcTypes queryType) throws IOException {
- // Get External policies of the node
- List<Policy> policyList = sdcCsarHelper.getPoliciesOfTopologyTemplateByToscaPolicyType(policyType);
+ EntityQuery policyEntityQuery = EntityQuery.newBuilder(policyType).build();
+ TopologyTemplateQuery topologyTemplateQuery;
+ if (queryType == SdcTypes.VF) {
+ topologyTemplateQuery = TopologyTemplateQuery.newBuilder(queryType).customizationUUID(resourceCustomizationUuid).build();
+ } else {
+ topologyTemplateQuery = TopologyTemplateQuery.newBuilder(queryType).build();
+ }
- for (Policy policy : policyList) {
+ List<IEntityDetails> policyEntities = sdcCsarHelper.getEntity(policyEntityQuery, topologyTemplateQuery, false);
+ if (policyEntities == null || policyEntities.isEmpty()) {
+ LOG.info("insertPolicyData: Could not find policy data for Service/VF: " + resourceUuid);
+ return;
+ }
+
+ for (IEntityDetails policyEntity : policyEntities) {
// extract policy metadata
- String policyUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("UUID", "").toString();
- String policyInvariantUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("invariantUUID", "").toString();
-
- // cleanup existing RESOURCE_POLICY data
- Map<String, String> cleanupParams = new HashMap<String, String>();
- addParameter("resource_uuid", resourceUuid, cleanupParams);
- addParameter("policy_uuid", policyUuid, cleanupParams);
- addParameter("policy_invariant_uuid", policyInvariantUuid, cleanupParams);
-
- // insert into RESOURCE_POLICY
- Map<String, String> policyParams = new HashMap<String, String>();
- addParameter("policy_uuid", policyUuid, policyParams);
- addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams);
- addParameter("policy_name", policy.getMetaDataObj().getAllProperties().getOrDefault("name", "").toString(), policyParams);
- addParameter("version", policy.getMetaDataObj().getAllProperties().getOrDefault("version", "").toString(), policyParams);
- addParameter("policy_type", policy.getType(), policyParams);
-
- // extract properties
- addParameter("property_type", extractValueStatic(policy, "type"), policyParams);
- addParameter("property_source", extractValueStatic(policy, "source"), policyParams);
- addParameter("property_name", extractValueStatic(policy, "name"), policyParams);
-
- try {
-
- // insert into RESOURCE_POLICY
- SdncBaseModel.cleanupExistingToscaData(jdbcDataSource, "RESOURCE_POLICY", cleanupParams);
- LOG.info("Call insertToscaData for RESOURCE_POLICY where resource_uuid = " + resourceUuid);
- insertToscaData(jdbcDataSource, getSql("RESOURCE_POLICY", "resource_uuid", resourceUuid, "", policyParams), null);
+ String policyUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID);
+ String policyCustomizationUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
- } catch (IOException e) {
- LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY table");
- throw new IOException (e);
- }
-
- // insert into RESOURCE_POLICY_TO_TARGET_NODE_MAPPING
- List<String> policyTargetNameList = policy.getTargets();
- if (policyTargetNameList == null) {
+ insertResourcePolicyData(policyEntity, resourceUuid);
+ List<IEntityDetails> targetEntities = policyEntity.getTargetEntities();
+ if (targetEntities == null || targetEntities.isEmpty()) {
+ LOG.info("insertPolicyData: Could not find targetEntites for policy: " + policyUuid);
continue;
- }
-
- for (String targetName : policyTargetNameList) {
- NodeTemplate targetNode = sdcCsarHelper.getNodeTemplateByName(targetName);
-
- // insert into RESOURCE_POLICY_TO_TARGET_NODE_MAPPING
- try {
- Map<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);
- }
+ }
+ for (IEntityDetails targetEntity : targetEntities) {
+
+ String targetUuid = extractValue(targetEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID);
+ String targetCustomizationUuid = extractValue(targetEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
+ String targetType = extractValue(targetEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_TYPE);
+ insertResourcePolicyToTargetNodeMappingData(policyUuid, parentUuid, targetUuid, targetCustomizationUuid, policyCustomizationUuid, targetType);
}
}
}
- protected void insertPolicyData (NodeTemplate nodeTemplate, DBResourceManager jdbcDataSource, String parentUuid, String policyType) throws IOException {
+ protected void insertResourcePolicyData (IEntityDetails policyEntity, String resourceUuid) throws IOException {
- // Get External policies of the node
- List<Policy> policyList = sdcCsarHelper.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nodeTemplate, policyType);
- String resourceUuid = "\"" + extractValue (nodeTemplate.getMetaData(), SdcPropertyNames.PROPERTY_NAME_UUID) + "\"";
+ // extract policy metadata
+ String policyUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID);
+ String policyInvariantUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID);
+ String policyCustomizationUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
- for (Policy policy : policyList) {
-
- // extract policy metadata
- String policyUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("UUID", "").toString();
- String policyInvariantUuid = policy.getMetaDataObj().getAllProperties().getOrDefault("invariantUUID", "").toString();
-
- // cleanup existing RESOURCE_POLICY data
- Map<String, String> cleanupParams = new HashMap<String, String>();
- addParameter("resource_uuid", resourceUuid, cleanupParams);
- addParameter("policy_uuid", policyUuid, cleanupParams);
- addParameter("policy_invariant_uuid", policyInvariantUuid, cleanupParams);
+ // cleanup existing RESOURCE_POLICY data
+ Map<String, String> cleanupParams = new HashMap<String, String>();
+ addParameter("resource_uuid", resourceUuid, cleanupParams);
+ addParameter("policy_uuid", policyUuid, cleanupParams);
+ addParameter("policy_invariant_uuid", policyInvariantUuid, cleanupParams);
+
+ // insert into RESOURCE_POLICY
+ 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(policyEntity.getMetadata(), PARAM_NAME_KEY), policyParams);
+ addParameter(PARAM_VERSION_KEY, extractValue(policyEntity.getMetadata(), PARAM_VERSION_KEY), policyParams);
+ addParameter("policy_type", policyEntity.getToscaType(), policyParams);
+
+ // extract properties
+ addParameter("property_type", extractValue(policyEntity, PARAM_TYPE_KEY), policyParams);
+ addParameter("property_source", extractValue(policyEntity, "source"), policyParams);
+ addParameter("property_name", extractValue(policyEntity, PARAM_NAME_KEY), policyParams);
+
+ // Insert into RESOURCE_POLICY and RESOURCE_POLICY_TO_TARGET_NODE_MAPPING
+ // RESOURCE_POLICY: resource_uuid (CR node UUID), uuid, customization_uuid, invariant_uuid, name, version, policy_type,
+ // property_type, property_source, property_name
+
+ try {
// insert into RESOURCE_POLICY
- Map<String, String> policyParams = new HashMap<String, String>();
- addParameter("policy_uuid", policyUuid, policyParams);
- addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams);
- String policyName = policy.getMetaDataObj().getAllProperties().getOrDefault(PARAM_NAME_KEY, "").toString();
- addParameter("policy_name", policyName, policyParams);
- addParameter(PARAM_VERSION_KEY, policy.getMetaDataObj().getAllProperties().getOrDefault(PARAM_VERSION_KEY, "").toString(), policyParams);
- addParameter("policy_type", policy.getType(), policyParams);
-
- // extract properties
- addParameter("property_type", extractValue(policy, PARAM_TYPE_KEY), policyParams);
- addParameter("property_source", extractValue(policy, "source"), policyParams);
- addParameter("property_name", extractValue(policy, PARAM_NAME_KEY), policyParams);
-
- try {
-
- // insert into RESOURCE_POLICY
- cleanupExistingToscaData(jdbcDataSource, "RESOURCE_POLICY", cleanupParams);
- LOG.info("Call insertToscaData for RESOURCE_POLICY where resource_uuid = " + resourceUuid);
- insertToscaData(jdbcDataSource, getSql("RESOURCE_POLICY", "resource_uuid", resourceUuid, "", policyParams), null);
+ cleanupExistingToscaData("RESOURCE_POLICY", cleanupParams);
+ LOG.info("Call insertToscaData for RESOURCE_POLICY where resource_uuid = " + resourceUuid + " and policy_uuid = " + "\"" + policyUuid + "\"" );
+ insertToscaData(buildSql("RESOURCE_POLICY", "resource_uuid", resourceUuid, model_yaml, policyParams), null);
- } catch (IOException e) {
- LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY table");
- throw new IOException (e);
- }
-
- // insert into RESOURCE_POLICY_TO_TARGET_NODE_MAPPING
- List<NodeTemplate> targetNodeList = sdcCsarHelper.getPolicyTargetsFromOrigin(nodeTemplate, policyName);
- if (targetNodeList == null) {
- continue;
- }
-
- for (NodeTemplate targetNode : targetNodeList) {
- //NodeTemplate targetNode = sdcCsarHelper.getNodeTemplateByName(targetName);
- if (targetNode == null) {
- LOG.error("Target node for policy " + policyName + " is NULL. Can't insert into RESOURCE_POLICY_TO_TARGET_NODE_MAPPING");
- continue;
- }
-
- // insert into RESOURCE_POLICY_TO_TARGET_NODE_MAPPING
- try {
- Map<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(PARAM_TYPE_KEY), mappingParams); // type of the target node
- LOG.info("Call insertToscaData for RESOURCE_POLICY_TO_TARGET_NODE_MAPPING where policy_uuid = " + policyUuid + " and target_node_uuid = " + targetNode.getMetaData().getValue("UUID"));
- SdncBaseModel.insertToscaData(jdbcDataSource, getSql("RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", "policy_uuid", "\"" + policyUuid + "\"", "", mappingParams), null);
-
- } catch (IOException e) {
- LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY_TO_TARGET_NODE_MAPPING table");
- throw new IOException (e);
- }
-
- }
+ } catch (IOException e) {
+ LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY table");
+ throw new IOException (e);
}
+
}
+ protected void insertResourcePolicyToTargetNodeMappingData(String policyUuid, String parentUuid, String targetUuid, String targetCustomizationUuid, String policyCustomizationUuid, String targetType) throws IOException {
+
+ // insert RESOURCE_POLICY_TO_TARGET_NODE_MAPPING: policy_uuid, parent_uuid (CR node UUID), target_node_uuid, target_type, table_name
+ try {
+ Map<String, String> mappingCleanupParams = new HashMap<String, String>();
+ addParameter("policy_uuid", policyUuid, mappingCleanupParams);
+ addParameter("parent_uuid", parentUuid, mappingCleanupParams);
+ addParameter("target_node_uuid", targetUuid, mappingCleanupParams);
+ cleanupExistingToscaData("RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", mappingCleanupParams);
+
+ Map<String, String> mappingParams = new HashMap<String, String>();
+ addParameter("parent_uuid", parentUuid, mappingParams);
+ addParameter("target_node_uuid", targetUuid, mappingParams);
+ addParameter("target_node_customization_uuid", targetCustomizationUuid, mappingParams);
+ addParameter("policy_customization_uuid", policyCustomizationUuid, mappingParams);
+ addParameter("target_type", targetType, mappingParams);
+ LOG.info("Call insertToscaData for RESOURCE_POLICY_TO_TARGET_NODE_MAPPING where policy_uuid = " + "\"" + policyUuid + "\" and parent_uuid = " + "\"" + parentUuid + "\" and target_node_uuid = " + "\"" + targetUuid + "\"");
+ insertToscaData(buildSql("RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", "policy_uuid", "\"" + policyUuid + "\"", model_yaml, mappingParams), null);
+
+ } catch (IOException e) {
+ LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY_TO_TARGET_NODE_MAPPING");
+ throw new IOException (e);
+ }
+ }
+
+
protected void insertNodeCapabilitiesData (CapabilityAssignments capabilities) throws IOException {
// Process the capabilities on the node template
diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java
index 4bed2fe76..52e38624a 100644
--- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java
+++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java
@@ -21,6 +21,7 @@
package org.onap.ccsdk.sli.northbound.uebclient;
+import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
import org.onap.sdc.toscaparser.api.elements.Metadata;
@@ -35,9 +36,9 @@ public class SdncServiceModel extends SdncBaseModel {
private String serviceInstanceNamePrefix = null;
private String filename = null;
- public SdncServiceModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata) {
+ public SdncServiceModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata, DBResourceManager jdbcDataSource) {
- super(sdcCsarHelper, metadata);
+ super(sdcCsarHelper, metadata, jdbcDataSource);
UUID = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_UUID);
diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java
index 95672ea5f..d39622621 100644
--- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java
+++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java
@@ -689,7 +689,7 @@ public class SdncUebCallback implements INotificationCallback {
// Ingest Service Data - 1707
Metadata serviceMetadata = sdcCsarHelper.getServiceMetadata();
- SdncServiceModel serviceModel = new SdncServiceModel(sdcCsarHelper, serviceMetadata);
+ SdncServiceModel serviceModel = new SdncServiceModel(sdcCsarHelper, serviceMetadata, jdbcDataSource);
serviceModel.setFilename(spoolFile.toString().substring(spoolFile.toString().lastIndexOf("/")+1)); // will be csar file name
serviceModel.setServiceInstanceNamePrefix(SdncBaseModel.extractSubstitutionMappingTypeName(sdcCsarHelper).substring(SdncBaseModel.extractSubstitutionMappingTypeName(sdcCsarHelper).lastIndexOf(".")+1));
diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java
index ac59eafa3..750cb72a3 100644
--- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java
+++ b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java
@@ -385,7 +385,9 @@ public class SdncVFModel extends SdncBaseModel {
List<NodeTemplate> targetNodeList = group.getMemberNodes();
for (NodeTemplate targetNode : targetNodeList) {
- String targetNodeUuid = targetNode.getMetaData().getValue("UUID");
+ String targetNodeUuid = extractValue(targetNode.getMetaData(), SdcPropertyNames.PROPERTY_NAME_UUID);
+ String targetNodeCustomizationUuid = extractValue(targetNode.getMetaData(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
+ String targetNodeType = extractValue(targetNode.getMetaData(), SdcPropertyNames.PROPERTY_NAME_TYPE);
// insert RESOURCE_GROUP_TO_TARGET_NODE_MAPPING
try {
@@ -398,10 +400,9 @@ public class SdncVFModel extends SdncBaseModel {
Map<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);
+ addParameter("target_type", targetNodeType, mappingParams);
String tableName = "";
- switch (targetType) {
+ switch (targetNodeType) {
case "CVFC":
tableName = "VFC_MODEL";
break;
@@ -417,8 +418,9 @@ public class SdncVFModel extends SdncBaseModel {
throw new IOException (e);
}
- // For each target node, get External policies
- insertPolicyData(nodeTemplate, targetNode, "org.openecomp.policies.External");
+ // For each target node, get External policies
+ SdcTypes queryType = SdcTypes.valueOf(extractValue(nodeTemplate.getMetaData(), SdcPropertyNames.PROPERTY_NAME_TYPE));
+ insertEntityPolicyData(getCustomizationUUIDNoQuotes(), getUUID().replace("\"", ""), queryType, targetNodeCustomizationUuid, targetNodeUuid, targetNodeType, "org.openecomp.policies.External"); // AFTER getEntity
}
}
}
@@ -426,7 +428,7 @@ public class SdncVFModel extends SdncBaseModel {
private void insertVFPolicyData() throws IOException {
// For each VF node, ingest External Policy data
- insertPolicyData (nodeTemplate, jdbcDataSource, serviceUUID, "org.openecomp.policies.External");
+ insertEntityPolicyData (getCustomizationUUIDNoQuotes(), getUUID(), serviceUUID.replace("\"", ""), "org.openecomp.policies.External", SdcTypes.VF);
}
public String getVendor() {
diff --git a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModelTest.java b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModelTest.java
index 95f5a75ec..af17e2291 100644
--- a/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModelTest.java
+++ b/ueb-listener/src/test/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModelTest.java
@@ -7,6 +7,7 @@ import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
+import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.toscaparser.api.elements.Metadata;
@@ -17,13 +18,14 @@ import org.onap.sdc.toscaparser.api.elements.Metadata;
@Before
public void setUp() throws Exception {
ISdcCsarHelper mockCsarHelper = mock(ISdcCsarHelper.class);
+ DBResourceManager mockDBResourceManager = mock(DBResourceManager.class);
Metadata mockMetadata = mock(Metadata.class);
when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "UUID")).thenReturn("aaaa-bbbb-cccc-dddd");
when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "invariantUUID")).thenReturn("bbbb-cccc-dddd-eeee");
when(mockCsarHelper.getMetadataPropertyValue(mockMetadata, "namingPolicy")).thenReturn("test-naming-policy");
- testSdncServiceModel = new SdncServiceModel(mockCsarHelper,mockMetadata);
+ testSdncServiceModel = new SdncServiceModel(mockCsarHelper,mockMetadata,mockDBResourceManager);
assertNotNull(testSdncServiceModel);
}