Search in sources :

Example 16 with RepositoryGroup

use of org.apache.archiva.repository.RepositoryGroup in project archiva by apache.

the class DefaultMergedRemoteIndexesScheduler method schedule.

@Override
public void schedule(RepositoryGroup repositoryGroup, StorageAsset directory) {
    if (StringUtils.isEmpty(repositoryGroup.getSchedulingDefinition())) {
        return;
    }
    CronTrigger cronTrigger = new CronTrigger(repositoryGroup.getSchedulingDefinition());
    List<ManagedRepository> repositories = repositoryGroup.getRepositories();
    if (repositoryGroup.supportsFeature(IndexCreationFeature.class)) {
        IndexCreationFeature indexCreationFeature = repositoryGroup.getFeature(IndexCreationFeature.class);
        Path indexPath = indexCreationFeature.getLocalIndexPath().getFilePath();
        if (indexPath != null) {
            IndexMergerRequest indexMergerRequest = new IndexMergerRequest(repositories.stream().map(r -> r.getId()).collect(Collectors.toList()), true, repositoryGroup.getId(), indexPath.toString(), repositoryGroup.getMergedIndexTTL()).mergedIndexDirectory(directory);
            MergedRemoteIndexesTaskRequest taskRequest = new MergedRemoteIndexesTaskRequest(indexMergerRequest, indexMerger);
            logger.info("schedule merge remote index for group {} with cron {}", repositoryGroup.getId(), repositoryGroup.getSchedulingDefinition());
            ScheduledFuture scheduledFuture = taskScheduler.schedule(new MergedRemoteIndexesTask(taskRequest), cronTrigger);
            scheduledFutureMap.put(repositoryGroup.getId(), scheduledFuture);
        } else {
            logger.error("Requested index merger for repository group {} with non local index path {}", repositoryGroup.getId(), indexCreationFeature.getLocalIndexPath());
        }
    } else {
        logger.error("Scheduling merged index for repository group {}, but it does not support IndexCreationFeature.", repositoryGroup.getId());
    }
}
Also used : Path(java.nio.file.Path) Logger(org.slf4j.Logger) ScheduledFuture(java.util.concurrent.ScheduledFuture) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) LoggerFactory(org.slf4j.LoggerFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MergedRemoteIndexesScheduler(org.apache.archiva.indexer.merger.MergedRemoteIndexesScheduler) TaskScheduler(org.springframework.scheduling.TaskScheduler) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) IndexMerger(org.apache.archiva.indexer.merger.IndexMerger) ManagedRepository(org.apache.archiva.repository.ManagedRepository) CronTrigger(org.springframework.scheduling.support.CronTrigger) Inject(javax.inject.Inject) List(java.util.List) IndexMergerRequest(org.apache.archiva.indexer.merger.IndexMergerRequest) Service(org.springframework.stereotype.Service) Map(java.util.Map) Named(javax.inject.Named) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) Path(java.nio.file.Path) CronTrigger(org.springframework.scheduling.support.CronTrigger) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) ManagedRepository(org.apache.archiva.repository.ManagedRepository) IndexMergerRequest(org.apache.archiva.indexer.merger.IndexMergerRequest) ScheduledFuture(java.util.concurrent.ScheduledFuture)

Example 17 with RepositoryGroup

use of org.apache.archiva.repository.RepositoryGroup in project archiva by apache.

the class RepositoryGroupHandlerTest method testPutWithoutRegister.

@Test
void testPutWithoutRegister() throws RepositoryException {
    RepositoryGroupHandler groupHandler = createHandler();
    Configuration aCfg = new Configuration();
    RepositoryGroupConfiguration configuration = new RepositoryGroupConfiguration();
    final String id = "test-group-06";
    configuration.setId(id);
    configuration.setName("n-" + id);
    ArrayList<String> repos = new ArrayList<>();
    repos.add("internal");
    configuration.setRepositories(repos);
    groupHandler.put(configuration, aCfg);
    RepositoryGroup repo = groupHandler.get(id);
    assertNull(repo);
    assertFalse(hasGroupInConfig(id));
    assertTrue(aCfg.getRepositoryGroups().stream().anyMatch(g -> g != null && id.equals(g.getId())));
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ArgumentMatchers(org.mockito.ArgumentMatchers) CheckedResult(org.apache.archiva.repository.validation.CheckedResult) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) ArchivaRepositoryRegistry(org.apache.archiva.repository.base.ArchivaRepositoryRegistry) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) RemoteRepository(org.apache.archiva.repository.RemoteRepository) RepositoryHandler(org.apache.archiva.repository.RepositoryHandler) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ISEMPTY(org.apache.archiva.repository.validation.ErrorKeys.ISEMPTY) Map(java.util.Map) FileUtils(org.apache.archiva.common.utils.FileUtils) Named(javax.inject.Named) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) ConfigurationHandler(org.apache.archiva.repository.base.ConfigurationHandler) ValidationError(org.apache.archiva.repository.validation.ValidationError) Path(java.nio.file.Path) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Iterator(java.util.Iterator) SpringExtension(org.springframework.test.context.junit.jupiter.SpringExtension) Files(java.nio.file.Files) FileLockManager(org.apache.archiva.common.filelock.FileLockManager) RepositoryException(org.apache.archiva.repository.RepositoryException) MergedRemoteIndexesScheduler(org.apache.archiva.indexer.merger.MergedRemoteIndexesScheduler) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) IOException(java.io.IOException) RepositoryType(org.apache.archiva.repository.RepositoryType) ManagedRepository(org.apache.archiva.repository.ManagedRepository) Mockito.verify(org.mockito.Mockito.verify) BasicRemoteRepository(org.apache.archiva.repository.base.remote.BasicRemoteRepository) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) Paths(java.nio.file.Paths) ContextConfiguration(org.springframework.test.context.ContextConfiguration) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) Assertions(org.junit.jupiter.api.Assertions) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) RepositoryState(org.apache.archiva.repository.RepositoryState) BasicManagedRepository(org.apache.archiva.repository.base.managed.BasicManagedRepository) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 18 with RepositoryGroup

use of org.apache.archiva.repository.RepositoryGroup in project archiva by apache.

the class RepositoryGroupHandlerTest method validateRepositoryForUpdate.

@Test
void validateRepositoryForUpdate() throws IOException, RepositoryException {
    final String id = "test-group-12";
    try {
        RepositoryGroupHandler groupHandler = createHandler();
        EditableRepositoryGroup repositoryGroup = createRepository(id, "n-" + id);
        repositoryGroup.setMergedIndexTTL(5);
        groupHandler.put(repositoryGroup);
        CheckedResult<RepositoryGroup, Map<String, List<ValidationError>>> result = groupHandler.validateRepositoryForUpdate(repositoryGroup);
        assertNotNull(result);
        assertEquals(0, result.getResult().size());
    } finally {
        removeGroupFromConfig(id);
    }
}
Also used : EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) ValidationError(org.apache.archiva.repository.validation.ValidationError) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 19 with RepositoryGroup

use of org.apache.archiva.repository.RepositoryGroup in project archiva by apache.

the class RepositoryGroupHandlerTest method putWithCheck_invalid.

@Test
void putWithCheck_invalid() throws RepositoryException {
    final String id = "test-group-07";
    final String name = "n-" + id;
    try {
        RepositoryGroupHandler groupHandler = createHandler();
        BasicRepositoryGroupValidator checker = new BasicRepositoryGroupValidator(configurationHandler);
        RepositoryGroupConfiguration configuration = new RepositoryGroupConfiguration();
        configuration.setId("");
        configuration.setName(name);
        ArrayList<String> repos = new ArrayList<>();
        repos.add("internal");
        configuration.setRepositories(repos);
        CheckedResult<RepositoryGroup, Map<String, List<ValidationError>>> result = groupHandler.putWithCheck(configuration, checker);
        assertNull(groupHandler.get(id));
        assertNotNull(result.getResult());
        assertNotNull(result.getResult().get("id"));
        assertEquals(1, result.getResult().get("id").size());
        assertEquals(ISEMPTY, result.getResult().get("id").get(0).getType());
        assertFalse(hasGroupInConfig(id));
        assertFalse(hasGroupInConfig(""));
    } finally {
        removeGroupFromConfig(id);
    }
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) ArrayList(java.util.ArrayList) ValidationError(org.apache.archiva.repository.validation.ValidationError) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 20 with RepositoryGroup

use of org.apache.archiva.repository.RepositoryGroup in project archiva by apache.

the class RepositoryGroupHandlerTest method newInstance.

@Test
void newInstance() throws RepositoryException {
    String id = "test-group-03";
    RepositoryGroupHandler groupHandler = createHandler();
    RepositoryGroup instance = groupHandler.newInstance(RepositoryType.MAVEN, id);
    assertNotNull(instance);
    assertEquals(id, instance.getId());
    assertFalse(groupHandler.hasRepository(id));
    assertEquals(RepositoryState.REFERENCES_SET, instance.getLastState());
    assertFalse(hasGroupInConfig(id));
}
Also used : EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) Test(org.junit.jupiter.api.Test)

Aggregations

RepositoryGroup (org.apache.archiva.repository.RepositoryGroup)25 EditableRepositoryGroup (org.apache.archiva.repository.EditableRepositoryGroup)23 Test (org.junit.jupiter.api.Test)15 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)8 Map (java.util.Map)6 ArrayList (java.util.ArrayList)5 RepositoryException (org.apache.archiva.repository.RepositoryException)5 ValidationError (org.apache.archiva.repository.validation.ValidationError)5 IOException (java.io.IOException)4 RepositoryType (org.apache.archiva.repository.RepositoryType)4 Path (java.nio.file.Path)3 RegistryException (org.apache.archiva.components.registry.RegistryException)3 Configuration (org.apache.archiva.configuration.model.Configuration)3 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)3 IndeterminateConfigurationException (org.apache.archiva.configuration.provider.IndeterminateConfigurationException)3 ManagedRepository (org.apache.archiva.repository.ManagedRepository)3 List (java.util.List)2 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)2 Inject (javax.inject.Inject)2 Named (javax.inject.Named)2