Search in sources :

Example 6 with BucketNotFoundException

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);
    }
}
Also used : FunctionException(org.apache.geode.cache.execute.FunctionException) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) LuceneService(org.apache.geode.cache.lucene.LuceneService) IndexRepository(org.apache.geode.cache.lucene.internal.repository.IndexRepository) IndexWriter(org.apache.lucene.index.IndexWriter) InternalLuceneIndex(org.apache.geode.cache.lucene.internal.InternalLuceneIndex) FileSystem(org.apache.geode.cache.lucene.internal.filesystem.FileSystem) BucketNotFoundException(org.apache.geode.internal.cache.BucketNotFoundException) RepositoryManager(org.apache.geode.cache.lucene.internal.repository.RepositoryManager) File(java.io.File)

Aggregations

BucketNotFoundException (org.apache.geode.internal.cache.BucketNotFoundException)6 IndexRepository (org.apache.geode.cache.lucene.internal.repository.IndexRepository)5 IOException (java.io.IOException)3 RepositoryManager (org.apache.geode.cache.lucene.internal.repository.RepositoryManager)3 ArrayList (java.util.ArrayList)2 CacheClosedException (org.apache.geode.cache.CacheClosedException)2 Region (org.apache.geode.cache.Region)2 AsyncEvent (org.apache.geode.cache.asyncqueue.AsyncEvent)2 RegionFunctionContext (org.apache.geode.cache.execute.RegionFunctionContext)2 PrimaryBucketException (org.apache.geode.internal.cache.PrimaryBucketException)2 File (java.io.File)1 HashSet (java.util.HashSet)1 InternalGemFireError (org.apache.geode.InternalGemFireError)1 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)1 FunctionException (org.apache.geode.cache.execute.FunctionException)1 LuceneIndexNotFoundException (org.apache.geode.cache.lucene.LuceneIndexNotFoundException)1 LuceneQueryProvider (org.apache.geode.cache.lucene.LuceneQueryProvider)1 LuceneService (org.apache.geode.cache.lucene.LuceneService)1 InternalLuceneIndex (org.apache.geode.cache.lucene.internal.InternalLuceneIndex)1 LuceneIndexImpl (org.apache.geode.cache.lucene.internal.LuceneIndexImpl)1