Search in sources :

Example 1 with VirtualResource

use of org.commonjava.maven.galley.model.VirtualResource in project galley by Commonjava.

the class ArtifactManagerImpl method resolveFirstVirtualResource.

private VirtualResource resolveFirstVirtualResource(List<? extends Location> locations, ArtifactRef ref, final EventMetadata eventMetadata) throws TransferException {
    locations = expander.expand(locations);
    if (ref.isVariableVersion()) {
        final ProjectVersionRefLocation resolved = resolveSingleVariableVersion(locations, ref, eventMetadata);
        if (resolved != null) {
            locations = Collections.singletonList(resolved.getLocation());
            ref = (ArtifactRef) resolved.getRef();
        }
    }
    return new VirtualResource(expander.expand(locations), formatArtifactPath(ref, mapper));
}
Also used : ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) VirtualResource(org.commonjava.maven.galley.model.VirtualResource)

Example 2 with VirtualResource

use of org.commonjava.maven.galley.model.VirtualResource in project galley by Commonjava.

the class ArtifactMetadataManagerImpl method store.

/* (non-Javadoc)
     * @see org.commonjava.maven.galley.ArtifactMetadataManager#store(org.commonjava.maven.galley.model.Location, java.lang.String, java.lang.String, java.io.InputStream)
     */
@Override
public Transfer store(final Location location, final String groupId, final String filename, final InputStream stream, final EventMetadata eventMetadata) throws TransferException {
    final VirtualResource virt = new VirtualResource(expander.expand(location), formatMetadataPath(groupId, filename));
    final ConcreteResource selected = ArtifactRules.selectStorageResource(virt);
    if (selected == null) {
        logger.warn("Cannot deploy. No valid deploy points in group.");
        throw new TransferException("No deployment locations available for: {}", virt.toConcreteResources());
    }
    return transferManager.store(selected, stream, eventMetadata);
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) VirtualResource(org.commonjava.maven.galley.model.VirtualResource)

Example 3 with VirtualResource

use of org.commonjava.maven.galley.model.VirtualResource in project galley by Commonjava.

the class ArtifactMetadataManagerImpl method store.

/* (non-Javadoc)
     * @see org.commonjava.maven.galley.ArtifactMetadataManager#store(org.commonjava.maven.galley.model.Location, org.commonjava.maven.atlas.ident.ref.ProjectRef, java.lang.String, java.io.InputStream)
     */
@Override
public Transfer store(final Location location, final ProjectRef ref, final String filename, final InputStream stream, final EventMetadata eventMetadata) throws TransferException {
    final VirtualResource virt = new VirtualResource(expander.expand(location), formatMetadataPath(ref, filename));
    final ConcreteResource selected = ArtifactRules.selectStorageResource(virt);
    if (selected == null) {
        logger.warn("Cannot deploy. No valid deploy points in group.");
        throw new TransferException("No deployment locations available for: {}", virt.toConcreteResources());
    }
    return transferManager.store(selected, stream, eventMetadata);
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) VirtualResource(org.commonjava.maven.galley.model.VirtualResource)

Example 4 with VirtualResource

use of org.commonjava.maven.galley.model.VirtualResource 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 5 with VirtualResource

use of org.commonjava.maven.galley.model.VirtualResource in project galley by Commonjava.

the class ArtifactBatch method setArtifactToResourceMapping.

public void setArtifactToResourceMapping(final Map<ArtifactRef, Resource> mappings) {
    artifactMappings = new HashMap<>();
    final Set<ConcreteResource> resources = new HashSet<>();
    for (final Entry<ArtifactRef, Resource> entry : mappings.entrySet()) {
        final ArtifactRef artifact = entry.getKey();
        final Resource resource = entry.getValue();
        if (resource instanceof ConcreteResource) {
            artifactMappings.put(artifact, Collections.singletonList((ConcreteResource) resource));
            resources.add((ConcreteResource) resource);
        } else {
            final List<ConcreteResource> res = ((VirtualResource) resource).toConcreteResources();
            artifactMappings.put(artifact, res);
            resources.addAll(res);
        }
    }
    setResources(resources);
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Resource(org.commonjava.maven.galley.model.Resource) VirtualResource(org.commonjava.maven.galley.model.VirtualResource) VirtualResource(org.commonjava.maven.galley.model.VirtualResource) HashSet(java.util.HashSet) ArtifactRef(org.commonjava.maven.atlas.ident.ref.ArtifactRef)

Aggregations

VirtualResource (org.commonjava.maven.galley.model.VirtualResource)14 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)9 ArrayList (java.util.ArrayList)7 TransferException (org.commonjava.maven.galley.TransferException)6 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)5 ListingResult (org.commonjava.maven.galley.model.ListingResult)5 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)4 StoreResource (org.commonjava.indy.content.StoreResource)4 TransferLocationException (org.commonjava.maven.galley.TransferLocationException)4 Location (org.commonjava.maven.galley.model.Location)3 Resource (org.commonjava.maven.galley.model.Resource)3 LinkedHashMap (java.util.LinkedHashMap)2 IndyStoreErrorEvent (org.commonjava.indy.change.event.IndyStoreErrorEvent)2 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)2 BadGatewayException (org.commonjava.maven.galley.BadGatewayException)2 TransferTimeoutException (org.commonjava.maven.galley.TransferTimeoutException)2 ProjectVersionRefLocation (org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation)2 Measure (org.commonjava.o11yphant.metrics.annotation.Measure)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1