* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.io.ByteArrayInputStream;
import java.io.DataOutputStream;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
+import java.util.Properties;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
+import javax.sql.rowset.CachedRowSet;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Source;
import javax.xml.xpath.XPathFactory;
import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang3.tuple.Pair;
import org.openecomp.sdc.api.IDistributionClient;
import org.openecomp.sdc.api.consumer.IDistributionStatusMessage;
import org.openecomp.sdc.api.consumer.INotificationCallback;
import org.openecomp.sdc.api.notification.IResourceInstance;
import org.openecomp.sdc.api.results.IDistributionClientDownloadResult;
import org.openecomp.sdc.api.results.IDistributionClientResult;
+import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames;
+import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory;
+import org.openecomp.sdc.toscaparser.api.Group;
+import org.openecomp.sdc.toscaparser.api.Metadata;
+import org.openecomp.sdc.toscaparser.api.NodeTemplate;
import org.openecomp.sdc.utils.ArtifactTypeEnum;
import org.openecomp.sdc.utils.DistributionActionResultEnum;
import org.openecomp.sdc.utils.DistributionStatusEnum;
+import org.openecomp.sdnc.sli.resource.dblib.DBResourceManager;
+import org.openecomp.sdnc.uebclient.SdncArtifactMap.SdncArtifactType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.constructor.Constructor;
public class SdncUebCallback implements INotificationCallback {
private static final Logger LOG = LoggerFactory
.getLogger(SdncUebCallback.class);
- private static final int NUM_PASSES = 2;
+ private static DBResourceManager jdbcDataSource = null;
+ private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
- private enum SdncArtifactType {
- VF_LICENSE_MODEL("vf-license-model", "vf-license-model-update",0),
- UNKNOWN("","",0);
-
-
- private String tag;
- private String rpcName;
- private int pass;
-
- public int getPass() {
- return pass;
- }
-
- private SdncArtifactType(String tag, String rpcName, int pass) {
- this.tag = tag;
- this.rpcName = rpcName;
- this.pass = pass;
- }
-
- public String getTag() {
- return tag;
- }
-
- public String getRpcUrl(String base) {
- return base+rpcName;
- }
-
- public static SdncArtifactType fromTag(String tag) {
- if (tag != null) {
- for (SdncArtifactType artifact: SdncArtifactType.values()) {
- if (artifact.getTag().equalsIgnoreCase(tag)) {
- return artifact;
- }
- }
- }
-
- return UNKNOWN;
- }
- }
private class SdncAuthenticator extends Authenticator {
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;
private final IDistributionClient client;
private final SdncUebConfiguration config;
- private final LinkedList<DeployableArtifact> deployList[];
+ private LinkedList<DeployableArtifact> deployList[];
+ private static void setJdbcDataSource() throws IOException {
+
+ String propPath = null;
+ String propDir = System.getenv(SDNC_CONFIG_DIR);
+ if (propDir == null) {
+
+ propDir = "/opt/sdnc/data/properties";
+ }
+ propPath = propDir + "/dblib.properties";
+ File propFile = new File(propPath);
+
+ if (!propFile.exists()) {
+
+ throw new FileNotFoundException(
+ "Missing configuration properties file : "
+ + propFile);
+ }
+
+ Properties props = new Properties();
+ props.load(new FileInputStream(propFile));
+
+ try {
+ jdbcDataSource = DBResourceManager.create(props);
+ } catch(Throwable exc) {
+ LOG.error("", exc);
+ }
+
+ if(((DBResourceManager)jdbcDataSource).isActive()){
+ LOG.warn( "DBLIB: JDBC DataSource has been initialized.");
+ } else {
+ LOG.warn( "DBLIB: JDBC DataSource did not initialize successfully.");
+ }
+ }
+
+ private static void loadArtifactMap() {
+
+ }
public SdncUebCallback(IDistributionClient client, SdncUebConfiguration config) {
this.client = client;
this.config = config;
- 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());
+ ","+data.getServiceDescription() + ")");
String incomingDirName = config.getIncomingDir();
String archiveDirName = config.getArchiveDir();
LOG.info("Received artifact " + curArtifact.getArtifactName());
- handleArtifact(data, data.getServiceName(), null, curArtifact, incomingDir, archiveDir);
+ handleArtifact(data, data.getServiceName(), null, null, curArtifact, incomingDir, archiveDir);
}
}
LOG.info("Received artifact " + curArtifact.getArtifactName());
- handleArtifact(data, data.getServiceName(), curResource.getResourceName(), curArtifact, incomingDir, archiveDir);
+ handleArtifact(data, data.getServiceName(), curResource.getResourceName(), curResource.getResourceType(), curArtifact, incomingDir, archiveDir);
}
}
}
}
// Deploy scheduled deployments
+ int numPasses = config.getMaxPasses();
+
+ deployList = new LinkedList[numPasses];
- for (int pass = 0 ; pass < NUM_PASSES ; pass++) {
+ for (int i = 0 ; i < numPasses ; i++) {
+ deployList[i] = new LinkedList<DeployableArtifact>();
+ }
+ for (int pass = 0 ; pass < config.getMaxPasses() ; pass++) {
if (deployList[pass] != null) {
while (! deployList[pass].isEmpty()) {
IArtifactInfo artifactInfo = artifact.getArtifactInfo();
- if (artifactInfo != null && data != null) {
+ if ((artifactInfo != null) && (data != null)) {
IDistributionClientResult deploymentStatus;
deploymentStatus = client.sendDeploymentStatus(buildStatusMessage(
client, data, artifactInfo,
}
}
- private void handleArtifact(INotificationData data, String svcName, String resourceName, IArtifactInfo artifact, File incomingDir, File archiveDir) {
+ private void handleArtifact(INotificationData data, String svcName, String resourceName, String resourceType, IArtifactInfo artifact, File incomingDir, File archiveDir) {
// Download Artifact
IDistributionClientDownloadResult downloadResult = client
.download(artifact);
- String payload = new String(downloadResult.getArtifactPayload());
+ if (downloadResult == null) {
+
+ handleFailedDownload(data, artifact);
+ return;
+ }
+
+ byte[] payloadBytes = downloadResult.getArtifactPayload();
+
+ if (payloadBytes == null) {
+ handleFailedDownload(data, artifact);
+ return;
+ }
+
+ String payload = new String(payloadBytes);
File spoolFile = new File(incomingDir.getAbsolutePath() + "/" + artifact.getArtifactName());
}
- if (writeSucceeded && downloadResult.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) {
+ if (writeSucceeded && (downloadResult.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS)) {
handleSuccessfulDownload(data, svcName, resourceName, artifact, spoolFile, archiveDir);
private void handleSuccessfulDownload(INotificationData data, String svcName, String resourceName,
IArtifactInfo artifact, File spoolFile, File archiveDir) {
- if (data != null && artifact != null) {
+ if ((data != null) && (artifact != null)) {
// Send Download Status
IDistributionClientResult sendDownloadStatus = client
.sendDownloadStatus(buildStatusMessage(client, data, artifact, DistributionStatusEnum.DOWNLOAD_OK));
// If an override file exists, read that instead of the file we just downloaded
ArtifactTypeEnum artifactEnum = ArtifactTypeEnum.YANG_XML;
+ boolean toscaYamlType = false;
if (artifact != null) {
- artifact.getArtifactType();
+ String artifactTypeString = artifact.getArtifactType();
+ if (artifactTypeString.contains("TOSCA_TEMPLATE")) {
+ toscaYamlType = true;
+ }
+ } else {
+ if (spoolFile.toString().contains(".yml") || spoolFile.toString().contains(".csar")) {
+ toscaYamlType = true;
+ }
}
String overrideFileName = config.getOverrideFile();
- if (overrideFileName != null && overrideFileName.length() > 0) {
+ if ((overrideFileName != null) && (overrideFileName.length() > 0)) {
File overrideFile = new File(overrideFileName);
if (overrideFile.exists()) {
}
+ if (toscaYamlType == true) {
+ processToscaYaml (data, svcName, resourceName, artifact, spoolFile, archiveDir);
+
+ try {
+ Path source = spoolFile.toPath();
+ Path targetDir = archiveDir.toPath();
+
+ Files.move(source, targetDir.resolve(source.getFileName()), StandardCopyOption.REPLACE_EXISTING);
+ } catch (IOException e) {
+ LOG.warn("Could not move "+spoolFile.getAbsolutePath()+" to "+archiveDir.getAbsolutePath(), e);
+ }
+
+ return;
+ }
+
// Process spool file
Document spoolDoc = null;
File transformedFile = null;
// Apply XSLTs and get Doc object
try {
+ if (!spoolFile.isDirectory()) {
transformedFile = applyXslts(spoolFile);
+ }
} catch (Exception e) {
LOG.error("Caught exception trying to parse XML file", e);
}
SdncArtifactType artifactType = analyzeFileType(artifactEnum,
spoolFile, spoolDoc);
- if (artifactType != SdncArtifactType.UNKNOWN) {
+ if (artifactType != null) {
scheduleDeployment(artifactType, svcName, resourceName, artifact, spoolFile.getName(), transformedFile);
}
+ private void processToscaYaml(INotificationData data, String svcName, String resourceName,
+ IArtifactInfo artifact, File spoolFile, File archiveDir) {
+
+ // Use ASDC Dist Client 1.1.5 with TOSCA parsing APIs to extract relevant TOSCA model data
+
+ // TOSCA data extraction flow 1707:
+ // Use ASDC dist-client to get yaml string - not yet available
+ String model_yaml = null;
+ LOG.info("Process TOSCA YAML file: "+spoolFile.toString());
+
+ SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
+ ISdcCsarHelper sdcCsarHelper = null;
+ try {
+ sdcCsarHelper = factory.getSdcCsarHelper(spoolFile.getAbsolutePath());
+ } catch (SdcToscaParserException e) {
+ LOG.error("Could not create SDC TOSCA Parser ", e);
+ factory.close();
+ return;
+ }
+
+ // Ingest Service Data - 1707
+ Metadata serviceMetadata = sdcCsarHelper.getServiceMetadata();
+ SdncServiceModel serviceModel = new SdncServiceModel(sdcCsarHelper, serviceMetadata);
+ serviceModel.setFilename(spoolFile.toString().substring(spoolFile.toString().lastIndexOf("/")+1)); // will be csar file name
+ serviceModel.setServiceInstanceNamePrefix(SdncBaseModel.extractSubstitutionMappingTypeName(sdcCsarHelper).substring(SdncBaseModel.extractSubstitutionMappingTypeName(sdcCsarHelper).lastIndexOf(".")+1));
+
+ try {
+ cleanUpExistingToscaServiceData(serviceModel.getServiceUUID());
+ LOG.info("Call insertToscaData for SERVICE_MODEL serviceUUID = " + serviceModel.getServiceUUID());
+ insertToscaData(serviceModel.getSql(model_yaml));
+ } catch (IOException e) {
+ LOG.error("Could not insert Tosca YAML data into the SERVICE_MODEL table ", e);
+ factory.close();
+ return;
+ }
+
+ // Ingest Network (VL) Data - 1707
+ //List<NodeTemplate> vlNodeTemplatesList = sdcCsarHelper.getServiceNodeTemplatesByType("VL");
+ List<NodeTemplate> vlNodeTemplatesList = sdcCsarHelper.getServiceVlList();
+
+ for (NodeTemplate nodeTemplate : vlNodeTemplatesList) {
+ SdncNodeModel nodeModel = new SdncNodeModel (sdcCsarHelper, nodeTemplate);
+ nodeModel.setServiceUUID(serviceModel.getServiceUUID());
+ nodeModel.setEcompGeneratedNaming(SdncBaseModel.extractBooleanInputDefaultValue(sdcCsarHelper, SdcPropertyNames.PROPERTY_NAME_SERVICENAMING_DEFAULT_ECOMPGENERATEDNAMING));//service_naming#default#ecomp_generated_naming
+
+ try {
+ cleanUpExistingToscaData("NETWORK_MODEL", "customization_uuid", nodeModel.getCustomizationUUID());
+ cleanUpExistingToscaData("VPN_BINDINGS", "network_customization_uuid", nodeModel.getCustomizationUUID());
+ LOG.info("Call insertToscaData for NETWORK_MODEL customizationUUID = " + nodeModel.getCustomizationUUID());
+ // using ASDC dist-client use method for get yaml string
+ insertToscaData(nodeModel.getSql(model_yaml));
+ insertToscaData(nodeModel.getVpnBindingsSql());
+ } catch (IOException e) {
+ LOG.error("Could not insert Tosca YAML data into the NETWORK_MODEL table ", e);
+ }
+ }
+
+ // Ingest Allotted Resource Data - 1707
+ List<NodeTemplate> arNodeTemplatesList = sdcCsarHelper.getAllottedResources();
+
+ for (NodeTemplate nodeTemplate : arNodeTemplatesList) {
+ SdncARModel nodeModel = new SdncARModel (sdcCsarHelper, nodeTemplate);
+
+ try {
+ cleanUpExistingToscaData("ALLOTTED_RESOURCE_MODEL", "customization_uuid", nodeModel.getCustomizationUUID());
+ LOG.info("Call insertToscaData for ALLOTTED_RESOURCE_MODEL customizationUUID = " + nodeModel.getCustomizationUUID());
+ // using ASDC dist-client use method for get yaml string
+ insertToscaData(nodeModel.getSql("ALLOTTED_RESOURCE_MODEL", model_yaml));
+ } catch (IOException e) {
+ LOG.error("Could not insert Tosca YAML data into the NETWORK_MODEL table ", e);
+ }
+ }
+
+ // Ingest Network (VF) Data - 1707
+ //List<NodeTemplate> nodeTemplatesList = sdcCsarHelper.getServiceNodeTemplatesByType("VF");
+ List<NodeTemplate> vfNodeTemplatesList = sdcCsarHelper.getServiceVfList();
+
+ for (NodeTemplate nodeTemplate : vfNodeTemplatesList) {
+ SdncVFModel vfNodeModel = new SdncVFModel (sdcCsarHelper, nodeTemplate);
+
+ try {
+ cleanUpExistingToscaData("VF_MODEL", "customization_uuid", vfNodeModel.getCustomizationUUID()) ;
+ LOG.info("Call insertToscaData for VF_MODEL customizationUUID = " + vfNodeModel.getCustomizationUUID());
+ insertToscaData(vfNodeModel.getSql("VF_MODEL", model_yaml));
+ } catch (IOException e) {
+ LOG.error("Could not insert Tosca YAML data into the VF_MODEL table ", e);
+ }
+
+ // For each VF, insert VF_MODULE_MODEL data
+ List<Group> vfModules = sdcCsarHelper.getVfModulesByVf(vfNodeModel.getCustomizationUUIDNoQuotes());
+ for (Group group : vfModules){
+ SdncVFModuleModel vfModuleModel = new SdncVFModuleModel(sdcCsarHelper, group);
+
+ try {
+ cleanUpExistingToscaData("VF_MODULE_MODEL", "customization_uuid", vfModuleModel.getCustomizationUUID());
+ LOG.info("Call insertToscaData for VF_MODULE_MODEL customizationUUID = " + vfModuleModel.getCustomizationUUID());
+ insertToscaData(vfModuleModel.getSql("VF_MODULE_MODEL", model_yaml));
+ } catch (IOException e) {
+ LOG.error("Could not insert Tosca YAML data into the VF_MODULE_MODEL table ", e);
+ }
+
+ // For each VF Module, get the VFC list, insert VF_MODULE_TO_VFC_MAPPING data
+ // List<NodeTemplate> groupMembers = sdcCsarHelper.getMembersOfGroup(group); - old version
+ // For each vfcNode (group member) in the groupMembers list, extract vm_type and vm_count.
+ // Insert vf_module.customizationUUID, vfcNode.customizationUUID and vm_type and vm_count into VF_MODULE_TO_VFC_MAPPING
+ List<NodeTemplate> groupMembers = sdcCsarHelper.getMembersOfVfModule(nodeTemplate, group); // not yet available
+ for (NodeTemplate vfcNode : groupMembers){
+ SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, vfcNode);
+
+ try {
+ cleanUpExistingToscaData("VF_MODULE_TO_VFC_MAPPING", "vf_module_customization_uuid", vfModuleModel.getCustomizationUUID());
+ LOG.info("Call insertToscaData for VF_MODULE_TO_VFC_MAPPING customizationUUID = " + vfModuleModel.getCustomizationUUID());
+ insertToscaData("insert into VF_MODULE_TO_VFC_MAPPING (vf_module_customization_uuid, vfc_customization_uuid, vm_type, vm_count) values (" +
+ vfModuleModel.getCustomizationUUID() + ", " + vfcModel.getCustomizationUUID() + ", \"" + vfcModel.getVmType() + "\", \"" + vfcModel.getVmCount() + "\")");
+ } catch (IOException e) {
+ LOG.error("Could not insert Tosca YAML data into the VF_MODULE_TO_VFC_MAPPING table ", e);
+ }
+
+ }
+
+ }
+
+ // For each VF, insert VFC_MODEL data
+ List<NodeTemplate> vfcNodes = sdcCsarHelper.getVfcListByVf(vfNodeModel.getCustomizationUUIDNoQuotes());
+ for (NodeTemplate vfcNode : vfcNodes){
+ SdncVFCModel vfcModel = new SdncVFCModel(sdcCsarHelper, vfcNode);
+
+ try {
+ cleanUpExistingToscaData("VFC_MODEL", "customization_uuid", vfcModel.getCustomizationUUID());
+ LOG.info("Call insertToscaData for VFC_MODEL customizationUUID = " + vfcModel.getCustomizationUUID());
+ insertToscaData(vfcModel.getSql("VFC_MODEL", model_yaml));
+ } catch (IOException e) {
+ LOG.error("Could not insert Tosca YAML data into the VFC_MODEL table ", e);
+ }
+
+ }
+
+ // For each VF, insert VF_TO_NETWORK_ROLE_MAPPING data
+ List<NodeTemplate> cpNodes = sdcCsarHelper.getCpListByVf(vfNodeModel.getCustomizationUUIDNoQuotes());
+ for (NodeTemplate cpNode : cpNodes){
+
+ // Insert into VF_TO_NETWORK_ROLE_MAPPING vf_customization_uuid and network_role
+ String cpNetworkRole = sdcCsarHelper.getNodeTemplatePropertyLeafValue(cpNode, "network_role_tag");
+
+ try {
+ cleanUpExistingToscaData("VF_TO_NETWORK_ROLE_MAPPING", "vf_customization_uuid", vfNodeModel.getCustomizationUUID());
+ LOG.info("Call insertToscaData for VF_TO_NETWORK_ROLE_MAPPING vfCustomizationUUID = " + vfNodeModel.getCustomizationUUID());
+ insertToscaData("insert into VF_TO_NETWORK_ROLE_MAPPING (vf_customization_uuid, network_role) values (" +
+ vfNodeModel.getCustomizationUUID() + ", \"" + cpNetworkRole + "\")");
+ } catch (IOException e) {
+ LOG.error("Could not insert Tosca YAML data into the VF_TO_NETWORK_ROLE_MAPPING table ", e);
+ }
+
+ // Insert VFC_TO_NETWORK_ROLE_MAPPING data
+ Map<String, String> mappingParams = new HashMap<String, String>();
+ //String cpNetworkRoleTag = "\"" + sdcCsarHelper.getNodeTemplatePropertyLeafValue(cpNode, SdcPropertyNames.PROPERTY_NAME_NETWORKROLETAG) + "\"";
+ // extract network_role, network_role_tag and virtual_binding from this cpNode
+ SdncBaseModel.addParameter("network_role", SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "network_role"), mappingParams);
+ SdncBaseModel.addParameter("network_role_tag", SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "network_role_tag"), mappingParams);
+ String virtualBinding = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, cpNode, "requirements#virtualBinding") + "\"";
+
+ // get list of cpNodes and vfcNodes with matching virtualBinding
+ List<Pair<NodeTemplate, NodeTemplate>> matchList = sdcCsarHelper.getNodeTemplatePairsByReqName(sdcCsarHelper.getCpListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()), sdcCsarHelper.getVfcListByVf(vfNodeModel.getCustomizationUUIDNoQuotes()), virtualBinding);
+ for (Pair<NodeTemplate, NodeTemplate> match : matchList) { // should be 1 match?
+
+ // extract values from the left "CP" Node
+ SdncBaseModel.addParameter("ipv4_use_dhcp", SdncBaseModel.extractBooleanValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_DHCPENABLED), mappingParams);
+ //SdncBaseModel.addParameter("ipv4_ip_version", SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_IPVERSION), mappingParams);
+ SdncBaseModel.addParameter("ipv4_ip_version", "dummy_ipv4_vers", mappingParams);
+ SdncBaseModel.addParameter("ipv6_use_dhcp", SdncBaseModel.extractBooleanValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_DHCPENABLED), mappingParams);
+ //SdncBaseModel.addParameter("ipv6_ip_version", SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_IPVERSION), mappingParams);
+ SdncBaseModel.addParameter("ipv6_ip_version", "dummy_ipv6_vers", mappingParams);
+ //String extcp_subnetpool_id = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, match.getLeft(), SdcPropertyNames.PROPERTY_NAME_SUBNETPOOLID) + "\""; // need path to subnetpoolid
+
+ // extract values from the right "VFC" Node
+ String vfcCustomizationUuid = "\"" + SdncBaseModel.extractValue(sdcCsarHelper, match.getRight().getMetadata(), "customization_uuid") + "\"";
+ SdncBaseModel.addParameter("vm_type", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_VMTYPE), mappingParams);
+ SdncBaseModel.addIntParameter("ipv4_count", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT), mappingParams);
+ SdncBaseModel.addIntParameter("ipv6_count", SdncBaseModel.extractValue(sdcCsarHelper, match.getRight(), SdcPropertyNames.PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT), mappingParams);
+
+ try {
+ cleanUpExistingToscaData("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", vfcCustomizationUuid);
+ LOG.info("Call insertToscaData for VFC_TO_NETWORK_ROLE_MAPPING vfcCustomizationUUID = " + vfcCustomizationUuid);
+ insertToscaData(SdncBaseModel.getSql("VFC_TO_NETWORK_ROLE_MAPPING", "vfc_customization_uuid", vfcCustomizationUuid, "", mappingParams));
+ } catch (IOException e) {
+ LOG.error("Could not insert Tosca YAML data into the VFC_TO_NETWORK_ROLE_MAPPING table ", e);
+ }
+
+ }
+
+ } // CP loop
+
+ } // VF loop
+
+ // Close ASDC TOSCA Parser factory - we are done processing this distribution
+ factory.close();
+
+ if ((artifact != null) && (data != null)) {
+ LOG.info("Update to SDN-C succeeded");
+ IDistributionClientResult deploymentStatus;
+ deploymentStatus = client.sendDeploymentStatus(buildStatusMessage(
+ client, data, artifact,
+ DistributionStatusEnum.DEPLOY_OK));
+ }
+
+ }
+
+ private void cleanUpExistingToscaData(String tableName, String keyName, String keyValue) throws IOException
+ {
+
+ if (jdbcDataSource == null) {
+ setJdbcDataSource();
+ }
+ try {
+ int rowCount = 0;
+ CachedRowSet data = jdbcDataSource.getData("SELECT * from " + tableName + " where " + keyName + " = " + keyValue + ";", null, "");
+ while(data.next()) {
+ rowCount ++;
+ }
+ if (rowCount != 0) {
+ LOG.info("cleanUpExistingToscaData: " + keyValue);
+ jdbcDataSource.writeData("DELETE from " + tableName + " where " + keyName + " = " + keyValue + ";", null, null);
+ }
+
+ } catch (SQLException e) {
+ LOG.error("Could not clean up existing " + tableName + " for " + keyValue, e);
+ }
+
+ }
+
+
+ private void cleanUpExistingToscaServiceData(String serviceUUID) throws IOException
+ {
+
+ if (jdbcDataSource == null) {
+ setJdbcDataSource();
+ }
+ try {
+ int rowCount = 0;
+ CachedRowSet data = jdbcDataSource.getData("SELECT * from SERVICE_MODEL where service_uuid = " + serviceUUID + ";", null, "");
+ while(data.next()) {
+ rowCount ++;
+ }
+ if (rowCount != 0) {
+ LOG.info("cleanUpExistingToscaData: " + serviceUUID);
+ jdbcDataSource.writeData("DELETE from NETWORK_MODEL where service_uuid = " + serviceUUID + ";", null, null);
+ jdbcDataSource.writeData("DELETE from SERVICE_MODEL where service_uuid = " + serviceUUID + ";", null, null);
+ }
+
+ } catch (SQLException e) {
+ LOG.error("Could not clean up existing NETWORK_MODEL and SERVICE_MODEL for service_UUID " + serviceUUID, e);
+ }
+
+ }
+
+
+ private void insertToscaData(String toscaDataString) throws IOException
+ {
+ LOG.debug("insertToscaData: " + toscaDataString);
+
+ if (jdbcDataSource == null) {
+ setJdbcDataSource();
+ }
+ try {
+
+ jdbcDataSource.writeData(toscaDataString, null, null);
+
+ } catch (SQLException e) {
+ LOG.error("Could not insert Tosca YAML data into the database ", e);
+ }
+
+ }
+
+
private SdncArtifactType analyzeFileType(ArtifactTypeEnum artifactType, File spoolFile, Document spoolDoc) {
if (artifactType != ArtifactTypeEnum.YANG_XML) {
LOG.error("Unexpected artifact type - expecting YANG_XML, got "+artifactType);
- return SdncArtifactType.UNKNOWN;
+ return (null);
}
// Examine outer tag
}
if (rootName != null) {
- SdncArtifactType retValue = SdncArtifactType.fromTag(rootName);
+ SdncArtifactType mapEntry = config.getMapping(rootName);
- if (retValue == SdncArtifactType.UNKNOWN) {
+
+ if (mapEntry == null) {
LOG.error("Unexpected file contents - root tag is "+rootName);
}
- return retValue;
+ return(mapEntry);
} else {
LOG.error("Cannot get root tag from file");
- return SdncArtifactType.UNKNOWN;
+ return(null);
}
} catch (Exception e) {
LOG.error("Could not parse YANG_XML file "+spoolFile.getName(), e);
- return SdncArtifactType.UNKNOWN;
+ return(null);
}
}
String namespace = config.getAsdcApiNamespace();
- if (namespace == null || namespace.length() == 0) {
+ if ((namespace == null) || (namespace.length() == 0)) {
namespace="com:att:sdnctl:asdcapi";
}
} catch (Exception e) {
LOG.error("Could not process spool file "+artifact.getFile().getName(), e);
- return DistributionStatusEnum.DEPLOY_ERROR;
+ return(DistributionStatusEnum.DEPLOY_ERROR);
}
msgBuffer.append("</input>\n");
- return deployResult;
+ return(deployResult);
}
conn.setDoOutput(true);
conn.setUseCaches(false);
- return conn;
+ return(conn);
}
private Document postRestXml(String urlString, byte[] msgBytes) {
Document response = null;
- LOG.info("Sending REST POST to "+urlString);
- LOG.info("Message body:\n"+new String(msgBytes));
-
try {
- HttpURLConnection conn = getRestXmlConnection(urlString, "POST");
-
- if (conn instanceof HttpsURLConnection) {
- HostnameVerifier hostnameVerifier = new HostnameVerifier() {
- @Override
- public boolean verify(String hostname, SSLSession session) {
- return true;
- }
- };
- ((HttpsURLConnection)conn).setHostnameVerifier(hostnameVerifier);
- }
-
- // Write message
- conn.setRequestProperty("Content-Length", ""+msgBytes.length);
- DataOutputStream outStr = new DataOutputStream(conn.getOutputStream());
- outStr.write(msgBytes);
- outStr.close();
+ SdncOdlConnection odlConn = SdncOdlConnection.newInstance(urlString, config.getSdncUser(), config.getSdncPasswd());
-
- // Read response
- BufferedReader respRdr;
-
- LOG.info("Response: "+conn.getResponseCode()+" "+conn.getResponseMessage());
-
-
- if (conn.getResponseCode() < 300) {
-
- respRdr = new BufferedReader(new InputStreamReader(conn.getInputStream()));
- } else {
- respRdr = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
- }
-
- StringBuffer respBuff = new StringBuffer();
-
- String respLn;
-
- while ((respLn = respRdr.readLine()) != null) {
- respBuff.append(respLn+"\n");
- }
- respRdr.close();
-
- String respString = respBuff.toString();
-
- LOG.info("Response body :\n"+respString);
+ String sdncResp = odlConn.send("POST", "application/xml", new String(msgBytes));
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
- response = db.parse(new ByteArrayInputStream(respString.getBytes()));
-
+ response = db.parse(new ByteArrayInputStream(sdncResp.getBytes()));
} catch (Exception e) {
-
- LOG.error("Caught exception in postRestXml", e);
+ LOG.error("Caught exception posting to ODL tier", e);
}
- return response;
+ return(response);
+
}
private File applyXslts(File srcFile) {
String xsltPathList = config.getXsltPathList();
- if (xsltPathList == null || xsltPathList.length() == 0) {
+ if ((xsltPathList == null) || (xsltPathList.length() == 0)) {
outFile = inFile;
} else {
// After transformations, parse transformed XML
- return outFile;
+ return(outFile);
}
private String escapeFilename(String str) {
}
}
- return retval.toString();
+ return(retval.toString());
}