Search in sources :

Example 1 with MemberConfigurationInfo

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

the class ConfigCommands method describeConfig.

@CliCommand(value = { CliStrings.DESCRIBE_CONFIG }, help = CliStrings.DESCRIBE_CONFIG__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_CONFIG })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result describeConfig(@CliOption(key = CliStrings.DESCRIBE_CONFIG__MEMBER, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.DESCRIBE_CONFIG__MEMBER__HELP, mandatory = true) String memberNameOrId, @CliOption(key = CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS, help = CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS__HELP, unspecifiedDefaultValue = "true", specifiedDefaultValue = "true") boolean hideDefaults) {
    Result result = null;
    try {
        DistributedMember targetMember = null;
        if (memberNameOrId != null && !memberNameOrId.isEmpty()) {
            targetMember = CliUtil.getDistributedMemberByNameOrId(memberNameOrId);
        }
        if (targetMember != null) {
            ResultCollector<?, ?> rc = CliUtil.executeFunction(getMemberConfigFunction, new Boolean(hideDefaults), targetMember);
            ArrayList<?> output = (ArrayList<?>) rc.getResult();
            Object obj = output.get(0);
            if (obj != null && obj instanceof MemberConfigurationInfo) {
                MemberConfigurationInfo memberConfigInfo = (MemberConfigurationInfo) obj;
                CompositeResultData crd = ResultBuilder.createCompositeResultData();
                crd.setHeader(CliStrings.format(CliStrings.DESCRIBE_CONFIG__HEADER__TEXT, memberNameOrId));
                List<String> jvmArgsList = memberConfigInfo.getJvmInputArguments();
                TabularResultData jvmInputArgs = crd.addSection().addSection().addTable();
                for (String jvmArg : jvmArgsList) {
                    jvmInputArgs.accumulate("JVM command line arguments", jvmArg);
                }
                addSection(crd, memberConfigInfo.getGfePropsSetUsingApi(), "GemFire properties defined using the API");
                addSection(crd, memberConfigInfo.getGfePropsRuntime(), "GemFire properties defined at the runtime");
                addSection(crd, memberConfigInfo.getGfePropsSetFromFile(), "GemFire properties defined with the property file");
                addSection(crd, memberConfigInfo.getGfePropsSetWithDefaults(), "GemFire properties using default values");
                addSection(crd, memberConfigInfo.getCacheAttributes(), "Cache attributes");
                List<Map<String, String>> cacheServerAttributesList = memberConfigInfo.getCacheServerAttributes();
                if (cacheServerAttributesList != null && !cacheServerAttributesList.isEmpty()) {
                    SectionResultData cacheServerSection = crd.addSection();
                    cacheServerSection.setHeader("Cache-server attributes");
                    for (Map<String, String> cacheServerAttributes : cacheServerAttributesList) {
                        addSubSection(cacheServerSection, cacheServerAttributes, "");
                    }
                }
                result = ResultBuilder.buildResult(crd);
            }
        } else {
            ErrorResultData erd = ResultBuilder.createErrorResultData();
            erd.addLine(CliStrings.format(CliStrings.DESCRIBE_CONFIG__MEMBER__NOT__FOUND, new Object[] { memberNameOrId }));
            result = ResultBuilder.buildResult(erd);
        }
    } catch (FunctionInvocationTargetException e) {
        result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COULD_NOT_EXECUTE_COMMAND_TRY_AGAIN, CliStrings.DESCRIBE_CONFIG));
    } catch (Exception e) {
        ErrorResultData erd = ResultBuilder.createErrorResultData();
        erd.addLine(e.getMessage());
        result = ResultBuilder.buildResult(erd);
    }
    return result;
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) ArrayList(java.util.ArrayList) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) IOException(java.io.IOException) GfshParseResult(org.apache.geode.management.internal.cli.GfshParseResult) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) MemberConfigurationInfo(org.apache.geode.management.internal.cli.domain.MemberConfigurationInfo) DistributedMember(org.apache.geode.distributed.DistributedMember) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) HashMap(java.util.HashMap) Map(java.util.Map) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 2 with MemberConfigurationInfo

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

the class GetMemberConfigInformationFunction method execute.

@Override
public void execute(FunctionContext context) {
    Object argsObject = context.getArguments();
    boolean hideDefaults = ((Boolean) argsObject).booleanValue();
    Cache cache = CacheFactory.getAnyInstance();
    InternalDistributedSystem system = (InternalDistributedSystem) cache.getDistributedSystem();
    DistributionConfig config = system.getConfig();
    DistributionConfigImpl distConfigImpl = ((DistributionConfigImpl) config);
    MemberConfigurationInfo memberConfigInfo = new MemberConfigurationInfo();
    memberConfigInfo.setJvmInputArguments(getJvmInputArguments());
    memberConfigInfo.setGfePropsRuntime(distConfigImpl.getConfigPropsFromSource(ConfigSource.runtime()));
    memberConfigInfo.setGfePropsSetUsingApi(distConfigImpl.getConfigPropsFromSource(ConfigSource.api()));
    if (!hideDefaults)
        memberConfigInfo.setGfePropsSetWithDefaults(distConfigImpl.getConfigPropsFromSource(null));
    memberConfigInfo.setGfePropsSetFromFile(distConfigImpl.getConfigPropsDefinedUsingFiles());
    // CacheAttributes
    Map<String, String> cacheAttributes = new HashMap<String, String>();
    cacheAttributes.put("copy-on-read", Boolean.toString(cache.getCopyOnRead()));
    cacheAttributes.put("is-server", Boolean.toString(cache.isServer()));
    cacheAttributes.put("lock-timeout", Integer.toString(cache.getLockTimeout()));
    cacheAttributes.put("lock-lease", Integer.toString(cache.getLockLease()));
    cacheAttributes.put("message-sync-interval", Integer.toString(cache.getMessageSyncInterval()));
    cacheAttributes.put("search-timeout", Integer.toString(cache.getSearchTimeout()));
    if (cache.getPdxDiskStore() == null) {
        cacheAttributes.put("pdx-disk-store", "");
    } else {
        cacheAttributes.put("pdx-disk-store", cache.getPdxDiskStore());
    }
    cacheAttributes.put("pdx-ignore-unread-fields", Boolean.toString(cache.getPdxIgnoreUnreadFields()));
    cacheAttributes.put("pdx-persistent", Boolean.toString(cache.getPdxPersistent()));
    cacheAttributes.put("pdx-read-serialized", Boolean.toString(cache.getPdxReadSerialized()));
    if (hideDefaults) {
        removeDefaults(cacheAttributes, getCacheAttributesDefaultValues());
    }
    memberConfigInfo.setCacheAttributes(cacheAttributes);
    List<Map<String, String>> cacheServerAttributesList = new ArrayList<Map<String, String>>();
    List<CacheServer> cacheServers = cache.getCacheServers();
    if (cacheServers != null)
        for (CacheServer cacheServer : cacheServers) {
            Map<String, String> cacheServerAttributes = new HashMap<String, String>();
            cacheServerAttributes.put("bind-address", cacheServer.getBindAddress());
            cacheServerAttributes.put("hostname-for-clients", cacheServer.getHostnameForClients());
            cacheServerAttributes.put("max-connections", Integer.toString(cacheServer.getMaxConnections()));
            cacheServerAttributes.put("maximum-message-count", Integer.toString(cacheServer.getMaximumMessageCount()));
            cacheServerAttributes.put("maximum-time-between-pings", Integer.toString(cacheServer.getMaximumTimeBetweenPings()));
            cacheServerAttributes.put("max-threads", Integer.toString(cacheServer.getMaxThreads()));
            cacheServerAttributes.put("message-time-to-live", Integer.toString(cacheServer.getMessageTimeToLive()));
            cacheServerAttributes.put("notify-by-subscription", Boolean.toString(cacheServer.getNotifyBySubscription()));
            cacheServerAttributes.put("port", Integer.toString(cacheServer.getPort()));
            cacheServerAttributes.put(SOCKET_BUFFER_SIZE, Integer.toString(cacheServer.getSocketBufferSize()));
            cacheServerAttributes.put("load-poll-interval", Long.toString(cacheServer.getLoadPollInterval()));
            cacheServerAttributes.put("tcp-no-delay", Boolean.toString(cacheServer.getTcpNoDelay()));
            if (hideDefaults)
                removeDefaults(cacheServerAttributes, getCacheServerAttributesDefaultValues());
            cacheServerAttributesList.add(cacheServerAttributes);
        }
    memberConfigInfo.setCacheServerAttributes(cacheServerAttributesList);
    context.getResultSender().lastResult(memberConfigInfo);
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) DistributionConfigImpl(org.apache.geode.distributed.internal.DistributionConfigImpl) MemberConfigurationInfo(org.apache.geode.management.internal.cli.domain.MemberConfigurationInfo) CacheServer(org.apache.geode.cache.server.CacheServer) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) Cache(org.apache.geode.cache.Cache)

Aggregations

MemberConfigurationInfo (org.apache.geode.management.internal.cli.domain.MemberConfigurationInfo)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)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 DistributionConfigImpl (org.apache.geode.distributed.internal.DistributionConfigImpl)1 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)1 CliMetaData (org.apache.geode.management.cli.CliMetaData)1 Result (org.apache.geode.management.cli.Result)1 GfshParseResult (org.apache.geode.management.internal.cli.GfshParseResult)1 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)1 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)1 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)1 SectionResultData (org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)1 ErrorResultData (org.apache.geode.management.internal.cli.result.ErrorResultData)1