Search in sources :

Example 41 with RepositoryAdminException

use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.

the class DefaultArchivaAdministrationService method getKnownContentAdminRepositoryConsumers.

@Override
public List<AdminRepositoryConsumer> getKnownContentAdminRepositoryConsumers() throws ArchivaRestServiceException {
    try {
        AddAdminRepoConsumerClosure addAdminRepoConsumer = new AddAdminRepoConsumerClosure(archivaAdministration.getKnownContentConsumers());
        IterableUtils.forEach(repoConsumerUtil.getAvailableKnownConsumers(), addAdminRepoConsumer);
        List<AdminRepositoryConsumer> knownContentConsumers = addAdminRepoConsumer.getList();
        knownContentConsumers.sort(AdminRepositoryConsumerComparator.getInstance());
        return knownContentConsumers;
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(e.getMessage(), e);
    }
}
Also used : AddAdminRepoConsumerClosure(org.apache.archiva.rest.services.utils.AddAdminRepoConsumerClosure) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) AdminRepositoryConsumer(org.apache.archiva.rest.api.model.AdminRepositoryConsumer) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 42 with RepositoryAdminException

use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.

the class DefaultArchivaRuntimeConfigurationService method updateArchivaRuntimeConfiguration.

@Override
public Boolean updateArchivaRuntimeConfiguration(ArchivaRuntimeConfiguration archivaRuntimeConfiguration) throws ArchivaRestServiceException {
    try {
        archivaRuntimeConfigurationAdmin.updateArchivaRuntimeConfiguration(archivaRuntimeConfiguration);
        CacheConfiguration cacheConfiguration = archivaRuntimeConfiguration.getUrlFailureCacheConfiguration();
        if (cacheConfiguration != null) {
            usersCache.setTimeToLiveSeconds(cacheConfiguration.getTimeToLiveSeconds());
            usersCache.setTimeToIdleSeconds(cacheConfiguration.getTimeToIdleSeconds());
            usersCache.setMaxElementsOnDisk(cacheConfiguration.getMaxElementsOnDisk());
            usersCache.setMaxElementsInMemory(cacheConfiguration.getMaxElementsInMemory());
        }
        FileLockConfiguration fileLockConfiguration = archivaRuntimeConfiguration.getFileLockConfiguration();
        if (fileLockConfiguration != null) {
            fileLockManager.setTimeout(fileLockConfiguration.getLockingTimeout());
            fileLockManager.setSkipLocking(fileLockConfiguration.isSkipLocking());
        }
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(e.getMessage(), e);
    }
    return Boolean.TRUE;
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) CacheConfiguration(org.apache.archiva.admin.model.beans.CacheConfiguration) FileLockConfiguration(org.apache.archiva.admin.model.beans.FileLockConfiguration)

Example 43 with RepositoryAdminException

use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.

the class MavenIndexManager method update.

@Override
public void update(final ArchivaIndexingContext context, final boolean fullUpdate) throws IndexUpdateFailedException {
    log.info("start download remote index for remote repository {}", context.getRepository().getId());
    URI remoteUpdateUri;
    if (!(context.getRepository() instanceof RemoteRepository) || !(context.getRepository().supportsFeature(RemoteIndexFeature.class))) {
        throw new IndexUpdateFailedException("The context is not associated to a remote repository with remote index " + context.getId());
    } else {
        RemoteIndexFeature rif = context.getRepository().getFeature(RemoteIndexFeature.class).get();
        remoteUpdateUri = context.getRepository().getLocation().resolve(rif.getIndexUri());
    }
    final RemoteRepository remoteRepository = (RemoteRepository) context.getRepository();
    executeUpdateFunction(context, indexingContext -> {
        try {
            // create a temp directory to download files
            Path tempIndexDirectory = Paths.get(indexingContext.getIndexDirectoryFile().getParent(), ".tmpIndex");
            Path indexCacheDirectory = Paths.get(indexingContext.getIndexDirectoryFile().getParent(), ".indexCache");
            Files.createDirectories(indexCacheDirectory);
            if (Files.exists(tempIndexDirectory)) {
                org.apache.archiva.common.utils.FileUtils.deleteDirectory(tempIndexDirectory);
            }
            Files.createDirectories(tempIndexDirectory);
            tempIndexDirectory.toFile().deleteOnExit();
            String baseIndexUrl = indexingContext.getIndexUpdateUrl();
            String wagonProtocol = remoteUpdateUri.toURL().getProtocol();
            NetworkProxy networkProxy = null;
            if (remoteRepository.supportsFeature(RemoteIndexFeature.class)) {
                RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class).get();
                if (StringUtils.isNotBlank(rif.getProxyId())) {
                    try {
                        networkProxy = networkProxyAdmin.getNetworkProxy(rif.getProxyId());
                    } catch (RepositoryAdminException e) {
                        log.error("Error occured while retrieving proxy {}", e.getMessage());
                    }
                    if (networkProxy == null) {
                        log.warn("your remote repository is configured to download remote index trought a proxy we cannot find id:{}", rif.getProxyId());
                    }
                }
                final StreamWagon wagon = (StreamWagon) wagonFactory.getWagon(new WagonFactoryRequest(wagonProtocol, remoteRepository.getExtraHeaders()).networkProxy(networkProxy));
                int readTimeout = (int) rif.getDownloadTimeout().toMillis() * 1000;
                wagon.setReadTimeout(readTimeout);
                wagon.setTimeout((int) remoteRepository.getTimeout().toMillis() * 1000);
                if (wagon instanceof AbstractHttpClientWagon) {
                    HttpConfiguration httpConfiguration = new HttpConfiguration();
                    HttpMethodConfiguration httpMethodConfiguration = new HttpMethodConfiguration();
                    httpMethodConfiguration.setUsePreemptive(true);
                    httpMethodConfiguration.setReadTimeout(readTimeout);
                    httpConfiguration.setGet(httpMethodConfiguration);
                    AbstractHttpClientWagon.class.cast(wagon).setHttpConfiguration(httpConfiguration);
                }
                wagon.addTransferListener(new DownloadListener());
                ProxyInfo proxyInfo = null;
                if (networkProxy != null) {
                    proxyInfo = new ProxyInfo();
                    proxyInfo.setType(networkProxy.getProtocol());
                    proxyInfo.setHost(networkProxy.getHost());
                    proxyInfo.setPort(networkProxy.getPort());
                    proxyInfo.setUserName(networkProxy.getUsername());
                    proxyInfo.setPassword(networkProxy.getPassword());
                }
                AuthenticationInfo authenticationInfo = null;
                if (remoteRepository.getLoginCredentials() != null && (remoteRepository.getLoginCredentials() instanceof PasswordCredentials)) {
                    PasswordCredentials creds = (PasswordCredentials) remoteRepository.getLoginCredentials();
                    authenticationInfo = new AuthenticationInfo();
                    authenticationInfo.setUserName(creds.getUsername());
                    authenticationInfo.setPassword(new String(creds.getPassword()));
                }
                wagon.connect(new org.apache.maven.wagon.repository.Repository(remoteRepository.getId(), baseIndexUrl), authenticationInfo, proxyInfo);
                Path indexDirectory = indexingContext.getIndexDirectoryFile().toPath();
                if (!Files.exists(indexDirectory)) {
                    Files.createDirectories(indexDirectory);
                }
                ResourceFetcher resourceFetcher = new WagonResourceFetcher(log, tempIndexDirectory, wagon, remoteRepository);
                IndexUpdateRequest request = new IndexUpdateRequest(indexingContext, resourceFetcher);
                request.setForceFullUpdate(fullUpdate);
                request.setLocalIndexCacheDir(indexCacheDirectory.toFile());
                indexUpdater.fetchAndUpdateIndex(request);
                indexingContext.updateTimestamp(true);
            }
        } catch (AuthenticationException e) {
            log.error("Could not login to the remote proxy for updating index of {}", remoteRepository.getId(), e);
            throw new IndexUpdateFailedException("Login in to proxy failed while updating remote repository " + remoteRepository.getId(), e);
        } catch (ConnectionException e) {
            log.error("Connection error during index update for remote repository {}", remoteRepository.getId(), e);
            throw new IndexUpdateFailedException("Connection error during index update for remote repository " + remoteRepository.getId(), e);
        } catch (MalformedURLException e) {
            log.error("URL for remote index update of remote repository {} is not correct {}", remoteRepository.getId(), remoteUpdateUri, e);
            throw new IndexUpdateFailedException("URL for remote index update of repository is not correct " + remoteUpdateUri, e);
        } catch (IOException e) {
            log.error("IOException during index update of remote repository {}: {}", remoteRepository.getId(), e.getMessage(), e);
            throw new IndexUpdateFailedException("IOException during index update of remote repository " + remoteRepository.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""), e);
        } catch (WagonFactoryException e) {
            log.error("Wagon for remote index download of {} could not be created: {}", remoteRepository.getId(), e.getMessage(), e);
            throw new IndexUpdateFailedException("Error while updating the remote index of " + remoteRepository.getId(), e);
        }
    });
}
Also used : AbstractHttpClientWagon(org.apache.maven.wagon.shared.http.AbstractHttpClientWagon) MalformedURLException(java.net.MalformedURLException) HttpMethodConfiguration(org.apache.maven.wagon.shared.http.HttpMethodConfiguration) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) ResourceFetcher(org.apache.maven.index.updater.ResourceFetcher) RemoteRepository(org.apache.archiva.repository.RemoteRepository) HttpConfiguration(org.apache.maven.wagon.shared.http.HttpConfiguration) URI(java.net.URI) StreamWagon(org.apache.maven.wagon.StreamWagon) NetworkProxy(org.apache.archiva.admin.model.beans.NetworkProxy) AuthenticationInfo(org.apache.maven.wagon.authentication.AuthenticationInfo) ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) WagonFactoryRequest(org.apache.archiva.proxy.common.WagonFactoryRequest) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException) Path(java.nio.file.Path) PasswordCredentials(org.apache.archiva.repository.PasswordCredentials) IndexUpdateRequest(org.apache.maven.index.updater.IndexUpdateRequest) IOException(java.io.IOException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) WagonFactoryException(org.apache.archiva.proxy.common.WagonFactoryException) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) ConnectionException(org.apache.maven.wagon.ConnectionException)

Example 44 with RepositoryAdminException

use of org.apache.archiva.admin.model.RepositoryAdminException 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 45 with RepositoryAdminException

use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.

the class MavenRepositorySearch method search.

private SearchResults search(SearchResultLimits limits, BooleanQuery q, List<String> indexingContextIds, List<? extends ArtifactInfoFilter> filters, List<String> selectedRepos, boolean includePoms) throws RepositorySearchException {
    try {
        FlatSearchRequest request = new FlatSearchRequest(q);
        request.setContexts(getIndexingContexts(indexingContextIds));
        if (limits != null) {
            // we apply limits only when first page asked
            if (limits.getSelectedPage() == 0) {
                request.setCount(limits.getPageSize() * (Math.max(1, limits.getSelectedPage())));
            }
        }
        FlatSearchResponse response = indexer.searchFlat(request);
        if (response == null || response.getTotalHitsCount() == 0) {
            SearchResults results = new SearchResults();
            results.setLimits(limits);
            return results;
        }
        return convertToSearchResults(response, limits, filters, selectedRepos, includePoms);
    } catch (IOException e) {
        throw new RepositorySearchException(e.getMessage(), e);
    } catch (RepositoryAdminException e) {
        throw new RepositorySearchException(e.getMessage(), e);
    }
}
Also used : FlatSearchResponse(org.apache.maven.index.FlatSearchResponse) FlatSearchRequest(org.apache.maven.index.FlatSearchRequest) IOException(java.io.IOException) RepositorySearchException(org.apache.archiva.indexer.search.RepositorySearchException) SearchResults(org.apache.archiva.indexer.search.SearchResults) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Aggregations

RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)67 Configuration (org.apache.archiva.configuration.Configuration)18 Path (java.nio.file.Path)15 RedbackRuntimeConfiguration (org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration)14 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)14 RepositoryException (org.apache.archiva.repository.RepositoryException)13 IOException (java.io.IOException)12 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)10 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)10 ArrayList (java.util.ArrayList)9 RepositoryGroupConfiguration (org.apache.archiva.configuration.RepositoryGroupConfiguration)7 NetworkProxy (org.apache.archiva.admin.model.beans.NetworkProxy)6 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)6 IndexUpdateFailedException (org.apache.archiva.indexer.IndexUpdateFailedException)6 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)6 RemoteRepository (org.apache.archiva.repository.RemoteRepository)6 Date (java.util.Date)5 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)5 PostConstruct (javax.annotation.PostConstruct)4 LdapGroupMapping (org.apache.archiva.admin.model.beans.LdapGroupMapping)4