Search in sources :

Example 21 with Measure

use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.

the class DefaultContentManager method exists.

@Override
@Measure
public // TODO: to add content generation handling here, for things like merged metadata, checksum files, etc.
boolean exists(ArtifactStore store, String path) throws IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.trace("Checking existence of: {} in: {}", path, store.getKey());
    if (store instanceof Group) {
        List<ArtifactStore> members = getOrderedConcreteStoresAndFilter((Group) store, path);
        logger.trace("Trying to retrieve suitable transfer for: {} in group: {}", path, store.getName());
        logger.trace("Members in group {}: {}", store.getName(), members);
        for (ArtifactStore member : members) {
            if (exists(member, path)) {
                return true;
            }
        }
        return false;
    } else {
        return downloadManager.exists(store, path);
    }
}
Also used : Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Logger(org.slf4j.Logger) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 22 with Measure

use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.

the class ContentController method store.

@Measure
public Transfer store(final StoreKey key, final String path, final InputStream stream, final EventMetadata eventMetadata) throws IndyWorkflowException {
    final ArtifactStore store = getStore(key);
    validatePath(key, path);
    logger.info("Storing: {} in: {} with event metadata: {}", path, store, eventMetadata);
    return contentManager.store(store, path, stream, TransferOperation.UPLOAD, eventMetadata);
}
Also used : ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 23 with Measure

use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.

the class DefaultDownloadManager method list.

@Override
@Measure
public List<StoreResource> list(final List<? extends ArtifactStore> stores, final String path, final EventMetadata eventMetadata) 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)), eventMetadata);
        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 TransferLocationException e) {
        fireIndyStoreErrorEvent(e);
        logger.warn("Location Error: " + e.getMessage(), e);
        throw new IndyWorkflowException("Failed to list ALL paths: {} from: {}. Reason: {}", e, path, stores, e.getMessage());
    } 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 : StoreResource(org.commonjava.indy.content.StoreResource) TransferException(org.commonjava.maven.galley.TransferException) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArrayList(java.util.ArrayList) VirtualResource(org.commonjava.maven.galley.model.VirtualResource) ListingResult(org.commonjava.maven.galley.model.ListingResult) TransferLocationException(org.commonjava.maven.galley.TransferLocationException) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 24 with Measure

use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.

the class DefaultDownloadManager method getStorageReference.

@Override
@Measure
public Transfer getStorageReference(final ArtifactStore store, final String... path) {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.trace("Retrieving cache reference (Transfer) to: {} in: {}", Arrays.asList(path), store.getKey());
    ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
    return transfers.getCacheReference(resource);
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 25 with Measure

use of org.commonjava.o11yphant.metrics.annotation.Measure 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
@Measure
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() != hosted) {
        throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Cannot deploy to non-deploy point artifact store: {}.", store.getKey());
    }
    if (!isIgnoreReadonly(eventMetadata) && 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 != ContentQuality.METADATA) {
            if (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 {
        Location loc = LocationUtils.toLocation(store);
        boolean resetReadonly = (!loc.allowsStoring() && isIgnoreReadonly(eventMetadata));
        if (resetReadonly) {
            loc = LocationUtils.getNonReadonlyLocation(loc);
        }
        ConcreteResource resource = new ConcreteResource(loc, path);
        Transfer txfr = transfers.store(resource, stream, eventMetadata);
        nfc.clearMissing(resource);
        return txfr;
    } catch (final BadGatewayException e) {
        fireIndyStoreErrorEvent(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) {
        fireIndyStoreErrorEvent(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) {
        fireIndyStoreErrorEvent(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) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) BadGatewayException(org.commonjava.maven.galley.BadGatewayException) TransferLocationException(org.commonjava.maven.galley.TransferLocationException) HostedRepository(org.commonjava.indy.model.core.HostedRepository) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Location(org.commonjava.maven.galley.model.Location) CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Aggregations

Measure (org.commonjava.o11yphant.metrics.annotation.Measure)65 StoreKey (org.commonjava.indy.model.core.StoreKey)23 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)19 Transfer (org.commonjava.maven.galley.model.Transfer)19 Logger (org.slf4j.Logger)19 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)16 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)14 IndyDataException (org.commonjava.indy.data.IndyDataException)13 ArrayList (java.util.ArrayList)12 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)11 HashSet (java.util.HashSet)9 Group (org.commonjava.indy.model.core.Group)8 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)8 BoundStatement (com.datastax.driver.core.BoundStatement)6 StoreDataManager (org.commonjava.indy.data.StoreDataManager)6 StoreKey.fromString (org.commonjava.indy.model.core.StoreKey.fromString)6 Query (org.infinispan.query.dsl.Query)6 IOException (java.io.IOException)5 Set (java.util.Set)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5