Search in sources :

Example 11 with IndyWorkflowException

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

the class ReplicationController method getEndpoints.

private List<EndpointView> getEndpoints(final ReplicationDTO dto) throws IndyWorkflowException {
    final String apiUrl = dto.getApiUrl();
    String url = null;
    try {
        url = buildUrl(apiUrl, "/stats/all-endpoints");
    } catch (final MalformedURLException e) {
        throw new IndyWorkflowException("Failed to construct endpoint-retrieval URL from api-base: {}. Reason: {}", e, apiUrl, e.getMessage());
    }
    final HttpGet req = newGet(url, dto);
    CloseableHttpClient client = null;
    try {
        String siteId = new URL(url).getHost();
        client = http.createClient(siteId);
        CloseableHttpResponse response = client.execute(req, http.createContext(siteId));
        final StatusLine statusLine = response.getStatusLine();
        final int status = statusLine.getStatusCode();
        if (status == HttpStatus.SC_OK) {
            final String json = HttpResources.entityToString(response);
            final EndpointViewListing listing = serializer.readValue(json, EndpointViewListing.class);
            return listing.getItems();
        }
        throw new IndyWorkflowException(status, "Endpoint request failed: {}", statusLine);
    } catch (final IOException | IndyHttpException e) {
        throw new IndyWorkflowException("Failed to retrieve endpoints from: {}. Reason: {}", e, url, e.getMessage());
    } finally {
        IOUtils.closeQuietly(client);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) MalformedURLException(java.net.MalformedURLException) HttpGet(org.apache.http.client.methods.HttpGet) IndyHttpException(org.commonjava.indy.subsys.http.IndyHttpException) IOException(java.io.IOException) URL(java.net.URL) StatusLine(org.apache.http.StatusLine) EndpointViewListing(org.commonjava.indy.model.core.dto.EndpointViewListing) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 12 with IndyWorkflowException

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

the class DefaultContentManager method exists.

@Override
public // TODO: to add content generation handling here, for things like merged metadata, checksum files, etc.
boolean exists(ArtifactStore store, String path) throws IndyWorkflowException {
    if (!checkMask(store, path)) {
        return false;
    }
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("Checking existence of: {} in: {}", path, store.getKey());
    if (store instanceof Group) {
        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, allMembers, store.getName());
            for (ArtifactStore member : allMembers) {
                if (exists(member, path)) {
                    return true;
                }
            }
            return false;
        } catch (final IndyDataException e) {
            throw new IndyWorkflowException("Failed to lookup concrete members of: %s. Reason: %s", e, store, e.getMessage());
        }
    } else {
        return downloadManager.exists(store, path);
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Logger(org.slf4j.Logger)

Example 13 with IndyWorkflowException

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

the class DefaultDirectContentAccess method retrieveAllRaw.

@Override
public List<Transfer> retrieveAllRaw(final List<? extends ArtifactStore> stores, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    Map<ArtifactStore, Future<Transfer>> futures = new HashMap<>();
    for (final ArtifactStore store : stores) {
        logger.debug("Requesting retrieval of {} in {}", path, store);
        Future<Transfer> future = executorService.submit(() -> {
            logger.trace("Retrieving {} in {}", path, store);
            Transfer txfr = retrieveRaw(store, path, eventMetadata);
            logger.trace("Transfer {} in {} retrieved", path, store);
            return txfr;
        });
        futures.put(store, future);
    }
    final List<Transfer> txfrs = new ArrayList<>(stores.size());
    for (ArtifactStore store : stores) {
        Transfer txfr;
        try {
            logger.trace("Waiting for transfer of {} in {}", path, store);
            Future<Transfer> future = futures.get(store);
            txfr = future.get();
            logger.debug("Transfer {} in {} retrieved", path, store);
        } catch (InterruptedException ex) {
            throw new IndyWorkflowException("Retrieval of %s in %s was interrupted", ex, path, store);
        } catch (ExecutionException ex) {
            throw new IndyWorkflowException("Error retrieving %s from %s: %s", ex, path, store, ex);
        }
        if (txfr != null) {
            txfrs.add(txfr);
        }
    }
    return txfrs;
}
Also used : HashMap(java.util.HashMap) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Logger(org.slf4j.Logger) ExecutionException(java.util.concurrent.ExecutionException)

Example 14 with IndyWorkflowException

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

the class DefaultDownloadManager method list.

@Override
public List<StoreResource> list(final List<? extends ArtifactStore> stores, final String path) throws IndyWorkflowException {
    final String dir = PathUtils.dirname(path);
    final List<StoreResource> result = new ArrayList<>();
    try {
        final List<ListingResult> results = transfers.listAll(locationExpander.expand(new VirtualResource(LocationUtils.toLocations(stores), 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(), dir, 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, stores, e.getMessage());
    }
    return dedupeListing(result);
}
Also used : TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ArrayList(java.util.ArrayList) 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 15 with IndyWorkflowException

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

the class DefaultDownloadManager method getStorageReference.

@Override
public Transfer getStorageReference(final List<ArtifactStore> stores, final String path, final TransferOperation op) throws IndyWorkflowException {
    //        final ArtifactPathInfo pathInfo = ArtifactPathInfo.parse( path );
    final ContentQuality quality = getQuality(path);
    Transfer transfer = null;
    logger.debug("Checking {} stores to find one suitable for {} of: {}", stores.size(), op, path);
    boolean suitableFound = false;
    for (final ArtifactStore store : stores) {
        if (storeIsSuitableFor(store, quality, op)) {
            suitableFound = true;
            logger.info("Attempting to retrieve storage reference in: {} for: {} (operation: {})", store, path, op);
            transfer = getStorageReference(store, path);
            logger.debug("Checking {} (exists? {}; file: {})", transfer, transfer != null && transfer.exists(), transfer == null ? "NONE" : transfer.getFullPath());
            if (transfer != null && !transfer.exists() && (op == TransferOperation.DOWNLOAD || op == TransferOperation.LISTING)) {
                transfer = null;
            }
            if (transfer != null) {
                logger.info("Using transfer: {}", transfer);
                break;
            }
        }
    }
    if (!stores.isEmpty() && !suitableFound) {
        logger.warn("No suitable stores in list.");
        throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "No suitable store available.");
    }
    return transfer;
}
Also used : ContentQuality(org.commonjava.indy.spi.pkg.ContentQuality) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer)

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