Search in sources :

Example 16 with TransferException

use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.

the class TransferManagerImpl method retrieve.

@Override
public Transfer retrieve(final ConcreteResource resource, final boolean suppressFailures, final EventMetadata eventMetadata) throws TransferException {
    //        logger.info( "Attempting to resolve: {}", resource );
    // TODO: Handle the case where storage isn't allowed?
    // NOTE: This would expand the notion out from simply:
    //    "don't allow storing new stuff"
    // to:
    //    "don't ever cache this stuff"
    Transfer target = null;
    try {
        // TODO: (see above re:storing) Handle things like local archives that really don't need to be cached...
        target = getCacheReference(resource);
        if (target.exists()) {
            logger.debug("Using cached copy of: {}", target);
            return target;
        }
        SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(resource, eventMetadata.getPackageType());
        if (!resource.allowsDownloading() || (specialPathInfo != null && !specialPathInfo.isRetrievable())) {
            logger.debug("Download not allowed for: {}. Returning null transfer.", resource);
            return null;
        }
        final Transfer retrieved = downloader.download(resource, target, getTimeoutSeconds(resource), getTransport(resource), suppressFailures, eventMetadata);
        if (retrieved != null && retrieved.exists() && !target.equals(retrieved)) {
            if (specialPathInfo == null || specialPathInfo.isCachable()) {
                cacheProvider.createAlias(retrieved.getResource(), target.getResource());
            }
        }
        if (target.exists()) {
            logger.debug("DOWNLOADED: {}", resource);
            return target;
        } else {
            logger.debug("NOT DOWNLOADED: {}", resource);
            return null;
        }
    } catch (final TransferException e) {
        fileEventManager.fire(new FileErrorEvent(target, e, eventMetadata));
        throw e;
    } catch (final IOException e) {
        final TransferException error = new TransferException("Failed to download: {}. Reason: {}", e, resource, e.getMessage());
        fileEventManager.fire(new FileErrorEvent(target, error, eventMetadata));
        throw error;
    }
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) FileErrorEvent(org.commonjava.maven.galley.event.FileErrorEvent) Transfer(org.commonjava.maven.galley.model.Transfer) IOException(java.io.IOException)

Example 17 with TransferException

use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.

the class UploadHandler method joinOrStart.

private boolean joinOrStart(final ConcreteResource resource, final int timeoutSeconds, final InputStream stream, final long length, final String contentType, final Transport transport) throws TransferException {
    if (transport == null) {
        return false;
    }
    Future<PublishJob> future;
    synchronized (pending) {
        future = pending.get(resource);
        if (future == null) {
            final PublishJob job = transport.createPublishJob(resource, stream, length, timeoutSeconds);
            future = executor.submit(job);
            pending.put(resource, future);
        }
    }
    int waitSeconds = (int) (timeoutSeconds * config.getTimeoutOverextensionFactor());
    int tries = 1;
    try {
        while (tries > 0) {
            tries--;
            try {
                final PublishJob job = future.get(timeoutSeconds, TimeUnit.SECONDS);
                if (job.getError() != null) {
                    throw job.getError();
                }
                nfc.clearMissing(resource);
                return job.isSuccessful();
            } catch (final InterruptedException e) {
                throw new TransferException("Interrupted publish: {}. Reason: {}", e, resource, e.getMessage());
            } catch (final ExecutionException e) {
                throw new TransferException("Failed to publish: {}. Reason: {}", e, resource, e.getMessage());
            } catch (final TimeoutException e) {
                Long size = transferSizes.get(resource);
                if (tries > 0) {
                    continue;
                } else if (size != null && size > config.getThresholdWaitRetrySize()) {
                    logger.debug("Publishing a large file: {}. Retrying Future.get() up to {} times.", size, tries);
                    tries = (int) (size / config.getWaitRetryScalingIncrement());
                    continue;
                } else {
                    throw new TransferTimeoutException(resource, "Timed out waiting for execution of: {}", e, resource);
                }
            } catch (final TransferException e) {
                throw e;
            } catch (final Exception e) {
                throw new TransferException("Failed listing: {}. Reason: {}", e, resource, e.getMessage());
            }
        }
    } finally {
        transferSizes.remove(resource);
        //            logger.info( "Marking download complete: {}", url );
        pending.remove(resource);
    }
    return false;
}
Also used : TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) TransferException(org.commonjava.maven.galley.TransferException) ExecutionException(java.util.concurrent.ExecutionException) PublishJob(org.commonjava.maven.galley.spi.transport.PublishJob) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException) TransferLocationException(org.commonjava.maven.galley.TransferLocationException) TransferException(org.commonjava.maven.galley.TransferException) TimeoutException(java.util.concurrent.TimeoutException) TransferTimeoutException(org.commonjava.maven.galley.TransferTimeoutException)

Example 18 with TransferException

use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.

the class SimpleUrlLocationResolver method resolve.

@Override
public final Location resolve(final String spec) throws TransferException {
    final Location location = new SimpleLocation(spec);
    final List<Location> locations = locationExpander.expand(location);
    if (locations == null || locations.isEmpty()) {
        throw new TransferException("Invalid location: '%s'. Location expansion returned no results.", spec);
    }
    for (final Iterator<Location> iterator = new ArrayList<Location>(locations).iterator(); iterator.hasNext(); ) {
        final Location loc = iterator.next();
        // normally, this will probably throw an exception if no transport is available.
        // in case it's not, remove the location if the transport is null.
        final Transport transport = transportManager.getTransport(loc);
        if (transport == null) {
            iterator.remove();
        }
    }
    if (locations == null || locations.isEmpty()) {
        throw new TransferException("Invalid location: '%s'. No transports available for expanded locations.", spec);
    }
    return location;
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Transport(org.commonjava.maven.galley.spi.transport.Transport) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location)

Example 19 with TransferException

use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.

the class MavenPomReader method readLocalPom.

public MavenPomView readLocalPom(final ProjectVersionRef ref, final Transfer transfer, final boolean cache, final EventMetadata eventMetadata, final String... activeProfileIds) throws GalleyMavenException {
    DocRef<ProjectVersionRef> dr;
    try {
        dr = getDocRef(ref, transfer, cache, eventMetadata);
    } catch (final TransferException e) {
        throw new GalleyMavenException("Failed to parse POM for: {}. Reason: {}", e, ref, e.getMessage());
    }
    final MavenPomView view = new MavenPomView(ref, Collections.singletonList(dr), xpath, pluginDefaults, pluginImplications, xml, activeProfileIds);
    logStructure(view);
    return view;
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView)

Example 20 with TransferException

use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.

the class MavenPomReader method read.

public MavenPomView read(final ProjectVersionRef ref, final List<? extends Location> locations, final boolean cache, final EventMetadata eventMetadata, final String... activeProfileIds) throws GalleyMavenException {
    final List<DocRef<ProjectVersionRef>> stack = new ArrayList<DocRef<ProjectVersionRef>>();
    ProjectVersionRef next = ref;
    do {
        DocRef<ProjectVersionRef> dr;
        try {
            dr = getDocRef(next, locations, cache, eventMetadata);
        } catch (final TransferException e) {
            throw new GalleyMavenException("Failed to retrieve POM for: {}, {} levels deep in ancestry stack of: {}. Reason: {}", e, next, stack.size(), ref, e.getMessage());
        }
        if (dr == null) {
            throw new GalleyMavenException("Cannot resolve {}, {} levels dep in the ancestry stack of: {}", next, stack.size(), ref);
        }
        stack.add(dr);
        next = xml.getParentRef(dr.getDoc());
    } while (next != null);
    final MavenPomView view = new MavenPomView(ref, stack, xpath, pluginDefaults, pluginImplications, xml, activeProfileIds);
    assembleImportedInformation(view, locations);
    logStructure(view);
    return view;
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ArrayList(java.util.ArrayList) DocRef(org.commonjava.maven.galley.maven.model.view.DocRef) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView)

Aggregations

TransferException (org.commonjava.maven.galley.TransferException)49 IOException (java.io.IOException)17 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)15 Transfer (org.commonjava.maven.galley.model.Transfer)12 ArrayList (java.util.ArrayList)9 TransferLocationException (org.commonjava.maven.galley.TransferLocationException)9 TransferTimeoutException (org.commonjava.maven.galley.TransferTimeoutException)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 OutputStream (java.io.OutputStream)7 ListingResult (org.commonjava.maven.galley.model.ListingResult)7 InputStream (java.io.InputStream)6 Location (org.commonjava.maven.galley.model.Location)6 File (java.io.File)5 HashMap (java.util.HashMap)5 JarFile (java.util.jar.JarFile)5 ZipEntry (java.util.zip.ZipEntry)5 ZipFile (java.util.zip.ZipFile)5 SimpleHttpLocation (org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation)5 Test (org.junit.Test)5 ExecutionException (java.util.concurrent.ExecutionException)4