Search in sources :

Example 16 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.

the class DefaultDownloadManager method getStorageReference.

@Override
public Transfer getStorageReference(final ArtifactStore store, final String path, final TransferOperation op) throws IndyWorkflowException {
    //        final ArtifactPathInfo pathInfo = ArtifactPathInfo.parse( path );
    final ContentQuality quality = getQuality(path);
    if (storeIsSuitableFor(store, quality, op)) {
        return getStorageReference(store, path);
    }
    logger.warn("Store {} not suitable for: {}", store, op);
    throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Store is not suitable for this operation.");
}
Also used : ContentQuality(org.commonjava.indy.spi.pkg.ContentQuality) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException)

Example 17 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.

the class DefaultDownloadManager method store.

/*
     * (non-Javadoc)
     * @see org.commonjava.indy.core.rest.util.FileManager#upload(org.commonjava.indy.core.model.DeployPoint,
     * java.lang.String, java.io.InputStream)
     */
@Override
public Transfer store(final ArtifactStore store, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
    if (store.getKey().getType() == StoreType.group) {
        //FIXME: Why is this null? Investigate.
        return null;
    }
    if (store.getKey().getType() != StoreType.hosted) {
        throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Cannot deploy to non-deploy point artifact store: {}.", store.getKey());
    }
    if (storeManager.isReadonly(store)) {
        throw new IndyWorkflowException(ApplicationStatus.METHOD_NOT_ALLOWED.code(), "The store {} is readonly. If you want to store any content to this store, please modify it to non-readonly", store.getKey());
    }
    if (store instanceof HostedRepository) {
        final HostedRepository deploy = (HostedRepository) store;
        //            final ArtifactPathInfo pathInfo = ArtifactPathInfo.parse( path );
        final ContentQuality quality = getQuality(path);
        if (quality != null && quality == ContentQuality.SNAPSHOT) {
            if (!deploy.isAllowSnapshots()) {
                logger.error("Cannot store snapshot in non-snapshot deploy point: {}", deploy.getName());
                throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Cannot store snapshot in non-snapshot deploy point: {}", deploy.getName());
            }
        } else if (!deploy.isAllowReleases()) {
            logger.error("Cannot store release in snapshot-only deploy point: {}", deploy.getName());
            throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Cannot store release in snapshot-only deploy point: {}", deploy.getName());
        }
    }
    try {
        return transfers.store(new ConcreteResource(LocationUtils.toLocation(store), path), stream, eventMetadata);
    } catch (final BadGatewayException e) {
        Location location = e.getLocation();
        KeyedLocation kl = (KeyedLocation) location;
        fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
        logger.warn("Bad gateway: " + e.getMessage(), e);
        throw new IndyWorkflowException("Failed to store path: {} in: {}. Reason: {}", e, path, store, e.getMessage());
    } catch (final TransferTimeoutException e) {
        Location location = e.getLocation();
        KeyedLocation kl = (KeyedLocation) location;
        fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
        logger.warn("Timeout: " + e.getMessage(), e);
        throw new IndyWorkflowException("Failed to store path: {} in: {}. Reason: {}", e, path, store, e.getMessage());
    } catch (final TransferLocationException e) {
        Location location = e.getLocation();
        KeyedLocation kl = (KeyedLocation) location;
        fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
        logger.warn("Location Error: " + e.getMessage(), e);
        throw new IndyWorkflowException("Failed to store path: {} in: {}. Reason: {}", e, path, store, e.getMessage());
    } catch (TransferException e) {
        logger.error(String.format("Failed to store: %s in: %s. Reason: %s", path, store.getKey(), e.getMessage()), e);
        throw new IndyWorkflowException("Failed to store: %s in: %s. Reason: %s", e, path, store.getKey(), e.getMessage());
    }
}
Also used : TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) ContentQuality(org.commonjava.indy.spi.pkg.ContentQuality) TransferException(org.commonjava.maven.galley.TransferException) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) BadGatewayException(org.commonjava.maven.galley.BadGatewayException) TransferLocationException(org.commonjava.maven.galley.TransferLocationException) IndyStoreErrorEvent(org.commonjava.indy.change.event.IndyStoreErrorEvent) HostedRepository(org.commonjava.indy.model.core.HostedRepository) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Location(org.commonjava.maven.galley.model.Location)

Example 18 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.

the class StatsController method getEndpointsListing.

public EndpointViewListing getEndpointsListing(final String baseUri, final UriFormatter uriFormatter) throws IndyWorkflowException {
    final List<ArtifactStore> stores = new ArrayList<ArtifactStore>();
    try {
        stores.addAll(dataManager.getAllArtifactStores());
    } catch (final IndyDataException e) {
        throw new IndyWorkflowException(ApplicationStatus.SERVER_ERROR.code(), "Failed to retrieve all endpoints: {}", e, e.getMessage());
    }
    final List<EndpointView> points = new ArrayList<EndpointView>();
    for (final ArtifactStore store : stores) {
        final StoreKey key = store.getKey();
        final String resourceUri = uriFormatter.formatAbsolutePathTo(baseUri, "content", key.getPackageType(), key.getType().singularEndpointName(), key.getName());
        final EndpointView point = new EndpointView(store, resourceUri);
        if (!points.contains(point)) {
            points.add(point);
        }
    }
    return new EndpointViewListing(points);
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) EndpointView(org.commonjava.indy.model.core.dto.EndpointView) EndpointViewListing(org.commonjava.indy.model.core.dto.EndpointViewListing) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArrayList(java.util.ArrayList) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 19 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.

the class StoreContentListener method listPaths.

private Set<String> listPaths(StoreKey key, Predicate<? super String> pathFilter) {
    Logger logger = LoggerFactory.getLogger(getClass());
    Transfer root = null;
    try {
        Set<String> paths = new HashSet<>();
        root = directContentAccess.getTransfer(key, ROOT);
        root.lockWrite();
        List<Transfer> toProcess = new ArrayList<>();
        toProcess.add(root);
        while (!toProcess.isEmpty()) {
            Transfer next = toProcess.remove(0);
            try {
                Stream.of(next.list()).forEach(filename -> {
                    Transfer t = next.getChild(filename);
                    if (t.isDirectory()) {
                        logger.debug("Adding directory path for processing: {}", t.getPath());
                        toProcess.add(t);
                    } else {
                        logger.trace("Testing file path: {}", t.getPath());
                        if (pathFilter.test(t.getPath())) {
                            logger.trace("Adding file path to results: {}", t.getPath());
                            paths.add(t.getPath());
                        } else {
                            logger.trace("Skipping file path: {}", t.getPath());
                        }
                    }
                });
            } catch (IOException e) {
                logger.error(String.format("Failed to list contents of: %s. Reason: %s", next, e), e);
            }
        }
        return paths;
    } catch (IndyWorkflowException e) {
        logger.error(String.format("Failed to retrieve root directory reference for: %s. Reason: %s", key, e), e);
    } finally {
        if (root != null) {
            root.unlock();
        }
    }
    return Collections.emptySet();
}
Also used : IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Logger(org.slf4j.Logger) HashSet(java.util.HashSet)

Example 20 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.

the class AbstractMergedContentGenerator method clearMergedFile.

protected void clearMergedFile(final Group group, final String path) {
    try {
        // delete so it'll be recomputed.
        final Transfer target = fileManager.getTransfer(group, path);
        if (target.exists()) {
            logger.debug("Deleting merged file: {}", target);
            target.delete(false);
            if (target.exists()) {
                logger.error("\n\n\n\nDID NOT DELETE merged metadata file at: {} in group: {}\n\n\n\n", path, group.getName());
            }
            helper.deleteChecksumsAndMergeInfo(group, path);
        } else {
            ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(group), path);
            nfc.clearMissing(resource);
        }
    } catch (final IndyWorkflowException | IOException e) {
        logger.error("Failed to delete generated file (to allow re-generation on demand: {}/{}. Error: {}", e, group.getKey(), path, e.getMessage());
    }
}
Also used : IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) IOException(java.io.IOException)

Aggregations

IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)109 Response (javax.ws.rs.core.Response)40 Transfer (org.commonjava.maven.galley.model.Transfer)39 IOException (java.io.IOException)36 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)36 StoreKey (org.commonjava.indy.model.core.StoreKey)36 ApiOperation (io.swagger.annotations.ApiOperation)35 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)34 ApiResponse (io.swagger.annotations.ApiResponse)33 Path (javax.ws.rs.Path)32 StoreType (org.commonjava.indy.model.core.StoreType)26 IndyDataException (org.commonjava.indy.data.IndyDataException)25 GET (javax.ws.rs.GET)24 Logger (org.slf4j.Logger)22 ApiResponses (io.swagger.annotations.ApiResponses)21 ArrayList (java.util.ArrayList)19 Produces (javax.ws.rs.Produces)18 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)18 InputStream (java.io.InputStream)15 List (java.util.List)13