Search in sources :

Example 21 with DistributionConfig

use of org.apache.geode.distributed.internal.DistributionConfig 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)

Example 22 with DistributionConfig

use of org.apache.geode.distributed.internal.DistributionConfig 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 23 with DistributionConfig

use of org.apache.geode.distributed.internal.DistributionConfig in project geode by apache.

the class SizeExportLogsFunction method execute.

@Override
public void execute(final FunctionContext context) {
    try {
        InternalCache cache = GemFireCacheImpl.getInstance();
        DistributionConfig config = cache.getInternalDistributedSystem().getConfig();
        Args args = (Args) context.getArguments();
        long diskAvailable = getDiskAvailable(config);
        long estimatedSize = estimateLogFileSize(cache.getMyId(), config.getLogFile(), config.getStatisticArchiveFile(), args);
        BytesToString bytesToString = new BytesToString();
        if (estimatedSize == 0 || estimatedSize < diskAvailable) {
            context.getResultSender().lastResult(Arrays.asList(estimatedSize));
        } else {
            StringBuilder sb = new StringBuilder().append("Estimated disk space required (").append(bytesToString.of(estimatedSize)).append(") to consolidate logs on member ").append(cache.getName()).append(" will exceed available disk space (").append(bytesToString.of(diskAvailable)).append(")");
            // FileTooBigException
            context.getResultSender().sendException(new ManagementException(sb.toString()));
        }
    } catch (Exception e) {
        e.printStackTrace();
        LOGGER.error(e.getMessage());
        context.getResultSender().sendException(e);
    }
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) ManagementException(org.apache.geode.management.ManagementException) InternalCache(org.apache.geode.internal.cache.InternalCache) IOException(java.io.IOException) ManagementException(org.apache.geode.management.ManagementException) BytesToString(org.apache.geode.management.internal.cli.util.BytesToString)

Example 24 with DistributionConfig

use of org.apache.geode.distributed.internal.DistributionConfig in project geode by apache.

the class ConfigCommandsDUnitTest method testAlterRuntimeConfig.

@Test
public void testAlterRuntimeConfig() throws Exception {
    final String controller = "controller";
    String directory = this.temporaryFolder.newFolder(controller).getAbsolutePath();
    String statFilePath = new File(directory, "stat.gfs").getAbsolutePath();
    setUpJmxManagerOnVm0ThenConnect(null);
    Properties localProps = new Properties();
    localProps.setProperty(NAME, controller);
    localProps.setProperty(LOG_LEVEL, "error");
    getSystem(localProps);
    final GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
    final DistributionConfig config = cache.getSystem().getConfig();
    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG);
    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__MEMBER, controller);
    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL, "info");
    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__FILE__SIZE__LIMIT, "50");
    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT, "32");
    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT, "49");
    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE, "2000");
    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE, statFilePath);
    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLING__ENABLED, "true");
    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, "10");
    CommandResult cmdResult = executeCommand(csb.getCommandString());
    String resultString = commandResultToString(cmdResult);
    getLogWriter().info("Result\n");
    getLogWriter().info(resultString);
    assertEquals(true, cmdResult.getStatus().equals(Status.OK));
    assertEquals(LogWriterImpl.INFO_LEVEL, config.getLogLevel());
    assertEquals(50, config.getLogFileSizeLimit());
    assertEquals(32, config.getArchiveDiskSpaceLimit());
    assertEquals(2000, config.getStatisticSampleRate());
    assertEquals("stat.gfs", config.getStatisticArchiveFile().getName());
    assertEquals(true, config.getStatisticSamplingEnabled());
    assertEquals(10, config.getLogDiskSpaceLimit());
    CommandProcessor commandProcessor = new CommandProcessor();
    Result result = commandProcessor.createCommandStatement("alter runtime", Collections.EMPTY_MAP).process();
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) CommandProcessor(org.apache.geode.management.internal.cli.remote.CommandProcessor) Properties(java.util.Properties) File(java.io.File) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Result(org.apache.geode.management.cli.Result) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 25 with DistributionConfig

use of org.apache.geode.distributed.internal.DistributionConfig in project geode by apache.

the class ConfigCommandsDUnitTest method testAlterRuntimeConfigRandom.

@Test
public void testAlterRuntimeConfigRandom() throws Exception {
    IgnoredException.addIgnoredException("java.lang.IllegalArgumentException: Could not set \"log-disk-space-limit\"");
    final String member1 = "VM1";
    final String controller = "controller";
    setUpJmxManagerOnVm0ThenConnect(null);
    Properties localProps = new Properties();
    localProps.setProperty(NAME, controller);
    localProps.setProperty(LOG_LEVEL, "error");
    getSystem(localProps);
    final GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
    final DistributionConfig config = cache.getSystem().getConfig();
    Host.getHost(0).getVM(1).invoke(new SerializableRunnable() {

        public void run() {
            Properties localProps = new Properties();
            localProps.setProperty(NAME, member1);
            getSystem(localProps);
            getCache();
        }
    });
    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG);
    CommandResult cmdResult = executeCommand(csb.getCommandString());
    String resultAsString = commandResultToString(cmdResult);
    assertEquals(true, cmdResult.getStatus().equals(Status.ERROR));
    assertTrue(resultAsString.contains(CliStrings.ALTER_RUNTIME_CONFIG__RELEVANT__OPTION__MESSAGE));
    csb = new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG);
    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, "2000000000");
    cmdResult = executeCommand(csb.getCommandString());
    resultAsString = commandResultToString(cmdResult);
    assertEquals(true, cmdResult.getStatus().equals(Status.ERROR));
    assertTrue(resultAsString.contains("Could not set \"log-disk-space-limit\" to \"2,000,000,000\""));
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Properties(java.util.Properties) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

DistributionConfig (org.apache.geode.distributed.internal.DistributionConfig)45 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)19 Properties (java.util.Properties)17 File (java.io.File)14 Test (org.junit.Test)14 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)12 LogWriterLogger (org.apache.geode.internal.logging.log4j.LogWriterLogger)9 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)9 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)8 FileInputStream (java.io.FileInputStream)7 IOException (java.io.IOException)7 FastLogger (org.apache.geode.internal.logging.log4j.FastLogger)7 Logger (org.apache.logging.log4j.Logger)7 DistributionConfigImpl (org.apache.geode.distributed.internal.DistributionConfigImpl)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 UnknownHostException (java.net.UnknownHostException)4 Cache (org.apache.geode.cache.Cache)4 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)4 InternalCache (org.apache.geode.internal.cache.InternalCache)4 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)4