This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 c7ea296 Rename and unify StoragePrivilegeLoader (#9954)
c7ea296 is described below
commit c7ea29693b802cffd29fd5323bf35970434bd353
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Apr 7 00:43:32 2021 +0800
Rename and unify StoragePrivilegeLoader (#9954)
* Rename StoragePrivilegeLoader
* Refactor PrivilegeLoader to extend TypedSPI
* Refactor PrivilegeLoaderEngine
* Remove PrivilegeLoaderEngine
* Rename StoragePrivilegeLoader
---
.../builder/loader/PrivilegeLoaderEngine.java | 51 ----------------------
.../StoragePrivilegeLoadAlgorithm.java | 22 ++++++----
.../impl/StoragePrivilegeBuilder.java} | 29 +++++++-----
.../impl/StoragePrivilegeLoader.java} | 14 ++----
.../impl/StoragePrivilegeMerger.java} | 8 ++--
.../impl}/dialect/MySQLPrivilegeLoader.java | 8 ++--
.../impl}/dialect/PostgreSQLPrivilegeLoader.java | 8 ++--
...ity.loader.storage.impl.StoragePrivilegeLoader} | 4 +-
...dingsphere.authority.spi.PrivilegeLoadAlgorithm | 2 +-
.../impl}/dialect/MySQLPrivilegeLoaderTest.java | 19 +++-----
.../dialect/PostgreSQLPrivilegeLoaderTest.java | 19 +++-----
.../authority/GovernanceAuthorityContext.java | 19 ++++----
12 files changed, 72 insertions(+), 131 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/PrivilegeLoaderEngine.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/PrivilegeLoaderEngine.java
deleted file mode 100644
index c788b62..0000000
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/PrivilegeLoaderEngine.java
+++ /dev/null
@@ -1,51 +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.authority.loader.builder.loader;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-
-import java.util.Optional;
-
-/**
- * Privilege loader engine.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class PrivilegeLoaderEngine {
-
- static {
- ShardingSphereServiceLoader.register(PrivilegeLoader.class);
- }
-
- /**
- * Find privilege loader.
- *
- * @param databaseType database type
- * @return privilege loader
- */
- public static Optional<PrivilegeLoader> findPrivilegeLoader(final
DatabaseType databaseType) {
- for (PrivilegeLoader each :
ShardingSphereServiceLoader.getSingletonServiceInstances(PrivilegeLoader.class))
{
- if (each.getDatabaseType().equals(databaseType.getName())) {
- return Optional.of(each);
- }
- }
- return Optional.empty();
- }
-}
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/StoragePrivilegeLoadAlgorithm.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/StoragePrivilegeLoadAlgorithm.java
similarity index 68%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/StoragePrivilegeLoadAlgorithm.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/StoragePrivilegeLoadAlgorithm.java
index 5c0b88b..8bdc472 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/StoragePrivilegeLoadAlgorithm.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/StoragePrivilegeLoadAlgorithm.java
@@ -15,33 +15,39 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.loader;
+package org.apache.shardingsphere.authority.loader.storage;
+import
org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeBuilder;
+import
org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeLoader;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.authority.spi.PrivilegeLoadAlgorithm;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.authority.loader.builder.PrivilegeBuilder;
-import
org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoader;
-import
org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoaderEngine;
-import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
import javax.sql.DataSource;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
+import java.util.Properties;
/**
* Storage privilege load algorithm.
*/
public final class StoragePrivilegeLoadAlgorithm implements
PrivilegeLoadAlgorithm {
+ static {
+ ShardingSphereServiceLoader.register(StoragePrivilegeLoader.class);
+ }
+
@Override
public Map<ShardingSphereUser, Privileges> load(final String schemaName,
final DatabaseType databaseType, final Collection<DataSource> dataSources,
final
Collection<ShardingSphereRule> rules, final Collection<ShardingSphereUser>
users) {
- Optional<PrivilegeLoader> loader =
PrivilegeLoaderEngine.findPrivilegeLoader(databaseType);
- return loader.map(
- optional -> PrivilegeBuilder.build(schemaName,
groupDataSourcesByInstance(dataSources), rules, users, optional)).orElseGet(()
-> PrivilegeBuilder.buildDefaultPrivileges(users));
+ Optional<StoragePrivilegeLoader> loader =
TypedSPIRegistry.findRegisteredService(StoragePrivilegeLoader.class,
databaseType.getName(), new Properties());
+ return loader.map(optional -> StoragePrivilegeBuilder.build(
+ schemaName, groupDataSourcesByInstance(dataSources), rules,
users, optional)).orElseGet(() ->
StoragePrivilegeBuilder.buildDefaultPrivileges(users));
}
private Collection<DataSource> groupDataSourcesByInstance(final
Collection<DataSource> dataSources) {
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/PrivilegeBuilder.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/StoragePrivilegeBuilder.java
similarity index 88%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/PrivilegeBuilder.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/StoragePrivilegeBuilder.java
index b270ae0..4c6c123 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/PrivilegeBuilder.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/StoragePrivilegeBuilder.java
@@ -15,18 +15,18 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.loader.builder;
+package org.apache.shardingsphere.authority.loader.storage.impl;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import
org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoader;
-import
org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoaderEngine;
+import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
import javax.sql.DataSource;
import java.util.Collection;
@@ -36,6 +36,7 @@ import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
+import java.util.Properties;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -44,15 +45,19 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
- * Privilege builder.
+ * Storage privilege builder.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class PrivilegeBuilder {
+public final class StoragePrivilegeBuilder {
private static final int CPU_CORES =
Runtime.getRuntime().availableProcessors();
private static final long FUTURE_GET_TIME_OUT_MILLISECONDS = 5000L;
+ static {
+ ShardingSphereServiceLoader.register(StoragePrivilegeLoader.class);
+ }
+
/**
* Build privileges.
*
@@ -66,12 +71,12 @@ public final class PrivilegeBuilder {
if (metaDataList.isEmpty()) {
return buildDefaultPrivileges(users);
}
- Optional<PrivilegeLoader> loader =
PrivilegeLoaderEngine.findPrivilegeLoader(databaseType);
+ Optional<StoragePrivilegeLoader> loader =
TypedSPIRegistry.findRegisteredService(StoragePrivilegeLoader.class,
databaseType.getName(), new Properties());
return loader.map(optional -> build(metaDataList, users,
optional)).orElseGet(() -> buildDefaultPrivileges(users));
}
private static Map<ShardingSphereUser, Privileges> build(final
Collection<ShardingSphereMetaData> metaDataList,
- final
Collection<ShardingSphereUser> users, final PrivilegeLoader loader) {
+ final
Collection<ShardingSphereUser> users, final StoragePrivilegeLoader loader) {
Map<ShardingSphereUser, Privileges> result = new LinkedHashMap<>();
for (ShardingSphereMetaData each : metaDataList) {
result.putAll(build(each, users, loader));
@@ -79,7 +84,7 @@ public final class PrivilegeBuilder {
return result;
}
- private static Map<ShardingSphereUser, Privileges> build(final
ShardingSphereMetaData metaData, final Collection<ShardingSphereUser> users,
final PrivilegeLoader loader) {
+ private static Map<ShardingSphereUser, Privileges> build(final
ShardingSphereMetaData metaData, final Collection<ShardingSphereUser> users,
final StoragePrivilegeLoader loader) {
return build(metaData.getName(),
metaData.getResource().getAllInstanceDataSources(),
metaData.getRuleMetaData().getRules(), users, loader);
}
@@ -94,14 +99,14 @@ public final class PrivilegeBuilder {
* @return privileges
*/
public static Map<ShardingSphereUser, Privileges> build(final String
schemaName, final Collection<DataSource> dataSources,
- final
Collection<ShardingSphereRule> rules, final Collection<ShardingSphereUser>
users, final PrivilegeLoader loader) {
+ final
Collection<ShardingSphereRule> rules, final Collection<ShardingSphereUser>
users, final StoragePrivilegeLoader loader) {
Map<ShardingSphereUser, Collection<Privileges>> result =
load(dataSources, users, loader);
checkPrivileges(result);
- return PrivilegeMerger.merge(result, schemaName, rules);
+ return StoragePrivilegeMerger.merge(result, schemaName, rules);
}
private static Map<ShardingSphereUser, Collection<Privileges>> load(final
Collection<DataSource> dataSources,
- final
Collection<ShardingSphereUser> users, final PrivilegeLoader loader) {
+ final
Collection<ShardingSphereUser> users, final StoragePrivilegeLoader loader) {
Map<ShardingSphereUser, Collection<Privileges>> result = new
LinkedHashMap<>(users.size(), 1);
ExecutorService executorService =
Executors.newFixedThreadPool(Math.min(CPU_CORES * 2, dataSources.isEmpty() ? 1
: dataSources.size()));
Collection<Future<Map<ShardingSphereUser, Privileges>>> futures = new
HashSet<>(dataSources.size(), 1);
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/PrivilegeLoader.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/StoragePrivilegeLoader.java
similarity index 85%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/PrivilegeLoader.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/StoragePrivilegeLoader.java
index 12c746c..913bc3e 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/PrivilegeLoader.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/StoragePrivilegeLoader.java
@@ -15,10 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.loader.builder.loader;
+package org.apache.shardingsphere.authority.loader.storage.impl;
import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
+import org.apache.shardingsphere.infra.spi.typed.TypedSPI;
import javax.sql.DataSource;
import java.sql.SQLException;
@@ -26,9 +27,9 @@ import java.util.Collection;
import java.util.Map;
/**
- * Privilege loader.
+ * Storage privilege loader.
*/
-public interface PrivilegeLoader {
+public interface StoragePrivilegeLoader extends TypedSPI {
/**
* Load privilege.
@@ -39,11 +40,4 @@ public interface PrivilegeLoader {
* @throws SQLException SQL exception
*/
Map<ShardingSphereUser, Privileges> load(Collection<ShardingSphereUser>
users, DataSource dataSource) throws SQLException;
-
- /**
- * Get database type.
- *
- * @return database type
- */
- String getDatabaseType();
}
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/PrivilegeMerger.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/StoragePrivilegeMerger.java
similarity index 94%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/PrivilegeMerger.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/StoragePrivilegeMerger.java
index ef0380c..236fb3f 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/PrivilegeMerger.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/StoragePrivilegeMerger.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.loader.builder;
+package org.apache.shardingsphere.authority.loader.storage.impl;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -31,13 +31,13 @@ import java.util.Map;
import java.util.Map.Entry;
/**
- * Privilege merger.
+ * Storage privilege merger.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class PrivilegeMerger {
+public final class StoragePrivilegeMerger {
/**
- * Merge privilege.
+ * Merge privileges.
*
* @param authentication authentication
* @param schemaName schema name
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/MySQLPrivilegeLoader.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/MySQLPrivilegeLoader.java
similarity index 98%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/MySQLPrivilegeLoader.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/MySQLPrivilegeLoader.java
index 5b82252..510b12d 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/MySQLPrivilegeLoader.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/MySQLPrivilegeLoader.java
@@ -15,11 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.loader.builder.loader.dialect;
+package org.apache.shardingsphere.authority.loader.storage.impl.dialect;
import org.apache.shardingsphere.authority.model.database.SchemaPrivileges;
import org.apache.shardingsphere.authority.model.database.TablePrivileges;
-import
org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoader;
+import
org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeLoader;
import org.apache.shardingsphere.authority.model.PrivilegeType;
import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
@@ -41,7 +41,7 @@ import java.util.stream.Collectors;
/**
* MySQL privilege loader.
*/
-public final class MySQLPrivilegeLoader implements PrivilegeLoader {
+public final class MySQLPrivilegeLoader implements StoragePrivilegeLoader {
private static final String GLOBAL_PRIVILEGE_SQL = "SELECT * FROM
mysql.user WHERE (user, host) in (%s)";
@@ -229,7 +229,7 @@ public final class MySQLPrivilegeLoader implements
PrivilegeLoader {
}
@Override
- public String getDatabaseType() {
+ public String getType() {
return "MySQL";
}
}
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/PostgreSQLPrivilegeLoader.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/PostgreSQLPrivilegeLoader.java
similarity index 97%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/PostgreSQLPrivilegeLoader.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/PostgreSQLPrivilegeLoader.java
index 6cbf80b..32b3d88 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/PostgreSQLPrivilegeLoader.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/PostgreSQLPrivilegeLoader.java
@@ -15,11 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.loader.builder.loader.dialect;
+package org.apache.shardingsphere.authority.loader.storage.impl.dialect;
import org.apache.shardingsphere.authority.model.database.SchemaPrivileges;
import org.apache.shardingsphere.authority.model.database.TablePrivileges;
-import
org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoader;
+import
org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeLoader;
import org.apache.shardingsphere.authority.model.PrivilegeType;
import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
@@ -44,7 +44,7 @@ import java.util.stream.Collectors;
/**
* PostgreSQL privilege loader.
*/
-public final class PostgreSQLPrivilegeLoader implements PrivilegeLoader {
+public final class PostgreSQLPrivilegeLoader implements StoragePrivilegeLoader
{
private static final String ROLES_SQL = "select * from pg_roles WHERE
rolname IN (%s)";
@@ -185,7 +185,7 @@ public final class PostgreSQLPrivilegeLoader implements
PrivilegeLoader {
}
@Override
- public String getDatabaseType() {
+ public String getType() {
return "PostgreSQL";
}
}
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoader
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeLoader
similarity index 81%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoader
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeLoader
index 59e850d..bc2460e 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoader
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeLoader
@@ -15,5 +15,5 @@
# limitations under the License.
#
-org.apache.shardingsphere.authority.loader.builder.loader.dialect.MySQLPrivilegeLoader
-org.apache.shardingsphere.authority.loader.builder.loader.dialect.PostgreSQLPrivilegeLoader
+org.apache.shardingsphere.authority.loader.storage.impl.dialect.MySQLPrivilegeLoader
+org.apache.shardingsphere.authority.loader.storage.impl.dialect.PostgreSQLPrivilegeLoader
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.PrivilegeLoadAlgorithm
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.PrivilegeLoadAlgorithm
index 9f45f85..d6166f0 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.PrivilegeLoadAlgorithm
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/resources/META-INF/services/org.apache.shardingsphere.authority.spi.PrivilegeLoadAlgorithm
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.authority.loader.StoragePrivilegeLoadAlgorithm
+org.apache.shardingsphere.authority.loader.storage.StoragePrivilegeLoadAlgorithm
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/MySQLPrivilegeLoaderTest.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/MySQLPrivilegeLoaderTest.java
similarity index 93%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/MySQLPrivilegeLoaderTest.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/MySQLPrivilegeLoaderTest.java
index c757259..0b6f8c1 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/MySQLPrivilegeLoaderTest.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/MySQLPrivilegeLoaderTest.java
@@ -15,13 +15,14 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.loader.builder.loader.dialect;
+package org.apache.shardingsphere.authority.loader.storage.impl.dialect;
+import
org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeLoader;
import org.apache.shardingsphere.authority.model.PrivilegeType;
import org.apache.shardingsphere.authority.model.Privileges;
-import
org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoader;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -32,6 +33,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.Map;
+import java.util.Properties;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.stream.Collectors;
@@ -45,14 +47,14 @@ public final class MySQLPrivilegeLoaderTest {
@BeforeClass
public static void setUp() {
- ShardingSphereServiceLoader.register(PrivilegeLoader.class);
+ ShardingSphereServiceLoader.register(StoragePrivilegeLoader.class);
}
@Test
public void assertLoad() throws SQLException {
Collection<ShardingSphereUser> users = createUsers();
DataSource dataSource = mockDataSource(users);
- assertPrivileges(getPrivilegeLoader().load(users, dataSource));
+
assertPrivileges(TypedSPIRegistry.getRegisteredService(StoragePrivilegeLoader.class,
"MySQL", new Properties()).load(users, dataSource));
}
private Collection<ShardingSphereUser> createUsers() {
@@ -168,13 +170,4 @@ public final class MySQLPrivilegeLoaderTest {
assertThat(actual.get(sys).getDatabasePrivileges().getGlobalPrivileges().size(),
is(0));
assertThat(actual.get(sys).getDatabasePrivileges().getSpecificPrivileges().size(),
is(1));
}
-
- private PrivilegeLoader getPrivilegeLoader() {
- for (PrivilegeLoader each :
ShardingSphereServiceLoader.getSingletonServiceInstances(PrivilegeLoader.class))
{
- if ("MySQL".equals(each.getDatabaseType())) {
- return each;
- }
- }
- throw new IllegalStateException("Can not find MySQLPrivilegeLoader");
- }
}
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/PostgreSQLPrivilegeLoaderTest.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/PostgreSQLPrivilegeLoaderTest.java
similarity index 90%
rename from
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/PostgreSQLPrivilegeLoaderTest.java
rename to
shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/PostgreSQLPrivilegeLoaderTest.java
index 5b5ded9..f829a9a 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/builder/loader/dialect/PostgreSQLPrivilegeLoaderTest.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/loader/storage/impl/dialect/PostgreSQLPrivilegeLoaderTest.java
@@ -15,14 +15,15 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.loader.builder.loader.dialect;
+package org.apache.shardingsphere.authority.loader.storage.impl.dialect;
import org.apache.shardingsphere.authority.model.PrivilegeType;
import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.authority.model.database.SchemaPrivileges;
-import
org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoader;
+import
org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeLoader;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -35,6 +36,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.Map;
+import java.util.Properties;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.stream.Collectors;
@@ -50,14 +52,14 @@ public final class PostgreSQLPrivilegeLoaderTest {
@BeforeClass
public static void setUp() {
- ShardingSphereServiceLoader.register(PrivilegeLoader.class);
+ ShardingSphereServiceLoader.register(StoragePrivilegeLoader.class);
}
@Test
public void assertLoad() throws SQLException {
Collection<ShardingSphereUser> users = createUsers();
DataSource dataSource = mockDataSource(users);
- assertPrivileges(getPrivilegeLoader().load(users, dataSource));
+
assertPrivileges(TypedSPIRegistry.getRegisteredService(StoragePrivilegeLoader.class,
"PostgreSQL", new Properties()).load(users, dataSource));
}
private void assertPrivileges(final Map<ShardingSphereUser, Privileges>
actual) {
@@ -116,13 +118,4 @@ public final class PostgreSQLPrivilegeLoaderTest {
when(result.getBoolean("rolcanlogin")).thenReturn(true);
return result;
}
-
- private PrivilegeLoader getPrivilegeLoader() {
- for (PrivilegeLoader each :
ShardingSphereServiceLoader.getSingletonServiceInstances(PrivilegeLoader.class))
{
- if ("PostgreSQL".equals(each.getDatabaseType())) {
- return each;
- }
- }
- throw new IllegalStateException("Can not find
PostgreSQLPrivilegeLoader");
- }
}
diff --git
a/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/authority/GovernanceAuthorityContext.java
b/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/authority/GovernanceAuthorityContext.java
index d2361e3..a3f30aa 100644
---
a/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/authority/GovernanceAuthorityContext.java
+++
b/shardingsphere-governance/shardingsphere-governance-context/src/main/java/org/apache/shardingsphere/governance/context/authority/GovernanceAuthorityContext.java
@@ -20,24 +20,25 @@ package
org.apache.shardingsphere.governance.context.authority;
import com.google.common.base.Preconditions;
import com.google.common.eventbus.Subscribe;
import lombok.Setter;
+import org.apache.shardingsphere.authority.engine.Authentication;
+import org.apache.shardingsphere.authority.engine.AuthenticationContext;
+import org.apache.shardingsphere.authority.engine.impl.DefaultAuthentication;
+import
org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeBuilder;
+import
org.apache.shardingsphere.authority.loader.storage.impl.StoragePrivilegeLoader;
+import org.apache.shardingsphere.authority.model.Privileges;
import
org.apache.shardingsphere.governance.core.event.model.auth.PrivilegeChangedEvent;
import
org.apache.shardingsphere.governance.core.event.model.auth.UserRuleChangedEvent;
import
org.apache.shardingsphere.infra.context.metadata.MetaDataAwareEventSubscriber;
import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.authority.engine.Authentication;
-import org.apache.shardingsphere.authority.engine.AuthenticationContext;
-import org.apache.shardingsphere.authority.loader.builder.PrivilegeBuilder;
-import
org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoader;
-import
org.apache.shardingsphere.authority.loader.builder.loader.PrivilegeLoaderEngine;
-import org.apache.shardingsphere.authority.engine.impl.DefaultAuthentication;
-import org.apache.shardingsphere.authority.model.Privileges;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
+import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
+import java.util.Properties;
import java.util.stream.Collectors;
/**
@@ -100,9 +101,9 @@ public final class GovernanceAuthorityContext implements
MetaDataAwareEventSubsc
private void reloadPrivilege(final Collection<ShardingSphereUser> users) {
Authentication authentication =
AuthenticationContext.getInstance().getAuthentication();
DatabaseType databaseType =
metaDataContexts.getMetaDataMap().values().iterator().next().getResource().getDatabaseType();
- Optional<PrivilegeLoader> loader =
PrivilegeLoaderEngine.findPrivilegeLoader(databaseType);
+ Optional<StoragePrivilegeLoader> loader =
TypedSPIRegistry.findRegisteredService(StoragePrivilegeLoader.class,
databaseType.getName(), new Properties());
if (loader.isPresent()) {
- Map<ShardingSphereUser, Privileges> privileges =
PrivilegeBuilder.build(databaseType,
metaDataContexts.getMetaDataMap().values(), users);
+ Map<ShardingSphereUser, Privileges> privileges =
StoragePrivilegeBuilder.build(databaseType,
metaDataContexts.getMetaDataMap().values(), users);
authentication.getAuthentication().putAll(getPrivilegesWithPassword(authentication,
privileges));
}
AuthenticationContext.getInstance().init(authentication);