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);
}
}
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);
}
}
Aggregations