Search in sources :

Example 81 with Function

use of org.apache.geode.cache.execute.Function in project geode by apache.

the class RollingUpgrade2DUnitTest method doTestVerifyXmlEntity.

private void doTestVerifyXmlEntity(String oldVersion) throws Exception {
    final Host host = Host.getHost(0);
    VM oldLocator = host.getVM(oldVersion, 0);
    VM oldServer = host.getVM(oldVersion, 1);
    VM currentServer1 = host.getVM(2);
    VM currentServer2 = host.getVM(3);
    int[] locatorPorts = AvailablePortHelper.getRandomAvailableTCPPorts(1);
    String hostName = NetworkUtils.getServerHostName(host);
    String locatorsString = getLocatorString(locatorPorts);
    DistributedTestUtils.deleteLocatorStateFile(locatorPorts);
    try {
        // Start locator
        oldLocator.invoke(invokeStartLocator(hostName, locatorPorts[0], getTestMethodName(), getLocatorPropertiesPre91(locatorsString)));
        // Start servers
        invokeRunnableInVMs(invokeCreateCache(getSystemProperties(locatorPorts)), oldServer, currentServer1, currentServer2);
        currentServer1.invoke(invokeAssertVersion(Version.CURRENT_ORDINAL));
        currentServer2.invoke(invokeAssertVersion(Version.CURRENT_ORDINAL));
        // Get DistributedMembers of the servers
        DistributedMember oldServerMember = oldServer.invoke(() -> getDistributedMember());
        DistributedMember currentServer1Member = currentServer1.invoke(() -> getDistributedMember());
        DistributedMember currentServer2Member = currentServer2.invoke(() -> getDistributedMember());
        // Register function in all servers
        Function function = new GetDataSerializableFunction();
        invokeRunnableInVMs(invokeRegisterFunction(function), oldServer, currentServer1, currentServer2);
        // Execute the function in the old server against the other servers to verify the
        // DataSerializable can be serialized from a newer server to an older one.
        oldServer.invoke(() -> executeFunctionAndVerify(function.getId(), "org.apache.geode.management.internal.configuration.domain.XmlEntity", currentServer1Member, currentServer2Member));
        // Execute the function in a new server against the other servers to verify the
        // DataSerializable can be serialized from an older server to a newer one.
        currentServer1.invoke(() -> executeFunctionAndVerify(function.getId(), "org.apache.geode.management.internal.configuration.domain.XmlEntity", oldServerMember, currentServer2Member));
    } finally {
        invokeRunnableInVMs(true, invokeStopLocator(), oldLocator);
        invokeRunnableInVMs(true, invokeCloseCache(), oldServer, currentServer1, currentServer2);
    }
}
Also used : Function(org.apache.geode.cache.execute.Function) VM(org.apache.geode.test.dunit.VM) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) Host(org.apache.geode.test.dunit.Host)

Example 82 with Function

use of org.apache.geode.cache.execute.Function in project geode by apache.

the class GfshCommandJUnitTest method testRegisteredAlready.

@Test
public void testRegisteredAlready() {
    try {
        final Function registeredFunction = mockContext.mock(Function.class, "Registered Function");
        final Function unregisteredFunction = mockContext.mock(Function.class, "Unregistered Function");
        mockContext.checking(new Expectations() {

            {
                exactly(2).of(registeredFunction).getId();
                will(returnValue("testRegisteredAlready"));
                oneOf(registeredFunction).isHA();
                will(returnValue(false));
                exactly(2).of(unregisteredFunction).getId();
                will(returnValue("testRegisteredAlready"));
            }
        });
        final GfshCommand commands = createAbstractCommandsSupport(mockContext.mock(InternalCache.class));
        FunctionService.registerFunction(registeredFunction);
        assertTrue(FunctionService.isRegistered("testRegisteredAlready"));
        assertSame(registeredFunction, commands.register(unregisteredFunction));
        assertTrue(FunctionService.isRegistered("testRegisteredAlready"));
    } finally {
        FunctionService.unregisterFunction("testRegisteredAlready");
    }
}
Also used : Expectations(org.jmock.Expectations) Function(org.apache.geode.cache.execute.Function) InternalCache(org.apache.geode.internal.cache.InternalCache) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 83 with Function

use of org.apache.geode.cache.execute.Function in project geode by apache.

the class DataCommands method executeRebalanceOnDS.

private Result executeRebalanceOnDS(InternalCache cache, String simulate, String[] excludeRegionsList) {
    Result result = null;
    int index = 1;
    CompositeResultData rebalanceResultData = ResultBuilder.createCompositeResultData();
    List<String> listExcludedRegion = new ArrayList<>();
    if (excludeRegionsList != null) {
        Collections.addAll(listExcludedRegion, excludeRegionsList);
    }
    List<MemberPRInfo> listMemberRegion = getMemberRegionList(cache, listExcludedRegion);
    if (listMemberRegion.size() == 0) {
        return ResultBuilder.createInfoResult(CliStrings.REBALANCE__MSG__NO_REBALANCING_REGIONS_ON_DS);
    }
    Iterator<MemberPRInfo> iterator = listMemberRegion.iterator();
    boolean flagToContinueWithRebalance = false;
    // check if list has some members that can be rebalanced
    while (iterator.hasNext()) {
        if (iterator.next().dsMemberList.size() > 1) {
            flagToContinueWithRebalance = true;
            break;
        }
    }
    if (!flagToContinueWithRebalance) {
        return ResultBuilder.createInfoResult(CliStrings.REBALANCE__MSG__NO_REBALANCING_REGIONS_ON_DS);
    }
    for (MemberPRInfo memberPR : listMemberRegion) {
        try {
            // check if there are more than one members associated with region for rebalancing
            if (memberPR.dsMemberList.size() > 1) {
                for (int i = 0; i < memberPR.dsMemberList.size(); i++) {
                    DistributedMember dsMember = memberPR.dsMemberList.get(i);
                    Function rebalanceFunction = new RebalanceFunction();
                    Object[] functionArgs = new Object[3];
                    functionArgs[0] = simulate;
                    Set<String> regionSet = new HashSet<>();
                    regionSet.add(memberPR.region);
                    functionArgs[1] = regionSet;
                    Set<String> excludeRegionSet = new HashSet<>();
                    functionArgs[2] = excludeRegionSet;
                    List resultList = null;
                    try {
                        if (checkMemberPresence(dsMember, cache)) {
                            resultList = (ArrayList) CliUtil.executeFunction(rebalanceFunction, functionArgs, dsMember).getResult();
                            if (checkResultList(rebalanceResultData, resultList, dsMember)) {
                                result = ResultBuilder.buildResult(rebalanceResultData);
                                continue;
                            }
                            List<String> rstList = tokenize((String) resultList.get(0), ",");
                            result = ResultBuilder.buildResult(toCompositeResultData(rebalanceResultData, (ArrayList) rstList, index, simulate.equals("true"), cache));
                            index++;
                            // Rebalancing for region is done so break and continue with other region
                            break;
                        } else {
                            if (i == memberPR.dsMemberList.size() - 1) {
                                rebalanceResultData.addSection().addData(CliStrings.format(CliStrings.REBALANCE__MSG__NO_EXECUTION_FOR_REGION_0_ON_MEMBERS_1, memberPR.region, listOfAllMembers(memberPR.dsMemberList)), CliStrings.REBALANCE__MSG__MEMBERS_MIGHT_BE_DEPARTED);
                                result = ResultBuilder.buildResult(rebalanceResultData);
                            } else {
                                continue;
                            }
                        }
                    } catch (Exception ex) {
                        if (i == memberPR.dsMemberList.size() - 1) {
                            rebalanceResultData.addSection().addData(CliStrings.format(CliStrings.REBALANCE__MSG__NO_EXECUTION_FOR_REGION_0_ON_MEMBERS_1, memberPR.region, listOfAllMembers(memberPR.dsMemberList)), CliStrings.REBALANCE__MSG__REASON + ex.getMessage());
                            result = ResultBuilder.buildResult(rebalanceResultData);
                        } else {
                            continue;
                        }
                    }
                    if (checkResultList(rebalanceResultData, resultList, dsMember)) {
                        result = ResultBuilder.buildResult(rebalanceResultData);
                        continue;
                    }
                    List<String> rstList = tokenize((String) resultList.get(0), ",");
                    result = ResultBuilder.buildResult(toCompositeResultData(rebalanceResultData, (ArrayList) rstList, index, simulate.equals("true"), cache));
                    index++;
                }
            }
        } catch (Exception e) {
            ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
            return (ResultBuilder.buildResult(errorResultData));
        }
    }
    return result;
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) ArrayList(java.util.ArrayList) RebalanceFunction(org.apache.geode.management.internal.cli.functions.RebalanceFunction) ConverterHint(org.apache.geode.management.cli.ConverterHint) TimeoutException(java.util.concurrent.TimeoutException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) CacheClosedException(org.apache.geode.cache.CacheClosedException) Result(org.apache.geode.management.cli.Result) DataCommandResult(org.apache.geode.management.internal.cli.domain.DataCommandResult) Function(org.apache.geode.cache.execute.Function) DataCommandFunction(org.apache.geode.management.internal.cli.functions.DataCommandFunction) ExportDataFunction(org.apache.geode.management.internal.cli.functions.ExportDataFunction) ImportDataFunction(org.apache.geode.management.internal.cli.functions.ImportDataFunction) RebalanceFunction(org.apache.geode.management.internal.cli.functions.RebalanceFunction) DistributedMember(org.apache.geode.distributed.DistributedMember) List(java.util.List) ArrayList(java.util.ArrayList) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) HashSet(java.util.HashSet)

Example 84 with Function

use of org.apache.geode.cache.execute.Function in project geode by apache.

the class FunctionCommands method executeFunction.

@CliCommand(value = CliStrings.EXECUTE_FUNCTION, help = CliStrings.EXECUTE_FUNCTION__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_FUNCTION })
@ResourceOperation(resource = Resource.DATA, operation = Operation.WRITE)
public Result executeFunction(// TODO: Add optioncontext for functionID
@CliOption(key = CliStrings.EXECUTE_FUNCTION__ID, mandatory = true, help = CliStrings.EXECUTE_FUNCTION__ID__HELP) String functionId, @CliOption(key = CliStrings.EXECUTE_FUNCTION__ONGROUPS, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.EXECUTE_FUNCTION__ONGROUPS__HELP) String[] onGroups, @CliOption(key = CliStrings.EXECUTE_FUNCTION__ONMEMBER, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.EXECUTE_FUNCTION__ONMEMBER__HELP) String onMember, @CliOption(key = CliStrings.EXECUTE_FUNCTION__ONREGION, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.REGION_PATH, help = CliStrings.EXECUTE_FUNCTION__ONREGION__HELP) String onRegion, @CliOption(key = CliStrings.EXECUTE_FUNCTION__ARGUMENTS, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.EXECUTE_FUNCTION__ARGUMENTS__HELP) String[] arguments, @CliOption(key = CliStrings.EXECUTE_FUNCTION__RESULTCOLLECTOR, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.EXECUTE_FUNCTION__RESULTCOLLECTOR__HELP) String resultCollector, @CliOption(key = CliStrings.EXECUTE_FUNCTION__FILTER, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.EXECUTE_FUNCTION__FILTER__HELP) String filterString) {
    Result result = null;
    CompositeResultData executeFunctionResultTable = ResultBuilder.createCompositeResultData();
    TabularResultData resultTable = executeFunctionResultTable.addSection().addTable("Table1");
    String headerText = "Execution summary";
    resultTable.setHeader(headerText);
    ResultCollector resultCollectorInstance = null;
    Function function;
    Set<String> filters = new HashSet<String>();
    Execution execution = null;
    if (functionId != null) {
        functionId = functionId.trim();
    }
    if (onRegion != null) {
        onRegion = onRegion.trim();
    }
    if (onMember != null) {
        onMember = onMember.trim();
    }
    if (filterString != null) {
        filterString = filterString.trim();
    }
    try {
        // validate otherwise return right away. no need to process anything
        if (functionId == null || functionId.length() == 0) {
            ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__MISSING_FUNCTIONID);
            result = ResultBuilder.buildResult(errorResultData);
            return result;
        }
        if (onRegion != null && onMember != null && onGroups != null) {
            ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__OPTIONS);
            result = ResultBuilder.buildResult(errorResultData);
            return result;
        } else if (onRegion != null && onMember != null) {
            ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__OPTIONS);
            result = ResultBuilder.buildResult(errorResultData);
            return result;
        } else if (onMember != null && onGroups != null) {
            ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__OPTIONS);
            result = ResultBuilder.buildResult(errorResultData);
            return result;
        } else if (onRegion != null && onGroups != null) {
            ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__OPTIONS);
            result = ResultBuilder.buildResult(errorResultData);
            return result;
        } else if (onRegion != null && onMember != null && onGroups != null) {
            ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__OPTIONS);
            result = ResultBuilder.buildResult(errorResultData);
            return result;
        } else if ((onRegion == null || onRegion.length() == 0) && (filterString != null)) {
            ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__MEMBER_SHOULD_NOT_HAVE_FILTER_FOR_EXECUTION);
            result = ResultBuilder.buildResult(errorResultData);
            return result;
        }
        InternalCache cache = getCache();
        if (resultCollector != null) {
            resultCollectorInstance = (ResultCollector) ClassPathLoader.getLatest().forName(resultCollector).newInstance();
        }
        if (filterString != null && filterString.length() > 0) {
            filters.add(filterString);
        }
        if (onRegion == null && onMember == null && onGroups == null) {
            // run function on all the members excluding locators bug#46113
            // if user wish to execute on locator then he can choose --member or --group option
            Set<DistributedMember> dsMembers = CliUtil.getAllNormalMembers(cache);
            if (dsMembers.size() > 0) {
                function = new UserFunctionExecution();
                LogWrapper.getInstance().info(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__EXECUTING_0_ON_ENTIRE_DS, functionId));
                for (DistributedMember member : dsMembers) {
                    executeAndGetResults(functionId, filterString, resultCollector, arguments, cache, member, resultTable, onRegion);
                }
                return ResultBuilder.buildResult(resultTable);
            } else {
                return ResultBuilder.createUserErrorResult(CliStrings.EXECUTE_FUNCTION__MSG__DS_HAS_NO_MEMBERS);
            }
        } else if (onRegion != null && onRegion.length() > 0) {
            if (cache.getRegion(onRegion) == null) {
                // find a member where region is present
                DistributedRegionMXBean bean = ManagementService.getManagementService(getCache()).getDistributedRegionMXBean(onRegion);
                if (bean == null) {
                    bean = ManagementService.getManagementService(getCache()).getDistributedRegionMXBean(Region.SEPARATOR + onRegion);
                    if (bean == null) {
                        return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__MXBEAN_0_FOR_NOT_FOUND, onRegion));
                    }
                }
                DistributedMember member = null;
                String[] membersName = bean.getMembers();
                Set<DistributedMember> dsMembers = CliUtil.getAllMembers(cache);
                Iterator it = dsMembers.iterator();
                boolean matchFound = false;
                if (membersName.length > 0) {
                    while (it.hasNext() && matchFound == false) {
                        DistributedMember dsmember = (DistributedMember) it.next();
                        for (String memberName : membersName) {
                            if (MBeanJMXAdapter.getMemberNameOrId(dsmember).equals(memberName)) {
                                member = dsmember;
                                matchFound = true;
                                break;
                            }
                        }
                    }
                }
                if (matchFound == true) {
                    executeAndGetResults(functionId, filterString, resultCollector, arguments, cache, member, resultTable, onRegion);
                    return ResultBuilder.buildResult(resultTable);
                } else {
                    return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__NO_ASSOCIATED_MEMBER_REGION, " " + onRegion));
                }
            } else {
                execution = FunctionService.onRegion(cache.getRegion(onRegion));
                if (execution != null) {
                    if (resultCollectorInstance != null) {
                        execution = execution.withCollector(resultCollectorInstance);
                    }
                    if (filters != null && filters.size() > 0) {
                        execution = execution.withFilter(filters);
                    }
                    if (arguments != null && arguments.length > 0) {
                        execution = execution.setArguments(arguments);
                    }
                    try {
                        List<Object> results = (List<Object>) execution.execute(functionId).getResult();
                        if (results.size() > 0) {
                            StringBuilder strResult = new StringBuilder();
                            for (Object obj : results) {
                                strResult.append(obj);
                            }
                            toTabularResultData(resultTable, cache.getDistributedSystem().getDistributedMember().getId(), strResult.toString());
                        }
                        return ResultBuilder.buildResult(resultTable);
                    } catch (FunctionException e) {
                        return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__ERROR_IN_EXECUTING_0_ON_REGION_1_DETAILS_2, functionId, onRegion, e.getMessage()));
                    }
                } else {
                    return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__ERROR_IN_EXECUTING_0_ON_REGION_1_DETAILS_2, functionId, onRegion, CliStrings.EXECUTE_FUNCTION__MSG__ERROR_IN_RETRIEVING_EXECUTOR));
                }
            }
        } else if (onGroups != null) {
            // execute on group members
            Set<DistributedMember> dsMembers = new HashSet<DistributedMember>();
            for (String grp : onGroups) {
                dsMembers.addAll(cache.getDistributedSystem().getGroupMembers(grp));
            }
            StringBuilder successMessage = new StringBuilder();
            if (dsMembers.size() > 0) {
                for (DistributedMember member : dsMembers) {
                    executeAndGetResults(functionId, filterString, resultCollector, arguments, cache, member, resultTable, onRegion);
                }
                return ResultBuilder.buildResult(resultTable);
            } else {
                StringBuilder grps = new StringBuilder();
                for (String grp : onGroups) {
                    grps.append(grp);
                    grps.append(", ");
                }
                return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__GROUPS_0_HAS_NO_MEMBERS, grps.toString().substring(0, grps.toString().length() - 1)));
            }
        } else if (onMember != null && onMember.length() > 0) {
            // fix for bug
            DistributedMember member = CliUtil.getDistributedMemberByNameOrId(onMember);
            // 45658
            if (member != null) {
                executeAndGetResults(functionId, filterString, resultCollector, arguments, cache, member, resultTable, onRegion);
            } else {
                toTabularResultData(resultTable, onMember, CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__NO_ASSOCIATED_MEMBER + " " + onMember));
            }
            return ResultBuilder.buildResult(resultTable);
        }
    } catch (InstantiationException e) {
        ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
        result = ResultBuilder.buildResult(errorResultData);
        return result;
    } catch (IllegalAccessException e) {
        ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
        result = ResultBuilder.buildResult(errorResultData);
        return result;
    } catch (IllegalArgumentException e) {
        ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
        result = ResultBuilder.buildResult(errorResultData);
        return result;
    } catch (SecurityException e) {
        ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
        result = ResultBuilder.buildResult(errorResultData);
        return result;
    } catch (Exception e) {
        ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
        result = ResultBuilder.buildResult(errorResultData);
        return result;
    }
    return result;
}
Also used : UserFunctionExecution(org.apache.geode.management.internal.cli.functions.UserFunctionExecution) CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) HashSet(java.util.HashSet) Set(java.util.Set) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) InternalCache(org.apache.geode.internal.cache.InternalCache) GfshParseResult(org.apache.geode.management.internal.cli.GfshParseResult) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) Function(org.apache.geode.cache.execute.Function) ListFunctionFunction(org.apache.geode.management.internal.cli.functions.ListFunctionFunction) UnregisterFunction(org.apache.geode.management.internal.cli.functions.UnregisterFunction) UserFunctionExecution(org.apache.geode.management.internal.cli.functions.UserFunctionExecution) Execution(org.apache.geode.cache.execute.Execution) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet) FunctionException(org.apache.geode.cache.execute.FunctionException) DistributedRegionMXBean(org.apache.geode.management.DistributedRegionMXBean) FunctionException(org.apache.geode.cache.execute.FunctionException) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) DistributedMember(org.apache.geode.distributed.DistributedMember) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 85 with Function

use of org.apache.geode.cache.execute.Function in project geode by apache.

the class MiscellaneousCommands method shutdownNode.

public void shutdownNode(final long timeout, final Set<DistributedMember> includeMembers) throws TimeoutException, InterruptedException, ExecutionException {
    ExecutorService exec = Executors.newSingleThreadExecutor();
    try {
        final Function shutDownFunction = new ShutDownFunction();
        logger.info("Gfsh executing shutdown on members " + includeMembers);
        Callable<String> shutdownNodes = new Callable<String>() {

            @Override
            public String call() {
                try {
                    Execution execution = FunctionService.onMembers(includeMembers);
                    execution.execute(shutDownFunction);
                } catch (FunctionException functionEx) {
                // Expected Exception as the function is shutting down the target members and the result
                // collector will get member departed exception
                }
                return "SUCCESS";
            }
        };
        Future<String> result = exec.submit(shutdownNodes);
        result.get(timeout, TimeUnit.MILLISECONDS);
    } catch (TimeoutException te) {
        logger.error("TimeoutException in shutting down members." + includeMembers);
        throw te;
    } catch (InterruptedException e) {
        logger.error("InterruptedException in shutting down members." + includeMembers);
        throw e;
    } catch (ExecutionException e) {
        logger.error("ExecutionException in shutting down members." + includeMembers);
        throw e;
    } finally {
        exec.shutdownNow();
    }
}
Also used : ChangeLogLevelFunction(org.apache.geode.management.internal.cli.functions.ChangeLogLevelFunction) Function(org.apache.geode.cache.execute.Function) NetstatFunction(org.apache.geode.management.internal.cli.functions.NetstatFunction) ShutDownFunction(org.apache.geode.management.internal.cli.functions.ShutDownFunction) GarbageCollectionFunction(org.apache.geode.management.internal.cli.functions.GarbageCollectionFunction) GetStackTracesFunction(org.apache.geode.management.internal.cli.functions.GetStackTracesFunction) Execution(org.apache.geode.cache.execute.Execution) ShutDownFunction(org.apache.geode.management.internal.cli.functions.ShutDownFunction) ExecutorService(java.util.concurrent.ExecutorService) FunctionException(org.apache.geode.cache.execute.FunctionException) ExecutionException(java.util.concurrent.ExecutionException) Callable(java.util.concurrent.Callable) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

Function (org.apache.geode.cache.execute.Function)261 TestFunction (org.apache.geode.internal.cache.functions.TestFunction)204 Test (org.junit.Test)156 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)148 HashSet (java.util.HashSet)124 FunctionException (org.apache.geode.cache.execute.FunctionException)122 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)122 Execution (org.apache.geode.cache.execute.Execution)121 ArrayList (java.util.ArrayList)110 ResultCollector (org.apache.geode.cache.execute.ResultCollector)110 List (java.util.List)86 Region (org.apache.geode.cache.Region)83 IgnoredException (org.apache.geode.test.dunit.IgnoredException)75 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)74 Iterator (java.util.Iterator)68 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)67 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)63 VM (org.apache.geode.test.dunit.VM)62 Host (org.apache.geode.test.dunit.Host)61 AttributesFactory (org.apache.geode.cache.AttributesFactory)56