Search in sources :

Example 1 with CsarContentProperties

use of org.eclipse.winery.repository.export.CsarContentProperties 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 CsarContentProperties

use of org.eclipse.winery.repository.export.CsarContentProperties in project winery by eclipse.

the class YamlToscaExportUtil method putRemoteRefAsReferencedItemInCsar.

/**
 * Puts the given reference as item in the CSAR
 * <p>
 * Thereby, it uses the global variable referencesToPathInCSARMap
 */
protected String putRemoteRefAsReferencedItemInCsar(URL url, String typePath, String artifactName) {
    RemoteRefBasedCsarEntry ref = new RemoteRefBasedCsarEntry(url);
    String fileName = FilenameUtils.getName(url.getPath());
    String type = StringUtils.removeEnd(typePath, "/");
    String path = StringUtils.join(Arrays.asList(type, "files", artifactName, fileName), "/");
    this.referencesToPathInCSARMap.put(new CsarContentProperties(path), ref);
    return path;
}
Also used : CsarContentProperties(org.eclipse.winery.repository.export.CsarContentProperties) RemoteRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RemoteRefBasedCsarEntry)

Example 3 with CsarContentProperties

use of org.eclipse.winery.repository.export.CsarContentProperties in project winery by eclipse.

the class YamlExporter method writeCsar.

/**
 * Writes a complete CSAR containing all necessary things reachable from the given service template
 *
 * @param entryId the id of the service template to export
 * @param out     the output stream to write to
 * @return the TOSCA meta file for the generated Csar
 */
@Override
public String writeCsar(DefinitionsChildId entryId, OutputStream out, Map<String, Object> exportConfiguration) throws IOException, RepositoryCorruptException {
    LOGGER.trace("Starting CSAR export with {}", entryId.toString());
    Map<CsarContentProperties, CsarEntry> refMap = new HashMap<>();
    YamlToscaExportUtil exporter = new YamlToscaExportUtil();
    ExportedState exportedState = new ExportedState();
    DefinitionsChildId currentId = entryId;
    Collection<DefinitionsChildId> referencedIds;
    // Process definitions and referenced files
    do {
        String definitionsPathInsideCSAR = getDefinitionsPathInsideCSAR(repository, currentId);
        CsarContentProperties definitionsFileProperties = new CsarContentProperties(definitionsPathInsideCSAR);
        if (!YamlRepository.ROOT_TYPE_QNAME.equals(currentId.getQName())) {
            referencedIds = exporter.processTOSCA(repository, currentId, definitionsFileProperties, refMap, exportConfiguration);
            // for each entryId add license and readme files (if they exist) to the refMap
            addLicenseAndReadmeFiles(currentId, refMap);
            exportedState.flagAsExported(currentId);
            exportedState.flagAsExportRequired(referencedIds);
        }
        currentId = exportedState.pop();
    } while (currentId != null);
    // Archive creation
    try (final ZipOutputStream zos = new ZipOutputStream(out)) {
        // write all referenced files
        for (Map.Entry<CsarContentProperties, CsarEntry> entry : refMap.entrySet()) {
            CsarContentProperties fileProperties = entry.getKey();
            CsarEntry ref = entry.getValue();
            LOGGER.trace("Creating {}", fileProperties.getPathInsideCsar());
            if (ref instanceof RepositoryRefBasedCsarEntry && ((RepositoryRefBasedCsarEntry) ref).getReference().getParent() instanceof DirectoryId) {
                addArtifactTemplateToZipFile(zos, (RepositoryRefBasedCsarEntry) ref, fileProperties);
            } else {
                addCsarEntryToArchive(zos, ref, fileProperties);
            }
        }
        // create manifest file and add it to archive
        return this.addManifest(repository, entryId, refMap, zos, exportConfiguration);
    }
}
Also used : 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) HashMap(java.util.HashMap) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) CsarContentProperties(org.eclipse.winery.repository.export.CsarContentProperties) RepositoryRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry) DirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId) ZipOutputStream(java.util.zip.ZipOutputStream) HashMap(java.util.HashMap) Map(java.util.Map) ExportedState(org.eclipse.winery.repository.export.ExportedState)

Aggregations

CsarContentProperties (org.eclipse.winery.repository.export.CsarContentProperties)3 RemoteRefBasedCsarEntry (org.eclipse.winery.repository.export.entries.RemoteRefBasedCsarEntry)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)2 DirectoryId (org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId)2 ExportedState (org.eclipse.winery.repository.export.ExportedState)2 CsarEntry (org.eclipse.winery.repository.export.entries.CsarEntry)2 DefinitionsBasedCsarEntry (org.eclipse.winery.repository.export.entries.DefinitionsBasedCsarEntry)2 DocumentBasedCsarEntry (org.eclipse.winery.repository.export.entries.DocumentBasedCsarEntry)2 RepositoryRefBasedCsarEntry (org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry)2 XMLDefinitionsBasedCsarEntry (org.eclipse.winery.repository.export.entries.XMLDefinitionsBasedCsarEntry)2 YAMLDefinitionsBasedCsarEntry (org.eclipse.winery.repository.yaml.export.entries.YAMLDefinitionsBasedCsarEntry)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Collection (java.util.Collection)1 ZipEntry (java.util.zip.ZipEntry)1 IOUtils (org.apache.commons.io.IOUtils)1