Search in sources :

Example 1 with IndexPackingRequest

use of org.apache.maven.index.packer.IndexPackingRequest in project archiva by apache.

the class MavenIndexManager method pack.

@Override
public void pack(final ArchivaIndexingContext context) throws IndexUpdateFailedException {
    executeUpdateFunction(context, indexingContext -> {
        try {
            IndexPackingRequest request = new IndexPackingRequest(indexingContext, indexingContext.acquireIndexSearcher().getIndexReader(), indexingContext.getIndexDirectoryFile());
            indexPacker.packIndex(request);
            indexingContext.updateTimestamp(true);
        } catch (IOException e) {
            log.error("IOException while packing index of context " + context.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""));
            throw new IndexUpdateFailedException("IOException during update of " + context.getId(), e);
        }
    });
}
Also used : IndexPackingRequest(org.apache.maven.index.packer.IndexPackingRequest) IOException(java.io.IOException) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException)

Example 2 with IndexPackingRequest

use of org.apache.maven.index.packer.IndexPackingRequest in project archiva by apache.

the class DefaultIndexMerger method buildMergedIndex.

@Override
public IndexingContext buildMergedIndex(IndexMergerRequest indexMergerRequest) throws IndexMergerException {
    String groupId = indexMergerRequest.getGroupId();
    if (runningGroups.contains(groupId)) {
        log.info("skip build merge remote indexes for id: '{}' as already running", groupId);
        return null;
    }
    runningGroups.add(groupId);
    StopWatch stopWatch = new StopWatch();
    stopWatch.reset();
    stopWatch.start();
    Path mergedIndexDirectory = indexMergerRequest.getMergedIndexDirectory();
    String tempRepoId = mergedIndexDirectory.getFileName().toString();
    try {
        Path indexLocation = mergedIndexDirectory.resolve(indexMergerRequest.getMergedIndexPath());
        List<IndexingContext> members = indexMergerRequest.getRepositoriesIds().stream().map(id -> repositoryRegistry.getRepository(id)).filter(repo -> repo.getType().equals(RepositoryType.MAVEN)).map(repo -> {
            try {
                return repo.getIndexingContext().getBaseContext(IndexingContext.class);
            } catch (UnsupportedBaseContextException e) {
                return null;
            // Ignore
            }
        }).filter(Objects::nonNull).collect(Collectors.toList());
        ContextMemberProvider memberProvider = new StaticContextMemberProvider(members);
        IndexingContext mergedCtx = indexer.createMergedIndexingContext(tempRepoId, tempRepoId, mergedIndexDirectory.toFile(), indexLocation.toFile(), true, memberProvider);
        mergedCtx.optimize();
        if (indexMergerRequest.isPackIndex()) {
            IndexPackingRequest request = new // 
            IndexPackingRequest(// 
            mergedCtx, // 
            mergedCtx.acquireIndexSearcher().getIndexReader(), indexLocation.toFile());
            indexPacker.packIndex(request);
        }
        if (indexMergerRequest.isTemporary()) {
            temporaryGroupIndexes.add(new TemporaryGroupIndex(mergedIndexDirectory, tempRepoId, groupId, indexMergerRequest.getMergedIndexTtl()));
            temporaryContextes.add(mergedCtx);
        }
        stopWatch.stop();
        log.info("merged index for repos {} in {} s", indexMergerRequest.getRepositoriesIds(), stopWatch.getTime());
        return mergedCtx;
    } catch (IOException e) {
        throw new IndexMergerException(e.getMessage(), e);
    } finally {
        runningGroups.remove(groupId);
    }
}
Also used : Path(java.nio.file.Path) Async(org.springframework.scheduling.annotation.Async) UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) StaticContextMemberProvider(org.apache.maven.index.context.StaticContextMemberProvider) LoggerFactory(org.slf4j.LoggerFactory) IndexCreator(org.apache.maven.index.context.IndexCreator) Inject(javax.inject.Inject) Service(org.springframework.stereotype.Service) FileUtils(org.apache.archiva.common.utils.FileUtils) IndexPackingRequest(org.apache.maven.index.packer.IndexPackingRequest) Path(java.nio.file.Path) Logger(org.slf4j.Logger) IndexPacker(org.apache.maven.index.packer.IndexPacker) Files(java.nio.file.Files) ContextMemberProvider(org.apache.maven.index.context.ContextMemberProvider) Collection(java.util.Collection) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) IOException(java.io.IOException) TemporaryGroupIndex(org.apache.archiva.indexer.merger.TemporaryGroupIndex) RepositoryType(org.apache.archiva.repository.RepositoryType) Collectors(java.util.stream.Collectors) IndexMerger(org.apache.archiva.indexer.merger.IndexMerger) IndexMergerException(org.apache.archiva.indexer.merger.IndexMergerException) Indexer(org.apache.maven.index.Indexer) Objects(java.util.Objects) List(java.util.List) IndexingContext(org.apache.maven.index.context.IndexingContext) IndexMergerRequest(org.apache.archiva.indexer.merger.IndexMergerRequest) StopWatch(org.apache.commons.lang.time.StopWatch) Optional(java.util.Optional) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TemporaryGroupIndex(org.apache.archiva.indexer.merger.TemporaryGroupIndex) StaticContextMemberProvider(org.apache.maven.index.context.StaticContextMemberProvider) ContextMemberProvider(org.apache.maven.index.context.ContextMemberProvider) IOException(java.io.IOException) StopWatch(org.apache.commons.lang.time.StopWatch) UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) IndexPackingRequest(org.apache.maven.index.packer.IndexPackingRequest) IndexingContext(org.apache.maven.index.context.IndexingContext) StaticContextMemberProvider(org.apache.maven.index.context.StaticContextMemberProvider) IndexMergerException(org.apache.archiva.indexer.merger.IndexMergerException)

Example 3 with IndexPackingRequest

use of org.apache.maven.index.packer.IndexPackingRequest in project archiva by apache.

the class ArchivaIndexingTaskExecutor method finishIndexingTask.

private void finishIndexingTask(ArtifactIndexingTask indexingTask, ManagedRepository repository, IndexingContext context) throws TaskExecutionException {
    try {
        log.debug("Finishing indexing");
        context.optimize();
        if (repository.supportsFeature(IndexCreationFeature.class)) {
            IndexCreationFeature icf = repository.getFeature(IndexCreationFeature.class).get();
            if (!icf.isSkipPackedIndexCreation() && icf.getLocalPackedIndexPath() != null) {
                log.debug("Creating packed index from {} on {}", context.getIndexDirectoryFile(), icf.getLocalPackedIndexPath());
                IndexPackingRequest request = new // 
                IndexPackingRequest(// 
                context, context.acquireIndexSearcher().getIndexReader(), icf.getLocalPackedIndexPath().toFile());
                indexPacker.packIndex(request);
                context.updateTimestamp(true);
                log.debug("Index file packed at '{}'.", icf.getLocalPackedIndexPath());
            } else {
                log.debug("skip packed index creation");
            }
        } else {
            log.debug("skip packed index creation");
        }
    } catch (IOException e) {
        log.error("Error occurred while executing indexing task '{}': {}", indexingTask, e.getMessage());
        throw new TaskExecutionException("Error occurred while executing indexing task '" + indexingTask + "'", e);
    }
}
Also used : TaskExecutionException(org.apache.archiva.redback.components.taskqueue.execution.TaskExecutionException) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) IndexPackingRequest(org.apache.maven.index.packer.IndexPackingRequest) IOException(java.io.IOException)

Example 4 with IndexPackingRequest

use of org.apache.maven.index.packer.IndexPackingRequest in project archiva by apache.

the class ArchivaIndexManagerMock method pack.

@Override
public void pack(final ArchivaIndexingContext context) throws IndexUpdateFailedException {
    executeUpdateFunction(context, indexingContext -> {
        try {
            IndexPackingRequest request = new IndexPackingRequest(indexingContext, indexingContext.acquireIndexSearcher().getIndexReader(), indexingContext.getIndexDirectoryFile());
            indexPacker.packIndex(request);
            indexingContext.updateTimestamp(true);
        } catch (IOException e) {
            log.error("IOException while packing index of context " + context.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""));
            throw new IndexUpdateFailedException("IOException during update of " + context.getId(), e);
        }
    });
}
Also used : IndexPackingRequest(org.apache.maven.index.packer.IndexPackingRequest) IOException(java.io.IOException) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException)

Example 5 with IndexPackingRequest

use of org.apache.maven.index.packer.IndexPackingRequest in project archiva by apache.

the class ArchivaIndexManagerMock method pack.

@Override
public void pack(final ArchivaIndexingContext context) throws IndexUpdateFailedException {
    executeUpdateFunction(context, indexingContext -> {
        try {
            IndexPackingRequest request = new IndexPackingRequest(indexingContext, indexingContext.acquireIndexSearcher().getIndexReader(), indexingContext.getIndexDirectoryFile());
            indexPacker.packIndex(request);
            indexingContext.updateTimestamp(true);
        } catch (IOException e) {
            log.error("IOException while packing index of context " + context.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""));
            throw new IndexUpdateFailedException("IOException during update of " + context.getId(), e);
        }
    });
}
Also used : IndexPackingRequest(org.apache.maven.index.packer.IndexPackingRequest) IOException(java.io.IOException) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException)

Aggregations

IOException (java.io.IOException)5 IndexPackingRequest (org.apache.maven.index.packer.IndexPackingRequest)5 IndexUpdateFailedException (org.apache.archiva.indexer.IndexUpdateFailedException)3 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Collection (java.util.Collection)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 FileUtils (org.apache.archiva.common.utils.FileUtils)1 UnsupportedBaseContextException (org.apache.archiva.indexer.UnsupportedBaseContextException)1 IndexMerger (org.apache.archiva.indexer.merger.IndexMerger)1 IndexMergerException (org.apache.archiva.indexer.merger.IndexMergerException)1 IndexMergerRequest (org.apache.archiva.indexer.merger.IndexMergerRequest)1 TemporaryGroupIndex (org.apache.archiva.indexer.merger.TemporaryGroupIndex)1 TaskExecutionException (org.apache.archiva.redback.components.taskqueue.execution.TaskExecutionException)1 RepositoryRegistry (org.apache.archiva.repository.RepositoryRegistry)1