Search in sources :

Example 16 with AbstractExecution

use of org.apache.geode.internal.cache.execute.AbstractExecution in project geode by apache.

the class DiskStoreCommands method getDiskStoreListing.

@SuppressWarnings("unchecked")
protected List<DiskStoreDetails> getDiskStoreListing(Set<DistributedMember> members) {
    final Execution membersFunctionExecutor = getMembersFunctionExecutor(members);
    if (membersFunctionExecutor instanceof AbstractExecution) {
        ((AbstractExecution) membersFunctionExecutor).setIgnoreDepartedMembers(true);
    }
    final ResultCollector<?, ?> resultCollector = membersFunctionExecutor.execute(new ListDiskStoresFunction());
    final List<?> results = (List<?>) resultCollector.getResult();
    final List<DiskStoreDetails> distributedSystemMemberDiskStores = new ArrayList<DiskStoreDetails>(results.size());
    for (final Object result : results) {
        if (result instanceof Set) {
            // ignore FunctionInvocationTargetExceptions and other
            // Exceptions...
            distributedSystemMemberDiskStores.addAll((Set<DiskStoreDetails>) result);
        }
    }
    Collections.sort(distributedSystemMemberDiskStores);
    return distributedSystemMemberDiskStores;
}
Also used : AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) Execution(org.apache.geode.cache.execute.Execution) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) ListDiskStoresFunction(org.apache.geode.management.internal.cli.functions.ListDiskStoresFunction) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) DiskStoreDetails(org.apache.geode.management.internal.cli.domain.DiskStoreDetails) List(java.util.List) ArrayList(java.util.ArrayList)

Example 17 with AbstractExecution

use of org.apache.geode.internal.cache.execute.AbstractExecution in project geode by apache.

the class CliUtil method executeFunction.

/***
   * Executes a function with arguments on a set of members , ignores the departed members.
   * 
   * @param function Function to be executed.
   * @param args Arguments passed to the function, pass null if you wish to pass no arguments to the
   *        function.
   * @param targetMembers Set of members on which the function is to be executed.
   *
   * @return ResultCollector
   */
public static ResultCollector<?, ?> executeFunction(final Function function, Object args, final Set<DistributedMember> targetMembers) {
    Execution execution = null;
    if (args != null) {
        execution = FunctionService.onMembers(targetMembers).setArguments(args);
    } else {
        execution = FunctionService.onMembers(targetMembers);
    }
    ((AbstractExecution) execution).setIgnoreDepartedMembers(true);
    return execution.execute(function);
}
Also used : AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) Execution(org.apache.geode.cache.execute.Execution) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution)

Example 18 with AbstractExecution

use of org.apache.geode.internal.cache.execute.AbstractExecution in project geode by apache.

the class CliUtil method executeFunction.

/***
   * Executes a function with arguments on a member , ignores the departed member.
   * 
   * @param function Function to be executed
   * @param args Arguments passed to the function, pass null if you wish to pass no arguments to the
   *        function.
   * @param targetMember Member on which the function is to be executed.
   * @return ResultCollector
   */
public static ResultCollector<?, ?> executeFunction(final Function function, Object args, final DistributedMember targetMember) {
    Execution execution = null;
    if (args != null) {
        execution = FunctionService.onMember(targetMember).setArguments(args);
    } else {
        execution = FunctionService.onMember(targetMember);
    }
    ((AbstractExecution) execution).setIgnoreDepartedMembers(true);
    return execution.execute(function);
}
Also used : AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) Execution(org.apache.geode.cache.execute.Execution) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution)

Example 19 with AbstractExecution

use of org.apache.geode.internal.cache.execute.AbstractExecution in project geode by apache.

the class LuceneIndexCommandsJUnitTest method testListIndexWithStats.

@Test
public void testListIndexWithStats() {
    final InternalCache mockCache = mock(InternalCache.class, "InternalCache");
    final String serverName = "mockServer";
    final AbstractExecution mockFunctionExecutor = mock(AbstractExecution.class, "Function Executor");
    final ResultCollector mockResultCollector = mock(ResultCollector.class, "ResultCollector");
    final LuceneIndexStats mockIndexStats1 = getMockIndexStats(1, 10, 5, 1);
    final LuceneIndexStats mockIndexStats2 = getMockIndexStats(2, 20, 10, 2);
    final LuceneIndexStats mockIndexStats3 = getMockIndexStats(3, 30, 15, 3);
    String[] searchableFields = { "field1", "field2", "field3" };
    Map<String, Analyzer> fieldAnalyzers = new HashMap<>();
    fieldAnalyzers.put("field1", new StandardAnalyzer());
    fieldAnalyzers.put("field2", new KeywordAnalyzer());
    fieldAnalyzers.put("field3", null);
    final LuceneIndexDetails indexDetails1 = createIndexDetails("memberFive", "/Employees", searchableFields, fieldAnalyzers, mockIndexStats1, true, serverName);
    final LuceneIndexDetails indexDetails2 = createIndexDetails("memberSix", "/Employees", searchableFields, fieldAnalyzers, mockIndexStats2, true, serverName);
    final LuceneIndexDetails indexDetails3 = createIndexDetails("memberTen", "/Employees", searchableFields, fieldAnalyzers, mockIndexStats3, true, serverName);
    final List<Set<LuceneIndexDetails>> results = new ArrayList<>();
    results.add(CollectionUtils.asSet(indexDetails2, indexDetails1, indexDetails3));
    when(mockFunctionExecutor.execute(isA(LuceneListIndexFunction.class))).thenReturn(mockResultCollector);
    when(mockResultCollector.getResult()).thenReturn(results);
    final LuceneIndexCommands commands = createIndexCommands(mockCache, mockFunctionExecutor);
    CommandResult result = (CommandResult) commands.listIndex(true);
    TabularResultData data = (TabularResultData) result.getResultData();
    assertEquals(Arrays.asList("memberFive", "memberSix", "memberTen"), data.retrieveAllValues("Index Name"));
    assertEquals(Arrays.asList("/Employees", "/Employees", "/Employees"), data.retrieveAllValues("Region Path"));
    assertEquals(Arrays.asList("[field1, field2, field3]", "[field1, field2, field3]", "[field1, field2, field3]"), data.retrieveAllValues("Indexed Fields"));
    assertEquals(Arrays.asList("{field1=StandardAnalyzer, field2=KeywordAnalyzer}", "{field1=StandardAnalyzer, field2=KeywordAnalyzer}", "{field1=StandardAnalyzer, field2=KeywordAnalyzer}"), data.retrieveAllValues("Field Analyzer"));
    assertEquals(Arrays.asList("1", "2", "3"), data.retrieveAllValues("Query Executions"));
    assertEquals(Arrays.asList("10", "20", "30"), data.retrieveAllValues("Commits"));
    assertEquals(Arrays.asList("5", "10", "15"), data.retrieveAllValues("Updates"));
    assertEquals(Arrays.asList("1", "2", "3"), data.retrieveAllValues("Documents"));
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) LuceneIndexStats(org.apache.geode.cache.lucene.internal.LuceneIndexStats) Set(java.util.Set) HashSet(java.util.HashSet) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) HashMap(java.util.HashMap) LuceneListIndexFunction(org.apache.geode.cache.lucene.internal.cli.functions.LuceneListIndexFunction) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) Mockito.anyString(org.mockito.Mockito.anyString) KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) ResultCollector(org.apache.geode.cache.execute.ResultCollector) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

AbstractExecution (org.apache.geode.internal.cache.execute.AbstractExecution)19 ArrayList (java.util.ArrayList)11 HashSet (java.util.HashSet)11 Set (java.util.Set)10 Execution (org.apache.geode.cache.execute.Execution)8 ResultCollector (org.apache.geode.cache.execute.ResultCollector)8 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)6 InternalCache (org.apache.geode.internal.cache.InternalCache)6 UnitTest (org.apache.geode.test.junit.categories.UnitTest)6 IOException (java.io.IOException)5 Region (org.apache.geode.cache.Region)5 Function (org.apache.geode.cache.execute.Function)5 FunctionException (org.apache.geode.cache.execute.FunctionException)5 ExecuteFunctionOperationContext (org.apache.geode.cache.operations.ExecuteFunctionOperationContext)5 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)5 InternalFunctionInvocationTargetException (org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException)5 MemberMappedArgument (org.apache.geode.internal.cache.execute.MemberMappedArgument)5 PartitionedRegionFunctionExecutor (org.apache.geode.internal.cache.execute.PartitionedRegionFunctionExecutor)5 ServerToClientFunctionResultSender (org.apache.geode.internal.cache.execute.ServerToClientFunctionResultSender)5 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)5