use of org.apache.geode.management.internal.cli.domain.MemberResult in project geode by apache.
the class DurableClientCommands method closeDurableCqs.
@CliCommand(value = CliStrings.CLOSE_DURABLE_CQS, help = CliStrings.CLOSE_DURABLE_CQS__HELP)
@CliMetaData(shellOnly = false)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result closeDurableCqs(@CliOption(key = CliStrings.CLOSE_DURABLE_CQS__DURABLE__CLIENT__ID, mandatory = true, help = CliStrings.CLOSE_DURABLE_CQS__DURABLE__CLIENT__ID__HELP) final String durableClientId, @CliOption(key = CliStrings.CLOSE_DURABLE_CQS__NAME, mandatory = true, help = CliStrings.CLOSE_DURABLE_CQS__NAME__HELP) final String cqName, @CliOption(key = CliStrings.CLOSE_DURABLE_CQS__MEMBER, mandatory = false, help = CliStrings.CLOSE_DURABLE_CQS__MEMBER__HELP, optionContext = ConverterHint.MEMBERIDNAME) final String[] memberNameOrId, @CliOption(key = CliStrings.CLOSE_DURABLE_CQS__GROUP, mandatory = false, help = CliStrings.CLOSE_DURABLE_CQS__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);
}
String[] params = new String[2];
params[0] = durableClientId;
params[1] = cqName;
final ResultCollector<?, ?> rc = CliUtil.executeFunction(new CloseDurableCqFunction(), params, targetMembers);
final List<MemberResult> results = (List<MemberResult>) rc.getResult();
String failureHeader = CliStrings.format(CliStrings.CLOSE_DURABLE_CQS__FAILURE__HEADER, cqName, durableClientId);
String successHeader = CliStrings.format(CliStrings.CLOSE_DURABLE_CQS__SUCCESS, cqName, durableClientId);
result = buildResult(results, successHeader, failureHeader);
} catch (Exception e) {
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
}
return result;
}
use of org.apache.geode.management.internal.cli.domain.MemberResult in project geode by apache.
the class DurableClientCommands method buildResult.
private Result buildResult(List<MemberResult> results, String successHeader, String failureHeader) {
Result result = null;
boolean failure = true;
boolean partialFailure = false;
Map<String, List<String>> errorMap = new HashMap<String, List<String>>();
Map<String, List<String>> successMap = new HashMap<String, List<String>>();
Map<String, List<String>> exceptionMap = new HashMap<String, List<String>>();
/***
* Aggregate the results from the members
*/
for (MemberResult memberResult : results) {
if (memberResult.isSuccessful()) {
failure = false;
groupByMessage(memberResult.getSuccessMessage(), memberResult.getMemberNameOrId(), successMap);
} else {
if (memberResult.isOpPossible()) {
partialFailure = true;
groupByMessage(memberResult.getExceptionMessage(), memberResult.getMemberNameOrId(), exceptionMap);
} else {
groupByMessage(memberResult.getErrorMessage(), memberResult.getMemberNameOrId(), errorMap);
}
}
}
if (!failure && !partialFailure) {
result = ResultBuilder.buildResult(buildSuccessData(successMap));
} else {
result = ResultBuilder.buildResult(buildFailureData(successMap, exceptionMap, errorMap, failureHeader));
}
return result;
}
use of org.apache.geode.management.internal.cli.domain.MemberResult in project geode by apache.
the class CloseDurableClientFunction method execute.
@Override
public void execute(FunctionContext context) {
String durableClientId = (String) context.getArguments();
final Cache cache = CliUtil.getCacheIfExists();
final String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
MemberResult memberResult = new MemberResult(memberNameOrId);
try {
CacheClientNotifier cacheClientNotifier = CacheClientNotifier.getInstance();
if (cacheClientNotifier != null) {
CacheClientProxy ccp = cacheClientNotifier.getClientProxy(durableClientId);
if (ccp != null) {
boolean isClosed = cacheClientNotifier.closeDurableClientProxy(durableClientId);
if (isClosed) {
memberResult.setSuccessMessage(CliStrings.format(CliStrings.CLOSE_DURABLE_CLIENTS__SUCCESS, durableClientId));
} else {
memberResult.setErrorMessage(CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, durableClientId));
}
} else {
memberResult.setErrorMessage(CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, durableClientId));
}
} else {
memberResult.setErrorMessage(CliStrings.NO_CLIENT_FOUND);
}
} catch (Exception e) {
memberResult.setExceptionMessage(e.getMessage());
} finally {
context.getResultSender().lastResult(memberResult);
}
}
use of org.apache.geode.management.internal.cli.domain.MemberResult in project geode by apache.
the class CloseDurableCqFunction method execute.
@Override
public void execute(FunctionContext context) {
final Cache cache = CliUtil.getCacheIfExists();
final String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
CacheClientNotifier cacheClientNotifier = CacheClientNotifier.getInstance();
String[] args = (String[]) context.getArguments();
String durableClientId = args[0];
String cqName = args[1];
MemberResult memberResult = new MemberResult(memberNameOrId);
try {
if (cacheClientNotifier != null) {
CacheClientProxy cacheClientProxy = cacheClientNotifier.getClientProxy(durableClientId);
if (cacheClientProxy != null) {
if (cacheClientNotifier.closeClientCq(durableClientId, cqName)) {
memberResult.setSuccessMessage(CliStrings.format(CliStrings.CLOSE_DURABLE_CQS__SUCCESS, cqName, durableClientId));
} else {
memberResult.setErrorMessage(CliStrings.format(CliStrings.CLOSE_DURABLE_CQS__UNABLE__TO__CLOSE__CQ, cqName, durableClientId));
}
} else {
memberResult.setErrorMessage(CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, durableClientId));
}
} else {
memberResult.setErrorMessage(CliStrings.NO_CLIENT_FOUND);
}
} catch (Exception e) {
memberResult.setExceptionMessage(e.getMessage());
} finally {
context.getResultSender().lastResult(memberResult);
}
}
use of org.apache.geode.management.internal.cli.domain.MemberResult 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;
}
Aggregations