This is an automated email from the ASF dual-hosted git repository. klund pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/geode.git
commit 3e8b07c17ee6490b6c733e800065003f8c841904 Author: Kirk Lund <kl...@apache.org> AuthorDate: Fri Nov 2 16:44:16 2018 -0700 GEODE-2644: Add LogConfig and StatisticsConfig for logging --- .../internal/DistributedSystemConfigImpl.java | 46 +++++++++++++++++ .../internal/AbstractDistributionConfig.java | 5 ++ .../distributed/internal/DistributionConfig.java | 11 ++++- .../apache/geode/internal/logging/LogConfig.java | 57 +++++++++++++++++----- .../geode/internal/logging/SecurityLogConfig.java | 32 +++++++----- .../internal/logging/SecurityManagerLogWriter.java | 15 +++--- .../internal/statistics/StatisticsConfig.java | 52 ++++++++++++++++++++ .../internal/DistributedSystemConfigImplTest.java | 57 ++++++++++++++++++++++ 8 files changed, 241 insertions(+), 34 deletions(-) diff --git a/geode-core/src/main/java/org/apache/geode/admin/internal/DistributedSystemConfigImpl.java b/geode-core/src/main/java/org/apache/geode/admin/internal/DistributedSystemConfigImpl.java index 4ce7bb0..2f429e5 100755 --- a/geode-core/src/main/java/org/apache/geode/admin/internal/DistributedSystemConfigImpl.java +++ b/geode-core/src/main/java/org/apache/geode/admin/internal/DistributedSystemConfigImpl.java @@ -53,6 +53,7 @@ import org.apache.geode.internal.logging.LogConfig; import org.apache.geode.internal.logging.LogService; import org.apache.geode.internal.logging.LogWriterImpl; import org.apache.geode.internal.logging.log4j.LogLevel; +import org.apache.geode.internal.statistics.StatisticsConfig; /** * An implementation of the configuration object for an <code>AdminDistributedSystem</code>. After a @@ -282,6 +283,16 @@ public class DistributedSystemConfigImpl implements DistributedSystemConfig { } @Override + public File getSecurityLogFile() { + return null; + } + + @Override + public int getSecurityLogLevel() { + return LogLevel.getLogWriterLevel(DistributedSystemConfigImpl.this.getLogLevel()); + } + + @Override public int getLogFileSizeLimit() { return DistributedSystemConfigImpl.this.getLogFileSizeLimit(); } @@ -300,6 +311,41 @@ public class DistributedSystemConfigImpl implements DistributedSystemConfig { public String toLoggerString() { return DistributedSystemConfigImpl.this.toString(); } + + @Override + public boolean isLoner() { + return false; + } + }; + } + + public StatisticsConfig createStatisticsConfig() { + return new StatisticsConfig() { + + @Override + public File getStatisticArchiveFile() { + return null; + } + + @Override + public int getArchiveFileSizeLimit() { + return 0; + } + + @Override + public int getArchiveDiskSpaceLimit() { + return 0; + } + + @Override + public int getStatisticSampleRate() { + return 0; + } + + @Override + public boolean getStatisticSamplingEnabled() { + return false; + } }; } diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/AbstractDistributionConfig.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/AbstractDistributionConfig.java index 8ab7eb5..3de9c16 100644 --- a/geode-core/src/main/java/org/apache/geode/distributed/internal/AbstractDistributionConfig.java +++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/AbstractDistributionConfig.java @@ -1490,6 +1490,11 @@ public abstract class AbstractDistributionConfig extends AbstractConfig return dcAttDescriptions; } + @Override + public boolean isLoner() { + return getLocators().equals("") && getMcastPort() == 0; + } + static InetAddress _getDefaultMcastAddress() { // Default MCast address can be just IPv4 address. // On IPv6 machines, JGroups converts IPv4 address to equivalent IPv6 address. diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionConfig.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionConfig.java index 465105f..08e5fa0 100644 --- a/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionConfig.java +++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionConfig.java @@ -202,6 +202,7 @@ import org.apache.geode.internal.logging.InternalLogWriter; import org.apache.geode.internal.logging.LogConfig; import org.apache.geode.internal.logging.LogWriterImpl; import org.apache.geode.internal.security.SecurableCommunicationChannel; +import org.apache.geode.internal.statistics.StatisticsConfig; import org.apache.geode.internal.tcp.Connection; import org.apache.geode.memcached.GemFireMemcachedServer; @@ -215,7 +216,7 @@ import org.apache.geode.memcached.GemFireMemcachedServer; * @see Config * @since GemFire 2.1 */ -public interface DistributionConfig extends Config, LogConfig { +public interface DistributionConfig extends Config, LogConfig, StatisticsConfig { /** * The static String definition of the prefix used to defined ssl-* properties @@ -2451,6 +2452,7 @@ public interface DistributionConfig extends Config, LogConfig { * * @return the current security log-level */ + @Override @ConfigAttributeGetter(name = SECURITY_LOG_LEVEL) int getSecurityLogLevel(); @@ -2476,6 +2478,7 @@ public interface DistributionConfig extends Config, LogConfig { * * @return <code>null</code> if logging information goes to standard out */ + @Override @ConfigAttributeGetter(name = SECURITY_LOG_FILE) File getSecurityLogFile(); @@ -5206,6 +5209,12 @@ public interface DistributionConfig extends Config, LogConfig { */ String DEFAULT_SERIALIZABLE_OBJECT_FILTER = "!*"; + /** + * Returns true if locators and mcast-port are not configured. + */ + @Override + boolean isLoner(); + // *************** Initializers to gather all the annotations in this class // ************************ diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/LogConfig.java b/geode-core/src/main/java/org/apache/geode/internal/logging/LogConfig.java index 2df8f79..7586b71 100755 --- a/geode-core/src/main/java/org/apache/geode/internal/logging/LogConfig.java +++ b/geode-core/src/main/java/org/apache/geode/internal/logging/LogConfig.java @@ -16,48 +16,79 @@ package org.apache.geode.internal.logging; import java.io.File; +import org.apache.geode.distributed.ConfigurationProperties; import org.apache.geode.distributed.internal.DistributionConfig; +/** + * Configuration for logging. + */ public interface LogConfig { /** - * Returns the value of the <a href="../DistributedSystem.html#log-level">"log-level"</a> property + * Returns true if the {@code LogConfig} has a non-null and non-default + * {@link ConfigurationProperties#SECURITY_LOG_FILE}. + */ + static boolean hasSecurityLogFile(final LogConfig logConfig) { + return logConfig.getSecurityLogFile() != null + && !logConfig.getSecurityLogFile().equals(new File("")); + } + + /** + * Returns the value of the {@link ConfigurationProperties#LOG_LEVEL} property * * @see LogWriterImpl */ int getLogLevel(); /** - * Returns the value of the <a href="../DistributedSystem.html#log-file">"log-file"</a> property + * Returns the value of the {@link ConfigurationProperties#LOG_FILE} property * - * @return <code>null</code> if logging information goes to standard out + * @return {@code null} if logging information goes to standard out */ File getLogFile(); /** - * Returns the value of the - * <a href="../DistributedSystem.html#log-file-size-limit">"log-file-size-limit"</a> property + * Returns the value of the {@link ConfigurationProperties#SECURITY_LOG_FILE} property + * + * @return {@code null} if logging information goes to standard out + */ + File getSecurityLogFile(); + + /** + * Get the current log-level for {@link ConfigurationProperties#SECURITY_LOG_LEVEL}. + * + * @return the current security log-level + */ + int getSecurityLogLevel(); + + /** + * Returns the value of the {@link ConfigurationProperties#LOG_FILE_SIZE_LIMIT} property */ int getLogFileSizeLimit(); /** - * Returns the value of the - * <a href="../DistributedSystem.html#log-disk-space-limit">"log-disk-space-limit"</a> property + * Returns the value of the {@link ConfigurationProperties#LOG_DISK_SPACE_LIMIT} property */ int getLogDiskSpaceLimit(); /** - * Returns the value of the <a href="../DistributedSystem.html#name">"name"</a> property Gets the - * member's name. A name is optional and by default empty. If set it must be unique in the ds. - * When set its used by tools to help identify the member. - * + * Returns the value of the {@link ConfigurationProperties#NAME} property Gets the member's name. + * A name is optional and by default empty. If set it must be unique in the ds. When set its used + * by tools to help identify the member. * <p> - * The default value is: - * {@link DistributionConfig#DEFAULT_NAME}. + * The default value is: {@link DistributionConfig#DEFAULT_NAME}. * * @return the system's name. */ String getName(); + /** + * Returns string representation of {@code LogConfig} for logging the banner. + */ String toLoggerString(); + + /** + * Returns true if locators and mcast-port are not configured. + */ + boolean isLoner(); } diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/SecurityLogConfig.java b/geode-core/src/main/java/org/apache/geode/internal/logging/SecurityLogConfig.java index fed8ce2..661f766 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/logging/SecurityLogConfig.java +++ b/geode-core/src/main/java/org/apache/geode/internal/logging/SecurityLogConfig.java @@ -16,33 +16,38 @@ package org.apache.geode.internal.logging; import java.io.File; -import org.apache.geode.distributed.internal.DistributionConfig; - /** - * LogConfig implementation for Security logging configuration that delegates to a - * DistributionConfig. + * Wraps a {@link LogConfig} and overrides configuration for Security. */ -class SecurityLogConfig implements LogConfig { +public class SecurityLogConfig implements LogConfig { - private final DistributionConfig config; + private final LogConfig config; - SecurityLogConfig(final DistributionConfig config) { + SecurityLogConfig(final LogConfig config) { this.config = config; } @Override public int getLogLevel() { - // missing from LogConfig return config.getSecurityLogLevel(); } @Override public File getLogFile() { - // missing from LogConfig return config.getSecurityLogFile(); } @Override + public File getSecurityLogFile() { + return config.getSecurityLogFile(); + } + + @Override + public int getSecurityLogLevel() { + return config.getSecurityLogLevel(); + } + + @Override public int getLogFileSizeLimit() { return config.getLogFileSizeLimit(); } @@ -53,12 +58,17 @@ class SecurityLogConfig implements LogConfig { } @Override + public String getName() { + return config.getName(); + } + + @Override public String toLoggerString() { return config.toLoggerString(); } @Override - public String getName() { - return config.getName(); + public boolean isLoner() { + return config.isLoner(); } } diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/SecurityManagerLogWriter.java b/geode-core/src/main/java/org/apache/geode/internal/logging/SecurityManagerLogWriter.java index 7bd9bc2..ff69595 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/logging/SecurityManagerLogWriter.java +++ b/geode-core/src/main/java/org/apache/geode/internal/logging/SecurityManagerLogWriter.java @@ -16,8 +16,6 @@ package org.apache.geode.internal.logging; import java.io.PrintStream; -import org.apache.geode.distributed.internal.DistributionConfig; - /** * A log writer for security related logs. This will prefix all messages with "security-" in the * level part of log-line for easy recognition and filtering if required. Intended usage is in all @@ -32,20 +30,19 @@ import org.apache.geode.distributed.internal.DistributionConfig; */ public class SecurityManagerLogWriter extends ManagerLogWriter { - public SecurityManagerLogWriter(final int level, final PrintStream printStream) { - this(level, printStream, null); + public SecurityManagerLogWriter(final int level, final PrintStream printStream, + final boolean loner) { + this(level, printStream, null, loner); } public SecurityManagerLogWriter(final int level, final PrintStream printStream, - final String connectionName) { - super(level, printStream, connectionName); + final String connectionName, final boolean loner) { + super(level, printStream, connectionName, loner); } @Override public void setConfig(LogConfig config) { - if (config instanceof DistributionConfig) { - config = new SecurityLogConfig((DistributionConfig) config); - } + config = new SecurityLogConfig(config); super.setConfig(config); } diff --git a/geode-core/src/main/java/org/apache/geode/internal/statistics/StatisticsConfig.java b/geode-core/src/main/java/org/apache/geode/internal/statistics/StatisticsConfig.java new file mode 100644 index 0000000..f1996ec --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/internal/statistics/StatisticsConfig.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.geode.internal.statistics; + +import java.io.File; + +import org.apache.geode.distributed.ConfigurationProperties; + +/** + * Configuration for statistics. + */ +public interface StatisticsConfig { + + /** + * Returns the value of the {@link ConfigurationProperties#STATISTIC_ARCHIVE_FILE} property. + * + * @return <code>null</code> if no file was specified + */ + File getStatisticArchiveFile(); + + /** + * Returns the value of the {@link ConfigurationProperties#ARCHIVE_FILE_SIZE_LIMIT} property + */ + int getArchiveFileSizeLimit(); + + /** + * Returns the value of the {@link ConfigurationProperties#ARCHIVE_DISK_SPACE_LIMIT} property + */ + int getArchiveDiskSpaceLimit(); + + /** + * Returns the value of the {@link ConfigurationProperties#STATISTIC_SAMPLE_RATE} property + */ + int getStatisticSampleRate(); + + /** + * Returns the value of the {@link ConfigurationProperties#STATISTIC_SAMPLING_ENABLED} property + */ + boolean getStatisticSamplingEnabled(); +} diff --git a/geode-core/src/test/java/org/apache/geode/admin/internal/DistributedSystemConfigImplTest.java b/geode-core/src/test/java/org/apache/geode/admin/internal/DistributedSystemConfigImplTest.java new file mode 100644 index 0000000..0acbede --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/admin/internal/DistributedSystemConfigImplTest.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.geode.admin.internal; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import org.apache.geode.internal.logging.LogConfig; +import org.apache.geode.internal.logging.LogWriterLevel; +import org.apache.geode.test.junit.categories.LoggingTest; + +/** + * Unit tests for {@link DistributedSystemConfigImpl}. + */ +@Category(LoggingTest.class) +public class DistributedSystemConfigImplTest { + + private DistributedSystemConfigImpl distributedSystemConfigImpl; + + @Before + public void setUp() { + distributedSystemConfigImpl = new DistributedSystemConfigImpl(); + } + + @Test + public void createLogConfigCreatesLogConfigWithUsableLogLevel() { + LogConfig logConfig = distributedSystemConfigImpl.createLogConfig(); + int logLevel = logConfig.getLogLevel(); + + assertThat(logLevel).isNotEqualTo(0); + assertThat(LogWriterLevel.find(logLevel)).isInstanceOf(LogWriterLevel.class); + } + + @Test + public void createLogConfigCreatesLogConfigWithUsableSecurityLogLevel() { + LogConfig logConfig = distributedSystemConfigImpl.createLogConfig(); + int securityLogLevel = logConfig.getSecurityLogLevel(); + + assertThat(securityLogLevel).isNotEqualTo(0); + assertThat(LogWriterLevel.find(securityLogLevel)).isInstanceOf(LogWriterLevel.class); + } +}