Search in sources :

Example 41 with ResourceOperation

use of org.apache.geode.management.internal.security.ResourceOperation in project geode by apache.

the class StatusCommands method statusSharedConfiguration.

@SuppressWarnings("unchecked")
@CliCommand(value = CliStrings.STATUS_SHARED_CONFIG, help = CliStrings.STATUS_SHARED_CONFIG_HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_LOCATOR)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result statusSharedConfiguration() {
    final InternalCache cache = GemFireCacheImpl.getInstance();
    final Set<DistributedMember> locators = new HashSet<DistributedMember>(cache.getDistributionManager().getAllHostedLocatorsWithSharedConfiguration().keySet());
    if (locators.isEmpty()) {
        return ResultBuilder.createInfoResult(CliStrings.NO_LOCATORS_WITH_SHARED_CONFIG);
    } else {
        return ResultBuilder.buildResult(getSharedConfigurationStatus(locators));
    }
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) HashSet(java.util.HashSet) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 42 with ResourceOperation

use of org.apache.geode.management.internal.security.ResourceOperation 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 43 with ResourceOperation

use of org.apache.geode.management.internal.security.ResourceOperation in project geode by apache.

the class WanCommands method pauseGatewaySender.

@CliCommand(value = CliStrings.PAUSE_GATEWAYSENDER, help = CliStrings.PAUSE_GATEWAYSENDER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result pauseGatewaySender(@CliOption(key = CliStrings.PAUSE_GATEWAYSENDER__ID, mandatory = true, optionContext = ConverterHint.GATEWAY_SENDER_ID, help = CliStrings.PAUSE_GATEWAYSENDER__ID__HELP) String senderId, @CliOption(key = CliStrings.PAUSE_GATEWAYSENDER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.PAUSE_GATEWAYSENDER__GROUP__HELP) String[] onGroup, @CliOption(key = CliStrings.PAUSE_GATEWAYSENDER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.PAUSE_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()) {
                        accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_ALREADY_PAUSED_ON_MEMBER_1, new Object[] { senderId, member.getId() }));
                    } else {
                        bean.pause();
                        accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_OK, CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_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 44 with ResourceOperation

use of org.apache.geode.management.internal.security.ResourceOperation in project geode by apache.

the class WanCommands method startGatewayReceiver.

@CliCommand(value = CliStrings.START_GATEWAYRECEIVER, help = CliStrings.START_GATEWAYRECEIVER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result startGatewayReceiver(@CliOption(key = CliStrings.START_GATEWAYRECEIVER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.START_GATEWAYRECEIVER__GROUP__HELP) String[] onGroup, @CliOption(key = CliStrings.START_GATEWAYRECEIVER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.START_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()) {
                        accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_RECEIVER_IS_ALREADY_STARTED_ON_MEMBER_0, new Object[] { member.getId() }));
                    } else {
                        receieverBean.start();
                        accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_OK, CliStrings.format(CliStrings.GATEWAY_RECEIVER_IS_STARTED_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 45 with ResourceOperation

use of org.apache.geode.management.internal.security.ResourceOperation in project geode by apache.

the class WanCommands method listGateway.

@CliCommand(value = CliStrings.LIST_GATEWAY, help = CliStrings.LIST_GATEWAY__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result listGateway(@CliOption(key = CliStrings.LIST_GATEWAY__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.LIST_GATEWAY__MEMBER__HELP) String[] onMember, @CliOption(key = CliStrings.LIST_GATEWAY__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.LIST_GATEWAY__GROUP__HELP) String[] onGroup) {
    Result result = null;
    InternalCache cache = getCache();
    try {
        SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
        Set<DistributedMember> dsMembers = CliUtil.findMembers(onGroup, onMember);
        if (dsMembers.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        Map<String, Map<String, GatewaySenderMXBean>> gatewaySenderBeans = new TreeMap<String, Map<String, GatewaySenderMXBean>>();
        Map<String, GatewayReceiverMXBean> gatewayReceiverBeans = new TreeMap<String, GatewayReceiverMXBean>();
        DistributedSystemMXBean dsMXBean = service.getDistributedSystemMXBean();
        for (DistributedMember member : dsMembers) {
            String memberName = member.getName();
            String memberNameOrId = (memberName != null && !memberName.isEmpty()) ? memberName : member.getId();
            ObjectName[] gatewaySenderObjectNames = dsMXBean.listGatewaySenderObjectNames(memberNameOrId);
            // on it
            if (gatewaySenderObjectNames != null) {
                for (ObjectName name : gatewaySenderObjectNames) {
                    GatewaySenderMXBean senderBean = service.getMBeanProxy(name, GatewaySenderMXBean.class);
                    if (senderBean != null) {
                        if (gatewaySenderBeans.containsKey(senderBean.getSenderId())) {
                            Map<String, GatewaySenderMXBean> memberToBeanMap = gatewaySenderBeans.get(senderBean.getSenderId());
                            memberToBeanMap.put(member.getId(), senderBean);
                        } else {
                            Map<String, GatewaySenderMXBean> memberToBeanMap = new TreeMap<String, GatewaySenderMXBean>();
                            memberToBeanMap.put(member.getId(), senderBean);
                            gatewaySenderBeans.put(senderBean.getSenderId(), memberToBeanMap);
                        }
                    }
                }
            }
            // gateway receivers : a member can have only one gateway receiver
            ObjectName gatewayReceiverObjectName = MBeanJMXAdapter.getGatewayReceiverMBeanName(member);
            if (gatewayReceiverObjectName != null) {
                GatewayReceiverMXBean receieverBean = null;
                receieverBean = service.getMBeanProxy(gatewayReceiverObjectName, GatewayReceiverMXBean.class);
                if (receieverBean != null) {
                    gatewayReceiverBeans.put(member.getId(), receieverBean);
                }
            }
        }
        if (gatewaySenderBeans.isEmpty() && gatewayReceiverBeans.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.GATEWAYS_ARE_NOT_AVAILABLE_IN_CLUSTER);
        }
        CompositeResultData crd = ResultBuilder.createCompositeResultData();
        crd.setHeader(CliStrings.HEADER_GATEWAYS);
        accumulateListGatewayResult(crd, gatewaySenderBeans, gatewayReceiverBeans);
        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 : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) InternalCache(org.apache.geode.internal.cache.InternalCache) TreeMap(java.util.TreeMap) 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) GatewayReceiverMXBean(org.apache.geode.management.GatewayReceiverMXBean) DistributedSystemMXBean(org.apache.geode.management.DistributedSystemMXBean) DistributedMember(org.apache.geode.distributed.DistributedMember) Map(java.util.Map) TreeMap(java.util.TreeMap) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Aggregations

ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)58 CliCommand (org.springframework.shell.core.annotation.CliCommand)57 CliMetaData (org.apache.geode.management.cli.CliMetaData)55 DistributedMember (org.apache.geode.distributed.DistributedMember)49 Result (org.apache.geode.management.cli.Result)49 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)32 InternalCache (org.apache.geode.internal.cache.InternalCache)30 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)30 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)27 ArrayList (java.util.ArrayList)18 List (java.util.List)18 ExecutionException (java.util.concurrent.ExecutionException)15 GfshParseResult (org.apache.geode.management.internal.cli.GfshParseResult)14 ObjectName (javax.management.ObjectName)13 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)13 IOException (java.io.IOException)11 HashSet (java.util.HashSet)11 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)11 HashMap (java.util.HashMap)10 ConverterHint (org.apache.geode.management.cli.ConverterHint)10