Search in sources :

Example 1 with AccountabilityException

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);
    }
}
Also used : ModelProvenanceElement(org.eclipse.winery.accountability.model.ModelProvenanceElement) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) AccountabilityManager(org.eclipse.winery.accountability.AccountabilityManager) Path(javax.ws.rs.Path) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) LoggerFactory(org.slf4j.LoggerFactory) FileProvenanceElement(org.eclipse.winery.accountability.model.FileProvenanceElement) ArrayList(java.util.ArrayList) EncodingUtil(org.eclipse.winery.model.ids.EncodingUtil) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Charset(java.nio.charset.Charset) Consumes(javax.ws.rs.Consumes) VersionSupport(org.eclipse.winery.model.version.VersionSupport) AccountabilityManagerFactory(org.eclipse.winery.accountability.AccountabilityManagerFactory) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) AuthorizationNode(org.eclipse.winery.accountability.model.authorization.AuthorizationNode) IOException(java.io.IOException) StreamingOutput(javax.ws.rs.core.StreamingOutput) AccountabilityException(org.eclipse.winery.accountability.exceptions.AccountabilityException) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Response(javax.ws.rs.core.Response) AuthorizationInfo(org.eclipse.winery.accountability.model.authorization.AuthorizationInfo) WebApplicationException(javax.ws.rs.WebApplicationException) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) AccountabilityException(org.eclipse.winery.accountability.exceptions.AccountabilityException) QName(javax.xml.namespace.QName) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ExecutionException(java.util.concurrent.ExecutionException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with AccountabilityException

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);
    }
}
Also used : ModelProvenanceElement(org.eclipse.winery.accountability.model.ModelProvenanceElement) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) AccountabilityManager(org.eclipse.winery.accountability.AccountabilityManager) Path(javax.ws.rs.Path) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) LoggerFactory(org.slf4j.LoggerFactory) FileProvenanceElement(org.eclipse.winery.accountability.model.FileProvenanceElement) ArrayList(java.util.ArrayList) EncodingUtil(org.eclipse.winery.model.ids.EncodingUtil) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Charset(java.nio.charset.Charset) Consumes(javax.ws.rs.Consumes) VersionSupport(org.eclipse.winery.model.version.VersionSupport) AccountabilityManagerFactory(org.eclipse.winery.accountability.AccountabilityManagerFactory) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) AuthorizationNode(org.eclipse.winery.accountability.model.authorization.AuthorizationNode) IOException(java.io.IOException) StreamingOutput(javax.ws.rs.core.StreamingOutput) AccountabilityException(org.eclipse.winery.accountability.exceptions.AccountabilityException) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Response(javax.ws.rs.core.Response) AuthorizationInfo(org.eclipse.winery.accountability.model.authorization.AuthorizationInfo) WebApplicationException(javax.ws.rs.WebApplicationException) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) AccountabilityException(org.eclipse.winery.accountability.exceptions.AccountabilityException) QName(javax.xml.namespace.QName) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ExecutionException(java.util.concurrent.ExecutionException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with AccountabilityException

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;
}
Also used : BlockchainException(org.eclipse.winery.accountability.exceptions.BlockchainException) AccountabilityException(org.eclipse.winery.accountability.exceptions.AccountabilityException) BlockchainAccess(org.eclipse.winery.accountability.blockchain.BlockchainAccess) ImmutableStorageProvider(org.eclipse.winery.accountability.storage.ImmutableStorageProvider) AccountabilityConfigurationObject(org.eclipse.winery.common.configuration.AccountabilityConfigurationObject)

Example 4 with AccountabilityException

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);
    }
}
Also used : Path(java.nio.file.Path) ZipInputStream(java.util.zip.ZipInputStream) AccountabilityException(org.eclipse.winery.accountability.exceptions.AccountabilityException) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) File(java.io.File) TOSCAMetaFile(org.eclipse.winery.model.csar.toscametafile.TOSCAMetaFile)

Example 5 with AccountabilityException

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);
    }
}
Also used : 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) HashMap(java.util.HashMap) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) RepositoryRefBasedCsarEntry(org.eclipse.winery.repository.export.entries.RepositoryRefBasedCsarEntry) AccountabilityException(org.eclipse.winery.accountability.exceptions.AccountabilityException) ServiceTemplateSelfServiceFilesDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ServiceTemplateSelfServiceFilesDirectoryId) DirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId) ZipOutputStream(java.util.zip.ZipOutputStream) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

AccountabilityException (org.eclipse.winery.accountability.exceptions.AccountabilityException)5 IOException (java.io.IOException)3 ExecutionException (java.util.concurrent.ExecutionException)3 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)3 InputStream (java.io.InputStream)2 Charset (java.nio.charset.Charset)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Objects (java.util.Objects)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 QueryParam (javax.ws.rs.QueryParam)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 MediaType (javax.ws.rs.core.MediaType)2 Response (javax.ws.rs.core.Response)2 StreamingOutput (javax.ws.rs.core.StreamingOutput)2 QName (javax.xml.namespace.QName)2