diff --git a/.github/scripts/check-registry-dependencies.py b/.github/scripts/check-registry-dependencies.py index ff233ff0c332..81c7d86075e9 100644 --- a/.github/scripts/check-registry-dependencies.py +++ b/.github/scripts/check-registry-dependencies.py @@ -18,7 +18,7 @@ import sys from pathlib import Path -PROVIDERS = ("zookeeper", "etcd", "nacos", "apollo", "eureka", "kubernetes") +PROVIDERS = ("zookeeper", "nacos", "apollo", "eureka", "kubernetes") COMPATIBILITY_PROVIDERS = set(PROVIDERS) - {"apollo"} LEAN_MODULES = ( "shenyu-registry/shenyu-registry-api", diff --git a/README.md b/README.md index 408278893cd9..619c069118da 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Apache ShenYu is a Java-based gateway for service proxying, protocol conversion, | Registration and discovery | Client SDKs register service addresses and API metadata with Admin. Registry integrations support discovery; an optional Kubernetes controller reconciles Ingress and Endpoints resources. | | Security and traffic control | WAF, signing, authentication plugins, load balancing, rate limiting, and fault tolerance through Resilience4j and Sentinel; deprecated Hystrix remains available as an external plugin (see [plugin-store-hystrix](docs/plugin-store-hystrix.md)). | | Caching and transformation | In-memory or Redis-backed response caching, URL rewriting, redirection, and request/response transformation. | -| Dynamic configuration | Admin persists plugins, selectors, rules, metadata, and authentication data. WebSocket sync is the default; HTTP long polling, ZooKeeper, Nacos, and etcd are available. Apollo remains available during its deprecation release and is planned to move to an external extension (see [Apollo migration](docs/plugin-store-apollo.md)). Consul sync is available as an external extension (see [plugin-store-consul](docs/plugin-store-consul.md)). Gateway replicas apply updates to their local caches. | +| Dynamic configuration | Admin persists plugins, selectors, rules, metadata, and authentication data. WebSocket sync is the default; HTTP long polling, ZooKeeper, and Nacos are available; etcd sync and registry use [plugin-store-etcd](docs/plugin-store-etcd.md). Apollo remains available during its deprecation release and is planned to move to an external extension (see [Apollo migration](docs/plugin-store-apollo.md)). Consul sync is available as an external extension (see [plugin-store-consul](docs/plugin-store-consul.md)). Gateway replicas apply updates to their local caches. | | Observability | Metrics and logging plugins, including Kafka and Elasticsearch destinations; email and DingTalk alerts from Admin. | | AI and MCP | AI proxy, prompt processing, token limits, sensitive-word filtering, AI request/response transformation, and an MCP server plugin with SSE and Streamable HTTP. | diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 393a0bb1c4d0..1e75887d3f1a 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -2,6 +2,11 @@ ### API Changes +- The planned etcd cutover transfers the complete integration to plugin-store + while preserving the `etcd` type and keyspace (#7597). Merge requires the + released deprecation cycle, receiving validation, compatible publication and + rollback announcement. See [the migration guide](docs/plugin-store-etcd.md). + - WASM loaders support opt-in startup execution deadlines and per-instance linear-memory ceilings. Defaults remain disabled. Timed execution owns bounded workers, propagates interruption and replaces interrupted instances after physical exit. See diff --git a/docs/plugin-store-etcd.md b/docs/plugin-store-etcd.md new file mode 100644 index 000000000000..74a6129db08a --- /dev/null +++ b/docs/plugin-store-etcd.md @@ -0,0 +1,141 @@ + +# etcd plugin-store migration + +The entire etcd stack is transferred as one unit to `apache/shenyu-plugin-store`: +`shenyu-infra-etcd`, `shenyu-admin-listener-etcd`, `shenyu-sync-data-etcd`, +`shenyu-registry-etcd`, and `shenyu-spring-boot-starter-sync-data-etcd`. +Infrastructure is etcd-specific; no retained core module imports it. + +## Release gates + +The main removal PR can enter code review, but must not merge until dev-list consensus is recorded, an +advance deprecation notice has shipped in a core release, the full released +deprecation cycle is complete, receiving builds and real-server/full-deployment +tests pass, external artifacts are published, and a rollback window is announced. +The deprecation release retains the in-tree integration; this branch prepares a +later cutover. No removal release is scheduled. Source changes and local snapshots +do not complete these release gates. +The store currently uses `2.7.1-SNAPSHOT` and compiles against ShenYu `2.7.2-SNAPSHOT`; +select the announced compatible store release when deploying. Do not publish the +same group/artifact/version from both repositories. Retain the last in-tree release +and its configuration during the rollback window; the release announcement must +specify that window before the cutover is merged. + +## Dependency selection + +Admin needs `org.apache.shenyu:shenyu-admin-listener-etcd`; gateway needs +`org.apache.shenyu:shenyu-spring-boot-starter-sync-data-etcd`. Applications using etcd +instance registration, SDK discovery, or Admin etcd discovery additionally need +`org.apache.shenyu:shenyu-registry-etcd`. Use the **store** version for all five +external modules and the **core** version for retained ShenYu APIs. +Gateway registration also requires the retained core +`shenyu-spring-boot-starter-registry`; exclude its bundled providers and add the +external `shenyu-registry-etcd`. The receiving gateway example POM shows this selection. +The infrastructure and jetcd dependencies are transitive. For binary distributions, +resolve the complete runtime dependency closure into `lib/`, remove superseded etcd +JARs, and include the extension's LICENSE/NOTICE information in the custom package. +Adding only the starter JAR without its dependencies is insufficient. + +The `etcd` SPI key is unchanged. The JAR still registers +`etcd=org.apache.shenyu.registry.etcd.EtcdInstanceRegisterRepository` in +`META-INF/shenyu/org.apache.shenyu.registry.api.ShenyuInstanceRegisterRepository`. +Admin's existing `ShenyuInstanceRegisterRepositoryFactory.loadRepository` loads the +external provider without a hard-coded class or dependency in core. + +## Configuration and storage contract + +Admin and gateway retain `shenyu.sync.etcd.url`, with comma-separated endpoint URLs: + +```yaml +shenyu: + sync: + etcd: + url: http://etcd-1:2379,http://etcd-2:2379 + sessionTimeout: 30000 + connectionTimeout: 30000 +``` + +Disable the previous sync channel when selecting etcd. Admin uses +`shenyu.sync.websocket.enabled=false`; gateway must remove/disable its WebSocket +`urls` setting. Preserve the existing timeout values: the historical binding maps +`sessionTimeout` to the client's operation timeout (milliseconds) and +`connectionTimeout` to its lease TTL (seconds). This migration does not reinterpret +those values; revisit the naming/units in a separate compatible change. + +Gateway instance registration keeps: + +```yaml +shenyu: + register: + enabled: true + registerType: etcd + serverLists: http://etcd-1:2379,http://etcd-2:2379 + props: + etcdTimeout: "3000" + etcdTTL: "5" +``` + +Configuration keys retain their leading slash and namespace: + +| Data | Key | +| --- | --- | +| Plugin | `//shenyu/plugin/` | +| Selector | `//shenyu/selector//` | +| Rule | `//shenyu/rule//-` | +| Authentication | `//shenyu/auth/` | +| Metadata | `//shenyu/metaData/` | +| Proxy selector | `//shenyu/proxySelectorData//` | +| Discovery upstream | `//shenyu/discoveryUpstream//` | +| Instance | `/shenyu/register/instance//:` | + +JSON DTOs, enum values, discovery mode, namespace IDs and existing keyspaces stay +compatible. Instance keys remain lease-backed; after client shutdown they disappear +when their lease expires. No schema conversion or data deletion is required. + +## Compatibility, licensing and verification + +The transferred client remains `io.etcd:jetcd-core:0.7.3`, using the core-managed +gRPC `1.65.1`. The real-server fixture targets etcd `3.5.21`; other etcd/client +versions need validation before claiming support. Server and client are Apache-2.0: +see [etcd LICENSE](https://github.com/etcd-io/etcd/blob/v3.5.21/LICENSE) and +[jetcd LICENSE](https://github.com/etcd-io/jetcd/blob/jetcd-0.7.3/LICENSE). +The receiving extension carries the former distribution's CoreOS notice. +Historical release notes and upgrade documentation remain in main. + +The store README documents unit, starter, real-server and full Admin/gateway E2E +commands. Real-server tests cover initial snapshots, namespace isolation, route +create/update/delete, server restart/watch recovery, external SPI registration, +instance update/delete/lease expiry and client shutdown. CI uses Testcontainers; +a native etcd binary is an explicit local alternative. Full deployment validation +uses the real Admin API and gateway HTTP traffic with externally supplied JARs. + +## Upgrade and rollback + +1. Back up Admin's database and take an etcd snapshot. Record namespace, endpoints, + timeouts, TTL, core/store versions and the deployed JAR inventory. +2. Verify compatible external artifacts and all release gates in a staging deployment. + Add the selected artifacts and their runtime dependencies before changing images. +3. Roll Admin and gateways one at a time, preserving their namespace/endpoints and + registry settings. Check initial synchronization, route updates and instance discovery. +4. Keep the previous in-tree images and configuration available for the announced window. + To roll back, restore those images/configuration and remove the external etcd JARs. + Reuse the same etcd keyspace and Admin database; do not clear either as part of rollback. + +The archived compose/Kubernetes assets in `examples/etcd/legacy` belong to the last +in-tree deployment. They require the original core images; the receiving project's +new external-artifact E2E launcher is the cutover validation path. diff --git a/pom.xml b/pom.xml index 02b102a0a168..43585676cd0e 100644 --- a/pom.xml +++ b/pom.xml @@ -173,7 +173,6 @@ 4.1.139.Final 1.9.6 1.4.200 - 0.7.3 1.5.0 5.11.0 4.0.3 @@ -535,30 +534,6 @@ ${jakarta.json-api.version} - - io.etcd - jetcd-core - ${jetcd-core.version} - - - grpc-protobuf - io.grpc - - - grpc-stub - io.grpc - - - io.grpc - grpc-core - - - grpc-netty - io.grpc - - - - io.grpc grpc-core diff --git a/shenyu-admin-listener/pom.xml b/shenyu-admin-listener/pom.xml index 0ff72ea20c7f..40e01fc96d8f 100644 --- a/shenyu-admin-listener/pom.xml +++ b/shenyu-admin-listener/pom.xml @@ -30,7 +30,6 @@ shenyu-admin-listener-api shenyu-admin-listener-apollo - shenyu-admin-listener-etcd shenyu-admin-listener-nacos shenyu-admin-listener-zookeeper diff --git a/shenyu-admin-listener/shenyu-admin-listener-etcd/pom.xml b/shenyu-admin-listener/shenyu-admin-listener-etcd/pom.xml deleted file mode 100644 index c14eba228a2a..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-etcd/pom.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - 4.0.0 - - org.apache.shenyu - shenyu-admin-listener - 2.7.3-SNAPSHOT - - - shenyu-admin-listener-etcd - - - - com.google.guava - guava - test - - - - - org.apache.shenyu - shenyu-infra-etcd - ${project.version} - - - - org.apache.shenyu - shenyu-admin-listener-api - ${project.version} - - - - org.springframework.boot - spring-boot-starter-web - provided - - - - diff --git a/shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/java/org/apache/shenyu/admin/config/EtcdSyncConfiguration.java b/shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/java/org/apache/shenyu/admin/config/EtcdSyncConfiguration.java deleted file mode 100644 index d01a6ae253c5..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/java/org/apache/shenyu/admin/config/EtcdSyncConfiguration.java +++ /dev/null @@ -1,68 +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.shenyu.admin.config; - -import org.apache.shenyu.admin.listener.DataChangedInit; -import org.apache.shenyu.admin.listener.DataChangedListener; -import org.apache.shenyu.admin.listener.etcd.EtcdDataChangedInit; -import org.apache.shenyu.admin.listener.etcd.EtcdDataDataChangedListener; -import org.apache.shenyu.infra.etcd.autoconfig.ConditionOnSyncEtcd; -import org.apache.shenyu.infra.etcd.autoconfig.EtcdConfiguration; -import org.apache.shenyu.infra.etcd.client.EtcdClient; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * The type Etcd listener. - */ - -@Configuration -@ConditionOnSyncEtcd -@AutoConfiguration(after = { EtcdConfiguration.class }) -@ImportAutoConfiguration(EtcdConfiguration.class) -public class EtcdSyncConfiguration { - - /** - * Config event listener data changed listener. - * - * @param etcdClient the etcd client - * @return the data changed listener - */ - @Bean - @ConditionalOnMissingBean(EtcdDataDataChangedListener.class) - public DataChangedListener etcdDataChangedListener(final EtcdClient etcdClient) { - - return new EtcdDataDataChangedListener(etcdClient); - } - - /** - * data init. - * - * @param etcdClient the etcd client - * @return the etcd data init - */ - @Bean - @ConditionalOnMissingBean(EtcdDataChangedInit.class) - public DataChangedInit etcdDataChangedInit(final EtcdClient etcdClient) { - - return new EtcdDataChangedInit(etcdClient); - } -} diff --git a/shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/java/org/apache/shenyu/admin/listener/etcd/EtcdDataChangedInit.java b/shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/java/org/apache/shenyu/admin/listener/etcd/EtcdDataChangedInit.java deleted file mode 100644 index 8a11e8d97c88..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/java/org/apache/shenyu/admin/listener/etcd/EtcdDataChangedInit.java +++ /dev/null @@ -1,52 +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.shenyu.admin.listener.etcd; - -import org.apache.shenyu.admin.listener.AbstractDataChangedInit; -import org.apache.shenyu.common.constant.DefaultPathConstants; -import org.apache.shenyu.infra.etcd.client.EtcdClient; - -import java.util.stream.Stream; - -/** - * The type Etcd data changed init. - * - * @since 2.5.0 - */ -public class EtcdDataChangedInit extends AbstractDataChangedInit { - - private final EtcdClient etcdClient; - - /** - * Instantiates a new Etcd data changed init. - * - * @param etcdClient the etcdClient client - */ - public EtcdDataChangedInit(final EtcdClient etcdClient) { - this.etcdClient = etcdClient; - } - - @Override - protected boolean notExist() { - return Stream.of(DefaultPathConstants.PLUGIN_PARENT, - DefaultPathConstants.APP_AUTH_PARENT, - DefaultPathConstants.META_DATA, - DefaultPathConstants.PROXY_SELECTOR, - DefaultPathConstants.DISCOVERY_UPSTREAM).noneMatch(etcdClient::exists); - } -} diff --git a/shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/java/org/apache/shenyu/admin/listener/etcd/EtcdDataDataChangedListener.java b/shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/java/org/apache/shenyu/admin/listener/etcd/EtcdDataDataChangedListener.java deleted file mode 100644 index 8c5c78ca737d..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/java/org/apache/shenyu/admin/listener/etcd/EtcdDataDataChangedListener.java +++ /dev/null @@ -1,49 +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.shenyu.admin.listener.etcd; - -import org.apache.shenyu.admin.listener.AbstractPathDataChangedListener; -import org.apache.shenyu.common.utils.GsonUtils; -import org.apache.shenyu.infra.etcd.client.EtcdClient; - -/** - * EtcdDataDataChangedListener. - */ -public class EtcdDataDataChangedListener extends AbstractPathDataChangedListener { - - private final EtcdClient etcdClient; - - public EtcdDataDataChangedListener(final EtcdClient client) { - this.etcdClient = client; - } - - @Override - public void createOrUpdate(final String pluginPath, final Object data) { - etcdClient.put(pluginPath, GsonUtils.getInstance().toJson(data)); - } - - @Override - public void deleteNode(final String pluginPath) { - etcdClient.delete(pluginPath); - } - - @Override - public void deletePathRecursive(final String selectorParentPath) { - etcdClient.deleteEtcdPathRecursive(selectorParentPath); - } -} diff --git a/shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/resources/META-INF/spring.factories b/shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 8b477f369166..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,19 +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.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.apache.shenyu.admin.config.EtcdSyncConfiguration diff --git a/shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/resources/META-INF/spring.provides b/shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/resources/META-INF/spring.provides deleted file mode 100644 index 55e4b72de7f8..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/resources/META-INF/spring.provides +++ /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. -# - -provides: shenyu-admin-listener-nacos diff --git a/shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 927e1acdd7e5..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /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.shenyu.admin.config.EtcdSyncConfiguration diff --git a/shenyu-admin-listener/shenyu-admin-listener-etcd/src/test/java/org/apache/shenyu/admin/config/EtcdSyncConfigurationTest.java b/shenyu-admin-listener/shenyu-admin-listener-etcd/src/test/java/org/apache/shenyu/admin/config/EtcdSyncConfigurationTest.java deleted file mode 100644 index c59e91793bf9..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-etcd/src/test/java/org/apache/shenyu/admin/config/EtcdSyncConfigurationTest.java +++ /dev/null @@ -1,42 +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.shenyu.admin.config; - -import org.apache.shenyu.infra.etcd.client.EtcdClient; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.mockito.Mockito.mock; - -public class EtcdSyncConfigurationTest { - - @Test - public void testEtcdDataChangedListener() { - EtcdSyncConfiguration etcdListener = new EtcdSyncConfiguration(); - EtcdClient client = mock(EtcdClient.class); - assertNotNull(etcdListener.etcdDataChangedListener(client)); - } - - @Test - public void testEtcdDataInit() { - EtcdSyncConfiguration etcdListener = new EtcdSyncConfiguration(); - EtcdClient client = mock(EtcdClient.class); - assertNotNull(etcdListener.etcdDataChangedInit(client)); - } - -} diff --git a/shenyu-admin-listener/shenyu-admin-listener-etcd/src/test/java/org/apache/shenyu/admin/listener/etcd/EtcdDataChangedInitTest.java b/shenyu-admin-listener/shenyu-admin-listener-etcd/src/test/java/org/apache/shenyu/admin/listener/etcd/EtcdDataChangedInitTest.java deleted file mode 100644 index d01711223403..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-etcd/src/test/java/org/apache/shenyu/admin/listener/etcd/EtcdDataChangedInitTest.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.shenyu.admin.listener.etcd; - -import org.apache.shenyu.common.constant.DefaultPathConstants; -import org.apache.shenyu.infra.etcd.client.EtcdClient; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.when; - -/** - * Test cases for {@link EtcdDataChangedInit}. - */ -@ExtendWith(MockitoExtension.class) -public class EtcdDataChangedInitTest { - - @Mock - private EtcdClient etcdClient; - - @Test - public void testNotExist() throws Exception { - EtcdDataChangedInit etcdDataChangedInit = new EtcdDataChangedInit(etcdClient); - assertNotNull(etcdDataChangedInit); - - when(etcdClient.exists(DefaultPathConstants.PLUGIN_PARENT)).thenReturn(true); - boolean pluginExist = etcdDataChangedInit.notExist(); - assertFalse(pluginExist, "plugin exist."); - when(etcdClient.exists(DefaultPathConstants.PLUGIN_PARENT)).thenReturn(false); - - when(etcdClient.exists(DefaultPathConstants.APP_AUTH_PARENT)).thenReturn(true); - boolean appAuthExist = etcdDataChangedInit.notExist(); - assertFalse(appAuthExist, "app auth exist."); - when(etcdClient.exists(DefaultPathConstants.APP_AUTH_PARENT)).thenReturn(false); - - when(etcdClient.exists(DefaultPathConstants.META_DATA)).thenReturn(true); - boolean metaDataExist = etcdDataChangedInit.notExist(); - assertFalse(metaDataExist, "metadata exist."); - when(etcdClient.exists(DefaultPathConstants.META_DATA)).thenReturn(false); - boolean metaDataNotExist = etcdDataChangedInit.notExist(); - assertTrue(metaDataNotExist, "metadata not exist."); - } -} diff --git a/shenyu-admin-listener/shenyu-admin-listener-etcd/src/test/java/org/apache/shenyu/admin/listener/etcd/EtcdDataDataChangedListenerTest.java b/shenyu-admin-listener/shenyu-admin-listener-etcd/src/test/java/org/apache/shenyu/admin/listener/etcd/EtcdDataDataChangedListenerTest.java deleted file mode 100644 index f8e0c24575a4..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-etcd/src/test/java/org/apache/shenyu/admin/listener/etcd/EtcdDataDataChangedListenerTest.java +++ /dev/null @@ -1,141 +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.shenyu.admin.listener.etcd; - -import com.google.common.collect.ImmutableList; -import org.apache.shenyu.common.dto.AppAuthData; -import org.apache.shenyu.common.dto.MetaData; -import org.apache.shenyu.common.dto.PluginData; -import org.apache.shenyu.common.dto.RuleData; -import org.apache.shenyu.common.dto.SelectorData; -import org.apache.shenyu.common.enums.DataEventTypeEnum; -import org.apache.shenyu.infra.etcd.client.EtcdClient; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -/** - * The testCase for {@link EtcdDataDataChangedListener}. - */ -@ExtendWith(MockitoExtension.class) -public class EtcdDataDataChangedListenerTest { - - private static final String MOCK_APP_KEY = "MOCK_APP_KEY"; - - private static final String MOCK_APP_SECRET = "MOCK_APP_SECRET"; - - private static final String MOCK_ID = "MOCK_ID"; - - private static final String MOCK_PATH = "MOCK_PATH"; - - private static final String MOCK_APP_NAME = "MOCK_APP_NAME"; - - private static final String MOCK_NAME = "MOCK_NAME"; - - private static final String MOCK_CONFIG = "MOCK_CONFIG"; - - private static final String MOCK_PLUGIN_NAME = "MOCK_PLUGIN_NAME"; - - private static final String MOCK_SELECTOR_ID = "MOCK_SELECTOR_ID"; - - @InjectMocks - private EtcdDataDataChangedListener etcdDataDataChangedListener; - - @Mock - private EtcdClient etcdClient; - - /** - * test case onAppAuthChanged event. - */ - @Test - public void testOnAppAuthChanged() { - AppAuthData appAuthData = AppAuthData.builder().appKey(MOCK_APP_KEY).appSecret(MOCK_APP_SECRET).build(); - etcdDataDataChangedListener.onAppAuthChanged(ImmutableList.of(appAuthData), DataEventTypeEnum.CREATE); - etcdDataDataChangedListener.onAppAuthChanged(ImmutableList.of(appAuthData), DataEventTypeEnum.UPDATE); - etcdDataDataChangedListener.onAppAuthChanged(ImmutableList.of(appAuthData), DataEventTypeEnum.DELETE); - verify(etcdClient, times(2)).put(any(String.class), any(String.class)); - verify(etcdClient, times(1)).delete(any(String.class)); - } - - /** - * test case onMetaDataChanged event. - */ - @Test - public void testOnMetaDataChanged() { - MetaData metaData = MetaData.builder().id(MOCK_ID).path(MOCK_PATH).appName(MOCK_APP_NAME).build(); - etcdDataDataChangedListener.onMetaDataChanged(ImmutableList.of(metaData), DataEventTypeEnum.CREATE); - etcdDataDataChangedListener.onMetaDataChanged(ImmutableList.of(metaData), DataEventTypeEnum.UPDATE); - etcdDataDataChangedListener.onMetaDataChanged(ImmutableList.of(metaData), DataEventTypeEnum.DELETE); - verify(etcdClient, times(2)).put(any(String.class), any(String.class)); - verify(etcdClient, times(1)).delete(any(String.class)); - } - - /** - * test case onPluginChanged event. - */ - @Test - public void testOnPluginChanged() { - PluginData pluginData = PluginData.builder().id(MOCK_ID).name(MOCK_NAME).config(MOCK_CONFIG).build(); - etcdDataDataChangedListener.onPluginChanged(ImmutableList.of(pluginData), DataEventTypeEnum.CREATE); - etcdDataDataChangedListener.onPluginChanged(ImmutableList.of(pluginData), DataEventTypeEnum.UPDATE); - etcdDataDataChangedListener.onPluginChanged(ImmutableList.of(pluginData), DataEventTypeEnum.DELETE); - verify(etcdClient, times(2)).put(any(String.class), any(String.class)); - verify(etcdClient, times(3)).deleteEtcdPathRecursive(any(String.class)); - } - - /** - * test case onSelectorChanged event. - */ - @Test - public void testOnSelectorChanged() { - SelectorData selectorData = SelectorData.builder().id(MOCK_ID).name(MOCK_NAME).pluginName(MOCK_PLUGIN_NAME).build(); - etcdDataDataChangedListener.onSelectorChanged(ImmutableList.of(selectorData), DataEventTypeEnum.CREATE); - etcdDataDataChangedListener.onSelectorChanged(ImmutableList.of(selectorData), DataEventTypeEnum.UPDATE); - etcdDataDataChangedListener.onSelectorChanged(ImmutableList.of(selectorData), DataEventTypeEnum.REFRESH); - etcdDataDataChangedListener.onSelectorChanged(ImmutableList.of(selectorData), DataEventTypeEnum.DELETE); - verify(etcdClient, times(3)).put(any(String.class), any(String.class)); - verify(etcdClient, times(1)).delete(any(String.class)); - verify(etcdClient, times(1)).deleteEtcdPathRecursive(any(String.class)); - } - - /** - * test case onRuleChanged event. - */ - @Test - public void testOnRuleChanged() { - RuleData ruleData = RuleData.builder() - .id(MOCK_ID) - .name(MOCK_NAME) - .pluginName(MOCK_PLUGIN_NAME) - .selectorId(MOCK_SELECTOR_ID) - .build(); - etcdDataDataChangedListener.onRuleChanged(ImmutableList.of(ruleData), DataEventTypeEnum.CREATE); - etcdDataDataChangedListener.onRuleChanged(ImmutableList.of(ruleData), DataEventTypeEnum.UPDATE); - etcdDataDataChangedListener.onRuleChanged(ImmutableList.of(ruleData), DataEventTypeEnum.REFRESH); - etcdDataDataChangedListener.onRuleChanged(ImmutableList.of(ruleData), DataEventTypeEnum.DELETE); - verify(etcdClient, times(3)).put(any(String.class), any(String.class)); - verify(etcdClient, times(1)).delete(any(String.class)); - verify(etcdClient, times(1)).deleteEtcdPathRecursive(any(String.class)); - } -} diff --git a/shenyu-admin/pom.xml b/shenyu-admin/pom.xml index 6dafcffb1eb8..b7b998f0cebb 100644 --- a/shenyu-admin/pom.xml +++ b/shenyu-admin/pom.xml @@ -301,11 +301,6 @@ - - org.apache.shenyu - shenyu-admin-listener-etcd - ${project.version} - org.apache.shenyu @@ -346,12 +341,6 @@ ${project.version} runtime - - org.apache.shenyu - shenyu-registry-etcd - ${project.version} - runtime - org.apache.shenyu shenyu-registry-nacos diff --git a/shenyu-admin/src/main/resources/application.yml b/shenyu-admin/src/main/resources/application.yml index 2e1efce2a5b6..4297f51de347 100755 --- a/shenyu-admin/src/main/resources/application.yml +++ b/shenyu-admin/src/main/resources/application.yml @@ -118,8 +118,6 @@ shenyu: # namespace: # accessKey: # secretKey: -# etcd: -# url: http://localhost:2379 # consul: # url: http://localhost:8500 ldap: diff --git a/shenyu-admin/src/test/resources/application.yml b/shenyu-admin/src/test/resources/application.yml index a8066d9c4cb1..c7b3ce3d4fae 100644 --- a/shenyu-admin/src/test/resources/application.yml +++ b/shenyu-admin/src/test/resources/application.yml @@ -33,8 +33,8 @@ mybatis: shenyu: register: - registerType: http #http #zookeeper #etcd #nacos #consul - serverLists: #localhost:2181 #http://localhost:2379 #localhost:8848 + registerType: http #http #zookeeper #nacos #consul + serverLists: #localhost:2181 #localhost:8848 props: sessionTimeout: 5000 connectionTimeout: 2000 @@ -62,8 +62,6 @@ shenyu: # namespace: # accessKey: # secretKey: -# etcd: -# url: http://localhost:2379 # consul: # url: http://localhost:8500 aes: diff --git a/shenyu-bootstrap/pom.xml b/shenyu-bootstrap/pom.xml index 650e244e7e4f..3bb1ba5e2f41 100644 --- a/shenyu-bootstrap/pom.xml +++ b/shenyu-bootstrap/pom.xml @@ -408,23 +408,6 @@ shenyu-spring-boot-starter-sync-data-nacos ${project.version} - - - - org.apache.shenyu - shenyu-spring-boot-starter-sync-data-etcd - ${project.version} - - - io.grpc - grpc-grpclb - - - io.grpc - grpc-netty - - - diff --git a/shenyu-bootstrap/src/main/resources/application.yml b/shenyu-bootstrap/src/main/resources/application.yml index 9565990b4fd0..38d196b72eb6 100644 --- a/shenyu-bootstrap/src/main/resources/application.yml +++ b/shenyu-bootstrap/src/main/resources/application.yml @@ -199,8 +199,8 @@ shenyu: # daemon: true register: enabled: false - registerType: zookeeper #etcd #consul - serverLists: localhost:2181 #http://localhost:2379 #localhost:8848 + registerType: zookeeper #consul + serverLists: localhost:2181 #localhost:8848 props: cross: enabled: true @@ -270,8 +270,6 @@ shenyu: # namespace: # accessKey: # secretKey: -# etcd: -# url: http://localhost:2379 heartbeat: enabled: true serverLists: http://localhost:9095 diff --git a/shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE b/shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE index 9a47c6c8d064..452e324fe642 100644 --- a/shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE +++ b/shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE @@ -275,10 +275,6 @@ The text of each license is the standard Apache 2.0 license. jakarta.validation-api 3.0.2: http://beanvalidation.org, Apache 2.0 javassist 3.30.2-GA: https://github.com/jboss-javassist/javassist, Apache 2.0 jboss-logging 3.5.3.Final: http://www.jboss.org, Apache 2.0 - jetcd-api 0.7.3: https://github.com/etcd-io/jetcd, Apache 2.0 - jetcd-common 0.7.3: https://github.com/etcd-io/jetcd, Apache 2.0 - jetcd-core 0.7.3: https://github.com/etcd-io/jetcd, Apache 2.0 - jetcd-grpc 0.7.3: https://github.com/etcd-io/jetcd, Apache 2.0 jsqlparser 4.5: https://github.com/JSQLParser/JSqlParser, Apache 2.0 jsr305 3.0.2: http://findbugs.sourceforge.net/, Apache 2.0 jersey-apache-connector 3.1.7: https://mvnrepository.com/artifact/org.glassfish.jersey.connectors/jersey-apache-connector, Apache 2.0 diff --git a/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/LICENSE b/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/LICENSE index 4b971d4edb8f..3696f09ce21b 100644 --- a/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/LICENSE +++ b/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/LICENSE @@ -275,10 +275,6 @@ The text of each license is the standard Apache 2.0 license. jackson-module-jsonSchema 2.17.1: http://github.com/FasterXML/jackson, Apache 2.0 javassist 3.30.2-GA: https://github.com/jboss-javassist/javassist, Apache 2.0 jctools-core 4.0.3: https://github.com/JCTools/JCTools, Apache 2.0 - jetcd-api 0.7.3: https://github.com/etcd-io/jetcd, Apache 2.0 - jetcd-common 0.7.3: https://github.com/etcd-io/jetcd, Apache 2.0 - jetcd-core 0.7.3: https://github.com/etcd-io/jetcd, Apache 2.0 - jetcd-grpc 0.7.3: https://github.com/etcd-io/jetcd, Apache 2.0 jjwt-api 0.12.3: https://jwt.io, Apache 2.0 jjwt-impl 0.12.3: https://jwt.io, Apache 2.0 jjwt-jackson 0.12.3: https://jwt.io, Apache 2.0 diff --git a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-etcd-eureka.yml b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-etcd-eureka.yml deleted file mode 100644 index a02bc2503424..000000000000 --- a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-etcd-eureka.yml +++ /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. - -version: '3.9' - -services: - shenyu-etcd: - image: rancher/hardened-etcd:v3.5.21-k3s1-build20250910 - container_name: shenyu-etcd - command: ["etcd"] - environment: - - ALLOW_NONE_AUTHENTICATION=yes - - ETCD_ADVERTISE_CLIENT_URLS=http://shenyu-etcd:2379 - - TZ=Asia/Shanghai - ports: - - "32379:2379" - - "2380:2380" - healthcheck: - test: ["CMD", "etcdctl", "endpoint", "health"] - interval: 10s - timeout: 5s - retries: 10 - start_period: 30s - restart: always - networks: - - shenyu - - shenyu-mysql: - image: mysql:8.0 - container_name: shenyu-mysql - environment: - - MYSQL_ROOT_PASSWORD=shenyue2e - - MYSQL_USER=shenyue2e - - MYSQL_PASSWORD=shenyue2e - ports: - - "30306:3306" - volumes: - - /tmp/shenyu-e2e/mysql/schema/schema.sql:/docker-entrypoint-initdb.d/schema.sql - healthcheck: - test: [ "CMD", "mysql", "-h", "127.0.0.1", "-P", "3306", "-u", "root", "-pshenyue2e", "-e", "SELECT 1" ] - interval: 10s - timeout: 5s - retries: 10 - start_period: 30s - deploy: - resources: - limits: - cpus: '1' - memory: 768M - reservations: - cpus: '0.5' - memory: 512M - restart: always - networks: - - shenyu - - shenyu-admin: - image: apache/shenyu-admin:latest - container_name: shenyu-admin - command: [ "-Xmx768m", "-Xms768m" ] - ports: - - "31095:9095" - environment: - - TZ=Asia/Beijing - - SPRING_PROFILES_ACTIVE=mysql - - shenyu.database.dialect=mysql - - shenyu.database.init_enable=true - - spring.datasource.username=shenyue2e - - spring.datasource.password=shenyue2e - - spring.datasource.url=jdbc:mysql://shenyu-mysql:3306/shenyu?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull - - shenyu.sync.etcd.url=http://shenyu-etcd:2379 - - shenyu.jwt.secretKey=shenyu-e2e-jwt-secret-key-2024 - volumes: - - /tmp/shenyu-e2e/mysql/driver:/opt/shenyu-admin/ext-lib - healthcheck: - test: [ "CMD-SHELL", "wget -q -O - http://shenyu-admin:9095/actuator/health | grep UP || exit 1" ] - interval: 10s - timeout: 5s - retries: 15 - start_period: 30s - restart: always - depends_on: - shenyu-mysql: - condition: service_healthy - shenyu-etcd: - condition: service_healthy - networks: - - shenyu - - shenyu-bootstrap: - image: apache/shenyu-bootstrap:latest - container_name: shenyu-bootstrap - ports: - - "31195:9195" - environment: - - TZ=Asia/Beijing - - shenyu.sync.etcd.url=http://shenyu-etcd:2379 - - spring.cloud.discovery.enabled=true - - eureka.client.enabled=true - - eureka.client.serviceUrl.defaultZone=http://shenyu-examples-eureka:8761/eureka/ - - eureka.instance.prefer-ip-address=true - healthcheck: - test: [ "CMD-SHELL", "wget -q -O - http://shenyu-bootstrap:9195/actuator/health | grep UP || exit 1" ] - interval: 10s - timeout: 5s - retries: 15 - start_period: 30s - restart: always - depends_on: - shenyu-admin: - condition: service_healthy - networks: - - shenyu - -networks: - shenyu: - name: shenyu - driver: bridge - external: true diff --git a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-etcd.yml b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-etcd.yml deleted file mode 100644 index 865e2668e82f..000000000000 --- a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-etcd.yml +++ /dev/null @@ -1,128 +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. - -version: '3.9' - -services: - shenyu-etcd: - image: rancher/hardened-etcd:v3.5.21-k3s1-build20250910 - container_name: shenyu-etcd - command: ["etcd"] - environment: - - ALLOW_NONE_AUTHENTICATION=yes - - ETCD_ADVERTISE_CLIENT_URLS=http://shenyu-etcd:2379 - - TZ=Asia/Shanghai - ports: - - "32379:2379" - - "2380:2380" - healthcheck: - test: ["CMD", "etcdctl", "endpoint", "health"] - interval: 10s - timeout: 5s - retries: 10 - start_period: 30s - restart: always - networks: - - shenyu - - shenyu-mysql: - image: mysql:8.0 - container_name: shenyu-mysql - environment: - - MYSQL_ROOT_PASSWORD=shenyue2e - - MYSQL_USER=shenyue2e - - MYSQL_PASSWORD=shenyue2e - ports: - - "30306:3306" - volumes: - - /tmp/shenyu-e2e/mysql/schema/schema.sql:/docker-entrypoint-initdb.d/schema.sql - healthcheck: - test: [ "CMD", "mysql", "-h", "127.0.0.1", "-P", "3306", "-u", "root", "-pshenyue2e", "-e", "SELECT 1" ] - interval: 10s - timeout: 5s - retries: 10 - start_period: 30s - deploy: - resources: - limits: - cpus: '1' - memory: 768M - reservations: - cpus: '0.5' - memory: 512M - restart: always - networks: - - shenyu - - shenyu-admin: - image: apache/shenyu-admin:latest - container_name: shenyu-admin - command: [ "-Xmx768m", "-Xms768m" ] - ports: - - "31095:9095" - environment: - - TZ=Asia/Beijing - - SPRING_PROFILES_ACTIVE=mysql - - shenyu.database.dialect=mysql - - shenyu.database.init_enable=true - - spring.datasource.username=shenyue2e - - spring.datasource.password=shenyue2e - - spring.datasource.url=jdbc:mysql://shenyu-mysql:3306/shenyu?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull - - shenyu.sync.etcd.url=http://shenyu-etcd:2379 - - shenyu.jwt.secretKey=shenyu-e2e-jwt-secret-key-2024 - volumes: - - /tmp/shenyu-e2e/mysql/driver:/opt/shenyu-admin/ext-lib - healthcheck: - test: [ "CMD-SHELL", "wget -q -O - http://shenyu-admin:9095/actuator/health | grep UP || exit 1" ] - interval: 10s - timeout: 5s - retries: 15 - start_period: 30s - restart: always - depends_on: - shenyu-mysql: - condition: service_healthy - shenyu-etcd: - condition: service_healthy - networks: - - shenyu - - shenyu-bootstrap: - image: apache/shenyu-bootstrap:latest - container_name: shenyu-bootstrap - ports: - - "31195:9195" - environment: - - TZ=Asia/Beijing - - shenyu.sync.etcd.url=http://shenyu-etcd:2379 - healthcheck: - test: [ "CMD-SHELL", "wget -q -O - http://shenyu-bootstrap:9195/actuator/health | grep UP || exit 1" ] - interval: 10s - timeout: 5s - retries: 15 - start_period: 30s - restart: always - depends_on: - shenyu-admin: - condition: service_healthy - networks: - - shenyu - -networks: - shenyu: - name: shenyu - driver: bridge - external: true diff --git a/shenyu-e2e/shenyu-e2e-case/k8s/shenyu-etcd.yml b/shenyu-e2e/shenyu-e2e-case/k8s/shenyu-etcd.yml deleted file mode 100644 index 15e4302e47d9..000000000000 --- a/shenyu-e2e/shenyu-e2e-case/k8s/shenyu-etcd.yml +++ /dev/null @@ -1,67 +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. - -apiVersion: apps/v1 -kind: Deployment -metadata: - name: shenyu-etcd - labels: - app: shenyu-etcd -spec: - replicas: 1 - selector: - matchLabels: - app: shenyu-etcd - strategy: { } - template: - metadata: - labels: - app: shenyu-etcd - spec: - containers: - - image: rancher/hardened-etcd:v3.5.21-k3s1-build20250910 - name: shenyu-etcd - command: ["etcd"] - resources: { } - env: - - name: ALLOW_NONE_AUTHENTICATION - value: "yes" - - name: ETCD_ADVERTISE_CLIENT_URLS - value: http://shenyu-etcd:2379 - - name: TZ - value: Asia/Shanghai - ports: - - containerPort: 2379 - name: client - - containerPort: 2380 - name: server - restartPolicy: Always - ---- -apiVersion: v1 -kind: Service -metadata: - name: shenyu-etcd - labels: - app: shenyu-etcd -spec: - type: NodePort - selector: - app: shenyu-etcd - ports: - - port: 2379 - targetPort: 2379 - nodePort: 32379 diff --git a/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-admin-etcd.yml b/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-admin-etcd.yml deleted file mode 100644 index fa6bb3d6a2b1..000000000000 --- a/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-admin-etcd.yml +++ /dev/null @@ -1,114 +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. - -apiVersion: apps/v1 -kind: Deployment -metadata: - name: shenyu-admin -spec: - selector: - matchLabels: - app: shenyu-admin - replicas: 1 - template: - metadata: - labels: - app: shenyu-admin - spec: - containers: - - name: shenyu-admin - image: apache/shenyu-admin:latest - args: - - -Xmx768m -Xms768m - imagePullPolicy: IfNotPresent - ports: - - containerPort: 9095 - livenessProbe: - initialDelaySeconds: 30 - periodSeconds: 10 - timeoutSeconds: 5 - successThreshold: 1 - failureThreshold: 3 - httpGet: - port: 9095 - path: /actuator/health - readinessProbe: - initialDelaySeconds: 30 - periodSeconds: 10 - timeoutSeconds: 5 - successThreshold: 1 - failureThreshold: 3 - httpGet: - port: 9095 - path: /actuator/health - env: - - name: 'TZ' - value: 'Asia/Beijing' - - name: SPRING_PROFILES_ACTIVE - value: mysql, admin-sync-etcd - - name: SHENYU_JWT_SECRETKEY - value: shenyu-e2e-jwt-secret-key-2024 - volumeMounts: - - name: mysql-connector-volume - mountPath: /opt/shenyu-admin/ext-lib - - name: shenyu-admin-application - mountPath: /opt/shenyu-admin/conf/application.yml - subPath: shenyu-admin-application.yml - - name: shenyu-admin-application-mysql - mountPath: /opt/shenyu-admin/conf/application-mysql.yml - subPath: shenyu-admin-application-mysql.yml - - name: shenyu-admin-sync-etcd - mountPath: /opt/shenyu-admin/conf/application-admin-sync-etcd.yml - subPath: application-admin-sync-etcd.yml - restartPolicy: Always - volumes: - - name: mysql-connector-volume - hostPath: - path: /tmp/shenyu-e2e/mysql/driver - - name: shenyu-admin-application - configMap: - name: shenyu-configmap - items: - - key: shenyu-admin-application.yml - path: shenyu-admin-application.yml - - name: shenyu-admin-application-mysql - configMap: - name: shenyu-configmap - items: - - key: shenyu-admin-application-mysql.yml - path: shenyu-admin-application-mysql.yml - - name: shenyu-admin-sync-etcd - configMap: - name: shenyu-configmap - items: - - key: application-admin-sync-etcd.yml - path: application-admin-sync-etcd.yml ---- -apiVersion: v1 -kind: Service -metadata: - name: shenyu-admin - labels: - app: shenyu-admin -spec: - type: NodePort - selector: - app: shenyu-admin - ports: - - name: "9095" - port: 9095 - targetPort: 9095 - nodePort: 31095 diff --git a/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-bootstrap-etcd.yml b/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-bootstrap-etcd.yml deleted file mode 100644 index 037c0e830580..000000000000 --- a/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-bootstrap-etcd.yml +++ /dev/null @@ -1,96 +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. - -# shenyu-bootstrap -apiVersion: apps/v1 -kind: Deployment -metadata: - name: shenyu-bootstrap -spec: - selector: - matchLabels: - app: shenyu-bootstrap - replicas: 1 - template: - metadata: - labels: - app: shenyu-bootstrap - spec: - containers: - - name: shenyu-bootstrap - image: apache/shenyu-bootstrap:latest - imagePullPolicy: IfNotPresent - ports: - - containerPort: 9195 - livenessProbe: - initialDelaySeconds: 30 - periodSeconds: 10 - timeoutSeconds: 5 - successThreshold: 1 - failureThreshold: 3 - httpGet: - port: 9195 - path: /actuator/health - readinessProbe: - initialDelaySeconds: 30 - periodSeconds: 10 - timeoutSeconds: 5 - successThreshold: 1 - failureThreshold: 3 - httpGet: - port: 9195 - path: /actuator/health - env: - - name: TZ - value: Asia/Beijing - - name: SPRING_PROFILES_ACTIVE - value: bootstrap-sync-etcd - volumeMounts: - - name: shenyu-bootstrap-application - mountPath: /opt/shenyu-bootstrap/conf/application.yml - subPath: shenyu-bootstrap-application.yml - - name: shenyu-bootstrap-sync-etcd - mountPath: /opt/shenyu-bootstrap/conf/application-bootstrap-sync-etcd.yml - subPath: application-bootstrap-sync-etcd.yml - volumes: - - name: shenyu-bootstrap-application - configMap: - name: shenyu-configmap - items: - - key: shenyu-bootstrap-application.yml - path: shenyu-bootstrap-application.yml - - name: shenyu-bootstrap-sync-etcd - configMap: - name: shenyu-configmap - items: - - key: application-bootstrap-sync-etcd.yml - path: application-bootstrap-sync-etcd.yml - ---- -apiVersion: v1 -kind: Service -metadata: - name: shenyu-bootstrap -spec: - selector: - app: shenyu-bootstrap - type: NodePort - ports: - - protocol: TCP - port: 9195 - targetPort: 9195 - nodePort: 31195 - diff --git a/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-cm.yml b/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-cm.yml index b332aabc3584..03acef5a435c 100644 --- a/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-cm.yml +++ b/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-cm.yml @@ -70,8 +70,8 @@ data: shenyu: register: - registerType: http #http #zookeeper #etcd #nacos #consul - serverLists: #localhost:2181 #http://localhost:2379 #localhost:8848 + registerType: http #http #zookeeper #nacos #consul + serverLists: #localhost:2181 #localhost:8848 props: sessionTimeout: 5000 connectionTimeout: 2000 @@ -362,8 +362,8 @@ data: - Access-Control-Allow-Origin register: enabled: false - registerType: zookeeper #etcd #consul - serverLists: localhost:2181 #http://localhost:2379 #localhost:8848 + registerType: zookeeper #consul + serverLists: localhost:2181 #localhost:8848 props: cross: enabled: true @@ -496,12 +496,6 @@ data: sessionTimeoutMilliseconds: 5000 connectionTimeoutMilliseconds: 2000 - application-admin-sync-etcd.yml: | - shenyu: - sync: - etcd: - url: http://shenyu-etcd:2379 - application-admin-sync-nacos.yml: | shenyu: sync: @@ -554,12 +548,6 @@ data: sessionTimeoutMilliseconds: 5000 connectionTimeoutMilliseconds: 2000 - application-bootstrap-sync-etcd.yml: | - shenyu: - sync: - etcd: - url: http://shenyu-etcd:2379 - application-bootstrap-sync-nacos.yml: | shenyu: sync: diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/compose/script/e2e-cluster-jdbc-compose.sh b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/compose/script/e2e-cluster-jdbc-compose.sh index 6e33dd10b86a..f5d4990ab03d 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/compose/script/e2e-cluster-jdbc-compose.sh +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/compose/script/e2e-cluster-jdbc-compose.sh @@ -25,9 +25,9 @@ CUR_PATH=$(readlink -f "$(dirname "$0")") PRGDIR=$(dirname "$CUR_PATH") # init shenyu sync SYNC_ARRAY=("websocket") -#SYNC_ARRAY=("websocket" "http" "zookeeper" "etcd") +#SYNC_ARRAY=("websocket" "http" "zookeeper") #SYNC_ARRAY=("websocket" "nacos") -#MIDDLEWARE_SYNC_ARRAY=("zookeeper" "etcd" "nacos") +#MIDDLEWARE_SYNC_ARRAY=("zookeeper" "nacos") docker network create -d bridge shenyu diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/compose/script/e2e-cluster-zookeeper-compose.sh b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/compose/script/e2e-cluster-zookeeper-compose.sh index c706f276e361..52b966952f71 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/compose/script/e2e-cluster-zookeeper-compose.sh +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/compose/script/e2e-cluster-zookeeper-compose.sh @@ -25,9 +25,9 @@ CUR_PATH=$(readlink -f "$(dirname "$0")") PRGDIR=$(dirname "$CUR_PATH") # init shenyu sync SYNC_ARRAY=("websocket") -#SYNC_ARRAY=("websocket" "http" "zookeeper" "etcd") +#SYNC_ARRAY=("websocket" "http" "zookeeper") #SYNC_ARRAY=("websocket" "nacos") -#MIDDLEWARE_SYNC_ARRAY=("zookeeper" "etcd" "nacos") +#MIDDLEWARE_SYNC_ARRAY=("zookeeper" "nacos") docker network create -d bridge shenyu diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-logging-kafka/compose/script/e2e-logging-kafka-compose.sh b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-logging-kafka/compose/script/e2e-logging-kafka-compose.sh index bedabb4b5092..eec80023385a 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-logging-kafka/compose/script/e2e-logging-kafka-compose.sh +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-logging-kafka/compose/script/e2e-logging-kafka-compose.sh @@ -29,7 +29,7 @@ PRGDIR=$(dirname "$CUR_PATH") # init shenyu sync SYNC_ARRAY=("websocket" "http" "zookeeper") #SYNC_ARRAY=("websocket" "nacos") -#MIDDLEWARE_SYNC_ARRAY=("zookeeper" "etcd" "nacos") +#MIDDLEWARE_SYNC_ARRAY=("zookeeper" "nacos") docker network create -d bridge shenyu diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/k8s/shenyu-cm.yml b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/k8s/shenyu-cm.yml index 168d96981cc2..13ce965a1207 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/k8s/shenyu-cm.yml +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/k8s/shenyu-cm.yml @@ -71,8 +71,8 @@ data: shenyu: register: - registerType: http #http #zookeeper #etcd #nacos #consul - serverLists: #localhost:2181 #http://localhost:2379 #localhost:8848 + registerType: http #http #zookeeper #nacos #consul + serverLists: #localhost:2181 #localhost:8848 props: sessionTimeout: 5000 connectionTimeout: 2000 @@ -339,8 +339,8 @@ data: # daemon: true register: enabled: false - registerType: zookeeper #etcd #consul - serverLists: localhost:2181 #http://localhost:2379 #localhost:8848 + registerType: zookeeper #consul + serverLists: localhost:2181 #localhost:8848 props: cross: enabled: true @@ -463,12 +463,6 @@ data: sessionTimeoutMilliseconds: 5000 connectionTimeoutMilliseconds: 2000 - application-admin-sync-etcd.yml: | - shenyu: - sync: - etcd: - url: http://shenyu-etcd:2379 - application-admin-sync-nacos.yml: | shenyu: sync: @@ -509,12 +503,6 @@ data: sessionTimeoutMilliseconds: 5000 connectionTimeoutMilliseconds: 2000 - application-bootstrap-sync-etcd.yml: | - shenyu: - sync: - etcd: - url: http://shenyu-etcd:2379 - application-bootstrap-sync-nacos.yml: | shenyu: sync: diff --git a/shenyu-examples/shenyu-examples-grpc/src/main/resources/application.yml b/shenyu-examples/shenyu-examples-grpc/src/main/resources/application.yml index d617177a8445..d30cc5a1d673 100644 --- a/shenyu-examples/shenyu-examples-grpc/src/main/resources/application.yml +++ b/shenyu-examples/shenyu-examples-grpc/src/main/resources/application.yml @@ -50,9 +50,6 @@ shenyu: # maxSleepTimeMilliseconds: 5000 # connectionTimeoutMilliseconds: 60000 # sessionTimeoutMilliseconds: 8 -# type: etcd -# serverList: http://127.0.0.1:2379 -# registerPath: shenyu_discovery_${spring.application.name} # type: eureka # serverList: http://127.0.0.1:8761/eureka # registerPath: shenyu_discovery_${spring.application.name} diff --git a/shenyu-examples/shenyu-examples-http-swagger3/src/main/resources/application.yml b/shenyu-examples/shenyu-examples-http-swagger3/src/main/resources/application.yml index fa8450561d08..047b1743053e 100644 --- a/shenyu-examples/shenyu-examples-http-swagger3/src/main/resources/application.yml +++ b/shenyu-examples/shenyu-examples-http-swagger3/src/main/resources/application.yml @@ -47,9 +47,6 @@ shenyu: # maxSleepTimeMilliseconds: 5000 # connectionTimeoutMilliseconds: 60000 # sessionTimeoutMilliseconds: 8 -# type: etcd -# serverList: http://127.0.0.1:2379 -# registerPath: shenyu_discovery_demo_${shenyu.client.http.props.appName} # type: eureka # serverList: http://127.0.0.1:8761/eureka # registerPath: shenyu_discovery_demo_http-swagger3 diff --git a/shenyu-examples/shenyu-examples-http/src/main/resources/application.yml b/shenyu-examples/shenyu-examples-http/src/main/resources/application.yml index 902cacfe460b..5f23037da5bd 100644 --- a/shenyu-examples/shenyu-examples-http/src/main/resources/application.yml +++ b/shenyu-examples/shenyu-examples-http/src/main/resources/application.yml @@ -46,9 +46,6 @@ shenyu: # maxSleepTimeMilliseconds: 5000 # connectionTimeoutMilliseconds: 60000 # sessionTimeoutMilliseconds: 8 -# type: etcd -# serverList: http://127.0.0.1:2379 -# registerPath: shenyu_discovery_http_example # type: eureka # serverList: http://127.0.0.1:8761/eureka # registerPath: shenyu_discovery_http_example diff --git a/shenyu-examples/shenyu-examples-sdk/shenyu-examples-sdk-dubbo/shenyu-examples-sdk-apache-dubbo-consumer/src/main/resources/application.yml b/shenyu-examples/shenyu-examples-sdk/shenyu-examples-sdk-dubbo/shenyu-examples-sdk-apache-dubbo-consumer/src/main/resources/application.yml index 0ecbc0082489..cf982ce3a281 100644 --- a/shenyu-examples/shenyu-examples-sdk/shenyu-examples-sdk-dubbo/shenyu-examples-sdk-apache-dubbo-consumer/src/main/resources/application.yml +++ b/shenyu-examples/shenyu-examples-sdk/shenyu-examples-sdk-dubbo/shenyu-examples-sdk-apache-dubbo-consumer/src/main/resources/application.yml @@ -34,8 +34,8 @@ shenyu: sdk: enabled: true - register-type: zookeeper #local #etcd #nacos #consul - server-lists: localhost:2181 #http://localhost:9095 #http://localhost:2379 #localhost:8848 + register-type: zookeeper #local #nacos #consul + server-lists: localhost:2181 #http://localhost:9095 #localhost:8848 spring: servlet: diff --git a/shenyu-examples/shenyu-examples-springcloud/README.md b/shenyu-examples/shenyu-examples-springcloud/README.md index f83b1a2e8101..b35e963b09fc 100644 --- a/shenyu-examples/shenyu-examples-springcloud/README.md +++ b/shenyu-examples/shenyu-examples-springcloud/README.md @@ -1,41 +1,10 @@ -# Shenyu example SpringCloud -*** -## Run -first you should run eureka: shenyu-example-eureka +# ShenYu example Spring Cloud -Then you can run server with http/zookeeper/etcd register center +Start Eureka with `shenyu-example-eureka`, then run `ShenyuTestSpringCloudApplication` +using the configured HTTP client registration channel. -### run with etcd register center -#### Shenyu-Admin config -add etcd register center dependency in shenyu-admin: - -```xml - - org.apache.shenyu - shenyu-register-server-etcd - ${project.version} - -``` - -set etcd register config in shenyu-admin: - -```yaml -shenyu: - register: - registerType: etcd - serverLists : http://localhost:2379 -``` - -#### shenyu-examples-springcloud config -set etcd register config: - -```yaml -shenyu: - client: - registerType: etcd - serverLists: http://localhost:2379 - props: - contextPath: /springcloud -``` - -run ShenyuTestSpringCloudApplication +etcd data synchronization and gateway/SDK instance discovery are external integrations; +see the [plugin-store migration guide](../../docs/plugin-store-etcd.md) for artifacts, +configuration and rollback. Client HTTP API registration remains a separate channel. +The former etcd client/server registration example is archived in plugin-store's +`examples/etcd/legacy` for the pre-cutover release. diff --git a/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-annotation-websocket/src/main/resources/application.yml b/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-annotation-websocket/src/main/resources/application.yml index e5230e846c82..3b40dea211ea 100644 --- a/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-annotation-websocket/src/main/resources/application.yml +++ b/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-annotation-websocket/src/main/resources/application.yml @@ -43,9 +43,6 @@ shenyu: # maxSleepTimeMilliseconds: 5000 # connectionTimeoutMilliseconds: 60000 # sessionTimeoutMilliseconds: 8 - # type: etcd - # serverList: http://127.0.0.1:2379 - # registerPath: shenyu_discovery_http_example # type: eureka # serverList: http://127.0.0.1:8761/eureka # registerPath: shenyu_discovery_http_example diff --git a/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-native-websocket/src/main/resources/application.yml b/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-native-websocket/src/main/resources/application.yml index 74bbe91c4ee2..b28d1a6db835 100644 --- a/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-native-websocket/src/main/resources/application.yml +++ b/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-native-websocket/src/main/resources/application.yml @@ -51,9 +51,6 @@ shenyu: # maxSleepTimeMilliseconds: 5000 # connectionTimeoutMilliseconds: 60000 # sessionTimeoutMilliseconds: 8 -# type: etcd -# serverList: http://127.0.0.1:2379 -# registerPath: shenyu_discovery_http_example # type: eureka # serverList: http://127.0.0.1:8761/eureka # registerPath: shenyu_discovery_http_example diff --git a/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-reactive-websocket/src/main/resources/application.yml b/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-reactive-websocket/src/main/resources/application.yml index 68725f10ae3a..645716cda918 100644 --- a/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-reactive-websocket/src/main/resources/application.yml +++ b/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-reactive-websocket/src/main/resources/application.yml @@ -43,9 +43,6 @@ shenyu: # maxSleepTimeMilliseconds: 5000 # connectionTimeoutMilliseconds: 60000 # sessionTimeoutMilliseconds: 8 - # type: etcd - # serverList: http://127.0.0.1:2379 - # registerPath: shenyu_discovery_http_example # type: eureka # serverList: http://127.0.0.1:8761/eureka # registerPath: shenyu_discovery_http_example diff --git a/shenyu-infra/pom.xml b/shenyu-infra/pom.xml index a7807279cb0a..63b6af505ed3 100644 --- a/shenyu-infra/pom.xml +++ b/shenyu-infra/pom.xml @@ -28,7 +28,6 @@ shenyu-infra-common - shenyu-infra-etcd shenyu-infra-nacos shenyu-infra-redis shenyu-infra-zookeeper diff --git a/shenyu-infra/shenyu-infra-etcd/pom.xml b/shenyu-infra/shenyu-infra-etcd/pom.xml deleted file mode 100644 index a5ce2c433286..000000000000 --- a/shenyu-infra/shenyu-infra-etcd/pom.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - org.apache.shenyu - shenyu-infra - 2.7.3-SNAPSHOT - - 4.0.0 - shenyu-infra-etcd - - - - - org.apache.shenyu - shenyu-infra-common - ${project.version} - - - - io.etcd - jetcd-core - - - grpc-netty - io.grpc - - - grpc-protobuf - io.grpc - - - grpc-stub - io.grpc - - - - - - io.grpc - grpc-core - ${grpc.version} - - - - grpc-protobuf - io.grpc - ${grpc.version} - - - - grpc-stub - io.grpc - ${grpc.version} - - - - grpc-netty - io.grpc - ${grpc.version} - - - - - org.springframework.boot - spring-boot-test - test - - - - - diff --git a/shenyu-infra/shenyu-infra-etcd/src/main/java/org/apache/shenyu/infra/etcd/autoconfig/ConditionOnSyncEtcd.java b/shenyu-infra/shenyu-infra-etcd/src/main/java/org/apache/shenyu/infra/etcd/autoconfig/ConditionOnSyncEtcd.java deleted file mode 100644 index 45a85c5b3863..000000000000 --- a/shenyu-infra/shenyu-infra-etcd/src/main/java/org/apache/shenyu/infra/etcd/autoconfig/ConditionOnSyncEtcd.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.shenyu.infra.etcd.autoconfig; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Enable etcd data sync. - */ - -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Inherited -@ConditionalOnProperty(prefix = EtcdProperties.CONFIG_PREFIX, name = "url") -public @interface ConditionOnSyncEtcd { -} diff --git a/shenyu-infra/shenyu-infra-etcd/src/main/java/org/apache/shenyu/infra/etcd/autoconfig/EtcdConfiguration.java b/shenyu-infra/shenyu-infra-etcd/src/main/java/org/apache/shenyu/infra/etcd/autoconfig/EtcdConfiguration.java deleted file mode 100644 index d3c55a93fef2..000000000000 --- a/shenyu-infra/shenyu-infra-etcd/src/main/java/org/apache/shenyu/infra/etcd/autoconfig/EtcdConfiguration.java +++ /dev/null @@ -1,70 +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.shenyu.infra.etcd.autoconfig; - -import io.etcd.jetcd.Client; -import org.apache.shenyu.infra.etcd.client.EtcdClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.util.Objects; - -@Configuration -@ConditionOnSyncEtcd -@ConditionalOnClass(Client.class) -@EnableConfigurationProperties(EtcdProperties.class) -public class EtcdConfiguration { - - private static final Logger log = LoggerFactory.getLogger(EtcdConfiguration.class); - - private static final Integer DEFAULT_SESSION_TIMEOUT = 30 * 1000; - - private static final Integer DEFAULT_CONNECT_TIMEOUT = 30 * 1000; - - /** - * Init etcd client. - * - * @param etcdProperties etcd properties - * @return Etcd Client - */ - @Bean - @ConditionalOnMissingBean - public EtcdClient etcdClient(final EtcdProperties etcdProperties) { - - log.info("Initializing Etcd Client with URL: {}", etcdProperties.getEtcd()); - - int timeout = Objects.isNull(etcdProperties.getEtcd().getSessionTimeout()) ? DEFAULT_SESSION_TIMEOUT : etcdProperties.getEtcd().getSessionTimeout(); - int ttl = Objects.isNull(etcdProperties.getEtcd().getConnectionTimeout()) ? DEFAULT_CONNECT_TIMEOUT : etcdProperties.getEtcd().getConnectionTimeout(); - - return EtcdClient.builder() - .client( - Client.builder() - .endpoints(etcdProperties.getEtcd().getUrl().split(",")) - .build() - ) - .timeout(timeout) - .ttl(ttl) - .build(); - } - -} diff --git a/shenyu-infra/shenyu-infra-etcd/src/main/java/org/apache/shenyu/infra/etcd/autoconfig/EtcdProperties.java b/shenyu-infra/shenyu-infra-etcd/src/main/java/org/apache/shenyu/infra/etcd/autoconfig/EtcdProperties.java deleted file mode 100644 index 5697f30571f7..000000000000 --- a/shenyu-infra/shenyu-infra-etcd/src/main/java/org/apache/shenyu/infra/etcd/autoconfig/EtcdProperties.java +++ /dev/null @@ -1,43 +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.shenyu.infra.etcd.autoconfig; - -import org.apache.shenyu.common.constant.Constants; -import org.apache.shenyu.infra.common.InfraConstants; -import org.apache.shenyu.infra.common.InfraParentProperties; -import org.apache.shenyu.infra.etcd.config.EtcdConfig; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.NestedConfigurationProperty; - -@ConfigurationProperties(InfraParentProperties.PARENT_CONFIG_PREFIX) -public class EtcdProperties extends InfraParentProperties { - - public static final String CONFIG_PREFIX = PARENT_CONFIG_PREFIX + Constants.DOT + InfraConstants.SHENYU_ETCD; - - @NestedConfigurationProperty - private EtcdConfig etcd = EtcdConfig.builder().build(); - - public EtcdConfig getEtcd() { - return etcd; - } - - public void setEtcd(final EtcdConfig etcd) { - this.etcd = etcd; - } - -} diff --git a/shenyu-infra/shenyu-infra-etcd/src/main/java/org/apache/shenyu/infra/etcd/client/EtcdClient.java b/shenyu-infra/shenyu-infra-etcd/src/main/java/org/apache/shenyu/infra/etcd/client/EtcdClient.java deleted file mode 100644 index 6ea02a6ed8d7..000000000000 --- a/shenyu-infra/shenyu-infra-etcd/src/main/java/org/apache/shenyu/infra/etcd/client/EtcdClient.java +++ /dev/null @@ -1,548 +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.shenyu.infra.etcd.client; - -import io.etcd.jetcd.ByteSequence; -import io.etcd.jetcd.Client; -import io.etcd.jetcd.KV; -import io.etcd.jetcd.KeyValue; -import io.etcd.jetcd.Watch; -import io.etcd.jetcd.kv.GetResponse; -import io.etcd.jetcd.lease.LeaseKeepAliveResponse; -import io.etcd.jetcd.options.DeleteOption; -import io.etcd.jetcd.options.GetOption; -import io.etcd.jetcd.options.PutOption; -import io.etcd.jetcd.options.WatchOption; -import io.etcd.jetcd.watch.WatchEvent; -import io.grpc.stub.StreamObserver; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.shenyu.common.exception.ShenyuException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.stream.Collectors; - -import static java.nio.charset.StandardCharsets.UTF_8; - -/** - * Etcd client of Bootstrap. - */ -public class EtcdClient { - - private static final Logger LOG = LoggerFactory.getLogger(EtcdClient.class); - - private static final int MAX_RETRY_DELAY_SECONDS = 60; - - private static final int INITIAL_RETRY_DELAY_SECONDS = 1; - - private final Client client; - - private final long ttl; - - private final long timeout; - - private long globalLeaseId; - - private final ConcurrentHashMap watchCache = new ConcurrentHashMap<>(); - - private final ConcurrentHashMap watchChildCache = new ConcurrentHashMap<>(); - - private volatile boolean keepAliveRunning = true; - - private volatile StreamObserver currentObserver; - - private final ScheduledExecutorService retryExecutor; - - private volatile ScheduledFuture retryFuture; - - private final AtomicInteger retryCount = new AtomicInteger(0); - - public EtcdClient(final Client client, final long ttl, final long timeout) { - - this.ttl = ttl; - this.timeout = timeout; - this.client = client; - this.retryExecutor = new ScheduledThreadPoolExecutor(1, r -> { - Thread thread = new Thread(r, "etcd-keepalive-retry"); - thread.setDaemon(true); - return thread; - }); - - initLease(); - } - - /** - * close client. - */ - public void close() { - keepAliveRunning = false; - if (Objects.nonNull(retryFuture)) { - retryFuture.cancel(false); - } - retryExecutor.shutdown(); - try { - if (!retryExecutor.awaitTermination(5, TimeUnit.SECONDS)) { - retryExecutor.shutdownNow(); - } - } catch (InterruptedException e) { - retryExecutor.shutdownNow(); - Thread.currentThread().interrupt(); - } - this.client.close(); - } - - /** - * get node value. - * - * @param key node name - * @return string - */ - public String get(final String key) { - List keyValues = null; - try { - keyValues = client.getKVClient().get(bytesOf(key)).get().getKvs(); - } catch (InterruptedException | ExecutionException e) { - LOG.error("get key error, key:{}", key, e); - } - - if (CollectionUtils.isEmpty(keyValues)) { - LOG.warn("get key {} is empty", key); - return null; - } - return keyValues.iterator().next().getValue().toString(UTF_8); - } - - /** - * get keys by prefix. - * - * @param prefix key prefix. - * @return key valuesMap. - */ - public Map getKeysMapByPrefix(final String prefix) { - GetOption getOption = GetOption.newBuilder() - .isPrefix(true) - .build(); - try { - return this.client.getKVClient().get(bytesOf(prefix), getOption) - .get().getKvs().stream() - .collect(Collectors.toMap(e -> e.getKey().toString(UTF_8), e -> e.getValue().toString(UTF_8))); - } catch (ExecutionException | InterruptedException e) { - LOG.error("etcd getKeysMapByPrefix key {} error", prefix, e); - throw new ShenyuException(e); - } - - } - - /** - * bytesOf string. - * - * @param val val. - * @return bytes val. - */ - public ByteSequence bytesOf(final String val) { - return ByteSequence.from(val, UTF_8); - } - - /** - * get node sub nodes. - * - * @param prefix node prefix. - * @param separator separator char - * @return sub nodes - * @throws ExecutionException the exception - * @throws InterruptedException the exception - */ - public List getChildrenKeys(final String prefix, final String separator) - throws ExecutionException, InterruptedException { - ByteSequence prefixByteSequence = bytesOf(prefix); - GetOption getOption = GetOption.newBuilder() - .withPrefix(prefixByteSequence) - .withSortField(GetOption.SortTarget.KEY) - .withSortOrder(GetOption.SortOrder.ASCEND) - .build(); - - List keyValues = client.getKVClient() - .get(prefixByteSequence, getOption) - .get() - .getKvs(); - - return keyValues.stream() - .map(e -> getSubNodeKeyName(prefix, e.getKey().toString(UTF_8), separator)) - .distinct() - .filter(Objects::nonNull) - .collect(Collectors.toList()); - } - - /** - * get keyPrefix map. - * - * @param prefix key prefix. - * @param separator separator char - * @param map prefix map - * @return sub map - */ - public List getChildrenKeysByMap(final String prefix, final String separator, - final Map map) { - - return map.entrySet().stream() - .filter(e -> e.getKey().contains(prefix)) - .map(e -> getSubNodeKeyName(prefix, e.getKey(), separator)) - .distinct() - .filter(Objects::nonNull) - .collect(Collectors.toList()); - } - - private String getSubNodeKeyName(final String prefix, final String fullPath, final String separator) { - if (prefix.length() > fullPath.length()) { - return null; - } - String pathWithoutPrefix = fullPath.substring(prefix.length()); - return pathWithoutPrefix.contains(separator) ? pathWithoutPrefix.substring(1) : pathWithoutPrefix; - } - - /** - * subscribe data change. - * - * @param key node name - * @param updateHandler node value handler of update - * @param deleteHandler node value handler of delete - */ - public void watchDataChange(final String key, - final BiConsumer updateHandler, - final Consumer deleteHandler) { - Watch.Listener listener = watch(updateHandler, deleteHandler); - if (!watchCache.containsKey(key)) { - Watch.Watcher watch = client.getWatchClient().watch(ByteSequence.from(key, UTF_8), listener); - watchCache.put(key, watch); - } - } - - /** - * subscribe sub node change. - * - * @param key param node name. - * @param updateHandler sub node handler of update - * @param deleteHandler sub node delete of delete - */ - public void watchChildChange(final String key, - final BiConsumer updateHandler, - final Consumer deleteHandler) { - Watch.Listener listener = watch(updateHandler, deleteHandler); - WatchOption option = WatchOption.newBuilder() - .withPrefix(ByteSequence.from(key, UTF_8)) - .build(); - if (!watchChildCache.containsKey(key)) { - Watch.Watcher watch = client.getWatchClient().watch(ByteSequence.from(key, UTF_8), option, listener); - watchChildCache.put(key, watch); - } - } - - private Watch.Listener watch(final BiConsumer updateHandler, - final Consumer deleteHandler) { - return Watch.listener(response -> { - for (WatchEvent event : response.getEvents()) { - String path = event.getKeyValue().getKey().toString(UTF_8); - String value = event.getKeyValue().getValue().toString(UTF_8); - switch (event.getEventType()) { - case PUT: - Optional.ofNullable(updateHandler).ifPresent(handler -> handler.accept(path, value)); - continue; - case DELETE: - Optional.ofNullable(deleteHandler).ifPresent(handler -> handler.accept(path)); - continue; - default: - } - } - }, throwable -> { - LOG.error("etcd watch error {}", throwable.getMessage(), throwable); - throw new ShenyuException(throwable); - }); - } - - /** - * cancel subscribe. - * - * @param key node name - */ - public void watchClose(final String key) { - if (watchCache.containsKey(key)) { - watchCache.get(key).close(); - watchCache.remove(key); - } - if (watchChildCache.containsKey(key)) { - watchChildCache.get(key).close(); - watchChildCache.remove(key); - } - } - - /** - * check node exists. - * - * @param key node name - * @return bool - */ - public Boolean exists(final String key) { - try { - GetOption option = GetOption.newBuilder() - .withPrefix(ByteSequence.from(key, StandardCharsets.UTF_8)) - .build(); - List keyValues = client.getKVClient().get(ByteSequence.from(key, StandardCharsets.UTF_8), option) - .get().getKvs(); - return !keyValues.isEmpty(); - } catch (Exception e) { - LOG.error("check node exists error", e); - throw new ShenyuException(e); - } - } - - /** - * update value of node. - * - * @param key node name - * @param value node value - */ - public void put(final String key, final String value) { - try { - client.getKVClient().put(ByteSequence.from(key, StandardCharsets.UTF_8), - ByteSequence.from(value, StandardCharsets.UTF_8)).get(); - } catch (Exception e) { - LOG.error("update value of node error.", e); - throw new ShenyuException(e); - } - } - - /** - * delete node. - * - * @param key node name - */ - public void delete(final String key) { - client.getKVClient().delete(ByteSequence.from(key, StandardCharsets.UTF_8)); - } - - /** - * delete node of recursive. - * - * @param path parent node name - */ - public void deleteEtcdPathRecursive(final String path) { - DeleteOption option = DeleteOption.newBuilder() - .withPrefix(ByteSequence.from(path, StandardCharsets.UTF_8)) - .build(); - try { - client.getKVClient().delete(ByteSequence.from(path, StandardCharsets.UTF_8), option).get(10, - TimeUnit.SECONDS); - } catch (Exception e) { - LOG.error("delete node of recursive error.", e); - throw new ShenyuException(e); - } - } - - /** - * watchKeyChanges. - * - * @param key key - * @param listener listener - * @return {@link Watch.Watcher} - */ - public Watch.Watcher watchKeyChanges(final String key, final Watch.Listener listener) { - WatchOption option = WatchOption.newBuilder().isPrefix(true).build(); - - return client.getWatchClient().watch(bytesOf(key), option, listener); - } - - /** - * get keyResponse. - * - * @param key watch key. - * @param getOption get option. - * @return key response. - */ - public GetResponse getRange(final String key, final GetOption getOption) { - try { - return this.client.getKVClient().get(bytesOf(key), getOption).get(); - } catch (ExecutionException | InterruptedException e) { - LOG.error("etcd getRange key {} error", key, e); - throw new ShenyuException(e); - } - } - - /** - * put data as ephemeral. - * - * @param key key - * @param value value - */ - public void putEphemeral(final String key, final String value) { - try { - KV kvClient = client.getKVClient(); - kvClient.put(ByteSequence.from(key, UTF_8), ByteSequence.from(value, UTF_8), - PutOption.newBuilder().withLeaseId(globalLeaseId).build()) - .get(timeout, TimeUnit.MILLISECONDS); - } catch (InterruptedException | ExecutionException | TimeoutException e) { - LOG.error("putEphemeral(key:{},value:{}) error.", key, value, e); - throw new ShenyuException(e); - } - } - - private void initLease() { - try { - this.globalLeaseId = client.getLeaseClient().grant(ttl).get().getID(); - keepAlive(); - } catch (InterruptedException e) { - LOG.error("initLease error.", e); - Thread.currentThread().interrupt(); - throw new ShenyuException(e); - } catch (ExecutionException e) { - LOG.error("initLease error.", e); - throw new ShenyuException(e); - } - } - - private void keepAlive() { - if (!keepAliveRunning) { - return; - } - retryCount.set(0); - scheduleRetryInternal(0); - } - - private void scheduleRetry() { - int attempt = retryCount.incrementAndGet(); - scheduleRetryInternal(attempt); - } - - private void scheduleRetryInternal(final int attempt) { - if (!keepAliveRunning) { - return; - } - - if (Objects.nonNull(retryFuture) && !retryFuture.isDone()) { - retryFuture.cancel(false); - } - - long delaySeconds; - if (attempt <= 0) { - delaySeconds = 0; - } else { - long backoffFactor = 1L << Math.min(Math.max(attempt - 1, 0), 6); - delaySeconds = Math.min(INITIAL_RETRY_DELAY_SECONDS * backoffFactor, MAX_RETRY_DELAY_SECONDS); - } - - retryFuture = retryExecutor.schedule(() -> { - if (!keepAliveRunning) { - return; - } - - currentObserver = new StreamObserver<>() { - @Override - public void onNext(final LeaseKeepAliveResponse leaseKeepAliveResponse) { - retryCount.set(0); - } - - @Override - public void onError(final Throwable throwable) { - LOG.error("keep alive error", throwable); - currentObserver = null; - scheduleRetry(); - } - - @Override - public void onCompleted() { - LOG.warn("keep alive stream completed"); - currentObserver = null; - scheduleRetry(); - } - }; - - try { - client.getLeaseClient().keepAlive(globalLeaseId, currentObserver); - } catch (Exception e) { - LOG.error("Failed to start keep alive", e); - currentObserver = null; - scheduleRetry(); - } - }, delaySeconds, TimeUnit.SECONDS); - - LOG.debug("Scheduled keep alive retry in {} seconds (attempt: {})", delaySeconds, attempt); - } - - /** - * Create a new {@link Builder} instance for building an {@link EtcdClient}. - * - * @return a new {@link Builder} instance - */ - public static Builder builder() { - - return Builder.builder(); - } - - public static final class Builder { - - /** - * etcd client. - */ - private Client client; - - private long ttl = 60; - - private long timeout = 5000; - - private Builder() { - } - - private static Builder builder() { - return new Builder(); - } - - public Builder client(final Client client) { - this.client = client; - return this; - } - - public Builder ttl(final long ttl) { - this.ttl = ttl; - return this; - } - - public Builder timeout(final long timeout) { - this.timeout = timeout; - return this; - } - - public EtcdClient build() { - return new EtcdClient(client, ttl, timeout); - } - } - -} diff --git a/shenyu-infra/shenyu-infra-etcd/src/main/java/org/apache/shenyu/infra/etcd/config/EtcdConfig.java b/shenyu-infra/shenyu-infra-etcd/src/main/java/org/apache/shenyu/infra/etcd/config/EtcdConfig.java deleted file mode 100644 index 5d1541339e78..000000000000 --- a/shenyu-infra/shenyu-infra-etcd/src/main/java/org/apache/shenyu/infra/etcd/config/EtcdConfig.java +++ /dev/null @@ -1,173 +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.shenyu.infra.etcd.config; - -import java.util.StringJoiner; - -/** - * The type etcd configuration. - */ -public class EtcdConfig { - - private String url; - - private Integer sessionTimeout; - - private Integer connectionTimeout; - - private String serializer; - - public EtcdConfig(final String url, final Integer session, - final Integer connection, final String serializer) { - - this.url = url; - this.sessionTimeout = session; - this.connectionTimeout = connection; - this.serializer = serializer; - } - - /** - * Get url. - * - * @return url - */ - public String getUrl() { - return url; - } - - /** - * Set url. - * - * @param url url - */ - public void setUrl(final String url) { - this.url = url; - } - - /** - * Get sessionTimeout. - * - * @return sessionTimeout - */ - public Integer getSessionTimeout() { - return sessionTimeout; - } - - /** - * Set sessionTimeout. - * - * @param sessionTimeout sessionTimeout - */ - public void setSessionTimeout(final Integer sessionTimeout) { - this.sessionTimeout = sessionTimeout; - } - - /** - * Get connectionTimeout. - * - * @return connectionTimeout - */ - public Integer getConnectionTimeout() { - return connectionTimeout; - } - - /** - * Set connectionTimeout. - * - * @param connectionTimeout connectionTimeout - */ - public void setConnectionTimeout(final Integer connectionTimeout) { - this.connectionTimeout = connectionTimeout; - } - - /** - * Get serializer. - * - * @return serializer - */ - public String getSerializer() { - return serializer; - } - - /** - * Set serializer. - * - * @param serializer serializer - */ - public void setSerializer(final String serializer) { - this.serializer = serializer; - } - - @Override - public String toString() { - return new StringJoiner(", ", EtcdConfig.class.getSimpleName() + "[", "]") - .add("url='" + url + "'") - .add("sessionTimeout=" + sessionTimeout) - .add("connectionTimeout=" + connectionTimeout) - .add("serializer='" + serializer + "'") - .toString(); - } - - public static Builder builder() { - - return new Builder(); - } - - public static final class Builder { - - private String url; - - private Integer sessionTimeout; - - private Integer connectionTimeout; - - private String serializer; - - /** - * private constructor. not allow to create instance. - */ - private Builder() { - } - - public Builder url(final String url) { - this.url = url; - return this; - } - - public Builder sessionTimeout(final Integer sessionTimeout) { - this.sessionTimeout = sessionTimeout; - return this; - } - - public Builder connectionTimeout(final Integer connectionTimeout) { - this.connectionTimeout = connectionTimeout; - return this; - } - - public Builder serializer(final String serializer) { - this.serializer = serializer; - return this; - } - - public EtcdConfig build() { - - return new EtcdConfig(url, sessionTimeout, connectionTimeout, serializer); - } - } - -} diff --git a/shenyu-infra/shenyu-infra-etcd/src/main/resources/META-INF/spring.factories b/shenyu-infra/shenyu-infra-etcd/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 8ddda596152a..000000000000 --- a/shenyu-infra/shenyu-infra-etcd/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,19 +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.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.apache.shenyu.infra.etcd.autoconfig.EtcdConfiguration diff --git a/shenyu-infra/shenyu-infra-etcd/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/shenyu-infra/shenyu-infra-etcd/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 060f974eca67..000000000000 --- a/shenyu-infra/shenyu-infra-etcd/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /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.shenyu.infra.etcd.autoconfig.EtcdConfiguration diff --git a/shenyu-infra/shenyu-infra-etcd/src/test/java/org/apache/shenyu/infra/etcd/client/EtcdClientTest.java b/shenyu-infra/shenyu-infra-etcd/src/test/java/org/apache/shenyu/infra/etcd/client/EtcdClientTest.java deleted file mode 100644 index 7f9da1ad1cda..000000000000 --- a/shenyu-infra/shenyu-infra-etcd/src/test/java/org/apache/shenyu/infra/etcd/client/EtcdClientTest.java +++ /dev/null @@ -1,242 +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.shenyu.infra.etcd.client; - -import io.etcd.jetcd.Client; -import io.etcd.jetcd.ClientBuilder; -import io.etcd.jetcd.KV; -import io.etcd.jetcd.Lease; -import io.etcd.jetcd.kv.PutResponse; -import io.etcd.jetcd.lease.LeaseGrantResponse; -import io.etcd.jetcd.lease.LeaseKeepAliveResponse; -import io.grpc.stub.StreamObserver; -import org.apache.shenyu.common.exception.ShenyuException; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.mockito.MockedStatic; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.mockStatic; -import static org.mockito.Mockito.when; - -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.junit.jupiter.MockitoExtension; -import org.mockito.junit.jupiter.MockitoSettings; -import org.mockito.quality.Strictness; - -@MockitoSettings(strictness = Strictness.LENIENT) -@ExtendWith(MockitoExtension.class) -public class EtcdClientTest { - - @Test - public void etcdClientTest() { - try (MockedStatic clientMockedStatic = mockStatic(Client.class)) { - final ClientBuilder clientBuilder = mock(ClientBuilder.class); - clientMockedStatic.when(Client::builder).thenReturn(clientBuilder); - when(clientBuilder.endpoints(anyString())).thenReturn(clientBuilder); - final Client client = mock(Client.class); - when(clientBuilder.endpoints(anyString()).build()).thenReturn(client); - final Lease lease = mock(Lease.class); - when(client.getLeaseClient()).thenReturn(lease); - final CompletableFuture completableFuture = mock(CompletableFuture.class); - final LeaseGrantResponse leaseGrantResponse = mock(LeaseGrantResponse.class); - when(leaseGrantResponse.getID()).thenReturn(1L); - - when(client.getLeaseClient().grant(anyLong())).thenReturn(completableFuture); - when(completableFuture.get()).thenReturn(leaseGrantResponse); - List> observerList = new ArrayList<>(); - doAnswer(invocation -> { - observerList.add(invocation.getArgument(1)); - return lease; - }).when(lease).keepAlive(anyLong(), any()); - - final EtcdClient etcdClient = Assertions.assertDoesNotThrow(() -> EtcdClient.builder() - .client(Client.builder().endpoints("url").build()) - .ttl(60L) - .timeout(3000L) - .build()); - Assertions.assertNotNull(etcdClient); - - final LeaseKeepAliveResponse leaseKeepAliveResponse = mock(LeaseKeepAliveResponse.class); - observerList.forEach(streamObserver -> { - streamObserver.onCompleted(); - streamObserver.onError(new ShenyuException("test")); - streamObserver.onNext(leaseKeepAliveResponse); - }); - etcdClient.close(); - - doThrow(new InterruptedException("error")).when(completableFuture).get(); - Assertions.assertThrows(ShenyuException.class, () -> EtcdClient.builder() - .client(Client.builder().endpoints("url").build()) - .ttl(60L) - .timeout(3000L) - .build()); - } catch (Exception e) { - throw new ShenyuException(e.getCause()); - } - } - - @Test - public void keepAliveRetryTest() throws ExecutionException, InterruptedException { - try (MockedStatic clientMockedStatic = mockStatic(Client.class)) { - final Client client = this.mockEtcd(clientMockedStatic); - final Lease lease = client.getLeaseClient(); - - AtomicInteger keepAliveInvoked = new AtomicInteger(0); - CountDownLatch latch = new CountDownLatch(2); - CountDownLatch firstCallLatch = new CountDownLatch(1); - List> observerList = new ArrayList<>(); - - doAnswer(invocation -> { - keepAliveInvoked.incrementAndGet(); - latch.countDown(); - firstCallLatch.countDown(); - observerList.add(invocation.getArgument(1)); - return lease; - }).when(lease).keepAlive(anyLong(), any()); - - final EtcdClient etcdClient = EtcdClient.builder() - .client(Client.builder().endpoints("url").build()) - .ttl(60L) - .timeout(3000L) - .build(); - Assertions.assertNotNull(etcdClient); - - // Wait for the initial keepAlive registration to complete - Assertions.assertTrue(firstCallLatch.await(2, TimeUnit.SECONDS), "Initial keepAlive should run"); - awaitObserverRegistered(observerList); - - // Trigger error to schedule retry keep-alive - observerList.get(0).onError(new RuntimeException("test-error")); - - boolean retried = latch.await(3, TimeUnit.SECONDS); - etcdClient.close(); - - Assertions.assertTrue(retried, "keepAlive should retry after onError"); - Assertions.assertTrue(keepAliveInvoked.get() >= 2, "Expected retry keepAlive invocation"); - } - } - - @Test - public void keepAliveCompletedRetryTest() throws ExecutionException, InterruptedException { - try (MockedStatic clientMockedStatic = mockStatic(Client.class)) { - final Client client = this.mockEtcd(clientMockedStatic); - final Lease lease = client.getLeaseClient(); - - AtomicInteger keepAliveInvoked = new AtomicInteger(0); - CountDownLatch callsLatch = new CountDownLatch(2); - CountDownLatch firstCallLatch = new CountDownLatch(1); - List> observerList = new ArrayList<>(); - - doAnswer(invocation -> { - keepAliveInvoked.incrementAndGet(); - callsLatch.countDown(); - firstCallLatch.countDown(); - observerList.add(invocation.getArgument(1)); - return lease; - }).when(lease).keepAlive(anyLong(), any()); - - final EtcdClient etcdClient = EtcdClient.builder() - .client(Client.builder().endpoints("url").build()) - .ttl(60L) - .timeout(3000L) - .build(); - Assertions.assertNotNull(etcdClient); - - Assertions.assertTrue(firstCallLatch.await(2, TimeUnit.SECONDS), "Initial keepAlive should run"); - awaitObserverRegistered(observerList); - - observerList.get(0).onCompleted(); - - boolean retried = callsLatch.await(3, TimeUnit.SECONDS); - etcdClient.close(); - - Assertions.assertTrue(retried, "keepAlive should retry after onCompleted"); - Assertions.assertTrue(keepAliveInvoked.get() >= 2, "Expected keepAlive invocation after completion"); - } - } - - @Test - public void closeTest() { - try (MockedStatic clientMockedStatic = mockStatic(Client.class)) { - this.mockEtcd(clientMockedStatic); - final EtcdClient etcdClient = EtcdClient.builder().client(Client.builder().endpoints("url").build()).ttl(60L).timeout(3000L).build(); - etcdClient.close(); - } catch (Exception e) { - throw new ShenyuException(e.getCause()); - } - } - - @Test - public void putEphemeralTest() { - try (MockedStatic clientMockedStatic = mockStatic(Client.class)) { - final Client client = this.mockEtcd(clientMockedStatic); - final KV mockKV = mock(KV.class); - when(client.getKVClient()).thenReturn(mockKV); - final CompletableFuture completableFuture = mock(CompletableFuture.class); - when(mockKV.put(any(), any(), any())).thenReturn(completableFuture); - final PutResponse putResponse = mock(PutResponse.class); - when(completableFuture.get(anyLong(), any(TimeUnit.class))).thenReturn(putResponse); - final EtcdClient etcdClient = EtcdClient.builder().client(Client.builder().endpoints("url").build()).ttl(60L).timeout(3000L).build(); - etcdClient.putEphemeral("key", "value"); - - doThrow(new InterruptedException("error")).when(completableFuture).get(anyLong(), any(TimeUnit.class)); - Assertions.assertThrows(ShenyuException.class, () -> etcdClient.putEphemeral("key", "value")); - } catch (Exception e) { - throw new ShenyuException(e.getCause()); - } - } - - private Client mockEtcd(final MockedStatic clientMockedStatic) throws InterruptedException, ExecutionException { - final ClientBuilder clientBuilder = mock(ClientBuilder.class); - clientMockedStatic.when(Client::builder).thenReturn(clientBuilder); - when(clientBuilder.endpoints(anyString())).thenReturn(clientBuilder); - final Client client = mock(Client.class); - when(clientBuilder.endpoints(anyString()).build()).thenReturn(client); - final Lease lease = mock(Lease.class); - when(client.getLeaseClient()).thenReturn(lease); - final CompletableFuture completableFuture = mock(CompletableFuture.class); - final LeaseGrantResponse leaseGrantResponse = mock(LeaseGrantResponse.class); - when(leaseGrantResponse.getID()).thenReturn(1L); - when(client.getLeaseClient().grant(anyLong())).thenReturn(completableFuture); - when(completableFuture.get()).thenReturn(leaseGrantResponse); - return client; - } - - private void awaitObserverRegistered(final List> observerList) - throws InterruptedException { - for (int i = 0; i < 20 && observerList.isEmpty(); i++) { - Thread.sleep(50); - } - Assertions.assertFalse(observerList.isEmpty(), "Observer should be registered"); - } - -} diff --git a/shenyu-infra/shenyu-infra-etcd/src/test/java/org/apache/shenyu/infra/etcd/properties/AbstractConfigurationTest.java b/shenyu-infra/shenyu-infra-etcd/src/test/java/org/apache/shenyu/infra/etcd/properties/AbstractConfigurationTest.java deleted file mode 100644 index f376e461c609..000000000000 --- a/shenyu-infra/shenyu-infra-etcd/src/test/java/org/apache/shenyu/infra/etcd/properties/AbstractConfigurationTest.java +++ /dev/null @@ -1,69 +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.shenyu.infra.etcd.properties; - -import org.junit.jupiter.api.AfterEach; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.test.context.support.TestPropertySourceUtils; - -/** - * AbstractConfigurationTest for Configuration or Properties. - */ -public abstract class AbstractConfigurationTest { - - private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - - /** - * Get the current mock context. - * - * @return AnnotationConfigApplicationContext - */ - public AnnotationConfigApplicationContext getContext() { - return context; - } - - /** - * clear context. - */ - @AfterEach - public void clear() { - context.close(); - } - - /** - * Add properties to Environment and register configuration into spring context. - * - * @param configuration the configuration class - * @param inlinedProperties the config properties - */ - public void load(final Class configuration, final String... inlinedProperties) { - load(new Class[]{configuration}, inlinedProperties); - } - - /** - * Add properties to Environment and register configuration into spring context. - * - * @param configuration the configuration class array - * @param inlinedProperties the config properties - */ - public void load(final Class[] configuration, final String... inlinedProperties) { - TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, inlinedProperties); - this.context.register(configuration); - this.context.refresh(); - } -} diff --git a/shenyu-infra/shenyu-infra-etcd/src/test/java/org/apache/shenyu/infra/etcd/properties/EtcdPropertiesTest.java b/shenyu-infra/shenyu-infra-etcd/src/test/java/org/apache/shenyu/infra/etcd/properties/EtcdPropertiesTest.java deleted file mode 100644 index e1dcf4531684..000000000000 --- a/shenyu-infra/shenyu-infra-etcd/src/test/java/org/apache/shenyu/infra/etcd/properties/EtcdPropertiesTest.java +++ /dev/null @@ -1,74 +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.shenyu.infra.etcd.properties; - -import org.apache.shenyu.infra.etcd.autoconfig.EtcdProperties; -import org.apache.shenyu.infra.etcd.config.EtcdConfig; -import org.junit.jupiter.api.Test; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -/** - * Test case for ZookeeperProperties. - */ -public final class EtcdPropertiesTest extends AbstractConfigurationTest { - - @Test - public void testLoadPropertiesBySpringContext() { - final String url = "127.0.0.1:2181"; - final Integer sessionTimeOut = 100; - final Integer connectionTimeout = 20560; - final String[] inlinedProperties = new String[]{ - "shenyu.sync.etcd.url=" + url, - "shenyu.sync.etcd.sessionTimeout=" + sessionTimeOut, - "shenyu.sync.etcd.connectionTimeout=" + connectionTimeout, - }; - load(EtcdPropertiesConfiguration.class, inlinedProperties); - EtcdProperties properties = getContext().getBean(EtcdProperties.class); - assertThat(properties.getEtcd().getUrl(), is(url)); - assertThat(properties.getEtcd().getSessionTimeout(), is(sessionTimeOut)); - assertThat(properties.getEtcd().getConnectionTimeout(), is(connectionTimeout)); - } - - @Test - public void testSetEtcdConfig() { - EtcdProperties etcdProperties = new EtcdProperties(); - EtcdConfig customConfig = EtcdConfig.builder() - .connectionTimeout(60 * 1000) - .sessionTimeout(60 * 1000) - .build(); - - etcdProperties.setEtcd(customConfig); - EtcdConfig etcdConfig = etcdProperties.getEtcd(); - - assertNotNull(etcdConfig, "EtcdConfig should not be null after setting"); - assertEquals(60 * 1000, etcdConfig.getConnectionTimeout(), "Connection timeout should be updated to 60 seconds"); - assertEquals(60 * 1000, etcdConfig.getSessionTimeout(), "Session timeout(TTL) should be updated to 60 seconds"); - } - - @Configuration - @EnableConfigurationProperties(EtcdProperties.class) - static class EtcdPropertiesConfiguration { - } - -} diff --git a/shenyu-integrated-test/shenyu-integrated-test-k8s-ingress-apache-dubbo/src/main/resources/application.yml b/shenyu-integrated-test/shenyu-integrated-test-k8s-ingress-apache-dubbo/src/main/resources/application.yml index 6786c934de68..cbf9d6e99e21 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-k8s-ingress-apache-dubbo/src/main/resources/application.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-k8s-ingress-apache-dubbo/src/main/resources/application.yml @@ -181,8 +181,8 @@ shenyu: # daemon: true register: enabled: false - registerType: zookeeper #etcd #consul - serverLists: localhost:2181 #http://localhost:2379 #localhost:8848 + registerType: zookeeper #consul + serverLists: localhost:2181 #localhost:8848 props: cross: enabled: true @@ -241,8 +241,6 @@ shenyu: # namespace: # accessKey: # secretKey: -# etcd: -# url: http://localhost:2379 # consul: # url: http://localhost:8500 # waitTime: 1000 diff --git a/shenyu-integrated-test/shenyu-integrated-test-k8s-ingress-http/src/main/resources/application.yml b/shenyu-integrated-test/shenyu-integrated-test-k8s-ingress-http/src/main/resources/application.yml index 6786c934de68..cbf9d6e99e21 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-k8s-ingress-http/src/main/resources/application.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-k8s-ingress-http/src/main/resources/application.yml @@ -181,8 +181,8 @@ shenyu: # daemon: true register: enabled: false - registerType: zookeeper #etcd #consul - serverLists: localhost:2181 #http://localhost:2379 #localhost:8848 + registerType: zookeeper #consul + serverLists: localhost:2181 #localhost:8848 props: cross: enabled: true @@ -241,8 +241,6 @@ shenyu: # namespace: # accessKey: # secretKey: -# etcd: -# url: http://localhost:2379 # consul: # url: http://localhost:8500 # waitTime: 1000 diff --git a/shenyu-integrated-test/shenyu-integrated-test-k8s-ingress-websocket/src/main/resources/application.yml b/shenyu-integrated-test/shenyu-integrated-test-k8s-ingress-websocket/src/main/resources/application.yml index 6786c934de68..cbf9d6e99e21 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-k8s-ingress-websocket/src/main/resources/application.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-k8s-ingress-websocket/src/main/resources/application.yml @@ -181,8 +181,8 @@ shenyu: # daemon: true register: enabled: false - registerType: zookeeper #etcd #consul - serverLists: localhost:2181 #http://localhost:2379 #localhost:8848 + registerType: zookeeper #consul + serverLists: localhost:2181 #localhost:8848 props: cross: enabled: true @@ -241,8 +241,6 @@ shenyu: # namespace: # accessKey: # secretKey: -# etcd: -# url: http://localhost:2379 # consul: # url: http://localhost:8500 # waitTime: 1000 diff --git a/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/pom.xml b/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/pom.xml index 4a87214573ea..5da20f59bde9 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/pom.xml +++ b/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/pom.xml @@ -54,10 +54,6 @@ shenyu-spring-boot-starter-registry ${project.version} - - org.apache.shenyu - shenyu-registry-etcd - org.apache.shenyu shenyu-registry-nacos diff --git a/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/src/main/resources/application.yml b/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/src/main/resources/application.yml index 54ee7d822cf9..72d7b5721b32 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/src/main/resources/application.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/src/main/resources/application.yml @@ -72,8 +72,8 @@ shenyu: singleEventExecutorPerGroup: true register: enabled: true - registerType: zookeeper #etcd #consul - serverLists: localhost:2181 #http://localhost:2379 #localhost:8848 + registerType: zookeeper #consul + serverLists: localhost:2181 #localhost:8848 props: cross: enabled: true diff --git a/shenyu-integrated-test/shenyu-integrated-test-sdk-http/pom.xml b/shenyu-integrated-test/shenyu-integrated-test-sdk-http/pom.xml index c6abfed027ef..b565aeb6df5a 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-sdk-http/pom.xml +++ b/shenyu-integrated-test/shenyu-integrated-test-sdk-http/pom.xml @@ -46,10 +46,6 @@ shenyu-spring-boot-starter-registry ${project.version} - - org.apache.shenyu - shenyu-registry-etcd - org.apache.shenyu shenyu-registry-nacos diff --git a/shenyu-integrated-test/shenyu-integrated-test-sdk-http/src/main/resources/application.yml b/shenyu-integrated-test/shenyu-integrated-test-sdk-http/src/main/resources/application.yml index 2161949ad0b9..d97fab446262 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-sdk-http/src/main/resources/application.yml +++ b/shenyu-integrated-test/shenyu-integrated-test-sdk-http/src/main/resources/application.yml @@ -72,8 +72,8 @@ shenyu: singleEventExecutorPerGroup: true register: enabled: true - registerType: zookeeper #etcd #consul - serverLists: localhost:2181 #http://localhost:2379 #localhost:8848 + registerType: zookeeper #consul + serverLists: localhost:2181 #localhost:8848 props: cross: enabled: true diff --git a/shenyu-registry/README.md b/shenyu-registry/README.md index 66ea84e1b5c2..94e43a631cde 100644 --- a/shenyu-registry/README.md +++ b/shenyu-registry/README.md @@ -38,7 +38,7 @@ runtime classpath, using the same ShenYu version as the application: | SPI key | Implementation artifact | | --- | --- | | `zookeeper` | `shenyu-registry-zookeeper` | -| `etcd` | `shenyu-registry-etcd` | +| `etcd` | External `shenyu-registry-etcd` from plugin-store; see [migration](../docs/plugin-store-etcd.md) | | `nacos` | `shenyu-registry-nacos` | | `apollo` | `shenyu-registry-apollo`; in-tree deprecation and planned external ownership: [migration guide](../docs/plugin-store-apollo.md) | | `eureka` | `shenyu-registry-eureka` | @@ -59,17 +59,17 @@ example selects Eureka, and the gRPC example selects no registry implementation. ## Compatibility and migration -For the 2.7.2 transition, `shenyu-spring-boot-starter-registry` retains the five providers -previously supplied by core: ZooKeeper, etcd, Nacos, Eureka and Kubernetes. Existing users -of that starter keep the same classpath and configuration keys. Apollo was not part of -the previous aggregate and remains an explicit choice. Removing the compatibility -aggregate is deferred to a separately announced change. +The compatibility starter retains ZooKeeper, Nacos, Eureka and Kubernetes. +etcd is now an explicit external dependency: add the compatible plugin-store +`shenyu-registry-etcd` artifact before upgrading a deployment configured with `etcd`. +Its SPI key and configuration remain unchanged; see [migration and rollback](../docs/plugin-store-etcd.md). +Apollo remains an explicit choice. Applications depending directly on core, SDK libraries, or SDK starters should add their configured provider before upgrading. For gateway registration with a smaller classpath, retain the registry starter, exclude the unused implementation dependencies, and declare the selected implementation explicitly. The SDK integration tests show -this arrangement for ZooKeeper. Admin declares its five supported discovery providers +this arrangement for ZooKeeper. Admin declares its four in-tree discovery providers explicitly and preserves independent connections for separate discovery configurations. To roll back a dependency selection, restore the application's previous explicit @@ -79,7 +79,7 @@ key migration is required. The factory's cache and reinitialization behavior is ## External implementations -External providers, including Consul and Polaris extensions, implement +External providers, including etcd, Consul and Polaris extensions, implement `org.apache.shenyu.registry.api.ShenyuInstanceRegisterRepository`, carry `@Join`, and publish this resource in their JAR: @@ -90,7 +90,7 @@ META-INF/shenyu/org.apache.shenyu.registry.api.ShenyuInstanceRegisterRepository For example, `consul=com.example.ConsulInstanceRegisterRepository` preserves the existing registration key. Add the extension JAR and its client dependencies to the runtime classpath; no core POM change is needed. Existing ShenYu SPI classloader rules continue -to apply. Factory tests load external `consul` and `polaris` keys from isolated resources +to apply. Factory tests load external `consul`, `etcd` and `polaris` keys from isolated resources without any built-in provider dependency. ## Dependency and release inventory @@ -98,26 +98,18 @@ without any built-in provider dependency. | Consumer | Registry implementation inventory | | --- | --- | | Registry API/core, SDK libraries and SDK starters | None | -| Compatibility registry starter | ZooKeeper, etcd, Nacos, Eureka, Kubernetes | -| Admin distribution | ZooKeeper, etcd, Nacos, Eureka, Kubernetes, explicitly declared | +| Compatibility registry starter | ZooKeeper, Nacos, Eureka, Kubernetes | +| Admin distribution | ZooKeeper, Nacos, Eureka, Kubernetes, explicitly declared | | Bootstrap distribution | Registry API only; client libraries also arrive through sync/register/plugin modules | | SDK HTTP/Dubbo integration gateways | ZooKeeper | | Upload-plugin integration gateway | None; registry registration is not enabled | -The packaged Admin client inventory includes Curator 5.7.0, ZooKeeper 3.9.5, jetcd -0.7.3, Nacos 2.2.4, Eureka 2.0.2, and Kubernetes Java client 17.0.2. Bootstrap still -packages Curator, ZooKeeper, jetcd and Nacos through its other selected modules. Both -release archives include their LICENSE/NOTICE files. No registry client license entry -is removed by this change. +etcd clients are no longer part of the default Admin/Bootstrap dependency graphs; +their jetcd LICENSE/NOTICE entries move with the external stack. The remaining +client notices stay in the distributions. Custom packages enabling etcd must +include the notices for the external artifacts and their runtime dependencies. -Admin retains the same client libraries, so its existing distribution LICENSE/NOTICE -entries still apply. Bootstrap distribution client libraries also come from selected -plugin, registration and synchronization starters; removing an edge from registry-core -alone does not remove those libraries. Keep the existing license and notice entries -for libraries still shipped. Custom distributions must inventory the actual packaged -`lib/` JARs and include their notices when selecting or removing providers. - -CI checks resolved runtime trees for the API/core, both SDK libraries/starters, all six +CI checks resolved runtime trees for the API/core, both SDK libraries/starters, all five in-repository implementations and the compatibility starter. The checks reject registry implementations and client libraries in lean consumers, reverse implementation-to-core dependencies, and loss of a compatibility provider. Run locally: diff --git a/shenyu-registry/pom.xml b/shenyu-registry/pom.xml index edaf5ce05294..03ac14ee23a0 100644 --- a/shenyu-registry/pom.xml +++ b/shenyu-registry/pom.xml @@ -30,7 +30,6 @@ shenyu-registry-api shenyu-registry-core shenyu-registry-zookeeper - shenyu-registry-etcd shenyu-registry-nacos shenyu-registry-apollo shenyu-registry-eureka diff --git a/shenyu-registry/shenyu-registry-core/src/test/java/org/apache/shenyu/registry/core/ShenyuInstanceRegisterRepositoryFactoryTest.java b/shenyu-registry/shenyu-registry-core/src/test/java/org/apache/shenyu/registry/core/ShenyuInstanceRegisterRepositoryFactoryTest.java index 9fe641659c13..4e956e879e70 100644 --- a/shenyu-registry/shenyu-registry-core/src/test/java/org/apache/shenyu/registry/core/ShenyuInstanceRegisterRepositoryFactoryTest.java +++ b/shenyu-registry/shenyu-registry-core/src/test/java/org/apache/shenyu/registry/core/ShenyuInstanceRegisterRepositoryFactoryTest.java @@ -88,15 +88,17 @@ void oneProviderIsLoadedAndCached() throws Exception { @Test void multipleExternalProvidersKeepTheirSpiKeys() throws Exception { - useProviders(provider("consul") + provider("polaris")); + useProviders(provider("consul") + provider("etcd") + provider("polaris")); ShenyuInstanceRegisterRepository consul = ShenyuInstanceRegisterRepositoryFactory.newInstance("consul", classLoader); ShenyuInstanceRegisterRepository polaris = ShenyuInstanceRegisterRepositoryFactory.newInstance("polaris", classLoader); + ShenyuInstanceRegisterRepository etcd = ShenyuInstanceRegisterRepositoryFactory.loadRepository("etcd", classLoader); + assertNotSame(etcd, ShenyuInstanceRegisterRepositoryFactory.loadRepository("etcd", classLoader)); assertNotSame(consul, polaris); assertSame(consul, ShenyuInstanceRegisterRepositoryFactory.newInstance("consul", classLoader)); assertSame(polaris, ShenyuInstanceRegisterRepositoryFactory.newInstance("polaris", classLoader)); IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> ShenyuInstanceRegisterRepositoryFactory.newInstance("unknown", classLoader)); - assertTrue(exception.getMessage().contains("Available types: [consul, polaris]")); + assertTrue(exception.getMessage().contains("Available types: [consul, etcd, polaris]")); } @Test diff --git a/shenyu-registry/shenyu-registry-etcd/pom.xml b/shenyu-registry/shenyu-registry-etcd/pom.xml deleted file mode 100644 index 1fee9d64002c..000000000000 --- a/shenyu-registry/shenyu-registry-etcd/pom.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - org.apache.shenyu - shenyu-registry - 2.7.3-SNAPSHOT - - 4.0.0 - shenyu-registry-etcd - - - - com.google.guava - guava - - - - org.apache.shenyu - shenyu-registry-api - ${project.version} - - - - org.apache.shenyu - shenyu-infra-etcd - ${project.version} - - - - io.etcd - jetcd-core - - - grpc-protobuf - io.grpc - - - grpc-stub - io.grpc - - - io.grpc - grpc-core - - - grpc-netty - io.grpc - - - protobuf-java-util - com.google.protobuf - - - protobuf-java - com.google.protobuf - - - - - - - diff --git a/shenyu-registry/shenyu-registry-etcd/src/main/java/org/apache/shenyu/registry/etcd/EtcdInstanceRegisterRepository.java b/shenyu-registry/shenyu-registry-etcd/src/main/java/org/apache/shenyu/registry/etcd/EtcdInstanceRegisterRepository.java deleted file mode 100644 index ac6a8656bfbd..000000000000 --- a/shenyu-registry/shenyu-registry-etcd/src/main/java/org/apache/shenyu/registry/etcd/EtcdInstanceRegisterRepository.java +++ /dev/null @@ -1,172 +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.shenyu.registry.etcd; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; -import io.etcd.jetcd.Client; -import io.etcd.jetcd.Watch; -import io.etcd.jetcd.watch.WatchEvent; -import org.apache.shenyu.common.constant.Constants; -import org.apache.shenyu.common.exception.ShenyuException; -import org.apache.shenyu.common.utils.GsonUtils; -import org.apache.shenyu.infra.etcd.client.EtcdClient; -import org.apache.shenyu.registry.api.ShenyuInstanceRegisterRepository; -import org.apache.shenyu.registry.api.config.RegisterConfig; -import org.apache.shenyu.registry.api.entity.InstanceEntity; -import org.apache.shenyu.registry.api.event.ChangedEventListener; -import org.apache.shenyu.registry.api.path.InstancePathConstants; -import org.apache.shenyu.spi.Join; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.net.URI; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Properties; -import java.util.stream.Collectors; - -import static java.nio.charset.StandardCharsets.UTF_8; - -/** - * The type Etcd instance register repository. - */ -@Join(isSingleton = false) -public class EtcdInstanceRegisterRepository implements ShenyuInstanceRegisterRepository { - - private static final Logger LOGGER = LoggerFactory.getLogger(EtcdInstanceRegisterRepository.class); - - private EtcdClient client; - - private final Multimap watchCache = ArrayListMultimap.create(); - - @Override - public void init(final RegisterConfig config) { - Properties props = config.getProps(); - long timeout = Long.parseLong(props.getProperty("etcdTimeout", "3000")); - long ttl = Long.parseLong(props.getProperty("etcdTTL", "5")); - client = EtcdClient.builder() - .client( - Client.builder() - .endpoints(config.getServerLists().split(",")) - .build() - ).ttl(ttl) - .timeout(timeout) - .build(); - } - - @Override - public void persistInstance(final InstanceEntity instance) { - String instanceNodeName = buildInstanceNodeName(instance); - String instancePath = InstancePathConstants.buildInstanceParentPath(instance.getAppName()); - String realNode = InstancePathConstants.buildRealNode(instancePath, instanceNodeName); - String nodeData = GsonUtils.getInstance().toJson(instance); - client.putEphemeral(realNode, nodeData); - LOGGER.info("etcd client register success: {}", nodeData); - } - - @Override - public List selectInstances(final String selectKey) { - final String watchKey = InstancePathConstants.buildInstanceParentPath(selectKey); - return client.getKeysMapByPrefix(watchKey).values().stream().map(x -> { - InstanceEntity instanceEntity = GsonUtils.getInstance().fromJson(x, InstanceEntity.class); - instanceEntity.setUri(getURI(x, instanceEntity.getPort(), instanceEntity.getHost())); - return instanceEntity; - }).collect(Collectors.toList()); - } - - @Override - public boolean serviceExists(final String key) { - try { - return !selectInstances(key).isEmpty(); - } catch (Exception e) { - throw new ShenyuException(e); - } - } - - @Override - public void watchInstances(final String watchKey, final ChangedEventListener listener) { - try { - Map serverNodes = client.getKeysMapByPrefix(watchKey); - serverNodes.forEach((k, v) -> listener.onEvent(k, v, ChangedEventListener.Event.ADDED)); - final Watch.Watcher watcher = this.client.watchKeyChanges(watchKey, Watch.listener(response -> { - for (WatchEvent event : response.getEvents()) { - String value = event.getKeyValue().getValue().toString(UTF_8); - String path = event.getKeyValue().getKey().toString(UTF_8); - switch (event.getEventType()) { - case PUT: - if (event.getKeyValue().getCreateRevision() == event.getKeyValue().getModRevision()) { - listener.onEvent(path, value, ChangedEventListener.Event.ADDED); - } else { - listener.onEvent(path, value, ChangedEventListener.Event.UPDATED); - } - LOGGER.info("watch key {} updated, value is {}", watchKey, value); - continue; - case DELETE: - listener.onEvent(path, value, ChangedEventListener.Event.DELETED); - LOGGER.info("watch key {} deleted, key is {}", watchKey, path); - continue; - default: - } - } - })); - watchCache.put(watchKey, watcher); - LOGGER.info("etcd added watcher for key: {}", watchKey); - } catch (Exception e) { - LOGGER.error("etcd client watch key: {} error", watchKey, e); - throw new ShenyuException(e); - } - } - - @Override - public void unWatchInstances(final String key) { - if (watchCache.containsKey(key)) { - watchCache.get(key).forEach(Watch.Watcher::close); - watchCache.removeAll(key); - LOGGER.info("etcd Unwatched etcd key: {}", key); - } - } - - private URI getURI(final String instanceRegisterJsonStr, final int port, final String host) { - String scheme = (instanceRegisterJsonStr.contains("https") || instanceRegisterJsonStr.contains("HTTPS")) ? "https" : "http"; - String uri = String.format("%s://%s:%s", scheme, host, port); - return URI.create(uri); - } - - private String buildInstanceNodeName(final InstanceEntity instance) { - String host = instance.getHost(); - int port = instance.getPort(); - return String.join(Constants.COLONS, host, Integer.toString(port)); - } - - @Override - public void close() { - try { - watchCache.values().forEach(Watch.Watcher::close); - watchCache.clear(); - if (Objects.nonNull(client)) { - client.close(); - } - LOGGER.info("Shutting down EtcdDiscoveryService"); - } catch (Exception e) { - LOGGER.error("etcd client shutdown error", e); - throw new ShenyuException(e); - } - } -} diff --git a/shenyu-registry/shenyu-registry-etcd/src/main/resources/META-INF/shenyu/org.apache.shenyu.registry.api.ShenyuInstanceRegisterRepository b/shenyu-registry/shenyu-registry-etcd/src/main/resources/META-INF/shenyu/org.apache.shenyu.registry.api.ShenyuInstanceRegisterRepository deleted file mode 100644 index a9742e2597ec..000000000000 --- a/shenyu-registry/shenyu-registry-etcd/src/main/resources/META-INF/shenyu/org.apache.shenyu.registry.api.ShenyuInstanceRegisterRepository +++ /dev/null @@ -1,17 +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. - -etcd=org.apache.shenyu.registry.etcd.EtcdInstanceRegisterRepository diff --git a/shenyu-registry/shenyu-registry-etcd/src/test/java/org/apache/shenyu/registry/etcd/EtcdClientTest.java b/shenyu-registry/shenyu-registry-etcd/src/test/java/org/apache/shenyu/registry/etcd/EtcdClientTest.java deleted file mode 100644 index 8876e2c43c0f..000000000000 --- a/shenyu-registry/shenyu-registry-etcd/src/test/java/org/apache/shenyu/registry/etcd/EtcdClientTest.java +++ /dev/null @@ -1,148 +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.shenyu.registry.etcd; - -import io.etcd.jetcd.Client; -import io.etcd.jetcd.ClientBuilder; -import io.etcd.jetcd.KV; -import io.etcd.jetcd.Lease; -import io.etcd.jetcd.kv.PutResponse; -import io.etcd.jetcd.lease.LeaseGrantResponse; -import io.etcd.jetcd.lease.LeaseKeepAliveResponse; -import io.grpc.stub.StreamObserver; -import org.apache.shenyu.common.exception.ShenyuException; -import org.apache.shenyu.infra.etcd.client.EtcdClient; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.mockito.MockedStatic; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.mockStatic; -import static org.mockito.Mockito.when; - -/** - * test for EtcdClient. - */ -public class EtcdClientTest { - - @Test - public void etcdClientTest() { - try (MockedStatic clientMockedStatic = mockStatic(Client.class)) { - final ClientBuilder clientBuilder = mock(ClientBuilder.class); - clientMockedStatic.when(Client::builder).thenReturn(clientBuilder); - when(clientBuilder.endpoints(anyString())).thenReturn(clientBuilder); - final Client client = mock(Client.class); - when(clientBuilder.endpoints(anyString()).build()).thenReturn(client); - final Lease lease = mock(Lease.class); - when(client.getLeaseClient()).thenReturn(lease); - final CompletableFuture completableFuture = mock(CompletableFuture.class); - final LeaseGrantResponse leaseGrantResponse = mock(LeaseGrantResponse.class); - when(leaseGrantResponse.getID()).thenReturn(1L); - - when(client.getLeaseClient().grant(anyLong())).thenReturn(completableFuture); - when(completableFuture.get()).thenReturn(leaseGrantResponse); - List> observerList = new ArrayList<>(); - doAnswer(invocation -> { - observerList.add(invocation.getArgument(1)); - return lease; - }).when(lease).keepAlive(anyLong(), any()); - - final EtcdClient etcdClient = Assertions.assertDoesNotThrow(() -> EtcdClient.builder() - .client(Client.builder().endpoints("url").build()) - .ttl(60L) - .timeout(3000L) - .build()); - Assertions.assertNotNull(etcdClient); - - final LeaseKeepAliveResponse leaseKeepAliveResponse = mock(LeaseKeepAliveResponse.class); - observerList.forEach(streamObserver -> { - streamObserver.onCompleted(); - streamObserver.onError(new ShenyuException("test")); - streamObserver.onNext(leaseKeepAliveResponse); - }); - etcdClient.close(); - - doThrow(new InterruptedException("error")).when(completableFuture).get(); - Assertions.assertThrows(ShenyuException.class, () -> EtcdClient.builder() - .client(Client.builder().endpoints("url").build()) - .ttl(60L) - .timeout(3000L) - .build()); - } catch (Exception e) { - throw new ShenyuException(e.getCause()); - } - } - - @Test - public void closeTest() { - try (MockedStatic clientMockedStatic = mockStatic(Client.class)) { - this.mockEtcd(clientMockedStatic); - final EtcdClient etcdClient = EtcdClient.builder().client(Client.builder().endpoints("url").build()).ttl(60L).timeout(3000L).build(); - etcdClient.close(); - } catch (Exception e) { - throw new ShenyuException(e.getCause()); - } - } - - @Test - public void putEphemeralTest() { - try (MockedStatic clientMockedStatic = mockStatic(Client.class)) { - final Client client = this.mockEtcd(clientMockedStatic); - final KV mockKV = mock(KV.class); - when(client.getKVClient()).thenReturn(mockKV); - final CompletableFuture completableFuture = mock(CompletableFuture.class); - when(mockKV.put(any(), any(), any())).thenReturn(completableFuture); - final PutResponse putResponse = mock(PutResponse.class); - when(completableFuture.get(anyLong(), any(TimeUnit.class))).thenReturn(putResponse); - final EtcdClient etcdClient = EtcdClient.builder().client(Client.builder().endpoints("url").build()).ttl(60L).timeout(3000L).build(); - etcdClient.putEphemeral("key", "value"); - - doThrow(new InterruptedException("error")).when(completableFuture).get(anyLong(), any(TimeUnit.class)); - Assertions.assertThrows(ShenyuException.class, () -> etcdClient.putEphemeral("key", "value")); - } catch (Exception e) { - throw new ShenyuException(e.getCause()); - } - } - - private Client mockEtcd(final MockedStatic clientMockedStatic) throws InterruptedException, ExecutionException { - final ClientBuilder clientBuilder = mock(ClientBuilder.class); - clientMockedStatic.when(Client::builder).thenReturn(clientBuilder); - when(clientBuilder.endpoints(anyString())).thenReturn(clientBuilder); - final Client client = mock(Client.class); - when(clientBuilder.endpoints(anyString()).build()).thenReturn(client); - final Lease lease = mock(Lease.class); - when(client.getLeaseClient()).thenReturn(lease); - final CompletableFuture completableFuture = mock(CompletableFuture.class); - final LeaseGrantResponse leaseGrantResponse = mock(LeaseGrantResponse.class); - when(leaseGrantResponse.getID()).thenReturn(1L); - when(client.getLeaseClient().grant(anyLong())).thenReturn(completableFuture); - when(completableFuture.get()).thenReturn(leaseGrantResponse); - return client; - } -} diff --git a/shenyu-registry/shenyu-registry-etcd/src/test/java/org/apache/shenyu/registry/etcd/EtcdInstanceRegisterRepositoryTest.java b/shenyu-registry/shenyu-registry-etcd/src/test/java/org/apache/shenyu/registry/etcd/EtcdInstanceRegisterRepositoryTest.java deleted file mode 100644 index 5ceb3207b168..000000000000 --- a/shenyu-registry/shenyu-registry-etcd/src/test/java/org/apache/shenyu/registry/etcd/EtcdInstanceRegisterRepositoryTest.java +++ /dev/null @@ -1,239 +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.shenyu.registry.etcd; - -import io.etcd.jetcd.ByteSequence; -import io.etcd.jetcd.Client; -import io.etcd.jetcd.ClientBuilder; -import io.etcd.jetcd.KeyValue; -import io.etcd.jetcd.Lease; -import io.etcd.jetcd.Watch; -import io.etcd.jetcd.lease.LeaseGrantResponse; -import io.etcd.jetcd.watch.WatchEvent; -import io.etcd.jetcd.watch.WatchResponse; -import org.apache.shenyu.common.exception.ShenyuException; -import org.apache.shenyu.common.utils.GsonUtils; -import org.apache.shenyu.infra.etcd.client.EtcdClient; -import org.apache.shenyu.registry.api.config.RegisterConfig; -import org.apache.shenyu.registry.api.entity.InstanceEntity; -import org.apache.shenyu.registry.api.event.ChangedEventListener; -import org.apache.shenyu.registry.api.path.InstancePathConstants; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.MockedStatic; - -import java.lang.reflect.Field; -import java.net.URI; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CompletableFuture; - -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.mockStatic; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -/** - * The type Etcd instance register repository test. - */ -public final class EtcdInstanceRegisterRepositoryTest { - - private EtcdInstanceRegisterRepository repository; - - private EtcdClient etcdClient; - - private final Map etcdBroker = new HashMap<>(); - - /** - * Sets up. - * - * @throws NoSuchFieldException the no such field exception - * @throws IllegalAccessException the illegal access exception - */ - @BeforeEach - public void setUp() throws NoSuchFieldException, IllegalAccessException { - this.repository = new EtcdInstanceRegisterRepository(); - Class clazz = this.repository.getClass(); - - String fieldString = "client"; - Field field = clazz.getDeclaredField(fieldString); - field.setAccessible(true); - field.set(repository, mockEtcdClient()); - - etcdBroker.clear(); - } - - private EtcdClient mockEtcdClient() { - etcdClient = mock(EtcdClient.class); - when(etcdClient.getKeysMapByPrefix(anyString())).thenReturn(Collections.emptyMap()); - - doAnswer(invocationOnMock -> { - String key = invocationOnMock.getArgument(0); - String value = invocationOnMock.getArgument(1); - etcdBroker.put(key, value); - return null; - }).when(etcdClient).putEphemeral(anyString(), anyString()); - - doAnswer(invocationOnMock -> { - etcdBroker.clear(); - return null; - }).when(etcdClient).close(); - return etcdClient; - } - - /** - * Test persist instance. - */ - @Test - public void testPersistInstance() { - InstanceEntity data = InstanceEntity.builder() - .appName("shenyu-test") - .host("shenyu-host") - .port(9195) - .build(); - - final String realNode = "/shenyu/register/instance/shenyu-test/shenyu-host:9195"; - repository.persistInstance(data); - assertTrue(etcdBroker.containsKey(realNode)); - assertEquals(GsonUtils.getInstance().toJson(data), etcdBroker.get(realNode)); - repository.close(); - } - - /** - * Init test. - */ - @Test - public void initTest() { - try (MockedStatic clientMockedStatic = mockStatic(Client.class)) { - final ClientBuilder clientBuilder = mock(ClientBuilder.class); - clientMockedStatic.when(Client::builder).thenReturn(clientBuilder); - when(clientBuilder.endpoints(anyString())).thenReturn(clientBuilder); - final Client client = mock(Client.class); - when(clientBuilder.endpoints(anyString()).build()).thenReturn(client); - final Lease lease = mock(Lease.class); - when(client.getLeaseClient()).thenReturn(lease); - final CompletableFuture completableFuture = mock(CompletableFuture.class); - final LeaseGrantResponse leaseGrantResponse = mock(LeaseGrantResponse.class); - - when(client.getLeaseClient().grant(anyLong())).thenReturn(completableFuture); - when(completableFuture.get()).thenReturn(leaseGrantResponse); - RegisterConfig config = new RegisterConfig(); - config.setServerLists("url"); - Assertions.assertDoesNotThrow(() -> repository.init(config)); - } catch (Exception e) { - throw new ShenyuException(e); - } - } - - /** - * Test selecting instances does not create a persistent watcher. - */ - @Test - public void testSelectInstancesDoesNotCreateWatcher() { - assertTrue(repository.selectInstances("shenyu-test").isEmpty()); - assertTrue(repository.selectInstances("shenyu-test").isEmpty()); - - verify(etcdClient, times(2)).getKeysMapByPrefix(InstancePathConstants.buildInstanceParentPath("shenyu-test")); - verify(etcdClient, never()).watchKeyChanges(anyString(), any(Watch.Listener.class)); - } - - /** - * Test each selection reads current instances and fills their URIs. - */ - @Test - public void testSelectInstancesReadsCurrentInstances() { - InstanceEntity data = InstanceEntity.builder() - .appName("shenyu-test") - .host("shenyu-host") - .port(9195) - .build(); - String prefix = InstancePathConstants.buildInstanceParentPath(data.getAppName()); - String node = InstancePathConstants.buildRealNode(prefix, "shenyu-host:9195"); - Map serverNodes = new HashMap<>(); - when(etcdClient.getKeysMapByPrefix(prefix)).thenAnswer(invocation -> new HashMap<>(serverNodes)); - - assertTrue(repository.selectInstances(data.getAppName()).isEmpty()); - serverNodes.put(node, GsonUtils.getInstance().toJson(data)); - List instances = repository.selectInstances(data.getAppName()); - assertEquals(1, instances.size()); - assertEquals(data.getAppName(), instances.get(0).getAppName()); - assertEquals(data.getHost(), instances.get(0).getHost()); - assertEquals(data.getPort(), instances.get(0).getPort()); - assertEquals(URI.create("http://shenyu-host:9195"), instances.get(0).getUri()); - - data.setWeight(10); - data.setUri(URI.create("https://shenyu-host:9195")); - serverNodes.put(node, GsonUtils.getInstance().toJson(data)); - instances = repository.selectInstances(data.getAppName()); - assertEquals(1, instances.size()); - assertEquals(10, instances.get(0).getWeight()); - assertEquals(URI.create("https://shenyu-host:9195"), instances.get(0).getUri()); - - InstanceEntity another = new InstanceEntity(data.getAppName(), "another-host", 9196); - serverNodes.put(InstancePathConstants.buildRealNode(prefix, "another-host:9196"), GsonUtils.getInstance().toJson(another)); - assertEquals(2, repository.selectInstances(data.getAppName()).size()); - serverNodes.remove(node); - instances = repository.selectInstances(data.getAppName()); - assertEquals(1, instances.size()); - assertEquals(URI.create("http://another-host:9196"), instances.get(0).getUri()); - serverNodes.clear(); - assertTrue(repository.selectInstances(data.getAppName()).isEmpty()); - verify(etcdClient, times(6)).getKeysMapByPrefix(prefix); - } - - /** - * Test selecting instances preserves an explicit watcher and its notifications. - */ - @Test - public void testSelectInstancesPreservesExplicitWatcher() { - String key = InstancePathConstants.buildInstanceParentPath("shenyu-test"); - ChangedEventListener listener = mock(ChangedEventListener.class); - Watch.Watcher watcher = mock(Watch.Watcher.class); - when(etcdClient.watchKeyChanges(eq(key), any(Watch.Listener.class))).thenReturn(watcher); - - repository.watchInstances(key, listener); - repository.selectInstances("shenyu-test"); - ArgumentCaptor captor = ArgumentCaptor.forClass(Watch.Listener.class); - verify(etcdClient).watchKeyChanges(eq(key), captor.capture()); - verify(watcher, never()).close(); - String node = key + "/shenyu-host:9195"; - String value = "instance-data"; - KeyValue keyValue = mock(KeyValue.class); - when(keyValue.getKey()).thenReturn(ByteSequence.from(node, UTF_8)); - when(keyValue.getValue()).thenReturn(ByteSequence.from(value, UTF_8)); - WatchResponse response = mock(WatchResponse.class); - when(response.getEvents()).thenReturn(Collections.singletonList(new WatchEvent(keyValue, keyValue, WatchEvent.EventType.PUT))); - - captor.getValue().onNext(response); - verify(listener).onEvent(node, value, ChangedEventListener.Event.ADDED); - } -} diff --git a/shenyu-registry/shenyu-registry-etcd/src/test/java/org/apache/shenyu/registry/etcd/RegistrySpiTest.java b/shenyu-registry/shenyu-registry-etcd/src/test/java/org/apache/shenyu/registry/etcd/RegistrySpiTest.java deleted file mode 100644 index b1ae3d7c6709..000000000000 --- a/shenyu-registry/shenyu-registry-etcd/src/test/java/org/apache/shenyu/registry/etcd/RegistrySpiTest.java +++ /dev/null @@ -1,33 +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.shenyu.registry.etcd; - -import org.apache.shenyu.registry.api.ShenyuInstanceRegisterRepository; -import org.apache.shenyu.spi.ExtensionLoader; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class RegistrySpiTest { - - @Test - void discoversPublishedRegistryKey() { - ShenyuInstanceRegisterRepository repository = ExtensionLoader.getExtensionLoader(ShenyuInstanceRegisterRepository.class).getJoin("etcd"); - assertEquals(EtcdInstanceRegisterRepository.class, repository.getClass()); - } -} diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-registry/pom.xml b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-registry/pom.xml index a6949a4bb9ce..51b32226c0b0 100644 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-registry/pom.xml +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-registry/pom.xml @@ -38,11 +38,6 @@ shenyu-registry-zookeeper ${project.version} - - org.apache.shenyu - shenyu-registry-etcd - ${project.version} - org.apache.shenyu shenyu-registry-nacos diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-registry/src/test/java/org/apache/shenyu/springboot/starter/registry/RegistryClasspathTest.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-registry/src/test/java/org/apache/shenyu/springboot/starter/registry/RegistryClasspathTest.java index 52076875132e..b993c56ca09e 100644 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-registry/src/test/java/org/apache/shenyu/springboot/starter/registry/RegistryClasspathTest.java +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-registry/src/test/java/org/apache/shenyu/springboot/starter/registry/RegistryClasspathTest.java @@ -51,9 +51,9 @@ void disabledRegistrationStartsWithoutARegistryConnection() { } @Test - void compatibilityStarterStillDiscoversItsOriginalProviders() { + void compatibilityStarterDiscoversRetainedProviders() { assertThat(ExtensionLoader.getExtensionLoader(ShenyuInstanceRegisterRepository.class).getExtensionClasses1()) - .containsKeys("zookeeper", "etcd", "nacos", "eureka", "kubernetes"); + .containsKeys("zookeeper", "nacos", "eureka", "kubernetes").doesNotContainKey("etcd"); } @Test diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/pom.xml b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/pom.xml index 98d9bbc0b15d..d12461fd529d 100644 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/pom.xml +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/pom.xml @@ -32,7 +32,6 @@ shenyu-spring-boot-starter-sync-data-websocket shenyu-spring-boot-starter-sync-data-http shenyu-spring-boot-starter-sync-data-nacos - shenyu-spring-boot-starter-sync-data-etcd shenyu-spring-boot-starter-sync-data-apollo diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-etcd/pom.xml b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-etcd/pom.xml deleted file mode 100644 index 1d679e6098f9..000000000000 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-etcd/pom.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - org.apache.shenyu - shenyu-spring-boot-starter-sync-data-center - 2.7.3-SNAPSHOT - - 4.0.0 - - shenyu-spring-boot-starter-sync-data-etcd - - - - org.apache.shenyu - shenyu-sync-data-etcd - ${project.version} - - - - diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-etcd/src/main/java/org/apache/shenyu/springboot/sync/data/etcd/EtcdSyncDataConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-etcd/src/main/java/org/apache/shenyu/springboot/sync/data/etcd/EtcdSyncDataConfiguration.java deleted file mode 100644 index 7b6212486839..000000000000 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-etcd/src/main/java/org/apache/shenyu/springboot/sync/data/etcd/EtcdSyncDataConfiguration.java +++ /dev/null @@ -1,86 +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.shenyu.springboot.sync.data.etcd; - -import io.etcd.jetcd.Client; -import org.apache.shenyu.common.config.ShenyuConfig; -import org.apache.shenyu.infra.etcd.autoconfig.ConditionOnSyncEtcd; -import org.apache.shenyu.infra.etcd.autoconfig.EtcdProperties; -import org.apache.shenyu.infra.etcd.client.EtcdClient; -import org.apache.shenyu.sync.data.api.AuthDataSubscriber; -import org.apache.shenyu.sync.data.api.DiscoveryUpstreamDataSubscriber; -import org.apache.shenyu.sync.data.api.MetaDataSubscriber; -import org.apache.shenyu.sync.data.api.PluginDataSubscriber; -import org.apache.shenyu.sync.data.api.ProxySelectorDataSubscriber; -import org.apache.shenyu.sync.data.api.SyncDataService; -import org.apache.shenyu.sync.data.etcd.EtcdSyncDataService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.ObjectProvider; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.util.Collections; -import java.util.List; - -/** - * Etcd sync data configuration for spring boot. - */ - -@Configuration -@ConditionOnSyncEtcd -@EnableConfigurationProperties(EtcdProperties.class) -@ConditionalOnClass({EtcdSyncDataConfiguration.class, Client.class}) -public class EtcdSyncDataConfiguration { - - private static final Logger LOGGER = LoggerFactory.getLogger(EtcdSyncDataConfiguration.class); - - /** - * Sync data service. - * - * @param shenyuConfig the shenyu config - * @param etcdClients the etcd client - * @param pluginSubscriber the plugin subscriber - * @param metaSubscribers the meta subscribers - * @param authSubscribers the auth subscribers - * @param proxySelectorDataSubscribers the proxy selector data subscribers - * @param discoveryUpstreamDataSubscribers the discovery upstream data subscribers - * @return the sync data service - */ - @Bean - public SyncDataService syncDataService(final ObjectProvider shenyuConfig, - final ObjectProvider etcdClients, - final ObjectProvider pluginSubscriber, - final ObjectProvider> metaSubscribers, - final ObjectProvider> authSubscribers, - final ObjectProvider> proxySelectorDataSubscribers, - final ObjectProvider> discoveryUpstreamDataSubscribers) { - - LOGGER.info("you use etcd sync shenyu data......."); - return new EtcdSyncDataService(shenyuConfig.getIfAvailable(), - etcdClients.getIfAvailable(), - pluginSubscriber.getIfAvailable(), - metaSubscribers.getIfAvailable(Collections::emptyList), - authSubscribers.getIfAvailable(Collections::emptyList), - proxySelectorDataSubscribers.getIfAvailable(Collections::emptyList), - discoveryUpstreamDataSubscribers.getIfAvailable(Collections::emptyList)); - } - -} diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-etcd/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-etcd/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 89b299d5e4cf..000000000000 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-etcd/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /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.shenyu.springboot.sync.data.etcd.EtcdSyncDataConfiguration diff --git a/shenyu-sync-data-center/pom.xml b/shenyu-sync-data-center/pom.xml index 361a29aa5404..0e3971be9d07 100644 --- a/shenyu-sync-data-center/pom.xml +++ b/shenyu-sync-data-center/pom.xml @@ -32,7 +32,6 @@ shenyu-sync-data-websocket shenyu-sync-data-http shenyu-sync-data-nacos - shenyu-sync-data-etcd shenyu-sync-data-apollo diff --git a/shenyu-sync-data-center/shenyu-sync-data-etcd/pom.xml b/shenyu-sync-data-center/shenyu-sync-data-etcd/pom.xml deleted file mode 100644 index 86a65d4cc496..000000000000 --- a/shenyu-sync-data-center/shenyu-sync-data-etcd/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - org.apache.shenyu - shenyu-sync-data-center - 2.7.3-SNAPSHOT - - 4.0.0 - shenyu-sync-data-etcd - - - - org.apache.shenyu - shenyu-sync-data-api - ${project.version} - - - - org.apache.shenyu - shenyu-infra-etcd - ${project.version} - - - - diff --git a/shenyu-sync-data-center/shenyu-sync-data-etcd/src/main/java/org/apache/shenyu/sync/data/etcd/EtcdSyncDataService.java b/shenyu-sync-data-center/shenyu-sync-data-etcd/src/main/java/org/apache/shenyu/sync/data/etcd/EtcdSyncDataService.java deleted file mode 100644 index bbb60ecee2eb..000000000000 --- a/shenyu-sync-data-center/shenyu-sync-data-etcd/src/main/java/org/apache/shenyu/sync/data/etcd/EtcdSyncDataService.java +++ /dev/null @@ -1,114 +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.shenyu.sync.data.etcd; - -import org.apache.commons.lang3.ObjectUtils; -import org.apache.shenyu.common.config.ShenyuConfig; -import org.apache.shenyu.common.constant.Constants; -import org.apache.shenyu.common.constant.DefaultPathConstants; -import static org.apache.shenyu.common.constant.DefaultPathConstants.handlePathData; - -import org.apache.shenyu.infra.etcd.client.EtcdClient; -import org.apache.shenyu.sync.data.api.AuthDataSubscriber; -import org.apache.shenyu.sync.data.api.DiscoveryUpstreamDataSubscriber; -import org.apache.shenyu.sync.data.api.MetaDataSubscriber; -import org.apache.shenyu.sync.data.api.PluginDataSubscriber; -import org.apache.shenyu.sync.data.api.ProxySelectorDataSubscriber; -import org.apache.shenyu.sync.data.core.AbstractPathDataSyncService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; -import java.util.Objects; - -/** - * Data synchronize of etcd. - */ -public class EtcdSyncDataService extends AbstractPathDataSyncService { - - private static final Logger LOG = LoggerFactory.getLogger(EtcdSyncDataService.class); - - private final EtcdClient etcdClient; - - private final ShenyuConfig shenyuConfig; - - /** - * Instantiates a new Zookeeper cache manager. - * - * @param shenyuConfig shenyuConfig - * @param etcdClient etcdClient - * @param pluginDataSubscriber the plugin data subscriber - * @param metaDataSubscribers the meta data subscribers - * @param authDataSubscribers the auth data subscribers - */ - public EtcdSyncDataService(final ShenyuConfig shenyuConfig, - final EtcdClient etcdClient, - final PluginDataSubscriber pluginDataSubscriber, - final List metaDataSubscribers, - final List authDataSubscribers, - final List proxySelectorDataSubscribers, - final List discoveryUpstreamDataSubscribers) { - super(pluginDataSubscriber, metaDataSubscribers, authDataSubscribers, proxySelectorDataSubscribers, discoveryUpstreamDataSubscribers); - this.shenyuConfig = shenyuConfig; - this.etcdClient = etcdClient; - watcherData(); - } - - private void watcherData() { - String configNamespace = Constants.PATH_SEPARATOR + shenyuConfig.getNamespace(); - watcherData0(handlePathData(String.join(Constants.PATH_SEPARATOR, configNamespace, DefaultPathConstants.PLUGIN_PARENT))); - watcherData0(handlePathData(String.join(Constants.PATH_SEPARATOR, configNamespace, DefaultPathConstants.SELECTOR_PARENT))); - watcherData0(handlePathData(String.join(Constants.PATH_SEPARATOR, configNamespace, DefaultPathConstants.RULE_PARENT))); - watcherData0(handlePathData(String.join(Constants.PATH_SEPARATOR, configNamespace, DefaultPathConstants.PROXY_SELECTOR))); - watcherData0(handlePathData(String.join(Constants.PATH_SEPARATOR, configNamespace, DefaultPathConstants.DISCOVERY_UPSTREAM))); - watcherData0(handlePathData(String.join(Constants.PATH_SEPARATOR, configNamespace, DefaultPathConstants.APP_AUTH_PARENT))); - watcherData0(handlePathData(String.join(Constants.PATH_SEPARATOR, configNamespace, DefaultPathConstants.META_DATA))); - } - - private void watcherData0(final String registerPath) { - String configNamespace = Constants.PATH_SEPARATOR + shenyuConfig.getNamespace(); - etcdClient.watchChildChange( - registerPath, - (updatePath, updateValue) -> super.event(configNamespace, updatePath, updateValue, registerPath, EventType.PUT), - deletePath -> super.event(configNamespace, deletePath, null, registerPath, EventType.DELETE)); - try { - // load all key - final List childrenKeys = etcdClient.getChildrenKeys(registerPath, "/"); - if (!ObjectUtils.isEmpty(childrenKeys)) { - childrenKeys.forEach(nodePath -> { - // fix the update path - String updatePath = String.join(Constants.PATH_SEPARATOR, registerPath, nodePath); - final String nodeData = etcdClient.get(updatePath); - super.event(configNamespace, updatePath, nodeData, registerPath, EventType.PUT); - }); - } else { - LOG.info("etcd watcher path {} is empty", registerPath); - } - } catch (Exception e) { - LOG.error("watcherData0 errors", e); - } - } - - @Override - public void close() { - if (Objects.nonNull(etcdClient)) { - etcdClient.close(); - } - } - -} diff --git a/shenyu-sync-data-center/shenyu-sync-data-etcd/src/test/java/org/apache/shenyu/sync/data/etcd/EtcdSyncDataServiceTest.java b/shenyu-sync-data-center/shenyu-sync-data-etcd/src/test/java/org/apache/shenyu/sync/data/etcd/EtcdSyncDataServiceTest.java deleted file mode 100644 index 7f0e423701b7..000000000000 --- a/shenyu-sync-data-center/shenyu-sync-data-etcd/src/test/java/org/apache/shenyu/sync/data/etcd/EtcdSyncDataServiceTest.java +++ /dev/null @@ -1,73 +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.shenyu.sync.data.etcd; - -import org.apache.shenyu.common.config.ShenyuConfig; -import org.apache.shenyu.common.constant.Constants; -import org.apache.shenyu.infra.etcd.client.EtcdClient; -import org.apache.shenyu.sync.data.api.AuthDataSubscriber; -import org.apache.shenyu.sync.data.api.DiscoveryUpstreamDataSubscriber; -import org.apache.shenyu.sync.data.api.MetaDataSubscriber; -import org.apache.shenyu.sync.data.api.PluginDataSubscriber; -import org.apache.shenyu.sync.data.api.ProxySelectorDataSubscriber; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.Collections; -import java.util.function.BiConsumer; -import java.util.function.Consumer; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -/** - * test case for {@link EtcdSyncDataService}. - */ -@ExtendWith(MockitoExtension.class) -public class EtcdSyncDataServiceTest { - - @Test - public void testZookeeperInstanceRegisterRepository() throws Exception { - - EtcdClient etcdClient = mock(EtcdClient.class); - PluginDataSubscriber pluginDataSubscriber = mock(PluginDataSubscriber.class); - doAnswer(invocationOnMock -> { - BiConsumer updateHandler = invocationOnMock.getArgument(1); - updateHandler.accept("updateData", "{}"); - Consumer deleteHandler = invocationOnMock.getArgument(2); - String pluginName = invocationOnMock.getArgument(0); - deleteHandler.accept(pluginName + "removeKey"); - return null; - }).when(etcdClient).watchChildChange(any(), any(), any()); - when(etcdClient.getChildrenKeys(any(), any())).thenReturn(Collections.singletonList("test")); - final AuthDataSubscriber authDataSubscriber = mock(AuthDataSubscriber.class); - final MetaDataSubscriber metaDataSubscriber = mock(MetaDataSubscriber.class); - final ProxySelectorDataSubscriber proxySelectorDataSubscriber = mock(ProxySelectorDataSubscriber.class); - final DiscoveryUpstreamDataSubscriber discoveryUpstreamDataSubscriber = mock(DiscoveryUpstreamDataSubscriber.class); - final ShenyuConfig shenyuConfig = mock(ShenyuConfig.class); - when(shenyuConfig.getNamespace()).thenReturn(Constants.SYS_DEFAULT_NAMESPACE_ID); - final EtcdSyncDataService zookeeperSyncDataService = new EtcdSyncDataService(shenyuConfig, etcdClient, - pluginDataSubscriber, Collections.singletonList(metaDataSubscriber), Collections.singletonList(authDataSubscriber), - Collections.singletonList(proxySelectorDataSubscriber), Collections.singletonList(discoveryUpstreamDataSubscriber)); - - zookeeperSyncDataService.close(); - } -}