You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2021/11/08 02:53:22 UTC
[shardingsphere] branch master updated: Sync cron to elastic-job
(#13475)
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 2a68ef3 Sync cron to elastic-job (#13475)
2a68ef3 is described below
commit 2a68ef3c578306574950c87b430473f9a09424a7
Author: zhaojinchao <33...@users.noreply.github.com>
AuthorDate: Mon Nov 8 10:52:43 2021 +0800
Sync cron to elastic-job (#13475)
* sync cron to elastic-job
* update
* update
---
.../dbdiscovery/spi/DatabaseDiscoveryType.java | 9 +++++++++
.../dbdiscovery/rule/DatabaseDiscoveryRule.java | 4 ++--
.../dbdiscovery/fixture/TestDatabaseDiscoveryType.java | 6 ++++++
.../AlterDatabaseDiscoveryRuleStatementUpdater.java | 14 ++++++++++++--
.../shardingsphere-db-discovery-mgr/pom.xml | 5 +++++
.../dbdiscovery/mgr/MGRDatabaseDiscoveryType.java | 17 ++++++++++++++++-
.../text/distsql/fixture/TestDatabaseDiscoveryType.java | 6 ++++++
7 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/dbdiscovery/spi/DatabaseDiscoveryType.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/dbdiscovery/spi/DatabaseDiscoveryType.java
index 430cff0..59b6797 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/dbdiscovery/spi/DatabaseDiscoveryType.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/dbdiscovery/spi/DatabaseDiscoveryType.java
@@ -23,6 +23,7 @@ import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Map;
+import java.util.Properties;
/**
* Database discovery type.
@@ -75,4 +76,12 @@ public interface DatabaseDiscoveryType extends ShardingSphereAlgorithm {
* @return primary data source
*/
String getPrimaryDataSource();
+
+ /**
+ * update properties.
+ *
+ * @param groupName group name
+ * @param props properties
+ */
+ void updateProperties(String groupName, Properties props);
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
index 3133a62..edd9757 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
@@ -70,7 +70,7 @@ public final class DatabaseDiscoveryRule implements SchemaRule, DataSourceContai
this(config.getDataSources(), config.getDiscoveryTypes(), schemaName, dataSourceMap);
}
- private DatabaseDiscoveryRule(final Collection<DatabaseDiscoveryDataSourceRuleConfiguration> dataSourceRuleConfigs, final Map<String, DatabaseDiscoveryType> discoveryTypes,
+ private DatabaseDiscoveryRule(final Collection<DatabaseDiscoveryDataSourceRuleConfiguration> dataSourceRuleConfigs, final Map<String, DatabaseDiscoveryType> discoveryTypes,
final String schemaName, final Map<String, DataSource> dataSourceMap) {
checkDataSourcesArguments(dataSourceRuleConfigs, dataSourceMap);
this.discoveryTypes = discoveryTypes;
@@ -141,7 +141,7 @@ public final class DatabaseDiscoveryRule implements SchemaRule, DataSourceContai
/**
* Find data source rule.
- *
+ *
* @param dataSourceName data source name
* @return found data source rule
*/
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/fixture/TestDatabaseDiscoveryType.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/fixture/TestDatabaseDiscoveryType.java
index d763492..3af56e8 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/fixture/TestDatabaseDiscoveryType.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/fixture/TestDatabaseDiscoveryType.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
import javax.sql.DataSource;
import java.util.Collection;
import java.util.Map;
+import java.util.Properties;
public final class TestDatabaseDiscoveryType implements DatabaseDiscoveryType {
@@ -49,6 +50,11 @@ public final class TestDatabaseDiscoveryType implements DatabaseDiscoveryType {
}
@Override
+ public void updateProperties(final String groupName, final Properties props) {
+
+ }
+
+ @Override
public String getType() {
return "TEST";
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDis [...]
index 4ec34ee..6d2bc9b 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java
@@ -25,6 +25,7 @@ import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDisc
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.AlterDatabaseDiscoveryRuleStatement;
import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import org.apache.shardingsphere.infra.distsql.exception.resource.RequiredResourceMissedException;
import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException;
@@ -67,7 +68,7 @@ public final class AlterDatabaseDiscoveryRuleStatementUpdater implements RuleDef
}
}
- private void checkToBeAlteredRules(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement,
+ private void checkToBeAlteredRules(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement,
final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws RequiredRuleMissedException {
Collection<String> currentRuleNames = currentRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName).collect(Collectors.toSet());
Collection<String> notExistedRuleNames = getToBeAlteredRuleNames(sqlStatement).stream().filter(each -> !currentRuleNames.contains(each)).collect(Collectors.toList());
@@ -80,7 +81,7 @@ public final class AlterDatabaseDiscoveryRuleStatementUpdater implements RuleDef
return sqlStatement.getRules().stream().map(DatabaseDiscoveryRuleSegment::getName).collect(Collectors.toList());
}
- private void checkToBeAlteredResources(final String schemaName,
+ private void checkToBeAlteredResources(final String schemaName,
final AlterDatabaseDiscoveryRuleStatement sqlStatement, final ShardingSphereResource resource) throws RequiredResourceMissedException {
Collection<String> notExistedResources = resource.getNotExistedResources(getToBeAlteredResourceNames(sqlStatement));
if (!notExistedResources.isEmpty()) {
@@ -115,6 +116,7 @@ public final class AlterDatabaseDiscoveryRuleStatementUpdater implements RuleDef
public void updateCurrentRuleConfiguration(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final DatabaseDiscoveryRuleConfiguration toBeAlteredRuleConfig) {
dropRuleConfiguration(currentRuleConfig, toBeAlteredRuleConfig);
addRuleConfiguration(currentRuleConfig, toBeAlteredRuleConfig);
+ updateProperties(toBeAlteredRuleConfig);
}
private void dropRuleConfiguration(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final DatabaseDiscoveryRuleConfiguration toBeAlteredRuleConfig) {
@@ -136,6 +138,14 @@ public final class AlterDatabaseDiscoveryRuleStatementUpdater implements RuleDef
currentRuleConfig.getDiscoveryTypes().putAll(toBeAlteredRuleConfig.getDiscoveryTypes());
}
+ private void updateProperties(final DatabaseDiscoveryRuleConfiguration ruleConfiguration) {
+ ruleConfiguration.getDataSources().forEach(each -> {
+ ShardingSphereAlgorithmConfiguration configuration = ruleConfiguration.getDiscoveryTypes().get(each.getDiscoveryTypeName());
+ TypedSPIRegistry.findRegisteredService(DatabaseDiscoveryType.class, configuration.getType(),
+ new Properties()).ifPresent(databaseDiscoveryType -> databaseDiscoveryType.updateProperties(each.getName(), configuration.getProps()));
+ });
+ }
+
@Override
public Class<DatabaseDiscoveryRuleConfiguration> getRuleConfigurationClass() {
return DatabaseDiscoveryRuleConfiguration.class;
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/pom.xml b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/pom.xml
index 7d766b8..b9ad06b 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/pom.xml
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/pom.xml
@@ -36,6 +36,11 @@
</dependency>
<dependency>
<groupId>org.apache.shardingsphere.elasticjob</groupId>
+ <artifactId>elasticjob-lite-lifecycle</artifactId>
+ <version>${elasticjob.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere.elasticjob</groupId>
<artifactId>elasticjob-lite-core</artifactId>
<version>${elasticjob.version}</version>
<exclusions>
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/main/java/org/apache/shardingsphere/dbdiscovery/mgr/MGRDatabaseDiscoveryType.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/main/java/org/apache/shardingsphere/dbdiscovery/mgr/MGRDatabaseDiscoveryType.java
index 4c039b3..20ad00b 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/main/java/org/apache/shardingsphere/dbdiscovery/mgr/MGRDatabaseDiscoveryType.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/main/java/org/apache/shardingsphere/dbdiscovery/mgr/MGRDatabaseDiscoveryType.java
@@ -22,7 +22,9 @@ import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
+import org.apache.shardingsphere.elasticjob.infra.pojo.JobConfigurationPOJO;
import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap;
+import org.apache.shardingsphere.elasticjob.lite.lifecycle.internal.settings.JobConfigurationAPIImpl;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
@@ -148,7 +150,7 @@ public final class MGRDatabaseDiscoveryType implements DatabaseDiscoveryType {
String primaryDataSourceURL = findPrimaryDataSourceURL(dataSourceMap);
return findPrimaryDataSourceName(primaryDataSourceURL, dataSourceMap);
}
-
+
private String findPrimaryDataSourceURL(final Map<String, DataSource> dataSourceMap) {
String result = "";
String sql = "SELECT MEMBER_HOST, MEMBER_PORT FROM performance_schema.replication_group_members WHERE MEMBER_ID = "
@@ -289,6 +291,19 @@ public final class MGRDatabaseDiscoveryType implements DatabaseDiscoveryType {
}
@Override
+ public void updateProperties(final String groupName, final Properties props) {
+ new JobConfigurationAPIImpl(coordinatorRegistryCenter).updateJobConfiguration(createJobConfiguration("MGR-" + groupName, props.getProperty("keepAliveCron")));
+ }
+
+ private JobConfigurationPOJO createJobConfiguration(final String jobName, final String cron) {
+ JobConfigurationPOJO result = new JobConfigurationPOJO();
+ result.setJobName(jobName);
+ result.setCron(cron);
+ result.setShardingTotalCount(1);
+ return result;
+ }
+
+ @Override
public String getType() {
return "MGR";
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/fixture/TestDatabaseDiscoveryType.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/fixture/TestDatabaseDiscoveryType.java
index 7daca47..7435870 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/fixture/TestDatabaseDiscoveryType.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/fixture/TestDatabaseDiscoveryType.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
import javax.sql.DataSource;
import java.util.Collection;
import java.util.Map;
+import java.util.Properties;
public final class TestDatabaseDiscoveryType implements DatabaseDiscoveryType {
@@ -49,6 +50,11 @@ public final class TestDatabaseDiscoveryType implements DatabaseDiscoveryType {
}
@Override
+ public void updateProperties(final String groupName, final Properties props) {
+
+ }
+
+ @Override
public String getType() {
return "TEST";
}