From ff3eecb980bfdc8d43d2ed3a4c786d634fa6f4e2 Mon Sep 17 00:00:00 2001 From: Jessica Wagantall Date: Tue, 1 Dec 2020 11:52:01 -0800 Subject: Migrate sli-northbound repo Migrate sli-northbound repo files into new directory "northbound". Signed-off-by: Jessica Wagantall --- .../sli/northbound/uebclient/SdncARModel.java | 106 -- .../sli/northbound/uebclient/SdncArtifactMap.java | 125 -- .../sli/northbound/uebclient/SdncBaseModel.java | 1123 ----------------- .../sli/northbound/uebclient/SdncGroupModel.java | 84 -- .../sli/northbound/uebclient/SdncNodeModel.java | 220 ---- .../northbound/uebclient/SdncOdlConnection.java | 158 --- .../sli/northbound/uebclient/SdncPNFModel.java | 142 --- .../sli/northbound/uebclient/SdncServiceModel.java | 125 -- .../sli/northbound/uebclient/SdncUebCallback.java | 1263 -------------------- .../sli/northbound/uebclient/SdncUebClient.java | 107 -- .../northbound/uebclient/SdncUebConfiguration.java | 317 ----- .../sli/northbound/uebclient/SdncVFCModel.java | 360 ------ .../sli/northbound/uebclient/SdncVFModel.java | 485 -------- .../northbound/uebclient/SdncVFModuleModel.java | 51 - ueb-listener/src/main/resources/log4j2.xml | 26 - .../src/main/resources/normalizeTagNames.xslt | 13 - ueb-listener/src/main/resources/removeNs.xslt | 16 - .../src/main/scripts/start-ueb-listener.sh | 68 -- ueb-listener/src/main/scripts/stop-ueb-listener.sh | 56 - 19 files changed, 4845 deletions(-) delete mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java delete mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java delete mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java delete mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java delete mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java delete mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java delete mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncPNFModel.java delete mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java delete mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java delete mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java delete mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java delete mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java delete mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java delete mode 100644 ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java delete mode 100644 ueb-listener/src/main/resources/log4j2.xml delete mode 100755 ueb-listener/src/main/resources/normalizeTagNames.xslt delete mode 100755 ueb-listener/src/main/resources/removeNs.xslt delete mode 100644 ueb-listener/src/main/scripts/start-ueb-listener.sh delete mode 100644 ueb-listener/src/main/scripts/stop-ueb-listener.sh (limited to 'ueb-listener/src/main') 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 deleted file mode 100644 index f1e514da4..000000000 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncARModel.java +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * Modifications Copyright © 2018 IBM. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.northbound.uebclient; - -import java.io.IOException; -import java.util.List; - -import org.onap.sdc.tosca.parser.api.IEntityDetails; -import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.tosca.parser.elements.queries.EntityQuery; -import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery; -import org.onap.sdc.tosca.parser.enums.SdcTypes; -import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; -import org.onap.sdc.toscaparser.api.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); - - private String type = null; - private String subcategory = null; - - public SdncARModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails arEntity, DBResourceManager jdbcDataSource, SdncUebConfiguration config) throws IOException { - - super(sdcCsarHelper, arEntity, jdbcDataSource, config); - - // extract metadata - Metadata metadata = arEntity.getMetadata(); - type = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_TYPE); - subcategory = extractValue (metadata, "subcategory"); - addParameter("type", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_TYPE)); - - // extract properties - addParameter("role", extractValue (arEntity, "nf_role")); - addParameter("type", extractValue (arEntity, "nf_type")); - addParameter("ecomp_generated_naming", extractBooleanValue (arEntity, "nf_naming", "ecomp_generated_naming")); - addParameter("naming_policy", extractValue (arEntity, "nf_naming", "naming_policy")); - } - - public void insertAllottedResourceModelData () throws IOException { - 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 void insertAllottedResourceVfcModelData () throws IOException { - - // Insert the child VFCs (not CVFC) into VFC_MODEL - String vfCustomizationUuid = getCustomizationUUID().replace("\"", ""); - EntityQuery vfcEntityQuery = EntityQuery.newBuilder(SdcTypes.VFC).build(); - TopologyTemplateQuery vfcTopologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF) - .customizationUUID(vfCustomizationUuid) - .build(); - List nestedVfcs = sdcCsarHelper.getEntity(vfcEntityQuery, vfcTopologyTemplateQuery, true); // true allows for nested search - if (nestedVfcs == null || nestedVfcs.isEmpty()) { - LOG.info("Could not find the nested VFCs for: " + vfCustomizationUuid); - } - - for (IEntityDetails nestedVfc: nestedVfcs) { - try { - SdncVFCModel arVfcModel = new SdncVFCModel (sdcCsarHelper, nestedVfc, jdbcDataSource, config); - arVfcModel.insertVFCModelData(); - } catch (IOException e) { - LOG.info("Could not find the nested VFCs for: " + vfCustomizationUuid); - } - } - } - - public String getSubcategory() { - return subcategory; - } - - public void setSubcategory(String subcategory) { - this.subcategory = subcategory; - } - -} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java deleted file mode 100644 index 601569a19..000000000 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncArtifactMap.java +++ /dev/null @@ -1,125 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * Modifications Copyright © 2018 IBM. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.northbound.uebclient; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.util.HashMap; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SdncArtifactMap { - - private static final Logger LOG = LoggerFactory - .getLogger(SdncArtifactMap.class); - - public class SdncArtifactType { - private String tag; - private String artifactType; - private String rpc; - private int pass; - - private SdncArtifactType(String tag, String rpc, String pass) { - this.tag = tag; - this.rpc = rpc; - try { - this.pass = Integer.parseInt(pass); - } catch (Exception e) { - LOG.error("Invalid pass value for artifact map entry ({} {} {})", tag, rpc, pass, e); - } - } - - public String getTag() { - return tag; - } - public String getArtifactType() { - return artifactType; - } - public String getRpc() { - return rpc; - } - - public int getPass() { - return pass; - } - - public String getRpcUrl(String base) { - return base+rpc; - } - } - - - - private Map mapItems = new HashMap<>(); - - private int numPasses = 1; - - public int getNumPasses() { - return numPasses; - } - - public void load(String fileName) { - - File mapFile = new File(fileName); - - if (mapFile.exists() && mapFile.canRead()) { - - try (BufferedReader rdr = new BufferedReader(new FileReader(mapFile))) { - - for (String ln ; (ln = rdr.readLine()) != null ; ) { - String[] lnFields = ln.split(","); - if (lnFields.length == 3) { - SdncArtifactType entry = new SdncArtifactType(lnFields[0], lnFields[1], lnFields[2]); - mapItems.put(entry.getTag(), entry); - if (entry.getPass() + 1 > numPasses ) { - numPasses = entry.getPass() + 1; - } - } - } - - - } catch (Exception e) { - LOG.error("Caught exception reading artifact map", e); - return; - } - } else { - LOG.info("Artifact map {} does not exist or is not readable", fileName); - } - } - - public SdncArtifactType getMapping(String tag) { - if (mapItems.containsKey(tag)) { - return mapItems.get(tag); - } else { - return null; - } - } - - public static SdncArtifactMap getInstance() { - return new SdncArtifactMap(); - } - -} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java deleted file mode 100644 index bced6a830..000000000 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncBaseModel.java +++ /dev/null @@ -1,1123 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.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.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; -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 UUID = null; - protected String model_yaml = null; - protected String version = null; - protected String name = null; - - protected String PARAM_INVARIANT_UUID_KEY = "invariant_uuid"; - protected String PARAM_CUSTOMIZATION_UUID_KEY = "customization_uuid"; - protected String PARAM_UUID_KEY = "uuid"; - protected String PARAM_VERSION_KEY = "version"; - protected String PARAM_NAME_KEY = "name"; - protected String PARAM_DESCRIPTION_KEY = "description"; - protected String PARAM_TYPE_KEY = "type"; - protected String PARAM_CATEGORY_KEY = "category"; - - protected Map params = null; - protected Map attributeValueParams = null; - protected ISdcCsarHelper sdcCsarHelper = null; - protected static DBResourceManager jdbcDataSource = null; - protected static SdncUebConfiguration config = null; - protected IEntityDetails entityDetails = null; - - - public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails entityDetails, DBResourceManager jdbcDataSource, SdncUebConfiguration config) throws IOException { - this (sdcCsarHelper, entityDetails); - this.sdcCsarHelper = sdcCsarHelper; - this.entityDetails = entityDetails; - SdncBaseModel.jdbcDataSource = jdbcDataSource; - SdncBaseModel.config = config; - } - - public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata, DBResourceManager jdbcDataSource) { - - params = new HashMap(); - this.sdcCsarHelper = sdcCsarHelper; - SdncBaseModel.jdbcDataSource = jdbcDataSource; - - // extract service metadata - invariantUUID = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID); - addParameter(PARAM_INVARIANT_UUID_KEY,invariantUUID); - addParameter(PARAM_VERSION_KEY,extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_VERSION)); - name = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_NAME); - addParameter(PARAM_NAME_KEY,name); - addParameter(PARAM_DESCRIPTION_KEY,extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); - addParameter(PARAM_TYPE_KEY,extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_TYPE)); - addParameter(PARAM_CATEGORY_KEY,extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_CATEGORY)); - } - - public SdncBaseModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails entityDetails) { - - params = new HashMap(); - attributeValueParams = new HashMap(); - this.sdcCsarHelper = sdcCsarHelper; - this.entityDetails = entityDetails; - - // extract common nodeTemplate metadata - Metadata metadata = entityDetails.getMetadata(); - customizationUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); - invariantUUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID); - addParameter(PARAM_INVARIANT_UUID_KEY, invariantUUID); - UUID = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_UUID); - addParameter(PARAM_UUID_KEY, UUID); - addParameter(PARAM_VERSION_KEY, extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_VERSION)); - } - - -/* This is the generic approach Shoujit attempted for 18.06 but can't be implemented without parser API to - * get properties with substring match on the name - * protected void extractRelevantAttributeData(List propList, SdncUebConfiguration config) { - - //List propList = nodeTemplate.getPropertiesObjects(); - for (Property prop : propList) { - String propName = prop.getName(); - Object propValue = prop.getValue(); - - if (propValue instanceof Map) - - LOG.info("Property: propertyName: " + propName + " propertyValue: " + propValue.toString()); - - // Compare this property name with each config.relevant-attribute-name - List attributeNames = config.getRelevantAttributeNames(); - for (String attributeName : attributeNames) { - if (prop.getName().contains(attributeName)) - addParameter(prop.getName(), prop.getValue().toString(), attributeValueParams); - } - - } - - }*/ - - protected void insertRelevantAttributeData() throws IOException{ - - insertRelevantAttributeData(""); - } - - protected void insertRelevantAttributeData(String type) throws IOException{ - - // type can be passed as "group" or taken from the nodeTemplate - String metadataType = ""; - if (!type.isEmpty()) metadataType = type; - else { - Metadata metadata = entityDetails.getMetadata(); - metadataType = extractValue (metadata, PARAM_TYPE_KEY); - } - - // Clean up all attributes for this resource - try { - cleanUpExistingToscaData("ATTRIBUTE_VALUE_PAIR", "resource_uuid", getUUID(), "resource_type", "\"" + metadataType + "\""); - } catch (IOException e) { - LOG.error("Could not cleanup Tosca CSAR data from the ATTRIBUTE_VALUE_PAIR table"); - throw new IOException (e); - } - - for (String paramName : attributeValueParams.keySet()) { - String paramValue = attributeValueParams.get(paramName); - - Map attributeParams = new HashMap(); - addParameter("attribute_name", paramName, attributeParams); - addParameter("attribute_value", paramValue, attributeParams); - addParameter("resource_type", metadataType, attributeParams); - addParameter("resource_customization_uuid", getCustomizationUUID(), attributeParams); - - LOG.info("Call insertToscaData for ATTRIBUTE_VALUE_PAIR where resource_uuid = " + getUUID() + " and attribute_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 insertEntityGroupData (IEntityDetails entityDetails, IEntityDetails targetNode, String groupType) throws IOException { - - // Get the Groups on a node - Convert to use getEntity in 19.08 - EntityQuery entityQuery = EntityQuery.newBuilder(groupType).build(); - String customizationUuid = getCustomizationUUIDNoQuotes(); - SdcTypes entitySdcType = SdcTypes.valueOf(extractValue(entityDetails.getMetadata(), SdcPropertyNames.PROPERTY_NAME_TYPE)); - TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(entitySdcType) - .customizationUUID(customizationUuid).build(); - List groupList = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false); - if (groupList == null) { - return; - } - - for (IEntityDetails group : groupList){ - - // Insert into RESOURCE_GROUP/ATTRIBUTE_VALUE_PAIR and RESOURCE_GROUP_TO_TARGET_NODE_MAPPING - // RESOURCE_GROUP (group metadata): resource_uuid (CR node UUID), uuid, customization_uuid, invariant_uuid, name, version - // 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, entityDetails, config, jdbcDataSource); - String resourceUuid = getUUID(); - groupModel.insertGroupData(resourceUuid); - - // insert RESOURCE_GROUP_TO_TARGET_NODE_MAPPING - try { - Map mappingCleanupParams = new HashMap(); - addParameter("group_uuid", groupModel.getUUID(), mappingCleanupParams); - addParameter("parent_uuid", extractValue(entityDetails.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingCleanupParams); - addParameter("target_node_uuid", extractValue(targetNode.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingCleanupParams); - cleanupExistingToscaData("RESOURCE_GROUP_TO_TARGET_NODE_MAPPING", mappingCleanupParams); - - Map mappingParams = new HashMap(); - addParameter("parent_uuid", extractValue(entityDetails.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingParams); - addParameter("target_node_uuid", extractValue(targetNode.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID), mappingParams); - String targetType = extractValue(targetNode.getMetadata(), PARAM_TYPE_KEY); - addParameter("target_type", targetType, mappingParams); - String tableName = ""; - switch (targetType) { - 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 insertEntityPolicyData (String nodeTemplateCustomizationUuid, String nodeTemplateUuid, SdcTypes queryType, String targetCustomizationUuid, String targetUuid, String targetType, String policyType) throws IOException { - - EntityQuery policyEntityQuery = EntityQuery.newBuilder(policyType).build(); - TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(queryType).customizationUUID(nodeTemplateCustomizationUuid).build(); - List policyEntities = sdcCsarHelper.getEntity(policyEntityQuery, topologyTemplateQuery, false); - if (policyEntities == null || policyEntities.isEmpty()) { - LOG.debug("insertPolicyData: Could not find policy data for: " + nodeTemplateCustomizationUuid); - return; - } - - String resourceUuid = getUUID(); - - for (IEntityDetails policyEntity : policyEntities) { - - // extract policy metadata - String policyUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID); - String policyCustomizationUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); - - insertResourcePolicyData(policyEntity, resourceUuid); - insertResourcePolicyToTargetNodeMappingData(policyUuid, nodeTemplateUuid, targetUuid, targetCustomizationUuid, policyCustomizationUuid, targetType); - } - } - - public void insertEntityPolicyData (String resourceCustomizationUuid, String resourceUuid, String parentUuid, String policyType, SdcTypes queryType) throws IOException { - - 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(); - } - - List policyEntities = sdcCsarHelper.getEntity(policyEntityQuery, topologyTemplateQuery, false); - if (policyEntities == null || policyEntities.isEmpty()) { - LOG.debug("insertPolicyData: Could not find policy data for Service/VF: " + resourceUuid); - return; - } - - for (IEntityDetails policyEntity : policyEntities) { - - // extract policy metadata - String policyUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID); - String policyCustomizationUuid = extractValue(policyEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); - - insertResourcePolicyData(policyEntity, resourceUuid); - List targetEntities = policyEntity.getTargetEntities(); - if (targetEntities == null || targetEntities.isEmpty()) { - LOG.debug("insertPolicyData: Could not find targetEntites for policy: " + policyUuid); - continue; - } - - 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 insertResourcePolicyData (IEntityDetails policyEntity, String resourceUuid) throws IOException { - - // 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); - - // cleanup existing RESOURCE_POLICY data - Map cleanupParams = new HashMap(); - addParameter("resource_uuid", resourceUuid, cleanupParams); - addParameter("policy_uuid", policyUuid, cleanupParams); - addParameter("policy_invariant_uuid", policyInvariantUuid, cleanupParams); - - // insert into RESOURCE_POLICY - Map policyParams = new HashMap(); - addParameter("policy_uuid", policyUuid, policyParams); - addParameter("policy_customization_uuid", policyCustomizationUuid, policyParams); - addParameter("policy_invariant_uuid", policyInvariantUuid, policyParams); - addParameter("policy_name", extractValue(policyEntity.getMetadata(), PARAM_NAME_KEY), policyParams); - addParameter(PARAM_VERSION_KEY, extractValue(policyEntity.getMetadata(), PARAM_VERSION_KEY), policyParams); - addParameter("policy_type", policyEntity.getToscaType(), policyParams); - - // extract properties - addParameter("property_type", extractValue(policyEntity, PARAM_TYPE_KEY), policyParams); - addParameter("property_source", extractValue(policyEntity, "source"), policyParams); - addParameter("property_name", extractValue(policyEntity, PARAM_NAME_KEY), policyParams); - - // Insert into RESOURCE_POLICY and RESOURCE_POLICY_TO_TARGET_NODE_MAPPING - // RESOURCE_POLICY: resource_uuid (CR node UUID), uuid, customization_uuid, invariant_uuid, name, version, policy_type, - // property_type, property_source, property_name - - try { - - // insert into RESOURCE_POLICY - 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); - } - - } - - protected void insertResourcePolicyToTargetNodeMappingData(String policyUuid, String parentUuid, String targetUuid, String targetCustomizationUuid, String policyCustomizationUuid, String targetType) throws IOException { - - // insert RESOURCE_POLICY_TO_TARGET_NODE_MAPPING: policy_uuid, parent_uuid (CR node UUID), target_node_uuid, target_type, table_name - try { - Map mappingCleanupParams = new HashMap(); - addParameter("policy_uuid", policyUuid, mappingCleanupParams); - addParameter("parent_uuid", parentUuid, mappingCleanupParams); - addParameter("target_node_uuid", targetUuid, mappingCleanupParams); - cleanupExistingToscaData("RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", mappingCleanupParams); - - Map mappingParams = new HashMap(); - addParameter("parent_uuid", parentUuid, mappingParams); - addParameter("target_node_uuid", targetUuid, mappingParams); - addParameter("target_node_customization_uuid", targetCustomizationUuid, mappingParams); - addParameter("policy_customization_uuid", policyCustomizationUuid, mappingParams); - addParameter("target_type", targetType, mappingParams); - LOG.info("Call insertToscaData for RESOURCE_POLICY_TO_TARGET_NODE_MAPPING where policy_uuid = " + "\"" + policyUuid + "\" and parent_uuid = " + "\"" + parentUuid + "\" and target_node_uuid = " + "\"" + targetUuid + "\""); - insertToscaData(buildSql("RESOURCE_POLICY_TO_TARGET_NODE_MAPPING", "policy_uuid", "\"" + policyUuid + "\"", model_yaml, mappingParams), null); - - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the RESOURCE_POLICY_TO_TARGET_NODE_MAPPING"); - throw new IOException (e); - } - } - - - protected void insertNodeCapabilitiesData (CapabilityAssignments capabilities) throws IOException { - - // Process the capabilities on the node template - - List capabilityList = capabilities.getAll(); - - for (CapabilityAssignment capability : capabilities.getAll()) { - - // Insert into NODE_CAPABILITY: - // capability_id (generated) - // capability_provider_uuid - UUID of this node - // capability_provider_customization_uuid - customization UUID of this node - // capability_name - capability.getName() - // capability_type - ? - - // Check capability name against relevant capabilities - boolean capabilityIsRelevant = false; - /*List relevantCapabilities = config.getRelevantCapabilityNames(); - for (String relevantCapabilityName : relevantCapabilities ) { - - if (capability.getName().toLowerCase().contains(relevantCapabilityName.toLowerCase())) { - capabilityIsRelevant = true; - } - }*/ - - if (capabilityIsRelevant == false){ - continue; - } - - String capabilityProviderUuid = getUUID(); - - Map cleanupParams = new HashMap(); - addParameter("capability_provider_uuid", capabilityProviderUuid, cleanupParams); // node customization UUID - addParameter("capability_provider_customization_uuid", getCustomizationUUIDNoQuotes(), cleanupParams); // node customization UUID - addParameter("capability_name", capability.getName(), cleanupParams); - - Map nodeCapabilityParams = new HashMap(); - addParameter("capability_provider_customization_uuid", getCustomizationUUIDNoQuotes(), nodeCapabilityParams); // node customization UUID - addParameter("capability_name", capability.getName(), nodeCapabilityParams); - addParameter("capability_type", extractValue(capability, PARAM_TYPE_KEY), nodeCapabilityParams); - - // Insert NODE_CAPABILITY data for each capability - String capabilityId = ""; - try { - - cleanupExistingToscaData("NODE_CAPABILITY", cleanupParams); // will also delete NODE_CAPABILITY_PROPERTY with same capability_id - LOG.info("Call insertToscaData for NODE_CAPABILITY where capability_provider_uuid = " + capabilityProviderUuid + " and capability_name = \"" + capability.getName() + "\""); - insertToscaData(buildSql("NODE_CAPABILITY", "capability_provider_uuid", capabilityProviderUuid, model_yaml, nodeCapabilityParams), null); - - // Get capabilityId for capability just inserted - CachedRowSet rowData = getToscaData("NODE_CAPABILITY", nodeCapabilityParams); - rowData.first(); - int capabilityIdint = rowData.getInt("capability_id"); - capabilityId = String.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 insertNodeCapabilitiesEntityData (List capabilities) throws IOException { - - // Process the capabilities - for (CapabilityAssignment capability : capabilities) { - - // Insert into NODE_CAPABILITY: - // capability_id (generated) - // capability_provider_uuid - UUID of this node - // capability_provider_customization_uuid - customization UUID of this node - // capability_name - capability.getName() - // capability_type - ? - - // Check capability name against relevant capabilities - boolean capabilityIsRelevant = false; - /*List relevantCapabilities = config.getRelevantCapabilityNames(); - for (String relevantCapabilityName : relevantCapabilities ) { - - if (capability.getName().toLowerCase().contains(relevantCapabilityName.toLowerCase())) { - capabilityIsRelevant = true; - } - }*/ - - if (capabilityIsRelevant == false){ - continue; - } - - String capabilityProviderUuid = getUUID(); - - Map cleanupParams = new HashMap(); - addParameter("capability_provider_uuid", capabilityProviderUuid, cleanupParams); // node customization UUID - addParameter("capability_provider_customization_uuid", getCustomizationUUIDNoQuotes(), cleanupParams); // node customization UUID - addParameter("capability_name", capability.getName(), cleanupParams); - - Map nodeCapabilityParams = new HashMap(); - addParameter("capability_provider_customization_uuid", getCustomizationUUIDNoQuotes(), nodeCapabilityParams); // node customization UUID - addParameter("capability_name", capability.getName(), nodeCapabilityParams); - addParameter("capability_type", extractValue(capability, PARAM_TYPE_KEY), nodeCapabilityParams); - - // Insert NODE_CAPABILITY data for each capability - String capabilityId = ""; - try { - - cleanupExistingToscaData("NODE_CAPABILITY", cleanupParams); // will also delete NODE_CAPABILITY_PROPERTY with same capability_id - LOG.info("Call insertToscaData for NODE_CAPABILITY where capability_provider_uuid = " + capabilityProviderUuid + " and capability_name = \"" + capability.getName()+ "\""); - insertToscaData(buildSql("NODE_CAPABILITY", "capability_provider_uuid", capabilityProviderUuid, model_yaml, nodeCapabilityParams), null); - - // Get capabilityId for capability just inserted - CachedRowSet rowData = getToscaData("NODE_CAPABILITY", nodeCapabilityParams); - rowData.first(); - int capabilityIdint = rowData.getInt("capability_id"); - capabilityId = String.valueOf(capabilityIdint); - - } catch (IOException | SQLException e) { - LOG.error("Could not insert Tosca CSAR data into the NODE_CAPABILITY table"); - throw new IOException (e); - } - - insertNodeCapabilityPropertyData (capability, capabilityId); - } - } - - protected void insertNodeCapabilityPropertyData(CapabilityAssignment capability, String capabilityId) throws IOException { - - // Insert property name / value into NODE_CAPABILITY_PROPERTY - LinkedHashMap propertiesMap = capability.getProperties(); - Map nodeCapabilityPropertyParams = new HashMap(); - - for (String propertyMapKey : propertiesMap.keySet() ) { - //LOG.info("property map key = " + propertyMapKey); - Property property = propertiesMap.get(propertyMapKey); - - addParameter ("capability_property_name", property.getName(), nodeCapabilityPropertyParams); - addParameter ("capability_property_type", property.getValue().toString(), nodeCapabilityPropertyParams); - - try { - // Data from NODE_CAPABILITY_PROPERTY is cleaned up via cascade delete on NODE_CAPABILITY - LOG.info("Call insertToscaData for NODE_CAPABILITY_PROPERTY where capability_id = \"" + capabilityId + "\" and capability_property_name = \"" + property.getName() + "\" and capability_property_type = \"" + property.getValue().toString() + "\""); - insertToscaData(buildSql("NODE_CAPABILITY_PROPERTY", "capability_id", capabilityId, model_yaml, nodeCapabilityPropertyParams), null); - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the NODE_CAPABILITY_PROPERTY table"); - throw new IOException (e); - } - } - - } - - protected void addParameter (String name, String value) { - if (value != null && !value.isEmpty()) { - // check if value already contain quotes - if (value.startsWith("\"", 0) && value.endsWith("\"")) { - params.put(name, value); - } else { - params.put(name, "\"" + value + "\""); - } - } - } - - protected void addIntParameter (String name, String value) { - if (value != null && !value.isEmpty()) { - params.put(name, value); - } - } - - public static void addParameter (String name, String value, Map params) { - if (value != null && !value.isEmpty()) { - // remove any quotes within the string - 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 + "\""); - } - } - } - - protected String extractValue (Metadata metadata, String name) { - String value = metadata.getValue(name); - if (value != null) { - return value; - } else { - return ""; - } - } - - protected String extractBooleanValue (Metadata metadata, String name) { - String value = metadata.getValue(name); - if (value != null && !value.isEmpty()) { - return value.contains("true") ? "Y" : "N"; - } else { - return ""; - } - } - - public static String extractValue (ISdcCsarHelper sdcCsarHelper, Metadata metadata, String name) { - String value = metadata.getValue(name); - if (value != null) { - return value; - } else { - return ""; - } - } - - protected String extractValue (IEntityDetails entityDetails, String name) { - String value = ""; - if (entityDetails.getProperties().containsKey(name)) { - Property property = entityDetails.getProperties().get(name); - if (property != null && property.getValue() != null) { - value = property.getValue().toString(); - } - } - - if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { - return value; - } else { - return ""; - } - } - - protected String extractValue (IEntityDetails entityDetails, String path, String name) { - String value = ""; - - if (entityDetails.getProperties().containsKey(path)) { - Property property = entityDetails.getProperties().get(path); - if (property != null && !property.getLeafPropertyValue(name).isEmpty()) { - value = property.getLeafPropertyValue(name).get(0); - } - } - - if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { - return value; - } else { - return ""; - } - } - - protected String extractValue (IEntityDetails entityDetails, String path1, String path2, String name) { - String value = ""; - - value = extractNestedValue (entityDetails, path1, path2, name); - - if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { - return value; - } else { - return ""; - } - } - - protected String extractValue (IEntityDetails entityDetails, String path1, String path2, String path3, String name) { - String value = ""; - - value = extractNestedValue (entityDetails, path1, path2, path3, name); - - if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { - return value; - } else { - return ""; - } - } - - protected String extractBooleanValue (IEntityDetails entityDetails, String path1, String path2, String name) { - String value = ""; - - value = extractNestedValue (entityDetails, path1, path2, name); - - if (value != null && !value.isEmpty()) { - return value.contains("true") ? "Y" : "N"; - } else { - return ""; - } - } - - protected String extractNestedValue (IEntityDetails entityDetails, String path1, String path2, String name) { - String value = ""; - - if (entityDetails.getProperties().containsKey(path1)) { - Property path1Property = entityDetails.getProperties().get(path1); - if (path1Property != null) { - Map path1PropertyValue = (Map) path1Property.getValue(); - if (path1PropertyValue.containsKey(path2)) { - Map path2PropertyValue = (Map) path1PropertyValue.get(path2); - if (path2PropertyValue != null && path2PropertyValue.containsKey(name)) { - value = path2PropertyValue.get(name).toString(); - } - } - } - } - - return value; - } - - protected String extractNestedValue (IEntityDetails entityDetails, String path1, String path2, String path3, String name) { - String value = ""; - - if (entityDetails.getProperties().containsKey(path1)) { - Property path1Property = entityDetails.getProperties().get(path1); - if (path1Property != null) { - Map path1PropertyValue = (Map) path1Property.getValue(); - if (path1PropertyValue.containsKey(path2)) { - Map path2PropertyValue = (Map) path1PropertyValue.get(path2); - if (path2PropertyValue != null && path2PropertyValue.containsKey(path3)) { - Map path3PropertyValue = (Map) path2PropertyValue.get(path3); - if (path3PropertyValue != null && path3PropertyValue.containsKey(name)) { - value = path3PropertyValue.get(name).toString(); - } - } - } - } - } - - return value; - } - - protected String extractIntegerValue (Property property, String name) { - String value = ""; - - if (!property.getLeafPropertyValue(name).isEmpty()) { - value = property.getLeafPropertyValue(name).get(0); - } - - if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { - return value; - } else { - return ""; - } - } - - protected String extractGetInputValue (IEntityDetails group, IEntityDetails entityDetails, String name) { - - // Extract the property on entityDetails after getting the property name from the group - String getInputName = extractGetInputName (group, name); - String entityPropertyValue = ""; - - if (entityDetails.getProperties().containsKey(getInputName)) { - Property entityProperty = entityDetails.getProperties().get(getInputName); - entityPropertyValue = entityProperty.getValue().toString(); - } - - if (!entityPropertyValue.isEmpty()) { - return entityPropertyValue; - } else { - return ""; - } - } - - protected String extractGetInputName (IEntityDetails group, String name) { - - String getInputName = name; - String groupPropertyValue = ""; - if (group.getProperties().containsKey(name)) { - Property groupProperty = group.getProperties().get(name); - groupPropertyValue = groupProperty.getValue().toString(); - } - if (!groupPropertyValue.isEmpty()) { - int getInputIndex = groupPropertyValue.indexOf("{get_input="); - if (getInputIndex > -1) { - getInputName = groupPropertyValue.substring(getInputIndex+11, groupPropertyValue.length()-1); - } - } - - return getInputName; - - } - - protected String extractValue (CapabilityAssignment capability, String name) { - String value = ""; - - if (capability.getProperties().containsKey(name)) { - Property property = capability.getProperties().get(name); - value = property.getLeafPropertyValue(name).get(0); - } - - if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { - return value; - } else { - return ""; - } - } - - protected String extractValue (CapabilityAssignment capability, String path, String name) { - String value = ""; - - if (capability.getProperties().containsKey(path)) { - Property property = capability.getProperties().get(path); - if (property != null && !property.getLeafPropertyValue(name).isEmpty()) { - value = property.getLeafPropertyValue(name).get(0); - } - } - - if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { - return value; - } else { - return ""; - } - } - - protected String extractBooleanValue (IEntityDetails entityDetails, String name) { - String value = null; - if (entityDetails.getProperties().containsKey(name)) { - Property property = entityDetails.getProperties().get(name); - if (property != null && property.getValue() != null) { - value = property.getValue().toString(); - } - } - - if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { - return value.contains("true") ? "Y" : "N"; - } else { - return ""; - } - } - - protected String extractBooleanValue (IEntityDetails entityDetails, String path, String name) { - String value = null; - if (entityDetails.getProperties().containsKey(path)) { - Property property = entityDetails.getProperties().get(path); - if (property != null) { - if (property != null && !property.getLeafPropertyValue(name).isEmpty()) { - value = property.getLeafPropertyValue(name).get(0); - } - } - } - - if (value != null && !value.isEmpty() && !value.equalsIgnoreCase("null")) { - return value.contains("true") ? "Y" : "N"; - } else { - return ""; - } - } - - protected Object extractObjectValue (IEntityDetails entityDetails, String name) { - Object value = ""; - if (entityDetails.getProperties().containsKey(name)) { - Property property = entityDetails.getProperties().get(name); - if (property != null && property.getValue() != null) { - value = property.getValue(); - } - } - - if (value != null) { - return value; - } else { - return ""; - } - } - - public static String extractSubstitutionMappingTypeName (ISdcCsarHelper sdcCsarHelper) { - String value = sdcCsarHelper.getServiceSubstitutionMappingsTypeName(); - if (value != null) { - return value; - } else { - return ""; - } - } - - protected String getUUID() { - return ("\"" + UUID + "\""); - } - public String getInvariantUUID() { - return ("\"" + invariantUUID + "\""); - } - public String getCustomizationUUID() { - return ("\"" + customizationUUID + "\""); - } - public String getCustomizationUUIDNoQuotes() { - return (customizationUUID); - } - public void setCustomizationUUID(String customizationUUID) { - this.customizationUUID = customizationUUID; - } - 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, "); - - int paramCount = 0; - for (String paramKey : params.keySet()) { - paramCount++; - sb.append(paramKey); - if (paramCount < params.size()) sb.append(", "); - } - - sb.append(") values (" + getCustomizationUUID() + ", \"" + model_yaml + "\", "); - - paramCount = 0; - for (String paramKey : params.keySet()) { - paramCount++; - String paramValue = params.get(paramKey); - sb.append(paramValue); - if (paramCount < params.size()) sb.append(", "); - } - - sb.append(");"); - return sb.toString(); - } - - public String buildSql(String tableName, String keyName, String keyValue, String model_yaml, Map params) { - - StringBuilder sb = new StringBuilder(); - sb.append("INSERT into " + tableName + " (" + keyName + ", "); - - int paramCount = 0; - for (String paramKey : params.keySet()) { - paramCount++; - sb.append(paramKey); - if (paramCount < params.size()) sb.append(", "); - } - - sb.append(") values (" + keyValue + ", "); - - paramCount = 0; - for (String paramKey : params.keySet()) { - paramCount++; - String paramValue = params.get(paramKey); - sb.append(paramValue); - if (paramCount < params.size()) sb.append(", "); - } - - sb.append(");"); - return sb.toString(); - } - - public static String getSql(String tableName, String keyName, String keyValue, String model_yaml, Map params) { - - StringBuilder sb = new StringBuilder(); - 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(); - } - - protected void insertToscaData(String toscaDataString, ArrayList arguments) throws IOException - { - LOG.debug("insertToscaData: " + toscaDataString); - - try { - - jdbcDataSource.writeData(toscaDataString, arguments, null); - - } catch (SQLException e) { - LOG.error("Could not insert Tosca data into the database"); - throw new IOException (e); - } - - } - - protected 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, ""); - if (data != null) { - while(data.next()) { - rowCount ++; - } - if (rowCount != 0) { - LOG.debug("cleanUpExistingToscaData from: " + tableName + " for " + keyValue); - jdbcDataSource.writeData("DELETE from " + tableName + " where " + keyName + " = " + keyValue + ";", null, null); - } - } - - } 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, ""); - if (data != null) { - while(data.next()) { - rowCount ++; - } - if (rowCount != 0) { - LOG.debug("cleanUpExistingToscaData from : " + tableName + " for " + key1Value + " and " + key2Value); - jdbcDataSource.writeData("DELETE from " + tableName + " where " + key1Name + " = " + key1Value + " AND " + key2Name + " = " + key2Value + ";", null, null); - } - } - - } catch (SQLException e) { - LOG.error("Could not clean up existing " + tableName + " for " + key1Value + " and " + key2Value, e); - } - - } - - protected boolean cleanupExistingToscaData(String tableName, Map keyParams) throws IOException - { - return SdncBaseModel.cleanupExistingToscaData(SdncBaseModel.jdbcDataSource, tableName, keyParams); - } - - public static boolean cleanupExistingToscaData(DBResourceManager jdbcDataSource, String tableName, Map keyParams) throws IOException - { - boolean dataExists = false; - StringBuilder sb = new StringBuilder(); - sb.append("SELECT * from " + tableName + " where "); - - int paramCount = 0; - for (String paramKey : keyParams.keySet()) { - paramCount++; - String paramValue = keyParams.get(paramKey); - sb.append(paramKey); - sb.append(" = "); - sb.append(paramValue); - if (paramCount < keyParams.size()) sb.append(" AND "); - } - - sb.append(";"); - - try { - int rowCount = 0; - CachedRowSet data = jdbcDataSource.getData(sb.toString(), null, ""); - while(data.next()) { - rowCount ++; - data.deleteRow(); - } - if (rowCount != 0) { - LOG.debug("cleanupExistingToscaData in " + tableName + ": Data FOUND"); - String deleteStmt = sb.replace(sb.indexOf("SELECT *"), sb.indexOf("SELECT")+8, "DELETE").toString(); - jdbcDataSource.writeData(deleteStmt, null, null); - dataExists = true; - } - - } catch (SQLException e) { - LOG.error("Could not get data in " + tableName, e); - } - - return dataExists; - } - - protected boolean checkForExistingToscaData(String tableName, Map keyParams) throws IOException - { - boolean dataExists = false; - StringBuilder sb = new StringBuilder(); - sb.append("SELECT * from " + tableName + " where "); - - int paramCount = 0; - for (String paramKey : keyParams.keySet()) { - paramCount++; - String paramValue = keyParams.get(paramKey); - sb.append(paramKey); - sb.append(" = "); - sb.append(paramValue); - if (paramCount < keyParams.size()) sb.append(" AND "); - } - - sb.append(";"); - - try { - int rowCount = 0; - CachedRowSet data = jdbcDataSource.getData(sb.toString(), null, ""); - while(data.next()) { - rowCount ++; - } - if (rowCount != 0) { - LOG.debug("checkForExistingToscaData in " + tableName + ": Data FOUND"); - dataExists = true; - } - - } catch (SQLException e) { - LOG.error("Could not get data in " + tableName, e); - } - - return dataExists; - } - - protected CachedRowSet getToscaData(String tableName, Map keyParams) throws IOException - { - StringBuilder sb = new StringBuilder(); - sb.append("SELECT * from " + tableName + " where "); - - int paramCount = 0; - for (String paramKey : keyParams.keySet()) { - paramCount++; - String paramValue = keyParams.get(paramKey); - sb.append(paramKey); - sb.append(" = "); - sb.append(paramValue); - if (paramCount < keyParams.size()) sb.append(" AND "); - } - - sb.append(";"); - - CachedRowSet data = null; - try { - int rowCount = 0; - data = jdbcDataSource.getData(sb.toString(), null, ""); - while(data.next()) { - rowCount ++; - } - if (rowCount == 0) { - LOG.info("getToscaData in " + tableName + ": Data NOT found"); - } - - } catch (SQLException e) { - LOG.error("Could not get data in " + tableName, e); - } - - return data; - } - - protected void addParamsToMap (Map fromMap, Map toMap) { - for (String key : fromMap.keySet()) { - if (!toMap.containsKey(key)) { - toMap.put(key, fromMap.get(key)); - } - } - } - - protected String nullCheck (Object extractedObject) { - String stringValue = ""; - if (extractedObject != null) { - return extractedObject.toString(); - } - return stringValue; - } - -} 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 deleted file mode 100644 index 622936652..000000000 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncGroupModel.java +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights - * reserved. - * Modifications Copyright © 2018 IBM. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * 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.IEntityDetails; -import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -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(SdncGroupModel.class); - - private static final String groupType = "group_type"; - - public SdncGroupModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails group, IEntityDetails entityDetails, SdncUebConfiguration config, DBResourceManager jdbcDataSource) throws IOException { - - super(sdcCsarHelper, group); - - // Metadata for Resource group is not extracted in base class due to inconsistency in TOSCA model Group object - Metadata metadata = group.getMetadata(); - params.remove("invariant_uuid"); // remove invariant_uuid which is added by base class, it does not apply for groups - invariantUUID = extractValue (metadata, "invariantUUID"); - addParameter("group_invariant_uuid", invariantUUID); - params.remove("uuid"); // remove uuid which is added by base class, it does not apply for groups - UUID = extractValue (metadata, "UUID"); - addParameter("group_uuid", UUID); - addParameter("group_name", extractValue (metadata, "name")); - addParameter(groupType, group.getToscaType()); - addParameter("version", extractValue (metadata, "version")); - - // extract properties - addParameter("vfc_parent_port_role", extractValue(group, "vfc_parent_port_role"), attributeValueParams); - addParameter("subinterface_role", extractValue(group, "subinterface_role"), attributeValueParams); - - // relevant complex group properties are extracted and inserted into ATTRIBUTE_VALUE_PAIR - addParameter(extractGetInputName (group, groupType), extractGetInputValue(group, entityDetails, groupType), attributeValueParams); - addParameter(extractGetInputName (group, "group_role"), extractGetInputValue(group, entityDetails, "group_role"), attributeValueParams); - addParameter(extractGetInputName (group, "group_function"), extractGetInputValue(group, entityDetails, "group_function"), attributeValueParams); - } - - public void insertGroupData(String resourceUuid) throws IOException { - - try { - - // insert into RESOURCE_GROUP/ATTRIBUTE_VALUE_PAIR - cleanUpExistingToscaData("RESOURCE_GROUP", "resource_uuid", resourceUuid, "group_uuid", getUUID()) ; - LOG.info("Call insertToscaData for RESOURCE_GROUP where group_uuid = " + getUUID() + " and resource_uuid = " + resourceUuid); - insertToscaData(buildSql("RESOURCE_GROUP", "resource_uuid", resourceUuid, model_yaml, params), null); - insertRelevantAttributeData("group"); - - } catch (IOException e) { - 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 deleted file mode 100644 index 8e790d9be..000000000 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncNodeModel.java +++ /dev/null @@ -1,220 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.northbound.uebclient; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.onap.sdc.tosca.parser.api.IEntityDetails; -import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; -import org.onap.sdc.toscaparser.api.Property; -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, IEntityDetails nodeEntity, DBResourceManager jdbcDataSource, SdncUebConfiguration config) throws IOException { - - super(sdcCsarHelper, nodeEntity, jdbcDataSource, config); - - // extract properties - addParameter("ecomp_generated_naming", extractBooleanValue (nodeEntity, "exVL_naming", "ecomp_generated_naming")); // should be extractBooleanValue? - addParameter("naming_policy", extractValue (nodeEntity, "exVL_naming", "naming_policy")); - - addParameter("network_type", extractValue (nodeEntity, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE)); - addParameter("network_role", extractValue (nodeEntity, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE)); - addParameter("network_scope", extractValue (nodeEntity, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE)); - addParameter("network_technology", extractValue (nodeEntity, SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY)); - - // extract properties - network_assignments - addParameter("is_shared_network", extractBooleanValue (nodeEntity, "network_assignments", "is_shared_network")); - addParameter("is_external_network", extractBooleanValue (nodeEntity, "network_assignments", "is_external_network")); - String trunkNetworkIndicator = extractBooleanValue(nodeEntity, "network_assignments", "is_trunked"); - addParameter("trunk_network_indicator", trunkNetworkIndicator); - - // extract properties - network_assignments - ipv4_subnet_default_assignment - String useIpv4 = extractBooleanValue(nodeEntity, "network_assignments", "ipv4_subnet_default_assignment", "use_ipv4"); - addParameter("use_ipv4", useIpv4); - addParameter("ipv4_dhcp_enabled", extractBooleanValue(nodeEntity, "network_assignments", "ipv4_subnet_default_assignment", "dhcp_enabled")); - addParameter("ipv4_ip_version", extractValue(nodeEntity, "network_assignments", "ipv4_subnet_default_assignment", "ip_version")); - addParameter("ipv4_cidr_mask", extractValue(nodeEntity, "network_assignments", "ipv4_subnet_default_assignment", "cidr_mask")); - addParameter("eipam_v4_address_plan", extractValue(nodeEntity, "network_assignments", "ipv4_subnet_default_assignment", "ip_network_address_plan")); - - // extract properties - network_assignments - ipv6_subnet_default_assignment - String useIpv6 = extractBooleanValue(nodeEntity, "network_assignments", "ipv6_subnet_default_assignment", "use_ipv6"); - addParameter("use_ipv6", useIpv6); - addParameter("ipv6_dhcp_enabled", extractBooleanValue(nodeEntity, "network_assignments", "ipv6_subnet_default_assignment", "dhcp_enabled")); - addParameter("ipv6_ip_version", extractValue(nodeEntity, "network_assignments", "ipv6_subnet_default_assignment", "ip_version")); - addParameter("ipv6_cidr_mask", extractValue(nodeEntity, "network_assignments", "ipv6_subnet_default_assignment", "cidr_mask")); - addParameter("eipam_v6_address_plan", extractValue(nodeEntity, "network_assignments", "ipv6_subnet_default_assignment", "ip_network_address_plan")); - - // extract properties - provider_network - addParameter("is_provider_network", extractBooleanValue (nodeEntity, "provider_network", "is_provider_network")); - addParameter("physical_network_name", extractValue(nodeEntity, "provider_network", "physical_network_name")); - - // extract properties - network_flows - addParameter("is_bound_to_vpn", extractBooleanValue (nodeEntity, "network_flows", "is_bound_to_vpn")); - - // extract properties - network_flows - vpn_bindings - String vpnBindingString = extractValue (nodeEntity, "network_flows", "vpn_binding"); - bindingUuids = vpnBindingString.split(","); - - } - - public String getServiceUUID() { - return serviceUUID; - } - public void setServiceUUID(String serviceUUID) { - this.serviceUUID = serviceUUID; - } - - public String getEcompGeneratedNaming() { - return ecompGeneratedNaming; - } - public void setEcompGeneratedNaming(String ecompGeneratedNaming) { - this.ecompGeneratedNaming = ecompGeneratedNaming; - if (ecompGeneratedNaming != null && !ecompGeneratedNaming.isEmpty()) { - params.put("ecomp_generated_naming", "\"" + ecompGeneratedNaming + "\""); - } - } - public void setComplexResourceUUID(String complexResourceUuid) { - if (complexResourceUuid != null && !complexResourceUuid.isEmpty()) { - params.put("complex_resource_uuid", complexResourceUuid); - } - } - - public void setComplexResourceCustomizationUUID(String complexResourceCustomizationUuid) { - if (complexResourceCustomizationUuid != null && !complexResourceCustomizationUuid.isEmpty()) { - params.put("complex_resource_customization_uuid", complexResourceCustomizationUuid); - } - } - - public void insertNetworkModelData () throws IOException { - try { - // Clean up NETWORK_MODEL data for this customization_uuid and service_uuid? - cleanUpExistingToscaData("NETWORK_MODEL", "customization_uuid", getCustomizationUUID()); - cleanUpExistingToscaData("VPN_BINDINGS", "network_customization_uuid", getCustomizationUUID()); - LOG.info("Call insertToscaData for NETWORK_MODEL where customization_uuid = " + 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 void insertRelatedNetworkRoleData () throws IOException { - - if (entityDetails.getProperties().containsKey("network_assignments")) { - - Map networkAssignmentsPropertyValue = (Map) entityDetails.getProperties().get("network_assignments").getValue(); - - if (networkAssignmentsPropertyValue != null && networkAssignmentsPropertyValue.containsKey("related_networks")) { - - ArrayList> relatedNetworkList = (ArrayList) networkAssignmentsPropertyValue.get("related_networks"); - String networkModelCustomizationUUID = getCustomizationUUID(); - - try { - cleanUpExistingToscaData("RELATED_NETWORK_ROLE", "network_model_customization_uuid", networkModelCustomizationUUID); - } catch (IOException e) { - LOG.error("Could not clean up Tosca CSAR data in the RELATED_NETWORK_ROLE table"); - throw new IOException (e); - } - - for (Map relatedNetworkValue : relatedNetworkList) { - String relatedNetworkRoleValue = relatedNetworkValue.get("related_network_role"); - LOG.debug("Node Template [" + entityDetails.getName() + "], property [" + "related_network_role" + "] property value: " + relatedNetworkRoleValue); - - try { - // Table cleanup RELATED_NETWORK_ROLE occurs per network - // If related_network_role for this service already exist in RELATED_NETWORK_ROLE, don't attempt insertion - Map relatedNetworkRoleParamsCheck = new HashMap(); - addParameter("related_network_role", relatedNetworkRoleValue, relatedNetworkRoleParamsCheck); - addParameter("network_model_customization_uuid", networkModelCustomizationUUID, relatedNetworkRoleParamsCheck); - if (checkForExistingToscaData("RELATED_NETWORK_ROLE", relatedNetworkRoleParamsCheck) == false) { - relatedNetworkRoleParamsCheck.remove("related_network_role"); - LOG.info("Call insertToscaData for RELATED_NETWORK_ROLE where network_model_customization_uuid = " + networkModelCustomizationUUID); - insertToscaData(buildSql("RELATED_NETWORK_ROLE", "related_network_role", "\"" + relatedNetworkRoleValue + "\"", model_yaml, relatedNetworkRoleParamsCheck), null); - } - } catch (IOException e) { - LOG.debug("Could not insert Tosca CSAR data into the RELATED_NETWORK_ROLE table"); - throw new IOException (e); - } - } - } - else { - LOG.debug("Node Template [" + entityDetails.getName() + "], property [" + "related_networks" + "] property value: " + null); - } - } - - } - - public String getSql(String model_yaml) { - - StringBuilder sb = new StringBuilder(); - sb.append("INSERT into NETWORK_MODEL (service_uuid, customization_uuid, model_yaml, "); - - int paramCount = 0; - for (String paramKey : params.keySet()) { - paramCount++; - sb.append(paramKey); - if (paramCount < params.size()) sb.append(", "); - } - - sb.append(") values (" + serviceUUID + ", " + getCustomizationUUID() + ", \"" + model_yaml + "\", "); - - paramCount = 0; - for (String paramKey : params.keySet()) { - paramCount++; - String paramValue = params.get(paramKey); - sb.append(paramValue); - if (paramCount < params.size()) sb.append(", "); - } - - sb.append(");"); - return sb.toString(); - } - - public String getVpnBindingsSql() { - - StringBuilder sb = new StringBuilder(); - for (int i=0; i < bindingUuids.length; i++) { - sb.append("INSERT into VPN_BINDINGS (network_customization_uuid, binding_uuid) values (" + getCustomizationUUID() + ", \"" + bindingUuids[i] + "\"); "); - } - - return sb.toString(); - } - -} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java deleted file mode 100644 index 78d9c5bc9..000000000 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncOdlConnection.java +++ /dev/null @@ -1,158 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.northbound.uebclient; - -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.Authenticator; -import java.net.HttpURLConnection; -import java.net.PasswordAuthentication; -import java.net.URL; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLSession; - -import org.apache.commons.codec.binary.Base64; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -public class SdncOdlConnection { - - private static final Logger LOG = LoggerFactory - .getLogger(SdncOdlConnection.class); - - private HttpURLConnection httpConn = null; - - private String url = null; - private String user = null; - private String password = null; - - private class SdncAuthenticator extends Authenticator { - - private String user; - private String passwd; - - SdncAuthenticator(String user, String passwd) { - this.user = user; - this.passwd = passwd; - } - @Override - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(user, passwd.toCharArray()); - } - - } - - private SdncOdlConnection() { - - } - - private SdncOdlConnection(String url, String user, String password) { - this.url = url; - this.user = user; - this.password = password; - - try { - URL sdncUrl = new URL(url); - Authenticator.setDefault(new SdncAuthenticator(user, password)); - - this.httpConn = (HttpURLConnection) sdncUrl.openConnection(); - } catch (Exception e) { - LOG.error("Unable to create http connection", e); - } - } - - public static SdncOdlConnection newInstance(String url, String user, String password) throws IOException - { - return new SdncOdlConnection(url, user, password); - } - - - - public String send(String method, String contentType, String msg) throws IOException { - - LOG.info("Sending REST " + method + " to " + url); - LOG.info("Message body:\n" + msg); - String authStr = user + ":" + password; - String encodedAuthStr = new String(Base64.encodeBase64(authStr.getBytes())); - - httpConn.addRequestProperty("Authentication", "Basic " + encodedAuthStr); - - httpConn.setRequestMethod(method); - httpConn.setRequestProperty("Content-Type", contentType); - httpConn.setRequestProperty("Accept", contentType); - - httpConn.setDoInput(true); - httpConn.setDoOutput(true); - httpConn.setUseCaches(false); - - if (httpConn instanceof HttpsURLConnection) { - HostnameVerifier hostnameVerifier = new HostnameVerifier() { - @Override - public boolean verify(String hostname, SSLSession session) { - return true; - } - }; - ((HttpsURLConnection) httpConn).setHostnameVerifier(hostnameVerifier); - } - - // Write message - httpConn.setRequestProperty("Content-Length", "" + msg.length()); - DataOutputStream outStr = new DataOutputStream(httpConn.getOutputStream()); - outStr.write(msg.getBytes()); - outStr.close(); - - // Read response - BufferedReader respRdr; - - LOG.info("Response: " + httpConn.getResponseCode() + " " + httpConn.getResponseMessage()); - - if (httpConn.getResponseCode() < 300) { - - respRdr = new BufferedReader(new InputStreamReader(httpConn.getInputStream())); - } else { - respRdr = new BufferedReader(new InputStreamReader(httpConn.getErrorStream())); - } - - StringBuilder respBuff = new StringBuilder(); - - String respLn; - - while ((respLn = respRdr.readLine()) != null) { - respBuff.append(respLn + "\n"); - } - respRdr.close(); - - String respString = respBuff.toString(); - - LOG.info("Response body :\n" + respString); - - return respString; - - } - - -} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncPNFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncPNFModel.java deleted file mode 100644 index 296b13819..000000000 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncPNFModel.java +++ /dev/null @@ -1,142 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.northbound.uebclient; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; -import org.onap.sdc.tosca.parser.api.IEntityDetails; -import org.onap.sdc.toscaparser.api.elements.Metadata; -import org.onap.ccsdk.sli.core.dblib.DBResourceManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SdncPNFModel extends SdncBaseModel { - - private static final Logger LOG = LoggerFactory - .getLogger(SdncVFModel.class); - - private String vendor = null; - private String vendorModelDescription = null; - private String nfNamingCode = null; - private String serviceUUID = null; - private String serviceInvariantUUID = null; - - public SdncPNFModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails entityDetails, DBResourceManager jdbcDataSource, SdncUebConfiguration config) throws IOException { - - super(sdcCsarHelper, entityDetails, jdbcDataSource, config); - - // extract metadata - Metadata metadata = entityDetails.getMetadata(); - addParameter("name", extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_NAME)); - vendor = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDOR); - addParameter("vendor", vendor); - vendorModelDescription = extractValue (metadata, "description"); - addParameter("vendor_version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDORRELEASE)); - - // extract properties - addParameter("ecomp_generated_naming", extractBooleanValue(entityDetails, "nf_naming#ecomp_generated_naming")); - addParameter("naming_policy", extractValue(entityDetails, "nf_naming#naming_policy")); - addParameter("nf_type", extractValue(entityDetails, SdcPropertyNames.PROPERTY_NAME_NFTYPE)); - addParameter("nf_role", extractValue(entityDetails, SdcPropertyNames.PROPERTY_NAME_NFROLE)); - nfNamingCode = extractValue(entityDetails, "nf_naming_code"); - addParameter("nf_code", nfNamingCode); - addParameter("nf_function", extractValue(entityDetails, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)); - addIntParameter("avail_zone_max_count", extractValue(entityDetails, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONEMAXCOUNT)); - addParameter("sdnc_model_name", extractValue(entityDetails, "sdnc_model_name")); - addParameter("sdnc_model_version", extractValue(entityDetails, "sdnc_model_version")); - addParameter("sdnc_artifact_name", extractValue(entityDetails, "sdnc_artifact_name")); - - } - - public void insertData() throws IOException { - - insertPNFModelData(); - } - - private void insertPNFModelData () throws IOException { - - try { - cleanUpExistingToscaData("VF_MODEL", "customization_uuid", getCustomizationUUID()) ; - cleanUpExistingToscaData("SERVICE_MODEL_TO_VF_MODEL_MAPPING", "service_uuid", serviceUUID, "vf_customization_uuid", getCustomizationUUID()); - - // insert into VF_MODEL/ATTRIBUTE_VALUE_PAIR and SERVICE_MODEL_TO_VF_MODEL_MAPPING - LOG.info("Call insertToscaData for VF_MODEL where customization_uuid = " + getCustomizationUUID()); - insertToscaData(buildSql("VF_MODEL", model_yaml), null); - //insertRelevantAttributeData(); - - Map mappingParams = new HashMap(); - addParameter("service_invariant_uuid", serviceInvariantUUID, mappingParams); - addParameter("vf_uuid", getUUID(), mappingParams); - addParameter("vf_customization_uuid", getCustomizationUUIDNoQuotes(), mappingParams); - insertToscaData(buildSql("SERVICE_MODEL_TO_VF_MODEL_MAPPING", "service_uuid", serviceUUID, model_yaml, mappingParams), null); - - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the VF_MODEL table"); - throw new IOException (e); - } - - } - - public String getVendor() { - return vendor; - } - - public void setVendor(String vendor) { - this.vendor = vendor; - } - - public String getVendorModelDescription() { - return vendorModelDescription; - } - - public void setVendorModelDescription(String vendorModelDescription) { - this.vendorModelDescription = vendorModelDescription; - } - - public String getNfNamingCode() { - return nfNamingCode; - } - - public void setNfNamingCode(String nfNamingCode) { - this.nfNamingCode = nfNamingCode; - } - - public String getServiceUUID() { - return serviceUUID; - } - public void setServiceUUID(String serviceUUID) { - this.serviceUUID = serviceUUID; - } - - public String getServiceInvariantUUID() { - return serviceInvariantUUID; - } - - public void setServiceInvariantUUID(String serviceInvariantUUID) { - this.serviceInvariantUUID = serviceInvariantUUID; - } - -} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java deleted file mode 100644 index 52e38624a..000000000 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncServiceModel.java +++ /dev/null @@ -1,125 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.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; -import org.slf4j.Logger; -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; - - public SdncServiceModel(ISdcCsarHelper sdcCsarHelper, Metadata metadata, DBResourceManager jdbcDataSource) { - - super(sdcCsarHelper, metadata, jdbcDataSource); - - UUID = extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_UUID); - - // 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() { - return "\"" + UUID + "\""; - } - public void setServiceUUID(String serviceUUID) { - this.UUID = serviceUUID; - } - public String getServiceInvariantUUID() { - return "\"" + invariantUUID + "\""; - } - public String getServiceInstanceNamePrefix() { - return serviceInstanceNamePrefix; - } - public void setServiceInstanceNamePrefix(String serviceInstanceNamePrefix) { - if (serviceInstanceNamePrefix != null && !serviceInstanceNamePrefix.isEmpty()) { - this.serviceInstanceNamePrefix = serviceInstanceNamePrefix; - params.put("service_instance_name_prefix", "\"" + serviceInstanceNamePrefix + "\""); - } - } - public String getFilename() { - return filename; - } - public void setFilename(String filename) { - this.filename = filename; - } - - public String getSql(String model_yaml) { - - StringBuilder sb = new StringBuilder(); - sb.append("INSERT into SERVICE_MODEL (service_uuid, model_yaml, filename, "); - - int paramCount = 0; - for (String paramKey : params.keySet()) { - paramCount++; - sb.append(paramKey); - if (paramCount < params.size()) sb.append(", "); - } - - sb.append(") values (" + getServiceUUID() + ", \"" + model_yaml + "\", \"" + filename + "\", "); - - paramCount = 0; - for (String paramKey : params.keySet()) { - paramCount++; - String paramValue = params.get(paramKey); - sb.append(paramValue); - if (paramCount < params.size()) sb.append(", "); - } - - sb.append(");"); - return sb.toString(); - } - - 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 deleted file mode 100644 index 8c3a290e0..000000000 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java +++ /dev/null @@ -1,1263 +0,0 @@ -/*- - * ============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.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.net.Authenticator; -import java.net.HttpURLConnection; -import java.net.PasswordAuthentication; -import java.net.URL; -import java.nio.file.DirectoryStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.sql.SQLException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import javax.sql.rowset.CachedRowSet; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.stream.StreamResult; -import javax.xml.transform.stream.StreamSource; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathFactory; -import javax.xml.XMLConstants; - -import org.apache.commons.codec.binary.Base64; -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; -import org.onap.sdc.api.notification.INotificationData; -import org.onap.sdc.api.notification.IResourceInstance; -import org.onap.sdc.api.results.IDistributionClientDownloadResult; -import org.onap.sdc.api.results.IDistributionClientResult; -import org.onap.sdc.tosca.parser.api.IEntityDetails; -import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.tosca.parser.elements.queries.EntityQuery; -import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery; -import org.onap.sdc.tosca.parser.enums.SdcTypes; -import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; -import org.onap.sdc.toscaparser.api.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); - - 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 { - - private final String user; - private final String passwd; - - SdncAuthenticator(String user, String passwd) { - this.user = user; - this.passwd = passwd; - } - @Override - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(user, passwd.toCharArray()); - } - - } - - private class DeployableArtifact { - SdncArtifactType type; - IArtifactInfo artifactInfo; - String svcName; - String resourceName; - String artifactName; - String artifactVersion; - File file; - - public String getArtifactName() { - return artifactName; - } - - - - public String getArtifactVersion() { - return artifactVersion; - } - - - public SdncArtifactType getType() { - return type; - } - - - - public IArtifactInfo getArtifactInfo() { - return artifactInfo; - } - - - public File getFile() { - return file; - } - - - - - public DeployableArtifact(SdncArtifactType type, String svcName, String resourceName, IArtifactInfo artifactInfo, File file) { - this.type = type; - this.artifactInfo = artifactInfo; - this.svcName = svcName; - this.resourceName = resourceName; - this.artifactName = artifactInfo.getArtifactName(); - this.artifactVersion = artifactInfo.getArtifactVersion(); - this.file = file; - } - - - public DeployableArtifact(SdncArtifactType type, String svcName, String resourceName, String artifactName, String artifactVersion, File file) { - this.type = type; - this.artifactInfo = null; - this.svcName = svcName; - this.resourceName = resourceName; - this.artifactName = artifactName; - this.artifactVersion = artifactVersion; - this.file = file; - } - - - - public String getSvcName() { - return svcName; - } - - - - public String getResourceName() { - return resourceName; - } - - } - - private final IDistributionClient client; - protected final SdncUebConfiguration config; - - private LinkedList deployList[]; - - - private static void setJdbcDataSource() throws IOException { - - String propPath = null; - String propDir = System.getenv(SDNC_CONFIG_DIR); - if (propDir == null) { - - propDir = "/opt/sdnc/data/properties"; - } - propPath = propDir + "/dblib.properties"; - File propFile = new File(propPath); - - if (!propFile.exists()) { - - throw new FileNotFoundException( - "Missing configuration properties file : " - + propFile); - } - - Properties props = new Properties(); - props.load(new FileInputStream(propFile)); - - setJdbcDataSource(new DBResourceManager(props)); - } - - static void setJdbcDataSource(DBResourceManager dbMgr) { - - jdbcDataSource = dbMgr; - - if(jdbcDataSource.isActive()){ - LOG.warn( "DBLIB: JDBC DataSource has been initialized."); - } else { - LOG.warn( "DBLIB: JDBC DataSource did not initialize successfully."); - } - } - - private static void loadArtifactMap() { - - } - - public SdncUebCallback(IDistributionClient client, SdncUebConfiguration config) { - this.client = client; - this.config = config; - - this.deployList = new LinkedList[NUM_PASSES]; - - for (int i = 0 ; i < NUM_PASSES ; i++) { - this.deployList[i] = new LinkedList(); - } - } - - @Override - public void activateCallback(INotificationData data) { - - 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 = new File(incomingDirName); - File archiveDir = new File(archiveDirName); - - LOG.debug("IncomingDirName is {}", incomingDirName); - - if (!incomingDir.exists()) { - incomingDir.mkdirs(); - } - - - if (!archiveDir.exists()) { - archiveDir.mkdirs(); - } - - // Process service level artifacts - List artifactList = data.getServiceArtifacts(); - - if (artifactList != null) { - - incomingDir = new File(incomingDirName + "/" + escapeFilename(data.getServiceName())); - if (!incomingDir.exists()) { - incomingDir.mkdirs(); - } - - archiveDir = new File(archiveDirName + "/" + escapeFilename(data.getServiceName())); - if (!archiveDir.exists()) { - archiveDir.mkdirs(); - } - for (IArtifactInfo curArtifact : artifactList) - { - - LOG.info("Received artifact " + curArtifact.getArtifactName()); - - // 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); - } - } - - - // Process resource level artifacts - for (IResourceInstance curResource : data.getResources()) { - - LOG.info("Received resource : "+curResource.getResourceName()); - artifactList = curResource.getArtifacts(); - - if (artifactList != null) { - - incomingDir = new File(incomingDirName + "/" + escapeFilename(data.getServiceName()) + "/" + escapeFilename(curResource.getResourceName())); - if (!incomingDir.exists()) { - incomingDir.mkdirs(); - } - - archiveDir = new File(archiveDirName + "/" + escapeFilename(data.getServiceName()) + "/" + escapeFilename(curResource.getResourceName())); - if (!archiveDir.exists()) { - archiveDir.mkdirs(); - } - for (IArtifactInfo curArtifact : artifactList) - { - - LOG.info("Received artifact " + curArtifact.getArtifactName()); - - handleArtifact(data, data.getServiceName(), curResource.getResourceName(), curResource.getResourceType(), curArtifact, incomingDir, archiveDir); - } - } - } - - deployDownloadedFiles(incomingDir, archiveDir, data); - - // 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()); - incomingDir = new File(config.getIncomingDir()); - - if (!incomingDir.exists()) { - incomingDir.mkdirs(); - } - - } else { - LOG.debug("incomingDir is not null - it is {}", incomingDir.getPath()); - } - - if (archiveDir == null) { - archiveDir = new File(config.getArchiveDir()); - - if (!archiveDir.exists()) { - archiveDir.mkdirs(); - } - } - - String curFileName = ""; - try (DirectoryStream stream = Files.newDirectoryStream(incomingDir.toPath())) { - for (Path file: stream) { - curFileName = file.toString(); - // 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 (Exception x) { - // IOException can never be thrown by the iteration. - // In this snippet, it can only be thrown by newDirectoryStream. - LOG.warn("Cannot process spool file "+ curFileName, x); - } - - // Deploy scheduled deployments - /*int numPasses = config.getMaxPasses(); - - deployList = new LinkedList[numPasses]; - - for (int i = 0 ; i < numPasses ; i++) { - deployList[i] = new LinkedList(); - }*/ - for (int pass = 0 ; pass < config.getMaxPasses() ; pass++) { - - if (deployList[pass] != null) { - while (! deployList[pass].isEmpty()) { - DeployableArtifact artifact = deployList[pass].pop(); - - DistributionStatusEnum deployResult = DistributionStatusEnum.DEPLOY_ERROR; - - - try { - - deployResult = deploySpoolFile(artifact); - } catch (Exception e) { - LOG.error("Caught exception trying to deploy file", e); - } - - - IArtifactInfo artifactInfo = artifact.getArtifactInfo(); - - if ((artifactInfo != null) && (data != null)) { - IDistributionClientResult deploymentStatus; - deploymentStatus = client.sendDeploymentStatus(buildStatusMessage( - client, data, artifactInfo, - deployResult)); - if (deployResult == DistributionStatusEnum.DEPLOY_ERROR) { - COMPONENT_DEPLOY_ERROR = true; - } - } - - } - } - } - } - - private void handleArtifact(INotificationData data, String svcName, String resourceName, String resourceType, IArtifactInfo artifact, File incomingDir, File archiveDir) { - - // Download Artifact - IDistributionClientDownloadResult downloadResult = client.download(artifact); - - if (downloadResult == null) { - - handleFailedDownload(data, artifact); - return; - } - - byte[] payloadBytes = downloadResult.getArtifactPayload(); - - if (payloadBytes == null) { - handleFailedDownload(data, artifact); - return; - } - - 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); - writeSucceeded = true; - } catch (Exception e) { - LOG.error("Unable to save downloaded zip file to spool directory ("+ incomingDir.getAbsolutePath() +")", e); - } - - } else { - - String payload = new String(payloadBytes); - - try(FileWriter spoolFileWriter = new FileWriter(spoolFile)) { - spoolFileWriter.write(payload); - writeSucceeded = true; - } catch (Exception e) { - LOG.error("Unable to save downloaded file to spool directory ("+ incomingDir.getAbsolutePath() +")", e); - } - } - - - if (writeSucceeded && (downloadResult.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS)) { - handleSuccessfulDownload(data, svcName, resourceName, artifact, spoolFile, archiveDir); - - - } else { - handleFailedDownload(data, artifact); - } - - } - - private void handleFailedDownload(INotificationData data, - IArtifactInfo relevantArtifact) { - // Send Download Status - 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 spoolFile, File archiveDir) { - - if ((data != null) && (artifact != null)) { - // Send Download Status - IDistributionClientResult sendDownloadStatus = client - .sendDownloadStatus(buildStatusMessage(client, data, artifact, DistributionStatusEnum.DOWNLOAD_OK)); - } - - // If an override file exists, read that instead of the file we just downloaded - ArtifactTypeEnum artifactEnum = ArtifactTypeEnum.YANG_XML; - - String overrideFileName = config.getOverrideFile(); - if ((overrideFileName != null) && (overrideFileName.length() > 0)) { - File overrideFile = new File(overrideFileName); - - if (overrideFile.exists()) { - artifactEnum = ArtifactTypeEnum.YANG_XML; - spoolFile = overrideFile; - } - - } - - // If 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; - - // Apply XSLTs and get Doc object - try { - if (!spoolFile.isDirectory()) { - transformedFile = applyXslts(spoolFile); - } - } catch (Exception e) { - LOG.error("Caught exception trying to parse XML file", e); - } - - if (transformedFile != null) { - try { - - try { - - DocumentBuilderFactory dbf = DocumentBuilderFactory - .newInstance(); - 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 deploy file", e); - } - } - - ArtifactTypeEnum artifactEnum = ArtifactTypeEnum.YANG_XML; - if (spoolDoc != null) { - // Analyze file type - SdncArtifactType artifactType = analyzeFileType(artifactEnum, - spoolFile, spoolDoc); - - if (artifactType != null) { - - scheduleDeployment(artifactType, svcName, resourceName, artifact, spoolFile.getName(), transformedFile); - - } - - // SDNGC-2660 : Move file to archive directory even if it is an unrecognized type so that - // we do not keep trying and failing to process it. - try { - Path source = spoolFile.toPath(); - Path targetDir = archiveDir.toPath(); - - Files.move(source, targetDir.resolve(source.getFileName()), StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { - LOG.warn("Could not move "+spoolFile.getAbsolutePath()+" to "+archiveDir.getAbsolutePath(), e); - } - } - - } - - private void 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 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()); - 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 DistributionStatusEnum.DEPLOY_ERROR; - } - - // Ingest Service Data - 1707 - Metadata serviceMetadata = sdcCsarHelper.getServiceMetadata(); - 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)); - - try { - cleanUpExistingToscaServiceData(serviceModel.getServiceUUID()); - 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 CSAR data into the SERVICE_MODEL table ", e); - return DistributionStatusEnum.DEPLOY_ERROR; - - } - - // Ingest Network (VL) Data - 1707 / migrate to getEntity - 1908 - EntityQuery vlEntityQuery = EntityQuery.newBuilder(SdcTypes.VL).build(); - TopologyTemplateQuery vlTopologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).build(); - List vlEntities = sdcCsarHelper.getEntity(vlEntityQuery, vlTopologyTemplateQuery, false); // false to not recurse - if (vlEntities != null && !vlEntities.isEmpty()) { - for (IEntityDetails vlEntity : vlEntities){ - - try { - SdncNodeModel nodeModel = new SdncNodeModel (sdcCsarHelper, vlEntity, jdbcDataSource, config); - nodeModel.setServiceUUID(serviceModel.getServiceUUID()); - - nodeModel.insertNetworkModelData(); - nodeModel.insertRelatedNetworkRoleData(); - } catch (IOException e) { - deployStatus = DistributionStatusEnum.DEPLOY_ERROR; - } - } - } - - // Ingest Allotted Resource Data - 1707 / migrate to getEntity - 1908 - // Use getEntity to get all VFs in the service filter by metadata Category = Allotted Resource - EntityQuery vfEntityQuery = EntityQuery.newBuilder(SdcTypes.VF).build(); - TopologyTemplateQuery vfTopologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).build(); - List vfEntities = sdcCsarHelper.getEntity(vfEntityQuery, vfTopologyTemplateQuery, true); - if (vfEntities != null) { - for (IEntityDetails vfEntity : vfEntities){ - - // If this VF has metadata Category: Allotted Resource, insert it into ALLOTTED_RESOURCE_MODEL table - String vfCategory = SdncBaseModel.extractValue(sdcCsarHelper, vfEntity.getMetadata(), "category"); - if (vfCategory.contains("Allotted Resource")) { - - try { - SdncARModel arModel = new SdncARModel (sdcCsarHelper, vfEntity, jdbcDataSource, config); - arModel.insertAllottedResourceModelData (); - arModel.insertAllottedResourceVfcModelData(); - } catch (IOException e) { - deployStatus = DistributionStatusEnum.DEPLOY_ERROR; - } - } - } - } - - // Ingest Network (VF) Data - 1707 / migrate to getEntity - 1911 - // Use getEntity to get all VFs in the service - if (vfEntities != null) { - for (IEntityDetails vfEntity : vfEntities){ - - SdncVFModel vfNodeModel = null; - try { - vfNodeModel = new SdncVFModel (sdcCsarHelper, vfEntity, jdbcDataSource, config); - vfNodeModel.setServiceUUID(serviceModel.getServiceUUID()); - vfNodeModel.setServiceInvariantUUID(serviceModel.getServiceInvariantUUID()); - vfNodeModel.insertData(); - - } catch (IOException e) { - deployStatus = DistributionStatusEnum.DEPLOY_ERROR; - } - - // For each VF, insert VNF Configuration data - DistributionStatusEnum vnfConfigDeployStatus = customProcessVnfConfig(sdcCsarHelper, vfNodeModel, jdbcDataSource); - if (vnfConfigDeployStatus == DistributionStatusEnum.DEPLOY_ERROR) { - deployStatus = DistributionStatusEnum.DEPLOY_ERROR; - } - - } // VF loop - } - - - // Ingest Network (PNF) Data - Dublin/1906 - EntityQuery entityQuery = EntityQuery.newBuilder(SdcTypes.PNF).build(); - TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).build(); - - List pnfs = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false); - if (!pnfs.isEmpty()) { - - for (IEntityDetails pnf : pnfs) { - - try { - SdncPNFModel pnfModel = new SdncPNFModel(sdcCsarHelper, pnf, jdbcDataSource, config); - pnfModel.setServiceUUID(serviceModel.getServiceUUID()); - pnfModel.setServiceInvariantUUID(serviceModel.getServiceInvariantUUID()); - pnfModel.insertData(); - - } catch (IOException e) { - deployStatus = DistributionStatusEnum.DEPLOY_ERROR; - } - } // PNF loop - } - - DistributionStatusEnum complexToscaDeployStatus = customProcessComplexTosca(sdcCsarHelper, config, jdbcDataSource, serviceModel, - data, svcName, resourceName, artifact, archiveDir); - if (complexToscaDeployStatus == DistributionStatusEnum.DEPLOY_ERROR) { - deployStatus = DistributionStatusEnum.DEPLOY_ERROR; - } - - return deployStatus; - } - - 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) { - setJdbcDataSource(); - } - try { - int rowCount = 0; - CachedRowSet data = jdbcDataSource.getData("SELECT * from " + tableName + " where " + keyName + " = " + keyValue + ";", null, ""); - while(data.next()) { - rowCount ++; - } - if (rowCount != 0) { - LOG.info("cleanUpExistingToscaData: " + keyValue); - jdbcDataSource.writeData("DELETE from " + tableName + " where " + keyName + " = " + keyValue + ";", null, null); - } - - } catch (SQLException e) { - LOG.error("Could not clean up existing " + tableName + " for " + keyValue, e); - } - - } - - - protected void cleanUpExistingToscaServiceData(String serviceUUID) throws IOException - { - - if (jdbcDataSource == null) { - setJdbcDataSource(); - } - try { - int rowCount = 0; - CachedRowSet data = jdbcDataSource.getData("SELECT * from SERVICE_MODEL where service_uuid = " + serviceUUID + ";", null, ""); - while(data.next()) { - rowCount ++; - } - if (rowCount != 0) { - LOG.info("cleanUpExistingToscaData: " + serviceUUID); - jdbcDataSource.writeData("DELETE from NETWORK_MODEL where service_uuid = " + serviceUUID + ";", null, null); - jdbcDataSource.writeData("DELETE from SERVICE_MODEL where service_uuid = " + serviceUUID + ";", null, null); - } - - } catch (SQLException e) { - LOG.error("Could not clean up existing NETWORK_MODEL and SERVICE_MODEL for service_UUID " + serviceUUID, e); - } - - } - - - protected void insertToscaData(String toscaDataString, ArrayList arguments) throws IOException - { - LOG.debug("insertToscaData: " + toscaDataString); - - if (jdbcDataSource == null) { - setJdbcDataSource(); - } - try { - - jdbcDataSource.writeData(toscaDataString, arguments, null); - - } catch (SQLException e) { - LOG.error("Could not insert Tosca YAML data into the database "); - throw new IOException (e); - } - - } - - - private SdncArtifactType analyzeFileType(ArtifactTypeEnum artifactType, File spoolFile, Document spoolDoc) { - - if (artifactType != ArtifactTypeEnum.YANG_XML) { - LOG.error("Unexpected artifact type - expecting YANG_XML, got "+artifactType); - return null; - } - - // Examine outer tag - - try { - - - Element root = spoolDoc.getDocumentElement(); - - String rootName = root.getTagName(); - - if (rootName.contains(":")) { - String[] rootNameElems = rootName.split(":"); - rootName = rootNameElems[rootNameElems.length - 1]; - } - - if (rootName != null) { - SdncArtifactType mapEntry = config.getMapping(rootName); - - - if (mapEntry == null) { - - LOG.error("Unexpected file contents - root tag is "+rootName); - } - return mapEntry; - } else { - LOG.error("Cannot get root tag from file"); - return null; - } - - } catch (Exception e) { - LOG.error("Could not parse YANG_XML file "+spoolFile.getName(), e); - return null; - } - } - - private void scheduleDeployment(SdncArtifactType type, String svcName, String resourceName, IArtifactInfo artifactInfo, String spoolFileName, File spoolFile) { - - if (type.getPass() < deployList.length) { - - if (artifactInfo != null) { - LOG.debug("Scheduling "+artifactInfo.getArtifactName()+" version "+artifactInfo.getArtifactVersion()+" for deployment"); - - deployList[type.getPass()].add(new DeployableArtifact(type, svcName, resourceName, artifactInfo, spoolFile)); - } else { - SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss.SSS");//dd/MM/yyyy - Date now = new Date(); - String artifactVersion = sdfDate.format(now); - LOG.debug("Scheduling "+spoolFileName+" version "+artifactVersion+" for deployment"); - String artifactName = spoolFileName; - if (artifactInfo != null) { - artifactName = artifactInfo.getArtifactName(); - } - deployList[type.getPass()].add(new DeployableArtifact(type, svcName, resourceName, artifactName, artifactVersion, spoolFile)); - } - } else { - LOG.info("Pass for type "+type.getTag()+" is "+type.getPass()+" which is not <= "+deployList.length); - } - } - - - private DistributionStatusEnum deploySpoolFile(DeployableArtifact artifact) { - - DistributionStatusEnum deployResult = DistributionStatusEnum.DEPLOY_OK; - - StringBuffer msgBuffer = new StringBuffer(); - - - String namespace = config.getAsdcApiNamespace(); - //String namespace = artifact.getType().getNamespace(); - - msgBuffer.append("\n"); - - String svcName = artifact.getSvcName(); - String resourceName = artifact.getResourceName(); - String artifactName = artifact.getArtifactName(); - - if (svcName != null) { - if (resourceName != null) { - artifactName = svcName + "/" + resourceName + "/" + artifactName; - } else { - artifactName = svcName + "/" + artifactName; - } - } - - // don't add artifact name/version for get-path-segments - if (!artifactName.contains("get-path-segments")) { - msgBuffer.append(""+artifactName+"\n"); - msgBuffer.append(""+artifact.getArtifactVersion()+"\n"); - } - - try(BufferedReader rdr = new BufferedReader(new FileReader(artifact.getFile()))) { - - String curLine = rdr.readLine(); - - while (curLine != null) { - - if (!curLine.startsWith("") || curLine.contains("")) { - skipThisLine = true; - } - } - - if (!skipThisLine) { - msgBuffer.append(curLine+"\n"); - } - } - curLine = rdr.readLine(); - } - } catch (Exception e) { - LOG.error("Could not process spool file "+artifact.getFile().getName(), e); - return(DistributionStatusEnum.DEPLOY_ERROR); - } - - msgBuffer.append("\n"); - - - byte[] msgBytes = msgBuffer.toString().getBytes(); - - Document results = postRestXml(artifact.getType().getRpcUrl(config.getAsdcApiBaseUrl()), msgBytes); - - if (results == null) { - - deployResult = DistributionStatusEnum.DEPLOY_ERROR; - } else { - - XPathFactory xpf = XPathFactory.newInstance(); - XPath xp = xpf.newXPath(); - - String asdcApiResponseCode = "500"; - - try { - - asdcApiResponseCode = xp.evaluate("//asdc-api-response-code[position()=1]/text()", results.getDocumentElement()); - } catch (Exception e) { - LOG.error("Caught exception retrying to evaluate xpath", e); - } - - if (asdcApiResponseCode.contains("200")) { - LOG.info("Update to SDN-C succeeded"); - deployResult = DistributionStatusEnum.DEPLOY_OK; - } else { - LOG.info("Update to SDN-C failed (response code "+asdcApiResponseCode+")"); - - if (asdcApiResponseCode.contains("409")) { - deployResult = DistributionStatusEnum.ALREADY_DEPLOYED; - } else { - - deployResult = DistributionStatusEnum.DEPLOY_ERROR; - } - } - } - - - - return deployResult; - } - - - - - - public static IDistributionStatusMessage buildStatusMessage( - final IDistributionClient client, final INotificationData data, - final IArtifactInfo relevantArtifact, - final DistributionStatusEnum status) { - IDistributionStatusMessage statusMessage = new IDistributionStatusMessage() { - - @Override - public long getTimestamp() { - long currentTimeMillis = System.currentTimeMillis(); - return currentTimeMillis; - } - - @Override - public DistributionStatusEnum getStatus() { - return status; - } - - @Override - public String getDistributionID() { - return data.getDistributionID(); - } - - @Override - public String getConsumerID() { - return client.getConfiguration().getConsumerID(); - } - - @Override - public String getArtifactURL() { - return relevantArtifact.getArtifactURL(); - } - }; - return statusMessage; - - } - - 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); - Authenticator.setDefault(new SdncAuthenticator(config.getSdncUser(), config.getSdncPasswd())); - - HttpURLConnection conn = (HttpURLConnection) sdncUrl.openConnection(); - - String authStr = config.getSdncUser()+":"+config.getSdncPasswd(); - String encodedAuthStr = new String(Base64.encodeBase64(authStr.getBytes())); - - conn.addRequestProperty("Authentication", "Basic "+encodedAuthStr); - - conn.setRequestMethod(method); - conn.setRequestProperty("Content-Type", "application/xml"); - conn.setRequestProperty("Accept", "application/xml"); - - conn.setDoInput(true); - conn.setDoOutput(true); - conn.setUseCaches(false); - - return conn; - - } - - private Document postRestXml(String urlString, byte[] msgBytes) { - Document response = null; - - try { - SdncOdlConnection odlConn = SdncOdlConnection.newInstance(urlString, config.getSdncUser(), config.getSdncPasswd()); - - String sdncResp = odlConn.send("POST", "application/xml", new String(msgBytes)); - - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - - 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); - - } - - private File applyXslts(File srcFile) { - - Document doc = null; - - - File inFile = srcFile; - File outFile = null; - - String xsltPathList = config.getXsltPathList(); - - if ((xsltPathList == null) || (xsltPathList.length() == 0)) { - outFile = inFile; - } else { - - String[] xsltPaths = xsltPathList.split(","); - - for (String xsltPath : xsltPaths) { - try{ - - outFile = File.createTempFile("tmp", "xml"); - TransformerFactory factory = TransformerFactory.newInstance(); - 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); - - - transformer.transform(text, new StreamResult(outFile)); - - inFile = outFile; - - } catch (Exception e) { - LOG.error("Caught exception trying to apply XSLT template "+xsltPath, e); - - } - - } - } - - // After transformations, parse transformed XML - - - return outFile; - } - - private String escapeFilename(String str) { - if (str == null) { - str = ""; - } - - StringBuffer retval = new StringBuffer(); - - for (int i = 0 ; i < str.length() ; i++) { - char curchar = str.charAt(i); - if (Character.isJavaIdentifierPart(curchar)) { - retval.append(curchar); - } - } - - return retval.toString(); - - } - - 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/SdncUebClient.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java deleted file mode 100644 index e5dec14c7..000000000 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.northbound.uebclient; - -import org.onap.sdc.api.IDistributionClient; -import org.onap.sdc.api.results.IDistributionClientResult; -import org.onap.sdc.impl.DistributionClientFactory; -import org.onap.sdc.utils.DistributionActionResultEnum; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.onap.sdc.utils.DistributionActionResultEnum; - -public class SdncUebClient { - - private static final Logger LOG = LoggerFactory.getLogger(SdncUebConfiguration.class); - - public static void main(String[] args) { - - SdncUebConfiguration config = new SdncUebConfiguration(); - - long startTm = System.currentTimeMillis(); - int sleepTm = config.getPollingInterval() * 1000; - long maxWaitTm = config.getClientStartupTimeout() * 1000L; - - boolean keepWaiting = true; - boolean listenerStarted = false; - boolean processDownloads = true; - - while (keepWaiting) { - LOG.info("Initializing ASDC distribution client"); - - IDistributionClient client = DistributionClientFactory.createDistributionClient(); - SdncUebCallback cb = new SdncUebCallback(client, config); - IDistributionClientResult result = client.init(config, cb); - LOG.info("Initialized ASDC distribution client - results = {}", result.getDistributionMessageResult()); - - if (result.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) { - if (processDownloads) { - LOG.info("Scanning for local distribution artifacts before starting client"); - cb.deployDownloadedFiles(null, null, null); - processDownloads = false; - } - LOG.info("Starting client..."); - try { - IDistributionClientResult start = client.start(); - LOG.info("Client startup result = {}", start.getDistributionMessageResult()); - - // Only stop waiting if the result is success - if (start.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) { - - keepWaiting = false; - listenerStarted = true; - } else { - LOG.info("SDC returned {} - exitting", start.getDistributionActionResult().toString()); - try { - client.stop(); - } catch (Exception e1) { - // Ignore exception on stop - } - } - } catch (Exception e) { - LOG.info("Client startup failure", e); - } - } - - if (System.currentTimeMillis() - startTm < maxWaitTm) { - keepWaiting = false; - } else { - - try { - Thread.sleep(sleepTm); - } catch (InterruptedException e) { - // Ignore - } - } - - } - - if (!listenerStarted) { - LOG.info("Timed out waiting to connect to SDC"); - System.exit(0); - } - - - - } - -} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java deleted file mode 100644 index 0088a14a8..000000000 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java +++ /dev/null @@ -1,317 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * Modifications Copyright © 2018 IBM. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.northbound.uebclient; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.LinkedList; -import java.util.List; -import java.util.Properties; - -import org.onap.sdc.api.consumer.IConfiguration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SdncUebConfiguration implements IConfiguration{ - - private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; - private static final Logger LOG = LoggerFactory - .getLogger(SdncUebConfiguration.class); - - private String asdcAddress = null; - private String consumerGroup = null; - private String consumerID = null; - private String environmentName = null; - private String password = null; - private int pollingInterval = 30; - private int pollingTimeout = 15; - private int clientStartupTimeout = 900; - private List relevantArtifactTypes = null; - private String user = null; - - private String sdncUser = null; - private String sdncPasswd = null; - private String asdcApiBaseUrl = null; - private String asdcApiNamespace = null; - private List msgBusAddress = null; - - private SdncArtifactMap artifactMap = SdncArtifactMap.getInstance(); - - private String incomingDir = null; - - private String archiveDir = null; - - private String overrideFile = null; - - private boolean activateServerTLSAuth; - private String keyStorePassword; - private String keyStorePath; - - private String xsltPathList; - - public SdncUebConfiguration() { - String propDir = System.getenv(SDNC_CONFIG_DIR); - if (propDir == null) { - - propDir = "/opt/sdnc/data/properties"; - } - try { - init(propDir); - } catch (Exception e) { - LOG.error("Cannot initialize SdncUebConfiguration", e); - } - } - - public SdncUebConfiguration(String propDir) { - try { - init(propDir); - } catch (Exception e) { - LOG.error("Cannot initialize SdncUebConfiguration", e); - } - } - - public String getAsdcApiNamespace() { - return asdcApiNamespace; - } - - public String getXsltPathList() { - return xsltPathList; - } - - public String getOverrideFile() { - return overrideFile; - } - - public void init(String propDir) throws IOException { - String propPath; - - - propPath = propDir + "/ueb-listener.properties"; - File propFile = new File(propPath); - - - if (!propFile.exists()) { - - throw new FileNotFoundException( - "Missing configuration properties file : " - + propFile); - } - - Properties props = new Properties(); - props.load(new FileInputStream(propFile)); - - asdcAddress = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.asdc-address"); - consumerGroup = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.consumer-group"); - consumerID = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.consumer-id"); - environmentName = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.environment-name"); - password = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.password"); - user = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.user"); - - sdncUser = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.sdnc-user"); - sdncPasswd = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.sdnc-passwd"); - asdcApiBaseUrl = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.asdc-api-base-url"); - asdcApiNamespace = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.asdc-api-namespace"); - - incomingDir = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.spool.incoming"); - archiveDir = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.spool.archive"); - overrideFile = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.override-file"); - - String curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.polling-interval"); - if ((curval != null) && (curval.length() > 0)) { - try { - pollingInterval = Integer.parseInt(curval); - } catch (Exception e) { - LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-interval ({}) ", curval, e); - } - } - - curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.polling-timeout"); - if ((curval != null) && (curval.length() > 0)) { - try { - pollingTimeout = Integer.parseInt(curval); - } catch (Exception e) { - LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-timeout ({}) ", curval, e); - } - } - - curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.client-startup-timeout"); - if ((curval != null) && (curval.length() > 0)) { - try { - clientStartupTimeout = Integer.parseInt(curval); - } catch (Exception e) { - LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-timeout ({}) ", curval, e); - } - } - curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.relevant-artifact-types"); - if ((curval != null) && (curval.length() > 0)) { - String[] artifactTypes = curval.split(","); - - relevantArtifactTypes = new LinkedList<>(); - - for (String artifactType : artifactTypes) { - - relevantArtifactTypes.add(artifactType); - - } - - } - - curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.activate-server-tls-auth", "false"); - activateServerTLSAuth = "true".equalsIgnoreCase(curval); - keyStorePath = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.keystore-path"); - keyStorePassword = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.keystore-password"); - xsltPathList = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.xslt-path-list"); - - - String artifactMapFile = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.artifact-map"); - if (artifactMapFile != null) { - LOG.info("Loading artifactMapFile {}", artifactMapFile); - artifactMap.load(artifactMapFile); - } else { - LOG.warn("artifact-map is unset"); - } - - msgBusAddress = new LinkedList<>(); - String msgBusAddressStr = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.msg-bus-address"); - if (msgBusAddressStr != null) { - String[] msgBusAddressArray = msgBusAddressStr.split(","); - for (int i = 0 ; i < msgBusAddressArray.length ; i++) { - msgBusAddress.add(msgBusAddressArray[i]); - } - } - - - } - - @Override - public String getAsdcAddress() { - return asdcAddress; - } - - @Override - public String getConsumerGroup() { - return consumerGroup; - } - - @Override - public String getConsumerID() { - return consumerID; - } - - @Override - public String getEnvironmentName() { - return environmentName; - } - - @Override - public String getPassword() { - return password; - } - - @Override - public int getPollingInterval() { - return pollingInterval; - } - - @Override - public int getPollingTimeout() { - return pollingTimeout; - } - - @Override - public List getRelevantArtifactTypes() { - return relevantArtifactTypes; - } - - public int getClientStartupTimeout() { - return clientStartupTimeout; - } - - @Override - public String getUser() { - return user; - } - - - public String getSdncUser() { - return sdncUser; - } - - public String getSdncPasswd() { - return sdncPasswd; - } - - public String getAsdcApiBaseUrl() { - return asdcApiBaseUrl; - } - - @Override - public boolean activateServerTLSAuth() { - return activateServerTLSAuth; - } - - @Override - public String getKeyStorePassword() { - return keyStorePassword; - } - - @Override - public String getKeyStorePath() { - return keyStorePath; - } - - public String getIncomingDir() { - return incomingDir; - } - - public String getArchiveDir() { - return archiveDir; - } - - public int getMaxPasses() { - return artifactMap.getNumPasses(); - } - - public SdncArtifactMap.SdncArtifactType getMapping(String tag) { - return artifactMap.getMapping(tag); - } - - @Override - public boolean isFilterInEmptyResources() { - return false; - } - - @Override - public Boolean isUseHttpsWithDmaap() { - return false; - } - - @Override - public List getMsgBusAddress() { - return msgBusAddress; - } - - -} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java deleted file mode 100644 index fc288aaa9..000000000 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFCModel.java +++ /dev/null @@ -1,360 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.northbound.uebclient; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.onap.sdc.tosca.parser.api.IEntityDetails; -import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.tosca.parser.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.Property; -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, IEntityDetails entityDetails, DBResourceManager jdbcDataSource, SdncUebConfiguration config) throws IOException { - - super(sdcCsarHelper, entityDetails, jdbcDataSource, config); - - // extract properties - addParameter("ecomp_generated_naming", extractBooleanValue (entityDetails, "nfc_naming", "ecomp_generated_naming")); - addParameter("naming_policy", extractValue (entityDetails, "nfc_naming", "naming_policy")); - vmCount = extractValue (entityDetails, "service_template_filter", "count"); // need path to vm_count, extracted as service_template_filter#count - if (vmCount.isEmpty()) { - vmCount = "0"; // vm_count can not be null - } - vmType = extractValue (entityDetails, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG); - addParameter("vm_type", vmType); // populate vm_type with vm_type_tag value - addParameter("vm_type_tag", vmType); - addParameter("nfc_naming_code", extractValue (entityDetails, "nfc_naming_code")); - addParameter("nfc_function", extractValue (entityDetails, "nfc_function")); - addParameter("high_availability", extractValue (entityDetails, "high_availablity")); - addParameter("vm_image_name", extractValue (entityDetails, "vm_image_name")); - addParameter("vm_flavor_name", extractValue (entityDetails, "vm_flavor_name")); - addParameter("nfc_naming", extractValue (entityDetails, "nfc_naming")); - addParameter("min_instances", extractValue (entityDetails, "min_instances")); - addParameter("max_instances", extractValue (entityDetails, "max_instances")); - } - - public void insertVFCModelData () throws IOException { - 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 (IEntityDetails cvfcEntity) throws IOException { - - // Get the CPs on this VFC - using getEntity - // For each VFC node, get CP properties to insert into VFC_TO_NETWORK_ROLE_MAPPING - // VFC_TO_NETWORK_ROLE_MAPPING: vfc_customization_uuid, network_role, network_role_tag, vm_type, ipv4_count, ipv6_count, - // ipv4_use_dhcp, ipv6_use_dhcp, ipv4_ip_version, ipv6_ip_version, extcp_subnetpool_id - - String vfcCustomizationUuid = getCustomizationUUID().replace("\"", ""); - EntityQuery entityQueryCP = EntityQuery.newBuilder(SdcTypes.CP).build(); - TopologyTemplateQuery topologyTemplateQueryVFC = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC).customizationUUID(vfcCustomizationUuid).build(); - List cpEntities = sdcCsarHelper.getEntity(entityQueryCP, topologyTemplateQueryVFC, true); - if (cpEntities == null || cpEntities.isEmpty()) { - LOG.debug("insertVFCtoNetworkRoleMappingData: Could not find the nested CVFCs for: " + vfcCustomizationUuid); - return; - } - - // 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 can be multiple insertions per CP: - // Insert once for each unique IP Version / Subnet Role combination per CP (network_role) - for (IEntityDetails cpEntity : cpEntities) { - - // Extract common parameters - Map commonParams = new HashMap(); // non-IP Version specific parameters - // Get vm_type from VFC node - addParameter("vm_type", getVmType(), commonParams); - - // Extract non-IP Version specific parameters - outside the ip_requirements block - String networkRole = extractValue(cpEntity, "network_role").isEmpty() ? "default-network-role" : extractValue(cpEntity, "network_role"); // set default-network-role? - addParameter("network_role", networkRole, commonParams); // can not be null - addParameter("network_role_tag", nullCheck(extractValue(cpEntity, "network_role_tag")), commonParams); - addParameter("extcp_subnetpool_id", nullCheck(extractValue(cpEntity, "subnetpoolid")), commonParams); - String subinterfaceIndicator = extractBooleanValue (cpEntity, "subinterface_indicator"); - addParameter("subinterface_indicator", subinterfaceIndicator, commonParams); - - // Build lists of all IPV4 and IPV6 ip_requirements elements - ArrayList> ipv4PropParamsList = new ArrayList>(); - ArrayList> ipv6PropParamsList = new ArrayList>(); - - // Extract IP Version specific parameters - if (cpEntity.getProperties().containsKey("ip_requirements")) { - - ArrayList> ipPropsList = new ArrayList>(); - ipPropsList = (ArrayList>) cpEntity.getProperties().get("ip_requirements").getValue(); - - if (ipPropsList != null) { - for (Map ipPropMap : ipPropsList) { - //LOG.info("ip_requirements prop map = " + nullCheck(ipPropMap)); - - String ipVersion = nullCheck(ipPropMap.get("ip_version")); - if (ipVersion == null) { - LOG.error("SdncVFCModel: ipVersion not included in ip_requirements element"); - continue; - } - - String subnetRole = nullCheck(ipPropMap.get("subnet_role")); - - if (ipVersion.contains("4")) { - - // If we have already encountered this subnetRole for IPV4, skip this ip_requirements element - if (!ipPropParamsMapContainsSubnetRole (ipv4PropParamsList, subnetRole)) { - - Map ipv4PropParams = new HashMap(); - SdncBaseModel.addParameter("ipv4_ip_version", ipVersion, ipv4PropParams); - SdncBaseModel.addParameter("ipv4_use_dhcp", nullCheck(ipPropMap.get("dhcp_enabled")).contains("true") ? "Y" : "N", ipv4PropParams); - Map ipCountRequired = (Map)ipPropMap.get("ip_count_required"); - if (ipCountRequired != null && ipCountRequired.get("count") != null) { - SdncBaseModel.addParameter("ipv4_count", nullCheck(ipCountRequired.get("count")), ipv4PropParams); - } - Map floatingIpCountRequired = (Map)ipPropMap.get("floating_ip_count_required"); - if (floatingIpCountRequired != null && floatingIpCountRequired.get("count") != null) { - SdncBaseModel.addParameter("ipv4_floating_count", nullCheck(floatingIpCountRequired.get("count")), ipv4PropParams); - } - SdncBaseModel.addParameter("ipv4_address_plan_name", nullCheck(ipPropMap.get("ip_address_plan_name")), ipv4PropParams); - SdncBaseModel.addParameter("ipv4_vrf_name", nullCheck(ipPropMap.get("vrf_name")), ipv4PropParams); - SdncBaseModel.addParameter("subnet_role", nullCheck(ipPropMap.get("subnet_role")), ipv4PropParams); - - ipv4PropParamsList.add(ipv4PropParams); - - } else { - LOG.error("SdncVFCModel: Additional V4 ip-requirements element encountered for this subnet_role: ", subnetRole); - } - - } else if (ipVersion.contains("6")) { - - // If we have already encountered this subnetRole for IPV6, skip this ip_requirements element - if (!ipPropParamsMapContainsSubnetRole (ipv6PropParamsList, subnetRole)) { - - Map ipv6PropParams = new HashMap(); - SdncBaseModel.addParameter("ipv6_ip_version", ipVersion, ipv6PropParams); - SdncBaseModel.addParameter("ipv6_use_dhcp", nullCheck(ipPropMap.get("dhcp_enabled")).contains("true") ? "Y" : "N", ipv6PropParams); - Map ipCountRequired = (Map)ipPropMap.get("ip_count_required"); - if (ipCountRequired != null && ipCountRequired.get("count") != null) { - SdncBaseModel.addParameter("ipv6_count", nullCheck(ipCountRequired.get("count")), ipv6PropParams); - } - Map floatingIpCountRequired = (Map)ipPropMap.get("floating_ip_count_required"); - if (floatingIpCountRequired != null && floatingIpCountRequired.get("count") != null) { - SdncBaseModel.addParameter("ipv6_floating_count", nullCheck(floatingIpCountRequired.get("count")), ipv6PropParams); - } - SdncBaseModel.addParameter("ipv6_address_plan_name", nullCheck(ipPropMap.get("ip_address_plan_name")), ipv6PropParams); - SdncBaseModel.addParameter("ipv6_vrf_name", nullCheck(ipPropMap.get("vrf_name")), ipv6PropParams); - SdncBaseModel.addParameter("subnet_role", nullCheck(ipPropMap.get("subnet_role")), ipv6PropParams); - - ipv6PropParamsList.add(ipv6PropParams); - - } else { - LOG.error("SdncVFCModel: Additional V6 ip-requirements element encountered for this subnetRole: ", subnetRole); - } - - } else { - LOG.error("SdncVFCModel: invalid IP version encountered: ", ipVersion); - } - - } // for each ip-requirements element - - } // ipPropsList null check - - // After all Common and IP Version specific parameters are extracted, insert IPV4 and IPV6 data separately - // Insert IPV4 data - for (Map ipv4PropParams: ipv4PropParamsList) { - - Map mappingParams = new HashMap(); // final list for single insertion - addParamsToMap(commonParams, mappingParams); - addParamsToMap(ipv4PropParams, mappingParams); - - // Insert ipv4PropParams into VFC_TO_NETWORK_ROLE_MAPPING - try { - LOG.info("Call insertToscaData for VFC_TO_NETWORK_ROLE_MAPPING where vfc_customization_uuid = " + getCustomizationUUID()); - addRequiredParameters(mappingParams); - insertToscaData(SdncBaseModel.getSql("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", getCustomizationUUID(), "", mappingParams), null); - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the VFC_TO_NETWORK_ROLE_MAPPING table"); - throw new IOException (e); - } - - } - - // Insert IPV6 data - for (Map ipv6PropParams: ipv6PropParamsList) { - - Map mappingParams = new HashMap(); // final list for single insertion - addParamsToMap(commonParams, mappingParams); - addParamsToMap(ipv6PropParams, mappingParams); - - // Insert ipv6PropParams into VFC_TO_NETWORK_ROLE_MAPPING - try { - LOG.info("Call insertToscaData for VFC_TO_NETWORK_ROLE_MAPPING where vfc_customization_uuid = " + getCustomizationUUID()); - addRequiredParameters(mappingParams); - insertToscaData(SdncBaseModel.getSql("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", getCustomizationUUID(), "", mappingParams), null); - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the VFC_TO_NETWORK_ROLE_MAPPING table"); - throw new IOException (e); - } - } - } - } - } - - protected boolean ipPropParamsMapContainsSubnetRole (ArrayList> ipPropParamsList, String subnetRole) { - - boolean subnetRoleFound = false; - - if (subnetRole != null && !subnetRole.isEmpty()) { - for (Map ipPropMap : ipPropParamsList) { - if (ipPropMap.get("subnet_role").contentEquals(subnetRole)) { - return true; - } - } - } - return subnetRoleFound; - } - - private void addRequiredParameters (Map mappingParams) { - - // Add parameters which can not be null if they have not already been added - network_role, ipv4_count, ipv6_count - String ipvCountDefault = "0"; - if (!mappingParams.containsKey("ipv4_count")) { - SdncBaseModel.addParameter("ipv4_count", ipvCountDefault, mappingParams); - } - if (!mappingParams.containsKey("ipv6_count")) { - SdncBaseModel.addParameter("ipv6_count", ipvCountDefault, mappingParams); - } - } - - public void insertVFCRelatedNetworkRoleData (String vfCustomizationUUID, IEntityDetails cvfcEntity) throws IOException { - - // Get the CPs on this VFC - using getEntity - - String vfcCustomizationUuid = getCustomizationUUID().replace("\"", ""); - // Get the CPs on this VFC - ASDC suggests getNodeTemplateChildren - //List cpNodesList = sdcCsarHelper.getNodeTemplateChildren(vfcNode); - EntityQuery entityQueryCP = EntityQuery.newBuilder(SdcTypes.CP).build(); - TopologyTemplateQuery topologyTemplateQueryVFC = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC).customizationUUID(vfcCustomizationUuid).build(); - List cpEntities = sdcCsarHelper.getEntity(entityQueryCP, topologyTemplateQueryVFC, true); - if (cpEntities == null || cpEntities.isEmpty()) { - LOG.debug("insertVFCRelatedNetworkRoleData: Could not find the nested CVFCs for: " + vfcCustomizationUuid); - return; - } - - try { - cleanUpExistingToscaData("VFC_RELATED_NETWORK_ROLE", "vfc_customization_uuid", getCustomizationUUID()); - } catch (IOException e) { - LOG.error("Could not clean up Tosca CSAR data in the VFC_RELATED_NETWORK_ROLE table"); - throw new IOException (e); - } - - for (IEntityDetails cpEntity : cpEntities){ - String networkRole = extractValue(cpEntity, "network_role"); - Map relatedNetworkRoleParams = new HashMap(); - addParameter("vfc_customization_uuid", getCustomizationUUID(), relatedNetworkRoleParams); - addParameter("vm_type", vmType, relatedNetworkRoleParams); - addParameter("network_role", networkRole, relatedNetworkRoleParams); - - if (cpEntity.getProperties().containsKey("related_networks")) { - - Property relatedNetworksProperty = cpEntity.getProperties().get("related_networks"); - List relatedNetworkRoles = relatedNetworksProperty.getLeafPropertyValue("related_network_role"); - - for (String relatedNetworkRole : relatedNetworkRoles) { - LOG.debug("CP [" + cpEntity.getName() + "], property [" + "related_network_role" + "] property value: " + relatedNetworkRole); - - try { - // Table cleanup for VFC_RELATED_NETWORK_ROLE occurs per vfc - // If cp related_network_role, cp network_role and vm_type for this vfc already exist in VFC_RELATED_NETWORK_ROLE, - // don't attempt insertion - Map relatedNetworkRoleParamsCheck = new HashMap(); - addParamsToMap(relatedNetworkRoleParams, relatedNetworkRoleParamsCheck); - addParameter("related_network_role", relatedNetworkRole, relatedNetworkRoleParamsCheck); - if (checkForExistingToscaData("VFC_RELATED_NETWORK_ROLE", relatedNetworkRoleParamsCheck) == false) { - LOG.info("Call insertToscaData for VFC_RELATED_NETWORK_ROLE where vfc_customization_uuid = " + getCustomizationUUID()); - insertToscaData(buildSql("VFC_RELATED_NETWORK_ROLE", "related_network_role", "\"" + relatedNetworkRole + "\"", model_yaml, relatedNetworkRoleParams), null); - } - - // Table cleanup for VNF_RELATED_NETWORK_ROLE occurs per vf (up one level) - // Insert same related_network_role data into VNF_RELATED_NETWORK_ROLE - Map vfRelatedNetworkRoleParamsCheck = new HashMap(); - addParameter("vnf_customization_uuid", vfCustomizationUUID, vfRelatedNetworkRoleParamsCheck); - addParameter("network_role", networkRole, vfRelatedNetworkRoleParamsCheck); - addParameter("related_network_role", relatedNetworkRole, vfRelatedNetworkRoleParamsCheck); - if (checkForExistingToscaData("VNF_RELATED_NETWORK_ROLE", vfRelatedNetworkRoleParamsCheck) == false) { - vfRelatedNetworkRoleParamsCheck.remove("related_network_role"); - LOG.info("Call insertToscaData for VNF_RELATED_NETWORK_ROLE where vnf_customization_uuid = " + vfCustomizationUUID); - insertToscaData(buildSql("VNF_RELATED_NETWORK_ROLE", "related_network_role", "\"" + relatedNetworkRole + "\"", model_yaml, vfRelatedNetworkRoleParamsCheck), null); - } - - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the VFC_RELATED_NETWORK_ROLE table"); - throw new IOException (e); - } - } - } - } - } - - public String getVmType() { - return vmType; - } - - public void setVmType(String vmType) { - this.vmType = vmType; - } - - public String getVmCount() { - return vmCount; - } - - public void setVmCount(String vmCount) { - this.vmCount = vmCount; - } - -} diff --git a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java b/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java deleted file mode 100644 index fa54c7c41..000000000 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModel.java +++ /dev/null @@ -1,485 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.northbound.uebclient; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.tosca.parser.enums.SdcTypes; -import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; -import org.onap.sdc.tosca.parser.api.IEntityDetails; -import org.onap.sdc.tosca.parser.elements.queries.EntityQuery; -import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery; -import org.onap.sdc.toscaparser.api.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 SdncVFModel extends SdncBaseModel { - - private static final Logger LOG = LoggerFactory - .getLogger(SdncVFModel.class); - - private String vendor = null; - private String vendorModelDescription = null; - private String nfNamingCode = null; - private String serviceUUID = null; - private String serviceInvariantUUID = null; - - public SdncVFModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails entityDetails, DBResourceManager jdbcDataSource, SdncUebConfiguration config) throws IOException { - - super(sdcCsarHelper, entityDetails, jdbcDataSource, config); - - // extract metadata - Metadata metadata = entityDetails.getMetadata(); - addParameter("name", extractValue(metadata, SdcPropertyNames.PROPERTY_NAME_NAME)); - vendor = extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDOR); - addParameter("vendor", vendor); - vendorModelDescription = extractValue (metadata, "description"); - addParameter("vendor_version", extractValue (metadata, SdcPropertyNames.PROPERTY_NAME_RESOURCEVENDORRELEASE)); - - // extract properties - addParameter("ecomp_generated_naming", extractBooleanValue(entityDetails, "nf_naming", "ecomp_generated_naming")); - addParameter("naming_policy", extractValue(entityDetails, "nf_naming", "naming_policy")); - addParameter("nf_type", extractValue(entityDetails, SdcPropertyNames.PROPERTY_NAME_NFTYPE)); - addParameter("nf_role", extractValue(entityDetails, SdcPropertyNames.PROPERTY_NAME_NFROLE)); - nfNamingCode = extractValue(entityDetails, "nf_naming_code"); - addParameter("nf_code", nfNamingCode); - addParameter("nf_function", extractValue(entityDetails, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)); - addIntParameter("avail_zone_max_count", extractValue(entityDetails, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONEMAXCOUNT)); - addParameter("sdnc_model_name", extractValue(entityDetails, "sdnc_model_name")); - addParameter("sdnc_model_version", extractValue(entityDetails, "sdnc_model_version")); - addParameter("sdnc_artifact_name", extractValue(entityDetails, "sdnc_artifact_name")); - - // store additional properties in ATTRIBUTE_VALUE_PAIR - // additional complex properties are extracted via VfcInstanceGroup - EntityQuery entityQuery = EntityQuery.newBuilder("org.openecomp.groups.VfcInstanceGroup").build(); - String vfCustomizationUuid = getCustomizationUUIDNoQuotes(); - TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF) - .customizationUUID(vfCustomizationUuid).build(); - List vfcInstanceGroupListForVf = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false); - if (vfcInstanceGroupListForVf != null) { - - for (IEntityDetails group : vfcInstanceGroupListForVf){ - - String vfcInstanceGroupFunction = extractGetInputValue(group, entityDetails, "vfc_instance_group_function"); - addParameter("vfc_instance_group_function", vfcInstanceGroupFunction, attributeValueParams); - String networkCollectionFunction = extractGetInputValue(group, entityDetails, "network_collection_function"); - addParameter("network_collection_function", networkCollectionFunction, attributeValueParams); - String initSubinterfaceQuantity = extractGetInputValue(group, entityDetails, "init_subinterface_quantity"); - addParameter("init_subinterface_quantity", initSubinterfaceQuantity, attributeValueParams); - } - } - } - - public void insertData() throws IOException { - - insertVFModelData(); - insertVFModuleData(); - insertVFtoNetworkRoleMappingData(); - insertVFCData(); - insertVFCInstanceGroupData(); - insertVFPolicyData(); - } - - private void insertVFModelData () throws IOException { - - try { - cleanUpExistingToscaData("VF_MODEL", "customization_uuid", getCustomizationUUID()) ; - //cleanUpExistingToscaData("SERVICE_MODEL_TO_VF_MODEL_MAPPING", "service_uuid", serviceUUID, "vf_uuid", getUUID()); - - // insert into VF_MODEL/ATTRIBUTE_VALUE_PAIR and SERVICE_MODEL_TO_VF_MODEL_MAPPING - LOG.info("Call insertToscaData for VF_MODEL where customization_uuid = " + getCustomizationUUID()); - insertToscaData(buildSql("VF_MODEL", model_yaml), null); - //insertRelevantAttributeData(); - - Map mappingParams = new HashMap(); - addParameter("service_invariant_uuid", serviceInvariantUUID, mappingParams); - addParameter("vf_uuid", getUUID(), mappingParams); - addParameter("vf_customization_uuid", getCustomizationUUIDNoQuotes(), mappingParams); - //insertToscaData(buildSql("SERVICE_MODEL_TO_VF_MODEL_MAPPING", "service_uuid", serviceUUID, model_yaml, mappingParams), null); - - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the VF_MODEL table"); - throw new IOException (e); - } - - } - - private void insertVFModuleData () throws IOException { - - // Pre-Step: Get all CVFC with VFC inside use this list to filter before insert into VF_MODULE_TO_VFC_MAPPING - // Get all VFC in all CFVC in entire model (getEntity VFC, CVFC, true) and then check resulting entity has parent that matches member - // if parent of VFC has customizationUUID that matches customizationUUID of group member, then insert into VF_MODULE_TO_VFC_MAPPING - // then get count property - EntityQuery vfcEntityQuery = EntityQuery.newBuilder(SdcTypes.VFC).build(); - TopologyTemplateQuery cvfcTopologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC).build(); - List allVfcsInsideAllCvfcs = sdcCsarHelper.getEntity(vfcEntityQuery, cvfcTopologyTemplateQuery, true); - - // Step 1: Get all the VF Module groups (entities) in this Service - EntityQuery entityQuery = EntityQuery.newBuilder("org.openecomp.groups.VfModule").build(); - String vfCustomizationUuid = getCustomizationUUIDNoQuotes(); - TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).build(); - List vfModules = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false); - if (vfModules == null) { - return; - } - - // Insert each VF Module group (entity) into VF_MODULE_MODEL if its name is prefixed with the VF name - for (IEntityDetails vfModule : vfModules){ - - // If this vfModule name is prefixed with the VF name of the VF being processed, insert this VF Module in VF_MODULE_MODEL - String normailizedVfName = entityDetails.getName().toLowerCase().replace(" ", "").replace("-", "").replace(".", ""); // need full set of normalization rules from ASDC - if (!vfModule.getName().startsWith(normailizedVfName)) { - continue; - } - - SdncVFModuleModel vfModuleModel = new SdncVFModuleModel(sdcCsarHelper, vfModule, this); - - try { - cleanUpExistingToscaData("VF_MODULE_MODEL", "customization_uuid", vfModuleModel.getCustomizationUUID()); - cleanUpExistingToscaData("VF_MODULE_TO_VFC_MAPPING", "vf_module_customization_uuid", vfModuleModel.getCustomizationUUID()); - LOG.info("Call insertToscaData for VF_MODULE_MODEL where customization_uuid = " + vfModuleModel.getCustomizationUUID()); - insertToscaData(vfModuleModel.buildSql("VF_MODULE_MODEL", model_yaml), null); - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_MODEL table "); - throw new IOException (e); - } - - // Step 2: Get the non-catalog VF Module in order to get the group members - String vfModuleUuid = vfModuleModel.getUUID().replace("\"", ""); - EntityQuery entityQuery2 = EntityQuery.newBuilder("org.openecomp.groups.VfModule") - .uUID(vfModuleUuid) - .build(); - TopologyTemplateQuery topologyTemplateQuery2 = TopologyTemplateQuery.newBuilder(SdcTypes.VF) - .customizationUUID(vfCustomizationUuid) // customization UUID of the VF if exists - .build(); - List vfModulesNonCatalog = sdcCsarHelper.getEntity(entityQuery2, topologyTemplateQuery2, false); - if (vfModulesNonCatalog == null || vfModulesNonCatalog.isEmpty()) { - LOG.debug("insertVFModuleData: Could not find the non-catelog VF Module for: " + vfModuleModel.getCustomizationUUID() + ". Unable to insert members into VF_MODULE_TO_VFC_MAPPING"); - continue; - } - - List vfModuleMembers = vfModulesNonCatalog.get(0).getMemberNodes(); // does getMemberNodes give nested CFVCs? - - // Find all members for each VF Module that are of type CVFC and insert it and any nested CFVCs into VF_MODULE_TO_VFC_MAPPING - for (IEntityDetails vfModuleMember: vfModuleMembers) { - if (vfModuleMember.getMetadata().getValue("type").equals(SdcTypes.CVFC.getValue())) { - - String cvfcCustomizationUuid = extractValue(vfModuleMember.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); - - // Additional check to see if this CVFC has a VFC in it? We only are to map CVFCs with VFC in it. - if (cvfcContainsVfc(allVfcsInsideAllCvfcs, vfModuleMember) == true) { - - // Insert this CVFC data into VF_MODULE_TO_VFC_MAPPING - String vfcVmType = extractValue (vfModuleMember, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG); // extracted as vm_type_tag - String vfcVmCount = ""; - if (vfModuleMember.getProperties().containsKey("service_template_filter")) { - vfcVmCount = extractIntegerValue (vfModuleMember.getProperties().get("service_template_filter"), "count"); - } - if (vfcVmCount.isEmpty()) { - vfcVmCount = "0"; // vm_count can not be null - } - - try { - LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING where vf_module_customization_uuid = " + vfModuleModel.getCustomizationUUID()); - insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" + - vfModuleModel.getCustomizationUUID() + ", \"" + cvfcCustomizationUuid + "\", \"" + vfcVmType + "\", \"" + vfcVmCount + "\")", null); - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_TO_VFC_MAPPING table"); - throw new IOException (e); - } - } - - // Step 3: Get any nested CVFCs under this CVFC - EntityQuery entityQuery3 = EntityQuery.newBuilder(SdcTypes.CVFC).build(); - TopologyTemplateQuery topologyTemplateQuery3 = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC) - .customizationUUID(cvfcCustomizationUuid) // customization UUID of the CVFC if exists - .build(); - List nestedCvfcs = sdcCsarHelper.getEntity(entityQuery3, topologyTemplateQuery3, true); // true allows for nested search - if (nestedCvfcs == null || nestedCvfcs.isEmpty()) { - LOG.debug("insertVFModuleData: Could not find the nested CVFCs for: " + cvfcCustomizationUuid); - continue; - } - - for (IEntityDetails nestedCvfc: nestedCvfcs) { - - // Additional check to see if this CVFC has a VFC in it? We only are to map CVFCs with VFC in it. - if (cvfcContainsVfc(allVfcsInsideAllCvfcs, nestedCvfc) == false) { - continue; // continue to next CVFC - } - - // Insert this CVFC data into VF_MODULE_TO_VFC_MAPPING - String nestedCvfcCustomizationUuid = extractValue(nestedCvfc.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); - String nestedVfcVmType = extractValue (nestedCvfc, SdcPropertyNames.PROPERTY_NAME_VMTYPETAG); // extracted as vm_type_tag - String nestedVfcVmCount = ""; - if (nestedCvfc.getProperties().containsKey("service_template_filter")) { - nestedVfcVmCount = extractIntegerValue (nestedCvfc.getProperties().get("service_template_filter"), "count"); - } - if (nestedVfcVmCount.isEmpty()) { - nestedVfcVmCount = "0"; // vm_count can not be null - } - - try { - LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING where vf_module_customization_uuid = " + vfModuleModel.getCustomizationUUID()); - insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" + - vfModuleModel.getCustomizationUUID() + ", \"" + nestedCvfcCustomizationUuid + "\", \"" + nestedVfcVmType + "\", \"" + nestedVfcVmCount + "\")", null); - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the VF_MODULE_TO_VFC_MAPPING table"); - throw new IOException (e); - } - } - } - } // For each VF Module member - } // For each VF Module - } - - private boolean cvfcContainsVfc (List allVfcsInsideAllCvfcs, IEntityDetails cvfcEntity) { - boolean containsVfc = false; - - for (IEntityDetails vfcEntity: allVfcsInsideAllCvfcs) { - IEntityDetails vfcParentEntity = vfcEntity.getParent(); - String parentCustomizationUuid = extractValue (vfcParentEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); - String cvfcEntityCustomizationUuid = extractValue (cvfcEntity.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); - if (parentCustomizationUuid == cvfcEntityCustomizationUuid) { - return true; - } - } - - return containsVfc; - } - - private void insertVFtoNetworkRoleMappingData () throws IOException { - - // Cleanup existing VF_TO_NETWORK_ROLE_MAPPING for this VF - try { - cleanUpExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", "vf_customization_uuid", getCustomizationUUID()); - } catch (IOException e) { - LOG.error("Could not cleanup Tosca CSAR data into the VF_TO_NETWORK_ROLE_MAPPING table"); - throw new IOException (e); - } - - // For this VF, insert VF_TO_NETWORK_ROLE_MAPPING data. network_role is a property on the CPs for this VF. - // Use getEntity to extract all the CPs on this VF - EntityQuery entityQueryCP = EntityQuery.newBuilder(SdcTypes.CP).build(); - TopologyTemplateQuery topologyTemplateQueryVF = TopologyTemplateQuery.newBuilder(SdcTypes.VF).customizationUUID(getCustomizationUUIDNoQuotes()).build(); - List cpEntities = sdcCsarHelper.getEntity(entityQueryCP, topologyTemplateQueryVF, true); - if (cpEntities == null || cpEntities.isEmpty()) { - LOG.debug("insertVFtoNetworkRoleMappingData: Could not find CPs for VF: " + getCustomizationUUIDNoQuotes()); - return; - } - - for (IEntityDetails entity: cpEntities ) { - - Map properties = entity.getProperties(); - if (properties.containsKey("network_role")) { - - Property networkRoleProperty = properties.get("network_role"); - if (networkRoleProperty != null && networkRoleProperty.getValue() != null) { - String cpNetworkRole = networkRoleProperty.getValue().toString(); - LOG.debug("insertVFtoNetworkRoleMappingData: " + "VF: " + getCustomizationUUID() + ", networkRole = " + cpNetworkRole); - - // Only insert unique network_role values for this VF - boolean networkRoleExists = false; - Map networkRoleyKeys = new HashMap(); - networkRoleyKeys.put("vf_customization_uuid", getCustomizationUUID()); - networkRoleyKeys.put("network_role", "\"" + cpNetworkRole + "\""); - networkRoleExists = checkForExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", networkRoleyKeys); - - if (networkRoleExists == false) { - try { - //cleanUpExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", "vf_customization_uuid", getCustomizationUUID()); - LOG.info("Call insertToscaData for VF_TO_NETWORK_ROLE_MAPPING where vf_customization_uuid = " + getCustomizationUUID()); - insertToscaData("insert into VF_TO_NETWORK_ROLE_MAPPING (vf_customization_uuid, network_role) values (" + - getCustomizationUUID() + ", \"" + cpNetworkRole + "\")", null); - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR data into the VF_TO_NETWORK_ROLE_MAPPING table"); - throw new IOException (e); - } - } - } - } - - } // CP loop - - } - - private void insertVFCData() throws IOException { - - /* For each VF, insert VFC_MODEL, VFC_TO_NETWORK_ROLE_MAPPING, VNF_RELATED_NETWORK_ROLE and VFC_RELATED_NETWORK_ROLE data - - try { - cleanUpExistingToscaData("VNF_RELATED_NETWORK_ROLE", "vnf_customization_uuid", getCustomizationUUID()); - } catch (IOException e) { - LOG.error("Could not clean up Tosca CSAR data in the VNF_RELATED_NETWORK_ROLE table"); - throw new IOException (e); - }*/ - - // Get any CVFCs under this VF (top-level and nested) - String vfCustomizationUid = customizationUUID; - EntityQuery entityQuery = EntityQuery.newBuilder(SdcTypes.CVFC) - .build(); - TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF) - .customizationUUID(vfCustomizationUid) // customization UUID of the VF if exists - .build(); - List cvfcEntities = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, true); // true allows for nested search - if (cvfcEntities == null || cvfcEntities.isEmpty()) { - LOG.debug("insertVFCDataEntity: Could not find the CVFCs for: " + vfCustomizationUid); - } - - for (IEntityDetails cvfcEntity: cvfcEntities) { - - // Insert this CVFC data into VFC_MODEL - try { - - SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, cvfcEntity, jdbcDataSource, config); - - vfcModel.insertVFCModelData(); - vfcModel.insertVFCtoNetworkRoleMappingData(cvfcEntity); - //vfcModel.insertVFCRelatedNetworkRoleData(getCustomizationUUID(), cvfcEntity); - - } catch (IOException e) { - LOG.error("Could not insert Tosca CSAR VFC data"); - throw new IOException (e); - } - } - - } - - public void insertVFCInstanceGroupData () throws IOException { - - // Insert Group data in RESOURCE_GROUP - // Store group capabilities and capability properties in NODE_CAPABILITY and NODE_CAPABILITY_PROPERTY table - - // For each VF, insert VFC Instance Group data (convert to use getEntity in 19.08) - EntityQuery entityQuery = EntityQuery.newBuilder("org.openecomp.groups.VfcInstanceGroup").build(); - String vfCustomizationUuid = getCustomizationUUIDNoQuotes(); - TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF) - .customizationUUID(vfCustomizationUuid).build(); - List vfcInstanceGroupListForVf = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false); - if (vfcInstanceGroupListForVf == null) { - return; - } - - for (IEntityDetails group : vfcInstanceGroupListForVf){ - - SdncGroupModel groupModel = new SdncGroupModel (sdcCsarHelper, group, entityDetails, config, jdbcDataSource); - groupModel.insertGroupData(getUUID()); - - // For each group, populate NODE_CAPABILITY/NODE_CAPABILITY_PROPERTY - insertNodeCapabilitiesEntityData(group.getCapabilities()); - - // Store relationship between VfcInstanceGroup and node-type=VFC in RESOURCE_GROUP_TO_TARGET_NODE_MAPPING table - // target is each VFC in targets section of group - List targetNodeList = group.getMemberNodes(); - for (IEntityDetails targetNode : targetNodeList) { - - String targetNodeUuid = extractValue(targetNode.getMetadata(), SdcPropertyNames.PROPERTY_NAME_UUID); - String targetNodeCustomizationUuid = extractValue(targetNode.getMetadata(), SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); - String targetNodeType = extractValue(targetNode.getMetadata(), SdcPropertyNames.PROPERTY_NAME_TYPE); - - // insert RESOURCE_GROUP_TO_TARGET_NODE_MAPPING - try { - Map mappingCleanupParams = new HashMap(); - addParameter("group_uuid", groupModel.getUUID(), mappingCleanupParams); - addParameter("parent_uuid", getUUID(), mappingCleanupParams); - addParameter("target_node_uuid", targetNodeUuid, mappingCleanupParams); - cleanupExistingToscaData("RESOURCE_GROUP_TO_TARGET_NODE_MAPPING", mappingCleanupParams); - - Map mappingParams = new HashMap(); - addParameter("parent_uuid", getUUID(), mappingParams); - addParameter("target_node_uuid", targetNodeUuid, mappingParams); - addParameter("target_type", targetNodeType, mappingParams); - String tableName = ""; - switch (targetNodeType) { - 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 - SdcTypes queryType = SdcTypes.valueOf(extractValue(entityDetails.getMetadata(), SdcPropertyNames.PROPERTY_NAME_TYPE)); - insertEntityPolicyData(getCustomizationUUIDNoQuotes(), getUUID().replace("\"", ""), queryType, targetNodeCustomizationUuid, targetNodeUuid, targetNodeType, "org.openecomp.policies.External"); // AFTER getEntity - } - } - } - - private void insertVFPolicyData() throws IOException { - - // For each VF node, ingest External Policy data - insertEntityPolicyData (getCustomizationUUIDNoQuotes(), getUUID(), serviceUUID.replace("\"", ""), "org.openecomp.policies.External", SdcTypes.VF); - } - - 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 deleted file mode 100644 index ef815d027..000000000 --- a/ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncVFModuleModel.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights - * reserved. - * Modifications Copyright © 2018 IBM. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.northbound.uebclient; - -import org.onap.sdc.tosca.parser.api.IEntityDetails; -import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; - -public class SdncVFModuleModel extends SdncBaseModel { - - public SdncVFModuleModel(ISdcCsarHelper sdcCsarHelper, IEntityDetails vfModule, SdncVFModel vfNodeModel) { - - super(sdcCsarHelper, vfModule); - // override base implementation for setting metadata because properties are called differently for Groups - customizationUUID = extractValue (vfModule.getMetadata(), "vfModuleModelCustomizationUUID"); - invariantUUID = extractValue (vfModule.getMetadata(), "vfModuleModelInvariantUUID"); - UUID = extractValue (vfModule.getMetadata(), "vfModuleModelUUID"); - version = extractValue (vfModule.getMetadata(), "vfModuleModelVersion"); - addParameter("vf_customization_uuid", vfNodeModel.getCustomizationUUIDNoQuotes()); - addParameter("invariant_uuid", invariantUUID); - addParameter("uuid", UUID); - addParameter("version", version); - - // extract properties - addParameter("vf_module_type", extractValue(vfModule, SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE)); - addParameter("vf_module_label", extractValue(vfModule, "vf_module_label")); - addIntParameter("availability_zone_count", extractValue(vfModule, SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)); - addParameter("ecomp_generated_vm_assignments", extractBooleanValue(vfModule, SdcPropertyNames.PROPERTY_NAME_ECOMPGENERATEDVMASSIGNMENTS)); - } - -} diff --git a/ueb-listener/src/main/resources/log4j2.xml b/ueb-listener/src/main/resources/log4j2.xml deleted file mode 100644 index 23ab908a5..000000000 --- a/ueb-listener/src/main/resources/log4j2.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - $${env:LOGDIR:-logs} - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ueb-listener/src/main/resources/normalizeTagNames.xslt b/ueb-listener/src/main/resources/normalizeTagNames.xslt deleted file mode 100755 index c37a5e049..000000000 --- a/ueb-listener/src/main/resources/normalizeTagNames.xslt +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - num of software instances - - diff --git a/ueb-listener/src/main/resources/removeNs.xslt b/ueb-listener/src/main/resources/removeNs.xslt deleted file mode 100755 index 7aa927b14..000000000 --- a/ueb-listener/src/main/resources/removeNs.xslt +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ueb-listener/src/main/scripts/start-ueb-listener.sh b/ueb-listener/src/main/scripts/start-ueb-listener.sh deleted file mode 100644 index 80ede3c8b..000000000 --- a/ueb-listener/src/main/scripts/start-ueb-listener.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash - -### -# ============LICENSE_START======================================================= -# openECOMP : SDN-C -# ================================================================================ -# Copyright (C) 2017 AT&T Intellectual Property. All rights -# reserved. -# ================================================================================ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END========================================================= -### - -PROPERTY_DIR=${PROPERTY_DIR:-/opt/sdnc/data/properties} - - -LISTENER=ueb-listener - -PIDFILE=/tmp/.${LISTENER}-pid -UEBLISTENERROOT=${UEBLISTENERROOT:-/opt/app/ueb-listener} -JAVA_HOME=${JAVA_HOME:-/usr/lib/jvm/java-7-oracle} -JAVA_OPTS=${JAVA_OPTS:--Dhttps.protocols=TLSv1.1,TLSv1.2} -JAVA=${JAVA:-${JAVA_HOME}/bin/java} - -# Redirect output from script to $LISTENER.out -exec >> ${UEBLISTENERROOT}/logs/$LISTENER.out -exec 2>&1 - -if [ -f $PIDFILE ] -then - pid=$(cat $PIDFILE) - if [ "$pid" != "" ] - then - if kill -0 $pid - then - echo "$LISTENER already running" - exit 0 - fi - fi -fi - -if [ ! -d ${UEBLISTENERROOT}/logs ] -then - mkdir ${UEBLISTENERROOT}/logs -fi - -for file in ${UEBLISTENERROOT}/lib/*.jar -do - LISTENERCLASSPATH=$LISTENERCLASSPATH:$file -done - -${JAVA} ${JAVA_OPTS} -jar ${UEBLISTENERROOT}/lib/ueb-listener*.jar -Dlog4j.configuration=file:${UEBLISTENERROOT}/lib/log4j.properties -cp ${LISTENERCLASSPATH} & - - -echo $! > $PIDFILE - -echo "$LISTENER started!" -exit 0 diff --git a/ueb-listener/src/main/scripts/stop-ueb-listener.sh b/ueb-listener/src/main/scripts/stop-ueb-listener.sh deleted file mode 100644 index cf110c5cc..000000000 --- a/ueb-listener/src/main/scripts/stop-ueb-listener.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash - -### -# ============LICENSE_START======================================================= -# openECOMP : SDN-C -# ================================================================================ -# Copyright (C) 2017 AT&T Intellectual Property. All rights -# reserved. -# ================================================================================ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END========================================================= -### - -PROPERTY_DIR=${PROPERTY_DIR:-/opt/sdnc/data/properties} - -if [ -f ${PROPERTY_DIR}/dmaap-listener.properties ] -then - LISTENER=dmaap-listener -else - LISTENER=ueb-listener -fi - -PIDFILE=/tmp/.${LISTENER}-pid -UEBLISTENERROOT=${UEBLISTENERROOT:-/opt/app/ueb-listener} - -if [ -f $PIDFILE ] -then - pid=$(cat $PIDFILE) - if [ "$pid" != "" ] - then - if kill -0 $pid - then - echo "Stopping $LISTENER" - kill $pid && rm $PIDFILE - exit 0 - else - echo "$LISTENER not running" - exit 1 - fi - else - echo "$LISTENER not running" - exit 1 - fi -fi - - -- cgit 1.2.3-korg