diff options
author | vasraz <vasyl.razinkov@est.tech> | 2022-05-18 14:00:11 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2022-05-23 09:57:34 +0000 |
commit | 96c003f567110f221a3d3e9d7a6b437c6783b80c (patch) | |
tree | e483be4a1758c7fc9d8004952baeab125010c38f /catalog-be/src | |
parent | 601fc9e34e16a214d23f4ed4ac1bc64069cb7d3a (diff) |
Include ETSI metadata 'entry_definition_type' in VSP package metadata
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: Iaa3262d9171cc2a1c6a353191aa4afe5e2124717
Issue-ID: SDC-4011
Diffstat (limited to 'catalog-be/src')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java | 46 | ||||
-rw-r--r-- | catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java | 8 |
2 files changed, 37 insertions, 17 deletions
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<byte[], ResponseFormat> createCsar(Component component, boolean getFromCS, boolean isInCertificationRequest) { + public Either<byte[], ResponseFormat> 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<String, ArtifactDefinition> 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<String, ArtifactDefinition> 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<CsarDefinition, ResponseFormat> 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<ArtifactGroupTypeEnum, Map<String, List<ArtifactDefinition>>> 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<byte[], ResponseFormat> 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<Void> writeComponentInterface( - Either<ToscaRepresentation,ToscaError> interfaceRepresentation, String fileName, ZipWriter zw) { + Either<ToscaRepresentation, ToscaError> interfaceRepresentation, String fileName, ZipWriter zw) { Either<byte[], ToscaError> 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<String, ArtifactDefinition> toscaArtifacts = new HashMap<>(); + Map<String, ArtifactDefinition> 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)); |