Search in sources :

Example 6 with RepositorySearchException

use of org.apache.archiva.indexer.search.RepositorySearchException in project archiva by apache.

the class DefaultSearchService method getAllGroupIds.

@Override
public GroupIdList getAllGroupIds(List<String> selectedRepos) throws ArchivaRestServiceException {
    List<String> observableRepos = getObservableRepos();
    List<String> repos = ListUtils.intersection(observableRepos, selectedRepos);
    if (repos == null || repos.isEmpty()) {
        return new GroupIdList(Collections.<String>emptyList());
    }
    try {
        return new GroupIdList(new ArrayList<>(repositorySearch.getAllGroupIds(getPrincipal(), repos)));
    } catch (RepositorySearchException e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), e);
    }
}
Also used : GroupIdList(org.apache.archiva.rest.api.model.GroupIdList) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) RepositorySearchException(org.apache.archiva.indexer.search.RepositorySearchException)

Example 7 with RepositorySearchException

use of org.apache.archiva.indexer.search.RepositorySearchException in project archiva by apache.

the class ArchivaDavResourceFactory method buildMergedIndexDirectory.

protected Path buildMergedIndexDirectory(List<String> repositories, String activePrincipal, DavServletRequest request, RepositoryGroupConfiguration repositoryGroupConfiguration) throws DavException {
    try {
        HttpSession session = request.getSession();
        @SuppressWarnings("unchecked") Map<String, TemporaryGroupIndex> temporaryGroupIndexMap = (Map<String, TemporaryGroupIndex>) session.getAttribute(TemporaryGroupIndexSessionCleaner.TEMPORARY_INDEX_SESSION_KEY);
        if (temporaryGroupIndexMap == null) {
            temporaryGroupIndexMap = new HashMap<>();
        }
        TemporaryGroupIndex tmp = temporaryGroupIndexMap.get(repositoryGroupConfiguration.getId());
        if (tmp != null && tmp.getDirectory() != null && Files.exists(tmp.getDirectory())) {
            if (System.currentTimeMillis() - tmp.getCreationTime() > (repositoryGroupConfiguration.getMergedIndexTtl() * 60 * 1000)) {
                log.debug(MarkerFactory.getMarker("group.merged.index"), "tmp group index '{}' is too old so delete it", repositoryGroupConfiguration.getId());
                indexMerger.cleanTemporaryGroupIndex(tmp);
            } else {
                log.debug(MarkerFactory.getMarker("group.merged.index"), "merged index for group '{}' found in cache", repositoryGroupConfiguration.getId());
                return tmp.getDirectory();
            }
        }
        Set<String> authzRepos = new HashSet<String>();
        String permission = WebdavMethodUtil.getMethodPermission(request.getMethod());
        for (String repository : repositories) {
            try {
                if (servletAuth.isAuthorized(activePrincipal, repository, permission)) {
                    authzRepos.add(repository);
                    authzRepos.addAll(this.repositorySearch.getRemoteIndexingContextIds(repository));
                }
            } catch (UnauthorizedException e) {
                // TODO: review exception handling
                log.debug("Skipping repository '{}' for user '{}': {}", repository, activePrincipal, e.getMessage());
            }
        }
        log.info("generate temporary merged index for repository group '{}' for repositories '{}'", repositoryGroupConfiguration.getId(), authzRepos);
        Path tempRepoFile = Files.createTempDirectory("temp");
        tempRepoFile.toFile().deleteOnExit();
        IndexMergerRequest indexMergerRequest = new IndexMergerRequest(authzRepos, true, repositoryGroupConfiguration.getId(), repositoryGroupConfiguration.getMergedIndexPath(), repositoryGroupConfiguration.getMergedIndexTtl()).mergedIndexDirectory(tempRepoFile).temporary(true);
        MergedRemoteIndexesTaskRequest taskRequest = new MergedRemoteIndexesTaskRequest(indexMergerRequest, indexMerger);
        MergedRemoteIndexesTask job = new MergedRemoteIndexesTask(taskRequest);
        IndexingContext indexingContext = job.execute().getIndexingContext();
        Path mergedRepoDir = indexingContext.getIndexDirectoryFile().toPath();
        TemporaryGroupIndex temporaryGroupIndex = new TemporaryGroupIndex(mergedRepoDir, indexingContext.getId(), repositoryGroupConfiguration.getId(), // 
        repositoryGroupConfiguration.getMergedIndexTtl()).setCreationTime(new Date().getTime());
        temporaryGroupIndexMap.put(repositoryGroupConfiguration.getId(), temporaryGroupIndex);
        session.setAttribute(TemporaryGroupIndexSessionCleaner.TEMPORARY_INDEX_SESSION_KEY, temporaryGroupIndexMap);
        return mergedRepoDir;
    } catch (RepositorySearchException e) {
        throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
    } catch (IndexMergerException e) {
        throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
    } catch (IOException e) {
        throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
    }
}
Also used : Path(java.nio.file.Path) TemporaryGroupIndex(org.apache.archiva.indexer.merger.TemporaryGroupIndex) MergedRemoteIndexesTaskRequest(org.apache.archiva.indexer.merger.MergedRemoteIndexesTaskRequest) MergedRemoteIndexesTask(org.apache.archiva.indexer.merger.MergedRemoteIndexesTask) DavException(org.apache.jackrabbit.webdav.DavException) HttpSession(javax.servlet.http.HttpSession) IndexMergerRequest(org.apache.archiva.indexer.merger.IndexMergerRequest) RepositorySearchException(org.apache.archiva.indexer.search.RepositorySearchException) IOException(java.io.IOException) Date(java.util.Date) UnauthorizedException(org.apache.archiva.redback.authorization.UnauthorizedException) IndexingContext(org.apache.maven.index.context.IndexingContext) IndexMergerException(org.apache.archiva.indexer.merger.IndexMergerException) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 8 with RepositorySearchException

use of org.apache.archiva.indexer.search.RepositorySearchException in project archiva by apache.

the class DefaultSearchService method quickSearchWithRepositories.

@Override
public List<Artifact> quickSearchWithRepositories(SearchRequest searchRequest) throws ArchivaRestServiceException {
    String queryString = searchRequest.getQueryTerms();
    if (StringUtils.isBlank(queryString)) {
        return Collections.emptyList();
    }
    List<String> repositories = searchRequest.getRepositories();
    if (repositories == null || repositories.isEmpty()) {
        repositories = getObservableRepos();
    }
    SearchResultLimits limits = new SearchResultLimits(searchRequest.getPageSize(), searchRequest.getSelectedPage());
    try {
        SearchResults searchResults = repositorySearch.search(getPrincipal(), repositories, queryString, limits, Collections.<String>emptyList());
        return getArtifacts(searchResults);
    } catch (RepositorySearchException e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), e);
    }
}
Also used : SearchResultLimits(org.apache.archiva.indexer.search.SearchResultLimits) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) RepositorySearchException(org.apache.archiva.indexer.search.RepositorySearchException) SearchResults(org.apache.archiva.indexer.search.SearchResults)

Example 9 with RepositorySearchException

use of org.apache.archiva.indexer.search.RepositorySearchException in project archiva by apache.

the class DefaultSearchService method getArtifactVersions.

@Override
public List<Artifact> getArtifactVersions(String groupId, String artifactId, String packaging) throws ArchivaRestServiceException {
    if (StringUtils.isBlank(groupId) || StringUtils.isBlank(artifactId)) {
        return Collections.emptyList();
    }
    SearchFields searchField = new SearchFields();
    searchField.setGroupId(groupId);
    searchField.setArtifactId(artifactId);
    searchField.setPackaging(StringUtils.isBlank(packaging) ? "jar" : packaging);
    searchField.setRepositories(getObservableRepos());
    try {
        SearchResults searchResults = repositorySearch.search(getPrincipal(), searchField, null);
        return getArtifacts(searchResults);
    } catch (RepositorySearchException e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), e);
    }
}
Also used : SearchFields(org.apache.archiva.indexer.search.SearchFields) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) RepositorySearchException(org.apache.archiva.indexer.search.RepositorySearchException) SearchResults(org.apache.archiva.indexer.search.SearchResults)

Example 10 with RepositorySearchException

use of org.apache.archiva.indexer.search.RepositorySearchException in project archiva by apache.

the class MavenRepositorySearch method addIndexingContexts.

/**
 * @param selectedRepos
 * @return indexing contextId used
 */
private List<String> addIndexingContexts(List<String> selectedRepos) {
    Set<String> indexingContextIds = new HashSet<>();
    for (String repo : selectedRepos) {
        try {
            Repository rRepo = repositoryRegistry.getRepository(repo);
            if (rRepo != null) {
                if (rRepo.getType().equals(RepositoryType.MAVEN)) {
                    assert rRepo.getIndexingContext() != null;
                    IndexingContext context = rRepo.getIndexingContext().getBaseContext(IndexingContext.class);
                    if (context.isSearchable()) {
                        indexingContextIds.addAll(getRemoteIndexingContextIds(repo));
                        indexingContextIds.add(context.getId());
                    } else {
                        log.warn("indexingContext with id {} not searchable", rRepo.getId());
                    }
                }
            } else {
                log.warn("Repository '{}' not found in configuration.", repo);
            }
        } catch (RepositorySearchException e) {
            log.warn("RepositorySearchException occured while accessing index of repository '{}' : {}", repo, e.getMessage());
            continue;
        } catch (UnsupportedBaseContextException e) {
            log.error("Fatal situation: Maven repository without IndexingContext found.");
            continue;
        }
    }
    return new ArrayList<>(indexingContextIds);
}
Also used : UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) Repository(org.apache.archiva.repository.Repository) RemoteRepository(org.apache.archiva.repository.RemoteRepository) ArrayList(java.util.ArrayList) IndexingContext(org.apache.maven.index.context.IndexingContext) RepositorySearchException(org.apache.archiva.indexer.search.RepositorySearchException) HashSet(java.util.HashSet)

Aggregations

RepositorySearchException (org.apache.archiva.indexer.search.RepositorySearchException)12 SearchFields (org.apache.archiva.indexer.search.SearchFields)5 SearchResults (org.apache.archiva.indexer.search.SearchResults)5 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 IndexingContext (org.apache.maven.index.context.IndexingContext)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)2 UnsupportedBaseContextException (org.apache.archiva.indexer.UnsupportedBaseContextException)2 SearchResultLimits (org.apache.archiva.indexer.search.SearchResultLimits)2 RemoteRepository (org.apache.archiva.repository.RemoteRepository)2 Path (java.nio.file.Path)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 HttpSession (javax.servlet.http.HttpSession)1 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)1 IndexMergerException (org.apache.archiva.indexer.merger.IndexMergerException)1