Search in sources :

Example 36 with CompositeResultData

use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.

the class CLIMultiStepHelper method getNextStep.

public static String getNextStep(Result cdata) {
    CommandResult cResult = (CommandResult) cdata;
    if (ResultData.TYPE_COMPOSITE.equals(cResult.getType())) {
        CompositeResultData rd = (CompositeResultData) cResult.getResultData();
        SectionResultData section = rd.retrieveSection(CLIMultiStepHelper.STEP_SECTION);
        String nextStep = (String) section.retrieveObject(CLIMultiStepHelper.NEXT_STEP_NAME);
        return nextStep;
    } else {
        if (ResultData.TYPE_ERROR.equals(cResult.getType())) {
            throw new CLIStepExecption(cResult);
        } else {
            throw new RuntimeException("Step returned result of type other than " + ResultData.TYPE_COMPOSITE + " Type " + cResult.getType());
        }
    }
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult)

Example 37 with CompositeResultData

use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.

the class CLIMultiStepHelper method extractArgumentsForNextStep.

public static SectionResultData extractArgumentsForNextStep(Result result) {
    CommandResult cResult = (CommandResult) result;
    if (ResultData.TYPE_COMPOSITE.equals(cResult.getType())) {
        CompositeResultData rd = (CompositeResultData) cResult.getResultData();
        SectionResultData data = rd.retrieveSection(CLIMultiStepHelper.ARG_SECTION);
        return data;
    } else {
        if (ResultData.TYPE_ERROR.equals(cResult.getType())) {
            throw new CLIStepExecption(cResult);
        } else {
            throw new StepExecutionException("Step returned result of type other than " + ResultData.TYPE_COMPOSITE + " Type " + cResult.getType());
        }
    }
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult)

Example 38 with CompositeResultData

use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.

the class WanCommands method listGateway.

@CliCommand(value = CliStrings.LIST_GATEWAY, help = CliStrings.LIST_GATEWAY__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result listGateway(@CliOption(key = CliStrings.LIST_GATEWAY__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.LIST_GATEWAY__MEMBER__HELP) String[] onMember, @CliOption(key = CliStrings.LIST_GATEWAY__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.LIST_GATEWAY__GROUP__HELP) String[] onGroup) {
    Result result = null;
    InternalCache cache = getCache();
    try {
        SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
        Set<DistributedMember> dsMembers = CliUtil.findMembers(onGroup, onMember);
        if (dsMembers.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        Map<String, Map<String, GatewaySenderMXBean>> gatewaySenderBeans = new TreeMap<String, Map<String, GatewaySenderMXBean>>();
        Map<String, GatewayReceiverMXBean> gatewayReceiverBeans = new TreeMap<String, GatewayReceiverMXBean>();
        DistributedSystemMXBean dsMXBean = service.getDistributedSystemMXBean();
        for (DistributedMember member : dsMembers) {
            String memberName = member.getName();
            String memberNameOrId = (memberName != null && !memberName.isEmpty()) ? memberName : member.getId();
            ObjectName[] gatewaySenderObjectNames = dsMXBean.listGatewaySenderObjectNames(memberNameOrId);
            // on it
            if (gatewaySenderObjectNames != null) {
                for (ObjectName name : gatewaySenderObjectNames) {
                    GatewaySenderMXBean senderBean = service.getMBeanProxy(name, GatewaySenderMXBean.class);
                    if (senderBean != null) {
                        if (gatewaySenderBeans.containsKey(senderBean.getSenderId())) {
                            Map<String, GatewaySenderMXBean> memberToBeanMap = gatewaySenderBeans.get(senderBean.getSenderId());
                            memberToBeanMap.put(member.getId(), senderBean);
                        } else {
                            Map<String, GatewaySenderMXBean> memberToBeanMap = new TreeMap<String, GatewaySenderMXBean>();
                            memberToBeanMap.put(member.getId(), senderBean);
                            gatewaySenderBeans.put(senderBean.getSenderId(), memberToBeanMap);
                        }
                    }
                }
            }
            // gateway receivers : a member can have only one gateway receiver
            ObjectName gatewayReceiverObjectName = MBeanJMXAdapter.getGatewayReceiverMBeanName(member);
            if (gatewayReceiverObjectName != null) {
                GatewayReceiverMXBean receieverBean = null;
                receieverBean = service.getMBeanProxy(gatewayReceiverObjectName, GatewayReceiverMXBean.class);
                if (receieverBean != null) {
                    gatewayReceiverBeans.put(member.getId(), receieverBean);
                }
            }
        }
        if (gatewaySenderBeans.isEmpty() && gatewayReceiverBeans.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.GATEWAYS_ARE_NOT_AVAILABLE_IN_CLUSTER);
        }
        CompositeResultData crd = ResultBuilder.createCompositeResultData();
        crd.setHeader(CliStrings.HEADER_GATEWAYS);
        accumulateListGatewayResult(crd, gatewaySenderBeans, gatewayReceiverBeans);
        result = ResultBuilder.buildResult(crd);
    } catch (Exception e) {
        LogWrapper.getInstance().warning(CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(e));
        result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR + e.getMessage());
    }
    return result;
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) InternalCache(org.apache.geode.internal.cache.InternalCache) TreeMap(java.util.TreeMap) GatewaySenderMXBean(org.apache.geode.management.GatewaySenderMXBean) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) ExecutionException(java.util.concurrent.ExecutionException) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) ObjectName(javax.management.ObjectName) GatewayReceiverMXBean(org.apache.geode.management.GatewayReceiverMXBean) DistributedSystemMXBean(org.apache.geode.management.DistributedSystemMXBean) DistributedMember(org.apache.geode.distributed.DistributedMember) Map(java.util.Map) TreeMap(java.util.TreeMap) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 39 with CompositeResultData

use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.

the class DataCommandResult method toSelectCommandResult.

/**
   * This method returns result when flag interactive=false i.e. Command returns result in one go
   * and does not goes through steps waiting for user input. Method returns CompositeResultData
   * instead of Result as Command Step is required to add NEXT_STEP information to guide
   * executionStragey to route it through final step.
   */
public CompositeResultData toSelectCommandResult() {
    if (errorString != null) {
        // return ResultBuilder.createGemFireErrorResult(errorString);
        CompositeResultData data = ResultBuilder.createCompositeResultData();
        SectionResultData section = data.addSection();
        section.addData("Message", errorString);
        section.addData(RESULT_FLAG, operationCompletedSuccessfully);
        return data;
    } else {
        CompositeResultData data = ResultBuilder.createCompositeResultData();
        SectionResultData section = data.addSection();
        TabularResultData table = section.addTable();
        section.addData(RESULT_FLAG, operationCompletedSuccessfully);
        if (infoString != null) {
            section.addData("Message", infoString);
        }
        if (inputQuery != null) {
            if (this.limit != -1) {
                section.addData("Limit", this.limit);
            }
            if (this.selectResult != null) {
                section.addData(NUM_ROWS, this.selectResult.size());
                if (this.queryTraceString != null) {
                    section.addData("Query Trace", this.queryTraceString);
                }
                buildTable(table, 0, selectResult.size());
            }
        }
        return data;
    }
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)

Example 40 with CompositeResultData

use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.

the class MiscellaneousCommands method changeLogLevel.

@CliCommand(value = CliStrings.CHANGE_LOGLEVEL, help = CliStrings.CHANGE_LOGLEVEL__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_LOGS }, interceptor = "org.apache.geode.management.internal.cli.commands.MiscellaneousCommands$ChangeLogLevelInterceptor")
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.WRITE)
public Result changeLogLevel(@CliOption(key = CliStrings.CHANGE_LOGLEVEL__MEMBER, help = CliStrings.CHANGE_LOGLEVEL__MEMBER__HELP) String[] memberIds, @CliOption(key = CliStrings.CHANGE_LOGLEVEL__GROUPS, unspecifiedDefaultValue = "", help = CliStrings.CHANGE_LOGLEVEL__GROUPS__HELP) String[] grps, @CliOption(key = CliStrings.CHANGE_LOGLEVEL__LOGLEVEL, optionContext = ConverterHint.LOG_LEVEL, mandatory = true, unspecifiedDefaultValue = "", help = CliStrings.CHANGE_LOGLEVEL__LOGLEVEL__HELP) String logLevel) {
    try {
        if ((memberIds == null || memberIds.length == 0) && (grps == null || grps.length == 0)) {
            return ResultBuilder.createUserErrorResult(CliStrings.CHANGE_LOGLEVEL__MSG__SPECIFY_GRP_OR_MEMBER);
        }
        InternalCache cache = GemFireCacheImpl.getInstance();
        LogWriter logger = cache.getLogger();
        Set<DistributedMember> dsMembers = new HashSet<DistributedMember>();
        Set<DistributedMember> ds = CliUtil.getAllMembers(cache);
        if (grps != null && grps.length > 0) {
            for (String grp : grps) {
                dsMembers.addAll(cache.getDistributedSystem().getGroupMembers(grp));
            }
        }
        if (memberIds != null && memberIds.length > 0) {
            for (String member : memberIds) {
                Iterator<DistributedMember> it = ds.iterator();
                while (it.hasNext()) {
                    DistributedMember mem = it.next();
                    if (mem.getName() == null ? false : mem.getName().equals(member) || mem.getId().equals(member)) {
                        dsMembers.add(mem);
                        break;
                    }
                }
            }
        }
        if (dsMembers.size() == 0) {
            return ResultBuilder.createGemFireErrorResult(CliStrings.CHANGE_LOGLEVEL__MSG_NO_MEMBERS);
        }
        Function logFunction = new ChangeLogLevelFunction();
        FunctionService.registerFunction(logFunction);
        Object[] functionArgs = new Object[1];
        functionArgs[0] = logLevel;
        CompositeResultData compositeResultData = ResultBuilder.createCompositeResultData();
        SectionResultData section = compositeResultData.addSection("section");
        TabularResultData resultTable = section.addTable("ChangeLogLevel");
        resultTable = resultTable.setHeader("Summary");
        Execution execution = FunctionService.onMembers(dsMembers).setArguments(functionArgs);
        if (execution == null) {
            return ResultBuilder.createUserErrorResult(CliStrings.CHANGE_LOGLEVEL__MSG__CANNOT_EXECUTE);
        }
        List<?> resultList = (List<?>) execution.execute(logFunction).getResult();
        for (Object object : resultList) {
            try {
                if (object instanceof Throwable) {
                    logger.warning("Exception in ChangeLogLevelFunction " + ((Throwable) object).getMessage(), ((Throwable) object));
                    continue;
                }
                if (object != null) {
                    Map<String, String> resultMap = (Map<String, String>) object;
                    Entry<String, String> entry = resultMap.entrySet().iterator().next();
                    if (entry.getValue().contains("ChangeLogLevelFunction exception")) {
                        resultTable.accumulate(CliStrings.CHANGE_LOGLEVEL__COLUMN_MEMBER, entry.getKey());
                        resultTable.accumulate(CliStrings.CHANGE_LOGLEVEL__COLUMN_STATUS, "false");
                    } else {
                        resultTable.accumulate(CliStrings.CHANGE_LOGLEVEL__COLUMN_MEMBER, entry.getKey());
                        resultTable.accumulate(CliStrings.CHANGE_LOGLEVEL__COLUMN_STATUS, "true");
                    }
                }
            } catch (Exception ex) {
                LogWrapper.getInstance().warning("change log level command exception " + ex);
                continue;
            }
        }
        Result result = ResultBuilder.buildResult(compositeResultData);
        logger.info("change log-level command result=" + result);
        return result;
    } catch (Exception ex) {
        GemFireCacheImpl.getInstance().getLogger().error("GFSH Changeloglevel exception: " + ex);
        return ResultBuilder.createUserErrorResult(ex.getMessage());
    }
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) InternalCache(org.apache.geode.internal.cache.InternalCache) TimeoutException(java.util.concurrent.TimeoutException) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) ResultDataException(org.apache.geode.management.internal.cli.result.ResultDataException) FunctionException(org.apache.geode.cache.execute.FunctionException) DataFormatException(java.util.zip.DataFormatException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) GfshParseResult(org.apache.geode.management.internal.cli.GfshParseResult) Result(org.apache.geode.management.cli.Result) NetstatFunctionResult(org.apache.geode.management.internal.cli.functions.NetstatFunction.NetstatFunctionResult) ChangeLogLevelFunction(org.apache.geode.management.internal.cli.functions.ChangeLogLevelFunction) 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) LogWriter(org.apache.geode.LogWriter) DistributedMember(org.apache.geode.distributed.DistributedMember) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Aggregations

CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)49 SectionResultData (org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)39 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)30 DistributedMember (org.apache.geode.distributed.DistributedMember)15 InternalCache (org.apache.geode.internal.cache.InternalCache)14 Result (org.apache.geode.management.cli.Result)14 CliMetaData (org.apache.geode.management.cli.CliMetaData)13 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)13 CliCommand (org.springframework.shell.core.annotation.CliCommand)13 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)12 HashSet (java.util.HashSet)10 ArrayList (java.util.ArrayList)9 ObjectName (javax.management.ObjectName)9 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)9 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)8 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)8 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)8 Test (org.junit.Test)8 List (java.util.List)6 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)6