use of org.eclipse.winery.repository.export.CsarExporter in project winery by eclipse.
the class RestUtils method getCSARofSelectedResource.
public static Response getCSARofSelectedResource(final AbstractComponentInstanceResource resource) {
final CsarExporter exporter = new CsarExporter();
StreamingOutput so = output -> {
try {
exporter.writeCsar(RepositoryFactory.getRepository(), resource.getId(), output);
} catch (Exception e) {
throw new WebApplicationException(e);
}
};
StringBuilder sb = new StringBuilder();
sb.append("attachment;filename=\"");
sb.append(resource.getXmlId().getEncoded());
sb.append(org.eclipse.winery.repository.Constants.SUFFIX_CSAR);
sb.append("\"");
return Response.ok().header("Content-Disposition", sb.toString()).type(MimeTypes.MIMETYPE_ZIP).entity(so).build();
}
use of org.eclipse.winery.repository.export.CsarExporter in project winery by eclipse.
the class ConsistencyChecker method checkCsar.
private void checkCsar(DefinitionsChildId id, Path tempCsar, IRepository repository) {
CsarExporter exporter = new CsarExporter(repository);
Map<String, Object> exportConfiguration = new HashMap<>();
try (OutputStream outputStream = Files.newOutputStream(tempCsar, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
try {
exporter.writeCsar(id, outputStream, exportConfiguration);
} catch (IOException e) {
LOGGER.debug("Error during checking ZIP", e);
printAndAddError(id, "I/O error: " + e.getMessage());
return;
} catch (RepositoryCorruptException e) {
LOGGER.debug("Repository is corrupt", e);
printAndAddError(id, "Corrupt: " + e.getMessage());
return;
} catch (Exception e) {
LOGGER.debug("Inner error at writing to temporary CSAR file", e);
printAndAddError(id, e.toString());
return;
}
} catch (Exception e) {
final String error = "Could not write to temp CSAR file";
LOGGER.debug(error, e);
printAndAddError(id, error);
return;
}
try (InputStream inputStream = Files.newInputStream(tempCsar);
ZipInputStream zis = new ZipInputStream(inputStream)) {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
if (configuration.getVerbosity().contains(ConsistencyCheckerVerbosity.OUTPUT_CURRENT_TOSCA_COMPONENT_ID)) {
LOGGER.info("Identified item in CSAR: {}", entry.getName());
}
}
} catch (Exception e) {
final String error = "Could not read from temp CSAR file";
LOGGER.debug(error, e);
printAndAddError(id, error);
}
}
use of org.eclipse.winery.repository.export.CsarExporter in project winery by eclipse.
the class RestUtils method getCsarOfSelectedResource.
/**
* @param options the set of options that are applicable for exporting a csar
*/
public static Response getCsarOfSelectedResource(final AbstractComponentInstanceResource resource, CsarExportOptions options) {
long start = System.currentTimeMillis();
final CsarExporter exporter = new CsarExporter(RepositoryFactory.getRepository());
Map<String, Object> exportConfiguration = new HashMap<>();
StreamingOutput so = output -> {
try {
// check which options are chosen
if (options.isAddToProvenance()) {
// We wait for the accountability layer to confirm the transaction
String result = exporter.writeCsarAndSaveManifestInProvenanceLayer(resource.getId(), output).get();
LOGGER.debug("Stored state in accountability layer in transaction " + result);
} else if (options.isIncludeDependencies() && resource.getId() instanceof ServiceTemplateId) {
SelfContainmentPackager packager = new SelfContainmentPackager(RepositoryFactory.getRepository());
DefinitionsChildId selfContainedVersion = packager.createSelfContainedVersion(resource.getId());
exporter.writeSelfContainedCsar(RepositoryFactory.getRepository(), selfContainedVersion, output, exportConfiguration);
} else {
exporter.writeCsar(resource.getId(), output, exportConfiguration);
}
long duration = (System.currentTimeMillis() - start) / 1000;
LOGGER.debug("CSAR export lasted {} min {} s", (int) duration / 60, duration % 60);
} catch (Exception e) {
LOGGER.error("Error while exporting CSAR", e);
throw new WebApplicationException(e);
}
};
String contentDisposition = String.format("attachment;filename=\"%s%s\"", resource.getXmlId().getEncoded(), Constants.SUFFIX_CSAR);
return Response.ok().header("Content-Disposition", contentDisposition).type(MimeTypes.MIMETYPE_ZIP).entity(so).build();
}
Aggregations