Search in sources :

Example 91 with ConcreteResource

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

the class IndyPathGeneratorTest method testGetHashedPathUnification.

@Test
public void testGetHashedPathUnification() {
    ConcreteResource resource = new StoreResource(location, "abc/xyz/license.html");
    String pathWithoutSlash = pathGenerator.getPath(resource);
    resource = new StoreResource(location, "/abc/xyz/license.html");
    String pathWithSlash = pathGenerator.getPath(resource);
    assertThat(pathWithoutSlash, is(pathWithSlash));
    resource = new StoreResource(location, "//abc/xyz/license.html");
    String pathWithDoubleSlash = pathGenerator.getPath(resource);
    assertThat(pathWithoutSlash, is(pathWithDoubleSlash));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Test(org.junit.Test)

Example 92 with ConcreteResource

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

the class IndyPathGeneratorTest method testGetHashedRootBasedPathUnification.

@Test
public void testGetHashedRootBasedPathUnification() {
    ConcreteResource resource = new StoreResource(location, "license.html");
    String pathWithoutSlash = pathGenerator.getPath(resource);
    resource = new StoreResource(location, "/license.html");
    String pathWithSlash = pathGenerator.getPath(resource);
    assertThat(pathWithoutSlash, is(pathWithSlash));
    resource = new StoreResource(location, "//license.html");
    String pathWithDoubleSlash = pathGenerator.getPath(resource);
    assertThat(pathWithoutSlash, is(pathWithDoubleSlash));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Test(org.junit.Test)

Example 93 with ConcreteResource

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

the class HtmlContentListBuilder method buildContent.

@Override
public List<ConcreteResource> buildContent(final RemoteRepository repository, final boolean isRescan) {
    if (repository.getPrefetchPriority() <= 0) {
        logger.warn("The repository {} prefetch disabled, can not use html content listing", repository.getName());
        return Collections.emptyList();
    }
    final Set<String> pathMasks = repository.getPathMaskPatterns();
    boolean useDefault = true;
    if (pathMasks != null && !pathMasks.isEmpty()) {
        useDefault = pathMasks.stream().anyMatch(p -> PathMaskChecker.isRegexPattern(p));
    }
    if (useDefault) {
        final String rootPath = "/";
        final KeyedLocation loc = LocationUtils.toLocation(repository);
        final StoreResource res = new StoreResource(loc, rootPath);
        try {
            // If this is a rescan prefetch, we need to clear the listing cache and re-fetch from external
            if (isRescan) {
                transferManager.delete(new StoreResource(loc, "/.listing.txt"));
            }
            final ListingResult lr = transferManager.list(res);
            if (lr != null && lr.getListing() != null) {
                String[] files = lr.getListing();
                List<ConcreteResource> resources = new ArrayList<>(files.length);
                for (final String file : lr.getListing()) {
                    resources.add(new StoreResource(loc, rootPath, file));
                }
                return resources;
            }
        } catch (TransferException e) {
            logger.error(String.format("Can not get transfer for repository %s", repository), e);
        }
    } else {
        // if all path mask patterns are plaintext, we will use these as the download list directly.
        return pathMasks.stream().map(p -> new StoreResource(LocationUtils.toLocation(repository), p)).collect(Collectors.toList());
    }
    return Collections.emptyList();
}
Also used : LocationUtils(org.commonjava.indy.util.LocationUtils) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ListingResult(org.commonjava.maven.galley.model.ListingResult) PathMaskChecker(org.commonjava.indy.core.content.PathMaskChecker) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) PREFETCH_LISTING_TYPE_HTML(org.commonjava.indy.model.core.RemoteRepository.PREFETCH_LISTING_TYPE_HTML) Inject(javax.inject.Inject) List(java.util.List) TransferManager(org.commonjava.maven.galley.TransferManager) StoreResource(org.commonjava.indy.content.StoreResource) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Collections(java.util.Collections) TransferException(org.commonjava.maven.galley.TransferException) StoreResource(org.commonjava.indy.content.StoreResource) TransferException(org.commonjava.maven.galley.TransferException) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ArrayList(java.util.ArrayList) ListingResult(org.commonjava.maven.galley.model.ListingResult)

Example 94 with ConcreteResource

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

the class PrefetchWorker method run.

@Override
public void run() {
    if (resources == null || resources.isEmpty()) {
        logger.trace("No resources for downloading");
        return;
    }
    logger.trace("Start downloading: {}", resources);
    final AtomicBoolean scheduled = new AtomicBoolean(false);
    for (Map.Entry<RemoteRepository, List<RescanableResourceWrapper>> entry : resources.entrySet()) {
        final RemoteRepository repo = entry.getKey();
        final List<RescanableResourceWrapper> res = entry.getValue();
        res.forEach(r -> {
            try {
                final String path = r.getResource().getPath();
                if (path == null || path.equals("") || path.endsWith("/") || path.endsWith(LISTING_HTML_FILE)) {
                    // If this is a rescan prefetch, we need to clear the listing cache and re-fetch from external
                    if (r.isRescan()) {
                        transfers.delete(new ConcreteResource(r.getResource().getLocation(), path, ".listing.txt"));
                    }
                    final List<RescanablePath> dirPaths = buildPaths(r.getResource(), r.isRescan());
                    logger.trace("{} is folder, will use it to schedule new Resources {}", r, dirPaths);
                    frontier.scheduleRepo(repo, dirPaths);
                    scheduled.set(true);
                } else {
                    // if repo has path masks, we need to check that first to only download path mask enabled artifacts.
                    if (PathMaskChecker.checkMask(repo, path)) {
                        // If this is a rescan prefetch, and artifact is metadata, we need to clear it and re-fetch from external
                        if (r.isRescan()) {
                            final SpecialPathInfo spi = specialPathManager.getSpecialPathInfo(r.getResource());
                            if (spi != null && spi.isMetadata()) {
                                transfers.delete(r.getResource());
                            }
                        }
                        logger.trace("{} is file", r);
                        transfers.retrieve(r.getResource());
                    } else {
                        logger.trace("Path {} in repo {} not available for path mask {}", path, repo, repo.getPathMaskPatterns());
                    }
                }
            } catch (TransferException e) {
                logger.error("Download failed during prefetch because of transfer getting failed for {}, Reason: {}", r, e.getMessage());
            }
        });
    }
    if (scheduled.get()) {
        prefetchManager.triggerWorkers();
    }
}
Also used : RescanablePath(org.commonjava.indy.subsys.prefetch.models.RescanablePath) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) RescanableResourceWrapper(org.commonjava.indy.subsys.prefetch.models.RescanableResourceWrapper) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TransferException(org.commonjava.maven.galley.TransferException) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 95 with ConcreteResource

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

the class PrefetchFrontier method get.

public Map<RemoteRepository, List<ConcreteResource>> get(final int size) {
    return lockAnd(t -> {
        Map<RemoteRepository, List<ConcreteResource>> resources = new HashMap<>(2);
        int removedSize = 0;
        for (RemoteRepository repo : repoQueue) {
            List<RescanablePath> paths = resourceCache.get(repo);
            if (paths != null && !paths.isEmpty()) {
                List<ConcreteResource> res = new ArrayList<>(size);
                for (RescanablePath path : paths) {
                    res.add(new StoreResource(LocationUtils.toLocation(repo), path.getPath()));
                }
                resources.put(repo, res);
                if (removedSize >= size) {
                    return resources;
                }
            }
        }
        return resources;
    });
}
Also used : StoreResource(org.commonjava.indy.content.StoreResource) RescanablePath(org.commonjava.indy.subsys.prefetch.models.RescanablePath) HashMap(java.util.HashMap) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ArrayList(java.util.ArrayList) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ArrayList(java.util.ArrayList) List(java.util.List)

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