Search in sources :

Example 6 with RepositoryGroup

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

the class DefaultRepositoryGroupAdmin method getRepositoryGroupsAsMap.

@Override
public Map<String, RepositoryGroup> getRepositoryGroupsAsMap() throws RepositoryAdminException {
    List<RepositoryGroup> repositoriesGroups = getRepositoriesGroups();
    Map<String, RepositoryGroup> map = new HashMap<>(repositoriesGroups.size());
    for (RepositoryGroup repositoryGroup : repositoriesGroups) {
        map.put(repositoryGroup.getId(), repositoryGroup);
    }
    return map;
}
Also used : RepositoryGroup(org.apache.archiva.admin.model.beans.RepositoryGroup) HashMap(java.util.HashMap)

Example 7 with RepositoryGroup

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

the class RepositoryGroupServiceTest method addAndDelete.

@Test
public void addAndDelete() throws Exception {
    RepositoryGroupService service = getRepositoryGroupService();
    WebClient.client(service).header("Authorization", authorizationHeader);
    WebClient.client(service).header("Referer", "http://localhost:" + port);
    WebClient.getConfig(service).getHttpConduit().getClient().setReceiveTimeout(300000);
    assertTrue(service.getRepositoriesGroups().isEmpty());
    ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService(authorizationHeader);
    WebClient.getConfig(service).getHttpConduit().getClient().setReceiveTimeout(300000);
    ManagedRepository managedRepository = getTestManagedRepository();
    managedRepositoriesService.addManagedRepository(managedRepository);
    RepositoryGroup repositoryGroup = new RepositoryGroup("one", Arrays.asList(managedRepository.getId())).mergedIndexTtl(40);
    service.addRepositoryGroup(repositoryGroup);
    assertFalse(service.getRepositoriesGroups().isEmpty());
    assertEquals(1, service.getRepositoriesGroups().size());
    assertEquals(40, service.getRepositoriesGroups().get(0).getMergedIndexTtl());
    service.deleteRepositoryGroup("one");
    assertTrue(service.getRepositoriesGroups().isEmpty());
    assertEquals(0, service.getRepositoriesGroups().size());
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) RepositoryGroup(org.apache.archiva.admin.model.beans.RepositoryGroup) RepositoryGroupService(org.apache.archiva.rest.api.services.RepositoryGroupService) Test(org.junit.Test)

Example 8 with RepositoryGroup

use of org.apache.archiva.admin.model.beans.RepositoryGroup 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 RepositoryGroup

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

the class ArchivaDavResourceFactoryTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    requestControl = createControl();
    request = requestControl.createMock(DavServletRequest.class);
    responseControl = createControl();
    response = responseControl.createMock(DavServletResponse.class);
    // responseControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
    archivaConfigurationControl = createControl();
    archivaConfiguration = archivaConfigurationControl.createMock(ArchivaConfiguration.class);
    config = new Configuration();
    expect(archivaConfiguration.getConfiguration()).andReturn(config).times(2, 20);
    expect(archivaConfiguration.getDefaultLocale()).andReturn(Locale.getDefault()).anyTimes();
    archivaConfiguration.addListener(EasyMock.anyObject());
    expectLastCall().times(0, 4);
    archivaConfiguration.save(config);
    expectLastCall().times(0, 4);
    archivaConfigurationControl.replay();
    defaultManagedRepositoryAdmin.setArchivaConfiguration(archivaConfiguration);
    repositoryRegistry.setArchivaConfiguration(archivaConfiguration);
    repositoryRegistry.reload();
    ((DefaultRepositoryCommonValidator) defaultManagedRepositoryAdmin.getRepositoryCommonValidator()).setArchivaConfiguration(archivaConfiguration);
    if (defaultManagedRepositoryAdmin.getManagedRepository(RELEASES_REPO) == null) {
        defaultManagedRepositoryAdmin.addManagedRepository(createManagedRepository(RELEASES_REPO, Paths.get("target/test-classes/" + RELEASES_REPO).toString(), "default"), false, null);
    }
    if (defaultManagedRepositoryAdmin.getManagedRepository(INTERNAL_REPO) == null) {
        defaultManagedRepositoryAdmin.addManagedRepository(createManagedRepository(INTERNAL_REPO, Paths.get("target/test-classes/" + INTERNAL_REPO).toString(), "default"), false, null);
    }
    RepositoryGroup repoGroupConfig = new RepositoryGroup();
    repoGroupConfig.setId(LOCAL_REPO_GROUP);
    repoGroupConfig.addRepository(RELEASES_REPO);
    repoGroupConfig.addRepository(INTERNAL_REPO);
    defaultRepositoryGroupAdmin.setArchivaConfiguration(archivaConfiguration);
    if (defaultManagedRepositoryAdmin.getManagedRepository(LOCAL_REPO_GROUP) == null) {
        defaultRepositoryGroupAdmin.addRepositoryGroup(repoGroupConfig, null);
    }
    repoContentFactoryControl = createControl();
    repoFactory = repoContentFactoryControl.createMock(RepositoryContentFactory.class);
    repoRequestControl = createControl();
    repoRequest = repoRequestControl.createMock(RepositoryRequest.class);
    resourceFactory = new OverridingArchivaDavResourceFactory(applicationContext, plexusSisuBridge, archivaConfiguration);
    resourceFactory.setArchivaConfiguration(archivaConfiguration);
    resourceFactory.setRepositoryFactory(repoFactory);
    resourceFactory.setRepositoryRequest(repoRequest);
    resourceFactory.setConnectors(new OverridingRepositoryProxyConnectors());
    resourceFactory.setRemoteRepositoryAdmin(remoteRepositoryAdmin);
    resourceFactory.setManagedRepositoryAdmin(defaultManagedRepositoryAdmin);
    resourceFactory.setRepositoryRegistry(repositoryRegistry);
}
Also used : DavServletRequest(org.apache.jackrabbit.webdav.DavServletRequest) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) RepositoryGroup(org.apache.archiva.admin.model.beans.RepositoryGroup) RepositoryRequest(org.apache.archiva.repository.content.maven2.RepositoryRequest) DavServletResponse(org.apache.jackrabbit.webdav.DavServletResponse) DefaultRepositoryCommonValidator(org.apache.archiva.admin.repository.DefaultRepositoryCommonValidator) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) RepositoryContentFactory(org.apache.archiva.repository.RepositoryContentFactory) Before(org.junit.Before)

Example 10 with RepositoryGroup

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

the class DownloadMergedIndexTest method downloadMergedIndex.

@Test
public void downloadMergedIndex() throws Exception {
    Path tmpIndexDir = Paths.get(System.getProperty("java.io.tmpdir"), "tmpIndex");
    if (Files.exists(tmpIndexDir)) {
        FileUtils.deleteDirectory(tmpIndexDir.toFile());
    }
    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(System.getProperty("java.io.tmpdir") + "/tmpIndex/" + 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);
    repositoryGroup.setRepositories(Arrays.asList(id));
    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(System.getProperty("java.io.tmpdir") + "/tmpIndex/" + id);
    if (managedRepositoriesService.getManagedRepository(id) != null) {
        managedRepositoriesService.deleteManagedRepository(id, false);
    }
    getManagedRepositoriesService().addManagedRepository(managedRepository);
    RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault());
    remoteRepository.setId("all-merged");
    remoteRepository.setName("all-merged");
    remoteRepository.setDownloadRemoteIndex(true);
    remoteRepository.setUrl("http://localhost:" + port + "/repository/test-group");
    remoteRepository.setRemoteIndexUrl("http://localhost:" + port + "/repository/test-group/.index");
    remoteRepository.setUserName(RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME);
    remoteRepository.setPassword(FakeCreateAdminService.ADMIN_TEST_PWD);
    if (getRemoteRepositoriesService().getRemoteRepository(remoteRepository.getId()) != null) {
        getRemoteRepositoriesService().deleteRemoteRepository(remoteRepository.getId());
    }
    getRemoteRepositoriesService().addRemoteRepository(remoteRepository);
    ProxyConnectorService proxyConnectorService = getProxyConnectorService();
    ProxyConnector proxyConnector = new ProxyConnector();
    proxyConnector.setProxyId("foo-bar1");
    proxyConnector.setSourceRepoId(id);
    proxyConnector.setTargetRepoId("all-merged");
    proxyConnectorService.addProxyConnector(proxyConnector);
    repositoriesService.scheduleDownloadRemoteIndex("all-merged", true, true);
    // wait a bit
    timeout = 20000;
    while (timeout > 0) {
        Thread.sleep(500);
        timeout -= 500;
    }
    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)

Aggregations

RepositoryGroup (org.apache.archiva.admin.model.beans.RepositoryGroup)16 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)9 Test (org.junit.Test)8 AbstractRepositoryAdminTest (org.apache.archiva.admin.repository.AbstractRepositoryAdminTest)5 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)4 Path (java.nio.file.Path)3 HashMap (java.util.HashMap)3 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)3 RepositoryGroupService (org.apache.archiva.rest.api.services.RepositoryGroupService)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)2 RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)2 Configuration (org.apache.archiva.configuration.Configuration)2 RepositoryGroupConfiguration (org.apache.archiva.configuration.RepositoryGroupConfiguration)2 Artifact (org.apache.archiva.maven2.model.Artifact)2 SearchRequest (org.apache.archiva.rest.api.model.SearchRequest)2 ProxyConnectorService (org.apache.archiva.rest.api.services.ProxyConnectorService)2 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)2 SearchService (org.apache.archiva.rest.api.services.SearchService)2