Search in sources :

Example 11 with GatewaySenderMXBean

use of org.apache.geode.management.GatewaySenderMXBean in project geode by apache.

the class WanCommands method loadBalanceGatewaySender.

@CliCommand(value = CliStrings.LOAD_BALANCE_GATEWAYSENDER, help = CliStrings.LOAD_BALANCE_GATEWAYSENDER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result loadBalanceGatewaySender(@CliOption(key = CliStrings.LOAD_BALANCE_GATEWAYSENDER__ID, mandatory = true, optionContext = ConverterHint.GATEWAY_SENDER_ID, help = CliStrings.LOAD_BALANCE_GATEWAYSENDER__ID__HELP) String senderId) {
    Result result = null;
    if (senderId != null) {
        senderId = senderId.trim();
    }
    try {
        InternalCache cache = getCache();
        SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
        TabularResultData resultData = ResultBuilder.createTabularResultData();
        Set<DistributedMember> dsMembers = CliUtil.getAllNormalMembers(cache);
        if (dsMembers.isEmpty()) {
            result = ResultBuilder.createInfoResult(CliStrings.GATEWAY_MSG_MEMBERS_NOT_FOUND);
        } else {
            boolean gatewaySenderExists = false;
            for (DistributedMember member : dsMembers) {
                GatewaySenderMXBean bean = null;
                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) {
                    gatewaySenderExists = true;
                    bean.rebalance();
                    accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_OK, CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_REBALANCED_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() }));
                }
            }
            if (gatewaySenderExists) {
                result = ResultBuilder.buildResult(resultData);
            } else {
                result = ResultBuilder.createInfoResult(CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_NOT_FOUND_ON_ANY_MEMBER, new Object[] { senderId }));
            }
        }
    } 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 12 with GatewaySenderMXBean

use of org.apache.geode.management.GatewaySenderMXBean in project geode by apache.

the class TestRemoteClusterDUnitTest method checkSenderMBean.

/**
   * Checks whether a GatewayReceiverMBean is created or not
   * 
   * @param vm reference to VM
   */
@SuppressWarnings("serial")
protected void checkSenderMBean(final VM vm, final String regionPath) {
    SerializableRunnable checkMBean = new SerializableRunnable("Check Sender MBean") {

        public void run() {
            Cache cache = GemFireCacheImpl.getInstance();
            ManagementService service = ManagementService.getManagementService(cache);
            GatewaySenderMXBean bean = service.getLocalGatewaySenderMXBean("pn");
            assertNotNull(bean);
            assertTrue(bean.isConnected());
            ObjectName regionBeanName = service.getRegionMBeanName(cache.getDistributedSystem().getDistributedMember(), "/" + regionPath);
            RegionMXBean rBean = service.getMBeanInstance(regionBeanName, RegionMXBean.class);
            assertTrue(rBean.isGatewayEnabled());
        }
    };
    vm.invoke(checkMBean);
}
Also used : ManagementService(org.apache.geode.management.ManagementService) RegionMXBean(org.apache.geode.management.RegionMXBean) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) GatewaySenderMXBean(org.apache.geode.management.GatewaySenderMXBean) Cache(org.apache.geode.cache.Cache) ObjectName(javax.management.ObjectName)

Example 13 with GatewaySenderMXBean

use of org.apache.geode.management.GatewaySenderMXBean in project geode by apache.

the class TestRemoteClusterDUnitTest method startGatewaySender.

/**
   * start a gateway sender
   * 
   * @param vm reference to VM
   */
@SuppressWarnings("serial")
protected void startGatewaySender(final VM vm) {
    SerializableRunnable stopGatewaySender = new SerializableRunnable("Start Gateway Sender") {

        public void run() {
            Cache cache = GemFireCacheImpl.getInstance();
            ManagementService service = ManagementService.getManagementService(cache);
            GatewaySenderMXBean bean = service.getLocalGatewaySenderMXBean("pn");
            assertNotNull(bean);
            bean.start();
            assertTrue(bean.isRunning());
        }
    };
    vm.invoke(stopGatewaySender);
}
Also used : ManagementService(org.apache.geode.management.ManagementService) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) GatewaySenderMXBean(org.apache.geode.management.GatewaySenderMXBean) Cache(org.apache.geode.cache.Cache)

Aggregations

GatewaySenderMXBean (org.apache.geode.management.GatewaySenderMXBean)13 ObjectName (javax.management.ObjectName)10 ExecutionException (java.util.concurrent.ExecutionException)7 DistributedMember (org.apache.geode.distributed.DistributedMember)7 InternalCache (org.apache.geode.internal.cache.InternalCache)7 CliMetaData (org.apache.geode.management.cli.CliMetaData)7 Result (org.apache.geode.management.cli.Result)7 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)7 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)7 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)7 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)7 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)7 CliCommand (org.springframework.shell.core.annotation.CliCommand)7 Cache (org.apache.geode.cache.Cache)3 ManagementService (org.apache.geode.management.ManagementService)3 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)3 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 GatewayReceiverMXBean (org.apache.geode.management.GatewayReceiverMXBean)2 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)2