Search in sources :

Example 1 with ContentQuality

use of org.commonjava.indy.spi.pkg.ContentQuality 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)

Example 2 with ContentQuality

use of org.commonjava.indy.spi.pkg.ContentQuality 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 3 with ContentQuality

use of org.commonjava.indy.spi.pkg.ContentQuality 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 4 with ContentQuality

use of org.commonjava.indy.spi.pkg.ContentQuality in project indy by Commonjava.

the class ScheduleManager method setSnapshotTimeouts.

public synchronized void setSnapshotTimeouts(final StoreKey key, final String path) throws IndySchedulerException {
    if (!schedulerConfig.isEnabled()) {
        logger.debug("Scheduler disabled.");
        return;
    }
    HostedRepository deploy = null;
    try {
        final ArtifactStore store = dataManager.getArtifactStore(key);
        if (store == null) {
            return;
        }
        if (store instanceof HostedRepository) {
            deploy = (HostedRepository) store;
        } else if (store instanceof Group) {
            final Group group = (Group) store;
            deploy = findDeployPoint(group);
        }
    } catch (final IndyDataException e) {
        logger.error(String.format("Failed to retrieve deploy point for: %s. Reason: %s", key, e.getMessage()), e);
    }
    if (deploy == null) {
        return;
    }
    final ContentAdvisor advisor = StreamSupport.stream(Spliterators.spliteratorUnknownSize(contentAdvisor.iterator(), Spliterator.ORDERED), false).filter(Objects::nonNull).findFirst().orElse(null);
    final ContentQuality quality = advisor == null ? null : advisor.getContentQuality(path);
    if (quality == null) {
        return;
    }
    if (ContentQuality.SNAPSHOT == quality && deploy.getSnapshotTimeoutSeconds() > 0) {
        final int timeout = deploy.getSnapshotTimeoutSeconds();
        //            //            logger.info( "[SNAPSHOT TIMEOUT SET] {}/{}; {}", deploy.getKey(), path, new Date( timeout ) );
        //            cancel( new StoreKeyMatcher( key, CONTENT_JOB_TYPE ), path );
        scheduleContentExpiration(key, path, timeout);
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) ContentAdvisor(org.commonjava.indy.spi.pkg.ContentAdvisor) ContentQuality(org.commonjava.indy.spi.pkg.ContentQuality) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Objects(java.util.Objects) HostedRepository(org.commonjava.indy.model.core.HostedRepository)

Example 5 with ContentQuality

use of org.commonjava.indy.spi.pkg.ContentQuality 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

ContentQuality (org.commonjava.indy.spi.pkg.ContentQuality)5 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)4 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)3 HostedRepository (org.commonjava.indy.model.core.HostedRepository)3 Objects (java.util.Objects)1 IndyStoreErrorEvent (org.commonjava.indy.change.event.IndyStoreErrorEvent)1 IndyDataException (org.commonjava.indy.data.IndyDataException)1 Group (org.commonjava.indy.model.core.Group)1 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)1 ContentAdvisor (org.commonjava.indy.spi.pkg.ContentAdvisor)1 BadGatewayException (org.commonjava.maven.galley.BadGatewayException)1 TransferException (org.commonjava.maven.galley.TransferException)1 TransferLocationException (org.commonjava.maven.galley.TransferLocationException)1 TransferTimeoutException (org.commonjava.maven.galley.TransferTimeoutException)1 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)1 Location (org.commonjava.maven.galley.model.Location)1 Transfer (org.commonjava.maven.galley.model.Transfer)1