You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2024/09/26 17:18:04 UTC
(shardingsphere) branch master updated: Refactor LoggingRule (#33018)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 41477cb2cd3 Refactor LoggingRule (#33018)
41477cb2cd3 is described below
commit 41477cb2cd3b7d2669415bc2a5c65f8670eb3495
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Sep 27 01:17:57 2024 +0800
Refactor LoggingRule (#33018)
* Add test cases on LoggingUtils
* Refactor LoggingRule
* Refactor LoggingRule
* Refactor LoggingRule
---
.../shardingsphere/logging/rule/LoggingRule.java | 13 ++++
.../logging/rule/builder/LoggingRuleBuilder.java | 36 ++++++++-
.../shardingsphere/logging/util/LoggingUtils.java | 83 --------------------
.../logging/rule/LoggingRuleTest.java | 15 +++-
.../rule/builder/LoggingRuleBuilderTest.java | 44 ++++++++++-
.../logging/util/LoggingUtilsTest.java | 89 ----------------------
.../ral/queryable/ShowDistVariableExecutor.java | 6 +-
.../ral/queryable/ShowDistVariablesExecutor.java | 4 +-
.../ral/updatable/SetDistVariableExecutor.java | 8 +-
9 files changed, 108 insertions(+), 190 deletions(-)
diff --git a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/rule/LoggingRule.java b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/rule/LoggingRule.java
index 2e9782ce754..2ee2b786881 100644
--- a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/rule/LoggingRule.java
+++ b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/rule/LoggingRule.java
@@ -20,6 +20,10 @@ package org.apache.shardingsphere.logging.rule;
import lombok.Getter;
import org.apache.shardingsphere.infra.rule.scope.GlobalRule;
import org.apache.shardingsphere.logging.config.LoggingRuleConfiguration;
+import org.apache.shardingsphere.logging.constant.LoggingConstants;
+import org.apache.shardingsphere.logging.logger.ShardingSphereLogger;
+
+import java.util.Optional;
/**
* Logging rule.
@@ -32,4 +36,13 @@ public final class LoggingRule implements GlobalRule {
public LoggingRule(final LoggingRuleConfiguration ruleConfig) {
configuration = ruleConfig;
}
+
+ /**
+ * Get SQL logger.
+ *
+ * @return SQL logger
+ */
+ public Optional<ShardingSphereLogger> getSQLLogger() {
+ return configuration.getLoggers().stream().filter(each -> LoggingConstants.SQL_LOG_TOPIC.equalsIgnoreCase(each.getLoggerName())).findFirst();
+ }
}
diff --git a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/rule/builder/LoggingRuleBuilder.java b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/rule/builder/LoggingRuleBuilder.java
index 90ad7422abf..1f331e524d3 100644
--- a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/rule/builder/LoggingRuleBuilder.java
+++ b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/rule/builder/LoggingRuleBuilder.java
@@ -21,11 +21,14 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder;
import org.apache.shardingsphere.logging.config.LoggingRuleConfiguration;
+import org.apache.shardingsphere.logging.constant.LoggingConstants;
import org.apache.shardingsphere.logging.constant.LoggingOrder;
+import org.apache.shardingsphere.logging.logger.ShardingSphereLogger;
import org.apache.shardingsphere.logging.rule.LoggingRule;
-import org.apache.shardingsphere.logging.util.LoggingUtils;
import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
/**
* Logging rule builder.
@@ -34,10 +37,39 @@ public final class LoggingRuleBuilder implements GlobalRuleBuilder<LoggingRuleCo
@Override
public LoggingRule build(final LoggingRuleConfiguration ruleConfig, final Map<String, ShardingSphereDatabase> databases, final ConfigurationProperties props) {
- LoggingUtils.syncLoggingRuleConfiguration(ruleConfig, props);
+ syncLoggingRuleConfiguration(ruleConfig, props);
return new LoggingRule(ruleConfig);
}
+ private void syncLoggingRuleConfiguration(final LoggingRuleConfiguration ruleConfig, final ConfigurationProperties props) {
+ getSQLLogger(ruleConfig).ifPresent(optional -> {
+ syncPropertiesToRule(optional.getProps(), props);
+ syncRuleToProperties(optional.getProps(), props);
+ });
+ }
+
+ private Optional<ShardingSphereLogger> getSQLLogger(final LoggingRuleConfiguration ruleConfig) {
+ return ruleConfig.getLoggers().stream().filter(each -> LoggingConstants.SQL_LOG_TOPIC.equalsIgnoreCase(each.getLoggerName())).findFirst();
+ }
+
+ private void syncPropertiesToRule(final Properties loggerProps, final ConfigurationProperties props) {
+ if (!loggerProps.containsKey(LoggingConstants.SQL_LOG_ENABLE) && props.getProps().containsKey(LoggingConstants.SQL_SHOW)) {
+ loggerProps.setProperty(LoggingConstants.SQL_LOG_ENABLE, props.getProps().get(LoggingConstants.SQL_SHOW).toString());
+ }
+ if (!loggerProps.containsKey(LoggingConstants.SQL_LOG_SIMPLE) && props.getProps().containsKey(LoggingConstants.SQL_SIMPLE)) {
+ loggerProps.setProperty(LoggingConstants.SQL_LOG_SIMPLE, props.getProps().get(LoggingConstants.SQL_SIMPLE).toString());
+ }
+ }
+
+ private void syncRuleToProperties(final Properties loggerProps, final ConfigurationProperties props) {
+ if (loggerProps.containsKey(LoggingConstants.SQL_LOG_ENABLE)) {
+ props.getProps().setProperty(LoggingConstants.SQL_SHOW, loggerProps.get(LoggingConstants.SQL_LOG_ENABLE).toString());
+ }
+ if (loggerProps.containsKey(LoggingConstants.SQL_LOG_SIMPLE)) {
+ props.getProps().setProperty(LoggingConstants.SQL_SIMPLE, loggerProps.get(LoggingConstants.SQL_LOG_SIMPLE).toString());
+ }
+ }
+
@Override
public int getOrder() {
return LoggingOrder.ORDER;
diff --git a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/util/LoggingUtils.java b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/util/LoggingUtils.java
deleted file mode 100644
index a18362f22ec..00000000000
--- a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/util/LoggingUtils.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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.shardingsphere.logging.util;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
-import org.apache.shardingsphere.logging.config.LoggingRuleConfiguration;
-import org.apache.shardingsphere.logging.constant.LoggingConstants;
-import org.apache.shardingsphere.logging.logger.ShardingSphereLogger;
-import org.apache.shardingsphere.logging.rule.LoggingRule;
-
-import java.util.Optional;
-import java.util.Properties;
-
-/**
- * Logging utility class.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class LoggingUtils {
-
- /**
- * Get ShardingSphere logger.
- *
- * @param globalRuleMetaData ShardingSphere rule metaData
- * @return ShardingSphere logger
- */
- public static Optional<ShardingSphereLogger> getSQLLogger(final RuleMetaData globalRuleMetaData) {
- return globalRuleMetaData.findSingleRule(LoggingRule.class).isPresent() ? getSQLLogger(globalRuleMetaData.getSingleRule(LoggingRule.class).getConfiguration()) : Optional.empty();
- }
-
- private static Optional<ShardingSphereLogger> getSQLLogger(final LoggingRuleConfiguration ruleConfig) {
- return ruleConfig.getLoggers().stream().filter(each -> LoggingConstants.SQL_LOG_TOPIC.equalsIgnoreCase(each.getLoggerName())).findFirst();
- }
-
- /**
- * Synchronize the log-related configuration in logging rule and props.
- * Use the configuration in the logging rule first.
- *
- * @param ruleConfig logging rule configuration
- * @param props configuration properties
- */
- public static void syncLoggingRuleConfiguration(final LoggingRuleConfiguration ruleConfig, final ConfigurationProperties props) {
- getSQLLogger(ruleConfig).ifPresent(optional -> {
- syncPropertiesToRule(optional.getProps(), props);
- syncRuleToProperties(optional.getProps(), props);
- });
- }
-
- private static void syncPropertiesToRule(final Properties loggerProps, final ConfigurationProperties props) {
- if (!loggerProps.containsKey(LoggingConstants.SQL_LOG_ENABLE) && props.getProps().containsKey(LoggingConstants.SQL_SHOW)) {
- loggerProps.setProperty(LoggingConstants.SQL_LOG_ENABLE, props.getProps().get(LoggingConstants.SQL_SHOW).toString());
- }
- if (!loggerProps.containsKey(LoggingConstants.SQL_LOG_SIMPLE) && props.getProps().containsKey(LoggingConstants.SQL_SIMPLE)) {
- loggerProps.setProperty(LoggingConstants.SQL_LOG_SIMPLE, props.getProps().get(LoggingConstants.SQL_SIMPLE).toString());
- }
- }
-
- private static void syncRuleToProperties(final Properties loggerProps, final ConfigurationProperties props) {
- if (loggerProps.containsKey(LoggingConstants.SQL_LOG_ENABLE)) {
- props.getProps().setProperty(LoggingConstants.SQL_SHOW, loggerProps.get(LoggingConstants.SQL_LOG_ENABLE).toString());
- }
- if (loggerProps.containsKey(LoggingConstants.SQL_LOG_SIMPLE)) {
- props.getProps().setProperty(LoggingConstants.SQL_SIMPLE, loggerProps.get(LoggingConstants.SQL_LOG_SIMPLE).toString());
- }
- }
-}
diff --git a/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/rule/LoggingRuleTest.java b/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/rule/LoggingRuleTest.java
index a44fec3235e..cdc832c6f78 100644
--- a/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/rule/LoggingRuleTest.java
+++ b/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/rule/LoggingRuleTest.java
@@ -18,15 +18,18 @@
package org.apache.shardingsphere.logging.rule;
import org.apache.shardingsphere.logging.config.LoggingRuleConfiguration;
+import org.apache.shardingsphere.logging.constant.LoggingConstants;
import org.apache.shardingsphere.logging.logger.ShardingSphereAppender;
import org.apache.shardingsphere.logging.logger.ShardingSphereLogger;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Collections;
+import java.util.Optional;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
class LoggingRuleTest {
@@ -34,13 +37,17 @@ class LoggingRuleTest {
@BeforeEach
void setup() {
- loggingRule = new LoggingRule(new LoggingRuleConfiguration(Collections.singleton(new ShardingSphereLogger("ROOT", "INFO", true, "console")),
+ loggingRule = new LoggingRule(new LoggingRuleConfiguration(Collections.singleton(new ShardingSphereLogger(LoggingConstants.SQL_LOG_TOPIC, "INFO", true, "console")),
Collections.singleton(new ShardingSphereAppender("console", "ch.qos.logback.core.ConsoleAppender", "[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n"))));
}
@Test
- void assertGetConfiguration() {
- assertThat(loggingRule.getConfiguration().getLoggers().size(), is(1));
- assertThat(loggingRule.getConfiguration().getAppenders().size(), is(1));
+ void assertGetSQLLoggerWhenLoggingRulePresent() {
+ Optional<ShardingSphereLogger> logger = loggingRule.getSQLLogger();
+ assertTrue(logger.isPresent());
+ assertThat(logger.get().getLoggerName(), is(LoggingConstants.SQL_LOG_TOPIC));
+ assertThat(logger.get().getLevel(), is("INFO"));
+ assertTrue(logger.get().getAdditivity());
+ assertThat(logger.get().getAppenderName(), is("console"));
}
}
diff --git a/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/rule/builder/LoggingRuleBuilderTest.java b/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/rule/builder/LoggingRuleBuilderTest.java
index d3d25d8ea9b..537e2a580be 100644
--- a/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/rule/builder/LoggingRuleBuilderTest.java
+++ b/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/rule/builder/LoggingRuleBuilderTest.java
@@ -21,7 +21,11 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder;
import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
import org.apache.shardingsphere.logging.config.LoggingRuleConfiguration;
+import org.apache.shardingsphere.logging.constant.LoggingConstants;
+import org.apache.shardingsphere.logging.logger.ShardingSphereLogger;
import org.apache.shardingsphere.logging.rule.LoggingRule;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.Test;
import java.util.Collections;
@@ -29,14 +33,48 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
class LoggingRuleBuilderTest {
@Test
- void assertBuild() {
- LoggingRuleConfiguration ruleConfig = new LoggingRuleConfiguration(Collections.emptyList(), Collections.emptyList());
+ void assertBuildWhenSyncPropertiesToRule() {
+ ShardingSphereLogger logger = new ShardingSphereLogger(LoggingConstants.SQL_LOG_TOPIC, null, false, null);
+ LoggingRuleConfiguration ruleConfig = new LoggingRuleConfiguration(Collections.singleton(logger), Collections.emptyList());
+ ConfigurationProperties props = new ConfigurationProperties(PropertiesBuilder.build(
+ new Property(LoggingConstants.SQL_SHOW, Boolean.TRUE.toString()), new Property(LoggingConstants.SQL_SIMPLE, Boolean.TRUE.toString())));
LoggingRuleBuilder ruleBuilder = (LoggingRuleBuilder) OrderedSPILoader.getServices(GlobalRuleBuilder.class, Collections.singleton(ruleConfig)).get(ruleConfig);
- LoggingRule actual = ruleBuilder.build(ruleConfig, Collections.emptyMap(), new ConfigurationProperties(new Properties()));
+ LoggingRule actual = ruleBuilder.build(ruleConfig, Collections.emptyMap(), props);
assertThat(actual.getConfiguration(), is(ruleConfig));
+ assertThat(logger.getProps().getProperty(LoggingConstants.SQL_LOG_ENABLE), is(Boolean.TRUE.toString()));
+ assertThat(logger.getProps().getProperty(LoggingConstants.SQL_LOG_SIMPLE), is(Boolean.TRUE.toString()));
+ }
+
+ @Test
+ void assertBuildWhenSyncRuleToProperties() {
+ ShardingSphereLogger logger = new ShardingSphereLogger(LoggingConstants.SQL_LOG_TOPIC, null, false, null);
+ logger.getProps().setProperty(LoggingConstants.SQL_LOG_ENABLE, Boolean.TRUE.toString());
+ logger.getProps().setProperty(LoggingConstants.SQL_LOG_SIMPLE, Boolean.TRUE.toString());
+ LoggingRuleConfiguration ruleConfig = new LoggingRuleConfiguration(Collections.singleton(logger), Collections.emptyList());
+ ConfigurationProperties props = new ConfigurationProperties(new Properties());
+ LoggingRuleBuilder ruleBuilder = (LoggingRuleBuilder) OrderedSPILoader.getServices(GlobalRuleBuilder.class, Collections.singleton(ruleConfig)).get(ruleConfig);
+ LoggingRule actual = ruleBuilder.build(ruleConfig, Collections.emptyMap(), props);
+ assertThat(actual.getConfiguration(), is(ruleConfig));
+ assertThat(props.getProps().getProperty(LoggingConstants.SQL_SHOW), is(Boolean.TRUE.toString()));
+ assertThat(props.getProps().getProperty(LoggingConstants.SQL_SIMPLE), is(Boolean.TRUE.toString()));
+ }
+
+ @Test
+ void assertBuildWhenSyncNothing() {
+ ShardingSphereLogger logger = new ShardingSphereLogger(LoggingConstants.SQL_LOG_TOPIC, null, false, null);
+ LoggingRuleConfiguration ruleConfig = new LoggingRuleConfiguration(Collections.singleton(logger), Collections.emptyList());
+ ConfigurationProperties props = new ConfigurationProperties(new Properties());
+ LoggingRuleBuilder ruleBuilder = (LoggingRuleBuilder) OrderedSPILoader.getServices(GlobalRuleBuilder.class, Collections.singleton(ruleConfig)).get(ruleConfig);
+ LoggingRule actual = ruleBuilder.build(ruleConfig, Collections.emptyMap(), props);
+ assertThat(actual.getConfiguration(), is(ruleConfig));
+ assertFalse(logger.getProps().containsKey(LoggingConstants.SQL_LOG_ENABLE));
+ assertFalse(logger.getProps().containsKey(LoggingConstants.SQL_LOG_SIMPLE));
+ assertFalse(props.getProps().containsKey(LoggingConstants.SQL_SHOW));
+ assertFalse(props.getProps().containsKey(LoggingConstants.SQL_SIMPLE));
}
}
diff --git a/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/util/LoggingUtilsTest.java b/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/util/LoggingUtilsTest.java
deleted file mode 100644
index f4faf68b65c..00000000000
--- a/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/util/LoggingUtilsTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * 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.shardingsphere.logging.util;
-
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
-import org.apache.shardingsphere.logging.config.LoggingRuleConfiguration;
-import org.apache.shardingsphere.logging.constant.LoggingConstants;
-import org.apache.shardingsphere.logging.logger.ShardingSphereLogger;
-import org.apache.shardingsphere.logging.rule.LoggingRule;
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collections;
-import java.util.Optional;
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class LoggingUtilsTest {
-
- @Test
- void assertGetSQLLoggerWhenLoggingRuleAbsent() {
- assertFalse(LoggingUtils.getSQLLogger(mock(RuleMetaData.class)).isPresent());
- }
-
- @Test
- void assertGetSQLLoggerWhenLoggingRulePresent() {
- RuleMetaData ruleMetaData = mock(RuleMetaData.class);
- LoggingRule loggingRule = new LoggingRule(new LoggingRuleConfiguration(
- Collections.singleton(new ShardingSphereLogger(LoggingConstants.SQL_LOG_TOPIC, null, false, null)), Collections.emptyList()));
- when(ruleMetaData.findSingleRule(LoggingRule.class)).thenReturn(Optional.of(loggingRule));
- when(ruleMetaData.getSingleRule(LoggingRule.class)).thenReturn(loggingRule);
- assertTrue(LoggingUtils.getSQLLogger(ruleMetaData).isPresent());
- }
-
- @Test
- void assertSyncLoggingRuleConfigurationWhenSyncPropertiesToRule() {
- ShardingSphereLogger logger = new ShardingSphereLogger(LoggingConstants.SQL_LOG_TOPIC, null, false, null);
- ConfigurationProperties props = new ConfigurationProperties(PropertiesBuilder.build(
- new Property(LoggingConstants.SQL_SHOW, Boolean.TRUE.toString()), new Property(LoggingConstants.SQL_SIMPLE, Boolean.TRUE.toString())));
- LoggingUtils.syncLoggingRuleConfiguration(new LoggingRuleConfiguration(Collections.singleton(logger), Collections.emptyList()), props);
- assertThat(logger.getProps().getProperty(LoggingConstants.SQL_LOG_ENABLE), is(Boolean.TRUE.toString()));
- assertThat(logger.getProps().getProperty(LoggingConstants.SQL_LOG_SIMPLE), is(Boolean.TRUE.toString()));
- }
-
- @Test
- void assertSyncLoggingRuleConfigurationWhenSyncRuleToProperties() {
- ShardingSphereLogger logger = new ShardingSphereLogger(LoggingConstants.SQL_LOG_TOPIC, null, false, null);
- logger.getProps().setProperty(LoggingConstants.SQL_LOG_ENABLE, Boolean.TRUE.toString());
- logger.getProps().setProperty(LoggingConstants.SQL_LOG_SIMPLE, Boolean.TRUE.toString());
- ConfigurationProperties props = new ConfigurationProperties(new Properties());
- LoggingUtils.syncLoggingRuleConfiguration(new LoggingRuleConfiguration(Collections.singleton(logger), Collections.emptyList()), props);
- assertThat(props.getProps().getProperty(LoggingConstants.SQL_SHOW), is(Boolean.TRUE.toString()));
- assertThat(props.getProps().getProperty(LoggingConstants.SQL_SIMPLE), is(Boolean.TRUE.toString()));
- }
-
- @Test
- void assertSyncLoggingRuleConfigurationWhenSyncNothing() {
- ShardingSphereLogger logger = new ShardingSphereLogger(LoggingConstants.SQL_LOG_TOPIC, null, false, null);
- ConfigurationProperties props = new ConfigurationProperties(new Properties());
- LoggingUtils.syncLoggingRuleConfiguration(new LoggingRuleConfiguration(Collections.singleton(logger), Collections.emptyList()), props);
- assertFalse(logger.getProps().containsKey(LoggingConstants.SQL_LOG_ENABLE));
- assertFalse(logger.getProps().containsKey(LoggingConstants.SQL_LOG_SIMPLE));
- assertFalse(props.getProps().containsKey(LoggingConstants.SQL_SHOW));
- assertFalse(props.getProps().containsKey(LoggingConstants.SQL_SIMPLE));
- }
-}
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutor.java
index 3b12f19099f..42400d3e25d 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutor.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutor.java
@@ -25,14 +25,14 @@ import org.apache.shardingsphere.distsql.statement.ral.queryable.show.ShowDistVa
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationPropertyKey;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.exception.kernel.syntax.UnsupportedVariableException;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
import org.apache.shardingsphere.logging.constant.LoggingConstants;
import org.apache.shardingsphere.logging.logger.ShardingSphereLogger;
-import org.apache.shardingsphere.logging.util.LoggingUtils;
+import org.apache.shardingsphere.logging.rule.LoggingRule;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.infra.exception.kernel.syntax.UnsupportedVariableException;
import org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.DistSQLVariable;
import java.util.Arrays;
@@ -78,7 +78,7 @@ public final class ShowDistVariableExecutor implements DistSQLQueryExecutor<Show
}
private String getLoggingPropsValue(final ShardingSphereMetaData metaData, final String variableName) {
- Optional<ShardingSphereLogger> sqlLogger = LoggingUtils.getSQLLogger(metaData.getGlobalRuleMetaData());
+ Optional<ShardingSphereLogger> sqlLogger = metaData.getGlobalRuleMetaData().findSingleRule(LoggingRule.class).flatMap(LoggingRule::getSQLLogger);
if (sqlLogger.isPresent()) {
Properties props = sqlLogger.get().getProps();
switch (variableName) {
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java
index 5376d792b8c..7a8be3f4f27 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java
@@ -30,7 +30,7 @@ import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
import org.apache.shardingsphere.infra.util.regex.RegexUtils;
import org.apache.shardingsphere.logging.constant.LoggingConstants;
import org.apache.shardingsphere.logging.logger.ShardingSphereLogger;
-import org.apache.shardingsphere.logging.util.LoggingUtils;
+import org.apache.shardingsphere.logging.rule.LoggingRule;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.DistSQLVariable;
@@ -81,7 +81,7 @@ public final class ShowDistVariablesExecutor implements DistSQLQueryExecutor<Sho
}
private void addLoggingPropsRows(final ShardingSphereMetaData metaData, final Collection<LocalDataQueryResultRow> rows) {
- Optional<ShardingSphereLogger> sqlLogger = LoggingUtils.getSQLLogger(metaData.getGlobalRuleMetaData());
+ Optional<ShardingSphereLogger> sqlLogger = metaData.getGlobalRuleMetaData().findSingleRule(LoggingRule.class).flatMap(LoggingRule::getSQLLogger);
if (sqlLogger.isPresent()) {
Properties sqlLoggerProps = sqlLogger.get().getProps();
rows.add(new LocalDataQueryResultRow(LoggingConstants.SQL_SHOW_VARIABLE_NAME, sqlLoggerProps.getOrDefault(LoggingConstants.SQL_LOG_ENABLE, Boolean.FALSE).toString()));
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutor.java
index 1517c07be1c..3326907589b 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutor.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableExecutor.java
@@ -33,7 +33,7 @@ import org.apache.shardingsphere.infra.props.TypedPropertyValue;
import org.apache.shardingsphere.infra.props.exception.TypedPropertyValueException;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
import org.apache.shardingsphere.logging.constant.LoggingConstants;
-import org.apache.shardingsphere.logging.util.LoggingUtils;
+import org.apache.shardingsphere.logging.rule.LoggingRule;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.decorator.RuleConfigurationPersistDecorateEngine;
@@ -102,7 +102,7 @@ public final class SetDistVariableExecutor implements DistSQLUpdateExecutor<SetD
private void syncSQLShowToLoggingRule(final TypedPropertyKey propertyKey, final MetaDataContexts metaDataContexts, final String value, final ContextManager contextManager) {
if (LoggingConstants.SQL_SHOW.equalsIgnoreCase(propertyKey.getKey())) {
- LoggingUtils.getSQLLogger(metaDataContexts.getMetaData().getGlobalRuleMetaData()).ifPresent(option -> {
+ metaDataContexts.getMetaData().getGlobalRuleMetaData().findSingleRule(LoggingRule.class).flatMap(LoggingRule::getSQLLogger).ifPresent(option -> {
option.getProps().setProperty(LoggingConstants.SQL_LOG_ENABLE, value);
decorateGlobalRuleConfiguration(contextManager);
});
@@ -111,8 +111,8 @@ public final class SetDistVariableExecutor implements DistSQLUpdateExecutor<SetD
private void syncSQLSimpleToLoggingRule(final TypedPropertyKey propertyKey, final MetaDataContexts metaDataContexts, final String value, final ContextManager contextManager) {
if (LoggingConstants.SQL_SIMPLE.equalsIgnoreCase(propertyKey.getKey())) {
- LoggingUtils.getSQLLogger(metaDataContexts.getMetaData().getGlobalRuleMetaData()).ifPresent(option -> {
- option.getProps().setProperty(LoggingConstants.SQL_LOG_SIMPLE, value);
+ metaDataContexts.getMetaData().getGlobalRuleMetaData().findSingleRule(LoggingRule.class).flatMap(LoggingRule::getSQLLogger).ifPresent(optional -> {
+ optional.getProps().setProperty(LoggingConstants.SQL_LOG_SIMPLE, value);
decorateGlobalRuleConfiguration(contextManager);
});
}