From 7f2da41a1babba9321d4c25a134af083eada0e5d Mon Sep 17 00:00:00 2001 From: yangjj-iso <3202137046@qq.com> Date: Wed, 14 Oct 2026 19:11:46 +0800 Subject: [PATCH 01/10] refactor(etcd): prepare plugin-store cutover --- .../scripts/check-registry-dependencies.py | 2 +- README.md | 2 +- docs/plugin-store-etcd.md | 137 +++++ pom.xml | 25 - shenyu-admin-listener/pom.xml | 1 - .../shenyu-admin-listener-etcd/pom.xml | 50 -- .../admin/config/EtcdSyncConfiguration.java | 68 --- .../listener/etcd/EtcdDataChangedInit.java | 52 -- .../etcd/EtcdDataDataChangedListener.java | 49 -- .../main/resources/META-INF/spring.factories | 19 - .../main/resources/META-INF/spring.provides | 18 - ...ot.autoconfigure.AutoConfiguration.imports | 18 - .../config/EtcdSyncConfigurationTest.java | 42 -- .../etcd/EtcdDataChangedInitTest.java | 63 -- .../etcd/EtcdDataDataChangedListenerTest.java | 141 ----- shenyu-admin/pom.xml | 11 - .../src/main/resources/application.yml | 2 - .../src/test/resources/application.yml | 6 +- shenyu-bootstrap/pom.xml | 17 - .../src/main/resources/application.yml | 6 +- .../src/main/release-docs/LICENSE | 4 - .../src/main/release-docs/NOTICE | 12 - .../src/main/release-docs/LICENSE | 4 - .../src/main/release-docs/NOTICE | 12 - .../compose/sync/shenyu-sync-etcd-eureka.yml | 132 ----- .../compose/sync/shenyu-sync-etcd.yml | 128 ---- .../shenyu-e2e-case/k8s/shenyu-etcd.yml | 67 --- .../k8s/sync/shenyu-admin-etcd.yml | 114 ---- .../k8s/sync/shenyu-bootstrap-etcd.yml | 96 --- .../shenyu-e2e-case/k8s/sync/shenyu-cm.yml | 20 +- .../script/e2e-apache-dubbo-sync-compose.sh | 2 +- .../script/e2e-cluster-jdbc-compose.sh | 4 +- .../script/e2e-cluster-zookeeper-compose.sh | 4 +- .../compose/script/e2e-grpc-sync-compose.sh | 2 +- .../compose/script/e2e-http-sync-compose.sh | 2 +- .../script/e2e-logging-kafka-compose.sh | 2 +- .../script/e2e-logging-rocketmq-compose.sh | 2 +- .../script/e2e-springcloud-sync-compose.sh | 2 +- .../k8s/shenyu-cm.yml | 20 +- .../script/e2e-websocket-sync-compose.sh | 2 +- .../src/main/resources/application.yml | 3 - .../src/main/resources/application.yml | 3 - .../src/main/resources/application.yml | 3 - .../src/main/resources/application.yml | 4 +- .../shenyu-examples-springcloud/README.md | 47 +- .../src/main/resources/application.yml | 3 - .../src/main/resources/application.yml | 3 - .../src/main/resources/application.yml | 3 - shenyu-infra/pom.xml | 1 - shenyu-infra/shenyu-infra-etcd/pom.xml | 88 --- .../etcd/autoconfig/ConditionOnSyncEtcd.java | 39 -- .../etcd/autoconfig/EtcdConfiguration.java | 70 --- .../infra/etcd/autoconfig/EtcdProperties.java | 43 -- .../shenyu/infra/etcd/client/EtcdClient.java | 548 ------------------ .../shenyu/infra/etcd/config/EtcdConfig.java | 173 ------ .../main/resources/META-INF/spring.factories | 19 - ...ot.autoconfigure.AutoConfiguration.imports | 18 - .../infra/etcd/client/EtcdClientTest.java | 242 -------- .../properties/AbstractConfigurationTest.java | 69 --- .../etcd/properties/EtcdPropertiesTest.java | 74 --- .../src/main/resources/application.yml | 6 +- .../src/main/resources/application.yml | 6 +- .../src/main/resources/application.yml | 6 +- .../pom.xml | 4 - .../src/main/resources/application.yml | 4 +- .../shenyu-integrated-test-sdk-http/pom.xml | 4 - .../src/main/resources/application.yml | 4 +- shenyu-registry/README.md | 40 +- shenyu-registry/pom.xml | 1 - ...InstanceRegisterRepositoryFactoryTest.java | 6 +- shenyu-registry/shenyu-registry-etcd/pom.xml | 74 --- .../etcd/EtcdInstanceRegisterRepository.java | 172 ------ ...istry.api.ShenyuInstanceRegisterRepository | 17 - .../shenyu/registry/etcd/EtcdClientTest.java | 148 ----- .../EtcdInstanceRegisterRepositoryTest.java | 239 -------- .../shenyu/registry/etcd/RegistrySpiTest.java | 33 -- .../pom.xml | 5 - .../registry/RegistryClasspathTest.java | 4 +- .../pom.xml | 1 - .../pom.xml | 37 -- .../data/etcd/EtcdSyncDataConfiguration.java | 86 --- ...ot.autoconfigure.AutoConfiguration.imports | 18 - shenyu-sync-data-center/pom.xml | 1 - .../shenyu-sync-data-etcd/pom.xml | 42 -- .../sync/data/etcd/EtcdSyncDataService.java | 114 ---- .../data/etcd/EtcdSyncDataServiceTest.java | 73 --- 86 files changed, 204 insertions(+), 3754 deletions(-) create mode 100644 docs/plugin-store-etcd.md delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-etcd/pom.xml delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/java/org/apache/shenyu/admin/config/EtcdSyncConfiguration.java delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/java/org/apache/shenyu/admin/listener/etcd/EtcdDataChangedInit.java delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/java/org/apache/shenyu/admin/listener/etcd/EtcdDataDataChangedListener.java delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/resources/META-INF/spring.factories delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/resources/META-INF/spring.provides delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-etcd/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-etcd/src/test/java/org/apache/shenyu/admin/config/EtcdSyncConfigurationTest.java delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-etcd/src/test/java/org/apache/shenyu/admin/listener/etcd/EtcdDataChangedInitTest.java delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-etcd/src/test/java/org/apache/shenyu/admin/listener/etcd/EtcdDataDataChangedListenerTest.java delete mode 100644 shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-etcd-eureka.yml delete mode 100644 shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-etcd.yml delete mode 100644 shenyu-e2e/shenyu-e2e-case/k8s/shenyu-etcd.yml delete mode 100644 shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-admin-etcd.yml delete mode 100644 shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-bootstrap-etcd.yml delete mode 100644 shenyu-infra/shenyu-infra-etcd/pom.xml delete mode 100644 shenyu-infra/shenyu-infra-etcd/src/main/java/org/apache/shenyu/infra/etcd/autoconfig/ConditionOnSyncEtcd.java delete mode 100644 shenyu-infra/shenyu-infra-etcd/src/main/java/org/apache/shenyu/infra/etcd/autoconfig/EtcdConfiguration.java delete mode 100644 shenyu-infra/shenyu-infra-etcd/src/main/java/org/apache/shenyu/infra/etcd/autoconfig/EtcdProperties.java delete mode 100644 shenyu-infra/shenyu-infra-etcd/src/main/java/org/apache/shenyu/infra/etcd/client/EtcdClient.java delete mode 100644 shenyu-infra/shenyu-infra-etcd/src/main/java/org/apache/shenyu/infra/etcd/config/EtcdConfig.java delete mode 100644 shenyu-infra/shenyu-infra-etcd/src/main/resources/META-INF/spring.factories delete mode 100644 shenyu-infra/shenyu-infra-etcd/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports delete mode 100644 shenyu-infra/shenyu-infra-etcd/src/test/java/org/apache/shenyu/infra/etcd/client/EtcdClientTest.java delete mode 100644 shenyu-infra/shenyu-infra-etcd/src/test/java/org/apache/shenyu/infra/etcd/properties/AbstractConfigurationTest.java delete mode 100644 shenyu-infra/shenyu-infra-etcd/src/test/java/org/apache/shenyu/infra/etcd/properties/EtcdPropertiesTest.java delete mode 100644 shenyu-registry/shenyu-registry-etcd/pom.xml delete mode 100644 shenyu-registry/shenyu-registry-etcd/src/main/java/org/apache/shenyu/registry/etcd/EtcdInstanceRegisterRepository.java delete mode 100644 shenyu-registry/shenyu-registry-etcd/src/main/resources/META-INF/shenyu/org.apache.shenyu.registry.api.ShenyuInstanceRegisterRepository delete mode 100644 shenyu-registry/shenyu-registry-etcd/src/test/java/org/apache/shenyu/registry/etcd/EtcdClientTest.java delete mode 100644 shenyu-registry/shenyu-registry-etcd/src/test/java/org/apache/shenyu/registry/etcd/EtcdInstanceRegisterRepositoryTest.java delete mode 100644 shenyu-registry/shenyu-registry-etcd/src/test/java/org/apache/shenyu/registry/etcd/RegistrySpiTest.java delete mode 100644 shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-etcd/pom.xml delete mode 100644 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 delete mode 100644 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 delete mode 100644 shenyu-sync-data-center/shenyu-sync-data-etcd/pom.xml delete mode 100644 shenyu-sync-data-center/shenyu-sync-data-etcd/src/main/java/org/apache/shenyu/sync/data/etcd/EtcdSyncDataService.java delete mode 100644 shenyu-sync-data-center/shenyu-sync-data-etcd/src/test/java/org/apache/shenyu/sync/data/etcd/EtcdSyncDataServiceTest.java 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 aa217f08d238..3bd8b4ec0f6a 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, etcd, and Apollo are available. 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, Nacos, and Apollo are available. etcd sync and registry are available through [plugin-store-etcd](docs/plugin-store-etcd.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/docs/plugin-store-etcd.md b/docs/plugin-store-etcd.md new file mode 100644 index 000000000000..f091870a775b --- /dev/null +++ b/docs/plugin-store-etcd.md @@ -0,0 +1,137 @@ + +# 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 must remain draft until the community agrees to externalization, +the receiving build and real-server/full-deployment tests pass, and the external +artifacts are published. This source change does not mean artifacts are released. +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 41146d6af896..cdb6bed6cb0d 100644 --- a/pom.xml +++ b/pom.xml @@ -139,7 +139,6 @@ 4.1.139.Final 1.9.6 1.4.200 - 0.7.3 1.5.0 5.11.0 4.0.3 @@ -479,30 +478,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 7ee0cc7eb311..bcd76450dd96 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 de8dd61a610e..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-etcd/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - 4.0.0 - - org.apache.shenyu - shenyu-admin-listener - 2.7.2-SNAPSHOT - - - shenyu-admin-listener-etcd - - - - - 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 3da4f9fd0ce3..47e16b771e68 100644 --- a/shenyu-admin/pom.xml +++ b/shenyu-admin/pom.xml @@ -309,11 +309,6 @@ - - org.apache.shenyu - shenyu-admin-listener-etcd - ${project.version} - org.apache.shenyu @@ -354,12 +349,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 69af897f43b5..031974c9247f 100755 --- a/shenyu-admin/src/main/resources/application.yml +++ b/shenyu-admin/src/main/resources/application.yml @@ -108,8 +108,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 e730a56af103..5ee75fce86a1 100644 --- a/shenyu-bootstrap/pom.xml +++ b/shenyu-bootstrap/pom.xml @@ -385,23 +385,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 e861868a07e0..b55bf51af62f 100644 --- a/shenyu-bootstrap/src/main/resources/application.yml +++ b/shenyu-bootstrap/src/main/resources/application.yml @@ -189,8 +189,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 @@ -251,8 +251,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 59c528566caa..f2aa8acbf18e 100644 --- a/shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE +++ b/shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE @@ -277,10 +277,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 json-path 2.7.0: https://github.com/jayway/JsonPath, Apache 2.0 json-smart 2.4.11: https://www.minidev.net/, Apache 2.0 jsqlparser 4.5: https://github.com/JSQLParser/JSqlParser, Apache 2.0 diff --git a/shenyu-dist/shenyu-admin-dist/src/main/release-docs/NOTICE b/shenyu-dist/shenyu-admin-dist/src/main/release-docs/NOTICE index 7553eb06da74..6b7c6b678682 100644 --- a/shenyu-dist/shenyu-admin-dist/src/main/release-docs/NOTICE +++ b/shenyu-dist/shenyu-admin-dist/src/main/release-docs/NOTICE @@ -304,18 +304,6 @@ be obtained at: * HOMEPAGE: * https://github.com/catapult-project/catapult -=========================================================================== - -jetcd Notice - -=========================================================================== - -CoreOS Project -Copyright 2018 CoreOS, Inc - -This product includes software developed at CoreOS, Inc. -(http://www.coreos.com/). - ======================================================================== Netty NOTICE 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 6e66f46a1080..6525b561dd0e 100644 --- a/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/LICENSE +++ b/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/LICENSE @@ -331,10 +331,6 @@ The text of each license is the standard Apache 2.0 license. javapoet 1.8.0: https://github.com/square/javapoet, Apache 2.0 javassist 3.29.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 jettison 1.5.4: https://github.com/jettison-json/jettison, Apache 2.0 jcommander 1.78: https://mvnrepository.com/artifact/com.beust/jcommander, Apache 2.0 jjwt-api 0.12.3: https://jwt.io, Apache 2.0 diff --git a/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/NOTICE b/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/NOTICE index 1f505ba590f5..84b14dd7675c 100644 --- a/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/NOTICE +++ b/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/NOTICE @@ -291,18 +291,6 @@ be obtained at: * HOMEPAGE: * https://github.com/catapult-project/catapult -=========================================================================== - -jetcd Notice - -=========================================================================== - -CoreOS Project -Copyright 2018 CoreOS, Inc - -This product includes software developed at CoreOS, Inc. -(http://www.coreos.com/). - ======================================================================== byte-buddy NOTICE 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 549294de2cd6..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", "-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 bf2df79e1e6f..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", "-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 641cc16ef5b7..128664480bb0 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-apache-dubbo/compose/script/e2e-apache-dubbo-sync-compose.sh b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-apache-dubbo/compose/script/e2e-apache-dubbo-sync-compose.sh index 24315f02e448..fc601ac7be90 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-apache-dubbo/compose/script/e2e-apache-dubbo-sync-compose.sh +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-apache-dubbo/compose/script/e2e-apache-dubbo-sync-compose.sh @@ -26,7 +26,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-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 506f83c2b209..a37b0df5e3d0 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 3c79e745184a..83b2a7d3e07b 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-grpc/compose/script/e2e-grpc-sync-compose.sh b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-grpc/compose/script/e2e-grpc-sync-compose.sh index c81fd62a4caf..7db33d03169a 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-grpc/compose/script/e2e-grpc-sync-compose.sh +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-grpc/compose/script/e2e-grpc-sync-compose.sh @@ -26,7 +26,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-http/compose/script/e2e-http-sync-compose.sh b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-http/compose/script/e2e-http-sync-compose.sh index 790884fdf998..740647f6d94e 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-http/compose/script/e2e-http-sync-compose.sh +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-http/compose/script/e2e-http-sync-compose.sh @@ -65,7 +65,7 @@ start_examples() { # 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 || true 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-logging-rocketmq/compose/script/e2e-logging-rocketmq-compose.sh b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-logging-rocketmq/compose/script/e2e-logging-rocketmq-compose.sh index 4620d9b73f6f..e313733ecf3a 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-logging-rocketmq/compose/script/e2e-logging-rocketmq-compose.sh +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-logging-rocketmq/compose/script/e2e-logging-rocketmq-compose.sh @@ -26,7 +26,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") wait_for_port() { local host="$1" diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/compose/script/e2e-springcloud-sync-compose.sh b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/compose/script/e2e-springcloud-sync-compose.sh index 7fc9332332b6..f39371feded7 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/compose/script/e2e-springcloud-sync-compose.sh +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/compose/script/e2e-springcloud-sync-compose.sh @@ -26,7 +26,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 0f9fd2f09007..f12229992906 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-e2e/shenyu-e2e-case/shenyu-e2e-case-websocket/compose/script/e2e-websocket-sync-compose.sh b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-websocket/compose/script/e2e-websocket-sync-compose.sh index 5f55416b89ed..215eb7cd8662 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-websocket/compose/script/e2e-websocket-sync-compose.sh +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-websocket/compose/script/e2e-websocket-sync-compose.sh @@ -26,7 +26,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-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 b6da910fecd7..8d38141b8647 100644 --- a/shenyu-infra/pom.xml +++ b/shenyu-infra/pom.xml @@ -27,7 +27,6 @@ pom - 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 90f2a8ddaa74..000000000000 --- a/shenyu-infra/shenyu-infra-etcd/pom.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - org.apache.shenyu - shenyu-infra - 2.7.2-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 b2cad8ad71d8..ac9a5b111361 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 b2cad8ad71d8..ac9a5b111361 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 34a7ecd17367..e3df8010b3e1 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 @@ -182,8 +182,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 @@ -242,8 +242,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 909756501752..3949337a873c 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 5ce537d271ea..7977b5431906 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 d91f0f8ef0e5..d5edf57d6fdd 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` | | `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 01b7c2397573..91bd91993905 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 d42e57ba3f75..f50e3f9494fb 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"); ShenyuInstanceRegisterRepository polaris = ShenyuInstanceRegisterRepositoryFactory.newInstance("polaris"); + ShenyuInstanceRegisterRepository etcd = ShenyuInstanceRegisterRepositoryFactory.loadRepository("etcd"); + assertNotSame(etcd, ShenyuInstanceRegisterRepositoryFactory.loadRepository("etcd")); assertNotSame(consul, polaris); assertSame(consul, ShenyuInstanceRegisterRepositoryFactory.newInstance("consul")); assertSame(polaris, ShenyuInstanceRegisterRepositoryFactory.newInstance("polaris")); IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> ShenyuInstanceRegisterRepositoryFactory.newInstance("unknown")); - 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 c860fd2b5855..000000000000 --- a/shenyu-registry/shenyu-registry-etcd/pom.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - org.apache.shenyu - shenyu-registry - 2.7.2-SNAPSHOT - - 4.0.0 - shenyu-registry-etcd - - - - 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 715b81f38862..f30b264d0878 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 ecc35648c6c3..3c45c980896b 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 @@ -31,7 +31,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 e1c37226ced2..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.2-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 7467a32ad790..2d97c8579566 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 0f7bc4376454..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.2-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(); - } -} From 1b232164f0cb82decddbcc3bbdee57831e074698 Mon Sep 17 00:00:00 2001 From: yangjj-iso <3202137046@qq.com> Date: Fri, 16 Oct 2026 14:10:15 +0800 Subject: [PATCH 02/10] docs: clarify retained sync providers during etcd cutover --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c653443ad2fe..ce215e22ddb6 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 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. | +| 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. | From 2b1d63dcfc299d4a87ef437a17993f46ecac43b7 Mon Sep 17 00:00:00 2001 From: yangjj-iso <3202137046@qq.com> Date: Fri, 16 Oct 2026 13:54:47 +0800 Subject: [PATCH 03/10] test(sync): assert proxy selector deletion by ID --- .../apache/shenyu/sync/data/apollo/ApolloDataServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shenyu-sync-data-center/shenyu-sync-data-apollo/src/test/java/org/apache/shenyu/sync/data/apollo/ApolloDataServiceTest.java b/shenyu-sync-data-center/shenyu-sync-data-apollo/src/test/java/org/apache/shenyu/sync/data/apollo/ApolloDataServiceTest.java index 9db5392159e4..107e3a3158e6 100644 --- a/shenyu-sync-data-center/shenyu-sync-data-apollo/src/test/java/org/apache/shenyu/sync/data/apollo/ApolloDataServiceTest.java +++ b/shenyu-sync-data-center/shenyu-sync-data-apollo/src/test/java/org/apache/shenyu/sync/data/apollo/ApolloDataServiceTest.java @@ -280,7 +280,7 @@ void testProxySelectorDataDeleted() { ArgumentCaptor captor = ArgumentCaptor.forClass(ProxySelectorData.class); verify(proxySelectorDataSubscriber, times(1)).unSubscribe(captor.capture()); assertEquals("test-plugin", captor.getValue().getPluginName()); - assertEquals("test-proxy", captor.getValue().getName()); + assertEquals("test-proxy", captor.getValue().getId()); } @Test From 14967aae5908545aa5e174914a82d7c445096492 Mon Sep 17 00:00:00 2001 From: yangjj-iso <3202137046@qq.com> Date: Fri, 16 Oct 2026 14:47:40 +0800 Subject: [PATCH 04/10] test(e2e): use local HTTP fixture for wait helper checks --- .../engine/function/WaitForHelperTest.java | 69 +++++++++++++++++-- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/shenyu-e2e/shenyu-e2e-engine/src/test/java/org/apache/shenyu/e2e/engine/function/WaitForHelperTest.java b/shenyu-e2e/shenyu-e2e-engine/src/test/java/org/apache/shenyu/e2e/engine/function/WaitForHelperTest.java index 10220adb54ac..9f07f4a5bd8a 100644 --- a/shenyu-e2e/shenyu-e2e-engine/src/test/java/org/apache/shenyu/e2e/engine/function/WaitForHelperTest.java +++ b/shenyu-e2e/shenyu-e2e-engine/src/test/java/org/apache/shenyu/e2e/engine/function/WaitForHelperTest.java @@ -17,13 +17,23 @@ package org.apache.shenyu.e2e.engine.function; -import org.apache.shenyu.e2e.engine.scenario.function.WaitForHelper; +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpServer; import io.restassured.builder.ResponseSpecBuilder; import io.restassured.http.Method; +import org.apache.shenyu.e2e.engine.scenario.function.WaitForHelper; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.nio.charset.StandardCharsets; import java.time.Duration; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import static io.restassured.RestAssured.given; @@ -31,26 +41,73 @@ import static org.hamcrest.CoreMatchers.equalTo; public class WaitForHelperTest { - + + private final CountDownLatch delayedRequest = new CountDownLatch(1); + + private final CountDownLatch releaseResponse = new CountDownLatch(1); + + private HttpServer server; + + @BeforeEach + void setUp() throws IOException { + server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0); + server.createContext("/get", exchange -> writeJson(exchange, "{\"url\":\"" + exchange.getRequestURI() + "\"}")); + server.createContext("/delay/2", exchange -> { + delayedRequest.countDown(); + try { + releaseResponse.await(); + writeJson(exchange, "{\"delay\":2}"); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + exchange.close(); + } + }); + server.start(); + // Initialize the HTTP client before measuring the helper's short timeout. + given().baseUri(baseUri()).get("/get").then().statusCode(200); + } + + @AfterEach + void tearDown() { + releaseResponse.countDown(); + server.stop(0); + } + @Test void testSuccess() throws TimeoutException { new WaitForHelper().waitFor( - () -> given().baseUri("https://postman-echo.com").when(), + () -> given().baseUri(baseUri()).when(), Method.GET, "/get?foo1=bar1&foo2=bar2", new ResponseSpecBuilder().expectBody("url", containsString("/get")).build() ); } - + @Test - void testTimeout() { + void testTimeout() throws InterruptedException { Assertions.assertThrows(TimeoutException.class, () -> new WaitForHelper(10, Duration.ofSeconds(1), Duration.ofMillis(500)).waitFor( - () -> given().baseUri("https://postman-echo.com").when(), + () -> given().baseUri(baseUri()).when(), Method.GET, "/delay/2", new ResponseSpecBuilder().expectBody("delay", equalTo(2)).build() ) ); + Assertions.assertTrue(delayedRequest.await(2, TimeUnit.SECONDS)); + } + + private String baseUri() { + return "http://127.0.0.1:" + server.getAddress().getPort(); + } + + private static void writeJson(final HttpExchange exchange, final String body) throws IOException { + byte[] bytes = body.getBytes(StandardCharsets.UTF_8); + exchange.getResponseHeaders().set("Content-Type", "application/json"); + exchange.sendResponseHeaders(200, bytes.length); + try (OutputStream output = exchange.getResponseBody()) { + output.write(bytes); + } finally { + exchange.close(); + } } } From 4317a16377b95516a505b5a41a701bc764a4b52b Mon Sep 17 00:00:00 2001 From: yangjj-iso <3202137046@qq.com> Date: Fri, 16 Oct 2026 18:48:29 +0800 Subject: [PATCH 05/10] test(e2e): use a local upstream for storage and cluster routing --- .github/workflows/e2e-k8s.yml | 2 + .../compose/fixtures/httpbin.py | 57 +++++++++++ .../compose/fixtures/httpbin.yml | 31 ++++++ .../compose/fixtures/test_httpbin.py | 97 +++++++++++++++++++ .../compose/storage/shenyu-storage-h2.yml | 6 ++ .../compose/storage/shenyu-storage-mysql.yml | 6 ++ .../storage/shenyu-storage-opengauss.yml | 6 ++ .../storage/shenyu-storage-postgres.yml | 6 ++ .../shenyu-sync-websocket-cluster-jdbc.yml | 6 ++ ...henyu-sync-websocket-cluster-zookeeper.yml | 6 ++ 10 files changed, 223 insertions(+) create mode 100644 shenyu-e2e/shenyu-e2e-case/compose/fixtures/httpbin.py create mode 100644 shenyu-e2e/shenyu-e2e-case/compose/fixtures/httpbin.yml create mode 100644 shenyu-e2e/shenyu-e2e-case/compose/fixtures/test_httpbin.py diff --git a/.github/workflows/e2e-k8s.yml b/.github/workflows/e2e-k8s.yml index c0b6775f8b49..bfd0e1f3834a 100644 --- a/.github/workflows/e2e-k8s.yml +++ b/.github/workflows/e2e-k8s.yml @@ -63,6 +63,8 @@ jobs: submodules: true - name: Test conditional disk cleanup run: bash .github/scripts/free-disk-space-test.sh + - name: Test local HTTP upstream fixture and Compose wiring + run: python3 -B shenyu-e2e/shenyu-e2e-case/compose/fixtures/test_httpbin.py - uses: ./actions/paths-filter id: filter with: diff --git a/shenyu-e2e/shenyu-e2e-case/compose/fixtures/httpbin.py b/shenyu-e2e/shenyu-e2e-case/compose/fixtures/httpbin.py new file mode 100644 index 000000000000..08c291145c4c --- /dev/null +++ b/shenyu-e2e/shenyu-e2e-case/compose/fixtures/httpbin.py @@ -0,0 +1,57 @@ +# 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. + +"""Local upstream for the Divide URI and HTTP method routing scenarios.""" + +import json +from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer +from urllib.parse import parse_qs, urlsplit + + +class HttpbinHandler(BaseHTTPRequestHandler): + protocol_version = "HTTP/1.1" + + def respond(self): + path = urlsplit(self.path) + data = self.rfile.read(int(self.headers.get("Content-Length", "0"))) + status = 200 + if path.path == "/status/200": + body = b"" + elif path.path == "/anything" or path.path.startswith("/anything/"): + body = json.dumps({ + "method": self.command, + "url": self.path, + "args": parse_qs(path.query), + "data": data.decode("utf-8"), + }).encode("utf-8") + else: + status = 404 + body = b'{"error":"unknown fixture endpoint"}' + self.send_response(status) + self.send_header("Content-Type", "application/json") + self.send_header("Content-Length", str(len(body))) + self.end_headers() + if self.command != "HEAD": + self.wfile.write(body) + + do_GET = respond + do_POST = respond + do_PUT = respond + do_DELETE = respond + do_HEAD = respond + + +if __name__ == "__main__": + ThreadingHTTPServer(("0.0.0.0", 80), HttpbinHandler).serve_forever() diff --git a/shenyu-e2e/shenyu-e2e-case/compose/fixtures/httpbin.yml b/shenyu-e2e/shenyu-e2e-case/compose/fixtures/httpbin.yml new file mode 100644 index 000000000000..762d031d120b --- /dev/null +++ b/shenyu-e2e/shenyu-e2e-case/compose/fixtures/httpbin.yml @@ -0,0 +1,31 @@ +# 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. + +services: + httpbin: + image: python:3.12-alpine + command: ["python", "-B", "-u", "/opt/httpbin.py"] + volumes: + - ./httpbin.py:/opt/httpbin.py:ro + healthcheck: + test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1/anything', timeout=2)"] + interval: 2s + timeout: 3s + retries: 15 + networks: + shenyu: + # Existing routing scenarios resolve their upstream on this test network. + aliases: + - httpbin.org diff --git a/shenyu-e2e/shenyu-e2e-case/compose/fixtures/test_httpbin.py b/shenyu-e2e/shenyu-e2e-case/compose/fixtures/test_httpbin.py new file mode 100644 index 000000000000..ec0741a1a6a8 --- /dev/null +++ b/shenyu-e2e/shenyu-e2e-case/compose/fixtures/test_httpbin.py @@ -0,0 +1,97 @@ +# 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. + +"""Exercise the upstream over HTTP and validate every consuming Compose file.""" + +import http.client +import json +from pathlib import Path +import subprocess +import threading +import unittest + +from httpbin import HttpbinHandler, ThreadingHTTPServer + + +class HttpbinTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.server = ThreadingHTTPServer(("127.0.0.1", 0), HttpbinHandler) + cls.thread = threading.Thread(target=cls.server.serve_forever) + cls.thread.start() + + @classmethod + def tearDownClass(cls): + cls.server.shutdown() + cls.server.server_close() + cls.thread.join() + + def setUp(self): + self.connection = http.client.HTTPConnection(*self.server.server_address, timeout=3) + + def tearDown(self): + self.connection.close() + + def test_echo_methods_paths_and_request_bodies(self): + for method in ("GET", "POST", "PUT", "DELETE"): + for path in ("/anything", "/anything/xx", "/anything/xx/yy", "/anything/xxx"): + with self.subTest(method=method, path=path): + self.connection.request(method, path + "?id=23", body="request body") + response = self.connection.getresponse() + self.assertEqual(200, response.status) + body = json.loads(response.read()) + self.assertEqual(method, body["method"]) + self.assertEqual(path + "?id=23", body["url"]) + self.assertEqual({"id": ["23"]}, body["args"]) + self.assertEqual("request body", body["data"]) + + def test_status_200_has_empty_body_for_every_method(self): + for method in ("GET", "POST", "PUT", "DELETE", "HEAD"): + with self.subTest(method=method): + self.connection.request(method, "/status/200") + response = self.connection.getresponse() + self.assertEqual(200, response.status) + self.assertEqual(b"", response.read()) + + def test_unknown_path_is_not_a_success(self): + self.connection.request("GET", "/not-a-fixture") + response = self.connection.getresponse() + self.assertEqual(404, response.status) + response.read() + + def test_compose_uses_healthy_local_upstream(self): + directory = Path(__file__).resolve().parent + compose = directory.parent + files = sorted((compose / "storage").glob("shenyu-storage-*.yml")) + files += sorted((compose / "sync").glob("shenyu-sync-websocket-cluster-*.yml")) + self.assertEqual(6, len(files)) + for path in files: + with self.subTest(compose=path.name): + result = subprocess.run( + ["docker", "compose", "-f", str(path), "config", "--format", "json"], + check=True, capture_output=True, text=True, + ) + services = json.loads(result.stdout)["services"] + fixture = services["httpbin"] + self.assertIn("httpbin.org", fixture["networks"]["shenyu"]["aliases"]) + self.assertEqual("service_healthy", services["shenyu-bootstrap"]["depends_on"]["httpbin"]["condition"]) + mount = next(v for v in fixture["volumes"] if v["target"] == "/opt/httpbin.py") + self.assertEqual(directory / "httpbin.py", Path(mount["source"])) + self.assertTrue(mount["read_only"]) + self.assertIn("/anything", fixture["healthcheck"]["test"][-1]) + + +if __name__ == "__main__": + unittest.main() diff --git a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-h2.yml b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-h2.yml index c35ccd1dbecb..a722a0501f57 100644 --- a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-h2.yml +++ b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-h2.yml @@ -17,6 +17,10 @@ version: '3.9' services: + httpbin: + extends: + file: ../fixtures/httpbin.yml + service: httpbin shenyu-admin: image: apache/shenyu-admin:latest @@ -63,6 +67,8 @@ services: start_period: 30s restart: always depends_on: + httpbin: + condition: service_healthy shenyu-admin: condition: service_healthy networks: diff --git a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-mysql.yml b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-mysql.yml index 06f0b40476ec..2141c9d9a8ec 100644 --- a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-mysql.yml +++ b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-mysql.yml @@ -17,6 +17,10 @@ version: '3.9' services: + httpbin: + extends: + file: ../fixtures/httpbin.yml + service: httpbin shenyu-mysql: image: mysql:8.0 container_name: shenyu-mysql @@ -98,6 +102,8 @@ services: start_period: 30s restart: always depends_on: + httpbin: + condition: service_healthy shenyu-admin: condition: service_healthy networks: diff --git a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-opengauss.yml b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-opengauss.yml index d0c3b6622836..53f62e6303da 100644 --- a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-opengauss.yml +++ b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-opengauss.yml @@ -17,6 +17,10 @@ version: '3.9' services: + httpbin: + extends: + file: ../fixtures/httpbin.yml + service: httpbin shenyu-opengauss: image: enmotech/opengauss-lite:5.0.1 container_name: shenyu-opengauss @@ -97,6 +101,8 @@ services: start_period: 30s restart: always depends_on: + httpbin: + condition: service_healthy shenyu-admin: condition: service_healthy networks: diff --git a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-postgres.yml b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-postgres.yml index 29e3e87acae0..147d78b699dc 100644 --- a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-postgres.yml +++ b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-postgres.yml @@ -17,6 +17,10 @@ version: '3.9' services: + httpbin: + extends: + file: ../fixtures/httpbin.yml + service: httpbin shenyu-postgres: image: postgres:14 container_name: shenyu-postgres @@ -97,6 +101,8 @@ services: start_period: 30s restart: always depends_on: + httpbin: + condition: service_healthy shenyu-admin: condition: service_healthy networks: diff --git a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-jdbc.yml b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-jdbc.yml index 85ac6bf35c80..7142d5d8d52b 100644 --- a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-jdbc.yml +++ b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-jdbc.yml @@ -17,6 +17,10 @@ version: '3.9' services: + httpbin: + extends: + file: ../fixtures/httpbin.yml + service: httpbin shenyu-mysql: image: mysql:8.0 container_name: shenyu-mysql @@ -133,6 +137,8 @@ services: start_period: 30s restart: always depends_on: + httpbin: + condition: service_healthy shenyu-admin-1: condition: service_healthy shenyu-admin-2: diff --git a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-zookeeper.yml b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-zookeeper.yml index 58d3d41b5b6b..79dea728bef4 100644 --- a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-zookeeper.yml +++ b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-zookeeper.yml @@ -17,6 +17,10 @@ version: '3.9' services: + httpbin: + extends: + file: ../fixtures/httpbin.yml + service: httpbin shenyu-zookeeper-cluster: image: zookeeper:3.9 container_name: shenyu-zookeeper-cluster @@ -158,6 +162,8 @@ services: start_period: 30s restart: always depends_on: + httpbin: + condition: service_healthy shenyu-admin-1: condition: service_healthy shenyu-admin-2: From 5a5e07613e8eb0d92cee612b6d9191f2dcc224ce Mon Sep 17 00:00:00 2001 From: yangjj-iso <3202137046@qq.com> Date: Fri, 16 Oct 2026 18:51:38 +0800 Subject: [PATCH 06/10] test(e2e): retain RocketMQ logs produced before queue assignment --- .../logging/rocketmq/DividePluginCases.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-logging-rocketmq/src/test/java/org/apache/shenyu/e2e/testcase/logging/rocketmq/DividePluginCases.java b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-logging-rocketmq/src/test/java/org/apache/shenyu/e2e/testcase/logging/rocketmq/DividePluginCases.java index 87ce0e4a9643..baa5201f00e2 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-logging-rocketmq/src/test/java/org/apache/shenyu/e2e/testcase/logging/rocketmq/DividePluginCases.java +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-logging-rocketmq/src/test/java/org/apache/shenyu/e2e/testcase/logging/rocketmq/DividePluginCases.java @@ -23,6 +23,7 @@ import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; +import org.apache.rocketmq.common.consumer.ConsumeFromWhere; import org.apache.shenyu.e2e.engine.scenario.ShenYuScenarioProvider; import org.apache.shenyu.e2e.engine.scenario.specification.ScenarioSpec; import org.apache.shenyu.e2e.engine.scenario.specification.ShenYuBeforeEachSpec; @@ -35,8 +36,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.nio.charset.StandardCharsets; import java.time.Duration; import java.util.List; +import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; import static org.apache.shenyu.e2e.engine.scenario.function.HttpCheckers.exists; @@ -103,15 +106,19 @@ private ShenYuScenarioSpec testRocketMQHello() { ShenYuCaseSpec.builder() .add(request -> { AtomicBoolean isLog = new AtomicBoolean(false); - DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(CONSUMERGROUP); + String requestId = UUID.randomUUID().toString(); + String endpoint = "/http/order/findById?id=23&e2e=" + requestId; + DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(CONSUMERGROUP + "-" + requestId); try { consumer.setNamesrvAddr(NAMESERVER); + // Queue assignment may happen after the request has already been logged. + consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET); consumer.subscribe(TOPIC, "*"); consumer.registerMessageListener((MessageListenerConcurrently) (msgs, consumeConcurrentlyContext) -> { LOG.info("Msg:{}", msgs); if (CollectionUtils.isNotEmpty(msgs)) { msgs.forEach(e -> { - if (new String(e.getBody()).contains("/http/order/findById?id=23")) { + if (new String(e.getBody(), StandardCharsets.UTF_8).contains(endpoint)) { isLog.set(true); } }); @@ -120,7 +127,7 @@ private ShenYuScenarioSpec testRocketMQHello() { }); consumer.start(); LOG.info("RocketMQ consumer started"); - request.request(Method.GET, "/http/order/findById?id=23"); + request.request(Method.GET, endpoint).then().statusCode(200); await().atMost(LOG_CONSUME_TIMEOUT).untilTrue(isLog); LOG.info("isLog.get():{}", isLog.get()); } catch (Exception e) { From 66fd9800dbe5b564933d636736467adb1831b501 Mon Sep 17 00:00:00 2001 From: yangjj-iso <3202137046@qq.com> Date: Fri, 16 Oct 2026 18:51:38 +0800 Subject: [PATCH 07/10] test(e2e): await discovered Spring Cloud route readiness --- .../shenyu-e2e-case-spring-cloud/pom.xml | 9 +++ .../springcloud/SpringCloudPluginTest.java | 28 +++++---- .../SpringCloudRouteReadinessTest.java | 57 +++++++++++++++++++ 3 files changed, 82 insertions(+), 12 deletions(-) create mode 100644 shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/src/test/java/org/apache/shenyu/e2e/testcase/springcloud/SpringCloudRouteReadinessTest.java diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/pom.xml b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/pom.xml index 4ff46f9ed993..ef1d944bd275 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/pom.xml +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/pom.xml @@ -28,4 +28,13 @@ shenyu-e2e-case-spring-cloud + + + org.awaitility + awaitility + ${awaitility.version} + test + + + diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/src/test/java/org/apache/shenyu/e2e/testcase/springcloud/SpringCloudPluginTest.java b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/src/test/java/org/apache/shenyu/e2e/testcase/springcloud/SpringCloudPluginTest.java index d2847f639e25..6c03a464a241 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/src/test/java/org/apache/shenyu/e2e/testcase/springcloud/SpringCloudPluginTest.java +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/src/test/java/org/apache/shenyu/e2e/testcase/springcloud/SpringCloudPluginTest.java @@ -20,7 +20,6 @@ import org.apache.shenyu.e2e.client.WaitDataSync; import org.apache.shenyu.e2e.client.admin.AdminClient; import org.apache.shenyu.e2e.client.gateway.GatewayClient; -import org.apache.shenyu.e2e.constant.Constants; import org.apache.shenyu.e2e.engine.annotation.ShenYuScenario; import org.apache.shenyu.e2e.engine.annotation.ShenYuTest; import org.apache.shenyu.e2e.engine.scenario.specification.CaseSpec; @@ -31,9 +30,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashMap; +import java.time.Duration; import java.util.List; -import java.util.Map; + +import static org.awaitility.Awaitility.await; +import static org.hamcrest.Matchers.equalTo; /** * Testing spring-cloud plugin. @@ -74,17 +75,20 @@ public void setup(final AdminClient adminClient, final GatewayClient gatewayClie List selectorCache = gatewayClient.getSelectorCache(); LOG.info("selectorCache: {}", selectorCache); - Map reqBody = new HashMap<>(); - reqBody.put("pluginId", "5"); - reqBody.put("name", "divide"); - reqBody.put("enabled", "true"); - reqBody.put("role", "Proxy"); - reqBody.put("sort", "200"); - reqBody.put("config", "{\"enabled\":true}"); - reqBody.put("namespaceId", Constants.SYS_DEFAULT_NAMESPACE_NAMESPACE_ID); - adminClient.changePluginStatus("1801816010882822185", reqBody); WaitDataSync.waitGatewayPluginUse(gatewayClient, "org.apache.shenyu.plugin.divide.DividePlugin"); + waitForRegisteredRoute(gatewayClient); + } + static void waitForRegisteredRoute(final GatewayClient gatewayClient) { + // Selector/rule synchronization can complete before Eureka publishes the upstream. + await().alias("Spring Cloud discovery upstream routes through the gateway") + .atMost(Duration.ofSeconds(90)) + .pollInterval(Duration.ofMillis(200)) + .untilAsserted(() -> gatewayClient.getHttpRequesterSupplier().get() + .get("/springcloud/order/path/123/hahah") + .then().statusCode(200) + .body("id", equalTo("123")) + .body("name", equalTo("hahah"))); } @ShenYuScenario(provider = SpringCloudPluginCases.class) diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/src/test/java/org/apache/shenyu/e2e/testcase/springcloud/SpringCloudRouteReadinessTest.java b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/src/test/java/org/apache/shenyu/e2e/testcase/springcloud/SpringCloudRouteReadinessTest.java new file mode 100644 index 000000000000..8071fb2ef60c --- /dev/null +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/src/test/java/org/apache/shenyu/e2e/testcase/springcloud/SpringCloudRouteReadinessTest.java @@ -0,0 +1,57 @@ +/* + * 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.e2e.testcase.springcloud; + +import com.sun.net.httpserver.HttpServer; +import org.apache.shenyu.e2e.client.gateway.GatewayClient; +import org.junit.jupiter.api.Test; + +import java.net.InetSocketAddress; +import java.nio.charset.StandardCharsets; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +class SpringCloudRouteReadinessTest { + + @Test + void waitsForDiscoveredUpstreamAndExpectedResponse() throws Exception { + AtomicInteger requests = new AtomicInteger(); + HttpServer server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0); + server.createContext("/springcloud/order/path/123/hahah", exchange -> { + int attempt = requests.incrementAndGet(); + byte[] body = (attempt < 3 ? "{\"code\":-107,\"message\":\"upstream not ready\"}" + : "{\"id\":\"123\",\"name\":\"hahah\"}").getBytes(StandardCharsets.UTF_8); + exchange.getResponseHeaders().set("Content-Type", "application/json"); + exchange.sendResponseHeaders(attempt == 1 ? 503 : 200, body.length); + try (var output = exchange.getResponseBody()) { + output.write(body); + } + }); + server.start(); + try { + GatewayClient gateway = new GatewayClient("readiness-test", "gateway", + "http://127.0.0.1:" + server.getAddress().getPort(), new Properties()); + SpringCloudPluginTest.waitForRegisteredRoute(gateway); + assertTrue(requests.get() >= 3); + } finally { + server.stop(0); + } + } +} From 3cc522d9f340542ae297f395dfc925ab20b358eb Mon Sep 17 00:00:00 2001 From: yangjj-iso <3202137046@qq.com> Date: Fri, 16 Oct 2026 19:09:40 +0800 Subject: [PATCH 08/10] test(e2e): match the Spring Cloud controller response --- .../shenyu/e2e/testcase/springcloud/SpringCloudPluginTest.java | 2 +- .../e2e/testcase/springcloud/SpringCloudRouteReadinessTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/src/test/java/org/apache/shenyu/e2e/testcase/springcloud/SpringCloudPluginTest.java b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/src/test/java/org/apache/shenyu/e2e/testcase/springcloud/SpringCloudPluginTest.java index 6c03a464a241..5166c418eda5 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/src/test/java/org/apache/shenyu/e2e/testcase/springcloud/SpringCloudPluginTest.java +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/src/test/java/org/apache/shenyu/e2e/testcase/springcloud/SpringCloudPluginTest.java @@ -88,7 +88,7 @@ static void waitForRegisteredRoute(final GatewayClient gatewayClient) { .get("/springcloud/order/path/123/hahah") .then().statusCode(200) .body("id", equalTo("123")) - .body("name", equalTo("hahah"))); + .body("name", equalTo("hello world spring cloud restful: hahah"))); } @ShenYuScenario(provider = SpringCloudPluginCases.class) diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/src/test/java/org/apache/shenyu/e2e/testcase/springcloud/SpringCloudRouteReadinessTest.java b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/src/test/java/org/apache/shenyu/e2e/testcase/springcloud/SpringCloudRouteReadinessTest.java index 8071fb2ef60c..ee1adb461280 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/src/test/java/org/apache/shenyu/e2e/testcase/springcloud/SpringCloudRouteReadinessTest.java +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/src/test/java/org/apache/shenyu/e2e/testcase/springcloud/SpringCloudRouteReadinessTest.java @@ -37,7 +37,7 @@ void waitsForDiscoveredUpstreamAndExpectedResponse() throws Exception { server.createContext("/springcloud/order/path/123/hahah", exchange -> { int attempt = requests.incrementAndGet(); byte[] body = (attempt < 3 ? "{\"code\":-107,\"message\":\"upstream not ready\"}" - : "{\"id\":\"123\",\"name\":\"hahah\"}").getBytes(StandardCharsets.UTF_8); + : "{\"id\":\"123\",\"name\":\"hello world spring cloud restful: hahah\"}").getBytes(StandardCharsets.UTF_8); exchange.getResponseHeaders().set("Content-Type", "application/json"); exchange.sendResponseHeaders(attempt == 1 ? 503 : 200, body.length); try (var output = exchange.getResponseBody()) { From cf84f14aa83c1d1cb88879254f997da222da33b3 Mon Sep 17 00:00:00 2001 From: yangjj-iso <3202137046@qq.com> Date: Fri, 16 Oct 2026 19:09:40 +0800 Subject: [PATCH 09/10] test(e2e): explicitly assign RocketMQ log queues after topic creation --- .../logging/rocketmq/DividePluginCases.java | 68 +++++++++----- .../rocketmq/RocketMQLogConsumptionTest.java | 94 +++++++++++++++++++ 2 files changed, 140 insertions(+), 22 deletions(-) create mode 100644 shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-logging-rocketmq/src/test/java/org/apache/shenyu/e2e/testcase/logging/rocketmq/RocketMQLogConsumptionTest.java diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-logging-rocketmq/src/test/java/org/apache/shenyu/e2e/testcase/logging/rocketmq/DividePluginCases.java b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-logging-rocketmq/src/test/java/org/apache/shenyu/e2e/testcase/logging/rocketmq/DividePluginCases.java index baa5201f00e2..a0cb0fdd6a41 100644 --- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-logging-rocketmq/src/test/java/org/apache/shenyu/e2e/testcase/logging/rocketmq/DividePluginCases.java +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-logging-rocketmq/src/test/java/org/apache/shenyu/e2e/testcase/logging/rocketmq/DividePluginCases.java @@ -19,11 +19,11 @@ import com.google.common.collect.Lists; import io.restassured.http.Method; -import org.apache.commons.collections.CollectionUtils; -import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; -import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; -import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; +import org.apache.rocketmq.client.consumer.DefaultLitePullConsumer; +import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.common.consumer.ConsumeFromWhere; +import org.apache.rocketmq.common.message.MessageQueue; +import org.apache.rocketmq.common.protocol.ResponseCode; import org.apache.shenyu.e2e.engine.scenario.ShenYuScenarioProvider; import org.apache.shenyu.e2e.engine.scenario.specification.ScenarioSpec; import org.apache.shenyu.e2e.engine.scenario.specification.ShenYuBeforeEachSpec; @@ -38,7 +38,9 @@ import java.nio.charset.StandardCharsets; import java.time.Duration; +import java.util.Collection; import java.util.List; +import java.util.Objects; import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; @@ -58,7 +60,7 @@ public class DividePluginCases implements ShenYuScenarioProvider { private static final String TEST = "/http/order/findById?id=123"; - private static final Duration LOG_CONSUME_TIMEOUT = Duration.ofSeconds(30); + private static final Duration LOG_CONSUME_TIMEOUT = Duration.ofSeconds(60); private static final Logger LOG = LoggerFactory.getLogger(DividePluginCases.class); @@ -82,6 +84,42 @@ private ShenYuScenarioSpec testDivideHello() { .build(); } + static void awaitRequestLog(final DefaultLitePullConsumer consumer, final String endpoint) { + AtomicBoolean assigned = new AtomicBoolean(); + await().alias("RocketMQ access log for " + endpoint) + .atMost(LOG_CONSUME_TIMEOUT).pollInterval(Duration.ofMillis(200)) + .until(() -> { + if (!assigned.get()) { + Collection queues; + try { + queues = consumer.fetchMessageQueues(TOPIC); + } catch (MQClientException ex) { + Throwable cause = ex; + while (Objects.nonNull(cause)) { + if (cause instanceof MQClientException && ((MQClientException) cause).getResponseCode() == ResponseCode.TOPIC_NOT_EXIST) { + return false; + } + cause = cause.getCause(); + } + throw ex; + } + if (queues.isEmpty()) { + return false; + } + consumer.assign(queues); + for (MessageQueue queue : queues) { + consumer.seekToBegin(queue); + } + assigned.set(true); + } + return consumer.poll(200).stream().anyMatch(message -> { + String body = new String(message.getBody(), StandardCharsets.UTF_8); + LOG.info("RocketMQ access log: {}", body); + return body.contains(endpoint); + }); + }); + } + private ShenYuScenarioSpec testRocketMQHello() { return ShenYuScenarioSpec.builder() .name("testRocketMQHello") @@ -105,31 +143,17 @@ private ShenYuScenarioSpec testRocketMQHello() { .caseSpec( ShenYuCaseSpec.builder() .add(request -> { - AtomicBoolean isLog = new AtomicBoolean(false); String requestId = UUID.randomUUID().toString(); String endpoint = "/http/order/findById?id=23&e2e=" + requestId; - DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(CONSUMERGROUP + "-" + requestId); + DefaultLitePullConsumer consumer = new DefaultLitePullConsumer(CONSUMERGROUP + "-" + requestId); try { consumer.setNamesrvAddr(NAMESERVER); - // Queue assignment may happen after the request has already been logged. consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET); - consumer.subscribe(TOPIC, "*"); - consumer.registerMessageListener((MessageListenerConcurrently) (msgs, consumeConcurrentlyContext) -> { - LOG.info("Msg:{}", msgs); - if (CollectionUtils.isNotEmpty(msgs)) { - msgs.forEach(e -> { - if (new String(e.getBody(), StandardCharsets.UTF_8).contains(endpoint)) { - isLog.set(true); - } - }); - } - return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; - }); + consumer.setAutoCommit(false); consumer.start(); LOG.info("RocketMQ consumer started"); request.request(Method.GET, endpoint).then().statusCode(200); - await().atMost(LOG_CONSUME_TIMEOUT).untilTrue(isLog); - LOG.info("isLog.get():{}", isLog.get()); + awaitRequestLog(consumer, endpoint); } catch (Exception e) { LOG.error("error", e); Assertions.fail("Failed to consume RocketMQ access log", e); diff --git a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-logging-rocketmq/src/test/java/org/apache/shenyu/e2e/testcase/logging/rocketmq/RocketMQLogConsumptionTest.java b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-logging-rocketmq/src/test/java/org/apache/shenyu/e2e/testcase/logging/rocketmq/RocketMQLogConsumptionTest.java new file mode 100644 index 000000000000..d620ca3c1f09 --- /dev/null +++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-logging-rocketmq/src/test/java/org/apache/shenyu/e2e/testcase/logging/rocketmq/RocketMQLogConsumptionTest.java @@ -0,0 +1,94 @@ +/* + * 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.e2e.testcase.logging.rocketmq; + +import org.apache.rocketmq.client.consumer.DefaultLitePullConsumer; +import org.apache.rocketmq.client.exception.MQClientException; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.common.message.MessageQueue; +import org.apache.rocketmq.common.protocol.ResponseCode; +import org.junit.jupiter.api.Test; + +import java.nio.charset.StandardCharsets; +import java.util.Collection; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class RocketMQLogConsumptionTest { + + @Test + void rejectsNonTransientBrokerErrors() { + DefaultLitePullConsumer consumer = new DefaultLitePullConsumer("denied-log-fixture") { + @Override + public Collection fetchMessageQueues(final String topic) throws MQClientException { + throw new MQClientException(ResponseCode.NO_PERMISSION, "access denied"); + } + }; + + MQClientException exception = assertThrows(MQClientException.class, () -> DividePluginCases.awaitRequestLog(consumer, "/current-request")); + assertEquals(ResponseCode.NO_PERMISSION, exception.getResponseCode()); + } + + @Test + void waitsForTopicCreationAndRejectsUnrelatedLogs() { + AtomicInteger discoveries = new AtomicInteger(); + AtomicInteger polls = new AtomicInteger(); + AtomicInteger seeks = new AtomicInteger(); + MessageQueue queue = new MessageQueue("shenyu-access-logging", "broker", 0); + String endpoint = "/http/order/findById?id=23&e2e=current-request"; + DefaultLitePullConsumer consumer = new DefaultLitePullConsumer("log-fixture") { + @Override + public Collection fetchMessageQueues(final String topic) throws MQClientException { + if (discoveries.incrementAndGet() == 1) { + throw new MQClientException("topic route pending", new MQClientException(ResponseCode.TOPIC_NOT_EXIST, "topic is not published yet")); + } + return List.of(queue); + } + + @Override + public void assign(final Collection queues) { + assertEquals(List.of(queue), queues); + } + + @Override + public void seekToBegin(final MessageQueue assignedQueue) { + assertEquals(queue, assignedQueue); + seeks.incrementAndGet(); + } + + @Override + public List poll(final long timeout) { + assertTrue(seeks.get() > 0); + MessageExt message = new MessageExt(); + String uri = polls.incrementAndGet() == 1 ? "/http/order/findById?id=23&e2e=old-request" : endpoint; + message.setBody(("{\"requestUri\":\"http://gateway" + uri + "\"}").getBytes(StandardCharsets.UTF_8)); + return List.of(message); + } + }; + + DividePluginCases.awaitRequestLog(consumer, endpoint); + + assertEquals(2, discoveries.get()); + assertEquals(1, seeks.get()); + assertEquals(2, polls.get()); + } +} From de1f0bc7d85b170c6f0b86cc0f196283480e2b6a Mon Sep 17 00:00:00 2001 From: yangjj-iso <3202137046@qq.com> Date: Fri, 16 Oct 2026 19:16:27 +0800 Subject: [PATCH 10/10] ci: retry transient Maven Central dependency download