use of org.apache.maven.index.packer.IndexPackingRequest in project archiva by apache.
the class MavenIndexManager method pack.
@Override
public void pack(final ArchivaIndexingContext context) throws IndexUpdateFailedException {
executeUpdateFunction(context, indexingContext -> {
try {
IndexPackingRequest request = new IndexPackingRequest(indexingContext, indexingContext.acquireIndexSearcher().getIndexReader(), indexingContext.getIndexDirectoryFile());
indexPacker.packIndex(request);
indexingContext.updateTimestamp(true);
} catch (IOException e) {
log.error("IOException while packing index of context " + context.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""));
throw new IndexUpdateFailedException("IOException during update of " + context.getId(), e);
}
});
}
use of org.apache.maven.index.packer.IndexPackingRequest in project archiva by apache.
the class DefaultIndexMerger method buildMergedIndex.
@Override
public IndexingContext buildMergedIndex(IndexMergerRequest indexMergerRequest) throws IndexMergerException {
String groupId = indexMergerRequest.getGroupId();
if (runningGroups.contains(groupId)) {
log.info("skip build merge remote indexes for id: '{}' as already running", groupId);
return null;
}
runningGroups.add(groupId);
StopWatch stopWatch = new StopWatch();
stopWatch.reset();
stopWatch.start();
Path mergedIndexDirectory = indexMergerRequest.getMergedIndexDirectory();
String tempRepoId = mergedIndexDirectory.getFileName().toString();
try {
Path indexLocation = mergedIndexDirectory.resolve(indexMergerRequest.getMergedIndexPath());
List<IndexingContext> members = indexMergerRequest.getRepositoriesIds().stream().map(id -> repositoryRegistry.getRepository(id)).filter(repo -> repo.getType().equals(RepositoryType.MAVEN)).map(repo -> {
try {
return repo.getIndexingContext().getBaseContext(IndexingContext.class);
} catch (UnsupportedBaseContextException e) {
return null;
// Ignore
}
}).filter(Objects::nonNull).collect(Collectors.toList());
ContextMemberProvider memberProvider = new StaticContextMemberProvider(members);
IndexingContext mergedCtx = indexer.createMergedIndexingContext(tempRepoId, tempRepoId, mergedIndexDirectory.toFile(), indexLocation.toFile(), true, memberProvider);
mergedCtx.optimize();
if (indexMergerRequest.isPackIndex()) {
IndexPackingRequest request = new //
IndexPackingRequest(//
mergedCtx, //
mergedCtx.acquireIndexSearcher().getIndexReader(), indexLocation.toFile());
indexPacker.packIndex(request);
}
if (indexMergerRequest.isTemporary()) {
temporaryGroupIndexes.add(new TemporaryGroupIndex(mergedIndexDirectory, tempRepoId, groupId, indexMergerRequest.getMergedIndexTtl()));
temporaryContextes.add(mergedCtx);
}
stopWatch.stop();
log.info("merged index for repos {} in {} s", indexMergerRequest.getRepositoriesIds(), stopWatch.getTime());
return mergedCtx;
} catch (IOException e) {
throw new IndexMergerException(e.getMessage(), e);
} finally {
runningGroups.remove(groupId);
}
}
use of org.apache.maven.index.packer.IndexPackingRequest in project archiva by apache.
the class ArchivaIndexingTaskExecutor method finishIndexingTask.
private void finishIndexingTask(ArtifactIndexingTask indexingTask, ManagedRepository repository, IndexingContext context) throws TaskExecutionException {
try {
log.debug("Finishing indexing");
context.optimize();
if (repository.supportsFeature(IndexCreationFeature.class)) {
IndexCreationFeature icf = repository.getFeature(IndexCreationFeature.class).get();
if (!icf.isSkipPackedIndexCreation() && icf.getLocalPackedIndexPath() != null) {
log.debug("Creating packed index from {} on {}", context.getIndexDirectoryFile(), icf.getLocalPackedIndexPath());
IndexPackingRequest request = new //
IndexPackingRequest(//
context, context.acquireIndexSearcher().getIndexReader(), icf.getLocalPackedIndexPath().toFile());
indexPacker.packIndex(request);
context.updateTimestamp(true);
log.debug("Index file packed at '{}'.", icf.getLocalPackedIndexPath());
} else {
log.debug("skip packed index creation");
}
} else {
log.debug("skip packed index creation");
}
} catch (IOException e) {
log.error("Error occurred while executing indexing task '{}': {}", indexingTask, e.getMessage());
throw new TaskExecutionException("Error occurred while executing indexing task '" + indexingTask + "'", e);
}
}
use of org.apache.maven.index.packer.IndexPackingRequest in project archiva by apache.
the class ArchivaIndexManagerMock method pack.
@Override
public void pack(final ArchivaIndexingContext context) throws IndexUpdateFailedException {
executeUpdateFunction(context, indexingContext -> {
try {
IndexPackingRequest request = new IndexPackingRequest(indexingContext, indexingContext.acquireIndexSearcher().getIndexReader(), indexingContext.getIndexDirectoryFile());
indexPacker.packIndex(request);
indexingContext.updateTimestamp(true);
} catch (IOException e) {
log.error("IOException while packing index of context " + context.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""));
throw new IndexUpdateFailedException("IOException during update of " + context.getId(), e);
}
});
}
use of org.apache.maven.index.packer.IndexPackingRequest in project archiva by apache.
the class ArchivaIndexManagerMock method pack.
@Override
public void pack(final ArchivaIndexingContext context) throws IndexUpdateFailedException {
executeUpdateFunction(context, indexingContext -> {
try {
IndexPackingRequest request = new IndexPackingRequest(indexingContext, indexingContext.acquireIndexSearcher().getIndexReader(), indexingContext.getIndexDirectoryFile());
indexPacker.packIndex(request);
indexingContext.updateTimestamp(true);
} catch (IOException e) {
log.error("IOException while packing index of context " + context.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""));
throw new IndexUpdateFailedException("IOException during update of " + context.getId(), e);
}
});
}
Aggregations