Search in sources :

Example 51 with ResourceOperation

use of org.apache.geode.management.internal.security.ResourceOperation 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)

Example 52 with ResourceOperation

use of org.apache.geode.management.internal.security.ResourceOperation in project geode by apache.

the class MiscellaneousCommands method shutdown.

@CliCommand(value = CliStrings.SHUTDOWN, help = CliStrings.SHUTDOWN__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_LIFECYCLE }, interceptor = "org.apache.geode.management.internal.cli.commands.MiscellaneousCommands$Interceptor")
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE)
public Result shutdown(@CliOption(key = CliStrings.SHUTDOWN__TIMEOUT, unspecifiedDefaultValue = DEFAULT_TIME_OUT, help = CliStrings.SHUTDOWN__TIMEOUT__HELP) int userSpecifiedTimeout, @CliOption(key = CliStrings.INCLUDE_LOCATORS, unspecifiedDefaultValue = "false", help = CliStrings.INCLUDE_LOCATORS_HELP) boolean shutdownLocators) {
    try {
        if (userSpecifiedTimeout < Integer.parseInt(DEFAULT_TIME_OUT)) {
            return ResultBuilder.createInfoResult(CliStrings.SHUTDOWN__MSG__IMPROPER_TIMEOUT);
        }
        // convert to mili-seconds
        long timeout = userSpecifiedTimeout * 1000;
        InternalCache cache = getCache();
        int numDataNodes = CliUtil.getAllNormalMembers(cache).size();
        Set<DistributedMember> locators = CliUtil.getAllMembers(cache);
        Set<DistributedMember> dataNodes = CliUtil.getAllNormalMembers(cache);
        locators.removeAll(dataNodes);
        if (!shutdownLocators && numDataNodes == 0) {
            return ResultBuilder.createInfoResult(CliStrings.SHUTDOWN__MSG__NO_DATA_NODE_FOUND);
        }
        String managerName = cache.getJmxManagerAdvisor().getDistributionManager().getId().getId();
        final DistributedMember manager = CliUtil.getDistributedMemberByNameOrId(managerName);
        dataNodes.remove(manager);
        // shut down all data members excluding this manager if manager is a data node
        long timeElapsed = shutDownNodeWithTimeOut(timeout, dataNodes);
        timeout = timeout - timeElapsed;
        // shut down locators one by one
        if (shutdownLocators) {
            if (manager == null) {
                return ResultBuilder.createUserErrorResult(CliStrings.SHUTDOWN__MSG__MANAGER_NOT_FOUND);
            }
            // remove current locator as that would get shutdown last
            if (locators.contains(manager)) {
                locators.remove(manager);
            }
            for (DistributedMember locator : locators) {
                Set<DistributedMember> lsSet = new HashSet<DistributedMember>();
                lsSet.add(locator);
                long elapsedTime = shutDownNodeWithTimeOut(timeout, lsSet);
                timeout = timeout - elapsedTime;
            }
        }
        if (locators.contains(manager) && !shutdownLocators) {
            // should not stop the manager
            return ResultBuilder.createInfoResult("Shutdown is triggered");
        }
        // now shut down this manager
        Set<DistributedMember> mgrSet = new HashSet<DistributedMember>();
        mgrSet.add(manager);
        // No need to check further timeout as this is the last node we will be
        // shutting down
        shutDownNodeWithTimeOut(timeout, mgrSet);
    } catch (TimeoutException tex) {
        return ResultBuilder.createInfoResult(CliStrings.SHUTDOWN_TIMEDOUT);
    } catch (Exception ex) {
        ex.printStackTrace();
        return ResultBuilder.createUserErrorResult(ex.getMessage());
    }
    // @TODO. List all the nodes which could be successfully shutdown
    return ResultBuilder.createInfoResult("Shutdown is triggered");
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) ConverterHint(org.apache.geode.management.cli.ConverterHint) 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) HashSet(java.util.HashSet) TimeoutException(java.util.concurrent.TimeoutException) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 53 with ResourceOperation

use of org.apache.geode.management.internal.security.ResourceOperation in project geode by apache.

the class MiscellaneousCommands method showDeadlock.

@CliCommand(value = CliStrings.SHOW_DEADLOCK, help = CliStrings.SHOW_DEADLOCK__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_DEBUG_UTIL })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result showDeadlock(@CliOption(key = CliStrings.SHOW_DEADLOCK__DEPENDENCIES__FILE, help = CliStrings.SHOW_DEADLOCK__DEPENDENCIES__FILE__HELP, mandatory = true) String filename) {
    Result result = null;
    try {
        if (!filename.endsWith(".txt")) {
            return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.INVALID_FILE_EXTENSION, ".txt"));
        }
        InternalCache cache = getCache();
        Set<DistributedMember> allMembers = CliUtil.getAllMembers(cache);
        GemFireDeadlockDetector gfeDeadLockDetector = new GemFireDeadlockDetector(allMembers);
        DependencyGraph dependencyGraph = gfeDeadLockDetector.find();
        Collection<Dependency> deadlock = dependencyGraph.findCycle();
        DependencyGraph deepest = null;
        if (deadlock == null) {
            deepest = dependencyGraph.findLongestCallChain();
            if (deepest != null) {
                deadlock = deepest.getEdges();
            }
        }
        Set<Dependency> dependencies = (Set<Dependency>) dependencyGraph.getEdges();
        InfoResultData resultData = ResultBuilder.createInfoResultData();
        if (deadlock != null) {
            if (deepest != null) {
                resultData.addLine(CliStrings.SHOW_DEADLOCK__DEEPEST_FOUND);
            } else {
                resultData.addLine(CliStrings.SHOW_DEADLOCK__DEADLOCK__DETECTED);
            }
            resultData.addLine(DeadlockDetector.prettyFormat(deadlock));
        } else {
            resultData.addLine(CliStrings.SHOW_DEADLOCK__NO__DEADLOCK);
        }
        resultData.addAsFile(filename, DeadlockDetector.prettyFormat(dependencies), MessageFormat.format(CliStrings.SHOW_DEADLOCK__DEPENDENCIES__REVIEW, filename), false);
        result = ResultBuilder.buildResult(resultData);
    } catch (Exception e) {
        result = ResultBuilder.createGemFireErrorResult(CliStrings.SHOW_DEADLOCK__ERROR + " : " + e.getMessage());
    }
    return result;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) GemFireDeadlockDetector(org.apache.geode.distributed.internal.deadlock.GemFireDeadlockDetector) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) DependencyGraph(org.apache.geode.distributed.internal.deadlock.DependencyGraph) Dependency(org.apache.geode.distributed.internal.deadlock.Dependency) 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) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 54 with ResourceOperation

use of org.apache.geode.management.internal.security.ResourceOperation in project geode by apache.

the class MiscellaneousCommands method showLog.

@CliCommand(value = CliStrings.SHOW_LOG, help = CliStrings.SHOW_LOG_HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_DEBUG_UTIL })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result showLog(@CliOption(key = CliStrings.SHOW_LOG_MEMBER, optionContext = ConverterHint.ALL_MEMBER_IDNAME, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.SHOW_LOG_MEMBER_HELP, mandatory = true) String memberNameOrId, @CliOption(key = CliStrings.SHOW_LOG_LINE_NUM, unspecifiedDefaultValue = "0", help = CliStrings.SHOW_LOG_LINE_NUM_HELP, mandatory = false) int numberOfLines) {
    Result result = null;
    try {
        InternalCache cache = getCache();
        SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
        MemberMXBean bean = null;
        DistributedMember memberToBeInvoked = CliUtil.getDistributedMemberByNameOrId(memberNameOrId);
        if (memberToBeInvoked != null) {
            String memberId = memberToBeInvoked.getId();
            if (cache.getDistributedSystem().getDistributedMember().getId().equals(memberId)) {
                bean = service.getMemberMXBean();
            } else {
                ObjectName objectName = service.getMemberMBeanName(memberToBeInvoked);
                bean = service.getMBeanProxy(objectName, MemberMXBean.class);
            }
            if (numberOfLines > ManagementConstants.MAX_SHOW_LOG_LINES) {
                numberOfLines = ManagementConstants.MAX_SHOW_LOG_LINES;
            }
            if (numberOfLines == 0 || numberOfLines < 0) {
                numberOfLines = ManagementConstants.DEFAULT_SHOW_LOG_LINES;
            }
            InfoResultData resultData = ResultBuilder.createInfoResultData();
            if (bean != null) {
                String log = bean.showLog(numberOfLines);
                if (log != null) {
                    resultData.addLine(log);
                } else {
                    resultData.addLine(CliStrings.SHOW_LOG_NO_LOG);
                }
            } else {
                ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(memberNameOrId + CliStrings.SHOW_LOG_MSG_MEMBER_NOT_FOUND);
                return (ResultBuilder.buildResult(errorResultData));
            }
            result = ResultBuilder.buildResult(resultData);
        } else {
            ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(memberNameOrId + CliStrings.SHOW_LOG_MSG_MEMBER_NOT_FOUND);
            return (ResultBuilder.buildResult(errorResultData));
        }
    } catch (Exception e) {
        result = ResultBuilder.createGemFireErrorResult(CliStrings.SHOW_LOG_ERROR + CliUtil.stackTraceAsString(e));
    }
    return result;
}
Also used : InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) 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) MemberMXBean(org.apache.geode.management.MemberMXBean) ObjectName(javax.management.ObjectName) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 55 with ResourceOperation

use of org.apache.geode.management.internal.security.ResourceOperation in project geode by apache.

the class MiscellaneousCommands method netstat.

@CliCommand(value = CliStrings.NETSTAT, help = CliStrings.NETSTAT__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_DEBUG_UTIL })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public // TODO : Verify the auto-completion for multiple values.
Result netstat(@CliOption(key = CliStrings.NETSTAT__MEMBER, mandatory = false, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.NETSTAT__MEMBER__HELP) String[] members, @CliOption(key = CliStrings.NETSTAT__GROUP, mandatory = false, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.NETSTAT__GROUP__HELP) String group, @CliOption(key = CliStrings.NETSTAT__FILE, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.NETSTAT__FILE__HELP) String saveAs, @CliOption(key = CliStrings.NETSTAT__WITHLSOF, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = CliStrings.NETSTAT__WITHLSOF__HELP) boolean withlsof) {
    Result result = null;
    Map<String, DistributedMember> hostMemberMap = new HashMap<String, DistributedMember>();
    Map<String, List<String>> hostMemberListMap = new HashMap<String, List<String>>();
    try {
        if (members != null && members.length > 0 && group != null) {
            throw new IllegalArgumentException(CliStrings.NETSTAT__MSG__ONLY_ONE_OF_MEMBER_OR_GROUP_SHOULD_BE_SPECIFIED);
        }
        StringBuilder resultInfo = new StringBuilder();
        // Execute for remote members whose id or name matches
        InternalDistributedSystem system = InternalDistributedSystem.getConnectedInstance();
        if (members != null) {
            Set<String> notFoundMembers = new HashSet<String>();
            for (String memberIdOrName : members) {
                Set<DistributedMember> membersToExecuteOn = CliUtil.getAllMembers(system);
                boolean memberFound = false;
                for (DistributedMember distributedMember : membersToExecuteOn) {
                    String memberName = distributedMember.getName();
                    String memberId = distributedMember.getId();
                    if (memberName.equals(memberIdOrName) || memberId.equals(memberIdOrName)) {
                        buildMaps(hostMemberMap, hostMemberListMap, memberIdOrName, distributedMember);
                        memberFound = true;
                        break;
                    }
                }
                if (!memberFound) {
                    notFoundMembers.add(memberIdOrName);
                }
            }
            // if there are not found members, it's probably unknown member or member has departed
            if (!notFoundMembers.isEmpty()) {
                throw new IllegalArgumentException(CliStrings.format(CliStrings.NETSTAT__MSG__COULD_NOT_FIND_MEMBERS_0, new Object[] { CliUtil.collectionToString(notFoundMembers, -1) }));
            }
        } else {
            Set<DistributedMember> membersToExecuteOn = null;
            if (group != null) {
                membersToExecuteOn = system.getGroupMembers(group);
            } else {
                // consider all members
                membersToExecuteOn = CliUtil.getAllMembers(system);
            }
            for (DistributedMember distributedMember : membersToExecuteOn) {
                String memberName = distributedMember.getName();
                String memberId = distributedMember.getId();
                String memberIdOrName = memberName != null && !memberName.isEmpty() ? memberName : memberId;
                buildMaps(hostMemberMap, hostMemberListMap, memberIdOrName, distributedMember);
            }
        }
        String lineSeparatorToUse = null;
        lineSeparatorToUse = CommandExecutionContext.getShellLineSeparator();
        if (lineSeparatorToUse == null) {
            lineSeparatorToUse = GfshParser.LINE_SEPARATOR;
        }
        NetstatFunctionArgument nfa = new NetstatFunctionArgument(lineSeparatorToUse, withlsof);
        if (!hostMemberMap.isEmpty()) {
            Set<DistributedMember> membersToExecuteOn = new HashSet<DistributedMember>(hostMemberMap.values());
            ResultCollector<?, ?> netstatResult = CliUtil.executeFunction(NetstatFunction.INSTANCE, nfa, membersToExecuteOn);
            List<?> resultList = (List<?>) netstatResult.getResult();
            for (int i = 0; i < resultList.size(); i++) {
                NetstatFunctionResult netstatFunctionResult = (NetstatFunctionResult) resultList.get(i);
                DeflaterInflaterData deflaterInflaterData = netstatFunctionResult.getCompressedBytes();
                try {
                    String remoteHost = netstatFunctionResult.getHost();
                    List<String> membersList = hostMemberListMap.get(remoteHost);
                    resultInfo.append(MessageFormat.format(netstatFunctionResult.getHeaderInfo(), CliUtil.collectionToString(membersList, 120)));
                    DeflaterInflaterData uncompressedBytes = CliUtil.uncompressBytes(deflaterInflaterData.getData(), deflaterInflaterData.getDataLength());
                    resultInfo.append(new String(uncompressedBytes.getData()));
                } catch (DataFormatException e) {
                    resultInfo.append("Error in some data. Reason : " + e.getMessage());
                }
            }
        }
        InfoResultData resultData = ResultBuilder.createInfoResultData();
        if (saveAs != null && !saveAs.isEmpty()) {
            String saveToFile = saveAs;
            if (!saveAs.endsWith(NETSTAT_FILE_REQUIRED_EXTENSION)) {
                saveToFile = saveAs + NETSTAT_FILE_REQUIRED_EXTENSION;
            }
            resultData.addAsFile(saveToFile, resultInfo.toString(), CliStrings.NETSTAT__MSG__SAVED_OUTPUT_IN_0, // Note: substitution for {0} will
            false);
        // happen on client side.
        } else {
            resultData.addLine(resultInfo.toString());
        }
        result = ResultBuilder.buildResult(resultData);
    } catch (IllegalArgumentException e) {
        LogWrapper.getInstance().info(CliStrings.format(CliStrings.NETSTAT__MSG__ERROR_OCCURRED_WHILE_EXECUTING_NETSTAT_ON_0, new Object[] { Arrays.toString(members) }));
        result = ResultBuilder.createUserErrorResult(e.getMessage());
    } catch (RuntimeException e) {
        LogWrapper.getInstance().info(CliStrings.format(CliStrings.NETSTAT__MSG__ERROR_OCCURRED_WHILE_EXECUTING_NETSTAT_ON_0, new Object[] { Arrays.toString(members) }), e);
        result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.NETSTAT__MSG__ERROR_OCCURRED_WHILE_EXECUTING_NETSTAT_ON_0, new Object[] { Arrays.toString(members) }));
    } finally {
        hostMemberMap.clear();
        hostMemberListMap.clear();
    }
    return result;
}
Also used : DeflaterInflaterData(org.apache.geode.management.internal.cli.CliUtil.DeflaterInflaterData) HashMap(java.util.HashMap) NetstatFunctionResult(org.apache.geode.management.internal.cli.functions.NetstatFunction.NetstatFunctionResult) 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) List(java.util.List) ArrayList(java.util.ArrayList) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) HashSet(java.util.HashSet) InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) ConverterHint(org.apache.geode.management.cli.ConverterHint) DataFormatException(java.util.zip.DataFormatException) DistributedMember(org.apache.geode.distributed.DistributedMember) NetstatFunctionArgument(org.apache.geode.management.internal.cli.functions.NetstatFunction.NetstatFunctionArgument) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Aggregations

ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)58 CliCommand (org.springframework.shell.core.annotation.CliCommand)57 CliMetaData (org.apache.geode.management.cli.CliMetaData)55 DistributedMember (org.apache.geode.distributed.DistributedMember)49 Result (org.apache.geode.management.cli.Result)49 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)32 InternalCache (org.apache.geode.internal.cache.InternalCache)30 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)30 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)27 ArrayList (java.util.ArrayList)18 List (java.util.List)18 ExecutionException (java.util.concurrent.ExecutionException)15 GfshParseResult (org.apache.geode.management.internal.cli.GfshParseResult)14 ObjectName (javax.management.ObjectName)13 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)13 IOException (java.io.IOException)11 HashSet (java.util.HashSet)11 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)11 HashMap (java.util.HashMap)10 ConverterHint (org.apache.geode.management.cli.ConverterHint)10