use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.
the class ClientCommands method buildTableResult.
private void buildTableResult(SectionResultData sectionResult, ClientHealthStatus clientHealthStatus, String isDurable, List<String> primaryServers, List<String> secondaryServers) {
StringBuilder primServers = new StringBuilder();
for (String primaryServer : primaryServers) {
primServers.append(primaryServer);
}
StringBuilder secondServers = new StringBuilder();
for (String secondServer : secondaryServers) {
secondServers.append(secondServer);
}
if (clientHealthStatus != null) {
sectionResult.addSeparator('-');
sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_PRIMARY_SERVERS, primServers);
sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_SECONDARY_SERVERS, secondServers);
sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_CPU, clientHealthStatus.getCpus());
sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_LISTNER_CALLS, clientHealthStatus.getNumOfCacheListenerCalls());
sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_GETS, clientHealthStatus.getNumOfGets());
sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_MISSES, clientHealthStatus.getNumOfMisses());
sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_PUTS, clientHealthStatus.getNumOfPuts());
sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_THREADS, clientHealthStatus.getNumOfThreads());
sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_PROCESS_CPU_TIME, clientHealthStatus.getProcessCpuTime());
sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_QUEUE_SIZE, clientHealthStatus.getQueueSize());
sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_UP_TIME, clientHealthStatus.getUpTime());
sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_DURABLE, isDurable);
sectionResult.addSeparator('-');
Map<String, String> poolStats = clientHealthStatus.getPoolStats();
if (poolStats.size() > 0) {
Iterator<Entry<String, String>> it = poolStats.entrySet().iterator();
while (it.hasNext()) {
Entry<String, String> entry = it.next();
TabularResultData poolStatsResultTable = sectionResult.addTable("Pool Stats For Pool Name = " + entry.getKey());
poolStatsResultTable.setHeader("Pool Stats For Pool Name = " + entry.getKey());
String poolStatsStr = entry.getValue();
String[] str = poolStatsStr.split(";");
LogWrapper.getInstance().info("decribe client clientHealthStatus min conn=" + str[0].substring(str[0].indexOf("=") + 1));
LogWrapper.getInstance().info("decribe client clientHealthStatus max conn =" + str[1].substring(str[1].indexOf("=") + 1));
LogWrapper.getInstance().info("decribe client clientHealthStatus redundancy =" + str[2].substring(str[2].indexOf("=") + 1));
LogWrapper.getInstance().info("decribe client clientHealthStatus CQs =" + str[3].substring(str[3].indexOf("=") + 1));
poolStatsResultTable.accumulate(CliStrings.DESCRIBE_CLIENT_MIN_CONN, str[0].substring(str[0].indexOf("=") + 1));
poolStatsResultTable.accumulate(CliStrings.DESCRIBE_CLIENT_MAX_CONN, str[1].substring(str[1].indexOf("=") + 1));
poolStatsResultTable.accumulate(CliStrings.DESCRIBE_CLIENT_REDUDANCY, str[2].substring(str[2].indexOf("=") + 1));
poolStatsResultTable.accumulate(CliStrings.DESCRIBE_CLIENT_CQs, str[3].substring(str[3].indexOf("=") + 1));
}
}
}
}
use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.
the class ConfigCommands method describeConfig.
@CliCommand(value = { CliStrings.DESCRIBE_CONFIG }, help = CliStrings.DESCRIBE_CONFIG__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_CONFIG })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result describeConfig(@CliOption(key = CliStrings.DESCRIBE_CONFIG__MEMBER, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.DESCRIBE_CONFIG__MEMBER__HELP, mandatory = true) String memberNameOrId, @CliOption(key = CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS, help = CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS__HELP, unspecifiedDefaultValue = "true", specifiedDefaultValue = "true") boolean hideDefaults) {
Result result = null;
try {
DistributedMember targetMember = null;
if (memberNameOrId != null && !memberNameOrId.isEmpty()) {
targetMember = CliUtil.getDistributedMemberByNameOrId(memberNameOrId);
}
if (targetMember != null) {
ResultCollector<?, ?> rc = CliUtil.executeFunction(getMemberConfigFunction, new Boolean(hideDefaults), targetMember);
ArrayList<?> output = (ArrayList<?>) rc.getResult();
Object obj = output.get(0);
if (obj != null && obj instanceof MemberConfigurationInfo) {
MemberConfigurationInfo memberConfigInfo = (MemberConfigurationInfo) obj;
CompositeResultData crd = ResultBuilder.createCompositeResultData();
crd.setHeader(CliStrings.format(CliStrings.DESCRIBE_CONFIG__HEADER__TEXT, memberNameOrId));
List<String> jvmArgsList = memberConfigInfo.getJvmInputArguments();
TabularResultData jvmInputArgs = crd.addSection().addSection().addTable();
for (String jvmArg : jvmArgsList) {
jvmInputArgs.accumulate("JVM command line arguments", jvmArg);
}
addSection(crd, memberConfigInfo.getGfePropsSetUsingApi(), "GemFire properties defined using the API");
addSection(crd, memberConfigInfo.getGfePropsRuntime(), "GemFire properties defined at the runtime");
addSection(crd, memberConfigInfo.getGfePropsSetFromFile(), "GemFire properties defined with the property file");
addSection(crd, memberConfigInfo.getGfePropsSetWithDefaults(), "GemFire properties using default values");
addSection(crd, memberConfigInfo.getCacheAttributes(), "Cache attributes");
List<Map<String, String>> cacheServerAttributesList = memberConfigInfo.getCacheServerAttributes();
if (cacheServerAttributesList != null && !cacheServerAttributesList.isEmpty()) {
SectionResultData cacheServerSection = crd.addSection();
cacheServerSection.setHeader("Cache-server attributes");
for (Map<String, String> cacheServerAttributes : cacheServerAttributesList) {
addSubSection(cacheServerSection, cacheServerAttributes, "");
}
}
result = ResultBuilder.buildResult(crd);
}
} else {
ErrorResultData erd = ResultBuilder.createErrorResultData();
erd.addLine(CliStrings.format(CliStrings.DESCRIBE_CONFIG__MEMBER__NOT__FOUND, new Object[] { memberNameOrId }));
result = ResultBuilder.buildResult(erd);
}
} catch (FunctionInvocationTargetException e) {
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COULD_NOT_EXECUTE_COMMAND_TRY_AGAIN, CliStrings.DESCRIBE_CONFIG));
} catch (Exception e) {
ErrorResultData erd = ResultBuilder.createErrorResultData();
erd.addLine(e.getMessage());
result = ResultBuilder.buildResult(erd);
}
return result;
}
use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.
the class CLIMultiStepHelper method createPageTableAndBanner.
private static void createPageTableAndBanner(SectionResultData page, String[] header, Object[][] table) {
TabularResultData resultData = page.addTable();
int columns = header.length;
for (int i = 0; i < table.length; i++) {
int rowLength = table[i].length;
if (rowLength != columns)
throw new RuntimeException("Row contains more than " + columns + " : " + rowLength);
}
for (int i = 0; i < table.length; i++) {
for (int j = 0; j < columns; j++) {
resultData.accumulate(header[j], table[i][j]);
}
}
}
use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.
the class QueueCommands method listAsyncEventQueues.
@CliCommand(value = CliStrings.LIST_ASYNC_EVENT_QUEUES, help = CliStrings.LIST_ASYNC_EVENT_QUEUES__HELP)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result listAsyncEventQueues() {
try {
TabularResultData tabularData = ResultBuilder.createTabularResultData();
boolean accumulatedData = false;
Set<DistributedMember> targetMembers = CliUtil.findMembers(null, null);
if (targetMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
ResultCollector<?, ?> rc = CliUtil.executeFunction(new ListAsyncEventQueuesFunction(), new Object[] {}, targetMembers);
List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult());
for (CliFunctionResult result : results) {
if (result.getThrowable() != null) {
tabularData.accumulate("Member", result.getMemberIdOrName());
tabularData.accumulate("Result", "ERROR: " + result.getThrowable().getClass().getName() + ": " + result.getThrowable().getMessage());
accumulatedData = true;
tabularData.setStatus(Status.ERROR);
} else {
AsyncEventQueueDetails[] details = (AsyncEventQueueDetails[]) result.getSerializables();
for (int i = 0; i < details.length; i++) {
tabularData.accumulate("Member", result.getMemberIdOrName());
tabularData.accumulate("ID", details[i].getId());
tabularData.accumulate("Batch Size", details[i].getBatchSize());
tabularData.accumulate("Persistent", details[i].isPersistent());
tabularData.accumulate("Disk Store", details[i].getDiskStoreName());
tabularData.accumulate("Max Memory", details[i].getMaxQueueMemory());
Properties listenerProperties = details[i].getListenerProperties();
if (listenerProperties == null || listenerProperties.size() == 0) {
tabularData.accumulate("Listener", details[i].getListener());
} else {
StringBuilder propsStringBuilder = new StringBuilder();
propsStringBuilder.append('(');
boolean firstProperty = true;
for (Map.Entry<Object, Object> property : listenerProperties.entrySet()) {
if (!firstProperty) {
propsStringBuilder.append(',');
} else {
firstProperty = false;
}
propsStringBuilder.append(property.getKey()).append('=').append(property.getValue());
}
propsStringBuilder.append(')');
tabularData.accumulate("Listener", details[i].getListener() + propsStringBuilder.toString());
}
accumulatedData = true;
}
}
}
if (!accumulatedData) {
return ResultBuilder.createInfoResult(CliStrings.LIST_ASYNC_EVENT_QUEUES__NO_QUEUES_FOUND_MESSAGE);
}
return ResultBuilder.buildResult(tabularData);
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable th) {
SystemFailure.checkFailure();
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.LIST_ASYNC_EVENT_QUEUES__ERROR_WHILE_LISTING_REASON_0, new Object[] { th.getMessage() }));
}
}
use of org.apache.geode.management.internal.cli.result.TabularResultData 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;
}
Aggregations