Search in sources :

Example 6 with KeyedLocation

use of org.commonjava.indy.model.galley.KeyedLocation 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 7 with KeyedLocation

use of org.commonjava.indy.model.galley.KeyedLocation in project indy by Commonjava.

the class DefaultContentManager method store.

@Override
public Transfer store(final ArtifactStore store, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
    if (group == store.getKey().getType()) {
        try {
            final List<ArtifactStore> allMembers = storeManager.query().packageType(store.getPackageType()).enabledState(true).getOrderedConcreteStoresInGroup(store.getName());
            final Transfer txfr = store(allMembers, store.getKey(), path, stream, op, eventMetadata);
            logger.info("Stored: {} for group: {} in: {}", path, store.getKey(), txfr);
            return txfr;
        } catch (final IndyDataException e) {
            throw new IndyWorkflowException("Failed to lookup concrete members of: %s. Reason: %s", e, store, e.getMessage());
        }
    }
    logger.info("Storing: {} for: {} with event metadata: {}", path, store.getKey(), eventMetadata);
    final Transfer txfr = downloadManager.store(store, path, stream, op, eventMetadata);
    if (txfr != null) {
        final KeyedLocation kl = (KeyedLocation) txfr.getLocation();
        ArtifactStore transferStore;
        try {
            transferStore = storeManager.getArtifactStore(kl.getKey());
        } catch (final IndyDataException e) {
            throw new IndyWorkflowException("Failed to lookup store: %s. Reason: %s", e, kl.getKey(), e.getMessage());
        }
        for (final ContentGenerator generator : contentGenerators) {
            generator.handleContentStorage(transferStore, path, txfr, eventMetadata);
        }
        if (!store.equals(transferStore)) {
            for (final ContentGenerator generator : contentGenerators) {
                generator.handleContentStorage(transferStore, path, txfr, eventMetadata);
            }
        }
    }
    return txfr;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ContentGenerator(org.commonjava.indy.content.ContentGenerator) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer)

Example 8 with KeyedLocation

use of org.commonjava.indy.model.galley.KeyedLocation in project indy by Commonjava.

the class DefaultContentManager method store.

//    @Override
//    public Transfer store( final List<? extends ArtifactStore> stores, final String path, final InputStream stream,
//                           final TransferOperation op )
//            throws IndyWorkflowException
//    {
//        return store( stores, path, stream, op, new EventMetadata() );
//    }
@Override
public Transfer store(final List<? extends ArtifactStore> stores, final StoreKey topKey, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
    logger.info("Storing: {} in: {} with event metadata: {}", path, stores, eventMetadata);
    final Transfer txfr = downloadManager.store(stores, path, stream, op, eventMetadata);
    if (txfr != null) {
        final KeyedLocation kl = (KeyedLocation) txfr.getLocation();
        ArtifactStore transferStore;
        try {
            transferStore = storeManager.getArtifactStore(kl.getKey());
        } catch (final IndyDataException e) {
            throw new IndyWorkflowException("Failed to lookup store: %s. Reason: %s", e, kl.getKey(), e.getMessage());
        }
        for (final ContentGenerator generator : contentGenerators) {
            logger.info("{} Handling content storage of: {} in: {}", generator, path, transferStore.getKey());
            generator.handleContentStorage(transferStore, path, txfr, eventMetadata);
        }
    }
    return txfr;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ContentGenerator(org.commonjava.indy.content.ContentGenerator) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer)

Example 9 with KeyedLocation

use of org.commonjava.indy.model.galley.KeyedLocation in project indy by Commonjava.

the class IndyPathGenerator method getFilePath.

@Override
public String getFilePath(final ConcreteResource resource) {
    final KeyedLocation kl = (KeyedLocation) resource.getLocation();
    final StoreKey key = kl.getKey();
    final String name = key.getPackageType() + "/" + key.getType().name() + "-" + key.getName();
    String path = resource.getPath();
    if (hashed == kl.getAttribute(LocationUtils.PATH_STYLE, PathStyle.class)) {
        File f = new File(path);
        String dir = f.getParent();
        if (dir == null) {
            dir = "";
        }
        if (dir.length() > 1 && dir.startsWith("/")) {
            dir = dir.substring(1, dir.length());
        }
        String digest = DigestUtils.sha256Hex(dir);
        Logger logger = LoggerFactory.getLogger(getClass());
        logger.trace("Using SHA-256 digest: '{}' for dir: '{}' of path: '{}'", digest, dir, path);
        // Format examples:
        // - aa/bb/aabbccddeeff001122/simple-1.0.pom
        // - aa/bb/aabbccddeeff001122/gulp-size
        // - 00/11/001122334455667788/gulp-size-1.3.0.tgz
        path = String.format("%s/%s/%s/%s", digest.substring(0, 2), digest.substring(2, 4), digest, f.getName());
    }
    return PathUtils.join(name, path);
}
Also used : KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) PathStyle(org.commonjava.indy.model.core.PathStyle) Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey) File(java.io.File)

Example 10 with KeyedLocation

use of org.commonjava.indy.model.galley.KeyedLocation in project indy by Commonjava.

the class LocationUtils method toLocation.

public static KeyedLocation toLocation(final ArtifactStore store) {
    if (store == null) {
        return null;
    }
    final StoreType type = store.getKey().getType();
    KeyedLocation location = null;
    switch(type) {
        case group:
            {
                location = new GroupLocation(store.getName());
                break;
            }
        case hosted:
            {
                location = new CacheOnlyLocation((HostedRepository) store);
                break;
            }
        case remote:
        default:
            {
                final RemoteRepository repository = (RemoteRepository) store;
                location = new RepositoryLocation(repository);
                AttributePasswordManager.bind(location, PasswordEntry.KEY_PASSWORD, repository.getKeyPassword());
                AttributePasswordManager.bind(location, PasswordEntry.PROXY_PASSWORD, repository.getProxyPassword());
                AttributePasswordManager.bind(location, PasswordEntry.USER_PASSWORD, repository.getPassword());
                // FIXME: Make this configurable on the RemoteRepository!
                location.setAttribute(Location.MAX_CONNECTIONS, 30);
            }
    }
    if (location != null) {
        location.setAttribute(PATH_STYLE, store.getPathStyle());
        Map<String, String> metadata = store.getMetadata();
        if (metadata != null) {
            Location loc = location;
            metadata.forEach((k, v) -> {
                if (!loc.getAttributes().containsKey(k)) {
                    loc.setAttribute(k, v);
                }
            });
        }
    }
    return location;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) GroupLocation(org.commonjava.indy.model.galley.GroupLocation) CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) GroupLocation(org.commonjava.indy.model.galley.GroupLocation) Location(org.commonjava.maven.galley.model.Location)

Aggregations

KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)19 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)11 Location (org.commonjava.maven.galley.model.Location)10 ArrayList (java.util.ArrayList)7 IndyDataException (org.commonjava.indy.data.IndyDataException)7 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)6 Transfer (org.commonjava.maven.galley.model.Transfer)6 StoreResource (org.commonjava.indy.content.StoreResource)5 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)5 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)4 StoreKey (org.commonjava.indy.model.core.StoreKey)4 TransferException (org.commonjava.maven.galley.TransferException)4 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)4 ListingResult (org.commonjava.maven.galley.model.ListingResult)4 Set (java.util.Set)3 IndyStoreErrorEvent (org.commonjava.indy.change.event.IndyStoreErrorEvent)3 File (java.io.File)2 HashSet (java.util.HashSet)2 Inject (javax.inject.Inject)2 ContentGenerator (org.commonjava.indy.content.ContentGenerator)2