Search in sources :

Example 86 with TabularResultData

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;
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheServerMXBean(org.apache.geode.management.CacheServerMXBean) Result(org.apache.geode.management.cli.Result) ObjectName(javax.management.ObjectName) Entry(java.util.Map.Entry) ManagementService(org.apache.geode.management.ManagementService) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 87 with TabularResultData

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;
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) RestHttpOperationInvoker(org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker) OperationInvoker(org.apache.geode.management.internal.cli.shell.OperationInvoker) HttpOperationInvoker(org.apache.geode.management.internal.web.shell.HttpOperationInvoker) JmxOperationInvoker(org.apache.geode.management.internal.cli.shell.JmxOperationInvoker) Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Result(org.apache.geode.management.cli.Result) ConnectToLocatorResult(org.apache.geode.management.internal.cli.domain.ConnectToLocatorResult) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 88 with TabularResultData

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());
        }
    }
}
Also used : GatewayReceiverMXBean(org.apache.geode.management.GatewayReceiverMXBean) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) Map(java.util.Map) TreeMap(java.util.TreeMap) GatewaySenderMXBean(org.apache.geode.management.GatewaySenderMXBean)

Example 89 with TabularResultData

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;
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) GatewaySenderMXBean(org.apache.geode.management.GatewaySenderMXBean) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) ExecutionException(java.util.concurrent.ExecutionException) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) ObjectName(javax.management.ObjectName) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 90 with TabularResultData

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;
}
Also used : Entry(java.util.Map.Entry) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) Result(org.apache.geode.management.cli.Result) ConnectToLocatorResult(org.apache.geode.management.internal.cli.domain.ConnectToLocatorResult) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Aggregations

TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)140 Test (org.junit.Test)74 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)68 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)63 Properties (java.util.Properties)54 DistributedMember (org.apache.geode.distributed.DistributedMember)40 CliCommand (org.springframework.shell.core.annotation.CliCommand)35 Result (org.apache.geode.management.cli.Result)34 CliMetaData (org.apache.geode.management.cli.CliMetaData)33 InternalCache (org.apache.geode.internal.cache.InternalCache)32 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)31 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)30 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)29 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)29 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)28 VM (org.apache.geode.test.dunit.VM)27 ArrayList (java.util.ArrayList)26 SectionResultData (org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)23 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)18 List (java.util.List)16