Search in sources :

Example 1 with MemberInformation

use of org.apache.geode.management.internal.cli.domain.MemberInformation in project geode by apache.

the class GetMemberInformationFunction method execute.

@Override
public void execute(FunctionContext functionContext) {
    try {
        Cache cache = CacheFactory.getAnyInstance();
        /*
       * TODO: 1) Get the CPU usage%
       */
        InternalDistributedSystem system = (InternalDistributedSystem) cache.getDistributedSystem();
        DistributionConfig config = system.getConfig();
        String serverBindAddress = config.getServerBindAddress();
        MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
        MemberInformation memberInfo = new MemberInformation();
        memberInfo.setGroups(config.getGroups());
        memberInfo.setLogFilePath(config.getLogFile().getCanonicalPath());
        memberInfo.setStatArchiveFilePath(config.getStatisticArchiveFile().getCanonicalPath());
        memberInfo.setWorkingDirPath(System.getProperty("user.dir"));
        memberInfo.setCacheXmlFilePath(config.getCacheXmlFile().getCanonicalPath());
        memberInfo.setLocators(config.getLocators());
        memberInfo.setServerBindAddress(serverBindAddress);
        memberInfo.setOffHeapMemorySize(config.getOffHeapMemorySize());
        MemoryUsage memUsage = memoryMXBean.getHeapMemoryUsage();
        memberInfo.setHeapUsage(Long.toString(bytesToMeg(memUsage.getUsed())));
        memberInfo.setMaxHeapSize(Long.toString(bytesToMeg(memUsage.getMax())));
        memberInfo.setInitHeapSize(Long.toString(bytesToMeg(memUsage.getInit())));
        memberInfo.setHostedRegions(CliUtil.getAllRegionNames());
        List<CacheServer> csList = cache.getCacheServers();
        // A member is a server only if it has a cacheserver
        if (csList != null) {
            memberInfo.setServer(true);
            Iterator<CacheServer> iters = csList.iterator();
            while (iters.hasNext()) {
                CacheServer cs = iters.next();
                String bindAddress = cs.getBindAddress();
                int port = cs.getPort();
                boolean isRunning = cs.isRunning();
                CacheServerInfo cacheServerInfo = new CacheServerInfo(bindAddress, port, isRunning);
                memberInfo.addCacheServerInfo(cacheServerInfo);
            }
            Map<ClientProxyMembershipID, CacheClientStatus> allConnectedClients = InternalClientMembership.getStatusForAllClientsIgnoreSubscriptionStatus();
            Iterator<ClientProxyMembershipID> it = allConnectedClients.keySet().iterator();
            int numConnections = 0;
            while (it.hasNext()) {
                CacheClientStatus status = allConnectedClients.get(it.next());
                numConnections = numConnections + status.getNumberOfConnections();
            }
            memberInfo.setClientCount(numConnections);
        } else {
            memberInfo.setServer(false);
        }
        functionContext.getResultSender().lastResult(memberInfo);
    } catch (CacheClosedException e) {
        functionContext.getResultSender().sendException(e);
    } catch (Exception e) {
        functionContext.getResultSender().sendException(e);
    }
}
Also used : CacheClientStatus(org.apache.geode.internal.cache.CacheClientStatus) CacheClosedException(org.apache.geode.cache.CacheClosedException) MemoryUsage(java.lang.management.MemoryUsage) CacheServerInfo(org.apache.geode.management.internal.cli.domain.CacheServerInfo) CacheClosedException(org.apache.geode.cache.CacheClosedException) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) MemoryMXBean(java.lang.management.MemoryMXBean) MemberInformation(org.apache.geode.management.internal.cli.domain.MemberInformation) CacheServer(org.apache.geode.cache.server.CacheServer) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) Cache(org.apache.geode.cache.Cache)

Example 2 with MemberInformation

use of org.apache.geode.management.internal.cli.domain.MemberInformation in project geode by apache.

the class MemberCommands method describeMember.

@CliCommand(value = { CliStrings.DESCRIBE_MEMBER }, help = CliStrings.DESCRIBE_MEMBER__HELP)
@CliMetaData(shellOnly = false, relatedTopic = CliStrings.TOPIC_GEODE_SERVER)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result describeMember(@CliOption(key = CliStrings.DESCRIBE_MEMBER__IDENTIFIER, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.DESCRIBE_MEMBER__HELP, mandatory = true) String memberNameOrId) {
    Result result = null;
    try {
        DistributedMember memberToBeDescribed = CliUtil.getDistributedMemberByNameOrId(memberNameOrId);
        if (memberToBeDescribed != null) {
            // This information should be available through the MBeans too. We might not need
            // the function.
            // Yes, but then the command is subject to Mbean availability, which would be
            // affected once MBean filters are used.
            ResultCollector<?, ?> rc = CliUtil.executeFunction(getMemberInformation, null, memberToBeDescribed);
            ArrayList<?> output = (ArrayList<?>) rc.getResult();
            Object obj = output.get(0);
            if (obj != null && (obj instanceof MemberInformation)) {
                CompositeResultData crd = ResultBuilder.createCompositeResultData();
                MemberInformation memberInformation = (MemberInformation) obj;
                memberInformation.setName(memberToBeDescribed.getName());
                memberInformation.setId(memberToBeDescribed.getId());
                memberInformation.setHost(memberToBeDescribed.getHost());
                memberInformation.setProcessId("" + memberToBeDescribed.getProcessId());
                SectionResultData section = crd.addSection();
                section.addData("Name", memberInformation.getName());
                section.addData("Id", memberInformation.getId());
                section.addData("Host", memberInformation.getHost());
                section.addData("Regions", CliUtil.convertStringSetToString(memberInformation.getHostedRegions(), '\n'));
                section.addData("PID", memberInformation.getProcessId());
                section.addData("Groups", memberInformation.getGroups());
                section.addData("Used Heap", memberInformation.getHeapUsage() + "M");
                section.addData("Max Heap", memberInformation.getMaxHeapSize() + "M");
                String offHeapMemorySize = memberInformation.getOffHeapMemorySize();
                if (offHeapMemorySize != null && !offHeapMemorySize.isEmpty()) {
                    section.addData("Off Heap Size", offHeapMemorySize);
                }
                section.addData("Working Dir", memberInformation.getWorkingDirPath());
                section.addData("Log file", memberInformation.getLogFilePath());
                section.addData("Locators", memberInformation.getLocators());
                if (memberInformation.isServer()) {
                    SectionResultData clientServiceSection = crd.addSection();
                    List<CacheServerInfo> csList = memberInformation.getCacheServeInfo();
                    if (csList != null) {
                        Iterator<CacheServerInfo> iters = csList.iterator();
                        clientServiceSection.setHeader("Cache Server Information");
                        while (iters.hasNext()) {
                            CacheServerInfo cacheServerInfo = iters.next();
                            clientServiceSection.addData("Server Bind", cacheServerInfo.getBindAddress());
                            clientServiceSection.addData("Server Port", cacheServerInfo.getPort());
                            clientServiceSection.addData("Running", cacheServerInfo.isRunning());
                        }
                        clientServiceSection.addData("Client Connections", memberInformation.getClientCount());
                    }
                }
                result = ResultBuilder.buildResult(crd);
            } else {
                result = ResultBuilder.createInfoResult(CliStrings.format(CliStrings.DESCRIBE_MEMBER__MSG__INFO_FOR__0__COULD_NOT_BE_RETRIEVED, new Object[] { memberNameOrId }));
            }
        } else {
            result = ResultBuilder.createInfoResult(CliStrings.format(CliStrings.DESCRIBE_MEMBER__MSG__NOT_FOUND, new Object[] { memberNameOrId }));
        }
    } catch (CacheClosedException e) {
    } catch (FunctionInvocationTargetException e) {
        result = ResultBuilder.createGemFireErrorResult(e.getMessage());
    } catch (Exception e) {
        result = ResultBuilder.createGemFireErrorResult(e.getMessage());
    }
    return result;
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) ArrayList(java.util.ArrayList) CacheClosedException(org.apache.geode.cache.CacheClosedException) CacheServerInfo(org.apache.geode.management.internal.cli.domain.CacheServerInfo) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) CacheClosedException(org.apache.geode.cache.CacheClosedException) Result(org.apache.geode.management.cli.Result) MemberInformation(org.apache.geode.management.internal.cli.domain.MemberInformation) DistributedMember(org.apache.geode.distributed.DistributedMember) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Aggregations

CacheClosedException (org.apache.geode.cache.CacheClosedException)2 CacheServerInfo (org.apache.geode.management.internal.cli.domain.CacheServerInfo)2 MemberInformation (org.apache.geode.management.internal.cli.domain.MemberInformation)2 MemoryMXBean (java.lang.management.MemoryMXBean)1 MemoryUsage (java.lang.management.MemoryUsage)1 ArrayList (java.util.ArrayList)1 Cache (org.apache.geode.cache.Cache)1 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)1 CacheServer (org.apache.geode.cache.server.CacheServer)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 DistributionConfig (org.apache.geode.distributed.internal.DistributionConfig)1 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)1 CacheClientStatus (org.apache.geode.internal.cache.CacheClientStatus)1 ClientProxyMembershipID (org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID)1 CliMetaData (org.apache.geode.management.cli.CliMetaData)1 Result (org.apache.geode.management.cli.Result)1 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)1 SectionResultData (org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)1 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)1 CliCommand (org.springframework.shell.core.annotation.CliCommand)1