Search in sources :

Example 1 with DocumentBasedCsarEntry

use of org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry in project winery by eclipse.

the class YamlExporter method addManifest.

private String addManifest(IRepository repository, DefinitionsChildId id, Map<CsarContentProperties, CsarEntry> refMap, ZipOutputStream out, Map<String, Object> exportConfiguration) throws IOException {
    String entryDefinitionsReference = getDefinitionsPathInsideCSAR(repository, id);
    out.putNextEntry(new ZipEntry("TOSCA-Metadata/TOSCA.meta"));
    StringBuilder stringBuilder = new StringBuilder();
    // Setting Versions
    stringBuilder.append(TOSCA_META_FILE_VERSION).append(": ").append(TOSCA_META_FILE_VERSION_VALUE).append("\n");
    stringBuilder.append(CSAR_VERSION).append(": ").append(CSAR_VERSION_VALUE_FOR_YAML).append("\n");
    stringBuilder.append(CREATED_BY).append(": Winery ").append(Environments.getInstance().getVersion()).append("\n");
    // Winery currently is unaware of tDefinitions, therefore, we use the
    // name of the service template
    stringBuilder.append(ENTRY_DEFINITIONS).append(": ").append(entryDefinitionsReference).append("\n");
    stringBuilder.append("\n");
    assert (refMap.keySet().stream().anyMatch(fileProperties -> fileProperties.getPathInsideCsar().equals(entryDefinitionsReference)));
    // Setting other files, mainly files belonging to artifacts
    for (Map.Entry<CsarContentProperties, CsarEntry> item : refMap.entrySet()) {
        final CsarEntry csarEntry = item.getValue();
        final CsarContentProperties fileProperties = item.getKey();
        stringBuilder.append(NAME).append(": ").append(fileProperties.getPathInsideCsar()).append("\n");
        String mimeType;
        if (csarEntry instanceof DocumentBasedCsarEntry) {
            mimeType = MimeTypes.MIMETYPE_XSD;
        } else if (csarEntry instanceof XMLDefinitionsBasedCsarEntry || csarEntry instanceof YAMLDefinitionsBasedCsarEntry || csarEntry instanceof DefinitionsBasedCsarEntry) {
            mimeType = MimeTypes.MIMETYPE_TOSCA_DEFINITIONS;
        } else if (csarEntry instanceof RemoteRefBasedCsarEntry) {
            mimeType = repository.getMimeType((RemoteRefBasedCsarEntry) csarEntry);
        } else {
            mimeType = repository.getMimeType(((RepositoryRefBasedCsarEntry) csarEntry).getReference());
        }
        stringBuilder.append(CONTENT_TYPE).append(": ").append(mimeType).append("\n");
        stringBuilder.append("\n");
    }
    String manifestString = stringBuilder.toString();
    out.write(manifestString.getBytes());
    out.closeEntry();
    return manifestString;
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) MimeTypes(org.eclipse.winery.common.constants.MimeTypes) DirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId) RemoteRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RemoteRefBasedCsarEntry) DefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.DefinitionsBasedCsarEntry) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CSAR_VERSION_VALUE_FOR_YAML(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.CSAR_VERSION_VALUE_FOR_YAML) TOSCA_META_FILE_VERSION_VALUE(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.TOSCA_META_FILE_VERSION_VALUE) CsarContentProperties(org.eclipse.winery.repository.export.CsarContentProperties) DocumentBasedCsarEntry(org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry) YamlRepository(org.eclipse.winery.repository.yaml.YamlRepository) Map(java.util.Map) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) YAMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.yaml.export.entries.YAMLDefinitionsBasedCsarEntry) ZipEntry(java.util.zip.ZipEntry) CsarEntry(org.eclipse.winery.repository.export.entries.CsarEntry) OutputStream(java.io.OutputStream) CsarExporter(org.eclipse.winery.repository.export.CsarExporter) Logger(org.slf4j.Logger) Environments(org.eclipse.winery.common.configuration.Environments) CREATED_BY(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.CREATED_BY) ENTRY_DEFINITIONS(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.ENTRY_DEFINITIONS) Collection(java.util.Collection) Constants(org.eclipse.winery.common.Constants) ExportedState(org.eclipse.winery.repository.export.ExportedState) IOException(java.io.IOException) XMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry) CSAR_VERSION(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.CSAR_VERSION) IOUtils(org.apache.commons.io.IOUtils) IRepository(org.eclipse.winery.repository.backend.IRepository) RepositoryCorruptException(org.eclipse.winery.repository.exceptions.RepositoryCorruptException) TOSCA_META_FILE_VERSION(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.TOSCA_META_FILE_VERSION) NAME(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.NAME) RepositoryRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry) InputStream(java.io.InputStream) CONTENT_TYPE(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.CONTENT_TYPE) RemoteRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RemoteRefBasedCsarEntry) DefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.DefinitionsBasedCsarEntry) DocumentBasedCsarEntry(org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry) YAMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.yaml.export.entries.YAMLDefinitionsBasedCsarEntry) CsarEntry(org.eclipse.winery.repository.export.entries.CsarEntry) XMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry) RepositoryRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry) DefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.DefinitionsBasedCsarEntry) YAMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.yaml.export.entries.YAMLDefinitionsBasedCsarEntry) XMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry) ZipEntry(java.util.zip.ZipEntry) CsarContentProperties(org.eclipse.winery.repository.export.CsarContentProperties) YAMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.yaml.export.entries.YAMLDefinitionsBasedCsarEntry) DocumentBasedCsarEntry(org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry) RepositoryRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry) RemoteRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RemoteRefBasedCsarEntry) HashMap(java.util.HashMap) Map(java.util.Map) XMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry)

Example 2 with DocumentBasedCsarEntry

use of org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry in project winery by eclipse.

the class CsarExporter method addManifest.

private String addManifest(DefinitionsChildId id, Map<CsarContentProperties, CsarEntry> refMap, ZipOutputStream out, Map<String, Object> exportConfiguration) throws IOException {
    String entryDefinitionsReference = CsarExporter.getDefinitionsPathInsideCSAR(repository, id);
    out.putNextEntry(new ZipEntry("TOSCA-Metadata/TOSCA.meta"));
    StringBuilder stringBuilder = new StringBuilder();
    // Setting Versions
    stringBuilder.append(TOSCA_META_VERSION).append(": 1.0").append("\n");
    stringBuilder.append(CSAR_VERSION).append(": 1.0").append("\n");
    stringBuilder.append(CREATED_BY).append(": Winery ").append(Environments.getInstance().getVersion()).append("\n");
    // Winery currently is unaware of tDefinitions, therefore, we use the
    // name of the service template
    stringBuilder.append(ENTRY_DEFINITIONS).append(": ").append(entryDefinitionsReference).append("\n");
    stringBuilder.append("\n");
    assert (refMap.keySet().stream().anyMatch(fileProperties -> fileProperties.getPathInsideCsar().equals(entryDefinitionsReference)));
    // Setting other files, mainly files belonging to artifacts
    for (Map.Entry<CsarContentProperties, CsarEntry> item : refMap.entrySet()) {
        final CsarEntry csarEntry = item.getValue();
        final CsarContentProperties fileProperties = item.getKey();
        stringBuilder.append(NAME).append(": ").append(fileProperties.getPathInsideCsar()).append("\n");
        String mimeType;
        if (csarEntry instanceof DocumentBasedCsarEntry) {
            mimeType = MimeTypes.MIMETYPE_XSD;
        } else if (csarEntry instanceof XMLDefinitionsBasedCsarEntry || csarEntry instanceof DefinitionsBasedCsarEntry) {
            mimeType = MimeTypes.MIMETYPE_TOSCA_DEFINITIONS;
        } else {
            mimeType = repository.getMimeType(((RepositoryRefBasedCsarEntry) csarEntry).getReference());
        }
        stringBuilder.append(CONTENT_TYPE).append(": ").append(mimeType).append("\n");
        if (exportConfiguration.containsKey(CsarExportConfiguration.INCLUDE_HASHES.name()) && Objects.nonNull(fileProperties.getFileHash())) {
            stringBuilder.append(HASH).append(": ").append(fileProperties.getFileHash()).append("\n");
        }
        if (exportConfiguration.containsKey(CsarExportConfiguration.STORE_IMMUTABLY.name()) && Objects.nonNull(fileProperties.getImmutableAddress())) {
            stringBuilder.append(IMMUTABLE_ADDRESS).append(": ").append(fileProperties.getImmutableAddress()).append("\n");
        }
        stringBuilder.append("\n");
    }
    String manifestString = stringBuilder.toString();
    out.write(manifestString.getBytes());
    out.closeEntry();
    return manifestString;
}
Also used : SortedSet(java.util.SortedSet) MimeTypes(org.eclipse.winery.common.constants.MimeTypes) LoggerFactory(org.slf4j.LoggerFactory) EncodingUtil(org.eclipse.winery.model.ids.EncodingUtil) DirectoryStream(java.nio.file.DirectoryStream) ServiceTemplateSelfServiceFilesDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ServiceTemplateSelfServiceFilesDirectoryId) SelfServiceMetaDataUtils(org.eclipse.winery.repository.backend.SelfServiceMetaDataUtils) SelfContainmentPackager(org.eclipse.winery.repository.backend.selfcontainmentpackager.SelfContainmentPackager) IdNames(org.eclipse.winery.model.ids.IdNames) DocumentBasedCsarEntry(org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry) VersionSupport(org.eclipse.winery.model.version.VersionSupport) Duration(java.time.Duration) Map(java.util.Map) TOSCA_META_VERSION(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.TOSCA_META_VERSION) GenericId(org.eclipse.winery.model.ids.GenericId) Util(org.eclipse.winery.repository.common.Util) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) CsarEntry(org.eclipse.winery.repository.export.entries.CsarEntry) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) CREATED_BY(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.CREATED_BY) ENTRY_DEFINITIONS(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.ENTRY_DEFINITIONS) Collection(java.util.Collection) Constants(org.eclipse.winery.common.Constants) IMMUTABLE_ADDRESS(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.IMMUTABLE_ADDRESS) Options(org.eclipse.winery.model.selfservice.Application.Options) XMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry) AccountabilityException(org.eclipse.winery.accountability.exceptions.AccountabilityException) Objects(java.util.Objects) CSAR_VERSION(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.CSAR_VERSION) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) IRepository(org.eclipse.winery.repository.backend.IRepository) RepositoryCorruptException(org.eclipse.winery.repository.exceptions.RepositoryCorruptException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MediaTypes(org.eclipse.winery.repository.backend.constants.MediaTypes) HASH(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.HASH) NAME(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.NAME) RepositoryRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry) ZipOutputStream(java.util.zip.ZipOutputStream) ApplicationOption(org.eclipse.winery.model.selfservice.ApplicationOption) AccountabilityManager(org.eclipse.winery.accountability.AccountabilityManager) DirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId) LocalDateTime(java.time.LocalDateTime) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) DefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.DefinitionsBasedCsarEntry) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) TArtifactReference(org.eclipse.winery.model.tosca.TArtifactReference) Application(org.eclipse.winery.model.selfservice.Application) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) OutputStream(java.io.OutputStream) AccountabilityManagerFactory(org.eclipse.winery.accountability.AccountabilityManagerFactory) Logger(org.slf4j.Logger) Files(java.nio.file.Files) Environments(org.eclipse.winery.common.configuration.Environments) GitInfo(org.eclipse.winery.repository.GitInfo) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) File(java.io.File) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) ExecutionException(java.util.concurrent.ExecutionException) NamespacesId(org.eclipse.winery.model.ids.admin.NamespacesId) Paths(java.nio.file.Paths) SelfServiceMetaDataId(org.eclipse.winery.repository.datatypes.ids.elements.SelfServiceMetaDataId) HashingUtil(org.eclipse.winery.common.HashingUtil) Git(org.eclipse.jgit.api.Git) InputStream(java.io.InputStream) CONTENT_TYPE(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.CONTENT_TYPE) DocumentBasedCsarEntry(org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry) DocumentBasedCsarEntry(org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry) CsarEntry(org.eclipse.winery.repository.export.entries.CsarEntry) XMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry) RepositoryRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry) DefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.DefinitionsBasedCsarEntry) XMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry) DefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.DefinitionsBasedCsarEntry) ZipEntry(java.util.zip.ZipEntry) Map(java.util.Map) HashMap(java.util.HashMap) XMLDefinitionsBasedCsarEntry(org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry)

Example 3 with DocumentBasedCsarEntry

use of org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry in project winery by eclipse.

the class ToscaExportUtil method exportEntityType.

protected void exportEntityType(TDefinitions entryDefinitions, URI uri, DefinitionsChildId tcId) {
    TEntityType entityType = (TEntityType) entryDefinitions.getElement();
    // we have an entity type with a possible properties definition
    WinerysPropertiesDefinition wpd = entityType.getWinerysPropertiesDefinition();
    if (wpd != null) {
        if (wpd.getIsDerivedFromXSD() == null) {
            // Write WPD only to file if it exists and is NOT derived from an XSD (which may happen during import)
            String wrapperElementNamespace = wpd.getNamespace();
            String wrapperElementLocalName = wpd.getElementName();
            // BEGIN: add import and put into CSAR
            TImport imp = new TImport();
            entryDefinitions.getImport().add(imp);
            // fill known import values
            imp.setImportType(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            imp.setNamespace(wrapperElementNamespace);
            // add "winerysPropertiesDefinition" flag to import tag to support
            Map<QName, String> otherAttributes = imp.getOtherAttributes();
            otherAttributes.put(QNames.QNAME_WINERYS_PROPERTIES_DEFINITION_ATTRIBUTE, "true");
            // Determine location
            String loc = BackendUtils.getImportLocationForWinerysPropertiesDefinitionXSD((EntityTypeId) tcId, uri, wrapperElementLocalName);
            if (uri == null) {
                ToscaExportUtil.LOGGER.trace("CSAR Export mode. Putting XSD into CSAR");
                // CSAR Export mode
                // XSD has to be put into the CSAR
                Document document = ModelUtilities.getWinerysPropertiesDefinitionXsdAsDocument(wpd);
                // loc in import is URL encoded, loc on filesystem isn't
                String locInCSAR = EncodingUtil.URLdecode(loc);
                // furthermore, the path has to start from the root of the CSAR; currently, it starts from Definitions/
                locInCSAR = locInCSAR.substring(3);
                ToscaExportUtil.LOGGER.trace("Location in CSAR: {}", locInCSAR);
                CsarContentProperties csarContentProperties = new CsarContentProperties(locInCSAR);
                this.referencesToPathInCSARMap.put(csarContentProperties, new DocumentBasedCsarEntry(document));
            }
            imp.setLocation(loc);
            // END: add import and put into CSAR
            // BEGIN: generate TOSCA conforming PropertiesDefinition
            // Winerys properties definitions are serialized as an XSD.
            // As such their TOSCA representation is a type reference, so we generate that here.
            // Of course that breaks when we export as YAML, but this exporter basically targets XML in the first place
            // TODO: future work — deal with WPD when exporting to YAML
            // (a map[string, string] can be represented as a TDataType)
            TEntityType.XmlTypeDefinition propertiesDefinition = new TEntityType.XmlTypeDefinition();
            propertiesDefinition.setType(new QName(wrapperElementNamespace, wrapperElementLocalName));
            entityType.setProperties(propertiesDefinition);
        // END: generate TOSCA conforming PropertiesDefinition
        } else {
        // otherwise WPD exists, but is derived from XSD
        // we DO NOT have to remove the winery properties definition from the output to allow "debugging" of the CSAR
        }
    }
}
Also used : DocumentBasedCsarEntry(org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry) TEntityType(org.eclipse.winery.model.tosca.TEntityType) QName(javax.xml.namespace.QName) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition) TImport(org.eclipse.winery.model.tosca.TImport) Document(org.w3c.dom.Document)

Aggregations

DocumentBasedCsarEntry (org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ZipEntry (java.util.zip.ZipEntry)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 IOUtils (org.apache.commons.io.IOUtils)2 Constants (org.eclipse.winery.common.Constants)2 Environments (org.eclipse.winery.common.configuration.Environments)2 MimeTypes (org.eclipse.winery.common.constants.MimeTypes)2 CONTENT_TYPE (org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.CONTENT_TYPE)2 CREATED_BY (org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.CREATED_BY)2 CSAR_VERSION (org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.CSAR_VERSION)2 ENTRY_DEFINITIONS (org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.ENTRY_DEFINITIONS)2 NAME (org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFileAttributes.NAME)2 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)2 IRepository (org.eclipse.winery.repository.backend.IRepository)2