Search in sources :

Example 1 with RepositoryTask

use of org.apache.archiva.scheduler.repository.model.RepositoryTask in project archiva by apache.

the class DefaultRepositoryProxyConnectors method queueRepositoryTask.

private void queueRepositoryTask(String repositoryId, Path localFile) {
    RepositoryTask task = new RepositoryTask();
    task.setRepositoryId(repositoryId);
    task.setResourceFile(localFile);
    task.setUpdateRelatedArtifacts(true);
    task.setScanAll(true);
    try {
        scheduler.queueTask(task);
    } catch (TaskQueueException e) {
        log.error("Unable to queue repository task to execute consumers on resource file ['{}" + "'].", localFile.getFileName());
    }
}
Also used : RepositoryTask(org.apache.archiva.scheduler.repository.model.RepositoryTask) TaskQueueException(org.apache.archiva.redback.components.taskqueue.TaskQueueException)

Example 2 with RepositoryTask

use of org.apache.archiva.scheduler.repository.model.RepositoryTask in project archiva by apache.

the class DefaultRepositoriesService method scanRepositoryNow.

@Override
public Boolean scanRepositoryNow(String repositoryId, boolean fullScan) throws ArchivaRestServiceException {
    try {
        org.apache.archiva.repository.ManagedRepository repository = repositoryRegistry.getManagedRepository(repositoryId);
        ArtifactIndexingTask task = new ArtifactIndexingTask(repository, null, ArtifactIndexingTask.Action.FINISH, repository.getIndexingContext());
        task.setExecuteOnEntireRepo(true);
        task.setOnlyUpdate(!fullScan);
        archivaIndexingTaskExecutor.executeTask(task);
        scheduler.queueTask(new RepositoryTask(repositoryId, fullScan));
        return Boolean.TRUE;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), e);
    }
}
Also used : ArtifactIndexingTask(org.apache.archiva.scheduler.indexing.ArtifactIndexingTask) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) RepositoryTask(org.apache.archiva.scheduler.repository.model.RepositoryTask) ArchivaSecurityException(org.apache.archiva.security.ArchivaSecurityException) TaskQueueException(org.apache.archiva.redback.components.taskqueue.TaskQueueException) RepositoryScannerException(org.apache.archiva.repository.scanner.RepositoryScannerException) DownloadRemoteIndexException(org.apache.archiva.scheduler.indexing.DownloadRemoteIndexException) XMLException(org.apache.archiva.xml.XMLException) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositoryException(org.apache.archiva.repository.RepositoryException) ContentNotFoundException(org.apache.archiva.repository.ContentNotFoundException) RepositoryNotFoundException(org.apache.archiva.repository.RepositoryNotFoundException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryMetadataException(org.apache.archiva.repository.metadata.RepositoryMetadataException) UserManagerException(org.apache.archiva.redback.users.UserManagerException) IOException(java.io.IOException) UserNotFoundException(org.apache.archiva.redback.users.UserNotFoundException) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) AuthorizationException(org.apache.archiva.redback.authorization.AuthorizationException)

Example 3 with RepositoryTask

use of org.apache.archiva.scheduler.repository.model.RepositoryTask in project archiva by apache.

the class ArchivaDavResource method queueRepositoryTask.

private void queueRepositoryTask(Path localFile) {
    RepositoryTask task = new RepositoryTask();
    task.setRepositoryId(repository.getId());
    task.setResourceFile(localFile);
    task.setUpdateRelatedArtifacts(false);
    task.setScanAll(false);
    try {
        scheduler.queueTask(task);
    } catch (TaskQueueException e) {
        log.error("Unable to queue repository task to execute consumers on resource file ['{}" + "'].", localFile.getFileName());
    }
}
Also used : RepositoryTask(org.apache.archiva.scheduler.repository.model.RepositoryTask) TaskQueueException(org.apache.archiva.redback.components.taskqueue.TaskQueueException)

Example 4 with RepositoryTask

use of org.apache.archiva.scheduler.repository.model.RepositoryTask in project archiva by apache.

the class ArchivaRepositoryScanningTaskExecutorPhase2Test method testExecutorScanOnlyNewArtifacts.

@Test
public void testExecutorScanOnlyNewArtifacts() throws Exception {
    RepositoryTask repoTask = new RepositoryTask();
    repoTask.setRepositoryId(TEST_REPO_ID);
    repoTask.setScanAll(false);
    createAndSaveTestStats();
    taskExecutor.executeTask(repoTask);
    // check no artifacts processed
    Collection<ArtifactReference> unprocessedResultList = testConsumer.getConsumed();
    assertNotNull(unprocessedResultList);
    assertEquals("Incorrect number of unprocessed artifacts detected. No new artifacts should have been found.", 0, unprocessedResultList.size());
    // check correctness of new stats
    RepositoryStatistics newStats = repositoryStatisticsManager.getLastStatistics(metadataRepository, TEST_REPO_ID);
    assertEquals(0, newStats.getNewFileCount());
    assertEquals(31, newStats.getTotalFileCount());
    // FIXME: can't test these as they weren't stored in the database, move to tests for RepositoryStatisticsManager implementation
    // assertEquals( 8, newStats.getTotalArtifactCount() );
    // assertEquals( 3, newStats.getTotalGroupCount() );
    // assertEquals( 5, newStats.getTotalProjectCount() );
    // assertEquals( 14159, newStats.getTotalArtifactFileSize() );
    Path newArtifactGroup = repoDir.resolve("org/apache/archiva");
    assertFalse("newArtifactGroup should not exist.", Files.exists(newArtifactGroup));
    FileUtils.copyDirectoryStructure(Paths.get("target/test-classes/test-repo/org/apache/archiva").toFile(), newArtifactGroup.toFile());
    // update last modified date
    Files.setLastModifiedTime(newArtifactGroup.resolve("archiva-index-methods-jar-test/1.0/pom.xml"), FileTime.fromMillis(Calendar.getInstance().getTimeInMillis() + 1000));
    Files.setLastModifiedTime(newArtifactGroup.resolve("archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar"), FileTime.fromMillis(Calendar.getInstance().getTimeInMillis() + 1000));
    assertTrue(Files.exists(newArtifactGroup));
    taskExecutor.executeTask(repoTask);
    unprocessedResultList = testConsumer.getConsumed();
    assertNotNull(unprocessedResultList);
    assertEquals("Incorrect number of unprocessed artifacts detected. One new artifact should have been found.", 1, unprocessedResultList.size());
    // check correctness of new stats
    RepositoryStatistics updatedStats = repositoryStatisticsManager.getLastStatistics(metadataRepository, TEST_REPO_ID);
    assertEquals(2, updatedStats.getNewFileCount());
    assertEquals(33, updatedStats.getTotalFileCount());
// FIXME: can't test these as they weren't stored in the database, move to tests for RepositoryStatisticsManager implementation
// assertEquals( 8, newStats.getTotalArtifactCount() );
// assertEquals( 3, newStats.getTotalGroupCount() );
// assertEquals( 5, newStats.getTotalProjectCount() );
// assertEquals( 19301, updatedStats.getTotalArtifactFileSize() );
}
Also used : Path(java.nio.file.Path) RepositoryTask(org.apache.archiva.scheduler.repository.model.RepositoryTask) ArtifactReference(org.apache.archiva.model.ArtifactReference) RepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics) DefaultRepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.DefaultRepositoryStatistics) Test(org.junit.Test)

Example 5 with RepositoryTask

use of org.apache.archiva.scheduler.repository.model.RepositoryTask in project archiva by apache.

the class ArchivaRepositoryScanningTaskExecutorPhase2Test method testExecutorScanOnlyNewArtifactsChangeTimes.

@Test
public void testExecutorScanOnlyNewArtifactsChangeTimes() throws Exception {
    RepositoryTask repoTask = new RepositoryTask();
    repoTask.setRepositoryId(TEST_REPO_ID);
    repoTask.setScanAll(false);
    createAndSaveTestStats();
    Path newArtifactGroup = repoDir.resolve("org/apache/archiva");
    assertFalse("newArtifactGroup should not exist.", Files.exists(newArtifactGroup));
    FileUtils.copyDirectoryStructure(Paths.get("target/test-classes/test-repo/org/apache/archiva").toFile(), newArtifactGroup.toFile());
    // update last modified date, placing shortly after last scan
    Files.setLastModifiedTime(newArtifactGroup.resolve("archiva-index-methods-jar-test/1.0/pom.xml"), FileTime.fromMillis(Calendar.getInstance().getTimeInMillis() + 1000));
    Files.setLastModifiedTime(newArtifactGroup.resolve("archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar"), FileTime.fromMillis(Calendar.getInstance().getTimeInMillis() + 1000));
    assertTrue(Files.exists(newArtifactGroup));
    // scan using the really long previous duration
    taskExecutor.executeTask(repoTask);
    // check no artifacts processed
    Collection<ArtifactReference> unprocessedResultList = testConsumer.getConsumed();
    assertNotNull(unprocessedResultList);
    assertEquals("Incorrect number of unprocessed artifacts detected. One new artifact should have been found.", 1, unprocessedResultList.size());
    // check correctness of new stats
    RepositoryStatistics newStats = repositoryStatisticsManager.getLastStatistics(metadataRepository, TEST_REPO_ID);
    assertEquals(2, newStats.getNewFileCount());
    assertEquals(33, newStats.getTotalFileCount());
// FIXME: can't test these as they weren't stored in the database, move to tests for RepositoryStatisticsManager implementation
// assertEquals( 8, newStats.getTotalArtifactCount() );
// assertEquals( 3, newStats.getTotalGroupCount() );
// assertEquals( 5, newStats.getTotalProjectCount() );
// assertEquals( 19301, newStats.getTotalArtifactFileSize() );
}
Also used : Path(java.nio.file.Path) RepositoryTask(org.apache.archiva.scheduler.repository.model.RepositoryTask) ArtifactReference(org.apache.archiva.model.ArtifactReference) RepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics) DefaultRepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.DefaultRepositoryStatistics) Test(org.junit.Test)

Aggregations

RepositoryTask (org.apache.archiva.scheduler.repository.model.RepositoryTask)15 TaskQueueException (org.apache.archiva.redback.components.taskqueue.TaskQueueException)10 ArtifactReference (org.apache.archiva.model.ArtifactReference)5 Test (org.junit.Test)5 Path (java.nio.file.Path)3 DefaultRepositoryStatistics (org.apache.archiva.metadata.repository.stats.model.DefaultRepositoryStatistics)3 RepositoryStatistics (org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics)3 IOException (java.io.IOException)1 Date (java.util.Date)1 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)1 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)1 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)1 AuthorizationException (org.apache.archiva.redback.authorization.AuthorizationException)1 TaskQueue (org.apache.archiva.redback.components.taskqueue.TaskQueue)1 UserManagerException (org.apache.archiva.redback.users.UserManagerException)1 UserNotFoundException (org.apache.archiva.redback.users.UserNotFoundException)1 ContentNotFoundException (org.apache.archiva.repository.ContentNotFoundException)1 RepositoryException (org.apache.archiva.repository.RepositoryException)1 RepositoryNotFoundException (org.apache.archiva.repository.RepositoryNotFoundException)1 RepositoryMetadataException (org.apache.archiva.repository.metadata.RepositoryMetadataException)1