use of org.apache.geode.internal.cache.BucketNotFoundException in project geode by apache.
the class DumpDirectoryFiles method execute.
@Override
public void execute(FunctionContext context) {
RegionFunctionContext ctx = (RegionFunctionContext) context;
if (!(context.getArguments() instanceof String[])) {
throw new IllegalArgumentException("Arguments should be a string array");
}
String[] args = (String[]) context.getArguments();
if (args.length != 2) {
throw new IllegalArgumentException("Expected 2 arguments: exportLocation, indexName");
}
String exportLocation = args[0];
String indexName = args[1];
final Region<Object, Object> region = ctx.getDataSet();
LuceneService service = LuceneServiceProvider.get(ctx.getDataSet().getCache());
InternalLuceneIndex index = (InternalLuceneIndex) service.getIndex(indexName, region.getFullPath());
if (index == null) {
throw new IllegalStateException("Index not found for region " + region + " index " + indexName);
}
final RepositoryManager repoManager = index.getRepositoryManager();
try {
final Collection<IndexRepository> repositories = repoManager.getRepositories(ctx);
repositories.stream().forEach(repo -> {
final IndexWriter writer = repo.getWriter();
RegionDirectory directory = (RegionDirectory) writer.getDirectory();
FileSystem fs = directory.getFileSystem();
String bucketName = index.getName() + "_" + repo.getRegion().getFullPath();
bucketName = bucketName.replace("/", "_");
File bucketDirectory = new File(exportLocation, bucketName);
bucketDirectory.mkdirs();
fs.export(bucketDirectory);
});
context.getResultSender().lastResult(null);
} catch (BucketNotFoundException e) {
throw new FunctionException(e);
}
}
Aggregations