Search in sources :

Example 6 with RepositoryStatistics

use of org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics in project archiva by apache.

the class DefaultReportRepositoriesService method getMultipleRepositoriesReport.

private List<RepositoryStatistics> getMultipleRepositoriesReport(List<String> repositoriesId, int rowCount) {
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        MetadataRepository metadataRepository = repositorySession.getRepository();
        List<RepositoryStatistics> stats = new ArrayList<>();
        for (String repo : repositoriesId) {
            try {
                stats.add(repositoryStatisticsManager.getLastStatistics(metadataRepository, repo));
            } catch (MetadataRepositoryException e) {
                log.warn("Unable to retrieve stats, assuming is empty: {}", e.getMessage(), e);
            }
        }
        return stats.subList(0, stats.size() > rowCount ? rowCount : stats.size());
    } finally {
        repositorySession.close();
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) ArrayList(java.util.ArrayList) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) RepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics)

Example 7 with RepositoryStatistics

use of org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics in project archiva by apache.

the class DefaultReportRepositoriesService method getUniqueRepositoryReport.

private List<RepositoryStatistics> getUniqueRepositoryReport(String repositoryId, int rowCount, Date startDate, Date endDate) {
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        MetadataRepository metadataRepository = repositorySession.getRepository();
        List<RepositoryStatistics> stats = null;
        try {
            stats = repositoryStatisticsManager.getStatisticsInRange(metadataRepository, repositoryId, startDate, endDate);
        } catch (MetadataRepositoryException e) {
            log.warn("Unable to retrieve stats, assuming is empty: {}", e.getMessage(), e);
        }
        if (stats == null || stats.isEmpty()) {
            return Collections.<RepositoryStatistics>emptyList();
        }
        return stats.subList(0, stats.size() > rowCount ? rowCount : stats.size());
    } finally {
        repositorySession.close();
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) RepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics)

Example 8 with RepositoryStatistics

use of org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics in project archiva by apache.

the class DefaultManagedRepositoriesService method getManagedRepositoryStatistics.

@Override
public ArchivaRepositoryStatistics getManagedRepositoryStatistics(String repositoryId, String lang) throws ArchivaRestServiceException {
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", new Locale(lang));
    try {
        MetadataRepository metadataRepository = repositorySession.getRepository();
        RepositoryStatistics stats = null;
        try {
            stats = repositoryStatisticsManager.getLastStatistics(metadataRepository, repositoryId);
        } catch (MetadataRepositoryException e) {
            log.warn("Error retrieving repository statistics: {}", e.getMessage(), e);
        }
        if (stats != null) {
            ArchivaRepositoryStatistics archivaRepositoryStatistics = getModelMapper().map(stats, ArchivaRepositoryStatistics.class);
            archivaRepositoryStatistics.setDuration(archivaRepositoryStatistics.getScanEndTime().getTime() - archivaRepositoryStatistics.getScanStartTime().getTime());
            archivaRepositoryStatistics.setLastScanDate(sdf.format(archivaRepositoryStatistics.getScanEndTime()));
            return archivaRepositoryStatistics;
        }
    } finally {
        if (repositorySession != null) {
            repositorySession.close();
        }
    }
    return null;
}
Also used : Locale(java.util.Locale) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) ArchivaRepositoryStatistics(org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) SimpleDateFormat(java.text.SimpleDateFormat) RepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics) ArchivaRepositoryStatistics(org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics)

Example 9 with RepositoryStatistics

use of org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics 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 10 with RepositoryStatistics

use of org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics 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

RepositoryStatistics (org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics)18 DefaultRepositoryStatistics (org.apache.archiva.metadata.repository.stats.model.DefaultRepositoryStatistics)14 Test (org.junit.Test)11 Date (java.util.Date)9 ArrayList (java.util.ArrayList)7 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)4 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)4 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)4 Path (java.nio.file.Path)3 ArtifactReference (org.apache.archiva.model.ArtifactReference)3 RepositoryTask (org.apache.archiva.scheduler.repository.model.RepositoryTask)3 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Locale (java.util.Locale)1 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)1 TaskExecutionException (org.apache.archiva.redback.components.taskqueue.execution.TaskExecutionException)1 ManagedRepository (org.apache.archiva.repository.ManagedRepository)1 RepositoryScanStatistics (org.apache.archiva.repository.scanner.RepositoryScanStatistics)1 RepositoryScannerException (org.apache.archiva.repository.scanner.RepositoryScannerException)1 ArchivaRepositoryStatistics (org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics)1