Search in sources :

Example 1 with RepositoryScanStatistics

use of org.apache.archiva.repository.scanner.RepositoryScanStatistics in project archiva by apache.

the class ArchivaCli method doScan.

private void doScan(String path, String[] consumers) throws ConsumerException, MalformedURLException {
    BasicManagedRepository repo = new BasicManagedRepository(Paths.get(path).getFileName().toString(), "Archiva CLI Provided Repo", Paths.get(path).getParent());
    repo.setLocation(Paths.get(path).toUri());
    List<KnownRepositoryContentConsumer> knownConsumerList = new ArrayList<>();
    knownConsumerList.addAll(getConsumerList(consumers));
    List<InvalidRepositoryContentConsumer> invalidConsumerList = Collections.emptyList();
    List<String> ignoredContent = new ArrayList<>();
    ignoredContent.addAll(Arrays.asList(RepositoryScanner.IGNORABLE_CONTENT));
    RepositoryScanner scanner = applicationContext.getBean(RepositoryScanner.class);
    try {
        RepositoryScanStatistics stats = scanner.scan(repo, knownConsumerList, invalidConsumerList, ignoredContent, RepositoryScanner.FRESH_SCAN);
        LOGGER.info(stats.toDump(repo));
    } catch (RepositoryScannerException e) {
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : BasicManagedRepository(org.apache.archiva.repository.BasicManagedRepository) RepositoryScanner(org.apache.archiva.repository.scanner.RepositoryScanner) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) RepositoryScanStatistics(org.apache.archiva.repository.scanner.RepositoryScanStatistics) ArrayList(java.util.ArrayList) RepositoryScannerException(org.apache.archiva.repository.scanner.RepositoryScannerException) InvalidRepositoryContentConsumer(org.apache.archiva.consumers.InvalidRepositoryContentConsumer)

Example 2 with RepositoryScanStatistics

use of org.apache.archiva.repository.scanner.RepositoryScanStatistics in project archiva by apache.

the class ArchivaRepositoryScanningTaskExecutor method executeTask.

@SuppressWarnings("unchecked")
@Override
public void executeTask(RepositoryTask task) throws TaskExecutionException {
    try {
        // TODO: replace this whole class with the prescribed content scanning service/action
        // - scan repository for artifacts that do not have corresponding metadata or have been updated and
        // send events for each
        // - scan metadata for artifacts that have been removed and send events for each
        // - scan metadata for missing plugin data
        // - store information so that it can restart upon failure (publish event on the server recovery
        // queue, remove it on successful completion)
        this.task = task;
        String repoId = task.getRepositoryId();
        if (StringUtils.isBlank(repoId)) {
            throw new TaskExecutionException("Unable to execute RepositoryTask with blank repository Id.");
        }
        ManagedRepository arepo = repositoryRegistry.getManagedRepository(repoId);
        // execute consumers on resource file if set
        if (task.getResourceFile() != null) {
            log.debug("Executing task from queue with job name: {}", task);
            consumers.executeConsumers(arepo, task.getResourceFile(), task.isUpdateRelatedArtifacts());
        } else {
            log.info("Executing task from queue with job name: {}", task);
            // otherwise, execute consumers on whole repository
            if (arepo == null) {
                throw new TaskExecutionException("Unable to execute RepositoryTask with invalid repository id: " + repoId);
            }
            long sinceWhen = RepositoryScanner.FRESH_SCAN;
            long previousFileCount = 0;
            RepositorySession repositorySession = repositorySessionFactory.createSession();
            MetadataRepository metadataRepository = repositorySession.getRepository();
            try {
                if (!task.isScanAll()) {
                    RepositoryStatistics previousStats = repositoryStatisticsManager.getLastStatistics(metadataRepository, repoId);
                    if (previousStats != null) {
                        sinceWhen = previousStats.getScanStartTime().getTime();
                        previousFileCount = previousStats.getTotalFileCount();
                    }
                }
                RepositoryScanStatistics stats;
                try {
                    stats = repoScanner.scan(arepo, sinceWhen);
                } catch (RepositoryScannerException e) {
                    throw new TaskExecutionException("Repository error when executing repository job.", e);
                }
                log.info("Finished first scan: {}", stats.toDump(arepo));
                // further statistics will be populated by the following method
                Date endTime = new Date(stats.getWhenGathered().getTime() + stats.getDuration());
                log.info("Gathering repository statistics");
                repositoryStatisticsManager.addStatisticsAfterScan(metadataRepository, repoId, stats.getWhenGathered(), endTime, stats.getTotalFileCount(), stats.getTotalFileCount() - previousFileCount);
                repositorySession.save();
            } catch (MetadataRepositoryException e) {
                throw new TaskExecutionException("Unable to store updated statistics: " + e.getMessage(), e);
            } finally {
                repositorySession.close();
            }
            // log.info( "Scanning for removed repository content" );
            // metadataRepository.findAllProjects();
            // FIXME: do something
            log.info("Finished repository task: {}", task);
            this.task = null;
        }
    } catch (RepositoryAdminException e) {
        log.error(e.getMessage(), e);
        throw new TaskExecutionException(e.getMessage(), e);
    }
}
Also used : TaskExecutionException(org.apache.archiva.redback.components.taskqueue.execution.TaskExecutionException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) ManagedRepository(org.apache.archiva.repository.ManagedRepository) RepositoryScanStatistics(org.apache.archiva.repository.scanner.RepositoryScanStatistics) RepositoryScannerException(org.apache.archiva.repository.scanner.RepositoryScannerException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) RepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics) Date(java.util.Date)

Aggregations

RepositoryScanStatistics (org.apache.archiva.repository.scanner.RepositoryScanStatistics)2 RepositoryScannerException (org.apache.archiva.repository.scanner.RepositoryScannerException)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)1 InvalidRepositoryContentConsumer (org.apache.archiva.consumers.InvalidRepositoryContentConsumer)1 KnownRepositoryContentConsumer (org.apache.archiva.consumers.KnownRepositoryContentConsumer)1 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)1 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)1 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)1 RepositoryStatistics (org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics)1 TaskExecutionException (org.apache.archiva.redback.components.taskqueue.execution.TaskExecutionException)1 BasicManagedRepository (org.apache.archiva.repository.BasicManagedRepository)1 ManagedRepository (org.apache.archiva.repository.ManagedRepository)1 RepositoryScanner (org.apache.archiva.repository.scanner.RepositoryScanner)1