use of org.eclipse.winery.repository.export.entries.CsarEntry 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;
}
use of org.eclipse.winery.repository.export.entries.CsarEntry 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;
}
use of org.eclipse.winery.repository.export.entries.CsarEntry in project winery by eclipse.
the class CsarExporter method immutablyStoreRefFiles.
/**
* Stores all files listed in the map in the immutable file storage, and updates the CsarContentProperties of each
* file to contain its address in the aforementioned storage.
*
* @param filesToStore a map of the CsarContentProperties of all files to be stored in the CSAR and their contents.
*/
private void immutablyStoreRefFiles(Map<CsarContentProperties, CsarEntry> filesToStore) throws AccountabilityException, ExecutionException, InterruptedException, IOException {
AccountabilityManager manager = AccountabilityManagerFactory.getAccountabilityManager();
Map<String, InputStream> filesMap = new HashMap<>();
for (Map.Entry<CsarContentProperties, CsarEntry> entry : filesToStore.entrySet()) {
filesMap.put(entry.getKey().getPathInsideCsar(), entry.getValue().getInputStream());
}
// store all files in immutable storage (already stored files will get their same old address)
Map<String, String> addressMap = manager.storeState(filesMap).get();
filesToStore.keySet().forEach((CsarContentProperties properties) -> properties.setImmutableAddress(addressMap.get(properties.getPathInsideCsar())));
}
use of org.eclipse.winery.repository.export.entries.CsarEntry in project winery by eclipse.
the class ToscaExportUtil method writeTOSCA.
public void writeTOSCA(IRepository repository, DefinitionsChildId id, Map<String, Object> conf, OutputStream outputStream) throws RepositoryCorruptException, IOException {
CsarEntry csarEntry = getExportableEntry(repository, id, conf);
csarEntry.writeToOutputStream(outputStream);
}
use of org.eclipse.winery.repository.export.entries.CsarEntry 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);
}
}
Aggregations