use of org.apache.archiva.admin.model.beans.ScanStatus in project archiva by apache.
the class RepositoryTaskAdministrationTest method testScanStatusWithId.
@Test
public void testScanStatusWithId() throws RepositoryAdminException, TaskQueueException {
TaskQueue queue = mock(TaskQueue.class);
TaskQueue indexQueue = mock(TaskQueue.class);
List<RepositoryTask> scanList = new ArrayList<>();
RepositoryTask scanTask1 = new RepositoryTask();
scanTask1.setRepositoryId("abcde");
scanTask1.setScanAll(true);
scanTask1.setResourceFile(null);
scanList.add(scanTask1);
RepositoryTask scanTask2 = new RepositoryTask();
scanTask2.setRepositoryId("testrepo2");
scanTask2.setScanAll(true);
scanTask2.setResourceFile(null);
scanList.add(scanTask1);
List<ArtifactIndexingTask> indexList = new ArrayList<>();
ArtifactIndexingTask indexTask1 = mock(ArtifactIndexingTask.class, RETURNS_DEEP_STUBS);
when(indexTask1.getRepository().getId()).thenReturn("indexrepo1");
when(indexTask1.isExecuteOnEntireRepo()).thenReturn(true);
when(indexTask1.getResourceFile()).thenReturn(null);
indexList.add(indexTask1);
ArtifactIndexingTask indexTask2 = mock(ArtifactIndexingTask.class, RETURNS_DEEP_STUBS);
when(indexTask2.getRepository().getId()).thenReturn("indexrepo2");
when(indexTask2.isExecuteOnEntireRepo()).thenReturn(true);
when(indexTask2.getResourceFile()).thenReturn(null);
indexList.add(indexTask2);
when(scanningTaskExecutor.getQueue()).thenReturn(queue);
when(indexingTaskExecutor.getQueue()).thenReturn(indexQueue);
when(queue.getQueueSnapshot()).thenReturn(scanList);
when(indexQueue.getQueueSnapshot()).thenReturn(indexList);
when(registry.getManagedRepository("indexrepo2")).thenReturn(mock(ManagedRepository.class));
ScanStatus currentScanStatus = taskAdministration.getCurrentScanStatus("indexrepo2");
assertNotNull(currentScanStatus);
assertNotNull(currentScanStatus.getIndexingQueue());
assertNotNull(currentScanStatus.getScanQueue());
assertEquals(0, currentScanStatus.getScanQueue().size());
assertEquals(1, currentScanStatus.getIndexingQueue().size());
}
use of org.apache.archiva.admin.model.beans.ScanStatus in project archiva by apache.
the class RepositoryTaskAdministrationTest method testScanStatus.
@Test
public void testScanStatus() throws RepositoryAdminException, TaskQueueException {
TaskQueue queue = mock(TaskQueue.class);
TaskQueue indexQueue = mock(TaskQueue.class);
List<RepositoryTask> scanList = new ArrayList<>();
RepositoryTask scanTask1 = new RepositoryTask();
scanTask1.setRepositoryId("abcde");
scanTask1.setScanAll(true);
scanTask1.setResourceFile(null);
scanList.add(scanTask1);
RepositoryTask scanTask2 = new RepositoryTask();
scanTask2.setRepositoryId("testrepo2");
scanTask2.setScanAll(true);
scanTask2.setResourceFile(null);
scanList.add(scanTask1);
List<ArtifactIndexingTask> indexList = new ArrayList<>();
ArtifactIndexingTask indexTask1 = mock(ArtifactIndexingTask.class, RETURNS_DEEP_STUBS);
when(indexTask1.getRepository().getId()).thenReturn("indexrepo1");
when(indexTask1.isExecuteOnEntireRepo()).thenReturn(true);
when(indexTask1.getResourceFile()).thenReturn(null);
indexList.add(indexTask1);
ArtifactIndexingTask indexTask2 = mock(ArtifactIndexingTask.class, RETURNS_DEEP_STUBS);
when(indexTask2.getRepository().getId()).thenReturn("indexrepo2");
when(indexTask2.isExecuteOnEntireRepo()).thenReturn(true);
when(indexTask2.getResourceFile()).thenReturn(null);
indexList.add(indexTask2);
when(scanningTaskExecutor.getQueue()).thenReturn(queue);
when(indexingTaskExecutor.getQueue()).thenReturn(indexQueue);
when(queue.getQueueSnapshot()).thenReturn(scanList);
when(indexQueue.getQueueSnapshot()).thenReturn(indexList);
ScanStatus currentScanStatus = taskAdministration.getCurrentScanStatus();
assertNotNull(currentScanStatus);
assertNotNull(currentScanStatus.getIndexingQueue());
assertNotNull(currentScanStatus.getScanQueue());
assertEquals(2, currentScanStatus.getScanQueue().size());
assertEquals(2, currentScanStatus.getIndexingQueue().size());
}
use of org.apache.archiva.admin.model.beans.ScanStatus in project archiva by apache.
the class DefaultRepositoryTaskAdministration method getCurrentScanStatus.
@Override
public ScanStatus getCurrentScanStatus(String repositoryId) throws RepositoryAdminException {
if (StringUtils.isEmpty(repositoryId)) {
throw RepositoryAdminException.ofKey("repository.id.invalid", "");
}
org.apache.archiva.repository.ManagedRepository repository = repositoryRegistry.getManagedRepository(repositoryId);
if (repository == null) {
throw RepositoryAdminException.ofKey("repository.not_found", repositoryId);
}
ScanStatus status = new ScanStatus();
try {
RepositoryTask scanTask = scanningTaskExecutor.getCurrentTask();
if (scanTask != null && !repositoryId.equals(scanTask.getRepositoryId())) {
scanTask = null;
}
ArtifactIndexingTask indexTask = indexingTaskExecutor.getCurrentTask();
if (indexTask != null && !repositoryId.equals(indexTask.getRepository().getId())) {
indexTask = null;
}
updateScanInfo(status, scanTask, scanningTaskExecutor.getQueue().getQueueSnapshot().stream().filter(task -> repositoryId.equals(task.getRepositoryId())).collect(Collectors.toList()));
updateIndexInfo(status, indexTask, indexingTaskExecutor.getQueue().getQueueSnapshot().stream().filter(task -> repositoryId.equals(task.getRepository().getId())).collect(Collectors.toList()));
return status;
} catch (TaskQueueException e) {
log.error("Could not get task information: {}", e.getMessage(), e);
throw RepositoryAdminException.ofKey("repository.scan.task_retrieval_failed", e.getMessage());
}
}
use of org.apache.archiva.admin.model.beans.ScanStatus in project archiva by apache.
the class DefaultRepositoryTaskAdministration method getCurrentScanStatus.
@Override
public ScanStatus getCurrentScanStatus() throws RepositoryAdminException {
ScanStatus status = new ScanStatus();
try {
RepositoryTask scanTask = scanningTaskExecutor.getCurrentTask();
ArtifactIndexingTask indexTask = indexingTaskExecutor.getCurrentTask();
updateScanInfo(status, scanTask, scanningTaskExecutor.getQueue().getQueueSnapshot());
updateIndexInfo(status, indexTask, indexingTaskExecutor.getQueue().getQueueSnapshot());
return status;
} catch (TaskQueueException e) {
log.error("Could not get task information: {}", e.getMessage(), e);
throw RepositoryAdminException.ofKey("repository.scan.task_retrieval_failed", e.getMessage());
}
}
Aggregations