use of org.apache.geode.management.internal.cli.result.InfoResultData in project geode by apache.
the class IndexCommands method clearDefinedIndexes.
@CliCommand(value = CliStrings.CLEAR_DEFINED_INDEXES, help = CliStrings.CLEAR_DEFINED__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA })
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public // TODO : Add optionContext for indexName
Result clearDefinedIndexes() {
indexDefinitions.clear();
final InfoResultData infoResult = ResultBuilder.createInfoResultData();
infoResult.addLine(CliStrings.CLEAR_DEFINED_INDEX__SUCCESS__MSG);
return ResultBuilder.buildResult(infoResult);
}
use of org.apache.geode.management.internal.cli.result.InfoResultData 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;
}
use of org.apache.geode.management.internal.cli.result.InfoResultData 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;
}
use of org.apache.geode.management.internal.cli.result.InfoResultData 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;
}
use of org.apache.geode.management.internal.cli.result.InfoResultData 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;
}
Aggregations