use of org.apache.geode.management.cli.CliMetaData 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.cli.CliMetaData 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.cli.CliMetaData 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;
}
use of org.apache.geode.management.cli.CliMetaData in project geode by apache.
the class DurableClientCommands method listDurableClientCqs.
@CliCommand(value = CliStrings.LIST_DURABLE_CQS, help = CliStrings.LIST_DURABLE_CQS__HELP)
@CliMetaData(shellOnly = false)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result listDurableClientCqs(@CliOption(key = CliStrings.LIST_DURABLE_CQS__DURABLECLIENTID, mandatory = true, help = CliStrings.LIST_DURABLE_CQS__DURABLECLIENTID__HELP) final String durableClientId, @CliOption(key = CliStrings.LIST_DURABLE_CQS__MEMBER, help = CliStrings.LIST_DURABLE_CQS__MEMBER__HELP, optionContext = ConverterHint.MEMBERIDNAME) final String[] memberNameOrId, @CliOption(key = CliStrings.LIST_DURABLE_CQS__GROUP, help = CliStrings.LIST_DURABLE_CQS__GROUP__HELP, optionContext = ConverterHint.MEMBERGROUP) final String[] group) {
Result result = null;
try {
boolean noResults = true;
Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId);
if (targetMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
final ResultCollector<?, ?> rc = CliUtil.executeFunction(new ListDurableCqNamesFunction(), durableClientId, targetMembers);
final List<DurableCqNamesResult> results = (List<DurableCqNamesResult>) rc.getResult();
Map<String, List<String>> memberCqNamesMap = new TreeMap<String, List<String>>();
Map<String, List<String>> errorMessageNodes = new HashMap<String, List<String>>();
Map<String, List<String>> exceptionMessageNodes = new HashMap<String, List<String>>();
for (DurableCqNamesResult memberResult : results) {
if (memberResult != null) {
if (memberResult.isSuccessful()) {
memberCqNamesMap.put(memberResult.getMemberNameOrId(), memberResult.getCqNamesList());
} else {
if (memberResult.isOpPossible()) {
groupByMessage(memberResult.getExceptionMessage(), memberResult.getMemberNameOrId(), exceptionMessageNodes);
} else {
groupByMessage(memberResult.getErrorMessage(), memberResult.getMemberNameOrId(), errorMessageNodes);
}
}
}
}
if (!memberCqNamesMap.isEmpty()) {
TabularResultData table = ResultBuilder.createTabularResultData();
Set<String> members = memberCqNamesMap.keySet();
for (String member : members) {
boolean isFirst = true;
List<String> cqNames = memberCqNamesMap.get(member);
for (String cqName : cqNames) {
if (isFirst) {
isFirst = false;
table.accumulate(CliStrings.LIST_DURABLE_CQS__MEMBER, member);
} else {
table.accumulate(CliStrings.LIST_DURABLE_CQS__MEMBER, "");
}
table.accumulate(CliStrings.LIST_DURABLE_CQS__NAME, cqName);
}
}
result = ResultBuilder.buildResult(table);
} else {
String errorHeader = CliStrings.format(CliStrings.LIST_DURABLE_CQS__FAILURE__HEADER, durableClientId);
result = ResultBuilder.buildResult(buildFailureData(null, exceptionMessageNodes, errorMessageNodes, errorHeader));
}
} catch (Exception e) {
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
}
return result;
}
use of org.apache.geode.management.cli.CliMetaData in project geode by apache.
the class DurableClientCommands method closeDurableClient.
@CliCommand(value = CliStrings.CLOSE_DURABLE_CLIENTS, help = CliStrings.CLOSE_DURABLE_CLIENTS__HELP)
@CliMetaData(shellOnly = false)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result closeDurableClient(@CliOption(key = CliStrings.CLOSE_DURABLE_CLIENTS__CLIENT__ID, mandatory = true, help = CliStrings.CLOSE_DURABLE_CLIENTS__CLIENT__ID__HELP) final String durableClientId, @CliOption(key = CliStrings.CLOSE_DURABLE_CLIENTS__MEMBER, mandatory = false, help = CliStrings.CLOSE_DURABLE_CLIENTS__MEMBER__HELP, optionContext = ConverterHint.MEMBERIDNAME) final String[] memberNameOrId, @CliOption(key = CliStrings.CLOSE_DURABLE_CLIENTS__GROUP, mandatory = false, help = CliStrings.COUNT_DURABLE_CQ_EVENTS__GROUP__HELP, optionContext = ConverterHint.MEMBERGROUP) final String[] group) {
Result result = null;
try {
Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId);
if (targetMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
final ResultCollector<?, ?> rc = CliUtil.executeFunction(new CloseDurableClientFunction(), durableClientId, targetMembers);
final List<MemberResult> results = (List<MemberResult>) rc.getResult();
String failureHeader = CliStrings.format(CliStrings.CLOSE_DURABLE_CLIENTS__FAILURE__HEADER, durableClientId);
String successHeader = CliStrings.format(CliStrings.CLOSE_DURABLE_CLIENTS__SUCCESS, durableClientId);
result = buildResult(results, successHeader, failureHeader);
} catch (Exception e) {
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
}
return result;
}
Aggregations