use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.
the class FunctionCommands method executeFunction.
@CliCommand(value = CliStrings.EXECUTE_FUNCTION, help = CliStrings.EXECUTE_FUNCTION__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_FUNCTION })
@ResourceOperation(resource = Resource.DATA, operation = Operation.WRITE)
public Result executeFunction(// TODO: Add optioncontext for functionID
@CliOption(key = CliStrings.EXECUTE_FUNCTION__ID, mandatory = true, help = CliStrings.EXECUTE_FUNCTION__ID__HELP) String functionId, @CliOption(key = CliStrings.EXECUTE_FUNCTION__ONGROUPS, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.EXECUTE_FUNCTION__ONGROUPS__HELP) String[] onGroups, @CliOption(key = CliStrings.EXECUTE_FUNCTION__ONMEMBER, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.EXECUTE_FUNCTION__ONMEMBER__HELP) String onMember, @CliOption(key = CliStrings.EXECUTE_FUNCTION__ONREGION, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.REGION_PATH, help = CliStrings.EXECUTE_FUNCTION__ONREGION__HELP) String onRegion, @CliOption(key = CliStrings.EXECUTE_FUNCTION__ARGUMENTS, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.EXECUTE_FUNCTION__ARGUMENTS__HELP) String[] arguments, @CliOption(key = CliStrings.EXECUTE_FUNCTION__RESULTCOLLECTOR, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.EXECUTE_FUNCTION__RESULTCOLLECTOR__HELP) String resultCollector, @CliOption(key = CliStrings.EXECUTE_FUNCTION__FILTER, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.EXECUTE_FUNCTION__FILTER__HELP) String filterString) {
Result result = null;
CompositeResultData executeFunctionResultTable = ResultBuilder.createCompositeResultData();
TabularResultData resultTable = executeFunctionResultTable.addSection().addTable("Table1");
String headerText = "Execution summary";
resultTable.setHeader(headerText);
ResultCollector resultCollectorInstance = null;
Function function;
Set<String> filters = new HashSet<String>();
Execution execution = null;
if (functionId != null) {
functionId = functionId.trim();
}
if (onRegion != null) {
onRegion = onRegion.trim();
}
if (onMember != null) {
onMember = onMember.trim();
}
if (filterString != null) {
filterString = filterString.trim();
}
try {
// validate otherwise return right away. no need to process anything
if (functionId == null || functionId.length() == 0) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__MISSING_FUNCTIONID);
result = ResultBuilder.buildResult(errorResultData);
return result;
}
if (onRegion != null && onMember != null && onGroups != null) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__OPTIONS);
result = ResultBuilder.buildResult(errorResultData);
return result;
} else if (onRegion != null && onMember != null) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__OPTIONS);
result = ResultBuilder.buildResult(errorResultData);
return result;
} else if (onMember != null && onGroups != null) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__OPTIONS);
result = ResultBuilder.buildResult(errorResultData);
return result;
} else if (onRegion != null && onGroups != null) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__OPTIONS);
result = ResultBuilder.buildResult(errorResultData);
return result;
} else if (onRegion != null && onMember != null && onGroups != null) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__OPTIONS);
result = ResultBuilder.buildResult(errorResultData);
return result;
} else if ((onRegion == null || onRegion.length() == 0) && (filterString != null)) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.EXECUTE_FUNCTION__MSG__MEMBER_SHOULD_NOT_HAVE_FILTER_FOR_EXECUTION);
result = ResultBuilder.buildResult(errorResultData);
return result;
}
InternalCache cache = getCache();
if (resultCollector != null) {
resultCollectorInstance = (ResultCollector) ClassPathLoader.getLatest().forName(resultCollector).newInstance();
}
if (filterString != null && filterString.length() > 0) {
filters.add(filterString);
}
if (onRegion == null && onMember == null && onGroups == null) {
// run function on all the members excluding locators bug#46113
// if user wish to execute on locator then he can choose --member or --group option
Set<DistributedMember> dsMembers = CliUtil.getAllNormalMembers(cache);
if (dsMembers.size() > 0) {
function = new UserFunctionExecution();
LogWrapper.getInstance().info(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__EXECUTING_0_ON_ENTIRE_DS, functionId));
for (DistributedMember member : dsMembers) {
executeAndGetResults(functionId, filterString, resultCollector, arguments, cache, member, resultTable, onRegion);
}
return ResultBuilder.buildResult(resultTable);
} else {
return ResultBuilder.createUserErrorResult(CliStrings.EXECUTE_FUNCTION__MSG__DS_HAS_NO_MEMBERS);
}
} else if (onRegion != null && onRegion.length() > 0) {
if (cache.getRegion(onRegion) == null) {
// find a member where region is present
DistributedRegionMXBean bean = ManagementService.getManagementService(getCache()).getDistributedRegionMXBean(onRegion);
if (bean == null) {
bean = ManagementService.getManagementService(getCache()).getDistributedRegionMXBean(Region.SEPARATOR + onRegion);
if (bean == null) {
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__MXBEAN_0_FOR_NOT_FOUND, onRegion));
}
}
DistributedMember member = null;
String[] membersName = bean.getMembers();
Set<DistributedMember> dsMembers = CliUtil.getAllMembers(cache);
Iterator it = dsMembers.iterator();
boolean matchFound = false;
if (membersName.length > 0) {
while (it.hasNext() && matchFound == false) {
DistributedMember dsmember = (DistributedMember) it.next();
for (String memberName : membersName) {
if (MBeanJMXAdapter.getMemberNameOrId(dsmember).equals(memberName)) {
member = dsmember;
matchFound = true;
break;
}
}
}
}
if (matchFound == true) {
executeAndGetResults(functionId, filterString, resultCollector, arguments, cache, member, resultTable, onRegion);
return ResultBuilder.buildResult(resultTable);
} else {
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__NO_ASSOCIATED_MEMBER_REGION, " " + onRegion));
}
} else {
execution = FunctionService.onRegion(cache.getRegion(onRegion));
if (execution != null) {
if (resultCollectorInstance != null) {
execution = execution.withCollector(resultCollectorInstance);
}
if (filters != null && filters.size() > 0) {
execution = execution.withFilter(filters);
}
if (arguments != null && arguments.length > 0) {
execution = execution.setArguments(arguments);
}
try {
List<Object> results = (List<Object>) execution.execute(functionId).getResult();
if (results.size() > 0) {
StringBuilder strResult = new StringBuilder();
for (Object obj : results) {
strResult.append(obj);
}
toTabularResultData(resultTable, cache.getDistributedSystem().getDistributedMember().getId(), strResult.toString());
}
return ResultBuilder.buildResult(resultTable);
} catch (FunctionException e) {
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__ERROR_IN_EXECUTING_0_ON_REGION_1_DETAILS_2, functionId, onRegion, e.getMessage()));
}
} else {
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__ERROR_IN_EXECUTING_0_ON_REGION_1_DETAILS_2, functionId, onRegion, CliStrings.EXECUTE_FUNCTION__MSG__ERROR_IN_RETRIEVING_EXECUTOR));
}
}
} else if (onGroups != null) {
// execute on group members
Set<DistributedMember> dsMembers = new HashSet<DistributedMember>();
for (String grp : onGroups) {
dsMembers.addAll(cache.getDistributedSystem().getGroupMembers(grp));
}
StringBuilder successMessage = new StringBuilder();
if (dsMembers.size() > 0) {
for (DistributedMember member : dsMembers) {
executeAndGetResults(functionId, filterString, resultCollector, arguments, cache, member, resultTable, onRegion);
}
return ResultBuilder.buildResult(resultTable);
} else {
StringBuilder grps = new StringBuilder();
for (String grp : onGroups) {
grps.append(grp);
grps.append(", ");
}
return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__GROUPS_0_HAS_NO_MEMBERS, grps.toString().substring(0, grps.toString().length() - 1)));
}
} else if (onMember != null && onMember.length() > 0) {
// fix for bug
DistributedMember member = CliUtil.getDistributedMemberByNameOrId(onMember);
// 45658
if (member != null) {
executeAndGetResults(functionId, filterString, resultCollector, arguments, cache, member, resultTable, onRegion);
} else {
toTabularResultData(resultTable, onMember, CliStrings.format(CliStrings.EXECUTE_FUNCTION__MSG__NO_ASSOCIATED_MEMBER + " " + onMember));
}
return ResultBuilder.buildResult(resultTable);
}
} catch (InstantiationException e) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
result = ResultBuilder.buildResult(errorResultData);
return result;
} catch (IllegalAccessException e) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
result = ResultBuilder.buildResult(errorResultData);
return result;
} catch (IllegalArgumentException e) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
result = ResultBuilder.buildResult(errorResultData);
return result;
} catch (SecurityException e) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
result = ResultBuilder.buildResult(errorResultData);
return result;
} catch (Exception e) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
result = ResultBuilder.buildResult(errorResultData);
return result;
}
return result;
}
use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.
the class RegionCommands method describeRegion.
@CliCommand(value = { CliStrings.DESCRIBE_REGION }, help = CliStrings.DESCRIBE_REGION__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_CONFIG })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result describeRegion(@CliOption(key = CliStrings.DESCRIBE_REGION__NAME, optionContext = ConverterHint.REGION_PATH, help = CliStrings.DESCRIBE_REGION__NAME__HELP, mandatory = true) String regionName) {
Result result = null;
try {
if (regionName == null || regionName.isEmpty()) {
return ResultBuilder.createUserErrorResult("Please provide a region name");
}
if (regionName.equals(Region.SEPARATOR)) {
return ResultBuilder.createUserErrorResult(CliStrings.INVALID_REGION_NAME);
}
InternalCache cache = getCache();
ResultCollector<?, ?> rc = CliUtil.executeFunction(getRegionDescription, regionName, CliUtil.getAllMembers(cache));
List<?> resultList = (List<?>) rc.getResult();
// The returned result could be a region description with per member and /or single local
// region
Object[] results = resultList.toArray();
List<RegionDescription> regionDescriptionList = new ArrayList<RegionDescription>();
for (int i = 0; i < results.length; i++) {
if (results[i] instanceof RegionDescriptionPerMember) {
RegionDescriptionPerMember regionDescPerMember = (RegionDescriptionPerMember) results[i];
if (regionDescPerMember != null) {
RegionDescription regionDescription = new RegionDescription();
regionDescription.add(regionDescPerMember);
for (int j = i + 1; j < results.length; j++) {
if (results[j] != null && results[j] instanceof RegionDescriptionPerMember) {
RegionDescriptionPerMember preyRegionDescPerMember = (RegionDescriptionPerMember) results[j];
if (regionDescription.add(preyRegionDescPerMember)) {
results[j] = null;
}
}
}
regionDescriptionList.add(regionDescription);
}
} else if (results[i] instanceof Throwable) {
Throwable t = (Throwable) results[i];
LogWrapper.getInstance().info(t.getMessage(), t);
}
}
if (regionDescriptionList.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.REGION_NOT_FOUND, regionName));
}
CompositeResultData crd = ResultBuilder.createCompositeResultData();
Iterator<RegionDescription> iters = regionDescriptionList.iterator();
while (iters.hasNext()) {
RegionDescription regionDescription = iters.next();
// No point in displaying the scope for PR's
if (regionDescription.isPartition()) {
regionDescription.getCndRegionAttributes().remove(RegionAttributesNames.SCOPE);
} else {
String scope = regionDescription.getCndRegionAttributes().get(RegionAttributesNames.SCOPE);
if (scope != null) {
scope = scope.toLowerCase().replace('_', '-');
regionDescription.getCndRegionAttributes().put(RegionAttributesNames.SCOPE, scope);
}
}
SectionResultData regionSection = crd.addSection();
regionSection.addSeparator('-');
regionSection.addData("Name", regionDescription.getName());
String dataPolicy = regionDescription.getDataPolicy().toString().toLowerCase().replace('_', ' ');
regionSection.addData("Data Policy", dataPolicy);
String memberType = "";
if (regionDescription.isAccessor()) {
memberType = CliStrings.DESCRIBE_REGION__ACCESSOR__MEMBER;
} else {
memberType = CliStrings.DESCRIBE_REGION__HOSTING__MEMBER;
}
regionSection.addData(memberType, CliUtil.convertStringSetToString(regionDescription.getHostingMembers(), '\n'));
regionSection.addSeparator('.');
TabularResultData commonNonDefaultAttrTable = regionSection.addSection().addTable();
commonNonDefaultAttrTable.setHeader(CliStrings.format(CliStrings.DESCRIBE_REGION__NONDEFAULT__COMMONATTRIBUTES__HEADER, memberType));
// Common Non Default Region Attributes
Map<String, String> cndRegionAttrsMap = regionDescription.getCndRegionAttributes();
// Common Non Default Eviction Attributes
Map<String, String> cndEvictionAttrsMap = regionDescription.getCndEvictionAttributes();
// Common Non Default Partition Attributes
Map<String, String> cndPartitionAttrsMap = regionDescription.getCndPartitionAttributes();
writeCommonAttributesToTable(commonNonDefaultAttrTable, CliStrings.DESCRIBE_REGION__ATTRIBUTE__TYPE__REGION, cndRegionAttrsMap);
writeCommonAttributesToTable(commonNonDefaultAttrTable, CliStrings.DESCRIBE_REGION__ATTRIBUTE__TYPE__EVICTION, cndEvictionAttrsMap);
writeCommonAttributesToTable(commonNonDefaultAttrTable, CliStrings.DESCRIBE_REGION__ATTRIBUTE__TYPE__PARTITION, cndPartitionAttrsMap);
// Member-wise non default Attributes
Map<String, RegionDescriptionPerMember> regDescPerMemberMap = regionDescription.getRegionDescriptionPerMemberMap();
Set<String> members = regDescPerMemberMap.keySet();
TabularResultData table = regionSection.addSection().addTable();
// table.setHeader(CliStrings.format(CliStrings.DESCRIBE_REGION__NONDEFAULT__PERMEMBERATTRIBUTES__HEADER,
// memberType));
boolean setHeader = false;
for (String member : members) {
RegionDescriptionPerMember regDescPerMem = regDescPerMemberMap.get(member);
Map<String, String> ndRa = regDescPerMem.getNonDefaultRegionAttributes();
Map<String, String> ndEa = regDescPerMem.getNonDefaultEvictionAttributes();
Map<String, String> ndPa = regDescPerMem.getNonDefaultPartitionAttributes();
// Get all the member-specific non-default attributes by removing the common keys
ndRa.keySet().removeAll(cndRegionAttrsMap.keySet());
ndEa.keySet().removeAll(cndEvictionAttrsMap.keySet());
ndPa.keySet().removeAll(cndPartitionAttrsMap.keySet());
// Scope is not valid for PR's
if (regionDescription.isPartition()) {
if (ndRa.get(RegionAttributesNames.SCOPE) != null) {
ndRa.remove(RegionAttributesNames.SCOPE);
}
}
List<FixedPartitionAttributesInfo> fpaList = regDescPerMem.getFixedPartitionAttributes();
if (!(ndRa.isEmpty() && ndEa.isEmpty() && ndPa.isEmpty()) || fpaList != null) {
setHeader = true;
boolean memberNameAdded = false;
memberNameAdded = writeAttributesToTable(table, CliStrings.DESCRIBE_REGION__ATTRIBUTE__TYPE__REGION, ndRa, member, memberNameAdded);
memberNameAdded = writeAttributesToTable(table, CliStrings.DESCRIBE_REGION__ATTRIBUTE__TYPE__EVICTION, ndEa, member, memberNameAdded);
memberNameAdded = writeAttributesToTable(table, CliStrings.DESCRIBE_REGION__ATTRIBUTE__TYPE__PARTITION, ndPa, member, memberNameAdded);
writeFixedPartitionAttributesToTable(table, "", fpaList, member, memberNameAdded);
// Fix for #46767
// writeAttributeToTable(table, "", "", "", "");
}
}
if (setHeader == true) {
table.setHeader(CliStrings.format(CliStrings.DESCRIBE_REGION__NONDEFAULT__PERMEMBERATTRIBUTES__HEADER, memberType));
}
}
result = ResultBuilder.buildResult(crd);
} catch (FunctionInvocationTargetException e) {
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COULD_NOT_EXECUTE_COMMAND_TRY_AGAIN, CliStrings.DESCRIBE_REGION));
} catch (Exception e) {
String errorMessage = CliStrings.format(CliStrings.EXCEPTION_CLASS_AND_MESSAGE, e.getClass().getName(), e.getMessage());
result = ResultBuilder.createGemFireErrorResult(errorMessage);
}
return result;
}
use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.
the class WanCommands method statusGatewaySender.
@CliCommand(value = CliStrings.STATUS_GATEWAYSENDER, help = CliStrings.STATUS_GATEWAYSENDER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result statusGatewaySender(@CliOption(key = CliStrings.STATUS_GATEWAYSENDER__ID, mandatory = true, optionContext = ConverterHint.GATEWAY_SENDER_ID, help = CliStrings.STATUS_GATEWAYSENDER__ID__HELP) String senderId, @CliOption(key = CliStrings.STATUS_GATEWAYSENDER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.STATUS_GATEWAYSENDER__GROUP__HELP) String[] onGroup, @CliOption(key = CliStrings.STATUS_GATEWAYSENDER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.STATUS_GATEWAYSENDER__MEMBER__HELP) String[] onMember) {
Result result = null;
if (senderId != null)
senderId = senderId.trim();
try {
InternalCache cache = getCache();
SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
GatewaySenderMXBean bean = null;
CompositeResultData crd = ResultBuilder.createCompositeResultData();
TabularResultData availableSenderData = crd.addSection(CliStrings.SECTION_GATEWAY_SENDER_AVAILABLE).addTable(CliStrings.TABLE_GATEWAY_SENDER);
TabularResultData notAvailableSenderData = crd.addSection(CliStrings.SECTION_GATEWAY_SENDER_NOT_AVAILABLE).addTable(CliStrings.TABLE_GATEWAY_SENDER);
Set<DistributedMember> dsMembers = CliUtil.findMembers(onGroup, onMember);
if (dsMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
for (DistributedMember member : dsMembers) {
if (cache.getDistributedSystem().getDistributedMember().getId().equals(member.getId())) {
bean = service.getLocalGatewaySenderMXBean(senderId);
} else {
ObjectName objectName = service.getGatewaySenderMBeanName(member, senderId);
bean = service.getMBeanProxy(objectName, GatewaySenderMXBean.class);
}
if (bean != null) {
buildSenderStatus(member.getId(), bean, availableSenderData);
} else {
buildSenderStatus(member.getId(), bean, notAvailableSenderData);
}
}
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 WanCommands method statusGatewayReceiver.
@CliCommand(value = CliStrings.STATUS_GATEWAYRECEIVER, help = CliStrings.STATUS_GATEWAYRECEIVER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result statusGatewayReceiver(@CliOption(key = CliStrings.STATUS_GATEWAYRECEIVER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.STATUS_GATEWAYRECEIVER__GROUP__HELP) String[] onGroup, @CliOption(key = CliStrings.STATUS_GATEWAYRECEIVER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.STATUS_GATEWAYRECEIVER__MEMBER__HELP) String[] onMember) {
Result result = null;
try {
InternalCache cache = getCache();
SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
CompositeResultData crd = ResultBuilder.createCompositeResultData();
TabularResultData availableReceiverData = crd.addSection(CliStrings.SECTION_GATEWAY_RECEIVER_AVAILABLE).addTable(CliStrings.TABLE_GATEWAY_RECEIVER);
TabularResultData notAvailableReceiverData = crd.addSection(CliStrings.SECTION_GATEWAY_RECEIVER_NOT_AVAILABLE).addTable(CliStrings.TABLE_GATEWAY_RECEIVER);
Set<DistributedMember> dsMembers = CliUtil.findMembers(onGroup, onMember);
if (dsMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
for (DistributedMember member : dsMembers) {
ObjectName gatewayReceiverObjectName = MBeanJMXAdapter.getGatewayReceiverMBeanName(member);
if (gatewayReceiverObjectName != null) {
GatewayReceiverMXBean receieverBean = service.getMBeanProxy(gatewayReceiverObjectName, GatewayReceiverMXBean.class);
if (receieverBean != null) {
buildReceiverStatus(member.getId(), receieverBean, availableReceiverData);
continue;
}
}
buildReceiverStatus(member.getId(), null, notAvailableReceiverData);
}
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 toCommandResult.
public Result toCommandResult() {
if (StringUtils.isEmpty(keyClass)) {
keyClass = "java.lang.String";
}
if (StringUtils.isEmpty(valueClass)) {
valueClass = "java.lang.String";
}
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 ResultBuilder.buildResult(data);
}
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 (isGet()) {
toCommandResult_isGet(section, table);
} else if (isLocateEntry()) {
toCommandResult_isLocate(section, table);
} else if (isPut()) {
toCommandResult_isPut(section, table);
} else if (isRemove()) {
toCommandResult_isRemove(section, table);
} else if (isSelect()) {
// its moved to its separate method
}
return ResultBuilder.buildResult(data);
}
Aggregations