Search in sources :

Example 1 with UnsupportedBaseContextException

use of org.apache.archiva.indexer.UnsupportedBaseContextException in project archiva by apache.

the class ArchivaIndexManagerMock method move.

@Override
public ArchivaIndexingContext move(ArchivaIndexingContext context, Repository repo) throws IndexCreationFailedException {
    if (context == null) {
        return null;
    }
    if (context.supports(IndexingContext.class)) {
        try {
            Path newPath = getIndexPath(repo);
            IndexingContext ctx = context.getBaseContext(IndexingContext.class);
            Path oldPath = ctx.getIndexDirectoryFile().toPath();
            if (oldPath.equals(newPath)) {
                // Nothing to do, if path does not change
                return context;
            }
            if (!Files.exists(oldPath)) {
                return createContext(repo);
            } else if (context.isEmpty()) {
                context.close();
                return createContext(repo);
            } else {
                context.close(false);
                Files.move(oldPath, newPath);
                return createContext(repo);
            }
        } catch (IOException e) {
            log.error("IOException while moving index directory {}", e.getMessage(), e);
            throw new IndexCreationFailedException("Could not recreated the index.", e);
        } catch (UnsupportedBaseContextException e) {
            throw new IndexCreationFailedException("The given context, is not a maven context.");
        }
    } else {
        throw new IndexCreationFailedException("Bad context type. This is not a maven context.");
    }
}
Also used : Path(java.nio.file.Path) UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) IndexCreationFailedException(org.apache.archiva.indexer.IndexCreationFailedException) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexingContext(org.apache.maven.index.context.IndexingContext) IOException(java.io.IOException)

Example 2 with UnsupportedBaseContextException

use of org.apache.archiva.indexer.UnsupportedBaseContextException in project archiva by apache.

the class ArchivaIndexManagerMock method executeUpdateFunction.

/*
     * This method is used to do some actions around the update execution code. And to make sure, that no other
     * method is running on the same index.
     */
private void executeUpdateFunction(ArchivaIndexingContext context, IndexUpdateConsumer function) throws IndexUpdateFailedException {
    IndexingContext indexingContext = null;
    try {
        indexingContext = getMvnContext(context);
    } catch (UnsupportedBaseContextException e) {
        throw new IndexUpdateFailedException("Maven index is not supported by this context", e);
    }
    final Path ctxPath = getIndexPath(context);
    int loop = MAX_WAIT;
    boolean active = false;
    while (loop-- > 0 && !active) {
        active = activeContexts.add(ctxPath);
        try {
            Thread.currentThread().sleep(WAIT_TIME);
        } catch (InterruptedException e) {
        // Ignore this
        }
    }
    if (active) {
        try {
            function.accept(indexingContext);
        } finally {
            activeContexts.remove(ctxPath);
        }
    } else {
        throw new IndexUpdateFailedException("Timeout while waiting for index release on context " + context.getId());
    }
}
Also used : Path(java.nio.file.Path) UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexingContext(org.apache.maven.index.context.IndexingContext) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException)

Example 3 with UnsupportedBaseContextException

use of org.apache.archiva.indexer.UnsupportedBaseContextException in project archiva by apache.

the class MavenIndexManager method executeUpdateFunction.

/*
     * This method is used to do some actions around the update execution code. And to make sure, that no other
     * method is running on the same index.
     */
private void executeUpdateFunction(ArchivaIndexingContext context, IndexUpdateConsumer function) throws IndexUpdateFailedException {
    IndexingContext indexingContext = null;
    try {
        indexingContext = getMvnContext(context);
    } catch (UnsupportedBaseContextException e) {
        throw new IndexUpdateFailedException("Maven index is not supported by this context", e);
    }
    final Path ctxPath = getIndexPath(context);
    int loop = MAX_WAIT;
    boolean active = false;
    while (loop-- > 0 && !active) {
        active = activeContexts.add(ctxPath);
        try {
            Thread.currentThread().sleep(WAIT_TIME);
        } catch (InterruptedException e) {
        // Ignore this
        }
    }
    if (active) {
        try {
            function.accept(indexingContext);
        } finally {
            activeContexts.remove(ctxPath);
        }
    } else {
        throw new IndexUpdateFailedException("Timeout while waiting for index release on context " + context.getId());
    }
}
Also used : Path(java.nio.file.Path) UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) ArchivaIndexingContext(org.apache.archiva.indexer.ArchivaIndexingContext) IndexingContext(org.apache.maven.index.context.IndexingContext) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException)

Example 4 with UnsupportedBaseContextException

use of org.apache.archiva.indexer.UnsupportedBaseContextException in project archiva by apache.

the class MavenRepositorySearch method getIndexingContext.

private IndexingContext getIndexingContext(String id) {
    String repoId;
    if (StringUtils.startsWith(id, "remote-")) {
        repoId = StringUtils.substringAfter(id, "remote-");
    } else {
        repoId = id;
    }
    Repository repo = repositoryRegistry.getRepository(repoId);
    if (repo == null) {
        return null;
    } else {
        if (repo.getIndexingContext() != null) {
            try {
                return repo.getIndexingContext().getBaseContext(IndexingContext.class);
            } catch (UnsupportedBaseContextException e) {
                return null;
            }
        } else {
            return null;
        }
    }
}
Also used : UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) Repository(org.apache.archiva.repository.Repository) RemoteRepository(org.apache.archiva.repository.RemoteRepository)

Example 5 with UnsupportedBaseContextException

use of org.apache.archiva.indexer.UnsupportedBaseContextException 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)

Aggregations

UnsupportedBaseContextException (org.apache.archiva.indexer.UnsupportedBaseContextException)12 IndexingContext (org.apache.maven.index.context.IndexingContext)11 Path (java.nio.file.Path)8 ArchivaIndexingContext (org.apache.archiva.indexer.ArchivaIndexingContext)7 IOException (java.io.IOException)5 IndexCreationFailedException (org.apache.archiva.indexer.IndexCreationFailedException)3 IndexUpdateFailedException (org.apache.archiva.indexer.IndexUpdateFailedException)3 RemoteRepository (org.apache.archiva.repository.RemoteRepository)3 HashSet (java.util.HashSet)2 Inject (javax.inject.Inject)2 RepositorySearchException (org.apache.archiva.indexer.search.RepositorySearchException)2 Repository (org.apache.archiva.repository.Repository)2 Indexer (org.apache.maven.index.Indexer)2 IndexPacker (org.apache.maven.index.packer.IndexPacker)2 IndexPackingRequest (org.apache.maven.index.packer.IndexPackingRequest)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Service (org.springframework.stereotype.Service)2 Files (java.nio.file.Files)1 ArrayList (java.util.ArrayList)1