Search in sources :

Example 31 with DistributionConfig

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

the class DistributedSystemLogFileJUnitTest method testDistributedSystemCreatesLogFile.

@Test
public void testDistributedSystemCreatesLogFile() throws Exception {
    // final int port = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
    final String logFileName = name.getMethodName() + "-system-0.log";
    final Properties properties = new Properties();
    properties.put(LOG_FILE, logFileName);
    properties.put(LOG_LEVEL, "config");
    properties.put(MCAST_PORT, "0");
    properties.put(LOCATORS, "");
    properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "false");
    properties.put(DISABLE_AUTO_RECONNECT, "true");
    properties.put(MEMBER_TIMEOUT, "2000");
    properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
    final File logFile = new File(logFileName);
    if (logFile.exists()) {
        logFile.delete();
    }
    assertFalse(logFile.exists());
    this.system = DistributedSystem.connect(properties);
    assertNotNull(this.system);
    DistributionConfig config = ((InternalDistributedSystem) this.system).getConfig();
    assertEquals("Expected " + LogWriterImpl.levelToString(InternalLogWriter.CONFIG_LEVEL) + " but was " + LogWriterImpl.levelToString(config.getLogLevel()), InternalLogWriter.CONFIG_LEVEL, config.getLogLevel());
    // CONFIG has been replaced with INFO -- all CONFIG statements are now logged at INFO as well
    InternalLogWriter logWriter = (InternalLogWriter) system.getLogWriter();
    assertNotNull(logWriter);
    assertTrue(logWriter instanceof LogWriterLogger);
    assertEquals("Expected " + LogWriterImpl.levelToString(InternalLogWriter.INFO_LEVEL) + " but was " + LogWriterImpl.levelToString(logWriter.getLogWriterLevel()), InternalLogWriter.INFO_LEVEL, logWriter.getLogWriterLevel());
    Wait.waitForCriterion(new WaitCriterion() {

        @Override
        public boolean done() {
            return logFile.exists();
        }

        @Override
        public String description() {
            return "waiting for log file to exist: " + logFile;
        }
    }, TIMEOUT_MILLISECONDS, INTERVAL_MILLISECONDS, true);
    assertTrue(logFile.exists());
    // assert not empty
    FileInputStream fis = new FileInputStream(logFile);
    try {
        assertTrue("log file is empty: " + logFile.getAbsoluteFile(), fis.available() > 0);
    } finally {
        fis.close();
    }
    final Logger logger = LogService.getLogger();
    final Logger appLogger = LogManager.getLogger("net.customer");
    assertEquals(Level.INFO, appLogger.getLevel());
    int i = 0;
    {
        i++;
        final String FINEST_STRING = "testLogLevels Message logged at FINEST level [" + i + "]";
        logWriter.finest(FINEST_STRING);
        assertFalse(fileContainsString(logFile, FINEST_STRING));
        i++;
        final String FINER_STRING = "testLogLevels Message logged at FINER level [" + i + "]";
        logWriter.finer(FINER_STRING);
        assertFalse(fileContainsString(logFile, FINER_STRING));
        i++;
        final String FINE_STRING = "testLogLevels Message logged at FINE level [" + i + "]";
        logWriter.fine(FINE_STRING);
        assertFalse(fileContainsString(logFile, FINE_STRING));
        i++;
        final String CONFIG_STRING = "testLogLevels Message logged at CONFIG level [" + i + "]";
        logWriter.config(CONFIG_STRING);
        assertTrue(fileContainsString(logFile, CONFIG_STRING));
        i++;
        final String INFO_STRING = "testLogLevels Message logged at INFO level [" + i + "]";
        logWriter.info(INFO_STRING);
        assertTrue(fileContainsString(logFile, INFO_STRING));
        i++;
        final String WARNING_STRING = "ExpectedStrings: testLogLevels Message logged at WARNING level [" + i + "]";
        logWriter.warning(WARNING_STRING);
        assertTrue(fileContainsString(logFile, WARNING_STRING));
        i++;
        final String ERROR_STRING = "ExpectedStrings: testLogLevels Message logged at ERROR level [" + i + "]";
        logWriter.error(ERROR_STRING);
        assertTrue(fileContainsString(logFile, ERROR_STRING));
        i++;
        final String SEVERE_STRING = "ExpectedStrings: testLogLevels Message logged at SEVERE level [" + i + "]";
        logWriter.severe(SEVERE_STRING);
        assertTrue(fileContainsString(logFile, SEVERE_STRING));
        i++;
        final String TRACE_STRING = "ExpectedStrings: testLogLevels Message logged at TRACE level [" + i + "]";
        logger.trace(TRACE_STRING);
        assertFalse(fileContainsString(logFile, TRACE_STRING));
        i++;
        final String DEBUG_STRING = "testLogLevels Message logged at DEBUG level [" + i + "]";
        logger.debug(DEBUG_STRING);
        assertFalse(fileContainsString(logFile, DEBUG_STRING));
        i++;
        final String INFO_STRING_J = "testLogLevels Message logged at INFO level [" + i + "]";
        logger.info(INFO_STRING_J);
        assertTrue(fileContainsString(logFile, INFO_STRING_J));
        i++;
        final String WARN_STRING = "ExpectedStrings: testLogLevels Message logged at WARN level [" + i + "]";
        logger.warn(WARN_STRING);
        assertTrue(fileContainsString(logFile, WARN_STRING));
        i++;
        final String ERROR_STRING_J = "ExpectedStrings: testLogLevels Message logged at ERROR level [" + i + "]";
        logger.error(ERROR_STRING_J);
        assertTrue(fileContainsString(logFile, ERROR_STRING_J));
        i++;
        final String FATAL_STRING = "ExpectedStrings: testLogLevels Message logged at FATAL level [" + i + "]";
        logger.fatal(FATAL_STRING);
        assertTrue(fileContainsString(logFile, FATAL_STRING));
        i++;
        final String TRACE_STRING_A = "Message logged at TRACE level [" + i + "]";
        appLogger.trace(TRACE_STRING_A);
        assertFalse(fileContainsString(logFile, TRACE_STRING_A));
        i++;
        final String DEBUG_STRING_A = "Message logged at DEBUG level [" + i + "]";
        appLogger.debug(DEBUG_STRING_A);
        assertFalse(fileContainsString(logFile, DEBUG_STRING_A));
        i++;
        final String INFO_STRING_A = "Message logged at INFO level [" + i + "]";
        appLogger.info(INFO_STRING_A);
        assertTrue(fileContainsString(logFile, INFO_STRING_A));
        i++;
        final String WARN_STRING_A = "ExpectedStrings: Message logged at WARN level [" + i + "]";
        appLogger.warn(WARN_STRING_A);
        assertTrue(fileContainsString(logFile, WARN_STRING_A));
        i++;
        final String ERROR_STRING_A = "ExpectedStrings: Message logged at ERROR level [" + i + "]";
        appLogger.error(ERROR_STRING_A);
        assertTrue(fileContainsString(logFile, ERROR_STRING_A));
        i++;
        final String FATAL_STRING_A = "ExpectedStrings: Message logged at FATAL level [" + i + "]";
        appLogger.fatal(FATAL_STRING_A);
        assertTrue(fileContainsString(logFile, FATAL_STRING_A));
    }
    // change log level to fine and verify
    config.setLogLevel(InternalLogWriter.FINE_LEVEL);
    assertEquals("Expected " + LogWriterImpl.levelToString(InternalLogWriter.FINE_LEVEL) + " but was " + LogWriterImpl.levelToString(config.getLogLevel()), InternalLogWriter.FINE_LEVEL, config.getLogLevel());
    assertEquals("Expected " + LogWriterImpl.levelToString(InternalLogWriter.FINE_LEVEL) + " but was " + LogWriterImpl.levelToString(logWriter.getLogWriterLevel()), InternalLogWriter.FINE_LEVEL, logWriter.getLogWriterLevel());
    assertEquals(Level.DEBUG, appLogger.getLevel());
    {
        i++;
        final String FINEST_STRING = "testLogLevels Message logged at FINEST level [" + i + "]";
        logWriter.finest(FINEST_STRING);
        assertFalse(fileContainsString(logFile, FINEST_STRING));
        i++;
        final String FINER_STRING = "testLogLevels Message logged at FINER level [" + i + "]";
        logWriter.finer(FINER_STRING);
        assertFalse(fileContainsString(logFile, FINER_STRING));
        i++;
        final String FINE_STRING = "testLogLevels Message logged at FINE level [" + i + "]";
        logWriter.fine(FINE_STRING);
        assertTrue(fileContainsString(logFile, FINE_STRING));
        i++;
        final String CONFIG_STRING = "testLogLevels Message logged at CONFIG level [" + i + "]";
        logWriter.config(CONFIG_STRING);
        assertTrue(fileContainsString(logFile, CONFIG_STRING));
        i++;
        final String INFO_STRING = "testLogLevels Message logged at INFO level [" + i + "]";
        logWriter.info(INFO_STRING);
        assertTrue(fileContainsString(logFile, INFO_STRING));
        i++;
        final String WARNING_STRING = "ExpectedStrings: testLogLevels Message logged at WARNING level [" + i + "]";
        logWriter.warning(WARNING_STRING);
        assertTrue(fileContainsString(logFile, WARNING_STRING));
        i++;
        final String ERROR_STRING = "ExpectedStrings: testLogLevels Message logged at ERROR level [" + i + "]";
        logWriter.error(ERROR_STRING);
        assertTrue(fileContainsString(logFile, ERROR_STRING));
        i++;
        final String SEVERE_STRING = "ExpectedStrings: testLogLevels Message logged at SEVERE level [" + i + "]";
        logWriter.severe(SEVERE_STRING);
        assertTrue(fileContainsString(logFile, SEVERE_STRING));
        i++;
        final String TRACE_STRING = "testLogLevels Message logged at TRACE level [" + i + "]";
        logger.trace(TRACE_STRING);
        assertFalse(fileContainsString(logFile, TRACE_STRING));
        i++;
        final String DEBUG_STRING = "testLogLevels Message logged at DEBUG level [" + i + "]";
        logger.debug(DEBUG_STRING);
        assertTrue(fileContainsString(logFile, DEBUG_STRING));
        i++;
        final String INFO_STRING_J = "testLogLevels Message logged at INFO level [" + i + "]";
        logger.info(INFO_STRING_J);
        assertTrue(fileContainsString(logFile, INFO_STRING_J));
        i++;
        final String WARN_STRING = "ExpectedStrings: testLogLevels Message logged at WARN level [" + i + "]";
        logger.warn(WARN_STRING);
        assertTrue(fileContainsString(logFile, WARN_STRING));
        i++;
        final String ERROR_STRING_J = "ExpectedStrings: testLogLevels Message logged at ERROR level [" + i + "]";
        logger.error(ERROR_STRING_J);
        assertTrue(fileContainsString(logFile, ERROR_STRING_J));
        i++;
        final String FATAL_STRING = "ExpectedStrings: testLogLevels Message logged at FATAL level [" + i + "]";
        logger.fatal(FATAL_STRING);
        assertTrue(fileContainsString(logFile, FATAL_STRING));
        i++;
        final String TRACE_STRING_A = "Message logged at TRACE level [" + i + "]";
        appLogger.trace(TRACE_STRING_A);
        assertFalse(fileContainsString(logFile, TRACE_STRING_A));
        i++;
        final String DEBUG_STRING_A = "Message logged at DEBUG level [" + i + "]";
        appLogger.debug(DEBUG_STRING_A);
        assertTrue(fileContainsString(logFile, DEBUG_STRING_A));
        i++;
        final String INFO_STRING_A = "Message logged at INFO level [" + i + "]";
        appLogger.info(INFO_STRING_A);
        assertTrue(fileContainsString(logFile, INFO_STRING_A));
        i++;
        final String WARN_STRING_A = "ExpectedStrings: Message logged at WARN level [" + i + "]";
        appLogger.warn(WARN_STRING_A);
        assertTrue(fileContainsString(logFile, WARN_STRING_A));
        i++;
        final String ERROR_STRING_A = "ExpectedStrings: Message logged at ERROR level [" + i + "]";
        appLogger.error(ERROR_STRING_A);
        assertTrue(fileContainsString(logFile, ERROR_STRING_A));
        i++;
        final String FATAL_STRING_A = "ExpectedStrings: Message logged at FATAL level [" + i + "]";
        appLogger.fatal(FATAL_STRING_A);
        assertTrue(fileContainsString(logFile, FATAL_STRING_A));
    }
    // change log level to error and verify
    config.setLogLevel(InternalLogWriter.ERROR_LEVEL);
    assertEquals("Expected " + LogWriterImpl.levelToString(InternalLogWriter.ERROR_LEVEL) + " but was " + LogWriterImpl.levelToString(config.getLogLevel()), InternalLogWriter.ERROR_LEVEL, config.getLogLevel());
    assertEquals("Expected " + LogWriterImpl.levelToString(InternalLogWriter.ERROR_LEVEL) + " but was " + LogWriterImpl.levelToString(logWriter.getLogWriterLevel()), InternalLogWriter.ERROR_LEVEL, logWriter.getLogWriterLevel());
    assertEquals(Level.ERROR, appLogger.getLevel());
    {
        i++;
        final String FINEST_STRING = "testLogLevels Message logged at FINEST level [" + i + "]";
        logWriter.finest(FINEST_STRING);
        assertFalse(fileContainsString(logFile, FINEST_STRING));
        i++;
        final String FINER_STRING = "testLogLevels Message logged at FINER level [" + i + "]";
        logWriter.finer(FINER_STRING);
        assertFalse(fileContainsString(logFile, FINER_STRING));
        i++;
        final String FINE_STRING = "testLogLevels Message logged at FINE level [" + i + "]";
        logWriter.fine(FINE_STRING);
        assertFalse(fileContainsString(logFile, FINE_STRING));
        i++;
        final String CONFIG_STRING = "testLogLevels Message logged at CONFIG level [" + i + "]";
        logWriter.config(CONFIG_STRING);
        assertFalse(fileContainsString(logFile, CONFIG_STRING));
        i++;
        final String INFO_STRING = "testLogLevels Message logged at INFO level [" + i + "]";
        logWriter.info(INFO_STRING);
        assertFalse(fileContainsString(logFile, INFO_STRING));
        i++;
        final String WARNING_STRING = "ExpectedStrings: testLogLevels Message logged at WARNING level [" + i + "]";
        logWriter.warning(WARNING_STRING);
        assertFalse(fileContainsString(logFile, WARNING_STRING));
        i++;
        final String ERROR_STRING = "ExpectedStrings: testLogLevels Message logged at ERROR level [" + i + "]";
        logWriter.error(ERROR_STRING);
        assertTrue(fileContainsString(logFile, ERROR_STRING));
        i++;
        final String SEVERE_STRING = "ExpectedStrings: testLogLevels Message logged at SEVERE level [" + i + "]";
        logWriter.severe(SEVERE_STRING);
        assertTrue(fileContainsString(logFile, SEVERE_STRING));
        i++;
        final String TRACE_STRING = "testLogLevels Message logged at TRACE level [" + i + "]";
        logger.trace(TRACE_STRING);
        assertFalse(fileContainsString(logFile, TRACE_STRING));
        i++;
        final String DEBUG_STRING = "testLogLevels Message logged at DEBUG level [" + i + "]";
        logger.debug(DEBUG_STRING);
        assertFalse(fileContainsString(logFile, DEBUG_STRING));
        i++;
        final String INFO_STRING_J = "testLogLevels Message logged at INFO level [" + i + "]";
        logger.info(INFO_STRING_J);
        assertFalse(fileContainsString(logFile, INFO_STRING_J));
        i++;
        final String WARN_STRING = "ExpectedStrings: testLogLevels Message logged at WARN level [" + i + "]";
        logger.warn(WARN_STRING);
        assertFalse(fileContainsString(logFile, WARN_STRING));
        i++;
        final String ERROR_STRING_J = "ExpectedStrings: testLogLevels Message logged at ERROR level [" + i + "]";
        logger.error(ERROR_STRING_J);
        assertTrue(fileContainsString(logFile, ERROR_STRING_J));
        i++;
        final String FATAL_STRING = "ExpectedStrings: testLogLevels Message logged at FATAL level [" + i + "]";
        logger.fatal(FATAL_STRING);
        assertTrue(fileContainsString(logFile, FATAL_STRING));
        i++;
        final String TRACE_STRING_A = "Message logged at TRACE level [" + i + "]";
        appLogger.trace(TRACE_STRING_A);
        assertFalse(fileContainsString(logFile, TRACE_STRING_A));
        i++;
        final String DEBUG_STRING_A = "Message logged at DEBUG level [" + i + "]";
        appLogger.debug(DEBUG_STRING_A);
        assertFalse(fileContainsString(logFile, DEBUG_STRING_A));
        i++;
        final String INFO_STRING_A = "Message logged at INFO level [" + i + "]";
        appLogger.info(INFO_STRING_A);
        assertFalse(fileContainsString(logFile, INFO_STRING_A));
        i++;
        final String WARN_STRING_A = "ExpectedStrings: Message logged at WARN level [" + i + "]";
        appLogger.warn(WARN_STRING_A);
        assertFalse(fileContainsString(logFile, WARN_STRING_A));
        i++;
        final String ERROR_STRING_A = "ExpectedStrings: Message logged at ERROR level [" + i + "]";
        appLogger.error(ERROR_STRING_A);
        assertTrue(fileContainsString(logFile, ERROR_STRING_A));
        i++;
        final String FATAL_STRING_A = "ExpectedStrings: Message logged at FATAL level [" + i + "]";
        appLogger.fatal(FATAL_STRING_A);
        assertTrue(fileContainsString(logFile, FATAL_STRING_A));
    }
    this.system.disconnect();
    this.system = null;
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) FastLogger(org.apache.geode.internal.logging.log4j.FastLogger) Logger(org.apache.logging.log4j.Logger) LogWriterLogger(org.apache.geode.internal.logging.log4j.LogWriterLogger) File(java.io.File) FileInputStream(java.io.FileInputStream) LogWriterLogger(org.apache.geode.internal.logging.log4j.LogWriterLogger) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 32 with DistributionConfig

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

the class LocatorLogFileJUnitTest method testLocatorCreatesLogFile.

@Test
public void testLocatorCreatesLogFile() throws Exception {
    final int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    final String locators = "localhost[" + port + "]";
    final Properties properties = new Properties();
    properties.put(LOG_LEVEL, "config");
    properties.put(MCAST_PORT, "0");
    properties.put(LOCATORS, locators);
    properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "false");
    properties.put(DISABLE_AUTO_RECONNECT, "true");
    properties.put(MEMBER_TIMEOUT, "2000");
    properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
    final File logFile = new File(name.getMethodName() + "-locator-" + port + ".log");
    if (logFile.exists()) {
        logFile.delete();
    }
    assertFalse(logFile.exists());
    this.locator = Locator.startLocatorAndDS(port, logFile, properties);
    InternalDistributedSystem ds = (InternalDistributedSystem) this.locator.getDistributedSystem();
    assertNotNull(ds);
    DistributionConfig config = ds.getConfig();
    assertNotNull(config);
    assertEquals("Expected " + LogWriterImpl.levelToString(InternalLogWriter.CONFIG_LEVEL) + " but was " + LogWriterImpl.levelToString(config.getLogLevel()), InternalLogWriter.CONFIG_LEVEL, config.getLogLevel());
    // CONFIG has been replaced with INFO -- all CONFIG statements are now logged at INFO as well
    InternalLogWriter logWriter = (InternalLogWriter) ds.getLogWriter();
    assertNotNull(logWriter);
    assertTrue(logWriter instanceof LogWriterLogger);
    assertEquals("Expected " + LogWriterImpl.levelToString(InternalLogWriter.INFO_LEVEL) + " but was " + LogWriterImpl.levelToString(logWriter.getLogWriterLevel()), InternalLogWriter.INFO_LEVEL, logWriter.getLogWriterLevel());
    assertNotNull(this.locator);
    Wait.waitForCriterion(new WaitCriterion() {

        @Override
        public boolean done() {
            return logFile.exists();
        }

        @Override
        public String description() {
            return "waiting for log file to exist: " + logFile;
        }
    }, TIMEOUT_MILLISECONDS, INTERVAL_MILLISECONDS, true);
    assertTrue(logFile.exists());
    // assert not empty
    this.fis = new FileInputStream(logFile);
    assertTrue(fis.available() > 0);
    this.locator.stop();
    this.locator = null;
    this.fis.close();
    this.fis = null;
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream) LogWriterLogger(org.apache.geode.internal.logging.log4j.LogWriterLogger) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 33 with DistributionConfig

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

the class LogWriterPerformanceTest method createLogWriter.

protected LogWriter createLogWriter() {
    final Properties props = createGemFireProperties();
    // create configuration with log-file and log-level
    // this.configDirectory = new File(getUniqueName());
    this.configDirectory.mkdir();
    assertTrue(this.configDirectory.isDirectory() && this.configDirectory.canWrite());
    // this.gemfireProperties = new File(this.configDirectory, "gemfire.properties");
    // writeProperties(props, this.gemfireProperties);
    final DistributionConfig config = new DistributionConfigImpl(props, false, false);
    // create a LogWriter that writes to log-file
    final boolean appendToFile = false;
    final boolean isLoner = true;
    final boolean isSecurityLog = false;
    final boolean logConfig = true;
    final FileOutputStream[] fosHolder = null;
    final LogWriter logWriter = TestLogWriterFactory.createLogWriter(appendToFile, isLoner, isSecurityLog, config, logConfig, fosHolder);
    return logWriter;
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) LogWriter(org.apache.geode.LogWriter) DistributionConfigImpl(org.apache.geode.distributed.internal.DistributionConfigImpl) FileOutputStream(java.io.FileOutputStream) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties)

Example 34 with DistributionConfig

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

the class DiskStoreMonitor method getLogDir.

private File getLogDir() {
    File log = null;
    InternalCache internalCache = GemFireCacheImpl.getInstance();
    if (internalCache != null) {
        InternalDistributedSystem ds = internalCache.getInternalDistributedSystem();
        if (ds != null) {
            DistributionConfig conf = ds.getConfig();
            if (conf != null) {
                log = conf.getLogFile();
                if (log != null) {
                    log = log.getParentFile();
                }
            }
        }
    }
    if (log == null) {
        // assume current directory
        log = new File(".");
    }
    return log;
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) File(java.io.File)

Example 35 with DistributionConfig

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

the class JGroupsMessenger method init.

@Override
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
public void init(Services s) {
    this.services = s;
    RemoteTransportConfig transport = services.getConfig().getTransport();
    DistributionConfig dc = services.getConfig().getDistributionConfig();
    boolean b = dc.getEnableNetworkPartitionDetection();
    System.setProperty("jgroups.resolve_dns", String.valueOf(!b));
    InputStream is;
    String r;
    if (transport.isMcastEnabled()) {
        r = JGROUPS_MCAST_CONFIG_FILE_NAME;
    } else {
        r = DEFAULT_JGROUPS_TCP_CONFIG;
    }
    is = ClassPathLoader.getLatest().getResourceAsStream(getClass(), r);
    if (is == null) {
        throw new GemFireConfigException(LocalizedStrings.GroupMembershipService_CANNOT_FIND_0.toLocalizedString(r));
    }
    String properties;
    try {
        // PlainConfigurator config = PlainConfigurator.getInstance(is);
        // properties = config.getProtocolStackString();
        StringBuilder sb = new StringBuilder(3000);
        BufferedReader br;
        br = new BufferedReader(new InputStreamReader(is, "US-ASCII"));
        String input;
        while ((input = br.readLine()) != null) {
            sb.append(input);
        }
        br.close();
        properties = sb.toString();
    } catch (Exception ex) {
        throw new GemFireConfigException(LocalizedStrings.GroupMembershipService_AN_EXCEPTION_WAS_THROWN_WHILE_READING_JGROUPS_CONFIG.toLocalizedString(), ex);
    }
    if (properties.startsWith("<!--")) {
        int commentEnd = properties.indexOf("-->");
        properties = properties.substring(commentEnd + 3);
    }
    if (transport.isMcastEnabled()) {
        properties = replaceStrings(properties, "MCAST_PORT", String.valueOf(transport.getMcastId().getPort()));
        properties = replaceStrings(properties, "MCAST_ADDRESS", dc.getMcastAddress().getHostAddress());
        properties = replaceStrings(properties, "MCAST_TTL", String.valueOf(dc.getMcastTtl()));
        properties = replaceStrings(properties, "MCAST_SEND_BUFFER_SIZE", String.valueOf(dc.getMcastSendBufferSize()));
        properties = replaceStrings(properties, "MCAST_RECV_BUFFER_SIZE", String.valueOf(dc.getMcastRecvBufferSize()));
        properties = replaceStrings(properties, "MCAST_RETRANSMIT_INTERVAL", "" + Integer.getInteger(DistributionConfig.GEMFIRE_PREFIX + "mcast-retransmit-interval", 500));
        properties = replaceStrings(properties, "RETRANSMIT_LIMIT", String.valueOf(dc.getUdpFragmentSize() - 256));
    }
    if (transport.isMcastEnabled() || transport.isTcpDisabled() || (dc.getUdpRecvBufferSize() != DistributionConfig.DEFAULT_UDP_RECV_BUFFER_SIZE)) {
        properties = replaceStrings(properties, "UDP_RECV_BUFFER_SIZE", "" + dc.getUdpRecvBufferSize());
    } else {
        properties = replaceStrings(properties, "UDP_RECV_BUFFER_SIZE", "" + DistributionConfig.DEFAULT_UDP_RECV_BUFFER_SIZE_REDUCED);
    }
    properties = replaceStrings(properties, "UDP_SEND_BUFFER_SIZE", "" + dc.getUdpSendBufferSize());
    String str = transport.getBindAddress();
    // JGroups UDP protocol requires a bind address
    if (str == null || str.length() == 0) {
        try {
            str = SocketCreator.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            throw new GemFireConfigException(e.getMessage(), e);
        }
    }
    properties = replaceStrings(properties, "BIND_ADDR_SETTING", "bind_addr=\"" + str + "\"");
    int port = Integer.getInteger(DistributionConfig.GEMFIRE_PREFIX + "jg-bind-port", 0);
    if (port != 0) {
        properties = replaceStrings(properties, "MEMBERSHIP_PORT_RANGE_START", "" + port);
        properties = replaceStrings(properties, "MEMBERSHIP_PORT_RANGE", "" + 0);
    } else {
        int[] ports = dc.getMembershipPortRange();
        properties = replaceStrings(properties, "MEMBERSHIP_PORT_RANGE_START", "" + ports[0]);
        properties = replaceStrings(properties, "MEMBERSHIP_PORT_RANGE", "" + (ports[1] - ports[0]));
    }
    properties = replaceStrings(properties, "UDP_FRAGMENT_SIZE", "" + dc.getUdpFragmentSize());
    properties = replaceStrings(properties, "FC_MAX_CREDITS", "" + dc.getMcastFlowControl().getByteAllowance());
    properties = replaceStrings(properties, "FC_THRESHOLD", "" + dc.getMcastFlowControl().getRechargeThreshold());
    properties = replaceStrings(properties, "FC_MAX_BLOCK", "" + dc.getMcastFlowControl().getRechargeBlockMs());
    this.jgStackConfig = properties;
    if (!dc.getSecurityUDPDHAlgo().isEmpty()) {
        try {
            this.encrypt = new GMSEncrypt(services);
            logger.info("Initializing GMSEncrypt ");
        } catch (Exception e) {
            throw new GemFireConfigException("problem initializing encryption protocol", e);
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) UnknownHostException(java.net.UnknownHostException) ByteArrayInputStream(java.io.ByteArrayInputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) RemoteTransportConfig(org.apache.geode.internal.admin.remote.RemoteTransportConfig) MemberShunnedException(org.apache.geode.internal.tcp.MemberShunnedException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) GemFireIOException(org.apache.geode.GemFireIOException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) GemFireConfigException(org.apache.geode.GemFireConfigException) BufferedReader(java.io.BufferedReader)

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