From 96c003f567110f221a3d3e9d7a6b437c6783b80c Mon Sep 17 00:00:00 2001 From: vasraz Date: Wed, 18 May 2022 14:00:11 +0100 Subject: Include ETSI metadata 'entry_definition_type' in VSP package metadata Signed-off-by: Vasyl Razinkov Change-Id: Iaa3262d9171cc2a1c6a353191aa4afe5e2124717 Issue-ID: SDC-4011 --- .../java/org/openecomp/sdc/be/tosca/CsarUtils.java | 46 +++++++++++++++------- .../org/openecomp/sdc/be/tosca/CsarUtilsTest.java | 8 ++-- 2 files changed, 37 insertions(+), 17 deletions(-) (limited to 'catalog-be') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java index f9662cc96e..9b0b25b250 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java @@ -368,19 +368,17 @@ public class CsarUtils { * @param isInCertificationRequest * @return */ - public Either createCsar(Component component, boolean getFromCS, boolean isInCertificationRequest) { + public Either createCsar(final Component component, final boolean getFromCS, final boolean isInCertificationRequest) { loggerSupportability .log(LoggerSupportabilityActions.GENERATE_CSAR, StatusCode.STARTED, "Starting to create Csar for component {} ", component.getName()); final String createdBy = component.getCreatorFullName(); - String fileName; - Map toscaArtifacts = component.getToscaArtifacts(); - ArtifactDefinition artifactDefinition = toscaArtifacts.get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE); - fileName = artifactDefinition.getArtifactName(); - String toscaConformanceLevel = ConfigurationManager.getConfigurationManager().getConfiguration().getToscaConformanceLevel(); - String csarBlock0 = createCsarBlock0(CSAR_META_VERSION, toscaConformanceLevel); - byte[] csarBlock0Byte = csarBlock0.getBytes(); - final String toscaBlock0 = createToscaBlock0(TOSCA_META_VERSION, CSAR_VERSION, createdBy, fileName); - byte[] toscaBlock0Byte = toscaBlock0.getBytes(); + final Map toscaArtifacts = component.getToscaArtifacts(); + final ArtifactDefinition artifactDefinition = toscaArtifacts.get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE); + final String fileName = artifactDefinition.getArtifactName(); + final String toscaConformanceLevel = ConfigurationManager.getConfigurationManager().getConfiguration().getToscaConformanceLevel(); + final byte[] csarBlock0Byte = createCsarBlock0(CSAR_META_VERSION, toscaConformanceLevel).getBytes(); + final byte[] toscaBlock0Byte = createToscaBlock0(TOSCA_META_VERSION, CSAR_VERSION, createdBy, fileName, isAsdPackage(component)).getBytes(); + return generateCsarZip(csarBlock0Byte, toscaBlock0Byte, component, getFromCS, isInCertificationRequest).left().map(responseFormat -> { loggerSupportability .log(LoggerSupportabilityActions.GENERATE_CSAR, StatusCode.COMPLETE, "Ended create Csar for component {} ", component.getName()); @@ -388,6 +386,26 @@ public class CsarUtils { }); } + private boolean isAsdPackage(final Component component) { + final Either collectedComponentCsarDefinition = collectComponentCsarDefinition(component); + if (collectedComponentCsarDefinition.isLeft()) { + final ComponentArtifacts componentArtifacts = collectedComponentCsarDefinition.left().value().getComponentArtifacts(); + if (componentArtifacts != null) { + final ComponentTypeArtifacts mainTypeAndCIArtifacts = componentArtifacts.getMainTypeAndCIArtifacts(); + if (mainTypeAndCIArtifacts != null) { + final ArtifactsInfo artifactsInfo = mainTypeAndCIArtifacts.getComponentArtifacts(); + if (artifactsInfo != null) { + final Map>> artifactsInfosMap = artifactsInfo.getArtifactsInfo(); + if (MapUtils.isNotEmpty(artifactsInfosMap) && artifactsInfosMap.containsKey(ArtifactGroupTypeEnum.DEPLOYMENT)) { + return artifactsInfosMap.get(ArtifactGroupTypeEnum.DEPLOYMENT).containsKey(ArtifactTypeEnum.ASD_PACKAGE.getType()); + } + } + } + } + } + return false; + } + private Either generateCsarZip(byte[] csarBlock0Byte, byte[] toscaBlock0Byte, Component component, boolean getFromCS, boolean isInCertificationRequest) { try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out)) { @@ -793,7 +811,7 @@ public class CsarUtils { } private Try writeComponentInterface( - Either interfaceRepresentation, String fileName, ZipWriter zw) { + Either interfaceRepresentation, String fileName, ZipWriter zw) { Either yml = interfaceRepresentation.left() .map(ToscaRepresentation::getMainYaml); return fromEither(yml, ToscaErrorException::new).flatMap(zw.write(DEFINITIONS_PATH + ToscaExportHandler.getInterfaceFilename(fileName))); @@ -873,9 +891,9 @@ public class CsarUtils { return String.format(BLOCK_0_TEMPLATE, metaFileVersion, toscaConformanceLevel); } - private String createToscaBlock0(String metaFileVersion, String csarVersion, String createdBy, String entryDef) { - final String block0template = "TOSCA-Meta-File-Version: %s\nCSAR-Version: %s\nCreated-By: %s\nEntry-Definitions: Definitions/%s\n\nName: csar.meta\nContent-Type: text/plain\n"; - return String.format(block0template, metaFileVersion, csarVersion, createdBy, entryDef); + private String createToscaBlock0(String metaFileVersion, String csarVersion, String createdBy, String entryDef, boolean isAsdPackage) { + final String block0template = "TOSCA-Meta-File-Version: %s\nCSAR-Version: %s\nCreated-By: %s\nEntry-Definitions: Definitions/%s\n%s\nName: csar.meta\nContent-Type: text/plain\n"; + return String.format(block0template, metaFileVersion, csarVersion, createdBy, entryDef, isAsdPackage ? "entry_definition_type: asd" : ""); } private String createNsMfBlock0(String serviceName, String createdBy, String serviceVersion, String releaseTime, String serviceType, diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java index 821d4271f8..373e9b1c89 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java @@ -160,13 +160,15 @@ class CsarUtilsTest extends BaseConfDependent { @Test void testCreateCsar() { Component component = new Resource(); - Map toscaArtifacts = new HashMap<>(); + Map artifactDefinitionHashMap = new HashMap<>(); ArtifactDefinition artifact = new ArtifactDefinition(); artifact.setArtifactName("artifactName"); artifact.setEsId("esId"); - toscaArtifacts.put("assettoscatemplate", artifact); + artifactDefinitionHashMap.put("assettoscatemplate", artifact); - component.setToscaArtifacts(toscaArtifacts); + component.setToscaArtifacts(artifactDefinitionHashMap); + component.setArtifacts(artifactDefinitionHashMap); + component.setDeploymentArtifacts(artifactDefinitionHashMap); Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))) .thenReturn(Either.right(CassandraOperationStatus.GENERAL_ERROR)); -- cgit 1.2.3-korg