Search in sources :

Example 96 with IndyWorkflowException

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

the class DefaultDownloadManager method list.

@Override
public List<StoreResource> list(final ArtifactStore store, final String path) throws IndyWorkflowException {
    final List<StoreResource> result = new ArrayList<>();
    if (store.getKey().getType() == StoreType.group) {
        try {
            final List<ListingResult> results = transfers.listAll(locationExpander.expand(new VirtualResource(LocationUtils.toLocations(store), path)));
            for (final ListingResult lr : results) {
                if (lr != null && lr.getListing() != null) {
                    for (final String file : lr.getListing()) {
                        result.add(new StoreResource((KeyedLocation) lr.getLocation(), path, file));
                    }
                }
            }
        } 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);
        } 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);
        } 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);
        } catch (final TransferException e) {
            logger.error(e.getMessage(), e);
            throw new IndyWorkflowException("Failed to list ALL paths: {} from: {}. Reason: {}", e, path, store.getKey(), e.getMessage());
        }
    } else {
        final KeyedLocation loc = LocationUtils.toLocation(store);
        final StoreResource res = new StoreResource(loc, path);
        if (store instanceof RemoteRepository) {
            try {
                final ListingResult lr = transfers.list(res);
                if (lr != null && lr.getListing() != null) {
                    for (final String file : lr.getListing()) {
                        result.add(new StoreResource(loc, path, file));
                    }
                }
            } 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);
            } 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);
            } 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);
            } catch (final TransferException e) {
                logger.error(e.getMessage(), e);
                throw new IndyWorkflowException("Failed to list path: {} from: {}. Reason: {}", e, path, store.getKey(), e.getMessage());
            }
        } else {
            try {
                final ListingResult listing = transfers.list(res);
                if (listing != null && listing.getListing() != null) {
                    for (final String child : listing.getListing()) {
                        result.add(new StoreResource(loc, path, child));
                    }
                }
            } catch (final TransferLocationException e) {
                Location location = res.getLocation();
                KeyedLocation kl = (KeyedLocation) location;
                logger.warn("Timeout  / bad gateway: " + e.getMessage(), e);
                fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), e));
            } catch (final TransferException e) {
                logger.error(e.getMessage(), e);
                throw new IndyWorkflowException("Failed to list path: {} from: {}. Reason: {}", e, path, store.getKey(), e.getMessage());
            }
        }
    }
    return dedupeListing(result);
}
Also used : TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ArrayList(java.util.ArrayList) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ListingResult(org.commonjava.maven.galley.model.ListingResult) StoreResource(org.commonjava.indy.content.StoreResource) TransferException(org.commonjava.maven.galley.TransferException) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) VirtualResource(org.commonjava.maven.galley.model.VirtualResource) BadGatewayException(org.commonjava.maven.galley.BadGatewayException) TransferLocationException(org.commonjava.maven.galley.TransferLocationException) IndyStoreErrorEvent(org.commonjava.indy.change.event.IndyStoreErrorEvent) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Location(org.commonjava.maven.galley.model.Location)

Example 97 with IndyWorkflowException

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

the class DefaultDownloadManager method recurseListing.

private void recurseListing(final Transfer transfer, final List<Transfer> result) throws IndyWorkflowException {
    if (transfer.isDirectory()) {
        try {
            final String[] children = transfer.list();
            for (final String child : children) {
                final Transfer childTransfer = transfer.getChild(child);
                recurseListing(childTransfer, result);
            }
        } catch (final IOException e) {
            throw new IndyWorkflowException("Failed to list children of: %s. Reason: %s", e, transfer, e.getMessage());
        }
    } else if (transfer.exists()) {
        result.add(transfer);
    }
}
Also used : IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) IOException(java.io.IOException)

Example 98 with IndyWorkflowException

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

the class DefaultContentDigester method digest.

public TransferMetadata digest(final StoreKey key, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
    final Transfer transfer = directContentAccess.getTransfer(key, path);
    if (transfer == null || !transfer.exists()) {
        return new TransferMetadata(Collections.emptyMap(), 0L);
    }
    TransferMetadata meta = getContentMetadata(transfer);
    if (meta != null) {
        return meta;
    }
    String cacheKey = generateCacheKey(transfer);
    logger.debug("TransferMetadata missing for: {}. Re-reading with FORCE_CHECKSUM now to calculate it.", cacheKey);
    // FIXME: This IS NOT WORKING! It results in NPE for callers assuming a non-null TransferMetadata response.
    EventMetadata forcedEventMetadata = new EventMetadata(eventMetadata).set(FORCE_CHECKSUM, Boolean.TRUE);
    try (InputStream stream = transfer.openInputStream(false, forcedEventMetadata)) {
        // depend on ChecksummingTransferDecorator to calculate / store metadata as this gets read, using
        // the FORCE_CHECKSUM metadata key to control its generation.
        IOUtils.toByteArray(stream);
    } catch (IOException e) {
        throw new IndyWorkflowException("Failed to calculate checksums (MD5, SHA-256, etc.) for: %s. Reason: %s", e, transfer, e.getMessage());
    }
    logger.debug("Retrying TransferMetadata retrieval from cache for: {} after recalculating", cacheKey);
    return getContentMetadata(transfer);
}
Also used : TransferMetadata(org.commonjava.maven.galley.io.checksum.TransferMetadata) InputStream(java.io.InputStream) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) Hex.encodeHexString(org.apache.commons.codec.binary.Hex.encodeHexString) IOException(java.io.IOException) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 99 with IndyWorkflowException

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

the class DefaultContentManager method retrieveAll.

@Override
public List<Transfer> retrieveAll(final List<? extends ArtifactStore> stores, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
    final List<Transfer> txfrs = new ArrayList<>();
    for (final ArtifactStore store : stores) {
        if (group == store.getKey().getType()) {
            List<ArtifactStore> members;
            try {
                members = storeManager.query().packageType(store.getPackageType()).enabledState(true).getOrderedConcreteStoresInGroup(store.getName());
            } catch (final IndyDataException e) {
                throw new IndyWorkflowException("Failed to lookup concrete members of: %s. Reason: %s", e, store, e.getMessage());
            }
            final List<Transfer> storeTransfers = new ArrayList<>();
            for (final ContentGenerator generator : contentGenerators) {
                final Transfer txfr = generator.generateGroupFileContent((Group) store, members, path, eventMetadata);
                if (txfr != null) {
                    storeTransfers.add(txfr);
                }
            }
            // ...if it's generated, it's merged in this case.
            if (storeTransfers.isEmpty()) {
                for (final ArtifactStore member : members) {
                    // NOTE: This is only safe to call because we're concrete ordered stores, so anything passing through here is concrete.
                    final Transfer txfr = doRetrieve(member, path, eventMetadata);
                    if (txfr != null) {
                        storeTransfers.add(txfr);
                    }
                }
            }
            txfrs.addAll(storeTransfers);
        } else {
            // NOTE: This is only safe to call because we're doing the group check up front, so anything passing through here is concrete.
            final Transfer txfr = doRetrieve(store, path, eventMetadata);
            if (txfr != null) {
                txfrs.add(txfr);
            }
        }
    }
    return txfrs;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ContentGenerator(org.commonjava.indy.content.ContentGenerator) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArrayList(java.util.ArrayList) Transfer(org.commonjava.maven.galley.model.Transfer)

Example 100 with IndyWorkflowException

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

the class DefaultContentManager method getTransfer.

@Override
public Transfer getTransfer(final ArtifactStore store, final String path, final TransferOperation op) throws IndyWorkflowException {
    logger.debug("Getting transfer for: {}/{} (op: {})", store.getKey(), path, op);
    if (group == store.getKey().getType()) {
        KeyedLocation location = LocationUtils.toLocation(store);
        SpecialPathInfo spInfo = specialPathManager.getSpecialPathInfo(location, path, store.getPackageType());
        if (spInfo == null || !spInfo.isMergable()) {
            try {
                final List<ArtifactStore> allMembers = storeManager.query().packageType(store.getPackageType()).enabledState(true).getOrderedConcreteStoresInGroup(store.getName());
                logger.debug("Trying to retrieve suitable transfer for: {} in group: {} members:\n{}", path, store.getName(), allMembers);
                return getTransfer(allMembers, path, op);
            } catch (final IndyDataException e) {
                throw new IndyWorkflowException("Failed to lookup concrete members of: %s. Reason: %s", e, store, e.getMessage());
            }
        } else {
            logger.debug("Detected mergable special path: {}/{}.", store.getKey(), path);
        }
    }
    logger.debug("Retrieving storage reference (Transfer) directly for: {}/{}", store.getKey(), path);
    return downloadManager.getStorageReference(store, path, op);
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException)

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