use of org.eclipse.winery.accountability.exceptions.AccountabilityException in project winery by eclipse.
the class AccountabilityResource method getFileHistory.
@GET
@Path("fileHistory")
@Produces(MediaType.APPLICATION_JSON)
public List<FileProvenanceElement> getFileHistory(@QueryParam("fileId") String fileId) {
ServiceTemplateId serviceTemplateId = new ServiceTemplateId(new QName(provenanceId));
String qNameWithComponentVersionOnly = VersionSupport.getQNameWithComponentVersionOnly(serviceTemplateId);
Objects.requireNonNull(fileId);
String fileIdDecoded = EncodingUtil.URLdecode(fileId);
try {
return getAccountabilityManager().getHistory(qNameWithComponentVersionOnly, fileIdDecoded).exceptionally(error -> null).get();
} catch (InterruptedException | ExecutionException | AccountabilityException e) {
LOGGER.error("Cannot history of file {}. Reason: {}", fileId, e.getMessage());
throw createException(e);
}
}
use of org.eclipse.winery.accountability.exceptions.AccountabilityException in project winery by eclipse.
the class AccountabilityResource method getModelHistory.
@GET
@Path("modelHistory")
@Produces(MediaType.APPLICATION_JSON)
public List<ModelProvenanceElement> getModelHistory() {
ServiceTemplateId serviceTemplateId = new ServiceTemplateId(new QName(provenanceId));
String qNameWithComponentVersionOnly = VersionSupport.getQNameWithComponentVersionOnly(serviceTemplateId);
try {
return getAccountabilityManager().getHistory(qNameWithComponentVersionOnly).exceptionally(error -> null).get();
} catch (InterruptedException | ExecutionException | AccountabilityException e) {
LOGGER.error("Cannot get history of model. Reason: {}", e.getMessage());
throw createException(e);
}
}
use of org.eclipse.winery.accountability.exceptions.AccountabilityException in project winery by eclipse.
the class AccountabilityManagerFactory method getAccountabilityManager.
public static AccountabilityManager getAccountabilityManager() throws AccountabilityException {
if (Objects.isNull(accountabilityManager)) {
try {
AccountabilityConfigurationObject properties = Environments.getInstance().getAccountabilityConfig();
Environments.getInstance().addConfigurationChangeListener(() -> {
BlockchainFactory.reset();
ImmutableStorageProviderFactory.reset();
});
BlockchainAccess blockchain = BlockchainFactory.getBlockchainAccess(BlockchainFactory.AvailableBlockchains.ETHEREUM, properties);
ImmutableStorageProvider storageProvider = ImmutableStorageProviderFactory.getStorageProvider(ImmutableStorageProviderFactory.AvailableImmutableStorages.SWARM, properties);
accountabilityManager = new AccountabilityManagerImpl(blockchain, storageProvider);
} catch (BlockchainException e) {
String msg = "Could not instantiate accountability layer: " + e.getMessage();
LOGGER.error(msg, e);
throw new AccountabilityException(msg, e);
}
}
return accountabilityManager;
}
use of org.eclipse.winery.accountability.exceptions.AccountabilityException in project winery by eclipse.
the class CsarImporter method readCSAR.
/**
* Reads the CSAR from the given inputStream
*
* @param in the inputStream to read from
* @param options the set of options applicable for importing the csar
*/
public ImportMetaInformation readCSAR(InputStream in, CsarImportOptions options) throws IOException, AccountabilityException, ExecutionException, InterruptedException {
// we have to extract the file to a temporary directory as
// the .definitions file does not necessarily have to be the first entry in the archive
Path csarDir = Files.createTempDirectory("winery");
Map<String, File> fileMap = null;
try (ZipInputStream zis = new ZipInputStream(in)) {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
if (!entry.isDirectory()) {
Path targetPath = csarDir.resolve(entry.getName());
Files.createDirectories(targetPath.getParent());
Files.copy(zis, targetPath);
if (options.isValidate()) {
if (Objects.isNull(fileMap)) {
fileMap = new HashMap<>();
}
fileMap.put(entry.getName(), targetPath.toFile());
}
}
}
return this.importFromDir(csarDir, options, fileMap);
} catch (AccountabilityException e) {
LOGGER.debug("Error while checking the accountability of the CSAR");
throw e;
} catch (IOException e) {
CsarImporter.LOGGER.debug("Could not import CSAR", e);
throw e;
} finally {
// cleanup: delete all contents of the temporary directory
FileUtils.forceDelete(csarDir);
}
}
use of org.eclipse.winery.accountability.exceptions.AccountabilityException in project winery by eclipse.
the class CsarExporter 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
*/
public String writeCsar(DefinitionsChildId entryId, OutputStream out, Map<String, Object> exportConfiguration) throws IOException, RepositoryCorruptException, InterruptedException, AccountabilityException, ExecutionException {
CsarExporter.LOGGER.trace("Starting CSAR export with {}", entryId.toString());
Map<CsarContentProperties, CsarEntry> refMap = new HashMap<>();
ToscaExportUtil exporter = new ToscaExportUtil();
ExportedState exportedState = new ExportedState();
DefinitionsChildId currentId = entryId;
Collection<DefinitionsChildId> referencedIds;
if (entryId.isSelfContained()) {
exportConfiguration.put(CsarExportConfiguration.INCLUDE_HASHES.name(), true);
}
// Process definitions and referenced files
do {
String definitionsPathInsideCSAR = CsarExporter.getDefinitionsPathInsideCSAR(repository, currentId);
CsarContentProperties definitionsFileProperties = new CsarContentProperties(definitionsPathInsideCSAR);
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);
// if we export a ServiceTemplate, data for the self-service portal might exist
if (entryId instanceof ServiceTemplateId) {
ServiceTemplateId serviceTemplateId = (ServiceTemplateId) entryId;
this.addSelfServiceMetaData(serviceTemplateId, refMap);
this.addSelfServiceFiles(serviceTemplateId, refMap);
}
this.addNamespacePrefixes(refMap);
// Calculate hashes for referenced files if necessary
if (exportConfiguration.containsKey(CsarExportConfiguration.INCLUDE_HASHES.name())) {
LOGGER.trace("Calculating checksum for {} files.", refMap.size());
calculateFileHashes(refMap);
}
// Store referenced files in immutable file storage if necessary
if (exportConfiguration.containsKey(CsarExportConfiguration.STORE_IMMUTABLY.name())) {
try {
LOGGER.trace("Storing {} files in the immutable file storage", refMap.size());
immutablyStoreRefFiles(refMap);
} catch (InterruptedException | ExecutionException | AccountabilityException e) {
LOGGER.error("Failed to store files in immutable storage. Reason: {}", e.getMessage());
throw e;
}
}
// 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();
CsarExporter.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(entryId, refMap, zos, exportConfiguration);
}
}
Aggregations