Search in sources :

Example 91 with IndyWorkflowException

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

the class ContentController method rescanAll.

public void rescanAll(final EventMetadata eventMetadata) throws IndyWorkflowException {
    try {
        final List<ArtifactStore> stores = storeManager.query().concreteStores().getAll();
        contentManager.rescanAll(stores, eventMetadata);
    } catch (final IndyDataException e) {
        throw new IndyWorkflowException(ApplicationStatus.SERVER_ERROR.code(), "Failed to retrieve list of concrete stores. Reason: {}", e, e.getMessage());
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException)

Example 92 with IndyWorkflowException

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

the class ReplicationController method addStoresFrom.

private <T extends ArtifactStore> void addStoresFrom(final List<ArtifactStore> result, final String remotesUrl, final ReplicationDTO dto, final Class<T> type) throws IndyWorkflowException {
    final HttpGet req = newGet(remotesUrl, dto);
    CloseableHttpClient client = null;
    try {
        String siteId = new URL(remotesUrl).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 StoreListingDTO<T> listing = serializer.readValue(json, serializer.getTypeFactory().constructParametricType(StoreListingDTO.class, type));
            if (listing != null) {
                result.addAll(listing.getItems());
            }
        } else {
            throw new IndyWorkflowException(status, "Request: %s failed: %s", remotesUrl, statusLine);
        }
    } catch (final IOException | IndyHttpException e) {
        throw new IndyWorkflowException("Failed to retrieve endpoints from: %s. Reason: %s", e, remotesUrl, e.getMessage());
    } finally {
        IOUtils.closeQuietly(client);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) 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) StoreListingDTO(org.commonjava.indy.model.core.dto.StoreListingDTO) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 93 with IndyWorkflowException

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

the class DefaultDirectContentAccess method listRaw.

@Override
public Map<String, List<StoreResource>> listRaw(ArtifactStore store, List<String> parentPathList) throws IndyWorkflowException {
    CompletionService<List<StoreResource>> executor = new ExecutorCompletionService<>(executorService);
    Map<String, Future<List<StoreResource>>> futures = new HashMap<>();
    Logger logger = LoggerFactory.getLogger(getClass());
    for (final String path : parentPathList) {
        logger.debug("Requesting listing of {} in {}", path, store);
        Future<List<StoreResource>> future = executor.submit(() -> {
            logger.trace("Starting listing of {} in {}", path, store);
            List<StoreResource> listRaw = listRaw(store, path);
            logger.trace("Listing of {} in {} finished", path, store);
            return listRaw;
        });
        futures.put(path, future);
    }
    final Map<String, List<StoreResource>> result = new HashMap<>();
    for (String path : parentPathList) {
        try {
            logger.trace("Waiting for listing of {} in {}", path, store);
            Future<List<StoreResource>> future = futures.get(path);
            List<StoreResource> listing = future.get();
            logger.debug("Listing of {} in {} received", path, store);
            if (listing != null) {
                result.put(path, listing);
            }
        } catch (InterruptedException ex) {
            throw new IndyWorkflowException("Listing retrieval of %s in %s was interrupted", ex, path, store);
        } catch (ExecutionException ex) {
            throw new IndyWorkflowException("There was an error in listing retrieval of %s in %s: %s", ex, path, store, ex);
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) Logger(org.slf4j.Logger) StoreResource(org.commonjava.indy.content.StoreResource) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException)

Example 94 with IndyWorkflowException

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

the class DefaultDirectContentAccess method retrieveRaw.

@Override
public Transfer retrieveRaw(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.info("Attempting to retrieve: {} from: {}", path, store.getKey());
    Transfer item = null;
    try {
        item = downloadManager.retrieve(store, path, eventMetadata);
    } catch (IndyWorkflowException e) {
        e.filterLocationErrors();
    }
    return item;
}
Also used : IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) Logger(org.slf4j.Logger)

Example 95 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(java.util.List, java.lang.String,
     * java.io.InputStream)
     */
@Override
public Transfer store(final List<? extends ArtifactStore> stores, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
    final ContentQuality quality = getQuality(path);
    HostedRepository selected = null;
    for (final ArtifactStore store : stores) {
        if (storeManager.isReadonly(store)) {
            logger.info("The store {} is readonly, store operation not allowed");
            continue;
        }
        if (storeIsSuitableFor(store, quality, op)) {
            selected = (HostedRepository) store;
            break;
        }
    }
    if (selected == null) {
        logger.warn("Cannot deploy. No valid deploy points in group.");
        throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "No deployment locations available.");
    }
    logger.info("Storing: {} in selected: {} with event metadata: {}", path, selected, eventMetadata);
    store(selected, path, stream, op, eventMetadata);
    return getStorageReference(selected.getKey(), path);
}
Also used : ContentQuality(org.commonjava.indy.spi.pkg.ContentQuality) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) HostedRepository(org.commonjava.indy.model.core.HostedRepository)

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