use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.
the class ClientCommands method listClient.
@CliCommand(value = CliStrings.LIST_CLIENTS, help = CliStrings.LIST_CLIENT__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_CLIENT })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result listClient() {
Result result = null;
try {
CompositeResultData compositeResultData = ResultBuilder.createCompositeResultData();
SectionResultData section = compositeResultData.addSection("section1");
TabularResultData resultTable = section.addTable("TableForClientList");
String headerText = "ClientList";
resultTable = resultTable.setHeader(headerText);
InternalCache cache = getCache();
ManagementService service = ManagementService.getExistingManagementService(cache);
ObjectName[] cacheServers = service.getDistributedSystemMXBean().listCacheServerObjectNames();
if (cacheServers.length == 0) {
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.LIST_CLIENT_COULD_NOT_RETRIEVE_SERVER_LIST));
}
Map<String, List<String>> clientServerMap = new HashMap<String, List<String>>();
for (ObjectName objName : cacheServers) {
CacheServerMXBean serverMbean = service.getMBeanInstance(objName, CacheServerMXBean.class);
String[] listOfClient = serverMbean.getClientIds();
if (listOfClient == null || listOfClient.length == 0) {
continue;
}
for (String clietName : listOfClient) {
String serverDetails = "member=" + objName.getKeyProperty("member") + ",port=" + objName.getKeyProperty("port");
if (clientServerMap.containsKey(clietName)) {
List<String> listServers = clientServerMap.get(clietName);
listServers.add(serverDetails);
} else {
List<String> listServer = new ArrayList<String>();
listServer.add(serverDetails);
clientServerMap.put(clietName, listServer);
}
}
}
if (clientServerMap.size() == 0) {
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.LIST_COULD_NOT_RETRIEVE_CLIENT_LIST));
}
String memberSeparator = "; ";
Iterator<Entry<String, List<String>>> it = clientServerMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, List<String>> pairs = (Map.Entry<String, List<String>>) it.next();
String client = (String) pairs.getKey();
List<String> servers = (List<String>) pairs.getValue();
StringBuilder serverListForClient = new StringBuilder();
int serversSize = servers.size();
int i = 0;
for (String server : servers) {
serverListForClient.append(server);
if (i < serversSize - 1) {
serverListForClient.append(memberSeparator);
}
i++;
}
resultTable.accumulate(CliStrings.LIST_CLIENT_COLUMN_Clients, client);
resultTable.accumulate(CliStrings.LIST_CLIENT_COLUMN_SERVERS, serverListForClient.toString());
}
result = ResultBuilder.buildResult(compositeResultData);
} catch (Exception e) {
LogWrapper.getInstance().warning("Error in list clients. stack trace" + CliUtil.stackTraceAsString(e));
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.LIST_CLIENT_COULD_NOT_RETRIEVE_CLIENT_LIST_0, e.getMessage()));
}
LogWrapper.getInstance().info("list client result " + result);
return result;
}
use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.
the class ShellCommands method describeConnection.
@CliCommand(value = { CliStrings.DESCRIBE_CONNECTION }, help = CliStrings.DESCRIBE_CONNECTION__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GFSH, CliStrings.TOPIC_GEODE_JMX })
public Result describeConnection() {
Result result = null;
try {
TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
Gfsh gfshInstance = getGfsh();
if (gfshInstance.isConnectedAndReady()) {
OperationInvoker operationInvoker = gfshInstance.getOperationInvoker();
// tabularResultData.accumulate("Monitored GemFire DS", operationInvoker.toString());
tabularResultData.accumulate("Connection Endpoints", operationInvoker.toString());
} else {
tabularResultData.accumulate("Connection Endpoints", "Not connected");
}
result = ResultBuilder.buildResult(tabularResultData);
} catch (Exception e) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
result = ResultBuilder.buildResult(errorResultData);
}
return result;
}
use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.
the class WanCommands method accumulateListGatewayResult.
private void accumulateListGatewayResult(CompositeResultData crd, Map<String, Map<String, GatewaySenderMXBean>> gatewaySenderBeans, Map<String, GatewayReceiverMXBean> gatewayReceiverBeans) {
if (!gatewaySenderBeans.isEmpty()) {
TabularResultData gatewaySenderData = crd.addSection(CliStrings.SECTION_GATEWAY_SENDER).addTable(CliStrings.TABLE_GATEWAY_SENDER).setHeader(CliStrings.HEADER_GATEWAY_SENDER);
for (Map.Entry<String, Map<String, GatewaySenderMXBean>> entry : gatewaySenderBeans.entrySet()) {
for (Map.Entry<String, GatewaySenderMXBean> memberToBean : entry.getValue().entrySet()) {
gatewaySenderData.accumulate(CliStrings.RESULT_GATEWAY_SENDER_ID, entry.getKey());
gatewaySenderData.accumulate(CliStrings.RESULT_HOST_MEMBER, memberToBean.getKey());
gatewaySenderData.accumulate(CliStrings.RESULT_REMOTE_CLUSTER, memberToBean.getValue().getRemoteDSId());
gatewaySenderData.accumulate(CliStrings.RESULT_TYPE, memberToBean.getValue().isParallel() ? CliStrings.SENDER_PARALLEL : CliStrings.SENDER_SERIAL);
gatewaySenderData.accumulate(CliStrings.RESULT_STATUS, memberToBean.getValue().isRunning() ? CliStrings.GATEWAY_RUNNING : CliStrings.GATEWAY_NOT_RUNNING);
gatewaySenderData.accumulate(CliStrings.RESULT_QUEUED_EVENTS, memberToBean.getValue().getEventQueueSize());
gatewaySenderData.accumulate(CliStrings.RESULT_RECEIVER, memberToBean.getValue().getGatewayReceiver());
}
}
}
if (!gatewayReceiverBeans.isEmpty()) {
TabularResultData gatewayReceiverData = crd.addSection(CliStrings.SECTION_GATEWAY_RECEIVER).addTable(CliStrings.TABLE_GATEWAY_RECEIVER).setHeader(CliStrings.HEADER_GATEWAY_RECEIVER);
for (Map.Entry<String, GatewayReceiverMXBean> entry : gatewayReceiverBeans.entrySet()) {
gatewayReceiverData.accumulate(CliStrings.RESULT_HOST_MEMBER, entry.getKey());
gatewayReceiverData.accumulate(CliStrings.RESULT_PORT, entry.getValue().getPort());
gatewayReceiverData.accumulate(CliStrings.RESULT_SENDERS_COUNT, entry.getValue().getClientConnectionCount());
gatewayReceiverData.accumulate(CliStrings.RESULT_SENDER_CONNECTED, entry.getValue().getConnectedGatewaySenders());
}
}
}
use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.
the class WanCommands method resumeGatewaySender.
@CliCommand(value = CliStrings.RESUME_GATEWAYSENDER, help = CliStrings.RESUME_GATEWAYSENDER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result resumeGatewaySender(@CliOption(key = CliStrings.RESUME_GATEWAYSENDER__ID, mandatory = true, optionContext = ConverterHint.GATEWAY_SENDER_ID, help = CliStrings.RESUME_GATEWAYSENDER__ID__HELP) String senderId, @CliOption(key = CliStrings.RESUME_GATEWAYSENDER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.RESUME_GATEWAYSENDER__GROUP__HELP) String[] onGroup, @CliOption(key = CliStrings.RESUME_GATEWAYSENDER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.RESUME_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;
TabularResultData resultData = ResultBuilder.createTabularResultData();
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) {
if (bean.isRunning()) {
if (bean.isPaused()) {
bean.resume();
accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_OK, CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_RESUMED_ON_MEMBER_1, new Object[] { senderId, member.getId() }));
} else {
accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_NOT_PAUSED_ON_MEMBER_1, new Object[] { senderId, member.getId() }));
}
} else {
accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_NOT_RUNNING_ON_MEMBER_1, new Object[] { senderId, member.getId() }));
}
} else {
accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_NOT_AVAILABLE_ON_MEMBER_1, new Object[] { senderId, member.getId() }));
}
}
result = ResultBuilder.buildResult(resultData);
} 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.TabularResultData in project geode by apache.
the class ShellCommands method echo.
@CliCommand(value = { CliStrings.ECHO }, help = CliStrings.ECHO__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GFSH })
public Result echo(@CliOption(key = { CliStrings.ECHO__STR, "" }, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = "", mandatory = true, help = CliStrings.ECHO__STR__HELP) String stringToEcho) {
Result result = null;
if (stringToEcho.equals("$*")) {
Gfsh gfshInstance = getGfsh();
Map<String, String> envMap = gfshInstance.getEnv();
Set<Entry<String, String>> setEnvMap = envMap.entrySet();
TabularResultData resultData = buildResultForEcho(setEnvMap);
result = ResultBuilder.buildResult(resultData);
} else {
result = ResultBuilder.createInfoResult(stringToEcho);
}
return result;
}
Aggregations