From b8e2faf476202b6ffe61bc3a9a37df1304881d40 Mon Sep 17 00:00:00 2001 From: Avi Ziv Date: Tue, 18 Jul 2017 19:45:38 +0300 Subject: [SDC] Onboarding 1710 rebase. Change-Id: If3b6b81d221fde13908f1e8160db6f7d9433c535 Signed-off-by: Avi Ziv --- .../openecomp-sdc-tosca-generator-api/pom.xml | 68 ++++ .../generator/datatypes/tosca/ComputeFlavor.java | 69 ++++ .../datatypes/tosca/DeploymentFlavorModel.java | 90 +++++ .../generator/datatypes/tosca/LicenseFlavor.java | 42 ++ .../datatypes/tosca/MultiFlavorVfcImage.java | 91 +++++ .../sdc/generator/datatypes/tosca/VendorInfo.java | 58 +++ .../generator/datatypes/tosca/VspModelInfo.java | 58 +++ .../sdc/generator/util/GeneratorConstants.java | 25 ++ .../openecomp-sdc-tosca-generator-core/pom.xml | 68 ++++ .../services/ManualVspToscaGenerationService.java | 433 +++++++++++++++++++++ .../sdc/generator/core/utils/GeneratorUtils.java | 244 ++++++++++++ .../resources/config-manualVspToscaGenerator.json | 5 + .../lib/openecomp-sdc-tosca-generator-lib/pom.xml | 22 ++ 13 files changed, 1273 insertions(+) create mode 100644 openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/pom.xml create mode 100644 openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/ComputeFlavor.java create mode 100644 openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/DeploymentFlavorModel.java create mode 100644 openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/LicenseFlavor.java create mode 100644 openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/MultiFlavorVfcImage.java create mode 100644 openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/VendorInfo.java create mode 100644 openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/VspModelInfo.java create mode 100644 openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/util/GeneratorConstants.java create mode 100644 openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/pom.xml create mode 100644 openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/src/main/java/org/openecomp/sdc/generator/core/services/ManualVspToscaGenerationService.java create mode 100644 openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/src/main/java/org/openecomp/sdc/generator/core/utils/GeneratorUtils.java create mode 100644 openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/src/main/resources/config-manualVspToscaGenerator.json create mode 100644 openecomp-be/lib/openecomp-sdc-tosca-generator-lib/pom.xml (limited to 'openecomp-be/lib/openecomp-sdc-tosca-generator-lib') diff --git a/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/pom.xml b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/pom.xml new file mode 100644 index 0000000000..047fe7f843 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/pom.xml @@ -0,0 +1,68 @@ + + 4.0.0 + + openecomp-sdc-tosca-generator-api + openecomp-sdc-tosca-generator-api + + + + org.openecomp.sdc + openecomp-sdc-lib + 1.1.0-SNAPSHOT + ../.. + + + + + org.openecomp.sdc.core + openecomp-facade-core + ${project.version} + + + org.openecomp.sdc + openecomp-sdc-validation-api + ${project.version} + + + org.openecomp.sdc + openecomp-sdc-validation-core + ${project.version} + runtime + + + io.swagger + swagger-annotations + 1.5.3 + + + org.openecomp.sdc.core + openecomp-tosca-lib + ${project.version} + + + org.openecomp.sdc.common + openecomp-configuration-management-core + ${openecomp.sdc.common.version} + runtime + + + org.slf4j + slf4j-log4j12 + + + + + org.openecomp.sdc.common + openecomp-configuration-management-api + ${project.version} + + + org.openecomp.sdc + openecomp-sdc-vendor-software-product-api + ${project.version} + + + + diff --git a/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/ComputeFlavor.java b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/ComputeFlavor.java new file mode 100644 index 0000000000..d888bd311b --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/ComputeFlavor.java @@ -0,0 +1,69 @@ +package org.openecomp.sdc.generator.datatypes.tosca; + +@SuppressWarnings("CheckStyle") +public class ComputeFlavor { + + private int num_cpus; + private String disk_size; + private String mem_size; + + public int getNum_cpus() { + return num_cpus; + } + + public void setNum_cpus(int num_cpus) { + this.num_cpus = num_cpus; + } + + public String getDisk_size() { + return disk_size; + } + + public void setDisk_size(String disk_size) { + this.disk_size = disk_size; + } + + public String getMem_size() { + return mem_size; + } + + public void setMem_size(String mem_size) { + this.mem_size = mem_size; + } + + @Override + public String toString() { + return "ComputeFlavor{ num_cpus=" + num_cpus + ", disk_size= " + disk_size + + ", mem_size=" + mem_size + "}"; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (getClass() != obj.getClass()) + return false; + ComputeFlavor other = (ComputeFlavor) obj; + if (num_cpus != other.num_cpus) + return false; + if (this.disk_size == null) { + if (other.disk_size != null) + return false; + } else if (!disk_size.equals(other.disk_size)) + return false; + if (this.mem_size == null) { + if (other.mem_size != null) + return false; + } else if (!mem_size.equals(other.mem_size)) + return false; + return true; + } + + @Override + public int hashCode() { + int result = num_cpus; + result = 31 * result + (disk_size != null ? disk_size.hashCode() : 0); + result = 31 * result + (mem_size != null ? mem_size.hashCode() : 0); + return result; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/DeploymentFlavorModel.java b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/DeploymentFlavorModel.java new file mode 100644 index 0000000000..a0d5f40b8c --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/DeploymentFlavorModel.java @@ -0,0 +1,90 @@ +package org.openecomp.sdc.generator.datatypes.tosca; + +@SuppressWarnings("CheckStyle") +public class DeploymentFlavorModel { + + private String sp_part_number; + private VendorInfo vendor_info; + private ComputeFlavor compute_flavor; + private LicenseFlavor license_flavor; + + public String getSp_part_number() { + return sp_part_number; + } + + public void setSp_part_number(String sp_part_number) { + this.sp_part_number = sp_part_number; + } + + public VendorInfo getVendor_info() { + return vendor_info; + } + + public void setVendor_info(VendorInfo vendor_info) { + this.vendor_info = vendor_info; + } + + public ComputeFlavor getCompute_flavor() { + return compute_flavor; + } + + public void setCompute_flavor(ComputeFlavor compute_flavor) { + this.compute_flavor = compute_flavor; + } + + public LicenseFlavor getLicense_flavor() { + return license_flavor; + } + + public void setLicense_flavor(LicenseFlavor license_flavor) { + this.license_flavor = license_flavor; + } + + @Override + public String toString() { + return "DeploymentFlavorModel{" + "sp_part_number='" + sp_part_number + '\'' + + ", vendor_info=" + vendor_info + + ", compute_flavor=" + compute_flavor + + ", license_flavor=" + license_flavor + + '}'; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (getClass() != obj.getClass()) + return false; + DeploymentFlavorModel other = (DeploymentFlavorModel) obj; + if (this.sp_part_number == null) { + if (other.sp_part_number != null) + return false; + } else if (!sp_part_number.equals(other.sp_part_number)) + return false; + if (this.vendor_info == null) { + if (other.vendor_info != null) + return false; + } else if (!vendor_info.equals(other.vendor_info)) + return false; + if (this.compute_flavor == null) { + if (other.compute_flavor != null) + return false; + } else if (!compute_flavor.equals(other.compute_flavor)) + return false; + if (this.license_flavor == null) { + if (other.license_flavor != null) + return false; + } else if (!license_flavor.equals(other.license_flavor)) + return false; + return true; + } + + @Override + public int hashCode() { + int result = sp_part_number != null ? sp_part_number.hashCode() : 0; + result = 31 * result + (vendor_info != null ? vendor_info.hashCode() : 0); + result = 31 * result + (compute_flavor != null ? compute_flavor.hashCode() : 0); + result = 31 * result + (license_flavor != null ? license_flavor.hashCode() : 0); + return result; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/LicenseFlavor.java b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/LicenseFlavor.java new file mode 100644 index 0000000000..f459d9e993 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/LicenseFlavor.java @@ -0,0 +1,42 @@ +package org.openecomp.sdc.generator.datatypes.tosca; + +@SuppressWarnings("CheckStyle") +public class LicenseFlavor { + + String feature_group_uuid; + + public String getFeature_group_uuid() { + return feature_group_uuid; + } + + public void setFeature_group_uuid(String feature_group_uuid) { + this.feature_group_uuid = feature_group_uuid; + } + + @Override + public String toString() { + return "LicenseFlavor{" + + "feature_group_uuid='" + feature_group_uuid + '\'' + + '}'; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (getClass() != obj.getClass()) + return false; + LicenseFlavor other = (LicenseFlavor) obj; + if (this.feature_group_uuid == null) { + if (other.feature_group_uuid != null) + return false; + } else if (!feature_group_uuid.equals(other.feature_group_uuid)) + return false; + return true; + } + + @Override + public int hashCode() { + return feature_group_uuid != null ? feature_group_uuid.hashCode() : 0; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/MultiFlavorVfcImage.java b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/MultiFlavorVfcImage.java new file mode 100644 index 0000000000..6cd713e2d1 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/MultiFlavorVfcImage.java @@ -0,0 +1,91 @@ +package org.openecomp.sdc.generator.datatypes.tosca; + +@SuppressWarnings("CheckStyle") +public class MultiFlavorVfcImage { + + private String file_name; + private String file_hash; + private String file_hash_type; + private String software_version; + + public String getFile_name() { + return file_name; + } + + public void setFile_name(String file_name) { + this.file_name = file_name; + } + + public String getFile_hash() { + return file_hash; + } + + public void setFile_hash(String file_hash) { + this.file_hash = file_hash; + } + + public String getFile_hash_type() { + return file_hash_type; + } + + public void setFile_hash_type(String file_hash_type) { + this.file_hash_type = file_hash_type; + } + + public String getSoftware_version() { + return software_version; + } + + public void setSoftware_version(String software_version) { + this.software_version = software_version; + } + + @Override + public String toString() { + return "MultiFlavorVfcImage{" + + "file_name='" + file_name + '\'' + + ", file_hash='" + file_hash + '\'' + + ", file_hash_type='" + file_hash_type + '\'' + + ", software_version='" + software_version + '\'' + + '}'; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (getClass() != obj.getClass()) + return false; + MultiFlavorVfcImage other = (MultiFlavorVfcImage) obj; + if (this.file_name == null) { + if (other.file_name != null) + return false; + } else if (!file_name.equals(other.file_name)) + return false; + if (this.file_hash == null) { + if (other.file_hash != null) + return false; + } else if (!file_hash.equals(other.file_hash)) + return false; + if (this.file_hash_type == null) { + if (other.file_hash_type != null) + return false; + } else if (!file_hash_type.equals(other.file_hash_type)) + return false; + if (this.software_version == null) { + if (other.software_version != null) + return false; + } else if (!software_version.equals(other.software_version)) + return false; + return true; + } + + @Override + public int hashCode() { + int result = file_name != null ? file_name.hashCode() : 0; + result = 31 * result + (file_hash != null ? file_hash.hashCode() : 0); + result = 31 * result + (file_hash_type != null ? file_hash_type.hashCode() : 0); + result = 31 * result + (software_version != null ? software_version.hashCode() : 0); + return result; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/VendorInfo.java b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/VendorInfo.java new file mode 100644 index 0000000000..22348f3083 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/VendorInfo.java @@ -0,0 +1,58 @@ +package org.openecomp.sdc.generator.datatypes.tosca; + +@SuppressWarnings("CheckStyle") +public class VendorInfo { + + private String manufacturer_reference_number; + private String vendor_model; + + public String getManufacturer_reference_number() { + return manufacturer_reference_number; + } + + public void setManufacturer_reference_number(String manufacturer_reference_number) { + this.manufacturer_reference_number = manufacturer_reference_number; + } + + public String getVendor_model() { + return vendor_model; + } + + public void setVendor_model(String vendor_model) { + this.vendor_model = vendor_model; + } + + @Override + public String toString() { + return "VendorInfo{manufacturer_reference_number='" + manufacturer_reference_number + '\'' + + ", vendor_model='" + vendor_model + '\'' + '}'; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (getClass() != obj.getClass()) + return false; + VendorInfo other = (VendorInfo) obj; + if (this.manufacturer_reference_number == null) { + if (other.manufacturer_reference_number != null) + return false; + } else if (!manufacturer_reference_number.equals(other.manufacturer_reference_number)) + return false; + if (this.vendor_model == null) { + if (other.vendor_model != null) + return false; + } else if (!vendor_model.equals(other.vendor_model)) + return false; + return true; + } + + @Override + public int hashCode() { + int result = + manufacturer_reference_number != null ? manufacturer_reference_number.hashCode() : 0; + result = 31 * result + (vendor_model != null ? vendor_model.hashCode() : 0); + return result; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/VspModelInfo.java b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/VspModelInfo.java new file mode 100644 index 0000000000..1fb1030dd3 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/datatypes/tosca/VspModelInfo.java @@ -0,0 +1,58 @@ +package org.openecomp.sdc.generator.datatypes.tosca; + +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic; + +import java.util.List; +import java.util.Map; + +public class VspModelInfo { + private String releaseVendor; + //Map of component id and name + private Map components; + //Map of part number and deployment flavor model + private Map allowedFlavors; + //Map of component id and images + private Map> multiFlavorVfcImages; + //Map of component and ports (NICs) + private Map> nics; + + public String getReleaseVendor() { + return releaseVendor; + } + + public void setReleaseVendor(String releaseVendor) { + this.releaseVendor = releaseVendor; + } + + public Map getComponents() { + return components; + } + + public void setComponents(Map components) { + this.components = components; + } + + public Map getAllowedFlavors() { + return allowedFlavors; + } + + public void setAllowedFlavors(Map allowedFlavors) { + this.allowedFlavors = allowedFlavors; + } + + public Map> getMultiFlavorVfcImages() { + return multiFlavorVfcImages; + } + + public void setMultiFlavorVfcImages(Map> multiFlavorVfcImages) { + this.multiFlavorVfcImages = multiFlavorVfcImages; + } + + public Map> getNics() { + return nics; + } + + public void setNics(Map> nics) { + this.nics = nics; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/util/GeneratorConstants.java b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/util/GeneratorConstants.java new file mode 100644 index 0000000000..b24a85d61c --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-api/src/main/java/org/openecomp/sdc/generator/util/GeneratorConstants.java @@ -0,0 +1,25 @@ +package org.openecomp.sdc.generator.util; + +public class GeneratorConstants { + public static final String ALLOWED_FLAVORS_PROPERTY = "allowed_flavors"; + public static final String IMAGES_PROPERTY = "images"; + public static final String RELEASE_VENDOR = "releaseVendor"; + public static final String VNF_CONFIG_NODE_TEMPLATE_ID_SUFFIX = "_VNF_Configuration"; + public static final String VFC_NODE_TEMPLATE_ID_SUFFIX = "_VFC"; + public static final String VNF_NODE_TEMPLATE_ID_SUFFIX = "_VNF"; + public static final String PORT_NODE_TEMPLATE_ID_SUFFIX = "_wan_port"; + + public static final String TOSCA_SERVICE_TEMPLATE_FILE_NAME_SUFFIX = "ServiceTemplate.yaml"; + + //Manual VSP propeties + public static final String NUM_CPUS = "num_cpus"; + public static final String DISK_SIZE = "disk_size"; + public static final String MEM_SIZE = "mem_size"; + + public static final String NUM_CPUS_PROP_DESC_PREFIX = "Number of cpu for "; + public static final String DISK_SIZE_PROP_DESC_PREFIX = "Disk size for "; + public static final String MEM_SIZE_PROP_DESC_PREFIX = "Memory size for "; + + + +} diff --git a/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/pom.xml b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/pom.xml new file mode 100644 index 0000000000..12e39d9112 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/pom.xml @@ -0,0 +1,68 @@ + + 4.0.0 + + openecomp-sdc-tosca-generator-core + openecomp-sdc-tosca-generator-core + + + + org.openecomp.sdc + openecomp-sdc-lib + 1.1.0-SNAPSHOT + ../.. + + + + + org.openecomp.sdc.common + openecomp-tosca-datatype + ${openecomp.sdc.common.version} + + + ch.qos.logback + logback-classic + ${logback.version} + + + junit + junit + ${junit.version} + test + + + org.openecomp.sdc + openecomp-sdc-tosca-generator-api + ${project.version} + + + org.openecomp.sdc + openecomp-sdc-datatypes-lib + ${project.version} + + + org.openecomp.sdc.common + openecomp-tosca-datatype + ${openecomp.sdc.common.version} + + + commons-io + commons-io + 2.5 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.19.1 + + false + true + + + + + \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/src/main/java/org/openecomp/sdc/generator/core/services/ManualVspToscaGenerationService.java b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/src/main/java/org/openecomp/sdc/generator/core/services/ManualVspToscaGenerationService.java new file mode 100644 index 0000000000..6d488c0221 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/src/main/java/org/openecomp/sdc/generator/core/services/ManualVspToscaGenerationService.java @@ -0,0 +1,433 @@ +package org.openecomp.sdc.generator.core.services; + +import static org.openecomp.sdc.generator.util.GeneratorConstants.ALLOWED_FLAVORS_PROPERTY; +import static org.openecomp.sdc.generator.util.GeneratorConstants.DISK_SIZE; +import static org.openecomp.sdc.generator.util.GeneratorConstants.DISK_SIZE_PROP_DESC_PREFIX; +import static org.openecomp.sdc.generator.util.GeneratorConstants.IMAGES_PROPERTY; +import static org.openecomp.sdc.generator.util.GeneratorConstants.MEM_SIZE; +import static org.openecomp.sdc.generator.util.GeneratorConstants.MEM_SIZE_PROP_DESC_PREFIX; +import static org.openecomp.sdc.generator.util.GeneratorConstants.NUM_CPUS; +import static org.openecomp.sdc.generator.util.GeneratorConstants.NUM_CPUS_PROP_DESC_PREFIX; +import static org.openecomp.sdc.generator.util.GeneratorConstants.PORT_NODE_TEMPLATE_ID_SUFFIX; +import static org.openecomp.sdc.generator.util.GeneratorConstants.RELEASE_VENDOR; +import static org.openecomp.sdc.generator.util.GeneratorConstants.TOSCA_SERVICE_TEMPLATE_FILE_NAME_SUFFIX; +import static org.openecomp.sdc.generator.util.GeneratorConstants.VFC_NODE_TEMPLATE_ID_SUFFIX; +import static org.openecomp.sdc.generator.util.GeneratorConstants.VNF_CONFIG_NODE_TEMPLATE_ID_SUFFIX; +import static org.openecomp.sdc.generator.util.GeneratorConstants.VNF_NODE_TEMPLATE_ID_SUFFIX; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import org.openecomp.sdc.generator.core.utils.GeneratorUtils; +import org.openecomp.sdc.generator.datatypes.tosca.MultiFlavorVfcImage; +import org.openecomp.sdc.generator.datatypes.tosca.VspModelInfo; +import org.openecomp.sdc.tosca.datatypes.ToscaNodeType; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.tosca.datatypes.model.Import; +import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; +import org.openecomp.sdc.tosca.datatypes.model.NodeType; +import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition; +import org.openecomp.sdc.tosca.datatypes.model.PropertyType; +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.tosca.datatypes.model.TopologyTemplate; +import org.openecomp.sdc.tosca.services.DataModelUtil; +import org.openecomp.sdc.tosca.services.ToscaAnalyzerService; +import org.openecomp.sdc.tosca.services.ToscaConstants; +import org.openecomp.sdc.tosca.services.ToscaUtil; +import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl; +import org.openecomp.sdc.translator.services.heattotosca.Constants; +import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +/** + * The type Manual vsp tosca generator. + */ +public class ManualVspToscaGenerationService { + + //Map of the abstract node template id and substitution node type + private Map abstractSubstitutionIdTypes = new HashMap<>(); + //Map of service template name and service template for the generated service templates + private Map generatedServiceTemplates = new HashMap<>(); + + + /** + * Create manual vsp tosca service model tosca service model. + * + * @param vspModelInfo the vsp model info + * @return the tosca service model + */ + public ToscaServiceModel createManualVspToscaServiceModel(VspModelInfo vspModelInfo) { + ToscaServiceModel toscaServiceModel = new ToscaServiceModel(); + ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl(); + Map serviceTemplates = new HashMap<>(GlobalTypesGenerator + .getGlobalTypesServiceTemplate()); + toscaServiceModel.setServiceTemplates(serviceTemplates); + toscaServiceModel.setEntryDefinitionServiceTemplate(Constants.MAIN_TEMPLATE_NAME + + TOSCA_SERVICE_TEMPLATE_FILE_NAME_SUFFIX); + createToscaFromVspData(vspModelInfo, toscaServiceModel); + for (Map.Entry serviceTemplateEntry : + generatedServiceTemplates.entrySet()) { + ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates, serviceTemplateEntry + .getValue()); + } + return toscaServiceModel; + } + + private void createToscaFromVspData(VspModelInfo vspModelInfo, + ToscaServiceModel toscaServiceModel) { + List serviceTemplates = new ArrayList<>(); + //Only one component supported + Optional componentName = getComponentNameFromVspModel(vspModelInfo); + if (componentName.isPresent()) { + //Create main service template + ServiceTemplate mainServiceTemplate = createMainServiceTemplate(vspModelInfo); + generatedServiceTemplates.put(Constants.MAIN_TEMPLATE_NAME, mainServiceTemplate); + //Create substitution service template + for (Map.Entry entry : abstractSubstitutionIdTypes.entrySet()) { + ServiceTemplate substitutionServiceTemplate = + createSubstitutionServiceTemplate(componentName.get(), entry.getValue(), vspModelInfo, + toscaServiceModel); + generatedServiceTemplates.put(componentName.get(), substitutionServiceTemplate); + } + } + + } + + private Optional getComponentNameFromVspModel(VspModelInfo vspModelInfo) { + String componentName = null; + if (MapUtils.isNotEmpty(vspModelInfo.getComponents())) { + //supported for single component only + componentName = vspModelInfo.getComponents().entrySet().iterator().next().getValue(); + } + return Optional.ofNullable(componentName); + } + + private ServiceTemplate createMainServiceTemplate(VspModelInfo vspModelInfo) { + ServiceTemplate mainServiceTemplate = createInitMainServiceTemplate(vspModelInfo + .getReleaseVendor()); + Map components = vspModelInfo.getComponents(); + if (MapUtils.isNotEmpty(components)) { + //Currently since only one component is supported we can fetch the component in this manner. + // May be need to revisited for supporting multiple components + String componentId = components.entrySet().iterator().next().getKey(); + createVnfConfigurationNodeTemplate(mainServiceTemplate, vspModelInfo); + createComponentNodeTemplate(mainServiceTemplate, vspModelInfo, componentId); + createVnfNodeTemplate(mainServiceTemplate, vspModelInfo); + } + return mainServiceTemplate; + } + + private void createVnfConfigurationNodeTemplate(ServiceTemplate mainServiceTemplate, + VspModelInfo vspModelInfo) { + Optional componentName = getComponentNameFromVspModel(vspModelInfo); + if (componentName.isPresent()) { + NodeTemplate vnfConfigurationNodeTemplate = new NodeTemplate(); + vnfConfigurationNodeTemplate.setType(ToscaNodeType.VNF_CONFIG_NODE_TYPE); + if (Objects.nonNull(vspModelInfo.getAllowedFlavors())) { + Map properties = new LinkedHashMap<>(); + properties.put(ALLOWED_FLAVORS_PROPERTY, vspModelInfo.getAllowedFlavors()); + vnfConfigurationNodeTemplate.setProperties(properties); + } + String nodeTemplateId = componentName.get() + VNF_CONFIG_NODE_TEMPLATE_ID_SUFFIX; + DataModelUtil.addNodeTemplate(mainServiceTemplate, nodeTemplateId, + vnfConfigurationNodeTemplate); + } + } + + private void createComponentNodeTemplate(ServiceTemplate mainServiceTemplate, + VspModelInfo vspModelInfo, + String componentId) { + Optional componentName = getComponentNameFromVspModel(vspModelInfo); + if (componentName.isPresent()) { + NodeTemplate vfcNodeTemplate = new NodeTemplate(); + vfcNodeTemplate.setType(ToscaNodeType.MULTIFLAVOR_VFC_NODE_TYPE); + Map properties = new LinkedHashMap<>(); + if (MapUtils.isNotEmpty(vspModelInfo.getMultiFlavorVfcImages())) { + List componentImages = + vspModelInfo.getMultiFlavorVfcImages().get(componentId); + Map vfcImages = new HashMap<>(); + for (MultiFlavorVfcImage image : componentImages) { + vfcImages.put(image.getSoftware_version(), image); + } + properties.put(IMAGES_PROPERTY, vfcImages); + vfcNodeTemplate.setProperties(properties); + } + String nodeTemplateId = componentName.get() + VFC_NODE_TEMPLATE_ID_SUFFIX; + DataModelUtil.addNodeTemplate(mainServiceTemplate, nodeTemplateId, + vfcNodeTemplate); + } + } + + private void createVnfNodeTemplate(ServiceTemplate mainServiceTemplate, + VspModelInfo vspModelInfo) { + Optional componentName = getComponentNameFromVspModel(vspModelInfo); + if (componentName.isPresent()) { + NodeTemplate vnfNodeTemplate = new NodeTemplate(); + String vnfNodeTemplateType = + ToscaNodeType.MULTIDEPLOYMENTFLAVOR_NODE_TYPE + "." + componentName.get(); + vnfNodeTemplate.setType(vnfNodeTemplateType); + List directiveList = new ArrayList<>(); + directiveList.add(ToscaConstants.NODE_TEMPLATE_DIRECTIVE_SUBSTITUTABLE); + vnfNodeTemplate.setDirectives(directiveList); + vnfNodeTemplate.setProperties(new LinkedHashMap<>()); + DataModelUtil + .addSubstitutionFilteringProperty(getSubstitutionServiceTemplateFileName(componentName + .get()), vnfNodeTemplate, 1); + //Enable below if we need "abstract_" as prefix like we have in Unified model + //String nodeTemplateId = + // Constants.ABSTRACT_NODE_TEMPLATE_ID_PREFIX + componentName + "VNF_NODE_TEMPLATE_ID_SUFFIX"; + String nodeTemplateId = componentName.get() + VNF_NODE_TEMPLATE_ID_SUFFIX; + DataModelUtil.addNodeTemplate(mainServiceTemplate, nodeTemplateId, + vnfNodeTemplate); + abstractSubstitutionIdTypes.put(componentName.get(), vnfNodeTemplateType); + } + } + + private String getSubstitutionServiceTemplateFileName(String componentName) { + return componentName + TOSCA_SERVICE_TEMPLATE_FILE_NAME_SUFFIX; + } + + private String getNodeTemplateId(String componentName, String idPrefix, String idSuffix) { + StringBuilder builder = new StringBuilder(); + //builder.append(idPrefix); + builder.append(componentName); + builder.append(idSuffix); + return builder.toString(); + } + + private ServiceTemplate createInitMainServiceTemplate(String releaseVendor) { + ServiceTemplate mainServiceTemplate = new ServiceTemplate(); + Map templateMetadata = new HashMap<>(); + templateMetadata.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, Constants.MAIN_TEMPLATE_NAME); + if (Objects.nonNull(releaseVendor)) { + templateMetadata.put(RELEASE_VENDOR, releaseVendor); + } + mainServiceTemplate.setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION); + mainServiceTemplate.setMetadata(templateMetadata); + mainServiceTemplate.setTopology_template(new TopologyTemplate()); + mainServiceTemplate.setImports(getImports()); + return mainServiceTemplate; + } + + private List> getImports() { + Map globalSubstitutionTypeImportMap = new HashMap<>(); + Import globalSubstitutionTypeImport = new Import(); + globalSubstitutionTypeImport.setFile(ToscaUtil.getServiceTemplateFileName(Constants + .GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME)); + globalSubstitutionTypeImportMap.put(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME, + globalSubstitutionTypeImport); + Map globalImports = new HashMap<>(); + List> manualVspGlobalTypesImportList = GlobalTypesGenerator + .getManualVspGlobalTypesImportList(); + manualVspGlobalTypesImportList.add(globalSubstitutionTypeImportMap); + return manualVspGlobalTypesImportList; + } + + private ServiceTemplate createSubstitutionServiceTemplate(String serviceTemplateName, + String substitutionNodeTypeId, + VspModelInfo vspModelInfo, + ToscaServiceModel toscaServiceModel) { + ServiceTemplate substitutionServiceTemplate = + createInitSubstitutionServiceTemplate(serviceTemplateName); + createSubstitutionServiceTemplateComponents(substitutionServiceTemplate, vspModelInfo, + toscaServiceModel); + createSubstitutionServiceTemplateNics(substitutionServiceTemplate, vspModelInfo, + toscaServiceModel); + handleSubstitutionMapping(substitutionServiceTemplate, toscaServiceModel, + substitutionNodeTypeId, serviceTemplateName); + return substitutionServiceTemplate; + } + + private void createSubstitutionServiceTemplateComponents(ServiceTemplate + substitutionServiceTemplate, + VspModelInfo vspModelInfo, + ToscaServiceModel toscaServiceModel) { + Map components = vspModelInfo.getComponents(); + if (MapUtils.isNotEmpty(components)) { + for (String componentId : components.keySet()) { + String componentName = components.get(componentId); + String localNodeTypeId = + createComponentDefinitionNodeTemplate(substitutionServiceTemplate, componentName); + createLocalNodeType(substitutionServiceTemplate, localNodeTypeId); + } + } + } + + private void createSubstitutionServiceTemplateNics(ServiceTemplate substitutionServiceTemplate, + VspModelInfo vspModelInfo, + ToscaServiceModel toscaServiceModel) { + Map> nics = vspModelInfo.getNics(); + if (MapUtils.isNotEmpty(nics)) { + for (Map.Entry> entry : nics.entrySet()) { + String componentId = entry.getKey(); + String componentNodeTemplateId = getSubstitutionComponentNodeTemplateId( + vspModelInfo.getComponents().get(componentId)); + List nicList = entry.getValue(); + if (CollectionUtils.isNotEmpty(nicList)) { + for (Nic nic : nicList) { + NodeTemplate nicNodeTemplate = new NodeTemplate(); + nicNodeTemplate.setType(ToscaNodeType.NETWORK_PORT); + DataModelUtil.addBindingReqFromPortToCompute(componentNodeTemplateId, nicNodeTemplate); + DataModelUtil.addNodeTemplate(substitutionServiceTemplate, + getNicNodeTemplateId(nic.getName()), nicNodeTemplate); + } + } + } + } + } + + private String getSubstitutionComponentNodeTemplateId(String componentName) { + //TODO: Confirm if anything else is needed here + return componentName; + } + + private String getNicNodeTemplateId(String nicName) { + StringBuilder builder = new StringBuilder(); + builder.append(nicName); + builder.append(PORT_NODE_TEMPLATE_ID_SUFFIX); + return builder.toString(); + } + + private String createComponentDefinitionNodeTemplate(ServiceTemplate substitutionServiceTemplate, + String componentName) { + NodeTemplate nodeTemplate = new NodeTemplate(); + String localNodeTypeId = getLocalNodeTypeId(componentName); + nodeTemplate.setType(localNodeTypeId); + DataModelUtil.addNodeTemplate(substitutionServiceTemplate, componentName, nodeTemplate); + return localNodeTypeId; + } + + private void createLocalNodeType(ServiceTemplate substitutionServiceTemplate, + String localNodeTypeId) { + NodeType localNodeType = new NodeType(); + localNodeType.setDerived_from(ToscaNodeType.COMPUTE); + DataModelUtil.addNodeType(substitutionServiceTemplate, localNodeTypeId, localNodeType ); + } + + private String getLocalNodeTypeId(String componentName) { + return ToscaNodeType.VFC_NODE_TYPE_PREFIX + componentName; + } + + private ServiceTemplate createInitSubstitutionServiceTemplate(String serviceTemplateName) { + ServiceTemplate substitutionServiceTemplate = new ServiceTemplate(); + Map templateMetadata = new HashMap<>(); + substitutionServiceTemplate.setTosca_definitions_version(ToscaConstants + .TOSCA_DEFINITIONS_VERSION); + templateMetadata.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, serviceTemplateName); + substitutionServiceTemplate.setMetadata(templateMetadata); + substitutionServiceTemplate.setTopology_template(new TopologyTemplate()); + substitutionServiceTemplate.setImports(getImports()); + return substitutionServiceTemplate; + } + + private void handleSubstitutionMapping(ServiceTemplate substitutionServiceTemplate, + ToscaServiceModel toscaServiceModel, + String substitutionNodeTypeId, + String componentName) { + ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl(); + ServiceTemplate globalSubstitutionServiceTemplate = fetchGlobalSubstitutionServiceTemplate(); + NodeType substitutionNodeType = + createGlobalSubstitutionNodeType(substitutionServiceTemplate, componentName); + DataModelUtil.addNodeType(globalSubstitutionServiceTemplate, substitutionNodeTypeId, + substitutionNodeType); + + Map>> substitutionMapping = + GeneratorUtils.getSubstitutionNodeTypeExposedConnectionPoints(substitutionNodeType, + substitutionServiceTemplate, toscaServiceModel); + if (Objects.nonNull(substitutionMapping)) { + //add substitution mapping after capability and requirement expose calculation + substitutionServiceTemplate.getTopology_template().setSubstitution_mappings( + DataModelUtil.createSubstitutionTemplateSubMapping(substitutionNodeTypeId, + substitutionNodeType, substitutionMapping)); + } + } + + //*************** CREATE GLOBAL SUBSTITUTION SERVICE TEMPLATE ********************** + + private ServiceTemplate createGlobalSubstitutionServiceTemplate(ServiceTemplate + substitutionServiceTemplate, + String componentName) { + ServiceTemplate globalSubstitutionServiceTemplate = fetchGlobalSubstitutionServiceTemplate(); + NodeType substitutionNodeType = + createGlobalSubstitutionNodeType(substitutionServiceTemplate, componentName); + String substitutionNodeTypeId = getSubstitutionNodeTypeId(componentName); + DataModelUtil.addNodeType(globalSubstitutionServiceTemplate, substitutionNodeTypeId, + substitutionNodeType); + return globalSubstitutionServiceTemplate; + } + + private ServiceTemplate createInitGlobalSubstitutionServiceTemplate() { + ServiceTemplate globalSubstitutionServiceTemplate = new ServiceTemplate(); + Map templateMetadata = new HashMap<>(); + globalSubstitutionServiceTemplate.setTosca_definitions_version(ToscaConstants + .TOSCA_DEFINITIONS_VERSION); + templateMetadata.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, + Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME); + globalSubstitutionServiceTemplate.setMetadata(templateMetadata); + globalSubstitutionServiceTemplate.setImports(getImports()); + return globalSubstitutionServiceTemplate; + } + + private NodeType createGlobalSubstitutionNodeType(ServiceTemplate substitutionServiceTemplate, + String componentName) { + NodeType substitutionNodeType = new ToscaAnalyzerServiceImpl() + .createInitSubstitutionNodeType(substitutionServiceTemplate, + ToscaNodeType.VFC_ABSTRACT_SUBSTITUTE); + substitutionNodeType.setProperties( + getManualVspSubstitutionNodeTypeProperties(substitutionNodeType, componentName)); + return substitutionNodeType; + } + + private Map getManualVspSubstitutionNodeTypeProperties( + NodeType substitutionNodeType, String componentName) { + //Create num_cpus property + PropertyDefinition numCpus = new PropertyDefinition(); + numCpus.setType(PropertyType.INTEGER.getDisplayName()); + numCpus.setDescription(NUM_CPUS_PROP_DESC_PREFIX + componentName); + numCpus.setRequired(true); + //Create disk_size property + PropertyDefinition diskSize = new PropertyDefinition(); + diskSize.setType(PropertyType.SCALAR_UNIT_SIZE.getDisplayName()); + diskSize.setDescription(DISK_SIZE_PROP_DESC_PREFIX + componentName); + diskSize.setRequired(true); + //Create mem_size property + PropertyDefinition memSize = new PropertyDefinition(); + memSize.setType(PropertyType.SCALAR_UNIT_SIZE.getDisplayName()); + memSize.setDescription(MEM_SIZE_PROP_DESC_PREFIX + componentName); + memSize.setRequired(true); + + Map manualVspProperties = new LinkedHashMap<>(); + manualVspProperties.put(NUM_CPUS, numCpus); + manualVspProperties.put(DISK_SIZE, diskSize); + manualVspProperties.put(MEM_SIZE, memSize); + + return manualVspProperties; + } + + private String getSubstitutionNodeTypeId(String componentName) { + return ToscaNodeType.MULTIDEPLOYMENTFLAVOR_NODE_TYPE + "." + componentName; + } + + /** + * Fetch global substitution service template service template. + * + * @return the global substitution service template + */ + private ServiceTemplate fetchGlobalSubstitutionServiceTemplate() { + ServiceTemplate globalSubstitutionServiceTemplate = + generatedServiceTemplates.get(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME); + if (Objects.isNull(globalSubstitutionServiceTemplate)) { + globalSubstitutionServiceTemplate = createInitGlobalSubstitutionServiceTemplate(); + generatedServiceTemplates.put(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME, + globalSubstitutionServiceTemplate); + } + return globalSubstitutionServiceTemplate; + } +} \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/src/main/java/org/openecomp/sdc/generator/core/utils/GeneratorUtils.java b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/src/main/java/org/openecomp/sdc/generator/core/utils/GeneratorUtils.java new file mode 100644 index 0000000000..c13997b47c --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/src/main/java/org/openecomp/sdc/generator/core/utils/GeneratorUtils.java @@ -0,0 +1,244 @@ +package org.openecomp.sdc.generator.core.utils; + +import static org.openecomp.sdc.tosca.services.DataModelUtil.addSubstitutionNodeTypeRequirements; + +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage; +import org.openecomp.sdc.logging.types.LoggerConstants; +import org.openecomp.sdc.logging.types.LoggerErrorCode; +import org.openecomp.sdc.logging.types.LoggerTragetServiceName; +import org.openecomp.sdc.tosca.datatypes.ToscaElementTypes; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition; +import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; +import org.openecomp.sdc.tosca.datatypes.model.NodeType; +import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment; +import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition; +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.tosca.services.DataModelUtil; +import org.openecomp.sdc.tosca.services.ToscaAnalyzerService; +import org.openecomp.sdc.tosca.services.ToscaUtil; +import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl; +import org.openecomp.sdc.tosca.services.ToscaExtensionYamlUtil; +import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** + * The type Generator utils. + */ +public class GeneratorUtils { + + public static List supportedCapabilities = new ArrayList<>(); + public static List supportedRequirements = new ArrayList<>(); + protected static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + + static { + //TODO : Read from configuration + supportedCapabilities.addAll(Arrays.asList("host", "os", "endpoint", "scalable")); + supportedRequirements.addAll(Arrays.asList("link")); + } + + + /** + * Add service template to tosca service model. + * + * @param toscaServiceModel the tosca service model + * @param serviceTemplate the service template + */ + public static void addServiceTemplateToToscaServiceModel(ToscaServiceModel toscaServiceModel, + ServiceTemplate serviceTemplate) { + + String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate); + Map serviceTemplates = toscaServiceModel.getServiceTemplates(); + if (!serviceTemplates.containsKey(serviceTemplateFileName)) { + ToscaUtil.addServiceTemplateToMapWithKeyFileName(serviceTemplates, serviceTemplate); + } + toscaServiceModel.setServiceTemplates(serviceTemplates); + } + + /** + * Gets substitution node type exposed connection points. + * + * @param substitutionNodeType the substitution node type + * @param substitutionServiceTemplate the substitution service template + * @param toscaServiceModel the tosca service model + * @return the substitution node type exposed connection points + */ + public static Map>> + getSubstitutionNodeTypeExposedConnectionPoints(NodeType substitutionNodeType, + ServiceTemplate substitutionServiceTemplate, + ToscaServiceModel toscaServiceModel) { + + Map nodeTemplates = + substitutionServiceTemplate.getTopology_template().getNode_templates(); + String nodeTemplateId; + NodeTemplate nodeTemplate; + String nodeType; + Map>> substitutionMapping = new HashMap<>(); + if (nodeTemplates == null) { + return substitutionMapping; + } + + try { + Map> capabilitySubstitutionMapping = new HashMap<>(); + Map> requirementSubstitutionMapping = new HashMap<>(); + substitutionMapping.put("capability", capabilitySubstitutionMapping); + substitutionMapping.put("requirement", requirementSubstitutionMapping); + List> nodeTypeRequirementsDefinition; + Map nodeTemplateRequirementsAssignment; + List> exposedRequirementsDefinition; + Map> fullFilledRequirementsDefinition = + new HashMap<>(); + Map nodeTypeCapabilitiesDefinition = new HashMap<>(); + Map exposedCapabilitiesDefinition; + + ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl(); + for (Map.Entry entry : nodeTemplates.entrySet()) { + nodeTemplateId = entry.getKey(); + nodeTemplate = entry.getValue(); + nodeType = nodeTemplate.getType(); + NodeType flatNodeType = (NodeType) toscaAnalyzerService + .getFlatEntity(ToscaElementTypes.NODE_TYPE, nodeType, substitutionServiceTemplate, + toscaServiceModel); + // get requirements + nodeTypeRequirementsDefinition = + getNodeTypeRequirements(flatNodeType, nodeTemplateId, substitutionServiceTemplate, + requirementSubstitutionMapping); + nodeTemplateRequirementsAssignment = + DataModelUtil.getNodeTemplateRequirements(nodeTemplate); + fullFilledRequirementsDefinition.put(nodeTemplateId, nodeTemplateRequirementsAssignment); + //set substitution node type requirements + exposedRequirementsDefinition = + toscaAnalyzerService.calculateExposedRequirements(nodeTypeRequirementsDefinition, + nodeTemplateRequirementsAssignment); + + + //Filter unsupported requirements + Iterator> iterator = + exposedRequirementsDefinition.iterator(); + while (iterator.hasNext()) { + Map requirementDefinitionMap = iterator.next(); + for (Map.Entry requirementDefinitionEntry : + requirementDefinitionMap.entrySet()) { + String requirementKey = requirementDefinitionEntry.getKey(); + if (!supportedRequirements.contains(requirementKey)) { + iterator.remove(); + } + } + } + addSubstitutionNodeTypeRequirements(substitutionNodeType, exposedRequirementsDefinition, + nodeTemplateId); + //get capabilities + addNodeTypeCapabilitiesToSubMapping(nodeTypeCapabilitiesDefinition, + capabilitySubstitutionMapping, nodeType, + nodeTemplateId, substitutionServiceTemplate, toscaServiceModel); + } + + exposedCapabilitiesDefinition = + toscaAnalyzerService.calculateExposedCapabilities(nodeTypeCapabilitiesDefinition, + fullFilledRequirementsDefinition); + + //Filter unsupported capabilities + Iterator> iterator = exposedCapabilitiesDefinition + .entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry capabilityDefinitionEntry = iterator.next(); + //Expected Capability is of the format _ + String capabilityKey = capabilityDefinitionEntry.getKey().split("_")[0]; + if (!supportedCapabilities.contains(capabilityKey)) { + iterator.remove(); + } + } + + DataModelUtil.addNodeTypeCapabilitiesDef(substitutionNodeType, exposedCapabilitiesDefinition); + } catch (Exception ex) { + MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API, + LoggerTragetServiceName.GENERATE_MANUAL_VSP_TOSCA, ErrorLevel.INFO.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), "Error occured in get node type exposed " + + "points"); + return null; + } + return substitutionMapping; + } + + /** + * Gets node type requirements. + * + * @param flatNodeType the flat node type + * @param templateName the template name + * @param serviceTemplate the service template + * @param requirementSubstitutionMapping the requirement substitution mapping + * @return the node type requirements + */ + public static List> getNodeTypeRequirements( + NodeType flatNodeType, + String templateName, + ServiceTemplate serviceTemplate, + Map> requirementSubstitutionMapping) { + List> requirementList = new ArrayList<>(); + List requirementMapping; + if (flatNodeType.getRequirements() != null) { + for (Map requirementMap : flatNodeType.getRequirements()) { + for (Map.Entry requirementNodeEntry : requirementMap + .entrySet()) { + ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); + RequirementDefinition requirementNodeEntryValue = toscaExtensionYamlUtil + .yamlToObject(toscaExtensionYamlUtil.objectToYaml(requirementNodeEntry.getValue()), + RequirementDefinition.class); + if (requirementNodeEntryValue.getOccurrences() == null) { + requirementNodeEntryValue.setOccurrences(new Object[]{1, 1}); + } + Map requirementDef = new HashMap<>(); + requirementDef.put(requirementNodeEntry.getKey(), requirementNodeEntryValue); + DataModelUtil.addRequirementToList(requirementList, requirementDef); + requirementMapping = new ArrayList<>(); + requirementMapping.add(templateName); + requirementMapping.add(requirementNodeEntry.getKey()); + requirementSubstitutionMapping + .put(requirementNodeEntry.getKey() + "_" + templateName, requirementMapping); + if (requirementNodeEntryValue.getNode() == null) { + requirementNodeEntryValue.setOccurrences(new Object[]{1, 1}); + } + } + } + } + return requirementList; + } + + private static void addNodeTypeCapabilitiesToSubMapping( + Map nodeTypeCapabilitiesDefinition, + Map> capabilitySubstitutionMapping, String type, String templateName, + ServiceTemplate substitutionServiceTemplate, ToscaServiceModel toscaServiceModel) { + mdcDataDebugMessage.debugEntryMessage(null, null); + + ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl(); + NodeType flatNodeType = (NodeType) toscaAnalyzerService + .getFlatEntity(ToscaElementTypes.NODE_TYPE, type, substitutionServiceTemplate, + toscaServiceModel); + String capabilityKey; + List capabilityMapping; + if (flatNodeType.getCapabilities() != null) { + for (Map.Entry capabilityNodeEntry : flatNodeType + .getCapabilities() + .entrySet()) { + capabilityKey = capabilityNodeEntry.getKey() + "_" + templateName; + nodeTypeCapabilitiesDefinition.put(capabilityKey, capabilityNodeEntry.getValue().clone()); + capabilityMapping = new ArrayList<>(); + capabilityMapping.add(templateName); + capabilityMapping.add(capabilityNodeEntry.getKey()); + capabilitySubstitutionMapping.put(capabilityKey, capabilityMapping); + } + } + mdcDataDebugMessage.debugExitMessage(null, null); + } + +} diff --git a/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/src/main/resources/config-manualVspToscaGenerator.json b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/src/main/resources/config-manualVspToscaGenerator.json new file mode 100644 index 0000000000..b7d49cf9be --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/src/main/resources/config-manualVspToscaGenerator.json @@ -0,0 +1,5 @@ +{ + "_config": { + "namespace": "manualVspToscaGenerator" + } +} diff --git a/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/pom.xml b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/pom.xml new file mode 100644 index 0000000000..4cf38c64da --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-tosca-generator-lib/pom.xml @@ -0,0 +1,22 @@ + + 4.0.0 + openecomp-sdc-tosca-generator-lib + openecomp-sdc-tosca-generator-lib + + pom + + openecomp-sdc-lib + org.openecomp.sdc + 1.1.0-SNAPSHOT + + + + openecomp-sdc-tosca-generator-api + openecomp-sdc-tosca-generator-core + + + + + \ No newline at end of file -- cgit 1.2.3-korg