Search in sources :

Example 56 with ConcreteResource

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

the class RoutingCacheProviderWrapperTest method prepare.

@Before
public void prepare() throws Exception {
    final File cacheDir = temp.newFolder();
    partylineFac = new PartyLineCacheProviderFactory(cacheDir);
    DefaultCacheManager cacheManager = new DefaultCacheManager();
    SimpleCacheInstance<String, String> cacheInstance = new SimpleCacheInstance<>("test", cacheManager.getCache("simpleNfsCache"));
    SimpleCacheInstance<String, ConcreteResource> testLocalFileCacheInstance = new SimpleCacheInstance<>("testLocalFileCache", cacheManager.getCache("simpleLocalFileCache"));
    fastLocalFac = new FastLocalCacheProviderFactory(cacheDir, temp.newFolder(), cacheInstance, testLocalFileCacheInstance, Executors.newFixedThreadPool(5));
}
Also used : PartyLineCacheProviderFactory(org.commonjava.maven.galley.cache.partyline.PartyLineCacheProviderFactory) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) FastLocalCacheProviderFactory(org.commonjava.maven.galley.cache.infinispan.FastLocalCacheProviderFactory) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) File(java.io.File) SimpleCacheInstance(org.commonjava.maven.galley.cache.infinispan.SimpleCacheInstance) Before(org.junit.Before)

Example 57 with ConcreteResource

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

the class TransferManagerImpl method retrieveFirst.

@Override
public Transfer retrieveFirst(final VirtualResource virt, final EventMetadata eventMetadata) throws TransferException {
    Transfer target;
    TransferException lastError = null;
    int tries = 0;
    for (final ConcreteResource res : virt) {
        tries++;
        if (res == null) {
            continue;
        }
        try {
            target = retrieve(res, true, eventMetadata);
            lastError = null;
            if (target != null && target.exists()) {
                return target;
            }
        } catch (final TransferException e) {
            logger.warn("Failed to retrieve: {}. {} more tries. (Reason: {})", res, (virt.toConcreteResources().size() - tries), e.getMessage());
            lastError = e;
        }
    }
    if (lastError != null) {
        throw lastError;
    }
    fileEventManager.fire(new FileNotFoundEvent(virt, eventMetadata));
    return null;
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) FileNotFoundEvent(org.commonjava.maven.galley.event.FileNotFoundEvent) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource)

Example 58 with ConcreteResource

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

the class TransferManagerImpl method doBatch.

@SuppressWarnings("RedundantThrows")
private <T extends TransferBatch> T doBatch(final Set<Resource> resources, final T batch, final boolean suppressFailures, final EventMetadata eventMetadata) throws TransferException {
    logger.info("Attempting to batch-retrieve {} resources:\n  {}", resources.size(), new JoinString("\n  ", resources));
    final Set<BatchRetriever> retrievers = new HashSet<>(resources.size());
    for (final Resource resource : resources) {
        retrievers.add(new BatchRetriever(this, resource, suppressFailures, eventMetadata));
    }
    final Map<ConcreteResource, TransferException> errors = new HashMap<>();
    final Map<ConcreteResource, Transfer> transfers = new HashMap<>();
    do {
        for (final BatchRetriever retriever : retrievers) {
            batchExecutor.submit(retriever);
        }
        int count = retrievers.size();
        for (int i = 0; i < count; i++) {
            try {
                Future<BatchRetriever> pending = batchExecutor.take();
                BatchRetriever retriever = pending.get();
                final ConcreteResource resource = retriever.getLastTry();
                final TransferException error = retriever.getError();
                if (error != null) {
                    logger.warn("ERROR: {}...{}", error, resource, error.getMessage());
                    retrievers.remove(retriever);
                    if (!(error instanceof TransferLocationException)) {
                        errors.put(resource, error);
                    }
                    continue;
                }
                final Transfer transfer = retriever.getTransfer();
                if (transfer != null && transfer.exists()) {
                    transfers.put(resource, transfer);
                    retrievers.remove(retriever);
                    logger.debug("Completed: {}", resource);
                    continue;
                }
                if (!retriever.hasMoreTries()) {
                    logger.debug("Not completed, but out of tries: {}", resource);
                    retrievers.remove(retriever);
                }
            } catch (final InterruptedException e) {
                logger.error(String.format("Failed to wait for batch retrieval attempts to complete: %s", e.getMessage()), e);
                break;
            } catch (ExecutionException e) {
                logger.error(String.format("Failed to retrieve next completed retrieval: %s", e.getMessage()), e);
            }
        }
    } while (!retrievers.isEmpty());
    batch.setErrors(errors);
    batch.setTransfers(transfers);
    return batch;
}
Also used : HashMap(java.util.HashMap) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Resource(org.commonjava.maven.galley.model.Resource) VirtualResource(org.commonjava.maven.galley.model.VirtualResource) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) BatchRetriever(org.commonjava.maven.galley.internal.xfer.BatchRetriever) TransferException(org.commonjava.maven.galley.TransferException) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) TransferLocationException(org.commonjava.maven.galley.TransferLocationException) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet)

Example 59 with ConcreteResource

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

the class PartyLineCacheProviderConcurrentIOTest method testBigFileWrite.

@Test
public void testBigFileWrite() throws Exception {
    StringBuilder builder = new StringBuilder();
    int loop = 1024 * 1024 * 10;
    for (int i = 0; i < loop; i++) {
        builder.append(content);
    }
    final String bigContent = builder.toString();
    System.out.println(String.format("the content size is: %dm", bigContent.length() / 1024 / 1024));
    final ConcreteResource resource = createTestResource("file_read_write_bigfile.txt");
    new WriteTask(provider, bigContent, resource, null).run();
    assertThat(provider.exists(resource), equalTo(true));
    assertThat(TestIOUtils.readFromStream(new FileInputStream(provider.getDetachedFile(resource))), equalTo(bigContent));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) WriteTask(org.commonjava.maven.galley.cache.iotasks.WriteTask) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 60 with ConcreteResource

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

the class CacheProviderTCK method writeAndListDirectory.

@Test
public void writeAndListDirectory() throws Exception {
    final String content = "This is a test";
    final Location loc = new SimpleLocation("http://foo.com");
    final String dir = "/path/to/my/";
    final String fname = dir + "file.txt";
    final CacheProvider provider = getCacheProvider();
    final OutputStream out = provider.openOutputStream(new ConcreteResource(loc, fname));
    out.write(content.getBytes("UTF-8"));
    out.flush();
    out.close();
    // NOTE: This is NOT as tightly specified as I would like.
    // We keep the listing assertions loose (greater-than instead of equals,
    // contains instead of exact positional assertion) because the Infinispan
    // live testing has these spurious foo.txt.#0 files cropping up.
    // 
    // I have no idea what they are, but I'm sick of fighting JBoss bugs for now.
    final Set<String> listing = new HashSet<String>(Arrays.asList(provider.list(new ConcreteResource(loc, dir))));
    System.out.printf("\n\nFile listing is:\n\n  %s\n\n\n", join(listing, "\n  "));
    assertThat(listing.size() > 0, equalTo(true));
    assertThat(listing.contains("file.txt"), equalTo(true));
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) CacheProvider(org.commonjava.maven.galley.spi.cache.CacheProvider) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)206 Test (org.junit.Test)138 Transfer (org.commonjava.maven.galley.model.Transfer)92 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)55 Location (org.commonjava.maven.galley.model.Location)45 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)36 BMScript (org.jboss.byteman.contrib.bmunit.BMScript)33 OutputStream (java.io.OutputStream)30 InputStream (java.io.InputStream)26 Group (org.commonjava.indy.model.core.Group)25 ArrayList (java.util.ArrayList)23 HostedRepository (org.commonjava.indy.model.core.HostedRepository)23 TransferException (org.commonjava.maven.galley.TransferException)23 SimpleHttpLocation (org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation)23 HashSet (java.util.HashSet)22 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)18 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)18 Logger (org.slf4j.Logger)18 ByteArrayInputStream (java.io.ByteArrayInputStream)17 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)16