You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by do...@apache.org on 2020/12/20 00:10:31 UTC
[shardingsphere] branch master updated: Minor changes of
shardingsphere-governance-repository module (#8692)
This is an automated email from the ASF dual-hosted git repository.
dongzonglei 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 cfc0195 Minor changes of shardingsphere-governance-repository module (#8692)
cfc0195 is described below
commit cfc0195deaa587c1e03c3d4cc2168154ca32a58f
Author: Liang Zhang <te...@163.com>
AuthorDate: Sun Dec 20 08:10:02 2020 +0800
Minor changes of shardingsphere-governance-repository module (#8692)
* For code format
* Rename CuratorZookeeperRepository.lock
* Refactor CuratorZookeeperRepository
* Refactor LockCenter
* Refactor LockCenter
* For code format
* For code format
---
.../governance/core/lock/LockCenter.java | 10 ++--
.../governance/core/registry/RegistryCenter.java | 2 +-
.../pom.xml | 13 ++---
.../governance/repository/etcd/EtcdRepository.java | 4 +-
.../zookeeper/CuratorZookeeperRepository.java | 58 +++++++++++-----------
.../repository/zookeeper/EmbedTestingServer.java | 2 +-
6 files changed, 43 insertions(+), 46 deletions(-)
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/lock/LockCenter.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/lock/LockCenter.java
index ebfdf46..1224f7b 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/lock/LockCenter.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/lock/LockCenter.java
@@ -28,7 +28,6 @@ import org.apache.shardingsphere.governance.repository.api.RegistryRepository;
import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
import java.util.Collection;
-import java.util.Optional;
import java.util.concurrent.TimeUnit;
/**
@@ -118,9 +117,8 @@ public final class LockCenter {
}
private boolean check(final Collection<String> instanceIds) {
- for (String instanceId : instanceIds) {
- if (!RegistryCenterNodeStatus.LOCKED.toString()
- .equalsIgnoreCase(registryCenter.loadInstanceData(instanceId))) {
+ for (String each : instanceIds) {
+ if (!RegistryCenterNodeStatus.LOCKED.toString().equalsIgnoreCase(registryCenter.loadInstanceData(each))) {
return false;
}
}
@@ -134,8 +132,6 @@ public final class LockCenter {
*/
@Subscribe
public synchronized void lockNotice(final LockNoticeEvent event) {
- if (Optional.of(event).isPresent()) {
- registryCenter.persistInstanceData(event.isLocked() ? RegistryCenterNodeStatus.LOCKED.toString() : "");
- }
+ registryCenter.persistInstanceData(event.isLocked() ? RegistryCenterNodeStatus.LOCKED.toString() : "");
}
}
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
index a1fa1e2..a79111f 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
@@ -35,7 +35,7 @@ public final class RegistryCenter {
private final RegistryRepository repository;
private final GovernanceInstance instance;
-
+
public RegistryCenter(final RegistryRepository registryRepository) {
node = new RegistryCenterNode();
repository = registryRepository;
diff --git a/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-apollo/pom.xml b/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-apollo/pom.xml
index 719af64..4a2989c 100644
--- a/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-apollo/pom.xml
+++ b/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-apollo/pom.xml
@@ -41,12 +41,6 @@
</dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
- <artifactId>apollo-mockserver</artifactId>
- <version>${apollo.client.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-openapi</artifactId>
<version>${apollo.client.version}</version>
<scope>provided</scope>
@@ -55,5 +49,12 @@
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>com.ctrip.framework.apollo</groupId>
+ <artifactId>apollo-mockserver</artifactId>
+ <version>${apollo.client.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-etcd/src/main/java/org/apache/shardingsphere/governance/repository/etcd/EtcdRepository.java b/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-etcd/src/main/java/org/apache/shardingsphere/governance/repository/etcd/EtcdRepository.java
index 8508265..ce31f32 100644
--- a/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-etcd/src/main/java/org/apache/shardingsphere/governance/repository/etcd/EtcdRepository.java
+++ b/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-etcd/src/main/java/org/apache/shardingsphere/governance/repository/etcd/EtcdRepository.java
@@ -54,9 +54,9 @@ public final class EtcdRepository implements ConfigurationRepository, RegistryRe
@Getter
@Setter
private Properties props = new Properties();
-
+
private EtcdProperties etcdProperties;
-
+
@Override
public void init(final String name, final GovernanceCenterConfiguration config) {
etcdProperties = new EtcdProperties(props);
diff --git a/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/governance/repository/zookeeper/CuratorZookeeperRepository.java b/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/govern [...]
index ab042d1..8dd6414 100644
--- a/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/governance/repository/zookeeper/CuratorZookeeperRepository.java
+++ b/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/governance/repository/zookeeper/CuratorZookeeperRepository.java
@@ -63,7 +63,7 @@ public final class CuratorZookeeperRepository implements ConfigurationRepository
private CuratorFramework client;
- private InterProcessLock interProcessLock;
+ private InterProcessLock lock;
@Getter
@Setter
@@ -218,34 +218,6 @@ public final class CuratorZookeeperRepository implements ConfigurationRepository
}
@Override
- public void initLock(final String key) {
- interProcessLock = new InterProcessMutex(client, key);
- }
-
- @Override
- public boolean tryLock(final long time, final TimeUnit unit) {
- try {
- return interProcessLock.acquire(time, unit);
- // CHECKSTYLE:OFF
- } catch (final Exception e) {
- // CHECKSTYLE:ON
- CuratorZookeeperExceptionHandler.handleException(e);
- return false;
- }
- }
-
- @Override
- public void releaseLock() {
- try {
- interProcessLock.release();
- // CHECKSTYLE:OFF
- } catch (final Exception e) {
- // CHECKSTYLE:ON
- CuratorZookeeperExceptionHandler.handleException(e);
- }
- }
-
- @Override
public void delete(final String key) {
try {
if (isExisted(key)) {
@@ -301,6 +273,34 @@ public final class CuratorZookeeperRepository implements ConfigurationRepository
}
@Override
+ public void initLock(final String key) {
+ lock = new InterProcessMutex(client, key);
+ }
+
+ @Override
+ public boolean tryLock(final long time, final TimeUnit unit) {
+ try {
+ return lock.acquire(time, unit);
+ // CHECKSTYLE:OFF
+ } catch (final Exception ex) {
+ // CHECKSTYLE:ON
+ CuratorZookeeperExceptionHandler.handleException(ex);
+ return false;
+ }
+ }
+
+ @Override
+ public void releaseLock() {
+ try {
+ lock.release();
+ // CHECKSTYLE:OFF
+ } catch (final Exception ex) {
+ // CHECKSTYLE:ON
+ CuratorZookeeperExceptionHandler.handleException(ex);
+ }
+ }
+
+ @Override
public void close() {
caches.values().forEach(CuratorCache::close);
waitForCacheClose();
diff --git a/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-zookeeper-curator/src/test/java/org/apache/shardingsphere/governance/repository/zookeeper/EmbedTestingServer.java b/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-zookeeper-curator/src/test/java/org/apache/shardingsphere/governance/rep [...]
index 53b512a..aee82e5 100644
--- a/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-zookeeper-curator/src/test/java/org/apache/shardingsphere/governance/repository/zookeeper/EmbedTestingServer.java
+++ b/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-zookeeper-curator/src/test/java/org/apache/shardingsphere/governance/repository/zookeeper/EmbedTestingServer.java
@@ -56,7 +56,7 @@ public final class EmbedTestingServer {
}));
}
}
-
+
/**
* Get testingServer connection string.
*