Search in sources :

Example 31 with CliMetaData

use of org.apache.geode.management.cli.CliMetaData in project geode by apache.

the class WanCommands method stopGatewayReceiver.

@CliCommand(value = CliStrings.STOP_GATEWAYRECEIVER, help = CliStrings.STOP_GATEWAYRECEIVER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result stopGatewayReceiver(@CliOption(key = CliStrings.STOP_GATEWAYRECEIVER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.STOP_GATEWAYRECEIVER__GROUP__HELP) String[] onGroup, @CliOption(key = CliStrings.STOP_GATEWAYRECEIVER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.STOP_GATEWAYRECEIVER__MEMBER__HELP) String[] onMember) {
    Result result = null;
    try {
        InternalCache cache = getCache();
        SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
        GatewayReceiverMXBean receieverBean = 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) {
            ObjectName gatewayReceiverObjectName = MBeanJMXAdapter.getGatewayReceiverMBeanName(member);
            if (gatewayReceiverObjectName != null) {
                receieverBean = service.getMBeanProxy(gatewayReceiverObjectName, GatewayReceiverMXBean.class);
                if (receieverBean != null) {
                    if (receieverBean.isRunning()) {
                        receieverBean.stop();
                        accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_OK, CliStrings.format(CliStrings.GATEWAY_RECEIVER_IS_STOPPED_ON_MEMBER_0, new Object[] { member.getId() }));
                    } else {
                        accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_RECEIVER_IS_NOT_RUNNING_ON_MEMBER_0, new Object[] { member.getId() }));
                    }
                } else {
                    accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_RECEIVER_IS_NOT_AVAILABLE_ON_MEMBER_0, new Object[] { member.getId() }));
                }
            } else {
                accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_RECEIVER_IS_NOT_AVAILABLE_ON_MEMBER_0, new Object[] { member.getId() }));
            }
        }
        result = ResultBuilder.buildResult(resultData);
    } catch (CommandResultException crex) {
        result = handleCommandResultException(crex);
    } 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) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) 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 32 with CliMetaData

use of org.apache.geode.management.cli.CliMetaData in project geode by apache.

the class WanCommands method createGatewayReceiver.

@CliCommand(value = CliStrings.CREATE_GATEWAYRECEIVER, help = CliStrings.CREATE_GATEWAYRECEIVER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result createGatewayReceiver(@CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.CREATE_GATEWAYRECEIVER__GROUP__HELP) String[] onGroups, @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CREATE_GATEWAYRECEIVER__MEMBER__HELP) String[] onMember, @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__MANUALSTART, help = CliStrings.CREATE_GATEWAYRECEIVER__MANUALSTART__HELP) Boolean manualStart, @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__STARTPORT, help = CliStrings.CREATE_GATEWAYRECEIVER__STARTPORT__HELP) Integer startPort, @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__ENDPORT, help = CliStrings.CREATE_GATEWAYRECEIVER__ENDPORT__HELP) Integer endPort, @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__BINDADDRESS, help = CliStrings.CREATE_GATEWAYRECEIVER__BINDADDRESS__HELP) String bindAddress, @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__MAXTIMEBETWEENPINGS, help = CliStrings.CREATE_GATEWAYRECEIVER__MAXTIMEBETWEENPINGS__HELP) Integer maximumTimeBetweenPings, @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__SOCKETBUFFERSIZE, help = CliStrings.CREATE_GATEWAYRECEIVER__SOCKETBUFFERSIZE__HELP) Integer socketBufferSize, @CliOption(key = CliStrings.CREATE_GATEWAYRECEIVER__GATEWAYTRANSPORTFILTER, help = CliStrings.CREATE_GATEWAYRECEIVER__GATEWAYTRANSPORTFILTER__HELP) String[] gatewayTransportFilters) {
    Result result = null;
    AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
    try {
        GatewayReceiverFunctionArgs gatewayReceiverFunctionArgs = new GatewayReceiverFunctionArgs(manualStart, startPort, endPort, bindAddress, socketBufferSize, maximumTimeBetweenPings, gatewayTransportFilters);
        Set<DistributedMember> membersToCreateGatewayReceiverOn = CliUtil.findMembers(onGroups, onMember);
        if (membersToCreateGatewayReceiverOn.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        ResultCollector<?, ?> resultCollector = CliUtil.executeFunction(GatewayReceiverCreateFunction.INSTANCE, gatewayReceiverFunctionArgs, membersToCreateGatewayReceiverOn);
        @SuppressWarnings("unchecked") List<CliFunctionResult> gatewayReceiverCreateResults = (List<CliFunctionResult>) resultCollector.getResult();
        TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
        final String errorPrefix = "ERROR: ";
        for (CliFunctionResult gatewayReceiverCreateResult : gatewayReceiverCreateResults) {
            boolean success = gatewayReceiverCreateResult.isSuccessful();
            tabularResultData.accumulate("Member", gatewayReceiverCreateResult.getMemberIdOrName());
            tabularResultData.accumulate("Status", (success ? "" : errorPrefix) + gatewayReceiverCreateResult.getMessage());
            if (success && xmlEntity.get() == null) {
                xmlEntity.set(gatewayReceiverCreateResult.getXmlEntity());
            }
        }
        result = ResultBuilder.buildResult(tabularResultData);
    } catch (IllegalArgumentException e) {
        LogWrapper.getInstance().info(e.getMessage());
        result = ResultBuilder.createUserErrorResult(e.getMessage());
    }
    if (xmlEntity.get() != null) {
        persistClusterConfiguration(result, () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), onGroups));
    }
    return result;
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) AtomicReference(java.util.concurrent.atomic.AtomicReference) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) DistributedMember(org.apache.geode.distributed.DistributedMember) ArrayList(java.util.ArrayList) List(java.util.List) GatewayReceiverFunctionArgs(org.apache.geode.management.internal.cli.functions.GatewayReceiverFunctionArgs) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 33 with CliMetaData

use of org.apache.geode.management.cli.CliMetaData in project geode by apache.

the class WanCommands method createGatewaySender.

@CliCommand(value = CliStrings.CREATE_GATEWAYSENDER, help = CliStrings.CREATE_GATEWAYSENDER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result createGatewaySender(@CliOption(key = CliStrings.CREATE_GATEWAYSENDER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.CREATE_GATEWAYSENDER__GROUP__HELP) String[] onGroups, @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CREATE_GATEWAYSENDER__MEMBER__HELP) String[] onMember, @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__ID, mandatory = true, help = CliStrings.CREATE_GATEWAYSENDER__ID__HELP) String id, @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__REMOTEDISTRIBUTEDSYSTEMID, mandatory = true, help = CliStrings.CREATE_GATEWAYSENDER__REMOTEDISTRIBUTEDSYSTEMID__HELP) Integer remoteDistributedSystemId, @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__PARALLEL, help = CliStrings.CREATE_GATEWAYSENDER__PARALLEL__HELP) Boolean parallel, @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__MANUALSTART, help = CliStrings.CREATE_GATEWAYSENDER__MANUALSTART__HELP) Boolean manualStart, @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__SOCKETBUFFERSIZE, help = CliStrings.CREATE_GATEWAYSENDER__SOCKETBUFFERSIZE__HELP) Integer socketBufferSize, @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__SOCKETREADTIMEOUT, help = CliStrings.CREATE_GATEWAYSENDER__SOCKETREADTIMEOUT__HELP) Integer socketReadTimeout, @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__ENABLEBATCHCONFLATION, help = CliStrings.CREATE_GATEWAYSENDER__ENABLEBATCHCONFLATION__HELP) Boolean enableBatchConflation, @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__BATCHSIZE, help = CliStrings.CREATE_GATEWAYSENDER__BATCHSIZE__HELP) Integer batchSize, @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__BATCHTIMEINTERVAL, help = CliStrings.CREATE_GATEWAYSENDER__BATCHTIMEINTERVAL__HELP) Integer batchTimeInterval, @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__ENABLEPERSISTENCE, help = CliStrings.CREATE_GATEWAYSENDER__ENABLEPERSISTENCE__HELP) Boolean enablePersistence, @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__DISKSTORENAME, help = CliStrings.CREATE_GATEWAYSENDER__DISKSTORENAME__HELP) String diskStoreName, @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__DISKSYNCHRONOUS, help = CliStrings.CREATE_GATEWAYSENDER__DISKSYNCHRONOUS__HELP) Boolean diskSynchronous, @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__MAXQUEUEMEMORY, help = CliStrings.CREATE_GATEWAYSENDER__MAXQUEUEMEMORY__HELP) Integer maxQueueMemory, @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__ALERTTHRESHOLD, help = CliStrings.CREATE_GATEWAYSENDER__ALERTTHRESHOLD__HELP) Integer alertThreshold, @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__DISPATCHERTHREADS, help = CliStrings.CREATE_GATEWAYSENDER__DISPATCHERTHREADS__HELP) Integer dispatcherThreads, @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__ORDERPOLICY, help = CliStrings.CREATE_GATEWAYSENDER__ORDERPOLICY__HELP) String orderPolicy, @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__GATEWAYEVENTFILTER, help = CliStrings.CREATE_GATEWAYSENDER__GATEWAYEVENTFILTER__HELP) String[] gatewayEventFilters, @CliOption(key = CliStrings.CREATE_GATEWAYSENDER__GATEWAYTRANSPORTFILTER, help = CliStrings.CREATE_GATEWAYSENDER__GATEWAYTRANSPORTFILTER__HELP) String[] gatewayTransportFilter) {
    Result result = null;
    AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
    try {
        GatewaySenderFunctionArgs gatewaySenderFunctionArgs = new GatewaySenderFunctionArgs(id, remoteDistributedSystemId, parallel, manualStart, socketBufferSize, socketReadTimeout, enableBatchConflation, batchSize, batchTimeInterval, enablePersistence, diskStoreName, diskSynchronous, maxQueueMemory, alertThreshold, dispatcherThreads, orderPolicy, gatewayEventFilters, gatewayTransportFilter);
        Set<DistributedMember> membersToCreateGatewaySenderOn = CliUtil.findMembers(onGroups, onMember);
        if (membersToCreateGatewaySenderOn.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        ResultCollector<?, ?> resultCollector = CliUtil.executeFunction(GatewaySenderCreateFunction.INSTANCE, gatewaySenderFunctionArgs, membersToCreateGatewaySenderOn);
        @SuppressWarnings("unchecked") List<CliFunctionResult> gatewaySenderCreateResults = (List<CliFunctionResult>) resultCollector.getResult();
        TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
        final String errorPrefix = "ERROR: ";
        for (CliFunctionResult gatewaySenderCreateResult : gatewaySenderCreateResults) {
            boolean success = gatewaySenderCreateResult.isSuccessful();
            tabularResultData.accumulate("Member", gatewaySenderCreateResult.getMemberIdOrName());
            tabularResultData.accumulate("Status", (success ? "" : errorPrefix) + gatewaySenderCreateResult.getMessage());
            if (success && xmlEntity.get() == null) {
                xmlEntity.set(gatewaySenderCreateResult.getXmlEntity());
            }
        }
        result = ResultBuilder.buildResult(tabularResultData);
    } catch (IllegalArgumentException e) {
        LogWrapper.getInstance().info(e.getMessage());
        result = ResultBuilder.createUserErrorResult(e.getMessage());
    }
    if (xmlEntity.get() != null) {
        persistClusterConfiguration(result, () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), onGroups));
    }
    return result;
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) GatewaySenderFunctionArgs(org.apache.geode.management.internal.cli.functions.GatewaySenderFunctionArgs) AtomicReference(java.util.concurrent.atomic.AtomicReference) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) DistributedMember(org.apache.geode.distributed.DistributedMember) ArrayList(java.util.ArrayList) List(java.util.List) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 34 with CliMetaData

use of org.apache.geode.management.cli.CliMetaData 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 35 with CliMetaData

use of org.apache.geode.management.cli.CliMetaData 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)

Aggregations

CliMetaData (org.apache.geode.management.cli.CliMetaData)94 CliCommand (org.springframework.shell.core.annotation.CliCommand)93 Result (org.apache.geode.management.cli.Result)65 DistributedMember (org.apache.geode.distributed.DistributedMember)58 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)56 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)40 InternalCache (org.apache.geode.internal.cache.InternalCache)37 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)33 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)31 ArrayList (java.util.ArrayList)28 List (java.util.List)24 ConverterHint (org.apache.geode.management.cli.ConverterHint)22 IOException (java.io.IOException)20 InfoResultData (org.apache.geode.management.internal.cli.result.InfoResultData)17 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)16 ExecutionException (java.util.concurrent.ExecutionException)15 GfshParseResult (org.apache.geode.management.internal.cli.GfshParseResult)15 XmlEntity (org.apache.geode.management.internal.configuration.domain.XmlEntity)15 HashSet (java.util.HashSet)14 ObjectName (javax.management.ObjectName)14