diff --git a/kernel/schedule/core/src/main/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectJobWorker.java b/kernel/schedule/core/src/main/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectJobWorker.java index 7c7c74dcfe453..5eb96a6440421 100644 --- a/kernel/schedule/core/src/main/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectJobWorker.java +++ b/kernel/schedule/core/src/main/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectJobWorker.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration; import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter; import org.apache.shardingsphere.infra.config.mode.ModeConfiguration; -import org.apache.shardingsphere.mode.node.path.statistics.StatisticsNodePathGenerator; +import org.apache.shardingsphere.mode.node.path.statistics.job.StatisticsJobNodePath; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration; @@ -68,7 +68,7 @@ public void initialize() { private CoordinatorRegistryCenter createRegistryCenter(final ModeConfiguration modeConfig) { ClusterPersistRepositoryConfiguration repositoryConfig = (ClusterPersistRepositoryConfiguration) modeConfig.getRepository(); - String namespace = repositoryConfig.getNamespace() + StatisticsNodePathGenerator.getJobPath(); + String namespace = repositoryConfig.getNamespace() + new StatisticsJobNodePath().getRootPath(); CoordinatorRegistryCenter result = new ZookeeperRegistryCenter(getZookeeperConfiguration(repositoryConfig, namespace)); result.init(); return result; diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/metadata/service/TableRowDataPersistService.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/metadata/service/TableRowDataPersistService.java index 2a3f8f97e4151..e344edc550de3 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/metadata/service/TableRowDataPersistService.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/metadata/service/TableRowDataPersistService.java @@ -19,12 +19,14 @@ import com.google.common.base.Strings; import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.infra.metadata.statistics.TableStatistics; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; +import org.apache.shardingsphere.infra.metadata.statistics.TableStatistics; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; import org.apache.shardingsphere.infra.yaml.data.pojo.YamlRowStatistics; import org.apache.shardingsphere.infra.yaml.data.swapper.YamlRowStatisticsSwapper; -import org.apache.shardingsphere.mode.node.path.statistics.StatisticsNodePathGenerator; +import org.apache.shardingsphere.mode.node.path.NodePathGenerator; +import org.apache.shardingsphere.mode.node.path.statistics.database.StatisticsTableNodePath; +import org.apache.shardingsphere.mode.node.path.statistics.database.StatisticsTableRowNodePath; import org.apache.shardingsphere.mode.spi.repository.PersistRepository; import java.util.ArrayList; @@ -48,10 +50,10 @@ public final class TableRowDataPersistService { */ public void persist(final String databaseName, final String schemaName, final String tableName, final Collection rows) { if (rows.isEmpty()) { - repository.persist(StatisticsNodePathGenerator.getTablePath(databaseName, schemaName, tableName.toLowerCase()), ""); + repository.persist(new NodePathGenerator(new StatisticsTableNodePath(databaseName, schemaName)).getPath(tableName.toLowerCase()), ""); } else { - rows.forEach( - each -> repository.persist(StatisticsNodePathGenerator.getTableRowPath(databaseName, schemaName, tableName.toLowerCase(), each.getUniqueKey()), YamlEngine.marshal(each))); + rows.forEach(each -> repository.persist(new NodePathGenerator(new StatisticsTableRowNodePath(databaseName, schemaName, tableName.toLowerCase())).getPath(each.getUniqueKey()), + YamlEngine.marshal(each))); } } @@ -64,7 +66,7 @@ public void persist(final String databaseName, final String schemaName, final St * @param rows rows */ public void delete(final String databaseName, final String schemaName, final String tableName, final Collection rows) { - rows.forEach(each -> repository.delete(StatisticsNodePathGenerator.getTableRowPath(databaseName, schemaName, tableName.toLowerCase(), each.getUniqueKey()))); + rows.forEach(each -> repository.delete(new NodePathGenerator(new StatisticsTableRowNodePath(databaseName, schemaName, tableName.toLowerCase())).getPath(each.getUniqueKey()))); } /** @@ -78,8 +80,8 @@ public void delete(final String databaseName, final String schemaName, final Str public TableStatistics load(final String databaseName, final String schemaName, final ShardingSphereTable table) { TableStatistics result = new TableStatistics(table.getName()); YamlRowStatisticsSwapper swapper = new YamlRowStatisticsSwapper(new ArrayList<>(table.getAllColumns())); - for (String each : repository.getChildrenKeys(StatisticsNodePathGenerator.getTablePath(databaseName, schemaName, table.getName()))) { - String yamlRow = repository.query(StatisticsNodePathGenerator.getTableRowPath(databaseName, schemaName, table.getName(), each)); + for (String each : repository.getChildrenKeys(new NodePathGenerator(new StatisticsTableNodePath(databaseName, schemaName)).getPath(table.getName()))) { + String yamlRow = repository.query(new NodePathGenerator(new StatisticsTableRowNodePath(databaseName, schemaName, table.getName())).getPath(each)); if (!Strings.isNullOrEmpty(yamlRow)) { result.getRows().add(swapper.swapToObject(YamlEngine.unmarshal(yamlRow, YamlRowStatistics.class))); } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/statistics/StatisticsPersistService.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/statistics/StatisticsPersistService.java index 1866504d746c2..1c0cc37f56221 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/statistics/StatisticsPersistService.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/statistics/StatisticsPersistService.java @@ -26,7 +26,10 @@ import org.apache.shardingsphere.infra.yaml.data.pojo.YamlRowStatistics; import org.apache.shardingsphere.infra.yaml.data.swapper.YamlRowStatisticsSwapper; import org.apache.shardingsphere.mode.metadata.persist.metadata.service.TableRowDataPersistService; -import org.apache.shardingsphere.mode.node.path.statistics.StatisticsNodePathGenerator; +import org.apache.shardingsphere.mode.node.path.NodePathGenerator; +import org.apache.shardingsphere.mode.node.path.statistics.database.StatisticsDatabaseNodePath; +import org.apache.shardingsphere.mode.node.path.statistics.database.StatisticsSchemaNodePath; +import org.apache.shardingsphere.mode.node.path.statistics.database.StatisticsTableNodePath; import org.apache.shardingsphere.mode.spi.repository.PersistRepository; import java.util.ArrayList; @@ -54,7 +57,7 @@ public StatisticsPersistService(final PersistRepository repository) { * @return statistics */ public ShardingSphereStatistics load(final ShardingSphereMetaData metaData) { - Collection databaseNames = repository.getChildrenKeys(StatisticsNodePathGenerator.getDatabasesRootPath()); + Collection databaseNames = repository.getChildrenKeys(new StatisticsDatabaseNodePath().getRootPath()); if (databaseNames.isEmpty()) { return new ShardingSphereStatistics(); } @@ -67,7 +70,7 @@ public ShardingSphereStatistics load(final ShardingSphereMetaData metaData) { private DatabaseStatistics load(final ShardingSphereDatabase database) { DatabaseStatistics result = new DatabaseStatistics(); - for (String each : repository.getChildrenKeys(StatisticsNodePathGenerator.getSchemaRootPath(database.getName())).stream().filter(database::containsSchema).collect(Collectors.toList())) { + for (String each : repository.getChildrenKeys(new StatisticsSchemaNodePath(database.getName()).getRootPath()).stream().filter(database::containsSchema).collect(Collectors.toList())) { result.putSchemaStatistics(each, load(database.getName(), database.getSchema(each))); } return result; @@ -75,7 +78,7 @@ private DatabaseStatistics load(final ShardingSphereDatabase database) { private SchemaStatistics load(final String databaseName, final ShardingSphereSchema schema) { SchemaStatistics result = new SchemaStatistics(); - for (String each : repository.getChildrenKeys(StatisticsNodePathGenerator.getTableRootPath(databaseName, schema.getName())).stream().filter(schema::containsTable) + for (String each : repository.getChildrenKeys(new StatisticsTableNodePath(databaseName, schema.getName()).getRootPath()).stream().filter(schema::containsTable) .collect(Collectors.toList())) { result.putTableStatistics(each, tableRowDataPersistService.load(databaseName, schema.getName(), schema.getTable(each))); @@ -98,7 +101,7 @@ public void persist(final ShardingSphereDatabase database, final String schemaNa } private void persistSchema(final String databaseName, final String schemaName) { - repository.persist(StatisticsNodePathGenerator.getSchemaPath(databaseName, schemaName), ""); + repository.persist(new NodePathGenerator(new StatisticsSchemaNodePath(databaseName)).getPath(schemaName), ""); } private void persistTableData(final ShardingSphereDatabase database, final String schemaName, final SchemaStatistics schemaStatistics) { @@ -133,6 +136,6 @@ public void update(final AlteredDatabaseStatistics alteredDatabaseStatistics) { * @param databaseName database name */ public void delete(final String databaseName) { - repository.delete(StatisticsNodePathGenerator.getDatabasePath(databaseName)); + repository.delete(new NodePathGenerator(new StatisticsDatabaseNodePath()).getPath(databaseName)); } } diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/StatisticsNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/StatisticsNodePath.java new file mode 100644 index 0000000000000..a4edee277e0f4 --- /dev/null +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/StatisticsNodePath.java @@ -0,0 +1,33 @@ +/* + * 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.mode.node.path.statistics; + +import org.apache.shardingsphere.mode.node.path.NodePath; + +/** + * Statistics node path. + */ +public final class StatisticsNodePath implements NodePath { + + private static final String ROOT_NODE = "/statistics"; + + @Override + public String getRootPath() { + return ROOT_NODE; + } +} diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/StatisticsNodePathGenerator.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/StatisticsNodePathGenerator.java deleted file mode 100644 index bc555095a77a8..0000000000000 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/StatisticsNodePathGenerator.java +++ /dev/null @@ -1,123 +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.mode.node.path.statistics; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -/** - * Statistics node path generator. - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class StatisticsNodePathGenerator { - - private static final String ROOT_NODE = "/statistics"; - - private static final String DATABASES_NODE = "databases"; - - private static final String SCHEMAS_NODE = "schemas"; - - private static final String TABLES_NODE = "tables"; - - private static final String JOB_NODE = "job"; - - /** - * Get database root path. - * - * @return database root path - */ - public static String getDatabasesRootPath() { - return String.join("/", ROOT_NODE, DATABASES_NODE); - } - - /** - * Get database path. - * - * @param databaseName database name - * @return database path - */ - public static String getDatabasePath(final String databaseName) { - return String.join("/", getDatabasesRootPath(), databaseName); - } - - /** - * Get schema root path. - * - * @param databaseName database name - * @return schema root path - */ - public static String getSchemaRootPath(final String databaseName) { - return String.join("/", getDatabasePath(databaseName), SCHEMAS_NODE); - } - - /** - * Get schema path. - * - * @param databaseName database name - * @param schemaName schema name - * @return schema path - */ - public static String getSchemaPath(final String databaseName, final String schemaName) { - return String.join("/", getSchemaRootPath(databaseName), schemaName); - } - - /** - * Get table root path. - * - * @param databaseName database name - * @param schemaName schema name - * @return table root path - */ - public static String getTableRootPath(final String databaseName, final String schemaName) { - return String.join("/", getSchemaPath(databaseName, schemaName), TABLES_NODE); - } - - /** - * Get table path. - * - * @param databaseName database name - * @param schemaName schema name - * @param tableName table name - * @return table path - */ - public static String getTablePath(final String databaseName, final String schemaName, final String tableName) { - return String.join("/", getTableRootPath(databaseName, schemaName), tableName); - } - - /** - * Get table row path. - * - * @param databaseName database name - * @param schemaName schema name - * @param tableName table name - * @param uniqueKey unique key - * @return table row path - */ - public static String getTableRowPath(final String databaseName, final String schemaName, final String tableName, final String uniqueKey) { - return String.join("/", getTablePath(databaseName, schemaName, tableName), uniqueKey); - } - - /** - * Get job path. - * - * @return job path - */ - public static String getJobPath() { - return String.join("/", ROOT_NODE, JOB_NODE); - } -} diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/StatisticsNodePathParser.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/StatisticsNodePathParser.java index 3ae27f559220b..d952f1dbbadfa 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/StatisticsNodePathParser.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/StatisticsNodePathParser.java @@ -19,7 +19,12 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.apache.shardingsphere.mode.node.path.NodePathGenerator; import org.apache.shardingsphere.mode.node.path.NodePathPattern; +import org.apache.shardingsphere.mode.node.path.statistics.database.StatisticsDatabaseNodePath; +import org.apache.shardingsphere.mode.node.path.statistics.database.StatisticsSchemaNodePath; +import org.apache.shardingsphere.mode.node.path.statistics.database.StatisticsTableNodePath; +import org.apache.shardingsphere.mode.node.path.statistics.database.StatisticsTableRowNodePath; import java.util.Optional; import java.util.regex.Matcher; @@ -42,7 +47,7 @@ public final class StatisticsNodePathParser { */ public static Optional findDatabaseName(final String path, final boolean containsChildPath) { String endPattern = containsChildPath ? "?" : "$"; - Pattern pattern = Pattern.compile(StatisticsNodePathGenerator.getDatabasePath(NodePathPattern.IDENTIFIER) + endPattern, Pattern.CASE_INSENSITIVE); + Pattern pattern = Pattern.compile(new NodePathGenerator(new StatisticsDatabaseNodePath()).getPath(NodePathPattern.IDENTIFIER) + endPattern, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(path); return matcher.find() ? Optional.of(matcher.group(1)) : Optional.empty(); } @@ -56,7 +61,7 @@ public static Optional findDatabaseName(final String path, final boolean */ public static Optional findSchemaName(final String path, final boolean containsChildPath) { String endPattern = containsChildPath ? "?" : "$"; - Pattern pattern = Pattern.compile(StatisticsNodePathGenerator.getSchemaPath(NodePathPattern.IDENTIFIER, NodePathPattern.IDENTIFIER) + endPattern, Pattern.CASE_INSENSITIVE); + Pattern pattern = Pattern.compile(new NodePathGenerator(new StatisticsSchemaNodePath()).getPath(NodePathPattern.IDENTIFIER) + endPattern, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(path); return matcher.find() ? Optional.of(matcher.group(2)) : Optional.empty(); } @@ -70,8 +75,7 @@ public static Optional findSchemaName(final String path, final boolean c */ public static Optional findTableName(final String path, final boolean containsChildPath) { String endPattern = containsChildPath ? "?" : "$"; - Pattern pattern = Pattern.compile( - StatisticsNodePathGenerator.getTablePath(NodePathPattern.IDENTIFIER, NodePathPattern.IDENTIFIER, NodePathPattern.IDENTIFIER) + endPattern, Pattern.CASE_INSENSITIVE); + Pattern pattern = Pattern.compile(new NodePathGenerator(new StatisticsTableNodePath()).getPath(NodePathPattern.IDENTIFIER) + endPattern, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(path); return matcher.find() ? Optional.of(matcher.group(3)) : Optional.empty(); } @@ -83,8 +87,7 @@ public static Optional findTableName(final String path, final boolean co * @return found row unique key */ public static Optional findRowUniqueKey(final String path) { - Pattern pattern = Pattern.compile( - StatisticsNodePathGenerator.getTableRowPath(NodePathPattern.IDENTIFIER, NodePathPattern.IDENTIFIER, NodePathPattern.IDENTIFIER, UNIQUE_KEY_PATTERN) + "$", Pattern.CASE_INSENSITIVE); + Pattern pattern = Pattern.compile(new NodePathGenerator(new StatisticsTableRowNodePath()).getPath(UNIQUE_KEY_PATTERN) + "$", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(path); return matcher.find() ? Optional.of(matcher.group(4)) : Optional.empty(); } diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsDatabaseNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsDatabaseNodePath.java new file mode 100644 index 0000000000000..7e61ef2ef0185 --- /dev/null +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsDatabaseNodePath.java @@ -0,0 +1,37 @@ +/* + * 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.mode.node.path.statistics.database; + +import org.apache.shardingsphere.mode.node.path.NodePath; +import org.apache.shardingsphere.mode.node.path.NodePathGenerator; +import org.apache.shardingsphere.mode.node.path.statistics.StatisticsNodePath; + +/** + * Statistics database node path. + */ +public final class StatisticsDatabaseNodePath implements NodePath { + + private static final String DATABASES_NODE = "databases"; + + private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new StatisticsNodePath()); + + @Override + public String getRootPath() { + return nodePathGenerator.getPath(DATABASES_NODE); + } +} diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsSchemaNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsSchemaNodePath.java new file mode 100644 index 0000000000000..2261e19b01344 --- /dev/null +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsSchemaNodePath.java @@ -0,0 +1,45 @@ +/* + * 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.mode.node.path.statistics.database; + +import lombok.RequiredArgsConstructor; +import org.apache.shardingsphere.mode.node.path.NodePath; +import org.apache.shardingsphere.mode.node.path.NodePathGenerator; +import org.apache.shardingsphere.mode.node.path.NodePathPattern; + +/** + * Statistics schema node path. + */ +@RequiredArgsConstructor +public final class StatisticsSchemaNodePath implements NodePath { + + private static final String SCHEMAS_NODE = "schemas"; + + private final String databaseName; + + private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new StatisticsDatabaseNodePath()); + + public StatisticsSchemaNodePath() { + this(NodePathPattern.IDENTIFIER); + } + + @Override + public String getRootPath() { + return String.join("/", nodePathGenerator.getPath(databaseName), SCHEMAS_NODE); + } +} diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsTableNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsTableNodePath.java new file mode 100644 index 0000000000000..61984fc990e3e --- /dev/null +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsTableNodePath.java @@ -0,0 +1,48 @@ +/* + * 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.mode.node.path.statistics.database; + +import org.apache.shardingsphere.mode.node.path.NodePath; +import org.apache.shardingsphere.mode.node.path.NodePathGenerator; +import org.apache.shardingsphere.mode.node.path.NodePathPattern; + +/** + * Statistics table node path. + */ +public final class StatisticsTableNodePath implements NodePath { + + private static final String TABLES_NODE = "tables"; + + private final String schemaName; + + private final NodePathGenerator nodePathGenerator; + + public StatisticsTableNodePath(final String databaseName, final String schemaName) { + this.schemaName = schemaName; + nodePathGenerator = new NodePathGenerator(new StatisticsSchemaNodePath(databaseName)); + } + + public StatisticsTableNodePath() { + this(NodePathPattern.IDENTIFIER, NodePathPattern.IDENTIFIER); + } + + @Override + public String getRootPath() { + return String.join("/", nodePathGenerator.getPath(schemaName), TABLES_NODE); + } +} diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsTableRowNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsTableRowNodePath.java new file mode 100644 index 0000000000000..430d51ae0ac90 --- /dev/null +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsTableRowNodePath.java @@ -0,0 +1,46 @@ +/* + * 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.mode.node.path.statistics.database; + +import org.apache.shardingsphere.mode.node.path.NodePath; +import org.apache.shardingsphere.mode.node.path.NodePathGenerator; +import org.apache.shardingsphere.mode.node.path.NodePathPattern; + +/** + * Statistics table row node path. + */ +public final class StatisticsTableRowNodePath implements NodePath { + + private final String tableName; + + private final NodePathGenerator nodePathGenerator; + + public StatisticsTableRowNodePath(final String databaseName, final String schemaName, final String tableName) { + this.tableName = tableName; + nodePathGenerator = new NodePathGenerator(new StatisticsTableNodePath(databaseName, schemaName)); + } + + public StatisticsTableRowNodePath() { + this(NodePathPattern.IDENTIFIER, NodePathPattern.IDENTIFIER, NodePathPattern.IDENTIFIER); + } + + @Override + public String getRootPath() { + return nodePathGenerator.getPath(tableName); + } +} diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/job/StatisticsJobNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/job/StatisticsJobNodePath.java new file mode 100644 index 0000000000000..397c110815f82 --- /dev/null +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/statistics/job/StatisticsJobNodePath.java @@ -0,0 +1,37 @@ +/* + * 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.mode.node.path.statistics.job; + +import org.apache.shardingsphere.mode.node.path.NodePath; +import org.apache.shardingsphere.mode.node.path.NodePathGenerator; +import org.apache.shardingsphere.mode.node.path.statistics.StatisticsNodePath; + +/** + * Statistics job node path generator. + */ +public final class StatisticsJobNodePath implements NodePath { + + private static final String JOB_NODE = "job"; + + private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new StatisticsNodePath()); + + @Override + public String getRootPath() { + return nodePathGenerator.getPath(JOB_NODE); + } +} diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/statistics/StatisticsNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/statistics/StatisticsNodePathTest.java index d83e8eff09518..3dd2bf6b40887 100644 --- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/statistics/StatisticsNodePathTest.java +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/statistics/StatisticsNodePathTest.java @@ -25,42 +25,7 @@ class StatisticsNodePathTest { @Test - void assertGetDatabasesRootPath() { - assertThat(StatisticsNodePathGenerator.getDatabasesRootPath(), is("/statistics/databases")); - } - - @Test - void assertGetDatabasePath() { - assertThat(StatisticsNodePathGenerator.getDatabasePath("foo_db"), is("/statistics/databases/foo_db")); - } - - @Test - void assertGetSchemaRootPath() { - assertThat(StatisticsNodePathGenerator.getSchemaRootPath("foo_db"), is("/statistics/databases/foo_db/schemas")); - } - - @Test - void assertGetSchemaPath() { - assertThat(StatisticsNodePathGenerator.getSchemaPath("foo_db", "db_schema"), is("/statistics/databases/foo_db/schemas/db_schema")); - } - - @Test - void assertGetTableRootPath() { - assertThat(StatisticsNodePathGenerator.getTableRootPath("foo_db", "db_schema"), is("/statistics/databases/foo_db/schemas/db_schema/tables")); - } - - @Test - void assertGetTablePath() { - assertThat(StatisticsNodePathGenerator.getTablePath("foo_db", "db_schema", "tbl_name"), is("/statistics/databases/foo_db/schemas/db_schema/tables/tbl_name")); - } - - @Test - void assertGetTableRowPath() { - assertThat(StatisticsNodePathGenerator.getTableRowPath("foo_db", "db_schema", "tbl_name", "key"), is("/statistics/databases/foo_db/schemas/db_schema/tables/tbl_name/key")); - } - - @Test - void assertGetJobPath() { - assertThat(StatisticsNodePathGenerator.getJobPath(), is("/statistics/job")); + void assertGetRootPath() { + assertThat(new StatisticsNodePath().getRootPath(), is("/statistics")); } } diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsDatabaseNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsDatabaseNodePathTest.java new file mode 100644 index 0000000000000..e050dd0de19b5 --- /dev/null +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsDatabaseNodePathTest.java @@ -0,0 +1,31 @@ +/* + * 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.mode.node.path.statistics.database; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class StatisticsDatabaseNodePathTest { + + @Test + void assertGetRootPath() { + assertThat(new StatisticsDatabaseNodePath().getRootPath(), is("/statistics/databases")); + } +} diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsSchemaNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsSchemaNodePathTest.java new file mode 100644 index 0000000000000..4c10480eac7a3 --- /dev/null +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsSchemaNodePathTest.java @@ -0,0 +1,31 @@ +/* + * 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.mode.node.path.statistics.database; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class StatisticsSchemaNodePathTest { + + @Test + void assertGetRootPath() { + assertThat(new StatisticsSchemaNodePath("foo_db").getRootPath(), is("/statistics/databases/foo_db/schemas")); + } +} diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsTableNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsTableNodePathTest.java new file mode 100644 index 0000000000000..6eda10f5fa954 --- /dev/null +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsTableNodePathTest.java @@ -0,0 +1,31 @@ +/* + * 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.mode.node.path.statistics.database; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class StatisticsTableNodePathTest { + + @Test + void assertGetRootPath() { + assertThat(new StatisticsTableNodePath("foo_db", "foo_schema").getRootPath(), is("/statistics/databases/foo_db/schemas/foo_schema/tables")); + } +} diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsTableRowNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsTableRowNodePathTest.java new file mode 100644 index 0000000000000..98cefd912bc3b --- /dev/null +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/statistics/database/StatisticsTableRowNodePathTest.java @@ -0,0 +1,31 @@ +/* + * 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.mode.node.path.statistics.database; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class StatisticsTableRowNodePathTest { + + @Test + void assertGetRootPath() { + assertThat(new StatisticsTableRowNodePath("foo_db", "foo_schema", "foo_tbl").getRootPath(), is("/statistics/databases/foo_db/schemas/foo_schema/tables/foo_tbl")); + } +} diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/statistics/job/StatisticsJobNodePathTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/statistics/job/StatisticsJobNodePathTest.java new file mode 100644 index 0000000000000..86978b4b0e306 --- /dev/null +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/statistics/job/StatisticsJobNodePathTest.java @@ -0,0 +1,31 @@ +/* + * 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.mode.node.path.statistics.job; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class StatisticsJobNodePathTest { + + @Test + void assertGetRootPath() { + assertThat(new StatisticsJobNodePath().getRootPath(), is("/statistics/job")); + } +} diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/StatisticsChangedHandler.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/StatisticsChangedHandler.java index f22c658ae2d66..e905d10051b81 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/StatisticsChangedHandler.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/StatisticsChangedHandler.java @@ -20,12 +20,12 @@ import com.google.common.base.Strings; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; import org.apache.shardingsphere.infra.yaml.data.pojo.YamlRowStatistics; -import org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.GlobalDataChangedEventHandler; -import org.apache.shardingsphere.mode.node.path.statistics.StatisticsNodePathGenerator; import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; import org.apache.shardingsphere.mode.manager.ContextManager; +import org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.GlobalDataChangedEventHandler; import org.apache.shardingsphere.mode.metadata.manager.statistics.StatisticsManager; +import org.apache.shardingsphere.mode.node.path.statistics.database.StatisticsDatabaseNodePath; import org.apache.shardingsphere.mode.node.path.statistics.StatisticsNodePathParser; import java.util.Arrays; @@ -39,7 +39,7 @@ public final class StatisticsChangedHandler implements GlobalDataChangedEventHan @Override public String getSubscribedKey() { - return StatisticsNodePathGenerator.getDatabasesRootPath(); + return new StatisticsDatabaseNodePath().getRootPath(); } @Override