Search in sources :

Example 11 with ListingResult

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

the class TransferManagerImpl method listAll.

@Override
public List<ListingResult> listAll(final VirtualResource virt, final EventMetadata metadata) throws TransferException {
    final Map<ConcreteResource, Future<ListingResult>> futureList = new HashMap<>();
    for (final ConcreteResource res : virt) {
        final Future<ListingResult> listingFuture = executorService.submit(new Callable<ListingResult>() {

            @Override
            public ListingResult call() throws TransferException {
                return doList(res, true, metadata);
            }
        });
        futureList.put(res, listingFuture);
    }
    final List<ListingResult> results = new ArrayList<>();
    for (Map.Entry<ConcreteResource, Future<ListingResult>> entry : futureList.entrySet()) {
        Future<ListingResult> listingFuture = entry.getValue();
        ConcreteResource res = entry.getKey();
        ListingResult listing;
        try {
            listing = listingFuture.get();
        } catch (InterruptedException ex) {
            throw new TransferException("Listing of %s was interrupted", ex, res);
        } catch (ExecutionException ex) {
            throw new TransferException("Listing of %s threw an error: %s", ex, res, ex);
        }
        if (listing != null) {
            results.add(listing);
        }
    }
    return results;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ListingResult(org.commonjava.maven.galley.model.ListingResult) TransferException(org.commonjava.maven.galley.TransferException) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with ListingResult

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

the class HttpListTest method simpleCentralListing_Error.

@Test
public void simpleCentralListing_Error() throws Exception {
    final String dir = "central-error/";
    final String fname = dir + "index.html";
    final String listingFname = dir + ".listing.txt";
    final String url = fixture.formatUrl(fname);
    final SimpleHttpLocation location = new SimpleHttpLocation("test", url, true, true, true, true, null);
    fixture.registerException(fixture.getUrlPath(url), "Test Error");
    final Transfer transfer = fixture.getTransfer(new ConcreteResource(location, listingFname));
    final HttpListing listing = new HttpListing(url, new ConcreteResource(location, fname), fixture.getHttp());
    final ListingResult result = listing.call();
    assertThat(result, nullValue());
    assertThat(listing.getError(), notNullValue());
    assertTrue(listing.getError().getMessage().contains("Test Error"));
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ListingResult(org.commonjava.maven.galley.model.ListingResult) Test(org.junit.Test)

Example 13 with ListingResult

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

the class HttpListTest method simpleCentralListing.

@Test
public void simpleCentralListing() throws Exception {
    final String dir = "central-btm/";
    final String fname = dir + "index.html";
    final String listingFname = dir + ".listing.txt";
    final String url = fixture.formatUrl(fname);
    final String body = getBody(fname);
    fixture.getServer().expect(url, 200, body);
    final SimpleHttpLocation location = new SimpleHttpLocation("test", url, true, true, true, true, null);
    final Transfer transfer = fixture.getTransfer(new ConcreteResource(location, listingFname));
    final HttpListing listing = new HttpListing(url, new ConcreteResource(location, fname), fixture.getHttp());
    final ListingResult result = listing.call();
    assertThat(listing.getError(), nullValue());
    assertThat(result, notNullValue());
    assertThat(result.getListing(), notNullValue());
    System.out.println("Got listing\n\n  " + StringUtils.join(result.getListing(), "\n  ") + "\n\n");
    assertTrue(Arrays.equals(centralbtm, result.getListing()));
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ListingResult(org.commonjava.maven.galley.model.ListingResult) Test(org.junit.Test)

Example 14 with ListingResult

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

the class HttpListTest method simpleNexusListing_Missing.

@Test
public void simpleNexusListing_Missing() throws Exception {
    final String dir = "nexus-missing/";
    final String fname = dir + "index.html";
    final String listingFname = dir + ".listing.txt";
    final String url = fixture.formatUrl(fname);
    final SimpleHttpLocation location = new SimpleHttpLocation("test", url, true, true, true, true, null);
    final Transfer transfer = fixture.getTransfer(new ConcreteResource(location, listingFname));
    final HttpListing listing = new HttpListing(url, new ConcreteResource(location, fname), fixture.getHttp());
    final ListingResult result = listing.call();
    assertThat(listing.getError(), nullValue());
    assertThat(result, nullValue());
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ListingResult(org.commonjava.maven.galley.model.ListingResult) Test(org.junit.Test)

Example 15 with ListingResult

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

the class HttpListTest method simpleNexusListing_Error.

@Test
public void simpleNexusListing_Error() throws Exception {
    final String dir = "nexus-error/";
    final String fname = dir + "index.html";
    final String listingFname = dir + ".listing.txt";
    final String url = fixture.formatUrl(fname);
    final SimpleHttpLocation location = new SimpleHttpLocation("test", url, true, true, true, true, null);
    fixture.registerException(fixture.getUrlPath(url), "Test Error");
    final Transfer transfer = fixture.getTransfer(new ConcreteResource(location, listingFname));
    final HttpListing listing = new HttpListing(url, new ConcreteResource(location, fname), fixture.getHttp());
    final ListingResult result = listing.call();
    assertThat(result, nullValue());
    assertThat(listing.getError(), notNullValue());
    assertTrue(listing.getError().getMessage().contains("Test Error"));
}
Also used : SimpleHttpLocation(org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ListingResult(org.commonjava.maven.galley.model.ListingResult) Test(org.junit.Test)

Aggregations

ListingResult (org.commonjava.maven.galley.model.ListingResult)21 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)12 TransferException (org.commonjava.maven.galley.TransferException)11 ArrayList (java.util.ArrayList)9 Transfer (org.commonjava.maven.galley.model.Transfer)8 StoreResource (org.commonjava.indy.content.StoreResource)7 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)7 SimpleHttpLocation (org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation)7 Test (org.junit.Test)7 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)5 VirtualResource (org.commonjava.maven.galley.model.VirtualResource)5 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)4 TransferLocationException (org.commonjava.maven.galley.TransferLocationException)4 IOException (java.io.IOException)3 TransferTimeoutException (org.commonjava.maven.galley.TransferTimeoutException)3 Logger (org.slf4j.Logger)3 InputStream (java.io.InputStream)2 IndyStoreErrorEvent (org.commonjava.indy.change.event.IndyStoreErrorEvent)2 BadGatewayException (org.commonjava.maven.galley.BadGatewayException)2 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)2