diff --git a/docs/document/content/dev-manual/mode.cn.md b/docs/document/content/dev-manual/mode.cn.md index 6ce9fb78ac3b4..edcda0e8cbab4 100644 --- a/docs/document/content/dev-manual/mode.cn.md +++ b/docs/document/content/dev-manual/mode.cn.md @@ -37,5 +37,4 @@ chapter = true |-----------|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ZooKeeper | 基于 ZooKeeper 的持久化 | [`org.apache.shardingsphere.mode.repository.cluster.zookeeper.ZookeeperRepository`](https://github.com/apache/shardingsphere/blob/master/mode/type/cluster/repository/provider/zookeeper/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/ZookeeperRepository.java) | | etcd | 基于 Etcd 的持久化 | [`org.apache.shardingsphere.mode.repository.cluster.etcd.EtcdRepository`](https://github.com/apache/shardingsphere/blob/master/mode/type/cluster/repository/provider/etcd/src/main/java/org/apache/shardingsphere/mode/repository/cluster/etcd/EtcdRepository.java) | -| Nacos | 基于 Nacos 的持久化 | [`org.apache.shardingsphere.mode.repository.cluster.nacos.NacosRepository`](https://github.com/apache/shardingsphere/blob/master/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/NacosRepository.java) | | Consul | 基于 Consul 的持久化 | [`org.apache.shardingsphere.mode.repository.cluster.consul.ConsulRepository`](https://github.com/apache/shardingsphere/blob/master/mode/type/cluster/repository/provider/consul/src/main/java/org/apache/shardingsphere/mode/repository/cluster/consul/ConsulRepository.java) | diff --git a/docs/document/content/dev-manual/mode.en.md b/docs/document/content/dev-manual/mode.en.md index 0f44fd25a76c0..0fab555b840fd 100644 --- a/docs/document/content/dev-manual/mode.en.md +++ b/docs/document/content/dev-manual/mode.en.md @@ -37,5 +37,4 @@ Cluster mode configuration information persistence definition |----------------------|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ZooKeeper | ZooKeeper based persistence | [`org.apache.shardingsphere.mode.repository.cluster.zookeeper.ZookeeperRepository`](https://github.com/apache/shardingsphere/blob/master/mode/type/cluster/repository/provider/zookeeper/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/ZookeeperRepository.java) | | etcd | Etcd based persistence | [`org.apache.shardingsphere.mode.repository.cluster.etcd.EtcdRepository`](https://github.com/apache/shardingsphere/blob/master/mode/type/cluster/repository/provider/etcd/src/main/java/org/apache/shardingsphere/mode/repository/cluster/etcd/EtcdRepository.java) | -| Nacos | Nacos based persistence | [`org.apache.shardingsphere.mode.repository.cluster.nacos.NacosRepository`](https://github.com/apache/shardingsphere/blob/master/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/NacosRepository.java) | | Consul | Consul based persistence | [`org.apache.shardingsphere.mode.repository.cluster.consul.ConsulRepository`](https://github.com/apache/shardingsphere/blob/master/mode/type/cluster/repository/provider/consul/src/main/java/org/apache/shardingsphere/mode/repository/cluster/consul/ConsulRepository.java) | diff --git a/docs/document/content/user-manual/common-config/builtin-algorithm/metadata-repository.cn.md b/docs/document/content/user-manual/common-config/builtin-algorithm/metadata-repository.cn.md index 40cdac63afecf..5181f984e9c27 100644 --- a/docs/document/content/user-manual/common-config/builtin-algorithm/metadata-repository.cn.md +++ b/docs/document/content/user-manual/common-config/builtin-algorithm/metadata-repository.cn.md @@ -54,21 +54,6 @@ Apache ShardingSphere 为不同的运行模式提供了不同的元数据持久 | timeToLiveSeconds | long | 临时数据失效的秒数 | 30 | | connectionTimeout | long | 连接超时秒数 | 30 | -### Nacos 持久化 - -类型:Nacos - -适用模式:Cluster - -可配置属性: - -| *名称* | *数据类型* | *说明* | *默认值* | -|---------------------------|--------|-------------------|--------| -| clusterIp | String | 集群中的唯一标识 | 真实主机IP | -| retryIntervalMilliseconds | long | 重试间隔毫秒数 | 500 | -| maxRetries | int | 客户端检查数据可用性的最大重试次数 | 3 | -| timeToLiveSeconds | int | 临时实例失效的秒数 | 30 | - ### Consul 持久化 类型:Consul diff --git a/docs/document/content/user-manual/common-config/builtin-algorithm/metadata-repository.en.md b/docs/document/content/user-manual/common-config/builtin-algorithm/metadata-repository.en.md index 3a39940202906..d2ad3e30abadf 100644 --- a/docs/document/content/user-manual/common-config/builtin-algorithm/metadata-repository.en.md +++ b/docs/document/content/user-manual/common-config/builtin-algorithm/metadata-repository.en.md @@ -54,21 +54,6 @@ Attributes: | timeToLiveSeconds | long | Seconds of ephemeral data live | 30 | | connectionTimeout | long | Seconds of connection timeout | 30 | -### Nacos Repository - -Type: Nacos - -Mode: Cluster - -Attributes: - -| *Name* | *Type* | *Description* | *Default Value* | -|---------------------------|--------|---------------------------------------------------|-----------------| -| clusterIp | String | Unique identifier in cluster | Host IP | -| retryIntervalMilliseconds | long | Milliseconds of retry interval | 500 | -| maxRetries | int | Max retries for client to check data availability | 3 | -| timeToLiveSeconds | int | Seconds of ephemeral instance live | 30 | - ### Consul Repository Type: Consul diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/_index.cn.md b/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/_index.cn.md index c71734713decd..be62924a0bd7b 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/_index.cn.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/_index.cn.md @@ -46,7 +46,6 @@ ShardingSphere 默认情况下仅包含核心 SPI 的实现,在 Git Source 存 - 集群模式配置信息持久化定义 - `org.apache.shardingsphere:shardingsphere-cluster-mode-repository-zookeeper`,基于 Zookeeper 的持久化实现 - `org.apache.shardingsphere:shardingsphere-cluster-mode-repository-etcd`,基于 Etcd 的持久化实现 - - `org.apache.shardingsphere:shardingsphere-cluster-mode-repository-nacos`,基于 Nacos 的持久化实现 - `org.apache.shardingsphere:shardingsphere-cluster-mode-repository-consul`,基于 Consul 的持久化实现 - XA 分布式事务管理器 - `org.apache.shardingsphere:shardingsphere-transaction-xa-narayana`,基于 Narayana 的 XA 分布式事务管理器 diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/_index.en.md b/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/_index.en.md index f07d87c6b40f8..ddae142a7b5ce 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/_index.en.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/_index.en.md @@ -46,7 +46,6 @@ All optional plugins are listed below in the form of `groupId:artifactId`. - Cluster mode configuration information persistence definition - `org.apache.shardingsphere:shardingsphere-cluster-mode-repository-zookeeper`, Zookeeper based persistence - `org.apache.shardingsphere:shardingsphere-cluster-mode-repository-etcd`, Etcd based persistence - - `org.apache.shardingsphere:shardingsphere-cluster-mode-repository-nacos`, Nacos based persistence - `org.apache.shardingsphere:shardingsphere-cluster-mode-repository-consul`, Consul based persistence - XA transaction manager provider definition - `org.apache.shardingsphere:shardingsphere-transaction-xa-narayana`, XA distributed transaction manager based on Narayana diff --git a/docs/document/content/user-manual/shardingsphere-proxy/optional-plugins/_index.cn.md b/docs/document/content/user-manual/shardingsphere-proxy/optional-plugins/_index.cn.md index ad289661b7a40..7ebe065776752 100644 --- a/docs/document/content/user-manual/shardingsphere-proxy/optional-plugins/_index.cn.md +++ b/docs/document/content/user-manual/shardingsphere-proxy/optional-plugins/_index.cn.md @@ -33,7 +33,6 @@ ShardingSphere 默认情况下仅包含核心 SPI 的实现,在 Git Source 存 - 单机模式配置信息持久化定义 - `org.apache.shardingsphere:shardingsphere-standalone-mode-repository-jdbc`,基于 JDBC 的持久化 - 集群模式配置信息持久化定义 - - `org.apache.shardingsphere:shardingsphere-cluster-mode-repository-nacos`,基于 Nacos 的持久化实现 - `org.apache.shardingsphere:shardingsphere-cluster-mode-repository-consul`,基于 Consul 的持久化实现 - XA 分布式事务管理器 - `org.apache.shardingsphere:shardingsphere-transaction-xa-narayana`,基于 Narayana 的 XA 分布式事务管理器 diff --git a/docs/document/content/user-manual/shardingsphere-proxy/optional-plugins/_index.en.md b/docs/document/content/user-manual/shardingsphere-proxy/optional-plugins/_index.en.md index d10f6a21f1701..f2d85e42cdceb 100644 --- a/docs/document/content/user-manual/shardingsphere-proxy/optional-plugins/_index.en.md +++ b/docs/document/content/user-manual/shardingsphere-proxy/optional-plugins/_index.en.md @@ -33,7 +33,6 @@ All optional plugins are listed below in the form of `groupId:artifactId`. - Standalone mode configuration information persistence definition - `org.apache.shardingsphere:shardingsphere-standalone-mode-repository-jdbc`, JDBC based persistence - Cluster mode configuration information persistence definition - - `org.apache.shardingsphere:shardingsphere-cluster-mode-repository-nacos`, Nacos based persistence - `org.apache.shardingsphere:shardingsphere-cluster-mode-repository-consul`, Consul based persistence - XA transaction manager provider definition - `org.apache.shardingsphere:shardingsphere-transaction-xa-narayana`, XA distributed transaction manager based on Narayana diff --git a/examples/pom.xml b/examples/pom.xml index add9a8d68b6fc..4c4921f69fb41 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -117,11 +117,6 @@ shardingsphere-cluster-mode-repository-etcd ${project.version} - - org.apache.shardingsphere - shardingsphere-cluster-mode-repository-nacos - ${project.version} - org.apache.shardingsphere shardingsphere-infra-common diff --git a/examples/shardingsphere-jdbc-example-generator/src/main/resources/template/resources/registry.ftl b/examples/shardingsphere-jdbc-example-generator/src/main/resources/template/resources/registry.ftl index 3be5402d98f94..95ef824f7b5e4 100644 --- a/examples/shardingsphere-jdbc-example-generator/src/main/resources/template/resources/registry.ftl +++ b/examples/shardingsphere-jdbc-example-generator/src/main/resources/template/resources/registry.ftl @@ -16,14 +16,9 @@ # registry { - # file 、nacos 、eureka、redis、zk + # file 、eureka、redis、zk type = "file" - nacos { - serverAddr = "localhost" - namespace = "public" - cluster = "default" - } eureka { serviceUrl = "http://localhost:1001/eureka" application = "default" @@ -45,14 +40,9 @@ registry { } config { - # file、nacos 、apollo、zk + # file、apollo、zk type = "file" - nacos { - serverAddr = "localhost" - namespace = "public" - cluster = "default" - } apollo { app.id = "fescar-server" apollo.meta = "http://192.168.1.204:8801" diff --git a/kernel/transaction/type/base/seata-at/src/test/resources/registry.conf b/kernel/transaction/type/base/seata-at/src/test/resources/registry.conf index 3be5402d98f94..95ef824f7b5e4 100644 --- a/kernel/transaction/type/base/seata-at/src/test/resources/registry.conf +++ b/kernel/transaction/type/base/seata-at/src/test/resources/registry.conf @@ -16,14 +16,9 @@ # registry { - # file 、nacos 、eureka、redis、zk + # file 、eureka、redis、zk type = "file" - nacos { - serverAddr = "localhost" - namespace = "public" - cluster = "default" - } eureka { serviceUrl = "http://localhost:1001/eureka" application = "default" @@ -45,14 +40,9 @@ registry { } config { - # file、nacos 、apollo、zk + # file、apollo、zk type = "file" - nacos { - serverAddr = "localhost" - namespace = "public" - cluster = "default" - } apollo { app.id = "fescar-server" apollo.meta = "http://192.168.1.204:8801" diff --git a/mode/type/cluster/repository/provider/nacos/pom.xml b/mode/type/cluster/repository/provider/nacos/pom.xml deleted file mode 100644 index 15f90bd3c676a..0000000000000 --- a/mode/type/cluster/repository/provider/nacos/pom.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - 4.0.0 - - org.apache.shardingsphere - shardingsphere-cluster-mode-repository-provider - 5.4.1-SNAPSHOT - - shardingsphere-cluster-mode-repository-nacos - ${project.artifactId} - - - 1.4.2 - - - - - org.apache.shardingsphere - shardingsphere-cluster-mode-repository-api - ${project.version} - - - - org.apache.shardingsphere - shardingsphere-test-util - ${project.version} - test - - - - com.alibaba.nacos - nacos-client - ${nacos.version} - - - diff --git a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/NacosRepository.java b/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/NacosRepository.java deleted file mode 100644 index 0a076804be0f7..0000000000000 --- a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/NacosRepository.java +++ /dev/null @@ -1,363 +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.repository.cluster.nacos; - -import com.alibaba.nacos.api.exception.NacosException; -import com.alibaba.nacos.api.naming.NamingFactory; -import com.alibaba.nacos.api.naming.NamingService; -import com.alibaba.nacos.api.naming.PreservedMetadataKeys; -import com.alibaba.nacos.api.naming.pojo.Instance; -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import lombok.SneakyThrows; -import org.apache.shardingsphere.infra.instance.util.IpUtils; -import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; -import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration; -import org.apache.shardingsphere.mode.repository.cluster.exception.ClusterPersistRepositoryException; -import org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEventListener; -import org.apache.shardingsphere.mode.repository.cluster.lock.holder.DistributedLockHolder; -import org.apache.shardingsphere.mode.repository.cluster.nacos.entity.KeyValue; -import org.apache.shardingsphere.mode.repository.cluster.nacos.entity.ServiceController; -import org.apache.shardingsphere.mode.repository.cluster.nacos.entity.ServiceMetaData; -import org.apache.shardingsphere.mode.repository.cluster.nacos.listener.NamingEventListener; -import org.apache.shardingsphere.mode.repository.cluster.nacos.props.NacosProperties; -import org.apache.shardingsphere.mode.repository.cluster.nacos.props.NacosPropertyKey; -import org.apache.shardingsphere.mode.repository.cluster.nacos.util.NacosMetaDataUtils; - -import java.security.SecureRandom; -import java.util.Collection; -import java.util.Comparator; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Optional; -import java.util.Properties; -import java.util.Random; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * Registry repository of Nacos. - */ -public final class NacosRepository implements ClusterPersistRepository { - - private final Random random = new SecureRandom(); - - private NamingService client; - - private NacosProperties nacosProps; - - private ServiceController serviceController; - - @Override - public void init(final ClusterPersistRepositoryConfiguration config) { - nacosProps = new NacosProperties(config.getProps()); - client = createClient(config); - initServiceMetaData(); - } - - private NamingService createClient(final ClusterPersistRepositoryConfiguration config) { - Properties props = new Properties(); - props.setProperty("serverAddr", config.getServerLists()); - props.setProperty("namespace", config.getNamespace()); - props.setProperty("username", nacosProps.getValue(NacosPropertyKey.USERNAME)); - props.setProperty("password", nacosProps.getValue(NacosPropertyKey.PASSWORD)); - try { - return NamingFactory.createNamingService(props); - } catch (final NacosException ex) { - throw new ClusterPersistRepositoryException(ex); - } - } - - private void initServiceMetaData() { - try { - String clusterIp = nacosProps.getValue(NacosPropertyKey.CLUSTER_IP); - String ip = Strings.isNullOrEmpty(clusterIp) ? IpUtils.getIp() : clusterIp; - serviceController = new ServiceController(); - for (ServiceMetaData each : serviceController.getAllServices()) { - Integer port = client.getAllInstances(each.getServiceName(), false).stream() - .filter(instance -> ip.equals(instance.getIp())).map(Instance::getPort).max(Comparator.naturalOrder()).orElse(Integer.MIN_VALUE); - each.setIp(ip); - each.setPort(new AtomicInteger(port)); - } - } catch (final NacosException ex) { - throw new ClusterPersistRepositoryException(ex); - } - } - - @Override - public void persistEphemeral(final String key, final String value) { - try { - Preconditions.checkNotNull(value, "Value can not be null"); - if (!findExistedInstance(key, true).isEmpty()) { - delete(key); - } - put(key, value, true); - } catch (final NacosException ex) { - throw new ClusterPersistRepositoryException(ex); - } - } - - @Override - public void persistExclusiveEphemeral(final String key, final String value) { - try { - Preconditions.checkState(findExistedInstance(key, true).isEmpty(), "Key `%s` already exists", key); - put(key, value, true); - } catch (final NacosException ex) { - throw new ClusterPersistRepositoryException(ex); - } - } - - @Override - public DistributedLockHolder getDistributedLockHolder() { - return null; - } - - @Override - public void watch(final String key, final DataChangedEventListener listener) { - try { - for (ServiceMetaData each : serviceController.getAllServices()) { - NamingEventListener eventListener = each.getListener(); - if (null != eventListener) { - eventListener.put(key, listener); - return; - } - eventListener = new NamingEventListener(); - eventListener.put(key, listener); - each.setListener(eventListener); - client.subscribe(each.getServiceName(), eventListener); - } - } catch (final NacosException ex) { - throw new ClusterPersistRepositoryException(ex); - } - } - - @Override - public String getDirectly(final String key) { - try { - for (ServiceMetaData each : serviceController.getAllServices()) { - Optional instance = findExistedInstance(key, each.isEphemeral()).stream().max(Comparator.comparing(NacosMetaDataUtils::getTimestamp)); - if (instance.isPresent()) { - return NacosMetaDataUtils.getValue(instance.get()); - } - } - return null; - } catch (final NacosException ex) { - throw new ClusterPersistRepositoryException(ex); - } - } - - @Override - public List getChildrenKeys(final String key) { - try { - Stream concatKeys = Stream.empty(); - for (ServiceMetaData each : serviceController.getAllServices()) { - Stream keys = findExistedInstance(each.isEphemeral()).stream() - .map(instance -> { - String fullPath = NacosMetaDataUtils.getKey(instance); - if (fullPath.startsWith(key + PATH_SEPARATOR)) { - String pathWithoutPrefix = fullPath.substring((key + PATH_SEPARATOR).length()); - return pathWithoutPrefix.contains(PATH_SEPARATOR) ? pathWithoutPrefix.substring(0, pathWithoutPrefix.indexOf(PATH_SEPARATOR)) : pathWithoutPrefix; - } - return null; - }).filter(Objects::nonNull); - concatKeys = Stream.concat(concatKeys, keys); - } - return concatKeys.distinct().sorted(Comparator.reverseOrder()).collect(Collectors.toList()); - } catch (final NacosException ex) { - throw new ClusterPersistRepositoryException(ex); - } - } - - @Override - public boolean isExisted(final String key) { - return false; - } - - @Override - public void persist(final String key, final String value) { - try { - Preconditions.checkNotNull(value, "Value can not be null"); - Optional instance = findExistedInstance(key, false).stream().max(Comparator.comparing(NacosMetaDataUtils::getTimestamp)); - if (instance.isPresent()) { - update(instance.get(), value); - } else { - put(key, value, false); - } - } catch (final NacosException ex) { - throw new ClusterPersistRepositoryException(ex); - } - } - - @Override - public void update(final String key, final String value) { - // TODO - } - - private void update(final Instance instance, final String value) throws NacosException { - Map metaDataMap = instance.getMetadata(); - String key = NacosMetaDataUtils.getKey(instance); - metaDataMap.put(key, value); - metaDataMap.put(NacosMetaDataUtils.UTC_ZONE_OFFSET.toString(), String.valueOf(NacosMetaDataUtils.getTimestamp())); - instance.setMetadata(metaDataMap); - ServiceMetaData persistentService = serviceController.getPersistentService(); - client.registerInstance(persistentService.getServiceName(), instance); - Collection keyValues = new LinkedList<>(); - keyValues.add(new KeyValue(key, value, instance.isEphemeral())); - waitValue(keyValues); - } - - private void put(final String key, final String value, final boolean ephemeral) throws NacosException { - final Collection keyValues = buildParentPath(key); - ServiceMetaData serviceMetaData = serviceController.getService(ephemeral); - Instance instance = new Instance(); - instance.setIp(serviceMetaData.getIp()); - instance.setPort(serviceMetaData.getPort()); - instance.setEphemeral(ephemeral); - Map metadataMap = new HashMap<>(5, 1F); - if (ephemeral) { - fillEphemeralMetaData(metadataMap); - } - metadataMap.put(key, value); - metadataMap.put(NacosMetaDataUtils.UTC_ZONE_OFFSET.toString(), String.valueOf(NacosMetaDataUtils.getTimestamp())); - instance.setMetadata(metadataMap); - client.registerInstance(serviceMetaData.getServiceName(), instance); - keyValues.add(new KeyValue(key, value, ephemeral)); - waitValue(keyValues); - } - - private Collection buildParentPath(final String key) throws NacosException { - Collection result = new LinkedList<>(); - StringBuilder parentPath = new StringBuilder(); - String[] partPath = key.split(PATH_SEPARATOR); - for (int index = 1; index < partPath.length - 1; index++) { - String path = parentPath.append(PATH_SEPARATOR).append(partPath[index]).toString(); - if (findExistedInstance(path, false).isEmpty()) { - result.addAll(build(path)); - } - } - return result; - } - - private Collection build(final String key) throws NacosException { - Collection result = new LinkedList<>(); - if (findExistedInstance(key, false).isEmpty()) { - Instance instance = new Instance(); - ServiceMetaData persistentService = serviceController.getPersistentService(); - instance.setIp(persistentService.getIp()); - instance.setPort(persistentService.getPort()); - instance.setEphemeral(false); - Map metaDataMap = new HashMap<>(2, 1F); - metaDataMap.put(key, ""); - metaDataMap.put(NacosMetaDataUtils.UTC_ZONE_OFFSET.toString(), String.valueOf(NacosMetaDataUtils.getTimestamp())); - instance.setMetadata(metaDataMap); - client.registerInstance(persistentService.getServiceName(), instance); - result.add(new KeyValue(key, "", false)); - } - return result; - } - - private void fillEphemeralMetaData(final Map metaDataMap) { - int timeToLiveSeconds = nacosProps.getValue(NacosPropertyKey.TIME_TO_LIVE_SECONDS); - metaDataMap.put(PreservedMetadataKeys.HEART_BEAT_INTERVAL, String.valueOf(timeToLiveSeconds * 1000 / 3)); - metaDataMap.put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT, String.valueOf(timeToLiveSeconds * 1000 * 2 / 3)); - metaDataMap.put(PreservedMetadataKeys.IP_DELETE_TIMEOUT, String.valueOf(timeToLiveSeconds * 1000)); - } - - @Override - public void delete(final String key) { - try { - for (ServiceMetaData each : serviceController.getAllServices()) { - Collection instances = findExistedInstance(each.isEphemeral()).stream() - .filter(instance -> { - String fullPath = NacosMetaDataUtils.getKey(instance); - return fullPath.startsWith(key + PATH_SEPARATOR) || key.equals(fullPath); - }) - .sorted(Comparator.comparing(NacosMetaDataUtils::getKey).reversed()).collect(Collectors.toList()); - Collection keyValues = new LinkedList<>(); - for (Instance instance : instances) { - client.deregisterInstance(each.getServiceName(), instance); - keyValues.add(new KeyValue(NacosMetaDataUtils.getKey(instance), null, each.isEphemeral())); - } - waitValue(keyValues); - } - } catch (final NacosException ex) { - throw new ClusterPersistRepositoryException(ex); - } - } - - private Collection findExistedInstance(final String key, final boolean ephemeral) throws NacosException { - return client.getAllInstances(serviceController.getService(ephemeral).getServiceName(), false).stream() - .filter(each -> Objects.equals(key, NacosMetaDataUtils.getKey(each))).collect(Collectors.toList()); - } - - private Collection findExistedInstance(final boolean ephemeral) throws NacosException { - return client.getAllInstances(serviceController.getService(ephemeral).getServiceName(), false); - } - - @SneakyThrows(InterruptedException.class) - private void waitValue(final Collection keyValues) throws NacosException { - if (!isAvailable(keyValues)) { - long retryIntervalMilliseconds = nacosProps.getValue(NacosPropertyKey.RETRY_INTERVAL_MILLISECONDS); - int maxRetries = nacosProps.getValue(NacosPropertyKey.MAX_RETRIES); - for (int retry = 0; retry < maxRetries; retry++) { - Thread.sleep(getSleepTimeMs(retry, retryIntervalMilliseconds)); - if (isAvailable(keyValues)) { - return; - } - } - throw new NacosException(NacosException.RESOURCE_NOT_FOUND, "Wait value availability timeout exceeded"); - } - } - - private boolean isAvailable(final Collection keyValues) throws NacosException { - Map> keyValueMap = keyValues.stream().collect(Collectors.groupingBy(KeyValue::isEphemeral)); - for (Entry> entry : keyValueMap.entrySet()) { - ServiceMetaData service = serviceController.getService(entry.getKey()); - Map> instanceMap = client.getAllInstances(service.getServiceName(), false).stream().collect(Collectors.groupingBy(NacosMetaDataUtils::getKey)); - keyValues.removeIf(keyValue -> { - String key = keyValue.getKey(); - String value = keyValue.getValue(); - return instanceMap.containsKey(key) ? instanceMap.get(key).stream().anyMatch(each -> Objects.equals(NacosMetaDataUtils.getValue(each), value)) : null == value; - }); - } - return keyValues.isEmpty(); - } - - private long getSleepTimeMs(final int retryCount, final long baseSleepTimeMs) { - return baseSleepTimeMs * Math.max(1, random.nextInt(1 << (retryCount + 1))); - } - - @Override - public void close() { - try { - client.shutDown(); - } catch (final NacosException ex) { - throw new ClusterPersistRepositoryException(ex); - } - } - - @Override - public String getType() { - return "Nacos"; - } -} diff --git a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/entity/KeyValue.java b/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/entity/KeyValue.java deleted file mode 100644 index a11b5cbc526b9..0000000000000 --- a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/entity/KeyValue.java +++ /dev/null @@ -1,35 +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.repository.cluster.nacos.entity; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -/** - * Key value. - */ -@RequiredArgsConstructor -@Getter -public final class KeyValue { - - private final String key; - - private final String value; - - private final boolean ephemeral; -} diff --git a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/entity/ServiceController.java b/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/entity/ServiceController.java deleted file mode 100644 index 5b613961ecfbf..0000000000000 --- a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/entity/ServiceController.java +++ /dev/null @@ -1,63 +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.repository.cluster.nacos.entity; - -import lombok.Getter; - -import java.util.Collection; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * Service controller. - */ -public final class ServiceController { - - private static final String PERSISTENT_SERVICE_NAME = "PERSISTENT"; - - private static final String EPHEMERAL_SERVICE_NAME = "EPHEMERAL"; - - @Getter - private final ServiceMetaData persistentService = new ServiceMetaData(PERSISTENT_SERVICE_NAME, false); - - @Getter - private final ServiceMetaData ephemeralService = new ServiceMetaData(EPHEMERAL_SERVICE_NAME, true); - - private final Map serviceMap = Stream.of(persistentService, ephemeralService).collect(Collectors.toMap(ServiceMetaData::isEphemeral, Function.identity())); - - /** - * Get all services. - * - * @return all services - */ - public Collection getAllServices() { - return serviceMap.values(); - } - - /** - * Get service. - * - * @param ephemeral is ephemeral service - * @return ephemeral service or persistent service - */ - public ServiceMetaData getService(final boolean ephemeral) { - return serviceMap.get(ephemeral); - } -} diff --git a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/entity/ServiceMetaData.java b/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/entity/ServiceMetaData.java deleted file mode 100644 index 75314a59b292e..0000000000000 --- a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/entity/ServiceMetaData.java +++ /dev/null @@ -1,56 +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.repository.cluster.nacos.entity; - -import com.google.common.base.Preconditions; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; -import org.apache.shardingsphere.mode.repository.cluster.nacos.listener.NamingEventListener; - -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Service meta data. - */ -@RequiredArgsConstructor -@Getter -@Setter -public final class ServiceMetaData { - - private final String serviceName; - - private String ip; - - private AtomicInteger port; - - private NamingEventListener listener; - - private final boolean ephemeral; - - /** - * Get incremental port. - * - * @return incremental port - */ - public int getPort() { - int result = port.incrementAndGet(); - Preconditions.checkState(Integer.MIN_VALUE != result, "Specified cluster ip exceeded the maximum number of persisting"); - return result; - } -} diff --git a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/listener/NamingEventListener.java b/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/listener/NamingEventListener.java deleted file mode 100644 index 09516f5bce07c..0000000000000 --- a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/listener/NamingEventListener.java +++ /dev/null @@ -1,132 +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.repository.cluster.nacos.listener; - -import com.alibaba.nacos.api.naming.listener.Event; -import com.alibaba.nacos.api.naming.listener.EventListener; -import com.alibaba.nacos.api.naming.listener.NamingEvent; -import com.alibaba.nacos.api.naming.pojo.Instance; -import org.apache.shardingsphere.mode.event.DataChangedEvent; -import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; -import org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEventListener; -import org.apache.shardingsphere.mode.repository.cluster.nacos.util.NacosMetaDataUtils; - -import java.util.Collection; -import java.util.Comparator; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; - -/** - * Naming event listener. - */ -public final class NamingEventListener implements EventListener { - - private Map preInstances = new HashMap<>(); - - private final Map prefixListenerMap = new HashMap<>(); - - @Override - public void onEvent(final Event event) { - if (!(event instanceof NamingEvent)) { - return; - } - NamingEvent namingEvent = (NamingEvent) event; - Collection instances = namingEvent.getInstances().stream().sorted(Comparator.comparing(NacosMetaDataUtils::getKey)).collect(Collectors.toList()); - Collection watchDataList = new LinkedList<>(); - synchronized (this) { - instances.forEach(instance -> prefixListenerMap.forEach((prefixPath, listener) -> { - String key = NacosMetaDataUtils.getKey(instance); - if (key.startsWith(prefixPath)) { - Instance preInstance = preInstances.remove(key); - WatchData watchData = new WatchData(key, preInstance, instance, listener); - watchDataList.add(watchData); - } - })); - preInstances.values().stream().sorted(Comparator.comparing(NacosMetaDataUtils::getKey).reversed()).forEach(instance -> prefixListenerMap.forEach((prefixPath, listener) -> { - String key = NacosMetaDataUtils.getKey(instance); - if (key.startsWith(prefixPath)) { - WatchData watchData = new WatchData(key, instance, null, listener); - watchDataList.add(watchData); - } - })); - watchDataList.forEach(this::watch); - setPreInstances(instances); - } - } - - private void watch(final WatchData watchData) { - String key = watchData.getKey(); - Instance preInstance = watchData.getPreInstance(); - Instance instance = watchData.getInstance(); - DataChangedEventListener listener = watchData.getListener(); - Type changedType = getEventChangedType(preInstance, instance); - switch (changedType) { - case ADDED: - case UPDATED: - listener.onChange(new DataChangedEvent(key, NacosMetaDataUtils.getValue(instance), changedType)); - break; - case DELETED: - listener.onChange(new DataChangedEvent(key, NacosMetaDataUtils.getValue(preInstance), changedType)); - break; - default: - } - } - - private Type getEventChangedType(final Instance preInstance, final Instance instance) { - if (null == preInstance && null != instance) { - return DataChangedEvent.Type.ADDED; - } - if (null != preInstance && null != instance && NacosMetaDataUtils.getTimestamp(preInstance) != NacosMetaDataUtils.getTimestamp(instance)) { - return DataChangedEvent.Type.UPDATED; - } - if (null != preInstance && null == instance) { - return DataChangedEvent.Type.DELETED; - } - return DataChangedEvent.Type.IGNORED; - } - - /** - * Update pre instances. - * - * @param instances instances - */ - public void setPreInstances(final Collection instances) { - preInstances = instances.stream().filter(instance -> { - for (String each : prefixListenerMap.keySet()) { - if (NacosMetaDataUtils.getKey(instance).startsWith(each)) { - return true; - } - } - return false; - }).collect(Collectors.toMap(NacosMetaDataUtils::getKey, Function.identity(), - (oldValue, currentValue) -> NacosMetaDataUtils.getTimestamp(oldValue) > NacosMetaDataUtils.getTimestamp(currentValue) ? oldValue : currentValue)); - } - - /** - * Put prefix path and listener. - * - * @param prefixPath prefix path - * @param listener listener - */ - public synchronized void put(final String prefixPath, final DataChangedEventListener listener) { - prefixListenerMap.put(prefixPath, listener); - } -} diff --git a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/listener/WatchData.java b/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/listener/WatchData.java deleted file mode 100644 index 939bb037a9c3e..0000000000000 --- a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/listener/WatchData.java +++ /dev/null @@ -1,39 +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.repository.cluster.nacos.listener; - -import com.alibaba.nacos.api.naming.pojo.Instance; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEventListener; - -/** - * Watch data. - */ -@Getter -@RequiredArgsConstructor -public final class WatchData { - - private final String key; - - private final Instance preInstance; - - private final Instance instance; - - private final DataChangedEventListener listener; -} diff --git a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosProperties.java b/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosProperties.java deleted file mode 100644 index 5b4e3a5b7e64c..0000000000000 --- a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosProperties.java +++ /dev/null @@ -1,32 +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.repository.cluster.nacos.props; - -import org.apache.shardingsphere.infra.props.TypedProperties; - -import java.util.Properties; - -/** - * Typed properties of Nacos. - */ -public final class NacosProperties extends TypedProperties { - - public NacosProperties(final Properties props) { - super(NacosPropertyKey.class, props); - } -} diff --git a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosPropertyKey.java b/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosPropertyKey.java deleted file mode 100644 index fbec54ac9eed5..0000000000000 --- a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosPropertyKey.java +++ /dev/null @@ -1,66 +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.repository.cluster.nacos.props; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.infra.props.TypedPropertyKey; - -/** - * Typed property key of Nacos. - */ -@RequiredArgsConstructor -@Getter -public enum NacosPropertyKey implements TypedPropertyKey { - - /** - * Cluster ip. - */ - CLUSTER_IP("clusterIp", "", String.class), - - /** - * Retry interval milliseconds when checking whether value is available. - */ - RETRY_INTERVAL_MILLISECONDS("retryIntervalMilliseconds", String.valueOf(500), long.class), - - /** - * Max Retry times when checking whether value is available. - */ - MAX_RETRIES("maxRetries", String.valueOf(3), int.class), - - /** - * Time to live seconds. - */ - TIME_TO_LIVE_SECONDS("timeToLiveSeconds", String.valueOf(30), int.class), - - /** - * Username. - */ - USERNAME("username", "", String.class), - - /** - * Password. - */ - PASSWORD("password", "", String.class); - - private final String key; - - private final String defaultValue; - - private final Class type; -} diff --git a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/util/NacosMetaDataUtils.java b/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/util/NacosMetaDataUtils.java deleted file mode 100644 index c56447c8427e6..0000000000000 --- a/mode/type/cluster/repository/provider/nacos/src/main/java/org/apache/shardingsphere/mode/repository/cluster/nacos/util/NacosMetaDataUtils.java +++ /dev/null @@ -1,82 +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.repository.cluster.nacos.util; - -import com.alibaba.nacos.api.exception.NacosException; -import com.alibaba.nacos.api.naming.PreservedMetadataKeys; -import com.alibaba.nacos.api.naming.pojo.Instance; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import lombok.SneakyThrows; - -import java.time.LocalDateTime; -import java.time.ZoneOffset; - -/** - * Nacos meta data utility class. - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class NacosMetaDataUtils { - - public static final ZoneOffset UTC_ZONE_OFFSET = ZoneOffset.of("+8"); - - /** - * Get timestamp. - * - * @param instance instance - * @return timestamp - */ - public static long getTimestamp(final Instance instance) { - return Long.parseLong(instance.getMetadata().get(UTC_ZONE_OFFSET.toString())); - } - - /** - * Get timestamp. - * - * @return timeStamp - */ - public static long getTimestamp() { - return LocalDateTime.now().toInstant(UTC_ZONE_OFFSET).toEpochMilli(); - } - - /** - * Get value. - * - * @param instance instance - * @return value - */ - public static String getValue(final Instance instance) { - return instance.getMetadata().get(getKey(instance)); - } - - /** - * Get key. - * - * @param instance instance - * @return key - */ - @SneakyThrows(NacosException.class) - public static String getKey(final Instance instance) { - return instance.getMetadata().keySet().stream() - .filter(entryKey -> !PreservedMetadataKeys.HEART_BEAT_INTERVAL.equals(entryKey) - && !PreservedMetadataKeys.HEART_BEAT_TIMEOUT.equals(entryKey) - && !PreservedMetadataKeys.IP_DELETE_TIMEOUT.equals(entryKey) - && !UTC_ZONE_OFFSET.toString().equals(entryKey)) - .findFirst().orElseThrow(() -> new NacosException(NacosException.RESOURCE_NOT_FOUND, "Failed to find key ")); - } -} diff --git a/mode/type/cluster/repository/provider/nacos/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository b/mode/type/cluster/repository/provider/nacos/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository deleted file mode 100644 index 7ab9d965fcb9e..0000000000000 --- a/mode/type/cluster/repository/provider/nacos/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository +++ /dev/null @@ -1,18 +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. -# - -org.apache.shardingsphere.mode.repository.cluster.nacos.NacosRepository diff --git a/mode/type/cluster/repository/provider/nacos/src/test/java/org/apache/shardingsphere/mode/repository/cluster/nacos/NacosRepositoryTest.java b/mode/type/cluster/repository/provider/nacos/src/test/java/org/apache/shardingsphere/mode/repository/cluster/nacos/NacosRepositoryTest.java deleted file mode 100644 index efccc41fb4e2f..0000000000000 --- a/mode/type/cluster/repository/provider/nacos/src/test/java/org/apache/shardingsphere/mode/repository/cluster/nacos/NacosRepositoryTest.java +++ /dev/null @@ -1,377 +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.repository.cluster.nacos; - -import com.alibaba.nacos.api.exception.NacosException; -import com.alibaba.nacos.api.naming.NamingService; -import com.alibaba.nacos.api.naming.PreservedMetadataKeys; -import com.alibaba.nacos.api.naming.listener.Event; -import com.alibaba.nacos.api.naming.listener.EventListener; -import com.alibaba.nacos.api.naming.listener.NamingEvent; -import com.alibaba.nacos.api.naming.pojo.Instance; -import com.google.common.util.concurrent.SettableFuture; -import org.apache.shardingsphere.mode.event.DataChangedEvent; -import org.apache.shardingsphere.mode.repository.cluster.exception.ClusterPersistRepositoryException; -import org.apache.shardingsphere.mode.repository.cluster.nacos.entity.ServiceController; -import org.apache.shardingsphere.mode.repository.cluster.nacos.entity.ServiceMetaData; -import org.apache.shardingsphere.mode.repository.cluster.nacos.props.NacosProperties; -import org.apache.shardingsphere.mode.repository.cluster.nacos.props.NacosPropertyKey; -import org.apache.shardingsphere.mode.repository.cluster.nacos.util.NacosMetaDataUtils; -import org.apache.shardingsphere.mode.spi.PersistRepository; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.AdditionalAnswers; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.internal.configuration.plugins.Plugins; -import org.mockito.junit.jupiter.MockitoExtension; -import org.mockito.plugins.MemberAccessor; -import org.mockito.stubbing.VoidAnswer2; - -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Properties; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -@ExtendWith(MockitoExtension.class) -class NacosRepositoryTest { - - private static final NacosRepository REPOSITORY = new NacosRepository(); - - @Mock - private NamingService client; - - private ServiceController serviceController; - - @BeforeEach - void initClient() throws ReflectiveOperationException { - MemberAccessor accessor = Plugins.getMemberAccessor(); - accessor.set(REPOSITORY.getClass().getDeclaredField("nacosProps"), REPOSITORY, new NacosProperties(new Properties())); - accessor.set(REPOSITORY.getClass().getDeclaredField("client"), REPOSITORY, client); - accessor.invoke(REPOSITORY.getClass().getDeclaredMethod("initServiceMetaData"), REPOSITORY); - serviceController = (ServiceController) accessor.get(REPOSITORY.getClass().getDeclaredField("serviceController"), REPOSITORY); - } - - @Test - void assertGetLatestKey() throws NacosException { - int total = 2; - String key = "/test/children/keys/persistent/1"; - List instances = new LinkedList<>(); - for (int count = 1; count <= total; count++) { - Instance instance = new Instance(); - Map metaDataMap = new HashMap<>(2, 1F); - metaDataMap.put(key, "value" + count); - metaDataMap.put(NacosMetaDataUtils.UTC_ZONE_OFFSET.toString(), String.valueOf(count)); - instance.setMetadata(metaDataMap); - instances.add(instance); - } - ServiceMetaData persistentService = serviceController.getPersistentService(); - when(client.getAllInstances(persistentService.getServiceName(), false)).thenReturn(instances); - String value = REPOSITORY.getDirectly(key); - assertThat(value, is("value2")); - } - - @Test - void assertGetChildrenKeys() throws NacosException { - Instance instance = new Instance(); - String key = "/test/children/keys/persistent/0"; - instance.setMetadata(Collections.singletonMap(key, "value0")); - ServiceMetaData persistentService = serviceController.getPersistentService(); - when(client.getAllInstances(persistentService.getServiceName(), false)).thenReturn(Collections.singletonList(instance)); - instance = new Instance(); - key = "/test/children/keys/ephemeral/0"; - instance.setMetadata(Collections.singletonMap(key, "value0")); - ServiceMetaData ephemeralService = serviceController.getEphemeralService(); - when(client.getAllInstances(ephemeralService.getServiceName(), false)).thenReturn(Collections.singletonList(instance)); - List childrenKeys = REPOSITORY.getChildrenKeys("/test/children/keys"); - assertThat(childrenKeys.size(), is(2)); - assertThat(childrenKeys.get(0), is("persistent")); - assertThat(childrenKeys.get(1), is("ephemeral")); - } - - @Test - void assertPersistNotExistKey() throws NacosException { - String key = "/test/children/keys/persistent/1"; - doAnswer(AdditionalAnswers.answerVoid(getRegisterInstanceAnswer())).when(client).registerInstance(anyString(), any(Instance.class)); - REPOSITORY.persist(key, "value4"); - ArgumentCaptor instanceArgumentCaptor = ArgumentCaptor.forClass(Instance.class); - ArgumentCaptor stringArgumentCaptor = ArgumentCaptor.forClass(String.class); - verify(client, times(5)).registerInstance(stringArgumentCaptor.capture(), instanceArgumentCaptor.capture()); - Instance registerInstance = instanceArgumentCaptor.getValue(); - String registerType = stringArgumentCaptor.getValue(); - ServiceMetaData persistentService = serviceController.getPersistentService(); - assertThat(registerType, is(persistentService.getServiceName())); - assertThat(registerInstance.isEphemeral(), is(false)); - assertThat(NacosMetaDataUtils.getValue(registerInstance), is("value4")); - } - - @Test - void assertPersistExistKey() throws NacosException { - String ip = "127.0.0.1"; - Instance instance = new Instance(); - instance.setIp(ip); - instance.setEphemeral(false); - String key = "/test/children/keys/persistent/0"; - instance.setMetadata(new HashMap<>(Collections.singletonMap(key, "value0"))); - List instances = new LinkedList<>(); - buildParentPath(key, instances); - instances.add(instance); - ServiceMetaData persistentService = serviceController.getPersistentService(); - when(client.getAllInstances(persistentService.getServiceName(), false)).thenReturn(instances); - doAnswer(AdditionalAnswers.answerVoid(getRegisterInstanceAnswer())).when(client).registerInstance(anyString(), any(Instance.class)); - REPOSITORY.persist(key, "value4"); - ArgumentCaptor instanceArgumentCaptor = ArgumentCaptor.forClass(Instance.class); - ArgumentCaptor stringArgumentCaptor = ArgumentCaptor.forClass(String.class); - verify(client).registerInstance(stringArgumentCaptor.capture(), instanceArgumentCaptor.capture()); - Instance registerInstance = instanceArgumentCaptor.getValue(); - String registerType = stringArgumentCaptor.getValue(); - assertThat(registerType, is(persistentService.getServiceName())); - assertThat(registerInstance.getIp(), is(ip)); - assertThat(registerInstance.isEphemeral(), is(false)); - assertThat(NacosMetaDataUtils.getValue(registerInstance), is("value4")); - } - - @Test - void assertPersistEphemeralExistKey() throws NacosException { - final String key = "/test/children/keys/ephemeral/1"; - final Instance instance = new Instance(); - instance.setEphemeral(true); - Map metaDataMap = new HashMap<>(4, 1F); - metaDataMap.put(PreservedMetadataKeys.HEART_BEAT_INTERVAL, String.valueOf(2000)); - metaDataMap.put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT, String.valueOf(4000)); - metaDataMap.put(PreservedMetadataKeys.IP_DELETE_TIMEOUT, String.valueOf(6000)); - metaDataMap.put(key, "value0"); - instance.setMetadata(metaDataMap); - List instances = new LinkedList<>(); - buildParentPath(key, instances); - ServiceMetaData persistentService = serviceController.getPersistentService(); - when(client.getAllInstances(persistentService.getServiceName(), false)).thenReturn(instances); - instances = new LinkedList<>(); - instances.add(instance); - ServiceMetaData ephemeralService = serviceController.getEphemeralService(); - when(client.getAllInstances(ephemeralService.getServiceName(), false)).thenReturn(instances); - doAnswer(AdditionalAnswers.answerVoid(getDeregisterInstanceAnswer())).when(client).deregisterInstance(anyString(), any(Instance.class)); - doAnswer(AdditionalAnswers.answerVoid(getRegisterInstanceAnswer())).when(client).registerInstance(anyString(), any(Instance.class)); - REPOSITORY.persistEphemeral(key, "value4"); - ArgumentCaptor instanceArgumentCaptor = ArgumentCaptor.forClass(Instance.class); - ArgumentCaptor stringArgumentCaptor = ArgumentCaptor.forClass(String.class); - verify(client).deregisterInstance(anyString(), any(Instance.class)); - verify(client).registerInstance(stringArgumentCaptor.capture(), instanceArgumentCaptor.capture()); - Instance registerInstance = instanceArgumentCaptor.getValue(); - String registerType = stringArgumentCaptor.getValue(); - assertThat(registerType, is(ephemeralService.getServiceName())); - assertThat(registerInstance.isEphemeral(), is(true)); - assertThat(NacosMetaDataUtils.getValue(registerInstance), is("value4")); - Map metaData = registerInstance.getMetadata(); - long timeToLiveSeconds = Long.parseLong(NacosPropertyKey.TIME_TO_LIVE_SECONDS.getDefaultValue()); - assertThat(metaData.get(PreservedMetadataKeys.HEART_BEAT_INTERVAL), is(String.valueOf(timeToLiveSeconds * 1000 / 3))); - assertThat(metaData.get(PreservedMetadataKeys.HEART_BEAT_TIMEOUT), is(String.valueOf(timeToLiveSeconds * 1000 * 2 / 3))); - assertThat(metaData.get(PreservedMetadataKeys.IP_DELETE_TIMEOUT), is(String.valueOf(timeToLiveSeconds * 1000))); - } - - private void buildParentPath(final String key, final List instances) { - StringBuilder parentPath = new StringBuilder(); - final String[] partPath = key.split(PersistRepository.PATH_SEPARATOR); - for (int index = 1; index < partPath.length - 1; index++) { - parentPath.append(PersistRepository.PATH_SEPARATOR); - parentPath.append(partPath[index]); - String path = parentPath.toString(); - Instance instance = new Instance(); - instance.setEphemeral(false); - instance.setMetadata(Collections.singletonMap(path, "")); - instances.add(instance); - } - } - - @Test - void assertPersistEphemeralNotExistKey() throws NacosException { - String key = "/test/children/keys/ephemeral/0"; - doAnswer(AdditionalAnswers.answerVoid(getRegisterInstanceAnswer())).when(client).registerInstance(anyString(), any(Instance.class)); - REPOSITORY.persistEphemeral(key, "value0"); - ArgumentCaptor instanceArgumentCaptor = ArgumentCaptor.forClass(Instance.class); - ArgumentCaptor stringArgumentCaptor = ArgumentCaptor.forClass(String.class); - verify(client, times(5)).registerInstance(stringArgumentCaptor.capture(), instanceArgumentCaptor.capture()); - Instance registerInstance = instanceArgumentCaptor.getValue(); - String registerType = stringArgumentCaptor.getValue(); - ServiceMetaData ephemeralService = serviceController.getEphemeralService(); - assertThat(registerType, is(ephemeralService.getServiceName())); - assertThat(registerInstance.isEphemeral(), is(true)); - assertThat(NacosMetaDataUtils.getValue(registerInstance), is("value0")); - Map metaData = registerInstance.getMetadata(); - long timeToLiveSeconds = Long.parseLong(NacosPropertyKey.TIME_TO_LIVE_SECONDS.getDefaultValue()); - assertThat(metaData.get(PreservedMetadataKeys.HEART_BEAT_INTERVAL), is(String.valueOf(timeToLiveSeconds * 1000 / 3))); - assertThat(metaData.get(PreservedMetadataKeys.HEART_BEAT_TIMEOUT), is(String.valueOf(timeToLiveSeconds * 1000 * 2 / 3))); - assertThat(metaData.get(PreservedMetadataKeys.IP_DELETE_TIMEOUT), is(String.valueOf(timeToLiveSeconds * 1000))); - } - - @Test - void assertDeleteExistKey() throws NacosException { - int total = 3; - List instances = new LinkedList<>(); - for (int count = 1; count <= total; count++) { - String key = "/test/children/keys/ephemeral/" + count; - Instance instance = new Instance(); - instance.setEphemeral(true); - instance.setMetadata(Collections.singletonMap(key, "value" + count)); - instances.add(instance); - } - ServiceMetaData ephemeralService = serviceController.getEphemeralService(); - when(client.getAllInstances(ephemeralService.getServiceName(), false)).thenReturn(instances); - instances = new LinkedList<>(); - String key = "/test/children/keys/persistent/0"; - Instance instance = new Instance(); - instance.setEphemeral(false); - instance.setMetadata(Collections.singletonMap(key, "value0")); - instances.add(instance); - ServiceMetaData persistentService = serviceController.getPersistentService(); - when(client.getAllInstances(persistentService.getServiceName(), false)).thenReturn(instances); - doAnswer(AdditionalAnswers.answerVoid(getDeregisterInstanceAnswer())).when(client).deregisterInstance(anyString(), any(Instance.class)); - REPOSITORY.delete("/test/children/keys"); - verify(client, times(4)).deregisterInstance(anyString(), any(Instance.class)); - } - - @Test - void assertDeleteNotExistKey() throws NacosException { - REPOSITORY.delete("/test/children/keys/persistent/1"); - verify(client, times(0)).deregisterInstance(anyString(), any(Instance.class)); - } - - @Test - void assertWatchAdded() throws NacosException, ExecutionException, InterruptedException { - ServiceMetaData ephemeralService = serviceController.getEphemeralService(); - ephemeralService.setListener(null); - String key = "key/key"; - String value = "value2"; - Instance instance = new Instance(); - instance.setMetadata(Collections.singletonMap(key, value)); - Event event = new NamingEvent(ephemeralService.getServiceName(), Collections.singletonList(instance)); - doAnswer(AdditionalAnswers.answerVoid(getListenerAnswer(null, event))).when(client).subscribe(anyString(), any(EventListener.class)); - SettableFuture settableFuture = SettableFuture.create(); - REPOSITORY.watch(key, settableFuture::set); - DataChangedEvent dataChangedEvent = settableFuture.get(); - assertThat(dataChangedEvent.getType(), is(DataChangedEvent.Type.ADDED)); - assertThat(dataChangedEvent.getKey(), is(key)); - assertThat(dataChangedEvent.getValue(), is(value)); - } - - @Test - void assertWatchUpdate() throws NacosException, ExecutionException, InterruptedException { - ServiceMetaData persistentService = serviceController.getPersistentService(); - persistentService.setListener(null); - String key = "key/key"; - long epochMilliseconds = NacosMetaDataUtils.getTimestamp(); - Instance preInstance = new Instance(); - Map metaDataMap = new HashMap<>(); - metaDataMap.put(key, "value1"); - metaDataMap.put(NacosMetaDataUtils.UTC_ZONE_OFFSET.toString(), String.valueOf(epochMilliseconds)); - preInstance.setMetadata(metaDataMap); - final Instance instance = new Instance(); - metaDataMap = new HashMap<>(); - metaDataMap.put(key, "value2"); - metaDataMap.put(NacosMetaDataUtils.UTC_ZONE_OFFSET.toString(), String.valueOf(epochMilliseconds + 1)); - instance.setMetadata(metaDataMap); - Event event = new NamingEvent(persistentService.getServiceName(), Collections.singletonList(instance)); - doAnswer(AdditionalAnswers.answerVoid(getListenerAnswer(preInstance, event))).when(client).subscribe(anyString(), any(EventListener.class)); - SettableFuture settableFuture = SettableFuture.create(); - REPOSITORY.watch(key, settableFuture::set); - DataChangedEvent dataChangedEvent = settableFuture.get(); - assertThat(dataChangedEvent.getType(), is(DataChangedEvent.Type.UPDATED)); - assertThat(dataChangedEvent.getKey(), is(key)); - assertThat(dataChangedEvent.getValue(), is("value2")); - } - - @Test - void assertWatchDelete() throws NacosException, ExecutionException, InterruptedException { - ServiceMetaData persistentService = serviceController.getPersistentService(); - persistentService.setListener(null); - String key = "key/key"; - Instance preInstance = new Instance(); - preInstance.setMetadata(Collections.singletonMap(key, "value1")); - Event event = new NamingEvent(persistentService.getServiceName(), Collections.emptyList()); - doAnswer(AdditionalAnswers.answerVoid(getListenerAnswer(preInstance, event))).when(client).subscribe(anyString(), any(EventListener.class)); - SettableFuture settableFuture = SettableFuture.create(); - REPOSITORY.watch(key, settableFuture::set); - DataChangedEvent dataChangedEvent = settableFuture.get(); - assertThat(dataChangedEvent.getType(), is(DataChangedEvent.Type.DELETED)); - assertThat(dataChangedEvent.getKey(), is(key)); - assertThat(dataChangedEvent.getValue(), is("value1")); - } - - @Test - void assertClose() throws NacosException { - REPOSITORY.close(); - verify(client).shutDown(); - } - - @Test - void assertPersistNotAvailable() { - assertThrows(ClusterPersistRepositoryException.class, () -> REPOSITORY.persist("/test/children/keys/persistent/1", "value4")); - } - - @Test - void assertExceededMaximum() { - ServiceMetaData ephemeralService = serviceController.getEphemeralService(); - ephemeralService.setPort(new AtomicInteger(Integer.MAX_VALUE)); - assertThrows(IllegalStateException.class, () -> REPOSITORY.persistEphemeral("/key2", "value")); - } - - private VoidAnswer2 getListenerAnswer(final Instance preInstance, final Event event) { - return (serviceName, listener) -> { - MemberAccessor accessor = Plugins.getMemberAccessor(); - if (null != preInstance) { - Map preInstances = new HashMap<>(); - preInstances.put(NacosMetaDataUtils.getKey(preInstance), preInstance); - accessor.set(listener.getClass().getDeclaredField("preInstances"), listener, preInstances); - } - listener.onEvent(event); - }; - } - - private VoidAnswer2 getRegisterInstanceAnswer() { - return (serviceName, instance) -> { - List instances = client.getAllInstances(serviceName, false); - instances.removeIf(each -> Objects.equals(each.getIp(), instance.getIp()) && each.getPort() == instance.getPort()); - instances.add(instance); - when(client.getAllInstances(serviceName, false)).thenReturn(instances); - }; - } - - private VoidAnswer2 getDeregisterInstanceAnswer() { - return (serviceName, instance) -> { - List instances = client.getAllInstances(serviceName, false); - instances.remove(instance); - when(client.getAllInstances(serviceName, false)).thenReturn(instances); - }; - } -} diff --git a/mode/type/cluster/repository/provider/nacos/src/test/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosPropertiesTest.java b/mode/type/cluster/repository/provider/nacos/src/test/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosPropertiesTest.java deleted file mode 100644 index 7e04a0810d333..0000000000000 --- a/mode/type/cluster/repository/provider/nacos/src/test/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosPropertiesTest.java +++ /dev/null @@ -1,62 +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.repository.cluster.nacos.props; - -import org.apache.shardingsphere.test.util.PropertiesBuilder; -import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; -import org.junit.jupiter.api.Test; - -import java.util.Properties; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -class NacosPropertiesTest { - - @Test - void assertGetValue() { - NacosProperties actual = new NacosProperties(createProperties()); - assertThat(actual.getValue(NacosPropertyKey.CLUSTER_IP), is("127.0.0.1")); - assertThat(actual.getValue(NacosPropertyKey.RETRY_INTERVAL_MILLISECONDS), is(1000L)); - assertThat(actual.getValue(NacosPropertyKey.MAX_RETRIES), is(5)); - assertThat(actual.getValue(NacosPropertyKey.TIME_TO_LIVE_SECONDS), is(60)); - assertThat(actual.getValue(NacosPropertyKey.USERNAME), is("nacos")); - assertThat(actual.getValue(NacosPropertyKey.PASSWORD), is("nacos")); - } - - private Properties createProperties() { - return PropertiesBuilder.build( - new Property(NacosPropertyKey.CLUSTER_IP.getKey(), "127.0.0.1"), - new Property(NacosPropertyKey.RETRY_INTERVAL_MILLISECONDS.getKey(), "1000"), - new Property(NacosPropertyKey.MAX_RETRIES.getKey(), "5"), - new Property(NacosPropertyKey.TIME_TO_LIVE_SECONDS.getKey(), "60"), - new Property(NacosPropertyKey.USERNAME.getKey(), "nacos"), - new Property(NacosPropertyKey.PASSWORD.getKey(), "nacos")); - } - - @Test - void assertGetDefaultValue() { - NacosProperties actual = new NacosProperties(new Properties()); - assertThat(actual.getValue(NacosPropertyKey.CLUSTER_IP), is("")); - assertThat(actual.getValue(NacosPropertyKey.RETRY_INTERVAL_MILLISECONDS), is(500L)); - assertThat(actual.getValue(NacosPropertyKey.MAX_RETRIES), is(3)); - assertThat(actual.getValue(NacosPropertyKey.TIME_TO_LIVE_SECONDS), is(30)); - assertThat(actual.getValue(NacosPropertyKey.USERNAME), is("")); - assertThat(actual.getValue(NacosPropertyKey.PASSWORD), is("")); - } -} diff --git a/mode/type/cluster/repository/provider/pom.xml b/mode/type/cluster/repository/provider/pom.xml index f6c0480c8482e..c51a3ef34b6e5 100644 --- a/mode/type/cluster/repository/provider/pom.xml +++ b/mode/type/cluster/repository/provider/pom.xml @@ -30,7 +30,6 @@ zookeeper etcd - nacos consul