Search in sources :

Example 11 with UnsupportedBaseContextException

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

the class MavenRepositorySearch method getRemoteIndexingContextIds.

@Override
public Set<String> getRemoteIndexingContextIds(String managedRepoId) throws RepositorySearchException {
    Set<String> ids = new HashSet<>();
    List<ProxyConnector> proxyConnectors = null;
    try {
        proxyConnectors = proxyConnectorAdmin.getProxyConnectorAsMap().get(managedRepoId);
    } catch (RepositoryAdminException e) {
        throw new RepositorySearchException(e.getMessage(), e);
    }
    if (proxyConnectors == null || proxyConnectors.isEmpty()) {
        return ids;
    }
    for (ProxyConnector proxyConnector : proxyConnectors) {
        String remoteId = "remote-" + proxyConnector.getTargetRepoId();
        RemoteRepository repo = repositoryRegistry.getRemoteRepository(proxyConnector.getTargetRepoId());
        if (repo.getType() == RepositoryType.MAVEN) {
            try {
                IndexingContext context = repo.getIndexingContext() != null ? repo.getIndexingContext().getBaseContext(IndexingContext.class) : null;
                if (context != null && context.isSearchable()) {
                    ids.add(remoteId);
                }
            } catch (UnsupportedBaseContextException e) {
            // Ignore this one
            }
        }
    }
    return ids;
}
Also used : UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) IndexingContext(org.apache.maven.index.context.IndexingContext) RemoteRepository(org.apache.archiva.repository.RemoteRepository) ProxyConnector(org.apache.archiva.admin.model.beans.ProxyConnector) RepositorySearchException(org.apache.archiva.indexer.search.RepositorySearchException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) HashSet(java.util.HashSet)

Example 12 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)

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