use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.
the class CLIMultiStepHelper method getNextStep.
public static String getNextStep(Result cdata) {
CommandResult cResult = (CommandResult) cdata;
if (ResultData.TYPE_COMPOSITE.equals(cResult.getType())) {
CompositeResultData rd = (CompositeResultData) cResult.getResultData();
SectionResultData section = rd.retrieveSection(CLIMultiStepHelper.STEP_SECTION);
String nextStep = (String) section.retrieveObject(CLIMultiStepHelper.NEXT_STEP_NAME);
return nextStep;
} else {
if (ResultData.TYPE_ERROR.equals(cResult.getType())) {
throw new CLIStepExecption(cResult);
} else {
throw new RuntimeException("Step returned result of type other than " + ResultData.TYPE_COMPOSITE + " Type " + cResult.getType());
}
}
}
use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.
the class CLIMultiStepHelper method extractArgumentsForNextStep.
public static SectionResultData extractArgumentsForNextStep(Result result) {
CommandResult cResult = (CommandResult) result;
if (ResultData.TYPE_COMPOSITE.equals(cResult.getType())) {
CompositeResultData rd = (CompositeResultData) cResult.getResultData();
SectionResultData data = rd.retrieveSection(CLIMultiStepHelper.ARG_SECTION);
return data;
} else {
if (ResultData.TYPE_ERROR.equals(cResult.getType())) {
throw new CLIStepExecption(cResult);
} else {
throw new StepExecutionException("Step returned result of type other than " + ResultData.TYPE_COMPOSITE + " Type " + cResult.getType());
}
}
}
use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.
the class WanCommands method listGateway.
@CliCommand(value = CliStrings.LIST_GATEWAY, help = CliStrings.LIST_GATEWAY__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result listGateway(@CliOption(key = CliStrings.LIST_GATEWAY__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.LIST_GATEWAY__MEMBER__HELP) String[] onMember, @CliOption(key = CliStrings.LIST_GATEWAY__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.LIST_GATEWAY__GROUP__HELP) String[] onGroup) {
Result result = null;
InternalCache cache = getCache();
try {
SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
Set<DistributedMember> dsMembers = CliUtil.findMembers(onGroup, onMember);
if (dsMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
Map<String, Map<String, GatewaySenderMXBean>> gatewaySenderBeans = new TreeMap<String, Map<String, GatewaySenderMXBean>>();
Map<String, GatewayReceiverMXBean> gatewayReceiverBeans = new TreeMap<String, GatewayReceiverMXBean>();
DistributedSystemMXBean dsMXBean = service.getDistributedSystemMXBean();
for (DistributedMember member : dsMembers) {
String memberName = member.getName();
String memberNameOrId = (memberName != null && !memberName.isEmpty()) ? memberName : member.getId();
ObjectName[] gatewaySenderObjectNames = dsMXBean.listGatewaySenderObjectNames(memberNameOrId);
// on it
if (gatewaySenderObjectNames != null) {
for (ObjectName name : gatewaySenderObjectNames) {
GatewaySenderMXBean senderBean = service.getMBeanProxy(name, GatewaySenderMXBean.class);
if (senderBean != null) {
if (gatewaySenderBeans.containsKey(senderBean.getSenderId())) {
Map<String, GatewaySenderMXBean> memberToBeanMap = gatewaySenderBeans.get(senderBean.getSenderId());
memberToBeanMap.put(member.getId(), senderBean);
} else {
Map<String, GatewaySenderMXBean> memberToBeanMap = new TreeMap<String, GatewaySenderMXBean>();
memberToBeanMap.put(member.getId(), senderBean);
gatewaySenderBeans.put(senderBean.getSenderId(), memberToBeanMap);
}
}
}
}
// gateway receivers : a member can have only one gateway receiver
ObjectName gatewayReceiverObjectName = MBeanJMXAdapter.getGatewayReceiverMBeanName(member);
if (gatewayReceiverObjectName != null) {
GatewayReceiverMXBean receieverBean = null;
receieverBean = service.getMBeanProxy(gatewayReceiverObjectName, GatewayReceiverMXBean.class);
if (receieverBean != null) {
gatewayReceiverBeans.put(member.getId(), receieverBean);
}
}
}
if (gatewaySenderBeans.isEmpty() && gatewayReceiverBeans.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.GATEWAYS_ARE_NOT_AVAILABLE_IN_CLUSTER);
}
CompositeResultData crd = ResultBuilder.createCompositeResultData();
crd.setHeader(CliStrings.HEADER_GATEWAYS);
accumulateListGatewayResult(crd, gatewaySenderBeans, gatewayReceiverBeans);
result = ResultBuilder.buildResult(crd);
} catch (Exception e) {
LogWrapper.getInstance().warning(CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(e));
result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR + e.getMessage());
}
return result;
}
use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.
the class DataCommandResult method toSelectCommandResult.
/**
* This method returns result when flag interactive=false i.e. Command returns result in one go
* and does not goes through steps waiting for user input. Method returns CompositeResultData
* instead of Result as Command Step is required to add NEXT_STEP information to guide
* executionStragey to route it through final step.
*/
public CompositeResultData toSelectCommandResult() {
if (errorString != null) {
// return ResultBuilder.createGemFireErrorResult(errorString);
CompositeResultData data = ResultBuilder.createCompositeResultData();
SectionResultData section = data.addSection();
section.addData("Message", errorString);
section.addData(RESULT_FLAG, operationCompletedSuccessfully);
return data;
} else {
CompositeResultData data = ResultBuilder.createCompositeResultData();
SectionResultData section = data.addSection();
TabularResultData table = section.addTable();
section.addData(RESULT_FLAG, operationCompletedSuccessfully);
if (infoString != null) {
section.addData("Message", infoString);
}
if (inputQuery != null) {
if (this.limit != -1) {
section.addData("Limit", this.limit);
}
if (this.selectResult != null) {
section.addData(NUM_ROWS, this.selectResult.size());
if (this.queryTraceString != null) {
section.addData("Query Trace", this.queryTraceString);
}
buildTable(table, 0, selectResult.size());
}
}
return data;
}
}
use of org.apache.geode.management.internal.cli.result.CompositeResultData 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());
}
}
Aggregations