Search in sources :

Example 11 with TabularResultData

use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.

the class StatusCommands method getSharedConfigurationStatus.

private TabularResultData getSharedConfigurationStatus(Set<DistributedMember> locators) {
    boolean isSharedConfigRunning = false;
    ResultCollector<?, ?> rc = CliUtil.executeFunction(fetchSharedConfigStatusFunction, null, locators);
    List<CliFunctionResult> results = (List<CliFunctionResult>) rc.getResult();
    TabularResultData table = ResultBuilder.createTabularResultData();
    table.setHeader("Status of shared configuration on locators");
    for (CliFunctionResult result : results) {
        table.accumulate(CliStrings.STATUS_SHARED_CONFIG_NAME_HEADER, result.getMemberIdOrName());
        String status = (String) result.getSerializables()[0];
        table.accumulate(CliStrings.STATUS_SHARED_CONFIG_STATUS, status);
        if (SharedConfigurationStatus.RUNNING.name().equals(status)) {
            isSharedConfigRunning = true;
        }
    }
    if (!isSharedConfigRunning) {
        table.setStatus(Status.ERROR);
    }
    return table;
}
Also used : CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) List(java.util.List)

Example 12 with TabularResultData

use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.

the class WanCommands method startGatewaySender.

@CliCommand(value = CliStrings.START_GATEWAYSENDER, help = CliStrings.START_GATEWAYSENDER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result startGatewaySender(@CliOption(key = CliStrings.START_GATEWAYSENDER__ID, mandatory = true, optionContext = ConverterHint.GATEWAY_SENDER_ID, help = CliStrings.START_GATEWAYSENDER__ID__HELP) String senderId, @CliOption(key = CliStrings.START_GATEWAYSENDER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.START_GATEWAYSENDER__GROUP__HELP) String[] onGroup, @CliOption(key = CliStrings.START_GATEWAYSENDER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.START_GATEWAYSENDER__MEMBER__HELP) String[] onMember) {
    Result result = null;
    final String id = senderId.trim();
    try {
        final InternalCache cache = getCache();
        final SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
        TabularResultData resultData = ResultBuilder.createTabularResultData();
        Set<DistributedMember> dsMembers = CliUtil.findMembers(onGroup, onMember);
        if (dsMembers.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        ExecutorService execService = Executors.newCachedThreadPool(new ThreadFactory() {

            AtomicInteger threadNum = new AtomicInteger();

            public Thread newThread(final Runnable r) {
                Thread result = new Thread(r, "Start Sender Command Thread " + threadNum.incrementAndGet());
                result.setDaemon(true);
                return result;
            }
        });
        List<Callable<List>> callables = new ArrayList<Callable<List>>();
        for (final DistributedMember member : dsMembers) {
            callables.add(new Callable<List>() {

                public List call() throws Exception {
                    GatewaySenderMXBean bean = null;
                    ArrayList<String> statusList = new ArrayList<String>();
                    if (cache.getDistributedSystem().getDistributedMember().getId().equals(member.getId())) {
                        bean = service.getLocalGatewaySenderMXBean(id);
                    } else {
                        ObjectName objectName = service.getGatewaySenderMBeanName(member, id);
                        bean = service.getMBeanProxy(objectName, GatewaySenderMXBean.class);
                    }
                    if (bean != null) {
                        if (bean.isRunning()) {
                            statusList.add(member.getId());
                            statusList.add(CliStrings.GATEWAY_ERROR);
                            statusList.add(CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_ALREADY_STARTED_ON_MEMBER_1, new Object[] { id, member.getId() }));
                        } else {
                            bean.start();
                            statusList.add(member.getId());
                            statusList.add(CliStrings.GATEWAY_OK);
                            statusList.add(CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_STARTED_ON_MEMBER_1, new Object[] { id, member.getId() }));
                        }
                    } else {
                        statusList.add(member.getId());
                        statusList.add(CliStrings.GATEWAY_ERROR);
                        statusList.add(CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_NOT_AVAILABLE_ON_MEMBER_1, new Object[] { id, member.getId() }));
                    }
                    return statusList;
                }
            });
        }
        Iterator<DistributedMember> memberIterator = dsMembers.iterator();
        List<Future<List>> futures = null;
        try {
            futures = execService.invokeAll(callables);
        } catch (InterruptedException ite) {
            accumulateStartResult(resultData, null, CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_SENDER_0_COULD_NOT_BE_INVOKED_DUE_TO_1, new Object[] { id, ite.getMessage() }));
        }
        for (Future<List> future : futures) {
            DistributedMember member = memberIterator.next();
            List<String> memberStatus = null;
            try {
                memberStatus = future.get();
                accumulateStartResult(resultData, memberStatus.get(0), memberStatus.get(1), memberStatus.get(2));
            } catch (InterruptedException ite) {
                accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_SENDER_0_COULD_NOT_BE_STARTED_ON_MEMBER_DUE_TO_1, new Object[] { id, ite.getMessage() }));
                continue;
            } catch (ExecutionException ee) {
                accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_SENDER_0_COULD_NOT_BE_STARTED_ON_MEMBER_DUE_TO_1, new Object[] { id, ee.getMessage() }));
                continue;
            }
        }
        execService.shutdown();
        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 : ThreadFactory(java.util.concurrent.ThreadFactory) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) Callable(java.util.concurrent.Callable) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) GatewaySenderMXBean(org.apache.geode.management.GatewaySenderMXBean) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) ExecutionException(java.util.concurrent.ExecutionException) ObjectName(javax.management.ObjectName) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DistributedMember(org.apache.geode.distributed.DistributedMember) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 13 with TabularResultData

use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.

the class WanCommands method stopGatewaySender.

@CliCommand(value = CliStrings.STOP_GATEWAYSENDER, help = CliStrings.STOP_GATEWAYSENDER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result stopGatewaySender(@CliOption(key = CliStrings.STOP_GATEWAYSENDER__ID, mandatory = true, optionContext = ConverterHint.GATEWAY_SENDER_ID, help = CliStrings.STOP_GATEWAYSENDER__ID__HELP) String senderId, @CliOption(key = CliStrings.STOP_GATEWAYSENDER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.STOP_GATEWAYSENDER__GROUP__HELP) String[] onGroup, @CliOption(key = CliStrings.STOP_GATEWAYSENDER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.STOP_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()) {
                    bean.stop();
                    accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_OK, CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_STOPPED_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 14 with TabularResultData

use of org.apache.geode.management.internal.cli.result.TabularResultData 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;
}
Also used : GatewayReceiverMXBean(org.apache.geode.management.GatewayReceiverMXBean) CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) 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 15 with TabularResultData

use of org.apache.geode.management.internal.cli.result.TabularResultData in project geode by apache.

the class DataCommandResult method pageResult.

/**
   * This method returns a "Page" as dictated by arguments startCount and endCount. Returned result
   * is not standard CommandResult and its consumed by Display Step
   */
@SuppressWarnings({ "rawtypes", "unchecked" })
public Result pageResult(int startCount, int endCount, String step) {
    List<String> fields = new ArrayList<>();
    List values = new ArrayList<String>();
    fields.add(RESULT_FLAG);
    values.add(operationCompletedSuccessfully);
    fields.add(QUERY_PAGE_START);
    values.add(startCount);
    fields.add(QUERY_PAGE_END);
    values.add(endCount);
    if (errorString != null) {
        fields.add("Message");
        values.add(errorString);
        return createBannerResult(fields, values, step);
    } else {
        if (infoString != null) {
            fields.add("Message");
            values.add(infoString);
        }
        if (selectResult != null) {
            try {
                TabularResultData table = ResultBuilder.createTabularResultData();
                String[] headers;
                Object[][] rows;
                int rowCount = buildTable(table, startCount, endCount);
                GfJsonArray array = table.getHeaders();
                headers = new String[array.size()];
                rows = new Object[rowCount][array.size()];
                for (int i = 0; i < array.size(); i++) {
                    headers[i] = (String) array.get(i);
                    List<String> list = table.retrieveAllValues(headers[i]);
                    for (int j = 0; j < list.size(); j++) {
                        rows[j][i] = list.get(j);
                    }
                }
                fields.add(NUM_ROWS);
                values.add((selectResult == null) ? 0 : selectResult.size());
                if (queryTraceString != null) {
                    fields.add(QUERY_TRACE);
                    values.add(queryTraceString);
                }
                return createPageResult(fields, values, step, headers, rows);
            } catch (GfJsonException e) {
                String[] headers = new String[] { "Error" };
                Object[][] rows = { { e.getMessage() } };
                String[] fieldsArray = { QUERY_PAGE_START, QUERY_PAGE_END };
                Object[] valuesArray = { startCount, endCount };
                return createPageResult(fieldsArray, valuesArray, step, headers, rows);
            }
        } else {
            return createBannerResult(fields, values, step);
        }
    }
}
Also used : GfJsonArray(org.apache.geode.management.internal.cli.json.GfJsonArray) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) ArrayList(java.util.ArrayList) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(org.json.JSONObject) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject)

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