use of org.apache.archiva.indexer.UnsupportedBaseContextException in project archiva by apache.
the class ArchivaIndexManagerMock method move.
@Override
public ArchivaIndexingContext move(ArchivaIndexingContext context, Repository repo) throws IndexCreationFailedException {
if (context == null) {
return null;
}
if (context.supports(IndexingContext.class)) {
try {
Path newPath = getIndexPath(repo);
IndexingContext ctx = context.getBaseContext(IndexingContext.class);
Path oldPath = ctx.getIndexDirectoryFile().toPath();
if (oldPath.equals(newPath)) {
// Nothing to do, if path does not change
return context;
}
if (!Files.exists(oldPath)) {
return createContext(repo);
} else if (context.isEmpty()) {
context.close();
return createContext(repo);
} else {
context.close(false);
Files.move(oldPath, newPath);
return createContext(repo);
}
} catch (IOException e) {
log.error("IOException while moving index directory {}", e.getMessage(), e);
throw new IndexCreationFailedException("Could not recreated the index.", e);
} catch (UnsupportedBaseContextException e) {
throw new IndexCreationFailedException("The given context, is not a maven context.");
}
} else {
throw new IndexCreationFailedException("Bad context type. This is not a maven context.");
}
}
use of org.apache.archiva.indexer.UnsupportedBaseContextException in project archiva by apache.
the class ArchivaIndexManagerMock method executeUpdateFunction.
/*
* This method is used to do some actions around the update execution code. And to make sure, that no other
* method is running on the same index.
*/
private void executeUpdateFunction(ArchivaIndexingContext context, IndexUpdateConsumer function) throws IndexUpdateFailedException {
IndexingContext indexingContext = null;
try {
indexingContext = getMvnContext(context);
} catch (UnsupportedBaseContextException e) {
throw new IndexUpdateFailedException("Maven index is not supported by this context", e);
}
final Path ctxPath = getIndexPath(context);
int loop = MAX_WAIT;
boolean active = false;
while (loop-- > 0 && !active) {
active = activeContexts.add(ctxPath);
try {
Thread.currentThread().sleep(WAIT_TIME);
} catch (InterruptedException e) {
// Ignore this
}
}
if (active) {
try {
function.accept(indexingContext);
} finally {
activeContexts.remove(ctxPath);
}
} else {
throw new IndexUpdateFailedException("Timeout while waiting for index release on context " + context.getId());
}
}
use of org.apache.archiva.indexer.UnsupportedBaseContextException in project archiva by apache.
the class MavenIndexManager method executeUpdateFunction.
/*
* This method is used to do some actions around the update execution code. And to make sure, that no other
* method is running on the same index.
*/
private void executeUpdateFunction(ArchivaIndexingContext context, IndexUpdateConsumer function) throws IndexUpdateFailedException {
IndexingContext indexingContext = null;
try {
indexingContext = getMvnContext(context);
} catch (UnsupportedBaseContextException e) {
throw new IndexUpdateFailedException("Maven index is not supported by this context", e);
}
final Path ctxPath = getIndexPath(context);
int loop = MAX_WAIT;
boolean active = false;
while (loop-- > 0 && !active) {
active = activeContexts.add(ctxPath);
try {
Thread.currentThread().sleep(WAIT_TIME);
} catch (InterruptedException e) {
// Ignore this
}
}
if (active) {
try {
function.accept(indexingContext);
} finally {
activeContexts.remove(ctxPath);
}
} else {
throw new IndexUpdateFailedException("Timeout while waiting for index release on context " + context.getId());
}
}
use of org.apache.archiva.indexer.UnsupportedBaseContextException in project archiva by apache.
the class MavenRepositorySearch method getIndexingContext.
private IndexingContext getIndexingContext(String id) {
String repoId;
if (StringUtils.startsWith(id, "remote-")) {
repoId = StringUtils.substringAfter(id, "remote-");
} else {
repoId = id;
}
Repository repo = repositoryRegistry.getRepository(repoId);
if (repo == null) {
return null;
} else {
if (repo.getIndexingContext() != null) {
try {
return repo.getIndexingContext().getBaseContext(IndexingContext.class);
} catch (UnsupportedBaseContextException e) {
return null;
}
} else {
return null;
}
}
}
use of org.apache.archiva.indexer.UnsupportedBaseContextException 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);
}
}
Aggregations