Search in sources :

Example 1 with StackTracesPerMember

use of org.apache.geode.management.internal.cli.domain.StackTracesPerMember in project geode by apache.

the class GetStackTracesFunction method execute.

@Override
public void execute(FunctionContext context) {
    try {
        Cache cache = CacheFactory.getAnyInstance();
        String memberNameOrId = cache.getDistributedSystem().getDistributedMember().getName();
        if (memberNameOrId == null) {
            memberNameOrId = cache.getDistributedSystem().getDistributedMember().getId();
        }
        StackTracesPerMember stackTracePerMember = new StackTracesPerMember(memberNameOrId, OSProcess.zipStacks());
        context.getResultSender().lastResult(stackTracePerMember);
    } catch (Exception e) {
        context.getResultSender().sendException(e);
    }
}
Also used : StackTracesPerMember(org.apache.geode.management.internal.cli.domain.StackTracesPerMember) Cache(org.apache.geode.cache.Cache)

Example 2 with StackTracesPerMember

use of org.apache.geode.management.internal.cli.domain.StackTracesPerMember in project geode by apache.

the class MiscellaneousCommands method exportStackTrace.

/**
   * Current implementation supports writing it to a file and returning the location of the file
   */
@CliCommand(value = CliStrings.EXPORT_STACKTRACE, help = CliStrings.EXPORT_STACKTRACE__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_DEBUG_UTIL })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result exportStackTrace(@CliOption(key = CliStrings.EXPORT_STACKTRACE__MEMBER, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.EXPORT_STACKTRACE__HELP) String[] memberNameOrId, @CliOption(key = CliStrings.EXPORT_STACKTRACE__GROUP, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.EXPORT_STACKTRACE__GROUP) String[] group, @CliOption(key = CliStrings.EXPORT_STACKTRACE__FILE, help = CliStrings.EXPORT_STACKTRACE__FILE__HELP) String fileName, @CliOption(key = CliStrings.EXPORT_STACKTRACE__FAIL__IF__FILE__PRESENT, unspecifiedDefaultValue = "false", help = CliStrings.EXPORT_STACKTRACE__FAIL__IF__FILE__PRESENT__HELP) boolean failIfFilePresent) {
    Result result = null;
    StringBuffer filePrefix = new StringBuffer("stacktrace");
    if (fileName == null) {
        fileName = filePrefix.append("_").append(System.currentTimeMillis()).toString();
    }
    final File outFile = new File(fileName);
    try {
        if (outFile.exists() && failIfFilePresent) {
            return ResultBuilder.createShellClientErrorResult(CliStrings.format(CliStrings.EXPORT_STACKTRACE__ERROR__FILE__PRESENT, outFile.getCanonicalPath()));
        }
        InternalCache cache = getCache();
        InternalDistributedSystem ads = cache.getInternalDistributedSystem();
        InfoResultData resultData = ResultBuilder.createInfoResultData();
        Map<String, byte[]> dumps = new HashMap<String, byte[]>();
        Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId);
        if (targetMembers.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        ResultCollector<?, ?> rc = CliUtil.executeFunction(getStackTracesFunction, null, targetMembers);
        ArrayList<Object> resultList = (ArrayList<Object>) rc.getResult();
        for (Object resultObj : resultList) {
            if (resultObj instanceof StackTracesPerMember) {
                StackTracesPerMember stackTracePerMember = (StackTracesPerMember) resultObj;
                dumps.put(stackTracePerMember.getMemberNameOrId(), stackTracePerMember.getStackTraces());
            }
        }
        String filePath = writeStacksToFile(dumps, fileName);
        resultData.addLine(CliStrings.format(CliStrings.EXPORT_STACKTRACE__SUCCESS, filePath));
        resultData.addLine(CliStrings.EXPORT_STACKTRACE__HOST + ads.getDistributedMember().getHost());
        result = ResultBuilder.buildResult(resultData);
    } catch (IOException ex) {
        result = ResultBuilder.createGemFireErrorResult(CliStrings.EXPORT_STACKTRACE__ERROR + ex.getMessage());
    }
    return result;
}
Also used : InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) IOException(java.io.IOException) 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) StackTracesPerMember(org.apache.geode.management.internal.cli.domain.StackTracesPerMember) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) File(java.io.File) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Aggregations

StackTracesPerMember (org.apache.geode.management.internal.cli.domain.StackTracesPerMember)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Cache (org.apache.geode.cache.Cache)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)1 InternalCache (org.apache.geode.internal.cache.InternalCache)1 CliMetaData (org.apache.geode.management.cli.CliMetaData)1 Result (org.apache.geode.management.cli.Result)1 GfshParseResult (org.apache.geode.management.internal.cli.GfshParseResult)1 NetstatFunctionResult (org.apache.geode.management.internal.cli.functions.NetstatFunction.NetstatFunctionResult)1 InfoResultData (org.apache.geode.management.internal.cli.result.InfoResultData)1 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)1 CliCommand (org.springframework.shell.core.annotation.CliCommand)1