Search in sources :

Example 6 with RemoteRepository

use of org.apache.archiva.admin.model.beans.RemoteRepository in project archiva by apache.

the class DefaultRemoteRepositoriesService method checkRemoteConnectivity.

@Override
public Boolean checkRemoteConnectivity(String repositoryId) throws ArchivaRestServiceException {
    try {
        RemoteRepository remoteRepository = remoteRepositoryAdmin.getRemoteRepository(repositoryId);
        if (remoteRepository == null) {
            log.warn("ignore scheduleDownloadRemote for repo with id {} as not exists", repositoryId);
            return Boolean.FALSE;
        }
        NetworkProxy networkProxy = null;
        if (StringUtils.isNotBlank(remoteRepository.getRemoteDownloadNetworkProxyId())) {
            networkProxy = networkProxyAdmin.getNetworkProxy(remoteRepository.getRemoteDownloadNetworkProxyId());
            if (networkProxy == null) {
                log.warn("your remote repository is configured to download remote index trought a proxy we cannot find id:{}", remoteRepository.getRemoteDownloadNetworkProxyId());
            }
        }
        String wagonProtocol = new URL(remoteRepository.getUrl()).getProtocol();
        final Wagon wagon = wagonFactory.getWagon(// 
        new WagonFactoryRequest(wagonProtocol, remoteRepository.getExtraHeaders()).networkProxy(networkProxy));
        // hardcoded value as it's a check of the remote repo connectivity
        wagon.setReadTimeout(checkReadTimeout);
        wagon.setTimeout(checkTimeout);
        if (wagon instanceof AbstractHttpClientWagon) {
            HttpMethodConfiguration httpMethodConfiguration = // 
            new HttpMethodConfiguration().setUsePreemptive(// 
            true).setReadTimeout(checkReadTimeout);
            HttpConfiguration httpConfiguration = new HttpConfiguration().setGet(httpMethodConfiguration);
            AbstractHttpClientWagon.class.cast(wagon).setHttpConfiguration(httpConfiguration);
        }
        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());
        }
        String url = StringUtils.stripEnd(remoteRepository.getUrl(), "/");
        wagon.connect(new Repository(remoteRepository.getId(), url), proxyInfo);
        // MRM-1933, there are certain servers that do not allow browsing
        if (!(StringUtils.isEmpty(remoteRepository.getCheckPath()) || "/".equals(remoteRepository.getCheckPath()))) {
            return wagon.resourceExists(remoteRepository.getCheckPath());
        } else {
            // we only check connectivity as remote repo can be empty
            // MRM-1909: Wagon implementation appends a slash already
            wagon.getFileList("");
        }
        return Boolean.TRUE;
    } catch (TransferFailedException e) {
        log.info("TransferFailedException :{}", e.getMessage());
        return Boolean.FALSE;
    } catch (Exception e) {
        // This service returns either true or false, Exception cannot be handled by the clients
        log.debug("Exception occured on connectivity test.", e);
        log.info("Connection exception: {}", e.getMessage());
        return Boolean.FALSE;
    }
}
Also used : AbstractHttpClientWagon(org.apache.maven.wagon.shared.http.AbstractHttpClientWagon) HttpMethodConfiguration(org.apache.maven.wagon.shared.http.HttpMethodConfiguration) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) AbstractHttpClientWagon(org.apache.maven.wagon.shared.http.AbstractHttpClientWagon) Wagon(org.apache.maven.wagon.Wagon) HttpConfiguration(org.apache.maven.wagon.shared.http.HttpConfiguration) NetworkProxy(org.apache.archiva.admin.model.beans.NetworkProxy) URL(java.net.URL) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) TransferFailedException(org.apache.maven.wagon.TransferFailedException) ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) Repository(org.apache.maven.wagon.repository.Repository) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) WagonFactoryRequest(org.apache.archiva.proxy.common.WagonFactoryRequest) TransferFailedException(org.apache.maven.wagon.TransferFailedException)

Example 7 with RemoteRepository

use of org.apache.archiva.admin.model.beans.RemoteRepository in project archiva by apache.

the class RemoteRepositoriesServiceTest method listRemoteRepositoriesKarma.

@Test
public void listRemoteRepositoriesKarma() throws Exception {
    RemoteRepositoriesService service = getRemoteRepositoriesService();
    WebClient.client(service).header("Authorization", authorizationHeader);
    WebClient.getConfig(service).getHttpConduit().getClient().setReceiveTimeout(300000);
    List<RemoteRepository> repos = service.getRemoteRepositories();
    assertFalse(repos.isEmpty());
    log.info("repos {}", repos);
}
Also used : RemoteRepositoriesService(org.apache.archiva.rest.api.services.RemoteRepositoriesService) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) Test(org.junit.Test)

Example 8 with RemoteRepository

use of org.apache.archiva.admin.model.beans.RemoteRepository in project archiva by apache.

the class DownloadMergedIndexNonDefaultPathTest method downloadMergedIndexWithNonDefaultPath.

@Test
public void downloadMergedIndexWithNonDefaultPath() throws Exception {
    Path indexBaseDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve("archiva").resolve("remotedownloadtest");
    String indexBase = indexBaseDir.toString();
    FileUtils.deleteQuietly(indexBaseDir);
    if (!Files.exists(indexBaseDir)) {
        Files.createDirectories(indexBaseDir);
    }
    String id = Long.toString(System.currentTimeMillis());
    ManagedRepository managedRepository = new ManagedRepository(Locale.getDefault());
    managedRepository.setId(id);
    managedRepository.setName("name of " + id);
    managedRepository.setLocation(System.getProperty("basedir") + "/src/test/repositories/test-repo");
    managedRepository.setIndexDirectory(indexBase + "/index-" + id);
    managedRepository.setPackedIndexDirectory(indexBase + "/indexPacked-" + id);
    ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService();
    if (managedRepositoriesService.getManagedRepository(id) != null) {
        managedRepositoriesService.deleteManagedRepository(id, false);
    }
    getManagedRepositoriesService().addManagedRepository(managedRepository);
    RepositoriesService repositoriesService = getRepositoriesService();
    repositoriesService.scanRepositoryNow(id, true);
    // wait a bit to ensure index is finished
    int timeout = 20000;
    while (timeout > 0 && repositoriesService.alreadyScanning(id)) {
        Thread.sleep(500);
        timeout -= 500;
    }
    RepositoryGroupService repositoryGroupService = getRepositoryGroupService();
    String repoGroupId = "test-group";
    if (repositoryGroupService.getRepositoryGroup(repoGroupId) != null) {
        repositoryGroupService.deleteRepositoryGroup(repoGroupId);
    }
    RepositoryGroup repositoryGroup = new RepositoryGroup();
    repositoryGroup.setId(repoGroupId);
    String path = ".fooooo";
    repositoryGroup.setRepositories(Arrays.asList(id));
    repositoryGroup.setMergedIndexPath(path);
    repositoryGroupService.addRepositoryGroup(repositoryGroup);
    // create a repo with a remote on the one with index
    id = Long.toString(System.currentTimeMillis());
    managedRepository = new ManagedRepository(Locale.getDefault());
    managedRepository.setId(id);
    managedRepository.setName("name of " + id);
    managedRepository.setLocation(System.getProperty("basedir") + "/src/test/repositories/test-repo");
    managedRepository.setIndexDirectory(indexBaseDir + "/index-" + id);
    managedRepository.setPackedIndexDirectory(indexBase + "/tmpIndexPacked-" + id);
    if (managedRepositoriesService.getManagedRepository(id) != null) {
        managedRepositoriesService.deleteManagedRepository(id, false);
    }
    getManagedRepositoriesService().addManagedRepository(managedRepository);
    String remoteId = Long.toString(System.currentTimeMillis());
    RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault());
    remoteRepository.setId(remoteId);
    remoteRepository.setName(remoteId);
    remoteRepository.setDownloadRemoteIndex(true);
    remoteRepository.setUrl("http://localhost:" + port + "/repository/test-group");
    remoteRepository.setRemoteIndexUrl("http://localhost:" + port + "/repository/test-group/" + path);
    remoteRepository.setUserName(RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME);
    remoteRepository.setPassword(FakeCreateAdminService.ADMIN_TEST_PWD);
    getRemoteRepositoriesService().addRemoteRepository(remoteRepository);
    ProxyConnectorService proxyConnectorService = getProxyConnectorService();
    ProxyConnector proxyConnector = new ProxyConnector();
    proxyConnector.setProxyId("foo-bar2");
    proxyConnector.setSourceRepoId(id);
    proxyConnector.setTargetRepoId(remoteId);
    proxyConnectorService.addProxyConnector(proxyConnector);
    repositoriesService.scheduleDownloadRemoteIndex(remoteId, true, true);
    // wait the end
    while (!repositoriesService.getRunningRemoteDownloadIds().getStrings().isEmpty()) {
        Thread.sleep(500);
        log.debug("still running remote download");
    }
    SearchService searchService = getSearchService();
    SearchRequest request = new SearchRequest();
    request.setRepositories(Arrays.asList(id));
    request.setGroupId("org.apache.felix");
    List<Artifact> artifacts = searchService.searchArtifacts(request);
    assertThat(artifacts).isNotNull().isNotEmpty().hasSize(1);
}
Also used : Path(java.nio.file.Path) SearchRequest(org.apache.archiva.rest.api.model.SearchRequest) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ProxyConnectorService(org.apache.archiva.rest.api.services.ProxyConnectorService) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) Artifact(org.apache.archiva.maven2.model.Artifact) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) RepositoryGroup(org.apache.archiva.admin.model.beans.RepositoryGroup) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) SearchService(org.apache.archiva.rest.api.services.SearchService) RepositoryGroupService(org.apache.archiva.rest.api.services.RepositoryGroupService) ProxyConnector(org.apache.archiva.admin.model.beans.ProxyConnector) Test(org.junit.Test)

Example 9 with RemoteRepository

use of org.apache.archiva.admin.model.beans.RemoteRepository in project archiva by apache.

the class RemoteRepositoryConnectivityCheckTest method checkRemoteConnectivity.

@Test
public void checkRemoteConnectivity() throws Exception {
    Server repoServer = buildStaticServer(Paths.get(System.getProperty("basedir"), "src/test/repositories/test-repo"));
    ServerConnector serverConnector = new ServerConnector(repoServer, new HttpConnectionFactory());
    repoServer.addConnector(serverConnector);
    repoServer.start();
    RemoteRepositoriesService service = getRemoteRepositoriesService();
    WebClient.client(service).header("Authorization", authorizationHeader);
    try {
        int repoServerPort = serverConnector.getLocalPort();
        RemoteRepository repo = getRemoteRepository();
        repo.setUrl("http://localhost:" + repoServerPort);
        service.addRemoteRepository(repo);
        assertThat(service.checkRemoteConnectivity(repo.getId())).isTrue();
    } finally {
        service.deleteRemoteRepository("id-new");
        repoServer.stop();
    }
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) RemoteRepositoriesService(org.apache.archiva.rest.api.services.RemoteRepositoriesService) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) Test(org.junit.Test)

Example 10 with RemoteRepository

use of org.apache.archiva.admin.model.beans.RemoteRepository in project archiva by apache.

the class DownloadRemoteIndexTaskTest method getRemoteRepository.

protected RemoteRepository getRemoteRepository() throws IOException {
    RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault());
    Path indexDirectory = Paths.get(FileUtils.getBasedir(), "target/index/test-" + Long.toString(System.currentTimeMillis()));
    Files.createDirectories(indexDirectory);
    indexDirectory.toFile().deleteOnExit();
    remoteRepository.setName("foo");
    remoteRepository.setIndexDirectory(indexDirectory.toAbsolutePath().toString());
    remoteRepository.setDownloadRemoteIndex(true);
    remoteRepository.setId("test-repo-re");
    remoteRepository.setUrl("http://localhost:" + port);
    remoteRepository.setRemoteIndexUrl("http://localhost:" + port + "/index-updates/");
    return remoteRepository;
}
Also used : Path(java.nio.file.Path) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository)

Aggregations

RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)23 Test (org.junit.Test)16 AbstractRepositoryAdminTest (org.apache.archiva.admin.repository.AbstractRepositoryAdminTest)7 Path (java.nio.file.Path)6 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)6 RemoteRepositoriesService (org.apache.archiva.rest.api.services.RemoteRepositoriesService)5 ArrayList (java.util.ArrayList)3 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)3 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)3 NetworkProxy (org.apache.archiva.admin.model.beans.NetworkProxy)3 HashMap (java.util.HashMap)2 ProxyConnectorRule (org.apache.archiva.admin.model.beans.ProxyConnectorRule)2 RepositoryGroup (org.apache.archiva.admin.model.beans.RepositoryGroup)2 Artifact (org.apache.archiva.maven2.model.Artifact)2 SearchRequest (org.apache.archiva.rest.api.model.SearchRequest)2 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)2 ProxyConnectorService (org.apache.archiva.rest.api.services.ProxyConnectorService)2 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)2 RepositoryGroupService (org.apache.archiva.rest.api.services.RepositoryGroupService)2 SearchService (org.apache.archiva.rest.api.services.SearchService)2