diff options
author | franciscovila <javier.paradela.vila@est.tech> | 2022-03-15 08:29:04 +0000 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2022-03-28 15:42:52 +0000 |
commit | 28e7f0f13e3d7b75750a449c9bda6c0d4a1986ce (patch) | |
tree | 82141658406c58d0846d937da895c6bb71a225c5 /openecomp-be/lib/openecomp-tosca-lib/src/main | |
parent | 88fdc6dd75f1119ffa8e54dbfd721b6ed722b779 (diff) |
Copy entry_defintion_type to TOSCA.meta
Copy "entry_defintion_type" from the
manifest file of ASD package into the
generated TOSCA.meta for the VSP
package
Issue-ID: SDC-3884
Signed-off-by: franciscovila <javier.paradela.vila@est.tech>
Change-Id: I35c4d0180529e8c60edc714aecadd0150cbd2c03
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib/src/main')
2 files changed, 38 insertions, 23 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaFileOutputService.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaFileOutputService.java index 334ff6f567..54f7890888 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaFileOutputService.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaFileOutputService.java @@ -26,7 +26,7 @@ public interface ToscaFileOutputService { byte[] createOutputFile(ToscaServiceModel toscaServiceModel, FileContentHandler externalArtifacts); - String createMetaFile(String entryDefinitionsFileName); + String createMetaFile(String entryDefinitionsFileName, boolean isAsdPackage); String getArtifactsFolderName(); } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java index d0df54b105..1fb3858717 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java @@ -15,20 +15,6 @@ */ package org.openecomp.sdc.tosca.services.impl; -import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.CREATED_BY_ENTRY; -import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.CSAR_VERSION_ENTRY; -import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.ENTRY_DEFINITIONS; -import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.TOSCA_META_FILE_VERSION_ENTRY; - -import java.io.BufferedOutputStream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.Map; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; import org.apache.commons.io.IOUtils; import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.core.utilities.file.FileContentHandler; @@ -36,11 +22,28 @@ import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.tosca.csar.AsdPackageHelper; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.tosca.exceptions.CsarCreationErrorBuilder; import org.openecomp.sdc.tosca.exceptions.CsarMissingEntryPointErrorBuilder; import org.openecomp.sdc.tosca.services.ToscaFileOutputService; +import java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +import static org.openecomp.sdc.tosca.csar.ManifestTokenType.ENTRY_DEFINITION_TYPE; +import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.CREATED_BY_ENTRY; +import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.CSAR_VERSION_ENTRY; +import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.ENTRY_DEFINITIONS; +import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.TOSCA_META_FILE_VERSION_ENTRY; + public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService { static final String EXTERNAL_ARTIFACTS_FOLDER_NAME = "Artifacts"; @@ -56,6 +59,11 @@ public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService { private static final String SPACE = " "; private static final String FILE_SEPARATOR = File.separator; private static final Logger logger = LoggerFactory.getLogger(ToscaFileOutputServiceCsarImpl.class); + private final AsdPackageHelper asdPackageHelper; + + public ToscaFileOutputServiceCsarImpl(AsdPackageHelper asdPackageHelper) { + this.asdPackageHelper = asdPackageHelper; + } @Override public byte[] createOutputFile(ToscaServiceModel toscaServiceModel, FileContentHandler externalArtifacts) { @@ -63,13 +71,13 @@ public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService { try (ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(baos))) { packDefinitions(zos, toscaServiceModel.getServiceTemplates()); FileContentHandler artifactFiles = toscaServiceModel.getArtifactFiles(); - if (artifactFiles != null && !artifactFiles.isEmpty()) { - packArtifacts(zos, artifactFiles); - } if (toscaServiceModel.getEntryDefinitionServiceTemplate() == null) { throw new CoreException(new CsarMissingEntryPointErrorBuilder().build()); } - createAndPackToscaMetaFile(zos, toscaServiceModel.getEntryDefinitionServiceTemplate()); + if (artifactFiles != null) { + packArtifacts(zos, artifactFiles); + } + createAndPackToscaMetaFile(zos, toscaServiceModel.getEntryDefinitionServiceTemplate(), isAsdPackage(artifactFiles)); if (externalArtifacts != null) { packExternalArtifacts(zos, externalArtifacts); } @@ -80,11 +88,12 @@ public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService { } @Override - public String createMetaFile(String entryDefinitionsFileName) { + public String createMetaFile(String entryDefinitionsFileName, boolean isAsdPackage) { return TOSCA_META_FILE_VERSION_ENTRY.getName() + META_FILE_DELIMITER + SPACE + TOSCA_META_FILE_VERSION_VALUE + System.lineSeparator() + CSAR_VERSION_ENTRY.getName() + META_FILE_DELIMITER + SPACE + CSAR_VERSION_VALUE + System.lineSeparator() + CREATED_BY_ENTRY.getName() + META_FILE_DELIMITER + SPACE + CREATED_BY_VALUE + System.lineSeparator() + ENTRY_DEFINITIONS.getName() + META_FILE_DELIMITER + SPACE - + DEFINITIONS_FOLDER_NAME + FILE_SEPARATOR + entryDefinitionsFileName; + + DEFINITIONS_FOLDER_NAME + FILE_SEPARATOR + entryDefinitionsFileName + + (isAsdPackage ? System.lineSeparator() + ENTRY_DEFINITION_TYPE.getToken() + META_FILE_DELIMITER + SPACE + "asd" : ""); } @Override @@ -92,8 +101,14 @@ public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService { return ARTIFACTS_FOLDER_NAME; } - private void createAndPackToscaMetaFile(ZipOutputStream zos, String entryDefinitionsFileName) throws IOException { - String metaFile = createMetaFile(entryDefinitionsFileName); + private boolean isAsdPackage(FileContentHandler artifactFiles){ + + return artifactFiles != null && !artifactFiles.isEmpty() && asdPackageHelper.isAsdPackage(artifactFiles); + + } + + private void createAndPackToscaMetaFile(ZipOutputStream zos, String entryDefinitionsFileName, boolean isAsdPackage) throws IOException { + String metaFile = createMetaFile(entryDefinitionsFileName, isAsdPackage); zos.putNextEntry(new ZipEntry(TOSCA_META_FOLDER_NAME + FILE_SEPARATOR + TOSCA_META_FILE_NAME)); writeBytesToZip(zos, new ByteArrayInputStream(metaFile.getBytes())); } |