This is an automated email from the ASF dual-hosted git repository.
menghaoran 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 c2dcf3d [DistSQL] Add syntax `ENABLE/DISABLE SHARDING SCALING`.
(#14704)
c2dcf3d is described below
commit c2dcf3d1e5f4459d3007a14f64712bfc319d28a8
Author: Raigor <[email protected]>
AuthorDate: Wed Jan 12 18:26:30 2022 +0800
[DistSQL] Add syntax `ENABLE/DISABLE SHARDING SCALING`. (#14704)
* Add syntax `ENABLE/DISABLE SHARDING SCALING`.
* register SPI services.
---
...=> DisableShardingScalingStatementUpdater.java} | 46 ++++++-----
.../DropShardingScalingStatementUpdater.java | 6 +-
... => EnableShardingScalingStatementUpdater.java} | 48 ++++++-----
...here.infra.distsql.update.RuleDefinitionUpdater | 2 +
...isabledShardingScalingStatementUpdaterTest.java | 86 ++++++++++++++++++++
.../EnableShardingScalingStatementUpdaterTest.java | 95 ++++++++++++++++++++++
.../src/main/antlr4/imports/scaling/Keyword.g4 | 8 ++
.../main/antlr4/imports/scaling/RDLStatement.g4 | 8 ++
.../distsql/parser/autogen/ScalingStatement.g4 | 2 +
.../parser/core/ScalingSQLStatementVisitor.java | 22 ++++-
.../DisableShardingScalingStatement.java} | 30 +++----
.../statement/EnableShardingScalingStatement.java} | 30 +++----
.../rule/RequiredRuleMissedException.java | 4 +
.../exception/rule/RuleDisabledException.java | 30 +++----
.../exception/rule/RuleEnabledException.java | 30 +++----
.../rdl/alter/AlterRuleStatementAssert.java | 10 +++
.../DisableShardingScalingStatementAssert.java | 53 ++++++++++++
.../impl/EnableShardingScalingStatementAssert.java | 53 ++++++++++++
.../jaxb/cases/domain/SQLParserTestCases.java | 10 +++
.../DisableShardingScalingStatementTestCase.java | 33 ++++----
.../EnableShardingScalingStatementTestCase.java | 33 ++++----
.../src/main/resources/case/rdl/alter.xml | 3 +
.../src/main/resources/sql/supported/rdl/alter.xml | 2 +
23 files changed, 488 insertions(+), 156 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/DropShardingScalingStatementUpdater.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/DisableShardingScalingStatementUpdater.java
similarity index 59%
copy from
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/DropShardingScalingStatementUpdater.java
copy to
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/DisableShardingScalingStatementUpdater.java
index fed4dcb..88efbc2 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/DropShardingScalingStatementUpdater.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/DisableShardingScalingStatementUpdater.java
@@ -19,50 +19,52 @@ package org.apache.shardingsphere.scaling.distsql.handler;
import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import
org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException;
-import
org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater;
+import
org.apache.shardingsphere.infra.distsql.exception.rule.RuleDisabledException;
+import
org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.scaling.distsql.statement.DropShardingScalingStatement;
+import
org.apache.shardingsphere.scaling.distsql.statement.DisableShardingScalingStatement;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import java.util.Arrays;
-
/**
- * Drop sharding scaling statement updater.
+ * Disable sharding scaling statement updater.
*/
-public final class DropShardingScalingStatementUpdater implements
RuleDefinitionDropUpdater<DropShardingScalingStatement,
ShardingRuleConfiguration> {
+public final class DisableShardingScalingStatementUpdater implements
RuleDefinitionAlterUpdater<DisableShardingScalingStatement,
ShardingRuleConfiguration> {
@Override
- public void checkSQLStatement(final ShardingSphereMetaData
shardingSphereMetaData, final DropShardingScalingStatement sqlStatement,
+ public void checkSQLStatement(final ShardingSphereMetaData
shardingSphereMetaData, final DisableShardingScalingStatement sqlStatement,
final ShardingRuleConfiguration
currentRuleConfig) throws DistSQLException {
String schemaName = shardingSphereMetaData.getName();
checkCurrentRuleConfiguration(schemaName, currentRuleConfig);
- checkStatement(schemaName, sqlStatement, currentRuleConfig);
+ checkExist(schemaName, sqlStatement, currentRuleConfig);
+ checkDisabled(schemaName, sqlStatement, currentRuleConfig);
}
-
+
private void checkCurrentRuleConfiguration(final String schemaName, final
ShardingRuleConfiguration currentRuleConfig) throws RequiredRuleMissedException
{
if (null == currentRuleConfig) {
throw new RequiredRuleMissedException("Sharding", schemaName);
}
}
- private void checkStatement(final String schemaName, final
DropShardingScalingStatement sqlStatement, final ShardingRuleConfiguration
currentRuleConfig) throws DistSQLException {
- checkExist(schemaName, sqlStatement, currentRuleConfig);
- // TODO checkNotInUse
+ private void checkExist(final String schemaName, final
DisableShardingScalingStatement sqlStatement, final ShardingRuleConfiguration
currentRuleConfig) throws DistSQLException {
+ if
(!currentRuleConfig.getScaling().containsKey(sqlStatement.getScalingName())) {
+ throw new RequiredRuleMissedException("Scaling", schemaName,
sqlStatement.getScalingName());
+ }
}
- private void checkExist(final String schemaName, final
DropShardingScalingStatement sqlStatement, final ShardingRuleConfiguration
currentRuleConfig) throws DistSQLException {
- if
(!currentRuleConfig.getScaling().containsKey(sqlStatement.getScalingName())) {
- throw new RequiredRuleMissedException("Scaling", schemaName,
Arrays.asList(sqlStatement.getScalingName()));
+ private void checkDisabled(final String schemaName, final
DisableShardingScalingStatement sqlStatement, final ShardingRuleConfiguration
currentRuleConfig) throws DistSQLException {
+ if (null == currentRuleConfig.getScalingName() ||
!currentRuleConfig.getScalingName().equals(sqlStatement.getScalingName())) {
+ throw new RuleDisabledException("Scaling", schemaName,
sqlStatement.getScalingName());
}
}
@Override
- public boolean updateCurrentRuleConfiguration(final
DropShardingScalingStatement sqlStatement, final ShardingRuleConfiguration
currentRuleConfig) {
- currentRuleConfig.getScaling().remove(sqlStatement.getScalingName());
- if (null != currentRuleConfig.getScalingName() &&
currentRuleConfig.getScalingName().equalsIgnoreCase(sqlStatement.getScalingName()))
{
- currentRuleConfig.setScalingName(null);
- }
- return false;
+ public ShardingRuleConfiguration buildToBeAlteredRuleConfiguration(final
DisableShardingScalingStatement sqlStatement) {
+ return null;
+ }
+
+ @Override
+ public void updateCurrentRuleConfiguration(final ShardingRuleConfiguration
currentRuleConfig, final ShardingRuleConfiguration toBeAlteredRuleConfig) {
+ currentRuleConfig.setScalingName(null);
}
@Override
@@ -72,6 +74,6 @@ public final class DropShardingScalingStatementUpdater
implements RuleDefinition
@Override
public String getType() {
- return DropShardingScalingStatement.class.getCanonicalName();
+ return DisableShardingScalingStatement.class.getCanonicalName();
}
}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/DropShardingScalingStatementUpdater.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/DropShardingScalingStatementUpdater.java
index fed4dcb..6507bd4 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/DropShardingScalingStatementUpdater.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/DropShardingScalingStatementUpdater.java
@@ -24,8 +24,6 @@ import
org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.scaling.distsql.statement.DropShardingScalingStatement;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import java.util.Arrays;
-
/**
* Drop sharding scaling statement updater.
*/
@@ -38,7 +36,7 @@ public final class DropShardingScalingStatementUpdater
implements RuleDefinition
checkCurrentRuleConfiguration(schemaName, currentRuleConfig);
checkStatement(schemaName, sqlStatement, currentRuleConfig);
}
-
+
private void checkCurrentRuleConfiguration(final String schemaName, final
ShardingRuleConfiguration currentRuleConfig) throws RequiredRuleMissedException
{
if (null == currentRuleConfig) {
throw new RequiredRuleMissedException("Sharding", schemaName);
@@ -52,7 +50,7 @@ public final class DropShardingScalingStatementUpdater
implements RuleDefinition
private void checkExist(final String schemaName, final
DropShardingScalingStatement sqlStatement, final ShardingRuleConfiguration
currentRuleConfig) throws DistSQLException {
if
(!currentRuleConfig.getScaling().containsKey(sqlStatement.getScalingName())) {
- throw new RequiredRuleMissedException("Scaling", schemaName,
Arrays.asList(sqlStatement.getScalingName()));
+ throw new RequiredRuleMissedException("Scaling", schemaName,
sqlStatement.getScalingName());
}
}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/DropShardingScalingStatementUpdater.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/EnableShardingScalingStatementUpdater.java
similarity index 59%
copy from
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/DropShardingScalingStatementUpdater.java
copy to
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/EnableShardingScalingStatementUpdater.java
index fed4dcb..78d14c1 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/DropShardingScalingStatementUpdater.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/EnableShardingScalingStatementUpdater.java
@@ -19,50 +19,54 @@ package org.apache.shardingsphere.scaling.distsql.handler;
import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import
org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException;
-import
org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater;
+import
org.apache.shardingsphere.infra.distsql.exception.rule.RuleEnabledException;
+import
org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.scaling.distsql.statement.DropShardingScalingStatement;
+import
org.apache.shardingsphere.scaling.distsql.statement.EnableShardingScalingStatement;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import java.util.Arrays;
-
/**
- * Drop sharding scaling statement updater.
+ * Enable sharding scaling statement updater.
*/
-public final class DropShardingScalingStatementUpdater implements
RuleDefinitionDropUpdater<DropShardingScalingStatement,
ShardingRuleConfiguration> {
+public final class EnableShardingScalingStatementUpdater implements
RuleDefinitionAlterUpdater<EnableShardingScalingStatement,
ShardingRuleConfiguration> {
@Override
- public void checkSQLStatement(final ShardingSphereMetaData
shardingSphereMetaData, final DropShardingScalingStatement sqlStatement,
+ public void checkSQLStatement(final ShardingSphereMetaData
shardingSphereMetaData, final EnableShardingScalingStatement sqlStatement,
final ShardingRuleConfiguration
currentRuleConfig) throws DistSQLException {
String schemaName = shardingSphereMetaData.getName();
checkCurrentRuleConfiguration(schemaName, currentRuleConfig);
- checkStatement(schemaName, sqlStatement, currentRuleConfig);
+ checkExist(schemaName, sqlStatement, currentRuleConfig);
+ checkEnabled(schemaName, sqlStatement, currentRuleConfig);
}
-
+
private void checkCurrentRuleConfiguration(final String schemaName, final
ShardingRuleConfiguration currentRuleConfig) throws RequiredRuleMissedException
{
if (null == currentRuleConfig) {
throw new RequiredRuleMissedException("Sharding", schemaName);
}
}
- private void checkStatement(final String schemaName, final
DropShardingScalingStatement sqlStatement, final ShardingRuleConfiguration
currentRuleConfig) throws DistSQLException {
- checkExist(schemaName, sqlStatement, currentRuleConfig);
- // TODO checkNotInUse
+ private void checkExist(final String schemaName, final
EnableShardingScalingStatement sqlStatement, final ShardingRuleConfiguration
currentRuleConfig) throws DistSQLException {
+ if
(!currentRuleConfig.getScaling().containsKey(sqlStatement.getScalingName())) {
+ throw new RequiredRuleMissedException("Scaling", schemaName,
sqlStatement.getScalingName());
+ }
}
- private void checkExist(final String schemaName, final
DropShardingScalingStatement sqlStatement, final ShardingRuleConfiguration
currentRuleConfig) throws DistSQLException {
- if
(!currentRuleConfig.getScaling().containsKey(sqlStatement.getScalingName())) {
- throw new RequiredRuleMissedException("Scaling", schemaName,
Arrays.asList(sqlStatement.getScalingName()));
+ private void checkEnabled(final String schemaName, final
EnableShardingScalingStatement sqlStatement, final ShardingRuleConfiguration
currentRuleConfig) throws DistSQLException {
+ if (null != currentRuleConfig.getScalingName() &&
currentRuleConfig.getScalingName().equals(sqlStatement.getScalingName())) {
+ throw new RuleEnabledException("Scaling", schemaName,
sqlStatement.getScalingName());
}
}
@Override
- public boolean updateCurrentRuleConfiguration(final
DropShardingScalingStatement sqlStatement, final ShardingRuleConfiguration
currentRuleConfig) {
- currentRuleConfig.getScaling().remove(sqlStatement.getScalingName());
- if (null != currentRuleConfig.getScalingName() &&
currentRuleConfig.getScalingName().equalsIgnoreCase(sqlStatement.getScalingName()))
{
- currentRuleConfig.setScalingName(null);
- }
- return false;
+ public ShardingRuleConfiguration buildToBeAlteredRuleConfiguration(final
EnableShardingScalingStatement sqlStatement) {
+ ShardingRuleConfiguration result = new ShardingRuleConfiguration();
+ result.setScalingName(sqlStatement.getScalingName());
+ return result;
+ }
+
+ @Override
+ public void updateCurrentRuleConfiguration(final ShardingRuleConfiguration
currentRuleConfig, final ShardingRuleConfiguration toBeAlteredRuleConfig) {
+
currentRuleConfig.setScalingName(toBeAlteredRuleConfig.getScalingName());
}
@Override
@@ -72,6 +76,6 @@ public final class DropShardingScalingStatementUpdater
implements RuleDefinition
@Override
public String getType() {
- return DropShardingScalingStatement.class.getCanonicalName();
+ return EnableShardingScalingStatement.class.getCanonicalName();
}
}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater
index e5ca760..a04fa07 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater
@@ -35,3 +35,5 @@
org.apache.shardingsphere.sharding.distsql.handler.update.AlterDefaultShardingSt
org.apache.shardingsphere.sharding.distsql.handler.update.DropDefaultStrategyStatementUpdater
org.apache.shardingsphere.scaling.distsql.handler.CreateShardingScalingStatementUpdater
org.apache.shardingsphere.scaling.distsql.handler.DropShardingScalingStatementUpdater
+org.apache.shardingsphere.scaling.distsql.handler.EnableShardingScalingStatementUpdater
+org.apache.shardingsphere.scaling.distsql.handler.DisableShardingScalingStatementUpdater
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/DisabledShardingScalingStatementUpdaterTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/DisabledShardingScalingStatementUpdaterTest.java
new file mode 100644
index 0000000..c666e54
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/DisabledShardingScalingStatementUpdaterTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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.scaling.distsql.handler;
+
+import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
+import
org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException;
+import
org.apache.shardingsphere.infra.distsql.exception.rule.RuleDisabledException;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import
org.apache.shardingsphere.scaling.distsql.statement.DisableShardingScalingStatement;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class DisabledShardingScalingStatementUpdaterTest {
+
+ @Mock
+ private ShardingSphereMetaData shardingSphereMetaData;
+
+ private final DisableShardingScalingStatementUpdater updater = new
DisableShardingScalingStatementUpdater();
+
+ @Before
+ public void before() {
+ when(shardingSphereMetaData.getName()).thenReturn("test");
+ }
+
+ @Test(expected = RequiredRuleMissedException.class)
+ public void assertCheckWithoutShardingRule() throws DistSQLException {
+ updater.checkSQLStatement(shardingSphereMetaData,
createSQLStatement("default_scaling"), null);
+ }
+
+ @Test(expected = RequiredRuleMissedException.class)
+ public void assertCheckNotExist() throws DistSQLException {
+ ShardingRuleConfiguration currentRuleConfig = new
ShardingRuleConfiguration();
+ currentRuleConfig.getScaling().put("default_scaling", null);
+ updater.checkSQLStatement(shardingSphereMetaData,
createSQLStatement("new_scaling"), currentRuleConfig);
+ }
+
+ @Test(expected = RuleDisabledException.class)
+ public void assertCheckDisabled() throws DistSQLException {
+ ShardingRuleConfiguration currentRuleConfig = new
ShardingRuleConfiguration();
+ String scalingName = "default_scaling";
+ currentRuleConfig.getScaling().put(scalingName, null);
+ updater.checkSQLStatement(shardingSphereMetaData,
createSQLStatement(scalingName), currentRuleConfig);
+ }
+
+ @Test
+ public void assertBuildToBeAlteredRuleConfiguration() {
+ ShardingRuleConfiguration result =
updater.buildToBeAlteredRuleConfiguration(createSQLStatement("default_scaling"));
+ assertNull(result);
+ }
+
+ @Test
+ public void assertUpdateSuccess() {
+ ShardingRuleConfiguration currentRuleConfig = new
ShardingRuleConfiguration();
+ String scalingName = "default_scaling";
+ currentRuleConfig.getScaling().put(scalingName, null);
+ updater.updateCurrentRuleConfiguration(currentRuleConfig, null);
+ assertNull(currentRuleConfig.getScalingName());
+ }
+
+ private DisableShardingScalingStatement createSQLStatement(final String
scalingName) {
+ return new DisableShardingScalingStatement(scalingName);
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/EnableShardingScalingStatementUpdaterTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/EnableShardingScalingStatementUpdaterTest.java
new file mode 100644
index 0000000..f1dec1a
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/EnableShardingScalingStatementUpdaterTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.scaling.distsql.handler;
+
+import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
+import
org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException;
+import
org.apache.shardingsphere.infra.distsql.exception.rule.RuleEnabledException;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import
org.apache.shardingsphere.scaling.distsql.statement.EnableShardingScalingStatement;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class EnableShardingScalingStatementUpdaterTest {
+
+ @Mock
+ private ShardingSphereMetaData shardingSphereMetaData;
+
+ private final EnableShardingScalingStatementUpdater updater = new
EnableShardingScalingStatementUpdater();
+
+ @Before
+ public void before() {
+ when(shardingSphereMetaData.getName()).thenReturn("test");
+ }
+
+ @Test(expected = RequiredRuleMissedException.class)
+ public void assertCheckWithoutShardingRule() throws DistSQLException {
+ updater.checkSQLStatement(shardingSphereMetaData,
createSQLStatement("default_scaling"), null);
+ }
+
+ @Test(expected = RequiredRuleMissedException.class)
+ public void assertCheckNotExist() throws DistSQLException {
+ ShardingRuleConfiguration currentRuleConfig = new
ShardingRuleConfiguration();
+ currentRuleConfig.getScaling().put("default_scaling", null);
+ updater.checkSQLStatement(shardingSphereMetaData,
createSQLStatement("new_scaling"), currentRuleConfig);
+ }
+
+ @Test(expected = RuleEnabledException.class)
+ public void assertCheckEnabled() throws DistSQLException {
+ ShardingRuleConfiguration currentRuleConfig = new
ShardingRuleConfiguration();
+ String scalingName = "default_scaling";
+ currentRuleConfig.getScaling().put(scalingName, null);
+ currentRuleConfig.setScalingName(scalingName);
+ updater.checkSQLStatement(shardingSphereMetaData,
createSQLStatement(scalingName), currentRuleConfig);
+ }
+
+ @Test
+ public void assertBuildToBeAlteredRuleConfiguration() {
+ ShardingRuleConfiguration currentRuleConfig = new
ShardingRuleConfiguration();
+ String scalingName = "default_scaling";
+ currentRuleConfig.getScaling().put(scalingName, null);
+ ShardingRuleConfiguration result =
updater.buildToBeAlteredRuleConfiguration(createSQLStatement(scalingName));
+ assertNotNull(result.getScalingName());
+ assertThat(result.getScalingName(), is(scalingName));
+ }
+
+ @Test
+ public void assertUpdateSuccess() {
+ ShardingRuleConfiguration currentRuleConfig = new
ShardingRuleConfiguration();
+ String scalingName = "new_scaling";
+ currentRuleConfig.getScaling().put("default_scaling", null);
+ currentRuleConfig.getScaling().put(scalingName, null);
+ ShardingRuleConfiguration toBeCreatedRuleConfiguration =
updater.buildToBeAlteredRuleConfiguration(createSQLStatement(scalingName));
+ updater.updateCurrentRuleConfiguration(currentRuleConfig,
toBeCreatedRuleConfiguration);
+ assertThat(currentRuleConfig.getScalingName(), is("new_scaling"));
+ }
+
+ private EnableShardingScalingStatement createSQLStatement(final String
scalingName) {
+ return new EnableShardingScalingStatement(scalingName);
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/scaling/Keyword.g4
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/scaling/Keyword.g4
index 2566af6..7cee561 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/scaling/Keyword.g4
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/scaling/Keyword.g4
@@ -134,3 +134,11 @@ RATE_LIMITER
STREAM_CHANNEL
: S T R E A M UL_ C H A N N E L
;
+
+ENABLE
+ : E N A B L E
+ ;
+
+DISABLE
+ : D I S A B L E
+ ;
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/scaling/RDLStatement.g4
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/scaling/RDLStatement.g4
index d5543d9..92fc5d8 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/scaling/RDLStatement.g4
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/scaling/RDLStatement.g4
@@ -27,6 +27,14 @@ dropShardingScaling
: DROP SHARDING SCALING scalingName
;
+enableShardingScaling
+ : ENABLE SHARDING SCALING scalingName
+ ;
+
+disableShardingScaling
+ : DISABLE SHARDING SCALING scalingName
+ ;
+
scalingName
: IDENTIFIER
;
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
index a50acce..d8d007b 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
@@ -32,5 +32,7 @@ execute
| checkoutScaling
| createShardingScaling
| dropShardingScaling
+ | enableShardingScaling
+ | disableShardingScaling
) SEMI?
;
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/scaling/distsql/parser/core/ScalingSQLStatementVisitor.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/scaling/distsql/parser/core/ScalingSQLStatementVisitor.java
index d05bc4a..289bc77 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/scaling/distsql/parser/core/ScalingSQLStatementVisitor.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/scaling/distsql/parser/core/ScalingSQLStatementVisitor.java
@@ -26,8 +26,10 @@ import
org.apache.shardingsphere.distsql.parser.autogen.ScalingStatementParser.C
import
org.apache.shardingsphere.distsql.parser.autogen.ScalingStatementParser.CompletionDetectorContext;
import
org.apache.shardingsphere.distsql.parser.autogen.ScalingStatementParser.CreateShardingScalingContext;
import
org.apache.shardingsphere.distsql.parser.autogen.ScalingStatementParser.DataConsistencyCheckerContext;
+import
org.apache.shardingsphere.distsql.parser.autogen.ScalingStatementParser.DisableShardingScalingContext;
import
org.apache.shardingsphere.distsql.parser.autogen.ScalingStatementParser.DropScalingContext;
import
org.apache.shardingsphere.distsql.parser.autogen.ScalingStatementParser.DropShardingScalingContext;
+import
org.apache.shardingsphere.distsql.parser.autogen.ScalingStatementParser.EnableShardingScalingContext;
import
org.apache.shardingsphere.distsql.parser.autogen.ScalingStatementParser.InputDefinitionContext;
import
org.apache.shardingsphere.distsql.parser.autogen.ScalingStatementParser.ManualDefinitionContext;
import
org.apache.shardingsphere.distsql.parser.autogen.ScalingStatementParser.MinimumAutoDefinitionContext;
@@ -46,8 +48,10 @@ import
org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import
org.apache.shardingsphere.scaling.distsql.statement.CheckScalingStatement;
import
org.apache.shardingsphere.scaling.distsql.statement.CheckoutScalingStatement;
import
org.apache.shardingsphere.scaling.distsql.statement.CreateShardingScalingStatement;
+import
org.apache.shardingsphere.scaling.distsql.statement.DisableShardingScalingStatement;
import
org.apache.shardingsphere.scaling.distsql.statement.DropScalingStatement;
import
org.apache.shardingsphere.scaling.distsql.statement.DropShardingScalingStatement;
+import
org.apache.shardingsphere.scaling.distsql.statement.EnableShardingScalingStatement;
import
org.apache.shardingsphere.scaling.distsql.statement.ResetScalingStatement;
import
org.apache.shardingsphere.scaling.distsql.statement.ShowScalingCheckAlgorithmsStatement;
import
org.apache.shardingsphere.scaling.distsql.statement.ShowScalingListStatement;
@@ -192,28 +196,38 @@ public final class ScalingSQLStatementVisitor extends
ScalingStatementBaseVisito
public ASTNode visitRateLimiter(final RateLimiterContext ctx) {
return visit(ctx.algorithmDefinition());
}
-
+
@Override
public ASTNode visitStreamChannel(final StreamChannelContext ctx) {
return visit(ctx.algorithmDefinition());
}
-
+
@Override
public ASTNode visitCompletionDetector(final CompletionDetectorContext
ctx) {
return visit(ctx.algorithmDefinition());
}
-
+
@Override
public ASTNode visitDataConsistencyChecker(final
DataConsistencyCheckerContext ctx) {
return visit(ctx.algorithmDefinition());
}
-
+
@Override
public ASTNode visitDropShardingScaling(final DropShardingScalingContext
ctx) {
return new DropShardingScalingStatement(new
IdentifierValue(ctx.scalingName().getText()).getValue());
}
@Override
+ public ASTNode visitEnableShardingScaling(final
EnableShardingScalingContext ctx) {
+ return new EnableShardingScalingStatement(new
IdentifierValue(ctx.scalingName().getText()).getValue());
+ }
+
+ @Override
+ public ASTNode visitDisableShardingScaling(final
DisableShardingScalingContext ctx) {
+ return new DisableShardingScalingStatement(new
IdentifierValue(ctx.scalingName().getText()).getValue());
+ }
+
+ @Override
public ASTNode visitAlgorithmDefinition(final AlgorithmDefinitionContext
ctx) {
return new AlgorithmSegment(ctx.algorithmName().getText(),
getAlgorithmProperties(ctx));
}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/scaling/distsql/statement/DisableShardingScalingStatement.java
similarity index 65%
copy from
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
copy to
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/scaling/distsql/statement/DisableShardingScalingStatement.java
index a50acce..56db23c 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/scaling/distsql/statement/DisableShardingScalingStatement.java
@@ -15,22 +15,18 @@
* limitations under the License.
*/
-grammar ScalingStatement;
+package org.apache.shardingsphere.scaling.distsql.statement;
-import Symbol, RALStatement, RDLStatement;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import
org.apache.shardingsphere.distsql.parser.statement.rdl.alter.AlterRuleStatement;
-execute
- : (showScalingList
- | showScalingStatus
- | startScaling
- | stopScaling
- | dropScaling
- | resetScaling
- | checkScaling
- | showScalingCheckAlgorithms
- | stopScalingSourceWriting
- | checkoutScaling
- | createShardingScaling
- | dropShardingScaling
- ) SEMI?
- ;
+/**
+ * Disable sharding scaling statement.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class DisableShardingScalingStatement extends AlterRuleStatement {
+
+ private final String scalingName;
+}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/scaling/distsql/statement/EnableShardingScalingStatement.java
similarity index 66%
copy from
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
copy to
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/scaling/distsql/statement/EnableShardingScalingStatement.java
index a50acce..ce3f233 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-statement/src/main/java/org/apache/shardingsphere/scaling/distsql/statement/EnableShardingScalingStatement.java
@@ -15,22 +15,18 @@
* limitations under the License.
*/
-grammar ScalingStatement;
+package org.apache.shardingsphere.scaling.distsql.statement;
-import Symbol, RALStatement, RDLStatement;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import
org.apache.shardingsphere.distsql.parser.statement.rdl.alter.AlterRuleStatement;
-execute
- : (showScalingList
- | showScalingStatus
- | startScaling
- | stopScaling
- | dropScaling
- | resetScaling
- | checkScaling
- | showScalingCheckAlgorithms
- | stopScalingSourceWriting
- | checkoutScaling
- | createShardingScaling
- | dropShardingScaling
- ) SEMI?
- ;
+/**
+ * Enable sharding scaling statement.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class EnableShardingScalingStatement extends AlterRuleStatement {
+
+ private final String scalingName;
+}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/RequiredRuleMissedException.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/RequiredRuleMissedException.java
index 296067f0..a52bae3 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/RequiredRuleMissedException.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/RequiredRuleMissedException.java
@@ -30,6 +30,10 @@ public final class RequiredRuleMissedException extends
RuleDefinitionViolationEx
super(1112, String.format("%s rule does not exist in schema `%s`.",
ruleType, schemaName));
}
+ public RequiredRuleMissedException(final String ruleType, final String
schemaName, final String ruleName) {
+ super(1112, String.format("%s rule `%s` do not exist in schema `%s`.",
ruleType, ruleName, schemaName));
+ }
+
public RequiredRuleMissedException(final String ruleType, final String
schemaName, final Collection<String> ruleNames) {
super(1112, String.format("%s rules `%s` do not exist in schema
`%s`.", ruleType, ruleNames, schemaName));
}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/RuleDisabledException.java
similarity index 61%
copy from
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
copy to
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/RuleDisabledException.java
index a50acce..4063cec 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/RuleDisabledException.java
@@ -15,22 +15,16 @@
* limitations under the License.
*/
-grammar ScalingStatement;
+package org.apache.shardingsphere.infra.distsql.exception.rule;
-import Symbol, RALStatement, RDLStatement;
-
-execute
- : (showScalingList
- | showScalingStatus
- | startScaling
- | stopScaling
- | dropScaling
- | resetScaling
- | checkScaling
- | showScalingCheckAlgorithms
- | stopScalingSourceWriting
- | checkoutScaling
- | createShardingScaling
- | dropShardingScaling
- ) SEMI?
- ;
+/**
+ * Rule disabled exception.
+ */
+public final class RuleDisabledException extends
RuleDefinitionViolationException {
+
+ private static final long serialVersionUID = -4024905659258386784L;
+
+ public RuleDisabledException(final String ruleType, final String
schemaName, final String ruleName) {
+ super(1119, String.format("%s rule `%s` has been disabled in schema
`%s`.", ruleType, ruleName, schemaName));
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/RuleEnabledException.java
similarity index 61%
copy from
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
copy to
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/RuleEnabledException.java
index a50acce..709869a 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/exception/rule/RuleEnabledException.java
@@ -15,22 +15,16 @@
* limitations under the License.
*/
-grammar ScalingStatement;
+package org.apache.shardingsphere.infra.distsql.exception.rule;
-import Symbol, RALStatement, RDLStatement;
-
-execute
- : (showScalingList
- | showScalingStatus
- | startScaling
- | stopScaling
- | dropScaling
- | resetScaling
- | checkScaling
- | showScalingCheckAlgorithms
- | stopScalingSourceWriting
- | checkoutScaling
- | createShardingScaling
- | dropShardingScaling
- ) SEMI?
- ;
+/**
+ * Rule enabled exception.
+ */
+public final class RuleEnabledException extends
RuleDefinitionViolationException {
+
+ private static final long serialVersionUID = 2381983504661441914L;
+
+ public RuleEnabledException(final String ruleType, final String
schemaName, final String ruleName) {
+ super(1120, String.format("%s rule `%s` has been enabled in schema
`%s`.", ruleType, ruleName, schemaName));
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/alter/AlterRuleStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/alter/AlterRuleStatementAssert.java
index d7c955d..19dc0a2 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/alter/AlterRuleStatementAssert.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/alter/AlterRuleStatementAssert.java
@@ -24,6 +24,8 @@ import
org.apache.shardingsphere.distsql.parser.statement.rdl.alter.AlterRuleSta
import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.AlterDefaultSingleTableRuleStatement;
import
org.apache.shardingsphere.encrypt.distsql.parser.statement.AlterEncryptRuleStatement;
import
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.AlterReadwriteSplittingRuleStatement;
+import
org.apache.shardingsphere.scaling.distsql.statement.DisableShardingScalingStatement;
+import
org.apache.shardingsphere.scaling.distsql.statement.EnableShardingScalingStatement;
import
org.apache.shardingsphere.shadow.distsql.parser.statement.AlterShadowAlgorithmStatement;
import
org.apache.shardingsphere.shadow.distsql.parser.statement.AlterShadowRuleStatement;
import
org.apache.shardingsphere.sharding.distsql.parser.statement.AlterDefaultShardingStrategyStatement;
@@ -45,6 +47,8 @@ import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.alter.impl.AlterShardingBroadcastTableRulesStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.alter.impl.AlterShardingKeyGeneratorStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.alter.impl.AlterShardingTableRuleStatementAssert;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.alter.impl.DisableShardingScalingStatementAssert;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rdl.alter.impl.EnableShardingScalingStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.alter.AlterDatabaseDiscoveryHeartbeatStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.alter.AlterDatabaseDiscoveryTypeStatementTestCase;
@@ -57,6 +61,8 @@ import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.alter.AlterShardingBindingTableRulesStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.alter.AlterShardingBroadcastTableRulesStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.alter.AlterShardingKeyGeneratorStatementTestCase;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.alter.DisableShardingScalingStatementTestCase;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.alter.EnableShardingScalingStatementTestCase;
/**
* Alter rule statement assert.
@@ -99,6 +105,10 @@ public final class AlterRuleStatementAssert {
(AlterDefaultSingleTableRuleStatementTestCase) expected);
} else if (actual instanceof AlterShardingKeyGeneratorStatement) {
AlterShardingKeyGeneratorStatementAssert.assertIs(assertContext,
(AlterShardingKeyGeneratorStatement) actual,
(AlterShardingKeyGeneratorStatementTestCase) expected);
+ } else if (actual instanceof EnableShardingScalingStatement) {
+ EnableShardingScalingStatementAssert.assertIs(assertContext,
(EnableShardingScalingStatement) actual,
(EnableShardingScalingStatementTestCase) expected);
+ } else if (actual instanceof DisableShardingScalingStatement) {
+ DisableShardingScalingStatementAssert.assertIs(assertContext,
(DisableShardingScalingStatement) actual,
(DisableShardingScalingStatementTestCase) expected);
}
}
}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/alter/impl/DisableShardingScalingStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/alter/impl/DisableShardingScalingStatementAssert.java
new file mode 100644
index 0000000..eb5b2e4
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/alter/impl/DisableShardingScalingStatementAssert.java
@@ -0,0 +1,53 @@
+/*
+ * 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.test.sql.parser.parameterized.asserts.statement.distsql.rdl.alter.impl;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.scaling.distsql.statement.DisableShardingScalingStatement;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.alter.DisableShardingScalingStatementTestCase;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Disable sharding scaling statement assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class DisableShardingScalingStatementAssert {
+
+ /**
+ * Assert disable sharding scaling statement is correct with expected
parser result.
+ *
+ * @param assertContext assert context
+ * @param actual actual disable sharding scaling statement
+ * @param expected expected disable sharding scaling statement test case
+ */
+ public static void assertIs(final SQLCaseAssertContext assertContext,
final DisableShardingScalingStatement actual, final
DisableShardingScalingStatementTestCase expected) {
+ if (null == expected) {
+ assertNull(assertContext.getText("Actual statement should not
exist."), actual);
+ } else {
+ assertNotNull(assertContext.getText("Actual statement should
exist."), actual);
+ assertThat(assertContext.getText(String.format("`%s`'s scaling
name assertion error: ", actual.getClass().getSimpleName())),
+ actual.getScalingName(), is(expected.getScalingName()));
+ }
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/alter/impl/EnableShardingScalingStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/alter/impl/EnableShardingScalingStatementAssert.java
new file mode 100644
index 0000000..fc2fea3
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/alter/impl/EnableShardingScalingStatementAssert.java
@@ -0,0 +1,53 @@
+/*
+ * 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.test.sql.parser.parameterized.asserts.statement.distsql.rdl.alter.impl;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.scaling.distsql.statement.EnableShardingScalingStatement;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.alter.EnableShardingScalingStatementTestCase;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Enable sharding scaling statement assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class EnableShardingScalingStatementAssert {
+
+ /**
+ * Assert enable sharding scaling statement is correct with expected
parser result.
+ *
+ * @param assertContext assert context
+ * @param actual actual enable sharding scaling statement
+ * @param expected expected enable sharding scaling statement test case
+ */
+ public static void assertIs(final SQLCaseAssertContext assertContext,
final EnableShardingScalingStatement actual, final
EnableShardingScalingStatementTestCase expected) {
+ if (null == expected) {
+ assertNull(assertContext.getText("Actual statement should not
exist."), actual);
+ } else {
+ assertNotNull(assertContext.getText("Actual statement should
exist."), actual);
+ assertThat(assertContext.getText(String.format("`%s`'s scaling
name assertion error: ", actual.getClass().getSimpleName())),
+ actual.getScalingName(), is(expected.getScalingName()));
+ }
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
index 3d4d5e0..621913d 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
@@ -191,6 +191,8 @@ import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.alter.AlterShardingBroadcastTableRulesStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.alter.AlterShardingKeyGeneratorStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.alter.AlterShardingTableRuleStatementTestCase;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.alter.DisableShardingScalingStatementTestCase;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.alter.EnableShardingScalingStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.AddResourceStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateDatabaseDiscoveryConstructionRuleStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.create.CreateDatabaseDiscoveryDefinitionRuleStatementTestCase;
@@ -717,6 +719,12 @@ public final class SQLParserTestCases {
@XmlElement(name = "drop-sharding-scaling")
private final List<DropShardingScalingStatementTestCase>
dropShardingScalingStatementTestCases = new LinkedList<>();
+ @XmlElement(name = "enable-sharding-scaling")
+ private final List<EnableShardingScalingStatementTestCase>
enableShardingScalingStatementTestCases = new LinkedList<>();
+
+ @XmlElement(name = "disable-sharding-scaling")
+ private final List<DisableShardingScalingStatementTestCase>
disableShardingScalingStatementTestCases = new LinkedList<>();
+
@XmlElement(name = "preview-sql")
private final List<PreviewStatementTestCase> previewStatementTestCase =
new LinkedList<>();
@@ -1141,6 +1149,8 @@ public final class SQLParserTestCases {
putAll(checkoutScalingStatementTestCases, result);
putAll(createShardingScalingStatementTestCases, result);
putAll(dropShardingScalingStatementTestCases, result);
+ putAll(enableShardingScalingStatementTestCases, result);
+ putAll(disableShardingScalingStatementTestCases, result);
putAll(showVariableStatementTestCase, result);
putAll(showAllVariablesStatementTestCase, result);
putAll(setVariableStatementTestCase, result);
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/alter/DisableShardingScalingStatementTestCase.java
similarity index 59%
copy from
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
copy to
shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/alter/DisableShardingScalingStatementTestCase.java
index a50acce..a2840a3 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/alter/DisableShardingScalingStatementTestCase.java
@@ -15,22 +15,21 @@
* limitations under the License.
*/
-grammar ScalingStatement;
+package
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.alter;
-import Symbol, RALStatement, RDLStatement;
+import lombok.Getter;
+import lombok.Setter;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
-execute
- : (showScalingList
- | showScalingStatus
- | startScaling
- | stopScaling
- | dropScaling
- | resetScaling
- | checkScaling
- | showScalingCheckAlgorithms
- | stopScalingSourceWriting
- | checkoutScaling
- | createShardingScaling
- | dropShardingScaling
- ) SEMI?
- ;
+import javax.xml.bind.annotation.XmlAttribute;
+
+/**
+ * Disable sharding scaling statement test case.
+ */
+@Getter
+@Setter
+public final class DisableShardingScalingStatementTestCase extends
SQLParserTestCase {
+
+ @XmlAttribute(name = "scaling-name")
+ private String scalingName;
+}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/alter/EnableShardingScalingStatementTestCase.java
similarity index 59%
copy from
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
copy to
shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/alter/EnableShardingScalingStatementTestCase.java
index a50acce..80fcfea 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/scaling/org/apache/shardingsphere/distsql/parser/autogen/ScalingStatement.g4
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/alter/EnableShardingScalingStatementTestCase.java
@@ -15,22 +15,21 @@
* limitations under the License.
*/
-grammar ScalingStatement;
+package
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.alter;
-import Symbol, RALStatement, RDLStatement;
+import lombok.Getter;
+import lombok.Setter;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
-execute
- : (showScalingList
- | showScalingStatus
- | startScaling
- | stopScaling
- | dropScaling
- | resetScaling
- | checkScaling
- | showScalingCheckAlgorithms
- | stopScalingSourceWriting
- | checkoutScaling
- | createShardingScaling
- | dropShardingScaling
- ) SEMI?
- ;
+import javax.xml.bind.annotation.XmlAttribute;
+
+/**
+ * Enable sharding scaling statement test case.
+ */
+@Getter
+@Setter
+public final class EnableShardingScalingStatementTestCase extends
SQLParserTestCase {
+
+ @XmlAttribute(name = "scaling-name")
+ private String scalingName;
+}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/alter.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/alter.xml
index b28f5d3..effc5d4 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/alter.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/alter.xml
@@ -310,4 +310,7 @@
<strategy default-type="TABLE" strategy-type="complex"
sharding-column="order_id,user_id" sharding-algorithm-name="algorithms_name">
</strategy>
</alter-default-sharding-strategy>
+
+ <enable-sharding-scaling sql-case-id="enable-sharding-scaling"
scaling-name="scalingName"/>
+ <disable-sharding-scaling sql-case-id="disable-sharding-scaling"
scaling-name="scalingName"/>
</sql-parser-test-cases>
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/alter.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/alter.xml
index 6bc15a1..5293f99 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/alter.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/alter.xml
@@ -47,4 +47,6 @@
<distsql-case id="alter-sharding-key-generator" value="ALTER SHARDING KEY
GENERATOR uuid_key_generator(TYPE(NAME=uuid,PROPERTIES('worker-id' = '123')))"
/>
<distsql-case id="alter-default-sharding-strategy" value="ALTER DEFAULT
SHARDING TABLE STRATEGY(TYPE=standard, SHARDING_COLUMN=order_id,
SHARDING_ALGORITHM=algorithms_name)" />
<distsql-case id="alter-default-sharding-strategy-complex" value="ALTER
DEFAULT SHARDING TABLE STRATEGY(TYPE=complex,
SHARDING_COLUMNS=order_id,user_id, SHARDING_ALGORITHM=algorithms_name)" />
+ <distsql-case id="enable-sharding-scaling" value="ENABLE SHARDING SCALING
scalingName" />
+ <distsql-case id="disable-sharding-scaling" value="DISABLE SHARDING
SCALING scalingName" />
</sql-cases>