diff options
author | dermot123 <dermot.melia@est.tech> | 2019-04-08 16:31:20 +0000 |
---|---|---|
committer | Oren Kleks <orenkle@amdocs.com> | 2019-04-10 06:46:55 +0000 |
commit | d9c0322b76c48e5f78158cb1a44da7aac9beb2a2 (patch) | |
tree | 2eb1428d007e0840c9ca406ecc8874787c14855a | |
parent | 18750938b1513ee32d4d68f0871ec90efdf3ddfd (diff) |
Supporting PNFD (SOL001) mapping to Internal AID model
This maps the PNF descriptor containing etsi defined types
according to SOL001 v2.5.1 to openecomp internal model. The
transformation is done in the "Create VSP" stage. As the main
PNF type gets mapped to the outer container in internal ecomp
model, it is possible to have no "resource instances" when
importing the PNF model into the catalog. The code was updated
to allow this for PNFs.
Change-Id: I961e91746ca638d858dd468e6c82aeb57993f7a3
Issue-ID: SDC-1976
Issue-ID: SDC-2160
Signed-off-by: dermot123 <dermot.melia@est.tech>
27 files changed, 1074 insertions, 366 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java index 48152ea166..e9b5baa49e 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java @@ -112,11 +112,7 @@ public class YamlTemplateParsingHandler { .left() .on(err -> failIfNoNodeTemplates(yamlName)); - Map<String, UploadComponentInstanceInfo> componentInstances = getInstances(toscaJson, createdNodesToscaResourceNames, nodeTemlates); - if (MapUtils.isEmpty(componentInstances)) { - failIfNotTopologyTemplate(yamlName); - } - return componentInstances; + return getInstances(toscaJson, createdNodesToscaResourceNames, nodeTemlates); } private Map<String, UploadComponentInstanceInfo> getInstances(Map<String, Object> toscaJson, Map<String, String> createdNodesToscaResourceNames, Map<String, Object> nodeTemlates) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java index 7ed18d727e..92d26a4eb8 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java @@ -60,13 +60,48 @@ import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.impl.WebAppContextWrapper; import org.openecomp.sdc.be.info.NodeTypeInfoToUpdateArtifacts; -import org.openecomp.sdc.be.model.*; +import org.openecomp.sdc.be.model.ArtifactDefinition; +import org.openecomp.sdc.be.model.CapabilityDefinition; +import org.openecomp.sdc.be.model.CapabilityRequirementRelationship; +import org.openecomp.sdc.be.model.CapabilityTypeDefinition; +import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.ComponentInstance; +import org.openecomp.sdc.be.model.ComponentInstanceInput; +import org.openecomp.sdc.be.model.ComponentInstanceProperty; +import org.openecomp.sdc.be.model.ComponentParametersView; +import org.openecomp.sdc.be.model.DataTypeDefinition; +import org.openecomp.sdc.be.model.GroupDefinition; +import org.openecomp.sdc.be.model.InputDefinition; +import org.openecomp.sdc.be.model.InterfaceDefinition; +import org.openecomp.sdc.be.model.LifeCycleTransitionEnum; +import org.openecomp.sdc.be.model.LifecycleStateEnum; +import org.openecomp.sdc.be.model.NodeTypeInfo; +import org.openecomp.sdc.be.model.Operation; +import org.openecomp.sdc.be.model.ParsedToscaYamlInfo; +import org.openecomp.sdc.be.model.PropertyDefinition; +import org.openecomp.sdc.be.model.RelationshipImpl; +import org.openecomp.sdc.be.model.RelationshipInfo; +import org.openecomp.sdc.be.model.RequirementCapabilityRelDef; +import org.openecomp.sdc.be.model.RequirementDefinition; +import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.UploadCapInfo; +import org.openecomp.sdc.be.model.UploadComponentInstanceInfo; +import org.openecomp.sdc.be.model.UploadInfo; +import org.openecomp.sdc.be.model.UploadNodeFilterInfo; +import org.openecomp.sdc.be.model.UploadPropInfo; +import org.openecomp.sdc.be.model.UploadReqInfo; +import org.openecomp.sdc.be.model.UploadResourceInfo; +import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache; import org.openecomp.sdc.be.model.category.CategoryDefinition; import org.openecomp.sdc.be.model.category.SubCategoryDefinition; import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter; import org.openecomp.sdc.be.model.operations.StorageException; -import org.openecomp.sdc.be.model.operations.api.*; +import org.openecomp.sdc.be.model.operations.api.ICacheMangerOperation; +import org.openecomp.sdc.be.model.operations.api.ICapabilityTypeOperation; +import org.openecomp.sdc.be.model.operations.api.IElementOperation; +import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation; +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter; import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils; @@ -95,12 +130,25 @@ import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; import javax.servlet.ServletContext; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; +import java.util.Set; import java.util.function.Function; import java.util.regex.Pattern; -import static java.util.stream.Collectors.*; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toMap; +import static java.util.stream.Collectors.toSet; import static org.apache.commons.collections.CollectionUtils.isNotEmpty; import static org.apache.commons.collections.MapUtils.isEmpty; import static org.apache.commons.collections.MapUtils.isNotEmpty; @@ -477,6 +525,9 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { try { uploadComponentInstanceInfoMap = csarBusinessLogic.getParsedToscaYamlInfo(yamlFileContent, yamlFileName, nodeTypesInfo, csarInfo, nodeName); Map<String, UploadComponentInstanceInfo> instances = uploadComponentInstanceInfoMap.getInstances(); + if (MapUtils.isEmpty(instances) && newRresource.getResourceType() != ResourceTypeEnum.PNF) { + throw new ComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlFileName); + } preparedResource = updateExistingResourceByImport(newRresource, oldRresource, csarInfo.getModifier(), inTransaction, shouldLock, isNested).left; log.trace("YAML topology file found in CSAR, file name: {}, contents: {}", yamlFileName, yamlFileContent); @@ -917,6 +968,9 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Resource createdResource; try{ ParsedToscaYamlInfo parsedToscaYamlInfo = csarBusinessLogic.getParsedToscaYamlInfo(topologyTemplateYaml, yamlName, nodeTypesInfo, csarInfo, nodeName); + if (MapUtils.isEmpty(parsedToscaYamlInfo.getInstances()) && resource.getResourceType() != ResourceTypeEnum.PNF) { + throw new ComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName); + } log.debug("#createResourceFromYaml - Going to create resource {} and RIs ", resource.getName()); createdResource = createResourceAndRIsFromYaml(yamlName, resource, parsedToscaYamlInfo, AuditingActionEnum.IMPORT_RESOURCE, false, createdArtifacts, topologyTemplateYaml, @@ -2091,9 +2145,10 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Map<String, UploadComponentInstanceInfo> uploadResInstancesMap) { log.debug("#createResourceInstancesRelations - Going to create relations "); List<ComponentInstance> componentInstancesList = resource.getComponentInstances(); - if (isEmpty(uploadResInstancesMap) || CollectionUtils.isEmpty(componentInstancesList)) { + if (((isEmpty(uploadResInstancesMap) || CollectionUtils.isEmpty(componentInstancesList)) && + resource.getResourceType() != ResourceTypeEnum.PNF)) { // PNF can have no resource instances log.debug("#createResourceInstancesRelations - No instances found in the resource {} is empty, yaml template file name {}, ", resource.getUniqueId(), yamlName); - BeEcompErrorManager.getInstance().logInternalDataError("createResourceInstancesRelations","No instances found in a resource or nn yaml template. ", ErrorSeverity.ERROR); + BeEcompErrorManager.getInstance().logInternalDataError("createResourceInstancesRelations", "No instances found in a resource or nn yaml template. ", ErrorSeverity.ERROR); throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName)); } Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>(); @@ -2969,7 +3024,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Either<Resource, ResponseFormat> eitherResource = null; log.debug("createResourceInstances is {} - going to create resource instanse from CSAR", yamlName); - if (isEmpty(uploadResInstancesMap)) { + if (isEmpty(uploadResInstancesMap) && resource.getResourceType() != ResourceTypeEnum.PNF) { // PNF can have no resource instances ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE); throw new ComponentException(responseFormat); } @@ -3002,7 +3057,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), resource); throw new ComponentException(responseFormat); } - if (CollectionUtils.isEmpty(eitherGetResource.left().value().getComponentInstances())) { + if (CollectionUtils.isEmpty(eitherGetResource.left().value().getComponentInstances()) && + resource.getResourceType() != ResourceTypeEnum.PNF) { // PNF can have no resource instances log.debug("Error when create resource instance from csar. ComponentInstances list empty"); BeEcompErrorManager.getInstance().logBeDaoSystemError( "Error when create resource instance from csar. ComponentInstances list empty"); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java index 49ec30eed7..59d0793eac 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java @@ -16,36 +16,6 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; -import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_PNF_METADATA; -import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_MANIFEST; -import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ORIG_PATH_FILE_NAME; -import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME; -import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder.candidateDataNotProcessedOrAbortedErrorBuilder; -import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder.invalidProcessedCandidate; -import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder.vspMissingDeploymentFlavorErrorBuilder; -import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_MF_FILE_NAME; - -import java.io.BufferedOutputStream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.zip.ZipInputStream; -import java.util.zip.ZipOutputStream; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.tuple.ImmutablePair; @@ -63,16 +33,13 @@ import org.openecomp.core.utilities.json.JsonUtil; import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.core.validation.api.ValidationManager; import org.openecomp.core.validation.util.MessageContainerUtil; -import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCode; import org.openecomp.sdc.common.errors.ValidationErrorBuilder; import org.openecomp.sdc.common.utils.CommonUtil; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.datatypes.error.ErrorMessage; -import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata; -import org.openecomp.sdc.tosca.csar.ToscaMetadata; -import org.openecomp.sdc.tosca.csar.SOL004ManifestOnboarding; +import org.openecomp.sdc.tosca.csar.Manifest; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.tosca.services.impl.ToscaFileOutputServiceCsarImpl; import org.openecomp.sdc.validation.util.ValidationManagerUtil; @@ -116,10 +83,9 @@ import org.openecomp.sdc.vendorsoftwareproduct.errors.PackageInvalidErrorBuilder import org.openecomp.sdc.vendorsoftwareproduct.errors.PackageNotFoundErrorBuilder; import org.openecomp.sdc.vendorsoftwareproduct.errors.TranslationFileCreationErrorBuilder; import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder; -import org.openecomp.sdc.tosca.csar.Manifest; import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator; -import org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi.ETSIService; import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi.ETSIService; import org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi.ETSIServiceImpl; import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator; import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse; @@ -142,6 +108,31 @@ import org.openecomp.sdc.versioning.VersioningManagerFactory; import org.openecomp.sdc.versioning.VersioningUtil; import org.openecomp.sdc.versioning.dao.types.Version; +import java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; + +import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder.candidateDataNotProcessedOrAbortedErrorBuilder; +import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder.invalidProcessedCandidate; +import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductInvalidErrorBuilder.vspMissingDeploymentFlavorErrorBuilder; + public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductManager { private VspMergeDao vspMergeDao; @@ -634,15 +625,11 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa .createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion, vspDetails.getFeatureGroups()); ETSIService etsiService = new ETSIServiceImpl(); - if(etsiService.isSol004WithToscaMetaDirectory(toscaServiceModel.getArtifactFiles())){ + if (etsiService.isSol004WithToscaMetaDirectory(toscaServiceModel.getArtifactFiles())) { FileContentHandler handler = toscaServiceModel.getArtifactFiles(); - try(InputStream manifestInputStream = getManifest(handler)) { - Manifest onboardingManifest = new SOL004ManifestOnboarding(); - onboardingManifest.parse(manifestInputStream); - etsiService.moveNonManoFileToArtifactFolder(handler, onboardingManifest); - //VSP PNF resource type is supported only for sol004 csar for now, default VSP resource type is VF - packageInfo.setResourceType(getResourceType(onboardingManifest)); - } + Manifest manifest = etsiService.getManifest(handler); + etsiService.moveNonManoFileToArtifactFolder(handler, manifest); + packageInfo.setResourceType(etsiService.getResourceType(manifest).name()); } packageInfo.setTranslatedFile(ByteBuffer.wrap( toscaServiceTemplateServiceCsar.createOutputFile(toscaServiceModel, licenseArtifacts))); @@ -651,49 +638,6 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa return packageInfo; } - private String getResourceType(Manifest onboardingManifest) { - //Valid manifest should contain whether vnf or pnf related metadata data exclusively in SOL004 standard, - // validation of manifest done during package upload stage - if(onboardingManifest != null && !onboardingManifest.getMetadata().isEmpty() - && MANIFEST_PNF_METADATA.stream().anyMatch(e -> onboardingManifest.getMetadata().containsKey(e))){ - return ResourceTypeEnum.PNF.name(); - } - //VNF is default resource type - return ResourceTypeEnum.VF.name(); - } - - private InputStream getManifest(FileContentHandler handler) throws IOException { - ToscaMetadata metadata = getMetadata(handler); - return getManifestInputStream(handler, metadata.getMetaEntries().get(TOSCA_META_ETSI_ENTRY_MANIFEST)); - } - - private ToscaMetadata getMetadata(FileContentHandler handler) throws IOException { - ToscaMetadata metadata; - if(handler.containsFile(TOSCA_META_PATH_FILE_NAME)){ - metadata = OnboardingToscaMetadata.parseToscaMetadataFile(handler.getFileContent(TOSCA_META_PATH_FILE_NAME)); - - }else if(handler.containsFile(TOSCA_META_ORIG_PATH_FILE_NAME)){ - metadata = OnboardingToscaMetadata.parseToscaMetadataFile(handler.getFileContent(TOSCA_META_ORIG_PATH_FILE_NAME)); - }else { - throw new IOException("TOSCA.meta file not found!"); - } - return metadata; - } - - private InputStream getManifestInputStream(FileContentHandler handler, String manifestLocation) throws IOException { - InputStream io; - if(manifestLocation == null || !handler.containsFile(manifestLocation)){ - io = handler.getFileContent(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME); - }else { - io = handler.getFileContent(manifestLocation); - } - - if(io == null){ - throw new IOException("Manifest file not found!"); - } - return io; - } - void populateVersionsForVlm(String vlmId, Version vlmVersion) { VersioningManager versioningManager = VersioningManagerFactory.getInstance().createInterface(); versioningManager.list(vlmId).stream() diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java index 665c63d64c..a86ce33e47 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java @@ -17,11 +17,14 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process; import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.impl.AbstractToscaSolConverter; import org.openecomp.core.impl.ToscaConverterImpl; -import org.openecomp.core.impl.ToscaSolConverterImpl; +import org.openecomp.core.impl.ToscaSolConverterPnf; +import org.openecomp.core.impl.ToscaSolConverterVnf; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.core.validation.util.MessageContainerUtil; +import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.utils.SdcCommon; import org.openecomp.sdc.datatypes.error.ErrorLevel; @@ -46,7 +49,12 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import java.io.ByteArrayInputStream; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; public class OrchestrationTemplateProcessCsarHandler implements OrchestrationTemplateProcessHandler { @@ -124,11 +132,12 @@ public class OrchestrationTemplateProcessCsarHandler implements OrchestrationTem ETSIService etsiService = new ETSIServiceImpl(); ToscaServiceModel toscaServiceModel; - if(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler)){ + if (etsiService.isSol004WithToscaMetaDirectory(fileContentHandler)) { fileContentHandler.addFile(SDC_ONBOARDED_PACKAGE_DIR + candidateData.getFileName() + - EXT_SEPARATOR + candidateData.getFileSuffix(), candidateData.getContentData().array()); - toscaServiceModel = new ToscaSolConverterImpl().convert(fileContentHandler); - }else{ + EXT_SEPARATOR + candidateData.getFileSuffix(), candidateData.getContentData().array()); + final ResourceTypeEnum resourceType = etsiService.getResourceType(fileContentHandler); + toscaServiceModel = instantiateToscaConverterFor(resourceType).convert(fileContentHandler); + } else { toscaServiceModel = new ToscaConverterImpl().convert(fileContentHandler); } orchestrationUtil.saveServiceModel(vspDetails.getId(), @@ -138,6 +147,14 @@ public class OrchestrationTemplateProcessCsarHandler implements OrchestrationTem .deleteOrchestrationTemplateCandidate(vspDetails.getId(), vspDetails.getVersion()); } + private AbstractToscaSolConverter instantiateToscaConverterFor(ResourceTypeEnum resourceType) { + if (resourceType == ResourceTypeEnum.PNF) { + return new ToscaSolConverterPnf(); + } + // default is VF + return new ToscaSolConverterVnf(); + } + private void addFiles(FileContentHandler fileContentHandler) { for (Map.Entry<String, byte[]> fileEntry : fileContentHandler.getFiles().entrySet()) { toscaTreeManager.addFile(fileEntry.getKey(), fileEntry.getValue()); diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricher.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricher.java index 658fc98725..a6bb9323ee 100644 --- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricher.java +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricher.java @@ -16,28 +16,6 @@ package org.openecomp.sdc.enrichment.impl.tosca; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.HIGH_AVAIL_MODE; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MANDATORY; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MAX_INSTANCES; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MIN_INSTANCES; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.NFC_FUNCTION; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.NFC_NAMING_CODE; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_CODE; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VM_TYPE_TAG; -import static org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType.NATIVE_NODE; -import static org.openecomp.sdc.tosca.datatypes.ToscaNodeType.MULTIDEPLOYMENTFLAVOR_NODE_TYPE; -import static org.openecomp.sdc.tosca.datatypes.ToscaNodeType.VFC_ABSTRACT_SUBSTITUTE; -import static org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType.NATIVE_DEPENDS_ON; -import static org.openecomp.sdc.tosca.services.ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME; -import static org.openecomp.sdc.translator.services.heattotosca.Constants.VNF_NODE_TEMPLATE_ID_SUFFIX; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.onap.sdc.tosca.datatypes.model.NodeTemplate; @@ -45,6 +23,7 @@ import org.onap.sdc.tosca.datatypes.model.NodeType; import org.onap.sdc.tosca.datatypes.model.RequirementAssignment; import org.onap.sdc.tosca.datatypes.model.RequirementDefinition; import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.onap.sdc.tosca.datatypes.model.TopologyTemplate; import org.openecomp.sdc.datatypes.error.ErrorMessage; import org.openecomp.sdc.tosca.datatypes.ToscaElementTypes; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; @@ -54,6 +33,28 @@ import org.openecomp.sdc.tosca.services.ToscaConstants; import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl; import org.openecomp.sdc.versioning.dao.types.Version; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.HIGH_AVAIL_MODE; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MANDATORY; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MAX_INSTANCES; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MIN_INSTANCES; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.NFC_FUNCTION; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.NFC_NAMING_CODE; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_CODE; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VM_TYPE_TAG; +import static org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType.NATIVE_NODE; +import static org.openecomp.sdc.tosca.datatypes.ToscaNodeType.MULTIDEPLOYMENTFLAVOR_NODE_TYPE; +import static org.openecomp.sdc.tosca.datatypes.ToscaNodeType.VFC_ABSTRACT_SUBSTITUTE; +import static org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType.NATIVE_DEPENDS_ON; +import static org.openecomp.sdc.tosca.services.ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME; +import static org.openecomp.sdc.translator.services.heattotosca.Constants.VNF_NODE_TEMPLATE_ID_SUFFIX; + public class AbstractSubstituteToscaEnricher { private ToscaAnalyzerService toscaAnalyzerService; @@ -80,6 +81,11 @@ public class AbstractSubstituteToscaEnricher { return errors; } + final TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template(); + if (topologyTemplate == null) { + return errors; + } + final Map<String, NodeTemplate> nodeTemplates = serviceTemplate.getTopology_template().getNode_templates(); if (nodeTemplates == null) { return errors; diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIService.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIService.java index d5dab46533..a6b58167f9 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIService.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIService.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi; import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.tosca.csar.Manifest; import java.io.IOException; @@ -42,4 +43,25 @@ public interface ETSIService { * @param manifest */ void moveNonManoFileToArtifactFolder(FileContentHandler handler, Manifest manifest); + + /** + * Retrieves the manifest file from the CSAR + * @param handler contains csar artifacts + * @throws IOException when TOSCA.meta file or manifest file is invalid + */ + Manifest getManifest(FileContentHandler handler) throws IOException; + + /** + * Determmines the type of resource that the CSAR represents + * @param handler contains csar artifacts + * @throws IOException when TOSCA.meta file or manifest file is invalid + */ + ResourceTypeEnum getResourceType(FileContentHandler handler) throws IOException; + + /** + * Determmines the type of resource that the CSAR represents + * @param manifest contains manifest content + * @throws IOException when TOSCA.meta file or manifest file is invalid + */ + ResourceTypeEnum getResourceType(Manifest manifest) throws IOException; } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java index 6dac3c8f60..1b74b0094f 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java @@ -23,7 +23,11 @@ package org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi; import org.apache.commons.io.IOUtils; import org.onap.sdc.tosca.parser.utils.YamlToObjectConverter; import org.openecomp.core.utilities.file.FileContentHandler; - +import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; +import org.openecomp.sdc.tosca.csar.Manifest; +import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata; +import org.openecomp.sdc.tosca.csar.SOL004ManifestOnboarding; +import org.openecomp.sdc.tosca.csar.ToscaMetadata; import java.io.IOException; import java.io.InputStream; @@ -31,12 +35,10 @@ import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; -import org.openecomp.sdc.tosca.csar.Manifest; -import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata; -import org.openecomp.sdc.tosca.csar.ToscaMetadata; - -import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_CHANGE_LOG; +import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_MF_FILE_NAME; +import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_PNF_METADATA; import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS; +import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_CHANGE_LOG; import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_MANIFEST; import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ORIG_PATH_FILE_NAME; import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME; @@ -47,7 +49,7 @@ public class ETSIServiceImpl implements ETSIService { public ETSIServiceImpl() throws IOException { InputStream io = getClass().getClassLoader().getResourceAsStream("nonManoConfig.yaml"); - if(io == null){ + if (io == null) { throw new IOException("Non Mano configuration not found"); } String data = IOUtils.toString(io, StandardCharsets.UTF_8); @@ -74,14 +76,6 @@ public class ETSIServiceImpl implements ETSIService { } } - private InputStream getMetadata(FileContentHandler contentHandler) throws IOException{ - if(contentHandler.containsFile(TOSCA_META_PATH_FILE_NAME)){ - return contentHandler.getFileContent(TOSCA_META_PATH_FILE_NAME); - }else if(contentHandler.containsFile(TOSCA_META_ORIG_PATH_FILE_NAME)){ - return contentHandler.getFileContent(TOSCA_META_ORIG_PATH_FILE_NAME); - } - throw new IOException("TOSCA.meta file does not exist"); - } private void updateNonManoLocation(FileContentHandler handler, String nonManoKey, List<String> sources) { Map<String, byte[]> files = handler.getFiles(); @@ -92,7 +86,7 @@ public class ETSIServiceImpl implements ETSIService { } } - private void updateLocation(String key, String nonManoKey, Map<String, byte[]> files){ + private void updateLocation(String key, String nonManoKey, Map<String, byte[]> files) { if (nonManoKey == null || nonManoKey.isEmpty()) { return; } @@ -107,14 +101,11 @@ public class ETSIServiceImpl implements ETSIService { } } - private String getFileName(String key) { return key.substring(key.lastIndexOf('/') + 1); } - private boolean hasMetaMandatoryEntries(InputStream metadataInputStream) throws IOException { - - ToscaMetadata toscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(metadataInputStream); + private boolean hasMetaMandatoryEntries(ToscaMetadata toscaMetadata) { Map<String, String> metaDataEntries = toscaMetadata.getMetaEntries(); return metaDataEntries.containsKey(TOSCA_META_ENTRY_DEFINITIONS) && metaDataEntries.containsKey(TOSCA_META_ETSI_ENTRY_MANIFEST) && metaDataEntries.containsKey(TOSCA_META_ETSI_ENTRY_CHANGE_LOG); @@ -123,4 +114,60 @@ public class ETSIServiceImpl implements ETSIService { private boolean isMetaFilePresent(Map<String, byte[]> handler) { return handler.containsKey(TOSCA_META_PATH_FILE_NAME) || handler.containsKey(TOSCA_META_ORIG_PATH_FILE_NAME); } + + public ResourceTypeEnum getResourceType(FileContentHandler handler) throws IOException { + ToscaMetadata metadata = getMetadata(handler); + Manifest manifest = getManifest(handler, metadata.getMetaEntries().get(TOSCA_META_ETSI_ENTRY_MANIFEST)); + return getResourceType(manifest); + } + + public ResourceTypeEnum getResourceType(Manifest manifest) { + // Valid manifest should contain whether vnf or pnf related metadata data exclusively in SOL004 standard, + // validation of manifest done during package upload stage + if (manifest != null && !manifest.getMetadata().isEmpty() + && MANIFEST_PNF_METADATA.stream().anyMatch(e -> manifest.getMetadata().containsKey(e))) { + return ResourceTypeEnum.PNF; + } + // VNF is default resource type + return ResourceTypeEnum.VF; + } + + public Manifest getManifest(FileContentHandler handler) throws IOException { + ToscaMetadata metadata = getMetadata(handler); + return getManifest(handler, metadata.getMetaEntries().get(TOSCA_META_ETSI_ENTRY_MANIFEST)); + } + + private Manifest getManifest(FileContentHandler handler, String manifestLocation) throws IOException { + try(InputStream manifestInputStream = getManifestInputStream(handler, manifestLocation)) { + Manifest onboardingManifest = new SOL004ManifestOnboarding(); + onboardingManifest.parse(manifestInputStream); + return onboardingManifest; + } + } + + private ToscaMetadata getMetadata(FileContentHandler handler) throws IOException { + ToscaMetadata metadata; + if (handler.containsFile(TOSCA_META_PATH_FILE_NAME)) { + metadata = OnboardingToscaMetadata.parseToscaMetadataFile(handler.getFileContent(TOSCA_META_PATH_FILE_NAME)); + } else if (handler.containsFile(TOSCA_META_ORIG_PATH_FILE_NAME)) { + metadata = OnboardingToscaMetadata.parseToscaMetadataFile(handler.getFileContent(TOSCA_META_ORIG_PATH_FILE_NAME)); + } else { + throw new IOException("TOSCA.meta file not found!"); + } + return metadata; + } + + private InputStream getManifestInputStream(FileContentHandler handler, String manifestLocation) throws IOException { + InputStream io; + if (manifestLocation == null || !handler.containsFile(manifestLocation)) { + io = handler.getFileContent(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME); + } else { + io = handler.getFileContent(manifestLocation); + } + + if (io == null) { + throw new IOException("Manifest file not found!"); + } + return io; + } } diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java index 0fc65c1f94..859d3da9dc 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java @@ -23,21 +23,12 @@ package org.openecomp.core.impl; import org.apache.commons.collections.MapUtils; -import org.onap.sdc.tosca.datatypes.model.ArtifactDefinition; -import org.onap.sdc.tosca.datatypes.model.CapabilityAssignment; import org.onap.sdc.tosca.datatypes.model.Import; -import org.onap.sdc.tosca.datatypes.model.NodeFilter; -import org.onap.sdc.tosca.datatypes.model.NodeTemplate; import org.onap.sdc.tosca.datatypes.model.NodeType; -import org.onap.sdc.tosca.datatypes.model.ParameterDefinition; -import org.onap.sdc.tosca.datatypes.model.RequirementAssignment; import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; -import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping; import org.openecomp.core.converter.ServiceTemplateReaderService; import org.openecomp.core.converter.ToscaConverter; -import org.openecomp.core.converter.datatypes.Constants; import org.openecomp.core.converter.datatypes.CsarFileTypes; -import org.openecomp.core.converter.errors.SubstitutionMappingsConverterErrorBuilder; import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; @@ -49,28 +40,23 @@ import org.openecomp.sdc.tosca.services.DataModelUtil; import org.openecomp.sdc.tosca.services.ToscaUtil; import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator; import org.yaml.snakeyaml.error.YAMLException; + import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.regex.Pattern; import static org.openecomp.core.converter.datatypes.Constants.ONAP_INDEX; -import static org.openecomp.core.converter.datatypes.Constants.capabilities; import static org.openecomp.core.converter.datatypes.Constants.definitionsDir; import static org.openecomp.core.converter.datatypes.Constants.globalStName; import static org.openecomp.core.converter.datatypes.Constants.globalSubstitution; -import static org.openecomp.core.converter.datatypes.Constants.inputs; import static org.openecomp.core.converter.datatypes.Constants.mainStName; -import static org.openecomp.core.converter.datatypes.Constants.nodeType; import static org.openecomp.core.converter.datatypes.Constants.openecompHeatIndex; -import static org.openecomp.core.converter.datatypes.Constants.outputs; -import static org.openecomp.core.converter.datatypes.Constants.requirements; import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME; import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.HEAT_INDEX_IMPORT_FILE; import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.ONAP_INDEX_IMPORT_FILE; @@ -82,6 +68,9 @@ public abstract class AbstractToscaConverter implements ToscaConverter { @Override public abstract ToscaServiceModel convert(FileContentHandler fileContentHandler) throws IOException; + public abstract void convertTopologyTemplate(ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService); + protected void handleMetadataFile(Map<String, byte[]> csarFiles) { byte[] bytes = csarFiles.remove(TOSCA_META_PATH_FILE_NAME); if (bytes != null) { @@ -105,9 +94,9 @@ public abstract class AbstractToscaConverter implements ToscaConverter { } } - protected String getConcreteArtifactFileName(String fileName){ + protected String getConcreteArtifactFileName(String fileName) { int artifactIndex = fileName.indexOf(CsarFileTypes.Artifacts.name()); - if(artifactIndex < 0){ + if (artifactIndex < 0) { return fileName; } @@ -130,7 +119,7 @@ public abstract class AbstractToscaConverter implements ToscaConverter { csarFiles.get(TOSCA_META_ORIG_PATH_FILE_NAME)); toscaServiceModel.setArtifactFiles(externalFilesHandler); - if(MapUtils.isNotEmpty(globalSubstitutionServiceTemplate.getNode_types())) { + if (MapUtils.isNotEmpty(globalSubstitutionServiceTemplate.getNode_types())) { serviceTemplates .put(GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME, globalSubstitutionServiceTemplate); } @@ -146,8 +135,8 @@ public abstract class AbstractToscaConverter implements ToscaConverter { protected void handleServiceTemplate(String serviceTemplateName, String fileName, Map<String, byte[]> csarFiles, Map<String, ServiceTemplate> serviceTemplates) { - Optional<ServiceTemplate> serviceTemplate = - getServiceTemplateFromCsar(fileName, csarFiles); + final byte[] inputServiceTemplate = getServiceTemplateFromCsar(fileName, csarFiles); + Optional<ServiceTemplate> serviceTemplate = convertServiceTemplate(fileName, inputServiceTemplate); serviceTemplate.ifPresent( serviceTemplateValue -> addServiceTemplate(serviceTemplateName, serviceTemplateValue, serviceTemplates)); @@ -159,16 +148,12 @@ public abstract class AbstractToscaConverter implements ToscaConverter { serviceTemplates.put(serviceTemplateName, serviceTemplate); } - private Optional<ServiceTemplate> getServiceTemplateFromCsar(String fileName, - Map<String, byte[]> csarFiles) { - byte[] fileContent = csarFiles.get(fileName); - ServiceTemplate serviceTemplate = convertServiceTemplate(fileName, fileContent); - - return Optional.of(serviceTemplate); + private byte[] getServiceTemplateFromCsar(String fileName, Map<String, byte[]> csarFiles) { + return csarFiles.get(fileName); } - private ServiceTemplate convertServiceTemplate(String serviceTemplateName, - byte[] fileContent) { + private Optional<ServiceTemplate> convertServiceTemplate(String serviceTemplateName, + byte[] fileContent) { ServiceTemplate serviceTemplate = new ServiceTemplate(); try { ServiceTemplateReaderService readerService = @@ -178,7 +163,6 @@ public abstract class AbstractToscaConverter implements ToscaConverter { convertImports(serviceTemplate); convertNodeTypes(serviceTemplate, readerService); convertTopologyTemplate(serviceTemplate, readerService); - } catch (YAMLException ye) { throw new CoreException(new ErrorCode.ErrorCodeBuilder() .withMessage("Invalid YAML content in file" + serviceTemplateName) @@ -186,7 +170,7 @@ public abstract class AbstractToscaConverter implements ToscaConverter { } - return serviceTemplate; + return Optional.of(serviceTemplate); } private void convertToscaVersion(ServiceTemplate serviceTemplate, @@ -249,133 +233,7 @@ public abstract class AbstractToscaConverter implements ToscaConverter { } } - private void convertTopologyTemplate(ServiceTemplate serviceTemplate, - ServiceTemplateReaderService readerService) { - - convertInputs(serviceTemplate, readerService); - convertNodeTemplates(serviceTemplate, readerService); - convertOutputs(serviceTemplate, readerService); - convertSubstitutionMappings(serviceTemplate, readerService); - } - - private void convertInputs(ServiceTemplate serviceTemplate, - ServiceTemplateReaderService readerService) { - Map<String, Object> inputs = readerService.getInputs(); - addInputsOrOutputsToServiceTemplate(serviceTemplate, inputs, Constants.inputs); - } - - private void convertOutputs(ServiceTemplate serviceTemplate, - ServiceTemplateReaderService readerService) { - Map<String, Object> outputs = readerService.getOutputs(); - addInputsOrOutputsToServiceTemplate(serviceTemplate, outputs, Constants.outputs); - } - - private void addInputsOrOutputsToServiceTemplate(ServiceTemplate serviceTemplate, - Map<String, Object> mapToConvert, - String inputsOrOutputs) { - if (MapUtils.isEmpty(mapToConvert)) { - return; - } - - for (Map.Entry<String, Object> entry : mapToConvert.entrySet()) { - Optional<ParameterDefinition> parameterDefinition = - ToscaConverterUtil.createObjectFromClass( - entry.getKey(), entry.getValue(), ParameterDefinition.class); - - parameterDefinition.ifPresent(parameterDefinitionValue -> { - Optional<Object> defaultValue = - ToscaConverterUtil.getDefaultValue(entry.getValue(), parameterDefinition.get()); - defaultValue.ifPresent(parameterDefinitionValue::set_default); - addToServiceTemplateAccordingToSection( - serviceTemplate, inputsOrOutputs, entry.getKey(), parameterDefinition.get()); - }); - } - } - - private void addToServiceTemplateAccordingToSection(ServiceTemplate serviceTemplate, - String inputsOrOutputs, - String parameterId, - ParameterDefinition parameterDefinition) { - if (inputsOrOutputs.equals(inputs)) { - DataModelUtil - .addInputParameterToTopologyTemplate(serviceTemplate, parameterId, parameterDefinition); - } else if (inputsOrOutputs.equals(outputs)) { - DataModelUtil - .addOutputParameterToTopologyTemplate(serviceTemplate, parameterId, parameterDefinition); - } - } - - private void convertNodeTemplates(ServiceTemplate serviceTemplate, - ServiceTemplateReaderService readerService) { - Map<String, Object> nodeTemplates = readerService.getNodeTemplates(); - if (MapUtils.isEmpty(nodeTemplates)) { - return; - } - - for (Map.Entry<String, Object> nodeTemplateEntry : nodeTemplates.entrySet()) { - NodeTemplate nodeTemplate = convertNodeTemplate(nodeTemplateEntry.getValue()); - DataModelUtil.addNodeTemplate(serviceTemplate, nodeTemplateEntry.getKey(), nodeTemplate); - } - } - - private void convertSubstitutionMappings(ServiceTemplate serviceTemplate, - ServiceTemplateReaderService readerService) { - Map<String, Object> substitutionMappings = readerService.getSubstitutionMappings(); - if (MapUtils.isEmpty(substitutionMappings)) { - return; - } - SubstitutionMapping substitutionMapping = convertSubstitutionMappings(substitutionMappings); - DataModelUtil.addSubstitutionMapping(serviceTemplate, substitutionMapping); - } - - private SubstitutionMapping convertSubstitutionMappings( - Map<String, Object> substitutionMappings) { - SubstitutionMapping substitutionMapping = new SubstitutionMapping(); - - substitutionMapping.setNode_type((String) substitutionMappings.get(nodeType)); - substitutionMapping.setCapabilities( - convertSubstitutionMappingsSections(capabilities, substitutionMappings.get(capabilities))); - substitutionMapping.setRequirements( - convertSubstitutionMappingsSections(requirements, substitutionMappings.get(requirements))); - - return substitutionMapping; - } - - private Map<String, List<String>> convertSubstitutionMappingsSections(String sectionName, - Object sectionToConvert) { - - if (Objects.isNull(sectionToConvert)) { - return null; - } - - if (!(sectionToConvert instanceof Map)) { - throw new CoreException( - new SubstitutionMappingsConverterErrorBuilder( - sectionName, sectionToConvert.getClass().getSimpleName()).build()); - } - - return convertSection(sectionToConvert); - } - - private Map<String, List<String>> convertSection(Object sectionToConvert) { - - Map<String, Object> sectionAsMap = (Map<String, Object>) sectionToConvert; - Map<String, List<String>> convertedSection = new HashMap<>(); - - if (MapUtils.isEmpty(sectionAsMap)) { - return null; - } - - for (Map.Entry<String, Object> entry : sectionAsMap.entrySet()) { - if (entry.getValue() instanceof List) { - convertedSection.put(entry.getKey(), (List<String>) entry.getValue()); - } - } - - return convertedSection; - } - - protected CsarFileTypes getFileType(String fileName){ + protected CsarFileTypes getFileType(String fileName) { if (isMainServiceTemplate(fileName)) { return CsarFileTypes.mainServiceTemplate; } else if (isGlobalServiceTemplate(fileName)) { @@ -388,47 +246,6 @@ public abstract class AbstractToscaConverter implements ToscaConverter { return CsarFileTypes.externalFile; } - private NodeTemplate convertNodeTemplate(Object candidateNodeTemplate) { - NodeTemplate nodeTemplate = new NodeTemplate(); - - Map<String, Object> nodeTemplateAsMap = (Map<String, Object>) candidateNodeTemplate; - nodeTemplate.setArtifacts((Map<String, ArtifactDefinition>) nodeTemplateAsMap.get("artifacts")); - nodeTemplate.setAttributes((Map<String, Object>) nodeTemplateAsMap.get("attributes")); - nodeTemplate.setCopy((String) nodeTemplateAsMap.get("copy")); - nodeTemplate.setDescription((String) nodeTemplateAsMap.get("description")); - nodeTemplate.setDirectives((List<String>) nodeTemplateAsMap.get("directives")); - nodeTemplate.setInterfaces( - (Map<String, Object>) nodeTemplateAsMap.get("interfaces")); - nodeTemplate.setNode_filter((NodeFilter) nodeTemplateAsMap.get("node_filter")); - nodeTemplate.setProperties((Map<String, Object>) nodeTemplateAsMap.get("properties")); - nodeTemplate.setRequirements( - (List<Map<String, RequirementAssignment>>) nodeTemplateAsMap.get("requirements")); - nodeTemplate.setType((String) nodeTemplateAsMap.get("type")); - nodeTemplate.setCapabilities( - convertCapabilities((Map<String, Object>) nodeTemplateAsMap.get("capabilities"))); - - return nodeTemplate; - } - - private Map<String, CapabilityAssignment> convertCapabilities(Map<String, Object> capabilities) { - if (MapUtils.isEmpty(capabilities)) { - return null; - } - - Map<String, CapabilityAssignment> convertedCapabilities = new HashMap<>(); - for (Map.Entry<String, Object> capabilityAssignmentEntry : capabilities.entrySet()) { - Optional<CapabilityAssignment> capabilityAssignment = ToscaConverterUtil.createObjectFromClass - (capabilityAssignmentEntry.getKey(), capabilityAssignmentEntry.getValue(), - CapabilityAssignment.class); - - capabilityAssignment.ifPresent(capabilityAssignmentValue -> - convertedCapabilities.put(capabilityAssignmentEntry.getKey(), capabilityAssignmentValue)); - - } - return convertedCapabilities; - } - - protected boolean isMainServiceTemplate(String fileName) { return fileName.endsWith(mainStName); } diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java index 46a5904299..6371ba67d9 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterImpl.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java @@ -31,6 +31,7 @@ import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata; import org.openecomp.sdc.tosca.csar.ToscaMetadata; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; + import java.io.IOException; import java.util.HashMap; import java.util.HashSet; @@ -43,9 +44,9 @@ import static org.openecomp.sdc.tosca.csar.CSARConstants.NON_FILE_IMPORT_ATTRIBU import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS; import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME; -public class ToscaSolConverterImpl extends AbstractToscaConverter { +public abstract class AbstractToscaSolConverter extends AbstractToscaConverter { - private static final Logger LOGGER = LoggerFactory.getLogger(ToscaSolConverterImpl.class); + private static final Logger LOGGER = LoggerFactory.getLogger(AbstractToscaSolConverter.class); private final Set<String> handledDefinitionFilesList = new HashSet<>(); @Override @@ -65,7 +66,7 @@ public class ToscaSolConverterImpl extends AbstractToscaConverter { private void handleMainServiceTemplate(Map<String, byte[]> csarFiles, Map<String, ServiceTemplate> serviceTemplates, GlobalSubstitutionServiceTemplate gsst, String mServiceDefinitionFileName) { - if(mServiceDefinitionFileName != null){ + if (mServiceDefinitionFileName != null) { handleServiceTemplate(getSimpleName(mServiceDefinitionFileName), mServiceDefinitionFileName, csarFiles, serviceTemplates); String parentDir = mServiceDefinitionFileName.substring(0, mServiceDefinitionFileName.lastIndexOf("/")); handleImportDefinitions(mServiceDefinitionFileName, csarFiles, parentDir, gsst); @@ -73,11 +74,11 @@ public class ToscaSolConverterImpl extends AbstractToscaConverter { } private void handleExternalArtifacts(Map<String, byte[]> csarFiles, Map<String, ServiceTemplate> serviceTemplates, FileContentHandler artifacts) { - for(Map.Entry<String, byte[]> fileEntry: csarFiles.entrySet()){ - if(!handledDefinitionFilesList.contains(fileEntry.getKey()) && !isMetadataFile(fileEntry.getKey())){ - if(isGlobalServiceTemplate(fileEntry.getKey())){ + for (Map.Entry<String, byte[]> fileEntry : csarFiles.entrySet()) { + if (!handledDefinitionFilesList.contains(fileEntry.getKey()) && !isMetadataFile(fileEntry.getKey())) { + if (isGlobalServiceTemplate(fileEntry.getKey())) { handleServiceTemplate(globalStName, fileEntry.getKey(), csarFiles, serviceTemplates); - }else{ + } else { artifacts.addFile( getConcreteArtifactFileName(fileEntry.getKey()), fileEntry.getValue()); } @@ -85,7 +86,7 @@ public class ToscaSolConverterImpl extends AbstractToscaConverter { } } - private void handleImportDefinitions(String fileName, Map<String,byte[]> csarFiles, String parentDir, GlobalSubstitutionServiceTemplate gsst) { + private void handleImportDefinitions(String fileName, Map<String, byte[]> csarFiles, String parentDir, GlobalSubstitutionServiceTemplate gsst) { handledDefinitionFilesList.add(fileName); ServiceTemplateReaderService readerService = new ServiceTemplateReaderServiceImpl(csarFiles.get(fileName)); List<Object> imports = (readerService).getImports(); @@ -102,17 +103,17 @@ public class ToscaSolConverterImpl extends AbstractToscaConverter { return; } - private String getImportedFilePath(Object o, String parentDir){ - if(o instanceof String){ + private String getImportedFilePath(Object o, String parentDir) { + if (o instanceof String) { String fileName = (String) o; - if(!fileName.contains("/")){ + if (!fileName.contains("/")) { fileName = parentDir + "/" + fileName; } return fileName; - }else if(o instanceof Map){ + } else if (o instanceof Map) { Map<String, Object> o1 = (Map) o; - for(Map.Entry<String, Object> entry: o1.entrySet()){ - if(NON_FILE_IMPORT_ATTRIBUTES.stream().noneMatch(attr -> entry.getKey().equals(attr))){ + for (Map.Entry<String, Object> entry : o1.entrySet()) { + if (NON_FILE_IMPORT_ATTRIBUTES.stream().noneMatch(attr -> entry.getKey().equals(attr))) { getImportedFilePath(entry.getValue(), parentDir); } } @@ -125,16 +126,17 @@ public class ToscaSolConverterImpl extends AbstractToscaConverter { ToscaMetadata toscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile( contentHandler.getFileContent(TOSCA_META_PATH_FILE_NAME)); return toscaMetadata.getMetaEntries().get(TOSCA_META_ENTRY_DEFINITIONS); - }catch (IOException e){ + } catch (IOException e) { LOGGER.error(e.getMessage(), e); throw new IOException(e.getMessage()); } } - private String getSimpleName(String path){ - if(path != null && path.contains("/")){ + private String getSimpleName(String path) { + if (path != null && path.contains("/")) { path = path.substring(path.lastIndexOf("/") + 1); } return path; } + }
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java index 01738c1f8a..8d4b9850ea 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java @@ -17,6 +17,7 @@ package org.openecomp.core.impl; import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.core.converter.ServiceTemplateReaderService; import org.openecomp.core.converter.datatypes.CsarFileTypes; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; @@ -66,4 +67,8 @@ public class ToscaConverterImpl extends AbstractToscaConverter { return toscaServiceModel; } + @Override + public void convertTopologyTemplate(ServiceTemplate serviceTemplate, ServiceTemplateReaderService readerService) { + new VnfTopologyTemplateConverter().convertTopologyTemplate(serviceTemplate, readerService); + } } diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterPnf.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterPnf.java new file mode 100644 index 0000000000..0258b42a3d --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterPnf.java @@ -0,0 +1,147 @@ +/* + * - + * * ============LICENSE_START======================================================= + * * Copyright (C) 2019 Nordix Foundation. + * * ================================================================================ + * * 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. + * * + * * SPDX-License-Identifier: Apache-2.0 + * * ============LICENSE_END========================================================= + * + */ + +package org.openecomp.core.impl; + +import org.apache.commons.collections.MapUtils; +import org.onap.sdc.tosca.datatypes.model.NodeTemplate; +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.onap.sdc.tosca.datatypes.model.TopologyTemplate; +import org.openecomp.core.converter.ServiceTemplateReaderService; +import org.openecomp.sdc.tosca.services.DataModelUtil; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +public class ToscaSolConverterPnf extends AbstractToscaSolConverter { + + private static final String PNF_EXT_CP_TYPE = "tosca.nodes.nfv.PnfExtCp"; + private static final String EXT_CP_TYPE = "org.openecomp.resource.cp.v2.extCP"; + private static final String LAYER_PROTOCOLS = "layer_protocols"; + private static final String IP_V4 = "ipv4"; + private static final String IP_V6 = "ipv6"; + private static final String IP_VERSION = "ip_version"; + private static final String ASSIGNMENT_METHOD = "assingment_method"; + private static final String DHCP = "dhcp"; + + /** + * For PNF the node templates are converted ETSI node types to ecomp node types + * All other data i.e. inputs, substitution mappings and outputs are simply dropped at this stage. The equivalent + * ecomp data will be added when the vsp is imported into the catalog. + * @param serviceTemplate + * @param readerService + */ + @Override + public void convertTopologyTemplate(ServiceTemplate serviceTemplate, ServiceTemplateReaderService readerService) { + convertNodeTemplatesToEcompTypes(serviceTemplate, readerService); + addEmptyNodeTemplatesIfNoneDefined(serviceTemplate); + } + + /** + * PNF only has nfv.PNF and nfv.PnfExtCp types defined in ETSI SOL001 v2.5.1. + * - The PNF is mapped to the outer Abstract PNF container in ecomp model and hence nfv.PNF is dropped here. + * - nfv.PnfExtCp is mapped to ecomp v2.extCp type. + * + * @param serviceTemplate + * @param readerService + */ + private void convertNodeTemplatesToEcompTypes(ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService) { + Map<String, Object> nodeTemplates = readerService.getNodeTemplates(); + if (MapUtils.isEmpty(nodeTemplates)) { + return; + } + + for (Map.Entry<String, Object> nodeTemplateEntry : nodeTemplates.entrySet()) { + Map<String, Object> inputNodeTemplate = (Map<String, Object>) nodeTemplateEntry.getValue(); + if (PNF_EXT_CP_TYPE.equals((String) inputNodeTemplate.get("type"))) { + NodeTemplate nodeTemplate = convertToEcompConnectionPointNodeType(inputNodeTemplate); + DataModelUtil.addNodeTemplate(serviceTemplate, nodeTemplateEntry.getKey(), nodeTemplate); + } + } + addEmptyNodeTemplatesIfNoneDefined(serviceTemplate); + } + + + /** + * Converts from the ETSI PnfExtCp node type to ecomp v2.extCP node type + * The following properties are mapped + * - layer_protocols is mapped to ip_requirements if it contains the values ipv4 and/or ipv6 + * <p> + * All other data e.g. remaining properties, requirements, capabilities are + * not mapped over to ecomp equivalent + * + * @param pnfExtCp + * @return ecomp v2.extCP node type + */ + private NodeTemplate convertToEcompConnectionPointNodeType(Map<String, Object> pnfExtCp) { + NodeTemplate nodeTemplate = new NodeTemplate(); + nodeTemplate.setType(EXT_CP_TYPE); + Map<String, Object> properties = (Map<String, Object>) pnfExtCp.get("properties"); + for (Map.Entry<String, Object> property : properties.entrySet()) { + final String propertyName = property.getKey(); + if (LAYER_PROTOCOLS.equals(propertyName)) { + List<Map<String, Object>> ipRequirements = convertToIpRequirementsProperty((List<String>) property.getValue()); + if (isNotEmpty(ipRequirements)) { + Map<String, Object> convertedProperties = new HashMap<>(); + convertedProperties.put("ip_requirements", ipRequirements); + nodeTemplate.setProperties(convertedProperties); + } + } + } + return nodeTemplate; + } + + private List<Map<String, Object>> convertToIpRequirementsProperty(List<String> layerProtocols) { + return layerProtocols.stream() + .filter(layerProtocol -> IP_V4.equals(layerProtocol) || IP_V6.equals(layerProtocol)) + .map(this::createIpPropertyElement) + .collect(Collectors.toList()); + } + + private Map<String, Object> createIpPropertyElement(String ipVersion) { + final int version = ipVersion.equals(IP_V4) ? 4 : 6; + Map<String, Object> result = new HashMap<>(); + result.put(IP_VERSION, version); + result.put(ASSIGNMENT_METHOD, DHCP); + return result; + } + + private boolean isNotEmpty(List<?> list) { + return !list.isEmpty(); + } + + private void addEmptyNodeTemplatesIfNoneDefined(ServiceTemplate serviceTemplate) { + TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template(); + if (Objects.isNull(topologyTemplate)) { + topologyTemplate = new TopologyTemplate(); + serviceTemplate.setTopology_template(topologyTemplate); + } + if (topologyTemplate.getNode_templates() == null) { + topologyTemplate.setNode_templates(new HashMap<>()); + } + } + +}
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterVnf.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterVnf.java new file mode 100644 index 0000000000..7d2a38f4f0 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterVnf.java @@ -0,0 +1,35 @@ +/* + * - + * * ============LICENSE_START======================================================= + * * Copyright (C) 2019 Nordix Foundation. + * * ================================================================================ + * * 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. + * * + * * SPDX-License-Identifier: Apache-2.0 + * * ============LICENSE_END========================================================= + * + */ + +package org.openecomp.core.impl; + +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.core.converter.ServiceTemplateReaderService; + +public class ToscaSolConverterVnf extends AbstractToscaSolConverter { + + @Override + public void convertTopologyTemplate(ServiceTemplate serviceTemplate, ServiceTemplateReaderService readerService) { + new VnfTopologyTemplateConverter().convertTopologyTemplate(serviceTemplate, readerService); + } + +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/VnfTopologyTemplateConverter.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/VnfTopologyTemplateConverter.java new file mode 100644 index 0000000000..e6978bcfe1 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/VnfTopologyTemplateConverter.java @@ -0,0 +1,220 @@ +/* + * - + * * ============LICENSE_START======================================================= + * * Copyright (C) 2019 Nordix Foundation. + * * ================================================================================ + * * 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. + * * + * * SPDX-License-Identifier: Apache-2.0 + * * ============LICENSE_END========================================================= + * + */ + +package org.openecomp.core.impl; + +import org.apache.commons.collections.MapUtils; +import org.onap.sdc.tosca.datatypes.model.ArtifactDefinition; +import org.onap.sdc.tosca.datatypes.model.CapabilityAssignment; +import org.onap.sdc.tosca.datatypes.model.NodeFilter; +import org.onap.sdc.tosca.datatypes.model.NodeTemplate; +import org.onap.sdc.tosca.datatypes.model.ParameterDefinition; +import org.onap.sdc.tosca.datatypes.model.RequirementAssignment; +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping; +import org.openecomp.core.converter.ServiceTemplateReaderService; +import org.openecomp.core.converter.datatypes.Constants; +import org.openecomp.core.converter.errors.SubstitutionMappingsConverterErrorBuilder; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.tosca.services.DataModelUtil; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +import static org.openecomp.core.converter.datatypes.Constants.capabilities; +import static org.openecomp.core.converter.datatypes.Constants.inputs; +import static org.openecomp.core.converter.datatypes.Constants.nodeType; +import static org.openecomp.core.converter.datatypes.Constants.outputs; +import static org.openecomp.core.converter.datatypes.Constants.requirements; + +public class VnfTopologyTemplateConverter { + + public void convertTopologyTemplate(ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService) { + + convertInputs(serviceTemplate, readerService); + convertNodeTemplates(serviceTemplate, readerService); + convertOutputs(serviceTemplate, readerService); + convertSubstitutionMappings(serviceTemplate, readerService); + } + + private void convertInputs(ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService) { + Map<String, Object> inputs = readerService.getInputs(); + addInputsOrOutputsToServiceTemplate(serviceTemplate, inputs, Constants.inputs); + } + + private void convertOutputs(ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService) { + Map<String, Object> outputs = readerService.getOutputs(); + addInputsOrOutputsToServiceTemplate(serviceTemplate, outputs, Constants.outputs); + } + + private void addInputsOrOutputsToServiceTemplate(ServiceTemplate serviceTemplate, + Map<String, Object> mapToConvert, + String inputsOrOutputs) { + if (MapUtils.isEmpty(mapToConvert)) { + return; + } + + for (Map.Entry<String, Object> entry : mapToConvert.entrySet()) { + Optional<ParameterDefinition> parameterDefinition = + ToscaConverterUtil.createObjectFromClass( + entry.getKey(), entry.getValue(), ParameterDefinition.class); + + parameterDefinition.ifPresent(parameterDefinitionValue -> { + Optional<Object> defaultValue = + ToscaConverterUtil.getDefaultValue(entry.getValue(), parameterDefinition.get()); + defaultValue.ifPresent(parameterDefinitionValue::set_default); + addToServiceTemplateAccordingToSection( + serviceTemplate, inputsOrOutputs, entry.getKey(), parameterDefinition.get()); + }); + } + } + + private void addToServiceTemplateAccordingToSection(ServiceTemplate serviceTemplate, + String inputsOrOutputs, + String parameterId, + ParameterDefinition parameterDefinition) { + if (inputsOrOutputs.equals(inputs)) { + DataModelUtil + .addInputParameterToTopologyTemplate(serviceTemplate, parameterId, parameterDefinition); + } else if (inputsOrOutputs.equals(outputs)) { + DataModelUtil + .addOutputParameterToTopologyTemplate(serviceTemplate, parameterId, parameterDefinition); + } + } + + private void convertNodeTemplates(ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService) { + Map<String, Object> nodeTemplates = readerService.getNodeTemplates(); + if (MapUtils.isEmpty(nodeTemplates)) { + return; + } + + for (Map.Entry<String, Object> nodeTemplateEntry : nodeTemplates.entrySet()) { + NodeTemplate nodeTemplate = convertNodeTemplate(nodeTemplateEntry.getValue()); + DataModelUtil.addNodeTemplate(serviceTemplate, nodeTemplateEntry.getKey(), nodeTemplate); + } + } + + private NodeTemplate convertNodeTemplate(Object candidateNodeTemplate) { + NodeTemplate nodeTemplate = new NodeTemplate(); + + Map<String, Object> nodeTemplateAsMap = (Map<String, Object>) candidateNodeTemplate; + nodeTemplate.setArtifacts((Map<String, ArtifactDefinition>) nodeTemplateAsMap.get("artifacts")); + nodeTemplate.setAttributes((Map<String, Object>) nodeTemplateAsMap.get("attributes")); + nodeTemplate.setCopy((String) nodeTemplateAsMap.get("copy")); + nodeTemplate.setDescription((String) nodeTemplateAsMap.get("description")); + nodeTemplate.setDirectives((List<String>) nodeTemplateAsMap.get("directives")); + nodeTemplate.setInterfaces( + (Map<String, Object>) nodeTemplateAsMap.get("interfaces")); + nodeTemplate.setNode_filter((NodeFilter) nodeTemplateAsMap.get("node_filter")); + nodeTemplate.setProperties((Map<String, Object>) nodeTemplateAsMap.get("properties")); + nodeTemplate.setRequirements( + (List<Map<String, RequirementAssignment>>) nodeTemplateAsMap.get("requirements")); + nodeTemplate.setType((String) nodeTemplateAsMap.get("type")); + nodeTemplate.setCapabilities( + convertCapabilities((Map<String, Object>) nodeTemplateAsMap.get("capabilities"))); + + return nodeTemplate; + } + + private Map<String, CapabilityAssignment> convertCapabilities(Map<String, Object> capabilities) { + if (MapUtils.isEmpty(capabilities)) { + return null; + } + + Map<String, CapabilityAssignment> convertedCapabilities = new HashMap<>(); + for (Map.Entry<String, Object> capabilityAssignmentEntry : capabilities.entrySet()) { + Optional<CapabilityAssignment> capabilityAssignment = ToscaConverterUtil.createObjectFromClass + (capabilityAssignmentEntry.getKey(), capabilityAssignmentEntry.getValue(), + CapabilityAssignment.class); + + capabilityAssignment.ifPresent(capabilityAssignmentValue -> + convertedCapabilities.put(capabilityAssignmentEntry.getKey(), capabilityAssignmentValue)); + + } + return convertedCapabilities; + } + + private void convertSubstitutionMappings(ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService) { + Map<String, Object> substitutionMappings = readerService.getSubstitutionMappings(); + if (MapUtils.isEmpty(substitutionMappings)) { + return; + } + SubstitutionMapping substitutionMapping = convertSubstitutionMappings(substitutionMappings); + DataModelUtil.addSubstitutionMapping(serviceTemplate, substitutionMapping); + } + + private SubstitutionMapping convertSubstitutionMappings( + Map<String, Object> substitutionMappings) { + SubstitutionMapping substitutionMapping = new SubstitutionMapping(); + + substitutionMapping.setNode_type((String) substitutionMappings.get(nodeType)); + substitutionMapping.setCapabilities( + convertSubstitutionMappingsSections(capabilities, substitutionMappings.get(capabilities))); + substitutionMapping.setRequirements( + convertSubstitutionMappingsSections(requirements, substitutionMappings.get(requirements))); + + return substitutionMapping; + } + + private Map<String, List<String>> convertSubstitutionMappingsSections(String sectionName, + Object sectionToConvert) { + + if (Objects.isNull(sectionToConvert)) { + return null; + } + + if (!(sectionToConvert instanceof Map)) { + throw new CoreException( + new SubstitutionMappingsConverterErrorBuilder( + sectionName, sectionToConvert.getClass().getSimpleName()).build()); + } + + return convertSection(sectionToConvert); + } + + private Map<String, List<String>> convertSection(Object sectionToConvert) { + + Map<String, Object> sectionAsMap = (Map<String, Object>) sectionToConvert; + Map<String, List<String>> convertedSection = new HashMap<>(); + + if (MapUtils.isEmpty(sectionAsMap)) { + return null; + } + + for (Map.Entry<String, Object> entry : sectionAsMap.entrySet()) { + if (entry.getValue() instanceof List) { + convertedSection.put(entry.getKey(), (List<String>) entry.getValue()); + } + } + + return convertedSection; + } + +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterPnfMultipleNodeTemplatesTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterPnfMultipleNodeTemplatesTest.java new file mode 100644 index 0000000000..21394c9c47 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterPnfMultipleNodeTemplatesTest.java @@ -0,0 +1,74 @@ +/* + * - + * * ============LICENSE_START======================================================= + * * Copyright (C) 2019 Nordix Foundation. + * * ================================================================================ + * * 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. + * * + * * SPDX-License-Identifier: Apache-2.0 + * * ============LICENSE_END========================================================= + * + */ + +package org.openecomp.core.impl; + +import org.apache.commons.io.IOUtils; +import org.junit.Test; +import org.onap.sdc.tosca.datatypes.model.NodeTemplate; +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.core.converter.ServiceTemplateReaderService; +import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class ToscaSolConverterPnfMultipleNodeTemplatesTest { + + private static final String PNF_EXT_CP_1 = "pnfExtCp_1"; + private static final String PNF_EXT_CP_2 = "pnfExtCp_2"; + + @Test + public void testGivenDescriptorWithPnfAndTwoPnfExts_WhenConvertTopologyTemplate_ThenTwoExtCpsInOutput() throws IOException { + // Added this as separate test as data-driven tests compare strings and as order of nodeTemplates + // can be different in hashMap and hence test may fail + final byte[] descriptor = getFileResource("pnfDescriptor/other/pnfDescriptor_PnfAnd2ExtCps.yaml"); + ServiceTemplateReaderService serviceTemplateReaderService = new ServiceTemplateReaderServiceImpl(descriptor); + ServiceTemplate serviceTemplate = new ServiceTemplate(); + ToscaSolConverterPnf toscaSolConverter = new ToscaSolConverterPnf(); + toscaSolConverter.convertTopologyTemplate(serviceTemplate, serviceTemplateReaderService); + Map<String, NodeTemplate> nodeTemplates = serviceTemplate.getTopology_template().getNode_templates(); + assertEquals(2, nodeTemplates.size()); + + nodeTemplates.entrySet().stream() + .map(Map.Entry::getKey) + .forEach((key -> assertTrue(getErrorString(), hasCorrectName(key)))); + } + + private byte[] getFileResource(String filePath) throws IOException { + try (InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath)) { + return IOUtils.toByteArray(inputStream); + } + } + + private boolean hasCorrectName(String name) { + return PNF_EXT_CP_1.equals(name) || PNF_EXT_CP_2.equals(name); + } + + private String getErrorString() { + return "node template name should be either " + PNF_EXT_CP_1 + " or " + PNF_EXT_CP_2; + } +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterPnfTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterPnfTest.java new file mode 100644 index 0000000000..c3f38fe3cd --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterPnfTest.java @@ -0,0 +1,114 @@ +/* + * - + * * ============LICENSE_START======================================================= + * * Copyright (C) 2019 Nordix Foundation. + * * ================================================================================ + * * 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. + * * + * * SPDX-License-Identifier: Apache-2.0 + * * ============LICENSE_END========================================================= + * + */ + +package org.openecomp.core.impl; + +import org.apache.commons.io.IOUtils; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil; +import org.onap.sdc.tosca.services.YamlUtil; +import org.openecomp.core.converter.ServiceTemplateReaderService; +import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collection; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.junit.Assert.assertEquals; + +@RunWith(Parameterized.class) +public class ToscaSolConverterPnfTest { + + public static final String INPUT_DIR = "pnfDescriptor/in/"; + public static final String OUTPUT_DIR = "pnfDescriptor/out/"; + private String inputFilename; + private YamlUtil yamlUtil = new YamlUtil(); + private ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); + + public ToscaSolConverterPnfTest(String inputFilename) { + this.inputFilename = inputFilename; + } + + @Parameterized.Parameters(name = "{index}: {0}") + public static Collection<String> input() throws IOException { + try (Stream<Path> files = Files.list(getPathFromClasspath(INPUT_DIR))) { + return files.map(path -> path.getFileName().toString()) + .collect(Collectors.toList()); + } + } + + @Test + public void testTopologyTemplateConversions() throws IOException { + final byte[] descriptor = getInputFileResource(inputFilename); + ServiceTemplateReaderService serviceTemplateReaderService = new ServiceTemplateReaderServiceImpl(descriptor); + ServiceTemplate serviceTemplate = new ServiceTemplate(); + ToscaSolConverterPnf toscaSolConverter = new ToscaSolConverterPnf(); + toscaSolConverter.convertTopologyTemplate(serviceTemplate, serviceTemplateReaderService); + + String result = yamlUtil.objectToYaml(serviceTemplate); + String expectedResult = getExpectedResultFor(inputFilename); + assertEquals(expectedResult, result); + } + + private String getExpectedResultFor(String inputFilename) throws IOException { + try (InputStream inputStream = getOutputFileResourceCorrespondingTo(inputFilename)) { + ServiceTemplate serviceTemplate = toscaExtensionYamlUtil.yamlToObject(inputStream, ServiceTemplate.class); + return yamlUtil.objectToYaml(serviceTemplate); + } + } + + private static Path getPathFromClasspath(String location) { + return Paths.get(Thread.currentThread().getContextClassLoader().getResource(location).getPath()); + } + + private byte[] getInputFileResource(String inputFilename) throws IOException { + return getFileResource(INPUT_DIR + inputFilename); + } + + private InputStream getOutputFileResourceCorrespondingTo(String inputFilename) { + String outputFilename = getOutputFilenameFrom(inputFilename); + return getFileResourceAsInputStream(OUTPUT_DIR + outputFilename); + } + + private String getOutputFilenameFrom(String inputFilename) { + return inputFilename.replace("pnfDescriptor", "topologyTemplate"); + } + + private byte[] getFileResource(String filePath) throws IOException { + try (InputStream inputStream = getFileResourceAsInputStream(filePath)) { + return IOUtils.toByteArray(inputStream); + } + } + + private InputStream getFileResourceAsInputStream(String filePath) { + return Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath); + } + +}
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterImplTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterVnfTest.java index 45d6332e06..bfc1fa9d85 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterImplTest.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterVnfTest.java @@ -36,14 +36,14 @@ import java.nio.charset.StandardCharsets; import java.util.Map; -public class ToscaSolConverterImplTest { +public class ToscaSolConverterVnfTest { - private ToscaSolConverterImpl toscaSolConverter; + private AbstractToscaSolConverter toscaSolConverter; private FileContentHandler fileContentHandler; @Before public void setUp(){ - toscaSolConverter = new ToscaSolConverterImpl(); + toscaSolConverter = new ToscaSolConverterVnf(); fileContentHandler = new FileContentHandler(); } diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_ExtCpWithNoIpv4OrIpv6Values.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_ExtCpWithNoIpv4OrIpv6Values.yaml new file mode 100644 index 0000000000..f78b763672 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_ExtCpWithNoIpv4OrIpv6Values.yaml @@ -0,0 +1,26 @@ +tosca_definitions_version: tosca_simple_yaml_1_1 + +description: service template of a PNF + +topology_template: + node_templates: + pnf_mainPart: + type: tosca.nodes.nfv.PNF + properties: + descriptor_id: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: an example PNF + provider: Mycompany + version: 1.0 + descriptor_invariant_id: 1111-2222-ccaa-bbdd + name: ExamplePnf + requirements: + - virtual_link: + capability: tosca.capabilities.nfv.VirtualLinkable + node: pnfExtCp_1 + pnfExtCp_1: + type: tosca.nodes.nfv.PnfExtCp + properties: + trunk_mode: false + layer_protocols: [ otherProtocol ] + role: leaf + description: External connection point to access this pnf
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_PnfAndExtCp.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_PnfAndExtCp.yaml new file mode 100644 index 0000000000..83c7d9c0d4 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_PnfAndExtCp.yaml @@ -0,0 +1,26 @@ +tosca_definitions_version: tosca_simple_yaml_1_1 + +description: service template of a PNF + +topology_template: + node_templates: + pnf_mainPart: + type: tosca.nodes.nfv.PNF + properties: + descriptor_id: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: an example PNF + provider: Mycompany + version: 1.0 + descriptor_invariant_id: 1111-2222-ccaa-bbdd + name: ExamplePnf + requirements: + - virtual_link: + capability: tosca.capabilities.nfv.VirtualLinkable + node: pnfExtCp_1 + pnfExtCp_1: + type: tosca.nodes.nfv.PnfExtCp + properties: + trunk_mode: false + layer_protocols: [ ipv4, ipv6, otherProtocol ] + role: leaf + description: External connection point to access this pnf
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_PnfOnly.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_PnfOnly.yaml new file mode 100644 index 0000000000..1b6ab8b95f --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_PnfOnly.yaml @@ -0,0 +1,19 @@ +tosca_definitions_version: tosca_simple_yaml_1_1 + +description: service template of a PNF + +topology_template: + node_templates: + pnf_mainPart: + type: tosca.nodes.nfv.PNF + properties: + descriptor_id: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: an example PNF + provider: Mycompany + version: 1.0 + descriptor_invariant_id: 1111-2222-ccaa-bbdd + name: ExamplePnf + requirements: + - virtual_link: + capability: tosca.capabilities.nfv.VirtualLinkable + node: pnfExtCp_1
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withExtraSpaces.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withExtraSpaces.yaml new file mode 100644 index 0000000000..913e200ead --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withExtraSpaces.yaml @@ -0,0 +1,26 @@ +tosca_definitions_version: tosca_simple_yaml_1_1 + +description: service template of a PNF + +topology_template: + node_templates: + pnf_mainPart: + type: tosca.nodes.nfv.PNF # This is a comment + properties: + descriptor_id: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: an example PNF + provider: Mycompany + version: 1.0 + descriptor_invariant_id: 1111-2222-ccaa-bbdd + name: ExamplePnf + requirements: + - virtual_link: + capability: tosca.capabilities.nfv.VirtualLinkable + node: pnfExtCp_1 + pnfExtCp_1: # This is another comment here + type: tosca.nodes.nfv.PnfExtCp + properties: + trunk_mode: false + layer_protocols: [ ipv4 , ipv6 , otherProtocol ] + role: leaf + description: External connection point to access this pnf
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withInputsAndSubstitutionMappings.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withInputsAndSubstitutionMappings.yaml new file mode 100644 index 0000000000..79108d9084 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withInputsAndSubstitutionMappings.yaml @@ -0,0 +1,40 @@ +tosca_definitions_version: tosca_simple_yaml_1_1 + +description: service template of a PNF + +topology_template: + inputs: + my_input1: + type: string + description: this is input1 + default: defaultValue + my_input2: + type: string + description: this is input2 + default: defaultValue2 + + node_templates: + pnf_mainPart: + type: tosca.nodes.nfv.PNF + properties: + descriptor_id: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: an example PNF + provider: Mycompany + version: 1.0 + descriptor_invariant_id: 1111-2222-ccaa-bbdd + name: ExamplePnf + + pnfExtCp_1: + type: tosca.nodes.nfv.PnfExtCp + properties: + trunk_mode: false + layer_protocols: [ ipv4, ipv6, otherProtocol ] + role: leaf + description: External connection point to access this pnf + requirements: + - virtual_link: + + substitution_mappings: + node_type: tosca.nodes.nfv.PNF + requirements: + virtual_link: [ pnfExtCp_1, virtual_link ]
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/other/pnfDescriptor_PnfAnd2ExtCps.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/other/pnfDescriptor_PnfAnd2ExtCps.yaml new file mode 100644 index 0000000000..26255ddd84 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/other/pnfDescriptor_PnfAnd2ExtCps.yaml @@ -0,0 +1,33 @@ +tosca_definitions_version: tosca_simple_yaml_1_1 + +description: service template of a PNF + +topology_template: + node_templates: + pnf_mainPart: + type: tosca.nodes.nfv.PNF + properties: + descriptor_id: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: an example PNF + provider: Mycompany + version: 1.0 + descriptor_invariant_id: 1111-2222-ccaa-bbdd + name: ExamplePnf + requirements: + - virtual_link: + capability: tosca.capabilities.nfv.VirtualLinkable + node: pnfExtCp_1 + pnfExtCp_1: + type: tosca.nodes.nfv.PnfExtCp + properties: + trunk_mode: false + layer_protocols: [ ipv4, ipv6, otherProtocol ] + role: leaf + description: External connection point to access this pnf + pnfExtCp_2: + type: tosca.nodes.nfv.PnfExtCp + properties: + trunk_mode: false + layer_protocols: [ ipv4, ipv6, otherProtocol ] + role: leaf + description: External connection point to access this pnf
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_ExtCpWithNoIpv4OrIpv6Values.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_ExtCpWithNoIpv4OrIpv6Values.yaml new file mode 100644 index 0000000000..6b1c45b6c9 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_ExtCpWithNoIpv4OrIpv6Values.yaml @@ -0,0 +1,4 @@ +topology_template: + node_templates: + pnfExtCp_1: + type: org.openecomp.resource.cp.v2.extCP
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_PnfAndExtCp.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_PnfAndExtCp.yaml new file mode 100644 index 0000000000..d04b06a89a --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_PnfAndExtCp.yaml @@ -0,0 +1,10 @@ +topology_template: + node_templates: + pnfExtCp_1: + type: org.openecomp.resource.cp.v2.extCP + properties: + ip_requirements: + - assingment_method: dhcp + ip_version: 4 + - assingment_method: dhcp + ip_version: 6
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_PnfOnly.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_PnfOnly.yaml new file mode 100644 index 0000000000..d47ce66ace --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_PnfOnly.yaml @@ -0,0 +1,2 @@ +topology_template: + node_templates: {}
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withExtraSpaces.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withExtraSpaces.yaml new file mode 100644 index 0000000000..d04b06a89a --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withExtraSpaces.yaml @@ -0,0 +1,10 @@ +topology_template: + node_templates: + pnfExtCp_1: + type: org.openecomp.resource.cp.v2.extCP + properties: + ip_requirements: + - assingment_method: dhcp + ip_version: 4 + - assingment_method: dhcp + ip_version: 6
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withInputsAndSubstitutionMappings.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withInputsAndSubstitutionMappings.yaml new file mode 100644 index 0000000000..d04b06a89a --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withInputsAndSubstitutionMappings.yaml @@ -0,0 +1,10 @@ +topology_template: + node_templates: + pnfExtCp_1: + type: org.openecomp.resource.cp.v2.extCP + properties: + ip_requirements: + - assingment_method: dhcp + ip_version: 4 + - assingment_method: dhcp + ip_version: 6
\ No newline at end of file |