From ac0ea89d836f2722e8589fa4725b4e68faa1327b Mon Sep 17 00:00:00 2001 From: yangjj-iso <3202137046@qq.com> Date: Wed, 14 Oct 2026 19:56:25 +0800 Subject: [PATCH 01/11] docs(apollo): announce staged plugin-store migration --- README.md | 2 +- RELEASE-NOTES.md | 8 ++ docs/plugin-store-apollo.md | 210 ++++++++++++++++++++++++++++++++++++ shenyu-registry/README.md | 2 +- 4 files changed, 220 insertions(+), 2 deletions(-) create mode 100644 docs/plugin-store-apollo.md diff --git a/README.md b/README.md index aa217f08d238..44efde0696d4 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 etcd are available. Apollo remains available during its deprecation release and is planned to move to an external extension (see [Apollo migration](docs/plugin-store-apollo.md)). Consul sync is available as an external extension (see [plugin-store-consul](docs/plugin-store-consul.md)). Gateway replicas apply updates to their local caches. | | Observability | Metrics and logging plugins, including Kafka and Elasticsearch destinations; email and DingTalk alerts from Admin. | | AI and MCP | AI proxy, prompt processing, token limits, sensitive-word filtering, AI request/response transformation, and an MCP server plugin with SSE and Streamable HTTP. | diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 65a7892c9142..fb14b1835e1b 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -2,6 +2,14 @@ ### API Changes +- Apollo's in-tree registry, sync adapter, Admin listener and sync starter are + deprecated for transfer to plugin-store (#7599). All four remain available in + the release carrying this notice. Removal requires dev-list consensus, a full + released deprecation cycle, compatible external artifact publication and an + announced rollback window; no removal release is scheduled. See the + [migration guide](docs/plugin-store-apollo.md). Existing `apollo` type names, + keys and `ApolloPathConstants` remain compatibility contracts. + - `MemorySafeLRUMap` is deprecated since 2.7.2. The class, public constructors, serialization identifier and existing behavior are retained for downstream source and binary compatibility. No removal release is scheduled; a future diff --git a/docs/plugin-store-apollo.md b/docs/plugin-store-apollo.md new file mode 100644 index 000000000000..1c6bd65baeb2 --- /dev/null +++ b/docs/plugin-store-apollo.md @@ -0,0 +1,210 @@ + +# Apollo plugin-store migration + +## Status and deprecation cycle + +Apollo is currently an optional, supported in-tree integration. Issue [#7599](https://github.com/apache/shenyu/issues/7599) +proposes transferring its registry, data-sync, Admin listener and gateway starter to +[plugin-store](https://github.com/apache/shenyu-plugin-store), extending [#7306](https://github.com/apache/shenyu/issues/7306). +This guide is the advance deprecation notice: the in-tree modules remain available +for the release carrying this notice. No removal release has been selected. +The separate removal PR is a draft and must not be merged in that deprecation release. + +| Stage | Required action | +| --- | --- | +| Agreement | Obtain and link the dev-list decision approving Apollo externalization. | +| Deprecation release | Ship this notice and migration guide in a core release while retaining all four in-tree modules. Record that released version publicly. | +| Receiving parity | Build/test all four modules together in plugin-store, verify external SPI loading and unchanged sync/registry configuration. | +| Publication | Announce compatible core/store versions, publish external artifacts before cutover, and reserve one publisher per Maven group/artifact/version. | +| Later core release | After the deprecation release has shipped, merge the separate removal, update the release inventory, and announce the rollback window. | + +Do not treat creating PRs, merging documentation, or producing local snapshot JARs +as completing the dev-list decision, a released deprecation cycle, or artifact publication. +Keep the issue open until all stages and their release evidence are complete. + +## Artifact ownership and installation + +The receiving `shenyu-extension-apollo` reactor owns these artifacts together: + +- `shenyu-admin-listener-apollo` +- `shenyu-sync-data-apollo` +- `shenyu-registry-apollo` +- `shenyu-spring-boot-starter-sync-data-apollo` + +The preparation branch uses store `2.7.1-SNAPSHOT` against core `2.7.2-SNAPSHOT`. +These are development coordinates, not an announced release compatibility matrix. +For deployment, select the published store release declared compatible with your core release. +Use the core version for retained APIs and the store version for **all four** Apollo artifacts. +Keep exactly one provider version on each runtime classpath; the in-tree and external +implementations retain identical packages and must not coexist. + +Admin needs: + +```xml + + org.apache.shenyu + shenyu-admin-listener-apollo + ${store.version} + +``` + +Gateway data synchronization needs: + +```xml + + org.apache.shenyu + shenyu-spring-boot-starter-sync-data-apollo + ${store.version} + +``` + +Applications using Apollo instance registration or SDK instance discovery additionally need: + +```xml + + org.apache.shenyu + shenyu-registry-apollo + ${store.version} + +``` + +Gateway registration also requires the retained core `shenyu-spring-boot-starter-registry`; +SDK discovery requires the appropriate SDK starter. Apollo was never included in the +compatibility registry starter, so it remains an explicit provider dependency. +For binary distributions, resolve the complete runtime dependency closure into `lib/`, +replace old Apollo JARs, and retain the extension's licensing information and dependency notices. + +Shading continues to package Apollo client dependencies, but excludes retained ShenYu +API artifacts and sibling extension modules. API classes come from the application's core artifacts, preserving +class identity for external SPI loading. The published POM retains runtime dependencies. + +## Enable Admin and gateway synchronization + +Admin keeps its existing property prefix and portal publishing settings: + +```yaml +shenyu: + sync: + websocket: + enabled: false + apollo: + appId: shenyu + meta: http://apollo-config-service:8080 + portalUrl: http://apollo-portal:8070 + env: DEV + clusterName: default + namespace: application + token: ${APOLLO_OPENAPI_TOKEN} + operatorUser: apollo +``` + +Gateway keeps the same reading settings; remove or disable the previous sync channel: + +```yaml +shenyu: + namespace: 649330b6-c2d7-4edc-be8e-8a54df9eb385 + sync: + websocket: + urls: false + apollo: + appId: shenyu + meta: http://apollo-config-service:8080 + env: DEV + clusterName: default + namespace: application + accessKey: ${APOLLO_ACCESS_KEY:} +``` + +The portal OpenAPI token and config-service access key serve different APIs. +Ensure the publishing app, environment, cluster and Apollo namespace match the reader. +The preserved reader calls Apollo `ConfigService.getAppConfig()`, so the example uses +`application`. This migration does not add arbitrary namespace selection. +The ShenYu namespace ID is a separate tenant prefix inside Apollo item keys. +The Apollo client sets JVM-wide app/meta/cluster properties; preserve the existing +process-level configuration when using sync and registry together. + +## Registry and SPI contract + +The external JAR continues to publish: + +```text +META-INF/shenyu/org.apache.shenyu.registry.api.ShenyuInstanceRegisterRepository +apollo=org.apache.shenyu.registry.apollo.ApolloInstanceRegisterRepository +``` + +`ShenyuInstanceRegisterRepositoryFactory.loadRepository("apollo")` resolves that +resource without any factory or core runtime change, and preserves the non-singleton provider. +Registry configuration remains: + +```yaml +shenyu: + register: + enabled: true + registerType: apollo + serverLists: http://apollo-config-service:8080 + props: + appId: shenyu + portalUrl: http://apollo-portal:8070 + token: ${APOLLO_OPENAPI_TOKEN} + env: DEV + clusterName: default + namespace: application +``` + +SDK discovery uses the same `apollo` type and registry settings via its existing SDK +configuration; it does not replace backend HTTP annotation/API registration. +Instance registration writes persistent portal items and publishes the namespace. +Existing shutdown removes listeners; it does not deregister persistent instance items. +Preserve that behavior during migration and apply your existing instance-removal procedure. + +## Stored keys and shared compatibility shim + +| Data | Existing Apollo item key | +| --- | --- | +| Plugin | `.plugin.` | +| Selector | `.selector..` | +| Rule | `.rule...` | +| Authentication | `.auth.` | +| Metadata | `.meta.` | +| Proxy selector | `.proxy.selector..` | +| Discovery upstream | `.discovery..` | +| Instance | `/shenyu/register/instance//:` | + +The existing `.list` index items under each category/group are retained alongside the data keys. +JSON DTOs, key prefixes, namespace IDs and the `apollo` type remain unchanged. +`org.apache.shenyu.common.constant.ApolloPathConstants` stays in core as a small +constants/path compatibility shim with no Apollo SDK dependency. Do not duplicate that +class in store JARs or migrate/delete existing keyspaces as part of this transfer. + +The client versions remain `apollo-client`, `apollo-openapi` and `apollo-core` `2.1.0`. +Source and the Apollo clients are Apache-2.0; preserve licenses when assembling custom packages. +Existing unit tests, real Apollo `DefaultConfig` listener filtering tests and starter +configuration tests move with their modules. Those tests do not claim a full live Apollo +portal/config-service deployment; validate your staging deployment before production cutover. + +## Upgrade and rollback + +1. After publication and release gates pass, back up the Admin database and Apollo + application/namespace configuration, recording exact core/store versions and deployed JARs. +2. Verify the external artifacts in staging using unchanged namespace, endpoints, tokens, + keys and registry properties. Check initial sync, create/update/delete and instance updates. +3. Roll Admin and gateways with complete external dependency closures, then confirm + subsequent changes propagate and existing instance discovery still works. +4. Retain the last in-tree release for the announced rollback window. To roll back, + restore its images/JARs and configuration and remove the external Apollo versions. + Reuse the same Admin database and Apollo keyspace; do not clear either during rollback. diff --git a/shenyu-registry/README.md b/shenyu-registry/README.md index d91f0f8ef0e5..66ea84e1b5c2 100644 --- a/shenyu-registry/README.md +++ b/shenyu-registry/README.md @@ -40,7 +40,7 @@ runtime classpath, using the same ShenYu version as the application: | `zookeeper` | `shenyu-registry-zookeeper` | | `etcd` | `shenyu-registry-etcd` | | `nacos` | `shenyu-registry-nacos` | -| `apollo` | `shenyu-registry-apollo` | +| `apollo` | `shenyu-registry-apollo`; in-tree deprecation and planned external ownership: [migration guide](../docs/plugin-store-apollo.md) | | `eureka` | `shenyu-registry-eureka` | | `kubernetes` | `shenyu-registry-kubernetes` | From 06125d3fa7922dd18718ce2003e75c102e837aeb Mon Sep 17 00:00:00 2001 From: yangjj-iso <3202137046@qq.com> Date: Wed, 14 Oct 2026 20:04:16 +0800 Subject: [PATCH 02/11] refactor(apollo): prepare the later plugin-store cutover --- .../scripts/check-registry-dependencies.py | 4 +- README.md | 2 +- RELEASE-NOTES.md | 18 +- docs/plugin-store-apollo.md | 7 +- pom.xml | 13 - shenyu-admin-listener/pom.xml | 1 - .../shenyu-admin-listener-apollo/pom.xml | 73 ---- .../admin/config/ApolloSyncConfiguration.java | 76 ---- .../config/properties/ApolloProperties.java | 196 --------- .../admin/listener/apollo/ApolloClient.java | 149 ------- .../apollo/ApolloDataChangedInit.java | 65 --- .../apollo/ApolloDataChangedListener.java | 63 --- .../main/resources/META-INF/spring.factories | 19 - .../main/resources/META-INF/spring.provides | 18 - ...ot.autoconfigure.AutoConfiguration.imports | 18 - .../listener/apollo/ApolloClientTest.java | 94 ----- .../apollo/ApolloDataChangedInitTest.java | 103 ----- .../apollo/ApolloDataChangedListenerTest.java | 93 ----- .../src/main/resources/application.yml | 8 - .../src/main/resources/application.yml | 6 - .../src/main/release-docs/LICENSE | 3 - .../src/main/release-docs/LICENSE | 3 - .../src/main/resources/application.yml | 6 - .../src/main/resources/application.yml | 6 - .../src/main/resources/application.yml | 6 - shenyu-registry/README.md | 8 +- shenyu-registry/pom.xml | 1 - .../shenyu-registry-apollo/pom.xml | 71 ---- .../shenyu/registry/apollo/ApolloClient.java | 134 ------ .../shenyu/registry/apollo/ApolloConfig.java | 150 ------- .../ApolloInstanceRegisterRepository.java | 186 --------- ...istry.api.ShenyuInstanceRegisterRepository | 17 - .../registry/apollo/ApolloClientTest.java | 98 ----- .../registry/apollo/ApolloConfigTest.java | 61 --- .../ApolloInstanceRegisterRepositoryTest.java | 109 ----- .../registry/apollo/RegistrySpiTest.java | 33 -- .../pom.xml | 1 - .../pom.xml | 56 --- .../apollo/ApolloSyncDataConfiguration.java | 116 ------ ...ot.autoconfigure.AutoConfiguration.imports | 18 - .../ApolloSyncDataConfigurationTest.java | 87 ---- shenyu-sync-data-center/pom.xml | 1 - .../shenyu-sync-data-apollo/pom.xml | 40 -- .../sync/data/apollo/ApolloDataService.java | 175 -------- .../sync/data/apollo/config/ApolloConfig.java | 155 ------- .../ApolloDataServiceIntegrationTest.java | 141 ------- .../data/apollo/ApolloDataServiceTest.java | 391 ------------------ .../data/apollo/config/ApolloConfigTest.java | 62 --- 48 files changed, 22 insertions(+), 3139 deletions(-) delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-apollo/pom.xml delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/java/org/apache/shenyu/admin/config/ApolloSyncConfiguration.java delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/java/org/apache/shenyu/admin/config/properties/ApolloProperties.java delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/java/org/apache/shenyu/admin/listener/apollo/ApolloClient.java delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/java/org/apache/shenyu/admin/listener/apollo/ApolloDataChangedInit.java delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/java/org/apache/shenyu/admin/listener/apollo/ApolloDataChangedListener.java delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/resources/META-INF/spring.factories delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/resources/META-INF/spring.provides delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-apollo/src/test/java/org/apache/shenyu/admin/listener/apollo/ApolloClientTest.java delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-apollo/src/test/java/org/apache/shenyu/admin/listener/apollo/ApolloDataChangedInitTest.java delete mode 100644 shenyu-admin-listener/shenyu-admin-listener-apollo/src/test/java/org/apache/shenyu/admin/listener/apollo/ApolloDataChangedListenerTest.java delete mode 100644 shenyu-registry/shenyu-registry-apollo/pom.xml delete mode 100644 shenyu-registry/shenyu-registry-apollo/src/main/java/org/apache/shenyu/registry/apollo/ApolloClient.java delete mode 100644 shenyu-registry/shenyu-registry-apollo/src/main/java/org/apache/shenyu/registry/apollo/ApolloConfig.java delete mode 100644 shenyu-registry/shenyu-registry-apollo/src/main/java/org/apache/shenyu/registry/apollo/ApolloInstanceRegisterRepository.java delete mode 100644 shenyu-registry/shenyu-registry-apollo/src/main/resources/META-INF/shenyu/org.apache.shenyu.registry.api.ShenyuInstanceRegisterRepository delete mode 100644 shenyu-registry/shenyu-registry-apollo/src/test/java/org/apache/shenyu/registry/apollo/ApolloClientTest.java delete mode 100644 shenyu-registry/shenyu-registry-apollo/src/test/java/org/apache/shenyu/registry/apollo/ApolloConfigTest.java delete mode 100644 shenyu-registry/shenyu-registry-apollo/src/test/java/org/apache/shenyu/registry/apollo/ApolloInstanceRegisterRepositoryTest.java delete mode 100644 shenyu-registry/shenyu-registry-apollo/src/test/java/org/apache/shenyu/registry/apollo/RegistrySpiTest.java delete mode 100644 shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-apollo/pom.xml delete mode 100644 shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-apollo/src/main/java/org/apache/shenyu/springboot/sync/data/apollo/ApolloSyncDataConfiguration.java delete mode 100644 shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-apollo/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports delete mode 100644 shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-apollo/src/test/java/org/apache/shenyu/springboot/sync/data/apollo/ApolloSyncDataConfigurationTest.java delete mode 100644 shenyu-sync-data-center/shenyu-sync-data-apollo/pom.xml delete mode 100644 shenyu-sync-data-center/shenyu-sync-data-apollo/src/main/java/org/apache/shenyu/sync/data/apollo/ApolloDataService.java delete mode 100644 shenyu-sync-data-center/shenyu-sync-data-apollo/src/main/java/org/apache/shenyu/sync/data/apollo/config/ApolloConfig.java delete mode 100644 shenyu-sync-data-center/shenyu-sync-data-apollo/src/test/java/org/apache/shenyu/sync/data/apollo/ApolloDataServiceIntegrationTest.java delete mode 100644 shenyu-sync-data-center/shenyu-sync-data-apollo/src/test/java/org/apache/shenyu/sync/data/apollo/ApolloDataServiceTest.java delete mode 100644 shenyu-sync-data-center/shenyu-sync-data-apollo/src/test/java/org/apache/shenyu/sync/data/apollo/config/ApolloConfigTest.java diff --git a/.github/scripts/check-registry-dependencies.py b/.github/scripts/check-registry-dependencies.py index ff233ff0c332..f968282c8c56 100644 --- a/.github/scripts/check-registry-dependencies.py +++ b/.github/scripts/check-registry-dependencies.py @@ -18,8 +18,8 @@ import sys from pathlib import Path -PROVIDERS = ("zookeeper", "etcd", "nacos", "apollo", "eureka", "kubernetes") -COMPATIBILITY_PROVIDERS = set(PROVIDERS) - {"apollo"} +PROVIDERS = ("zookeeper", "etcd", "nacos", "eureka", "kubernetes") +COMPATIBILITY_PROVIDERS = set(PROVIDERS) LEAN_MODULES = ( "shenyu-registry/shenyu-registry-api", "shenyu-registry/shenyu-registry-core", diff --git a/README.md b/README.md index 44efde0696d4..862c72322792 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Apache ShenYu is a Java-based gateway for service proxying, protocol conversion, | Registration and discovery | Client SDKs register service addresses and API metadata with Admin. Registry integrations support discovery; an optional Kubernetes controller reconciles Ingress and Endpoints resources. | | Security and traffic control | WAF, signing, authentication plugins, load balancing, rate limiting, and fault tolerance through Resilience4j and Sentinel; deprecated Hystrix remains available as an external plugin (see [plugin-store-hystrix](docs/plugin-store-hystrix.md)). | | Caching and transformation | In-memory or Redis-backed response caching, URL rewriting, redirection, and request/response transformation. | -| Dynamic configuration | Admin persists plugins, selectors, rules, metadata, and authentication data. WebSocket sync is the default; HTTP long polling, ZooKeeper, Nacos, and etcd are available. Apollo remains available during its deprecation release and is planned to move to an external extension (see [Apollo migration](docs/plugin-store-apollo.md)). Consul sync is available as an external extension (see [plugin-store-consul](docs/plugin-store-consul.md)). Gateway replicas apply updates to their local caches. | +| Dynamic configuration | Admin persists plugins, selectors, rules, metadata, and authentication data. WebSocket sync is the default; HTTP long polling, ZooKeeper, Nacos, and etcd are available. Apollo sync and registry are available as an external extension (see [Apollo migration](docs/plugin-store-apollo.md)). Consul sync is available as an external extension (see [plugin-store-consul](docs/plugin-store-consul.md)). Gateway replicas apply updates to their local caches. | | Observability | Metrics and logging plugins, including Kafka and Elasticsearch destinations; email and DingTalk alerts from Admin. | | AI and MCP | AI proxy, prompt processing, token limits, sensitive-word filtering, AI request/response transformation, and an MCP server plugin with SSE and Streamable HTTP. | diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index fb14b1835e1b..02963c1f6046 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -2,13 +2,11 @@ ### API Changes -- Apollo's in-tree registry, sync adapter, Admin listener and sync starter are - deprecated for transfer to plugin-store (#7599). All four remain available in - the release carrying this notice. Removal requires dev-list consensus, a full - released deprecation cycle, compatible external artifact publication and an - announced rollback window; no removal release is scheduled. See the - [migration guide](docs/plugin-store-apollo.md). Existing `apollo` type names, - keys and `ApolloPathConstants` remain compatibility contracts. +- The external Apollo stack retains the `apollo` SPI/configuration type and + existing stored keys (#7599). `ApolloPathConstants` remains in core as a small + compatibility shim without an Apollo SDK dependency. The separate deprecation + notice must have shipped in a preceding core release before this cutover can + merge; see the [migration guide](docs/plugin-store-apollo.md). - `MemorySafeLRUMap` is deprecated since 2.7.2. The class, public constructors, serialization identifier and existing behavior are retained for downstream @@ -28,6 +26,12 @@ ### Behavior Changes +- Apollo's runtime modules and sync starter are transferred to plugin-store in + this later cutover change (#7599). Merge and release only after the separate + deprecation notice has shipped in a preceding core release, dev-list agreement, + passing receiving CI and external publication. Existing configurations and + `ApolloPathConstants` remain compatible; see the [migration guide](docs/plugin-store-apollo.md). + - HTTP client registration now treats non-success Admin responses as failures, using the same bounded failback policy as transport errors (18 retry attempts per pending task). The text response contract does not reliably distinguish diff --git a/docs/plugin-store-apollo.md b/docs/plugin-store-apollo.md index 1c6bd65baeb2..e65bc39412be 100644 --- a/docs/plugin-store-apollo.md +++ b/docs/plugin-store-apollo.md @@ -18,11 +18,12 @@ limitations under the License. ## Status and deprecation cycle -Apollo is currently an optional, supported in-tree integration. Issue [#7599](https://github.com/apache/shenyu/issues/7599) +This source branch prepares the later removal of Apollo from the core reactor. +The published deprecation release must retain its in-tree integration. Issue [#7599](https://github.com/apache/shenyu/issues/7599) proposes transferring its registry, data-sync, Admin listener and gateway starter to [plugin-store](https://github.com/apache/shenyu-plugin-store), extending [#7306](https://github.com/apache/shenyu/issues/7306). -This guide is the advance deprecation notice: the in-tree modules remain available -for the release carrying this notice. No removal release has been selected. +The separate deprecation PR publishes the advance notice and this guide while +retaining all four modules for that release. No removal release has been selected. The separate removal PR is a draft and must not be merged in that deprecation release. | Stage | Required action | diff --git a/pom.xml b/pom.xml index 41146d6af896..13001f82f70a 100644 --- a/pom.xml +++ b/pom.xml @@ -169,7 +169,6 @@ 2.9.3 4.1.5 9.2 - 2.1.0 1.7.1 1.8.3 6.1.2.RELEASE @@ -373,18 +372,6 @@ ${zookeeper.version} - - com.ctrip.framework.apollo - apollo-client - ${apollo.version} - - - - com.ctrip.framework.apollo - apollo-openapi - ${apollo.version} - - com.github.pagehelper pagehelper diff --git a/shenyu-admin-listener/pom.xml b/shenyu-admin-listener/pom.xml index 7ee0cc7eb311..3e4950a58e01 100644 --- a/shenyu-admin-listener/pom.xml +++ b/shenyu-admin-listener/pom.xml @@ -29,7 +29,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-apollo/pom.xml b/shenyu-admin-listener/shenyu-admin-listener-apollo/pom.xml deleted file mode 100644 index ec32304930e1..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-apollo/pom.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - 4.0.0 - - org.apache.shenyu - shenyu-admin-listener - 2.7.2-SNAPSHOT - - - shenyu-admin-listener-apollo - - - - com.ctrip.framework.apollo - apollo-openapi - - - - org.apache.shenyu - shenyu-admin-listener-api - ${project.version} - - - - org.springframework.boot - spring-boot-starter-web - provided - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.apache.maven.plugins - maven-shade-plugin - ${maven-shade-plugin.version} - - - - - package - - shade - - - - - - - diff --git a/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/java/org/apache/shenyu/admin/config/ApolloSyncConfiguration.java b/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/java/org/apache/shenyu/admin/config/ApolloSyncConfiguration.java deleted file mode 100644 index 755c79439499..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/java/org/apache/shenyu/admin/config/ApolloSyncConfiguration.java +++ /dev/null @@ -1,76 +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.config.properties.ApolloProperties; -import org.apache.shenyu.admin.listener.DataChangedInit; -import org.apache.shenyu.admin.listener.DataChangedListener; -import org.apache.shenyu.admin.listener.apollo.ApolloClient; -import org.apache.shenyu.admin.listener.apollo.ApolloDataChangedInit; -import org.apache.shenyu.admin.listener.apollo.ApolloDataChangedListener; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * the type apollo listener. - */ -@Configuration -@ConditionalOnProperty(prefix = "shenyu.sync.apollo", name = "meta") -@EnableConfigurationProperties(ApolloProperties.class) -public class ApolloSyncConfiguration { - - - /** - * init Consul client. - * - * @param apolloProperties the apollo properties - * @return apollo client - */ - @Bean - public ApolloClient apolloClient(final ApolloProperties apolloProperties) { - return new ApolloClient(apolloProperties); - } - - /** - * Config event listener data changed listener. - * - * @param apolloClient the apollo client - * @return the data changed listener - */ - @Bean - @ConditionalOnMissingBean(ApolloDataChangedListener.class) - public DataChangedListener apolloDataChangeListener(final ApolloClient apolloClient) { - return new ApolloDataChangedListener(apolloClient); - } - - /** - * apollo data init. - * - * @param apolloClient the apollo client - * @return the apollo data init - */ - @Bean - @ConditionalOnMissingBean(ApolloDataChangedInit.class) - public DataChangedInit apolloDataChangeInit(final ApolloClient apolloClient) { - return new ApolloDataChangedInit(apolloClient); - } - -} diff --git a/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/java/org/apache/shenyu/admin/config/properties/ApolloProperties.java b/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/java/org/apache/shenyu/admin/config/properties/ApolloProperties.java deleted file mode 100644 index b1a100ff44f0..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/java/org/apache/shenyu/admin/config/properties/ApolloProperties.java +++ /dev/null @@ -1,196 +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.properties; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -@ConfigurationProperties("shenyu.sync.apollo") -public class ApolloProperties { - - /** - * appId. - */ - private String appId; - - /** - * apollo config service url. - */ - private String meta; - - /** - * portal url. - * e.g. localhost:8080 - */ - private String portalUrl; - - /** - * env. - * e.g. ENV - */ - private String env; - - /** - * cluster name. - */ - private String clusterName; - - /** - * namespace name. - */ - private String namespace; - - /** - * open api use token. - */ - private String token; - - /** - * operatorUser. - */ - private String operatorUser; - - /** - * get appId. - * @return appId - */ - public String getAppId() { - return appId; - } - - /** - * set app id. - * @param appId app id - */ - public void setAppId(final String appId) { - this.appId = appId; - } - - /** - * get config service url. - * @return config service url - */ - public String getMeta() { - return meta; - } - - /** - * set config service url. - * @param meta config service url - */ - public void setMeta(final String meta) { - this.meta = meta; - } - - /** - * get portal url. - * @return portal url - */ - public String getPortalUrl() { - return portalUrl; - } - - /** - * set portal url. - * @param portalUrl portal url - */ - public void setPortalUrl(final String portalUrl) { - this.portalUrl = portalUrl; - } - - /** - * get env. - * @return env - */ - public String getEnv() { - return env; - } - - /** - * set env. - * @param env env - */ - public void setEnv(final String env) { - this.env = env; - } - - /** - * get cluster name. - * @return cluster name - */ - public String getClusterName() { - return clusterName; - } - - /** - * set cluster name. - * @param clusterName cluster name - */ - public void setClusterName(final String clusterName) { - this.clusterName = clusterName; - } - - /** - * get namespace name. - * @return namespace name - */ - public String getNamespace() { - return namespace; - } - - /** - * set namespace name. - * @param namespace namespace name - */ - public void setNamespace(final String namespace) { - this.namespace = namespace; - } - - /** - * get token. - * @return token - */ - public String getToken() { - return token; - } - - /** - * set token. - * @param token token - */ - public void setToken(final String token) { - this.token = token; - } - - /** - * operatorUser. - * - * @return OperatorUser - */ - public String getOperatorUser() { - return operatorUser; - } - - /** - * set operatorUser. - * - * @param operatorUser operatorUser - */ - public void setOperatorUser(final String operatorUser) { - this.operatorUser = operatorUser; - } -} diff --git a/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/java/org/apache/shenyu/admin/listener/apollo/ApolloClient.java b/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/java/org/apache/shenyu/admin/listener/apollo/ApolloClient.java deleted file mode 100644 index 580b942ed0fc..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/java/org/apache/shenyu/admin/listener/apollo/ApolloClient.java +++ /dev/null @@ -1,149 +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.apollo; - -import com.ctrip.framework.apollo.openapi.client.ApolloOpenApiClient; -import com.ctrip.framework.apollo.openapi.dto.NamespaceReleaseDTO; -import com.ctrip.framework.apollo.openapi.dto.OpenItemDTO; -import org.apache.shenyu.admin.config.properties.ApolloProperties; -import org.apache.shenyu.common.exception.ShenyuException; -import org.apache.shenyu.common.utils.GsonUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Date; -import java.util.Objects; -import java.util.Optional; - -/** - * apollo open-api client. - */ -public class ApolloClient { - - private static final Logger LOG = LoggerFactory.getLogger(ApolloClient.class); - - private final String operatorUser; - - private final ApolloProperties apolloConfig; - - private final ApolloOpenApiClient apolloOpenApiClient; - - public ApolloClient(final ApolloProperties apolloConfig) { - this.apolloConfig = apolloConfig; - - this.apolloOpenApiClient = ApolloOpenApiClient - .newBuilder() - .withPortalUrl(apolloConfig.getPortalUrl()) - .withToken(apolloConfig.getToken()) - .build(); - operatorUser = Optional.ofNullable(apolloConfig.getOperatorUser()).orElse("apollo"); - } - - /** - * get item value. - * @param key item key - * @return item value - */ - public String getItemValue(final String key) { - OpenItemDTO openItemDTO = this.apolloOpenApiClient.getItem( - apolloConfig.getAppId(), - apolloConfig.getEnv(), - apolloConfig.getClusterName(), - apolloConfig.getNamespace(), - key); - if (Objects.isNull(openItemDTO)) { - return null; - } - if (openItemDTO.getKey().equals("timeout")) { - LOG.error("apollo client getItemValue time out"); - throw new ShenyuException("apollo client getItemValue time out"); - } - return openItemDTO.getValue(); - } - - - /** - * removeItemKey. - * - * @param key key - */ - public void removeItemKey(final String key) { - this.apolloOpenApiClient.removeItem( - apolloConfig.getAppId(), - apolloConfig.getEnv(), - apolloConfig.getClusterName(), - apolloConfig.getNamespace(), - key, operatorUser); - } - - /** - * create or update item into namespace. - * @param key item key - * @param value item value - * @param comment item comment - */ - public void createOrUpdateItem(final String key, final Object value, final String comment) { - this.createOrUpdateItem(key, GsonUtils.getInstance().toJson(value), comment); - } - - /** - * create or update item into namespace. - * @param key item key - * @param value item value - * @param comment item comment - */ - public void createOrUpdateItem(final String key, final String value, final String comment) { - OpenItemDTO openItemDTO = new OpenItemDTO(); - openItemDTO.setKey(key); - openItemDTO.setValue(value); - openItemDTO.setComment(comment); - openItemDTO.setDataChangeCreatedBy(operatorUser); - openItemDTO.setDataChangeLastModifiedBy(operatorUser); - Date now = new Date(); - openItemDTO.setDataChangeCreatedTime(now); - openItemDTO.setDataChangeLastModifiedTime(now); - - this.apolloOpenApiClient.createOrUpdateItem( - apolloConfig.getAppId(), - apolloConfig.getEnv(), - apolloConfig.getClusterName(), - apolloConfig.getNamespace(), - openItemDTO - ); - } - - /** - * publish item list in namespace. - * @param releaseTitle publish release title - * @param releaseComment publish release comment - */ - public void publishNamespace(final String releaseTitle, final String releaseComment) { - NamespaceReleaseDTO namespaceReleaseDTO = new NamespaceReleaseDTO(); - namespaceReleaseDTO.setReleaseTitle(releaseTitle); - namespaceReleaseDTO.setReleaseComment(releaseComment); - namespaceReleaseDTO.setReleasedBy(operatorUser); - - this.apolloOpenApiClient.publishNamespace( - apolloConfig.getAppId(), - apolloConfig.getEnv(), - apolloConfig.getClusterName(), - apolloConfig.getNamespace(), - namespaceReleaseDTO - ); - } -} diff --git a/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/java/org/apache/shenyu/admin/listener/apollo/ApolloDataChangedInit.java b/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/java/org/apache/shenyu/admin/listener/apollo/ApolloDataChangedInit.java deleted file mode 100644 index ee1090b03cf9..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/java/org/apache/shenyu/admin/listener/apollo/ApolloDataChangedInit.java +++ /dev/null @@ -1,65 +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.apollo; - -import org.apache.shenyu.admin.listener.AbstractDataChangedInit; -import org.apache.shenyu.admin.listener.utils.NodeDataPathUtils; -import org.apache.shenyu.common.constant.ApolloPathConstants; - -import java.util.Objects; -import java.util.stream.Stream; - -/** - * the type apollo data change init. - * - * @since 2.6.0 - */ -public class ApolloDataChangedInit extends AbstractDataChangedInit { - private final ApolloClient apolloClient; - - /** - * Instantiates a new apollo data changed init. - * - * @param apolloClient the apollo client - */ - public ApolloDataChangedInit(final ApolloClient apolloClient) { - this.apolloClient = apolloClient; - } - - /** - * not exist. - * - * @return true if not exist - */ - @Override - protected boolean notExist() { - return Stream.of(ApolloPathConstants.PLUGIN_DATA_ID, ApolloPathConstants.AUTH_DATA_ID, ApolloPathConstants.META_DATA_ID, ApolloPathConstants.PROXY_SELECTOR_DATA_ID) - .map(NodeDataPathUtils::appendListStuff) - .allMatch(this::dataIdNotExist); - } - - /** - * Data id not exist boolean. - * - * @param pluginDataId the plugin data id - * @return the boolean - */ - private boolean dataIdNotExist(final String pluginDataId) { - return Objects.isNull(apolloClient.getItemValue(pluginDataId)); - } -} diff --git a/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/java/org/apache/shenyu/admin/listener/apollo/ApolloDataChangedListener.java b/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/java/org/apache/shenyu/admin/listener/apollo/ApolloDataChangedListener.java deleted file mode 100644 index eab59e12e28f..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/java/org/apache/shenyu/admin/listener/apollo/ApolloDataChangedListener.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.apollo; - -import org.apache.shenyu.admin.listener.AbstractNodeDataChangedListener; -import org.apache.shenyu.common.constant.ApolloPathConstants; - -/** - * use apollo to push data changes. - * - * @since 2.6.0 - */ -public class ApolloDataChangedListener extends AbstractNodeDataChangedListener { - private final ApolloClient apolloClient; - - /** - * Instantiates a new apollo data changed listener. - * - * @param apolloClient the apollo client - */ - public ApolloDataChangedListener(final ApolloClient apolloClient) { - super(new ChangeData(ApolloPathConstants.PLUGIN_DATA_ID, - ApolloPathConstants.SELECTOR_DATA_ID, - ApolloPathConstants.RULE_DATA_ID, - ApolloPathConstants.AUTH_DATA_ID, - ApolloPathConstants.META_DATA_ID, - ApolloPathConstants.PROXY_SELECTOR_DATA_ID, - ApolloPathConstants.DISCOVERY_DATA_ID)); - this.apolloClient = apolloClient; - } - - @Override - public void doPublishConfig(final String dataId, final Object data) { - this.apolloClient.createOrUpdateItem(dataId, data, "create config data"); - this.apolloClient.publishNamespace("publish config data", ""); - } - - @Override - public String getConfig(final String dataId) { - return this.apolloClient.getItemValue(dataId); - } - - @Override - public void doDelConfig(final String dataId) { - this.apolloClient.removeItemKey(dataId); - this.apolloClient.publishNamespace("delete config data", ""); - } -} diff --git a/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/resources/META-INF/spring.factories b/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/resources/META-INF/spring.factories deleted file mode 100644 index f210012816e8..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-apollo/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.ApolloSyncConfiguration diff --git a/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/resources/META-INF/spring.provides b/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/resources/META-INF/spring.provides deleted file mode 100644 index 9893ff1dba24..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-apollo/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-apollo diff --git a/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/shenyu-admin-listener/shenyu-admin-listener-apollo/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index cda1dd637890..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-apollo/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.ApolloSyncConfiguration diff --git a/shenyu-admin-listener/shenyu-admin-listener-apollo/src/test/java/org/apache/shenyu/admin/listener/apollo/ApolloClientTest.java b/shenyu-admin-listener/shenyu-admin-listener-apollo/src/test/java/org/apache/shenyu/admin/listener/apollo/ApolloClientTest.java deleted file mode 100644 index 10385d90fe64..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-apollo/src/test/java/org/apache/shenyu/admin/listener/apollo/ApolloClientTest.java +++ /dev/null @@ -1,94 +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.apollo; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import org.apache.shenyu.admin.config.properties.ApolloProperties; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@ContextConfiguration(classes = {ApolloProperties.class}) -@RunWith(SpringJUnit4ClassRunner.class) -public class ApolloClientTest { - - @MockBean - private ApolloClient apolloClient; - - /** - * Method under test: {@link ApolloClient#ApolloClient(ApolloProperties)}. - */ - @Test - public void testConstructor() { - ApolloProperties apolloConfig = new ApolloProperties(); - apolloConfig.setAppId("42"); - apolloConfig.setClusterName("Cluster Name"); - apolloConfig.setEnv("Env"); - apolloConfig.setMeta("Meta"); - apolloConfig.setNamespace("Namespace"); - apolloConfig.setPortalUrl("http://localhost:8080"); - apolloConfig.setToken("ABC123"); - new ApolloClient(apolloConfig); - assertEquals("42", apolloConfig.getAppId()); - assertEquals("ABC123", apolloConfig.getToken()); - assertEquals("http://localhost:8080", apolloConfig.getPortalUrl()); - assertEquals("Namespace", apolloConfig.getNamespace()); - assertEquals("Meta", apolloConfig.getMeta()); - assertEquals("Env", apolloConfig.getEnv()); - assertEquals("Cluster Name", apolloConfig.getClusterName()); - } - - /** - * Method under test: {@link ApolloClient#getItemValue(String)}. - */ - @Test - public void testGetItemValue() { - when(apolloClient.getItemValue(Mockito.any())).thenReturn("42"); - assertEquals("42", apolloClient.getItemValue("Key")); - verify(apolloClient).getItemValue(Mockito.any()); - } - - /** - * Method under test: {@link ApolloClient#createOrUpdateItem(String, Object, String)}. - */ - @Test - public void testCreateOrUpdateItem() { - doNothing().when(apolloClient) - .createOrUpdateItem(Mockito.any(), Mockito.any(), Mockito.any()); - apolloClient.createOrUpdateItem("Key", (Object) "Value", "Comment"); - verify(apolloClient).createOrUpdateItem(Mockito.any(), Mockito.any(), Mockito.any()); - } - - /** - * Method under test: {@link ApolloClient#publishNamespace(String, String)}. - */ - @Test - public void testPublishNamespace() { - doNothing().when(apolloClient).publishNamespace(Mockito.any(), Mockito.any()); - apolloClient.publishNamespace("Dr", "1.0.2"); - verify(apolloClient).publishNamespace(Mockito.any(), Mockito.any()); - } -} - diff --git a/shenyu-admin-listener/shenyu-admin-listener-apollo/src/test/java/org/apache/shenyu/admin/listener/apollo/ApolloDataChangedInitTest.java b/shenyu-admin-listener/shenyu-admin-listener-apollo/src/test/java/org/apache/shenyu/admin/listener/apollo/ApolloDataChangedInitTest.java deleted file mode 100644 index 4cdddca25a86..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-apollo/src/test/java/org/apache/shenyu/admin/listener/apollo/ApolloDataChangedInitTest.java +++ /dev/null @@ -1,103 +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.apollo; - -import org.apache.shenyu.admin.config.properties.ApolloProperties; -import org.apache.shenyu.admin.listener.utils.NodeDataPathUtils; -import org.junit.Test; -import org.junit.jupiter.api.Assertions; -import org.junit.runner.RunWith; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import static org.apache.shenyu.common.constant.ApolloPathConstants.AUTH_DATA_ID; -import static org.apache.shenyu.common.constant.ApolloPathConstants.META_DATA_ID; -import static org.apache.shenyu.common.constant.ApolloPathConstants.PLUGIN_DATA_ID; -import static org.apache.shenyu.common.constant.ApolloPathConstants.PROXY_SELECTOR_DATA_ID; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.when; - -@ContextConfiguration(classes = {ApolloDataChangedInit.class}) -@RunWith(SpringJUnit4ClassRunner.class) -public class ApolloDataChangedInitTest { - - @MockBean - private ApolloClient apolloClient; - - @MockBean - private ApolloDataChangedInit apolloDataChangedInit; - - /** - * Method under test: {@link ApolloDataChangedInit#ApolloDataChangedInit(ApolloClient)}. - */ - @Test - public void testConstructor() { - ApolloProperties apolloConfig = new ApolloProperties(); - apolloConfig.setAppId("42"); - apolloConfig.setClusterName("Cluster Name"); - apolloConfig.setEnv("Env"); - apolloConfig.setMeta("Meta"); - apolloConfig.setNamespace("Namespace"); - apolloConfig.setPortalUrl("http://localhost:8080"); - apolloConfig.setToken("ABC123"); - ApolloClient apolloClient = new ApolloClient(apolloConfig); - ApolloDataChangedInit actualApolloDataChangedInit = new ApolloDataChangedInit(apolloClient); - assertNotNull(actualApolloDataChangedInit); - } - - /** - * Method under test: {@link ApolloDataChangedInit#notExist()}. - */ - @Test - public void testNotExist() { - - when(apolloClient.getItemValue(join(PLUGIN_DATA_ID))).thenReturn(PLUGIN_DATA_ID); - boolean pluginExist = apolloDataChangedInit.notExist(); - Assertions.assertFalse(pluginExist, "plugin exist."); - when(apolloClient.getItemValue(join(PLUGIN_DATA_ID))).thenReturn(null); - - when(apolloClient.getItemValue(join(AUTH_DATA_ID))).thenReturn(AUTH_DATA_ID); - boolean authExist = apolloDataChangedInit.notExist(); - Assertions.assertFalse(authExist, "auth exist."); - when(apolloClient.getItemValue(join(AUTH_DATA_ID))).thenReturn(null); - - when(apolloClient.getItemValue(join(META_DATA_ID))).thenReturn(META_DATA_ID); - boolean metaDataExist = apolloDataChangedInit.notExist(); - Assertions.assertFalse(metaDataExist, "metadata exist."); - when(apolloClient.getItemValue(join(META_DATA_ID))).thenReturn(null); - - when(apolloClient.getItemValue(join(PROXY_SELECTOR_DATA_ID))).thenReturn(PROXY_SELECTOR_DATA_ID); - boolean selectorDataExist = apolloDataChangedInit.notExist(); - Assertions.assertFalse(selectorDataExist, "selector exist."); - } - - @Test - public void testAllExist() { - when(apolloClient.getItemValue(join(PLUGIN_DATA_ID))).thenReturn(META_DATA_ID); - when(apolloClient.getItemValue(join(AUTH_DATA_ID))).thenReturn(META_DATA_ID); - when(apolloClient.getItemValue(join(META_DATA_ID))).thenReturn(META_DATA_ID); - when(apolloClient.getItemValue(join(PROXY_SELECTOR_DATA_ID))).thenReturn(META_DATA_ID); - Assertions.assertFalse(apolloDataChangedInit.notExist(), "some key not exist."); - } - - private String join(final String text) { - return NodeDataPathUtils.appendListStuff(text); - } -} - diff --git a/shenyu-admin-listener/shenyu-admin-listener-apollo/src/test/java/org/apache/shenyu/admin/listener/apollo/ApolloDataChangedListenerTest.java b/shenyu-admin-listener/shenyu-admin-listener-apollo/src/test/java/org/apache/shenyu/admin/listener/apollo/ApolloDataChangedListenerTest.java deleted file mode 100644 index c26397237cea..000000000000 --- a/shenyu-admin-listener/shenyu-admin-listener-apollo/src/test/java/org/apache/shenyu/admin/listener/apollo/ApolloDataChangedListenerTest.java +++ /dev/null @@ -1,93 +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.apollo; - -import org.apache.shenyu.admin.config.properties.ApolloProperties; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -@ContextConfiguration(classes = {ApolloDataChangedListener.class}) -@RunWith(SpringJUnit4ClassRunner.class) -public class ApolloDataChangedListenerTest { - - @MockBean - private ApolloClient apolloClient; - - @Autowired - private ApolloDataChangedListener apolloDataChangedListener; - - /** - * Method under test: {@link ApolloDataChangedListener#ApolloDataChangedListener(ApolloClient)}. - */ - @Test - public void testConstructor() { - ApolloProperties apolloConfig = new ApolloProperties(); - apolloConfig.setAppId("42"); - apolloConfig.setClusterName("Cluster Name"); - apolloConfig.setEnv("Env"); - apolloConfig.setMeta("Meta"); - apolloConfig.setNamespace("Namespace"); - apolloConfig.setPortalUrl("http://localhost:8080"); - apolloConfig.setToken("ABC123"); - new ApolloDataChangedListener(new ApolloClient(apolloConfig)); - } - - /** - * Method under test: {@link ApolloDataChangedListener#doPublishConfig(String, Object)}. - */ - @Test - public void testPublishConfig() { - doNothing().when(apolloClient) - .createOrUpdateItem(Mockito.any(), Mockito.any(), Mockito.any()); - doNothing().when(apolloClient).publishNamespace(Mockito.any(), Mockito.any()); - apolloDataChangedListener.doPublishConfig("42", "Data"); - verify(apolloClient).createOrUpdateItem(Mockito.any(), Mockito.any(), Mockito.any()); - verify(apolloClient).publishNamespace(Mockito.any(), Mockito.any()); - } - - /** - * Method under test: {@link ApolloDataChangedListener#getConfig(String)}. - */ - @Test - public void testGetConfig() { - when(apolloClient.getItemValue(Mockito.any())).thenReturn("42"); - assertEquals("42", apolloDataChangedListener.getConfig("42")); - verify(apolloClient).getItemValue(Mockito.any()); - } - - /** - * Method under test: {@link ApolloDataChangedListener#getConfig(String)}. - */ - @Test - public void testGetConfig2() { - when(apolloClient.getItemValue(Mockito.any())).thenReturn(""); - assertEquals("", apolloDataChangedListener.getConfig("42")); - verify(apolloClient).getItemValue(Mockito.any()); - } -} - diff --git a/shenyu-admin/src/main/resources/application.yml b/shenyu-admin/src/main/resources/application.yml index 69af897f43b5..0451c80c6623 100755 --- a/shenyu-admin/src/main/resources/application.yml +++ b/shenyu-admin/src/main/resources/application.yml @@ -82,14 +82,6 @@ shenyu: reconciliation: enabled: false interval: 60s -# apollo: -# meta: http://localhost:8080 -# appId: shenyu -# portalUrl: http://localhost:8070 -# env: dev -# clusterName: test -# namespace: application -# token: 0fff5645fc74ee5e0d63a6389433c8c8afc0beea31eed0279ecc1c8961d12da9 # zookeeper: # url: localhost:2181 # sessionTimeoutMilliseconds: 5000 diff --git a/shenyu-bootstrap/src/main/resources/application.yml b/shenyu-bootstrap/src/main/resources/application.yml index e861868a07e0..2a69aff4fbdc 100644 --- a/shenyu-bootstrap/src/main/resources/application.yml +++ b/shenyu-bootstrap/src/main/resources/application.yml @@ -225,12 +225,6 @@ shenyu: urls: ws://localhost:9095/websocket token: ${SHENYU_SYNC_WEBSOCKET_TOKEN:} allowOrigin: ws://localhost:9195 -# apollo: -# appId: shenyu -# meta: http://localhost:8080 -# env: dev -# clusterName: test -# namespace: application # zookeeper: # url: localhost:2181 # sessionTimeoutMilliseconds: 5000 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..64ecfd897d30 100644 --- a/shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE +++ b/shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE @@ -449,9 +449,6 @@ The text of each license is the standard Apache 2.0 license. curator-client 5.7.0: https://github.com/apache/curator, Apache 2.0 curator-framework 5.7.0: https://github.com/apache/curator, Apache 2.0 curator-recipes 5.7.0: https://github.com/apache/curator, Apache 2.0 - apollo-client 2.1.0: https://github.com/apolloconfig/apollo/blob/master/LICENSE, Apache 2.0 - apollo-openapi 2.1.0: https://github.com/apolloconfig/apollo/blob/master/LICENSE, Apache 2.0 - apollo-core 2.1.0: https://github.com/apolloconfig/apollo/blob/master/LICENSE, Apache 2.0 reactor-netty-core 1.1.20 https://github.com/reactor/reactor/blob/main/LICENSE, Apache 2.0 reactor-netty-http 1.1.20 https://github.com/reactor/reactor-netty/blob/main/LICENSE, Apache 2.0 javax.inject 1 http://www.apache.org/licenses/LICENSE-2.0, Apache 2.0 diff --git a/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/LICENSE b/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/LICENSE index 6e66f46a1080..48f0952a7245 100644 --- a/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/LICENSE +++ b/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/LICENSE @@ -598,9 +598,6 @@ The text of each license is the standard Apache 2.0 license. oltu 1.0.2: https://oltu.apache.org/, Apache 2.0 httpclient 4.5.14: https://github.com/apache/httpcomponents-client, Apache 2.0 okhttp 4.12.0: https://square.github.io/okhttp, Apache 2.0 - apollo-client 2.1.0: https://github.com/apolloconfig/apollo/blob/master/LICENSE, Apache 2.0 - apollo-openapi 2.1.0: https://github.com/apolloconfig/apollo/blob/master/LICENSE, Apache 2.0 - apollo-core 2.1.0: https://github.com/apolloconfig/apollo/blob/master/LICENSE, Apache 2.0 client-java-spring-integration 17.0.2: https://github.com/kubernetes-client/java, Apache 2.0 kotlin-stdlib 1.9.24 https://kotlinlang.org, Apache 2.0 kotlin-stdlib-common 1.9.24 https://kotlinlang.org, Apache 2.0 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..a38eb05e484a 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 @@ -216,12 +216,6 @@ shenyu: # websocket: # urls: ws://localhost:9095/websocket # allowOrigin: ws://localhost:9195 -# apollo: -# appId: shenyu -# meta: http://localhost:8080 -# env: dev -# clusterName: test -# namespace: application # zookeeper: # url: localhost:2181 # sessionTimeout: 5000 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..a38eb05e484a 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 @@ -216,12 +216,6 @@ shenyu: # websocket: # urls: ws://localhost:9095/websocket # allowOrigin: ws://localhost:9195 -# apollo: -# appId: shenyu -# meta: http://localhost:8080 -# env: dev -# clusterName: test -# namespace: application # zookeeper: # url: localhost:2181 # sessionTimeout: 5000 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..d5eb43f45498 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 @@ -217,12 +217,6 @@ shenyu: # websocket: # urls: ws://localhost:9095/websocket # allowOrigin: ws://localhost:9195 -# apollo: -# appId: shenyu -# meta: http://localhost:8080 -# env: dev -# clusterName: test -# namespace: application # zookeeper: # url: localhost:2181 # sessionTimeout: 5000 diff --git a/shenyu-registry/README.md b/shenyu-registry/README.md index 66ea84e1b5c2..156f2b57978e 100644 --- a/shenyu-registry/README.md +++ b/shenyu-registry/README.md @@ -40,7 +40,7 @@ runtime classpath, using the same ShenYu version as the application: | `zookeeper` | `shenyu-registry-zookeeper` | | `etcd` | `shenyu-registry-etcd` | | `nacos` | `shenyu-registry-nacos` | -| `apollo` | `shenyu-registry-apollo`; in-tree deprecation and planned external ownership: [migration guide](../docs/plugin-store-apollo.md) | +| `apollo` | External `shenyu-registry-apollo` from plugin-store: [migration guide](../docs/plugin-store-apollo.md) | | `eureka` | `shenyu-registry-eureka` | | `kubernetes` | `shenyu-registry-kubernetes` | @@ -62,7 +62,7 @@ example selects Eureka, and the gRPC example selects no registry implementation. 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 +the previous aggregate and now requires an explicit external provider dependency. Removing the compatibility aggregate is deferred to a separately announced change. Applications depending directly on core, SDK libraries, or SDK starters should add @@ -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 Apollo, Consul and Polaris extensions, implement `org.apache.shenyu.registry.api.ShenyuInstanceRegisterRepository`, carry `@Join`, and publish this resource in their JAR: @@ -117,7 +117,7 @@ alone does not remove those libraries. Keep the existing license and notice entr 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..b41a4c6d1361 100644 --- a/shenyu-registry/pom.xml +++ b/shenyu-registry/pom.xml @@ -32,7 +32,6 @@ shenyu-registry-zookeeper shenyu-registry-etcd shenyu-registry-nacos - shenyu-registry-apollo shenyu-registry-eureka shenyu-registry-kubernetes diff --git a/shenyu-registry/shenyu-registry-apollo/pom.xml b/shenyu-registry/shenyu-registry-apollo/pom.xml deleted file mode 100644 index 9a118eae1899..000000000000 --- a/shenyu-registry/shenyu-registry-apollo/pom.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - org.apache.shenyu - shenyu-registry - 2.7.2-SNAPSHOT - - 4.0.0 - shenyu-registry-apollo - - - - org.apache.shenyu - shenyu-registry-api - ${project.version} - - - - com.ctrip.framework.apollo - apollo-client - - - - com.ctrip.framework.apollo - apollo-openapi - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.apache.maven.plugins - maven-shade-plugin - ${maven-shade-plugin.version} - - - - - package - - shade - - - - - - - diff --git a/shenyu-registry/shenyu-registry-apollo/src/main/java/org/apache/shenyu/registry/apollo/ApolloClient.java b/shenyu-registry/shenyu-registry-apollo/src/main/java/org/apache/shenyu/registry/apollo/ApolloClient.java deleted file mode 100644 index 23b6915fb890..000000000000 --- a/shenyu-registry/shenyu-registry-apollo/src/main/java/org/apache/shenyu/registry/apollo/ApolloClient.java +++ /dev/null @@ -1,134 +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.apollo; - -import com.ctrip.framework.apollo.openapi.client.ApolloOpenApiClient; -import com.ctrip.framework.apollo.openapi.dto.NamespaceReleaseDTO; -import com.ctrip.framework.apollo.openapi.dto.OpenItemDTO; -import org.apache.shenyu.common.utils.GsonUtils; - -import java.util.Date; - -/** - * apollo open-api client. - */ -public class ApolloClient { - - private static final String DEFAULT_USER = "apollo"; - - private final ApolloConfig apolloConfig; - - private final ApolloOpenApiClient apolloOpenApiClient; - - public ApolloClient(final ApolloConfig apolloConfig) { - this.apolloConfig = apolloConfig; - - this.apolloOpenApiClient = ApolloOpenApiClient - .newBuilder() - .withPortalUrl(apolloConfig.getPortalUrl()) - .withToken(apolloConfig.getToken()) - .build(); - } - - /** - * get item value. - * @param key item key - * @return item value - */ - public String getItemValue(final String key) { - OpenItemDTO openItemDTO = this.apolloOpenApiClient.getItem( - apolloConfig.getAppId(), - apolloConfig.getEnv(), - apolloConfig.getClusterName(), - apolloConfig.getNamespace(), - key - ); - return openItemDTO.getValue(); - } - - /** - * create or update item into namespace. - * @param key item key - * @param value item value - * @param comment item comment - */ - public void createOrUpdateItem(final String key, final Object value, final String comment) { - this.createOrUpdateItem(key, GsonUtils.getInstance().toJson(value), comment); - } - - /** - * create or update item into namespace. - * @param key item key - * @param value item value - * @param comment item comment - */ - public void createOrUpdateItem(final String key, final String value, final String comment) { - OpenItemDTO openItemDTO = new OpenItemDTO(); - openItemDTO.setKey(key); - openItemDTO.setValue(value); - openItemDTO.setComment(comment); - openItemDTO.setDataChangeCreatedBy(DEFAULT_USER); - openItemDTO.setDataChangeLastModifiedBy(DEFAULT_USER); - Date now = new Date(); - openItemDTO.setDataChangeCreatedTime(now); - openItemDTO.setDataChangeLastModifiedTime(now); - - this.apolloOpenApiClient.createOrUpdateItem( - apolloConfig.getAppId(), - apolloConfig.getEnv(), - apolloConfig.getClusterName(), - apolloConfig.getNamespace(), - openItemDTO - ); - } - - /** - * remove item from namespace. - * @param key item key - */ - public void removeItem(final String key) { - this.apolloOpenApiClient.removeItem( - apolloConfig.getAppId(), - apolloConfig.getEnv(), - apolloConfig.getClusterName(), - apolloConfig.getNamespace(), - key, - DEFAULT_USER - ); - } - - /** - * publish item list in namespace. - * @param releaseTitle publish release title - * @param releaseComment publish release comment - */ - public void publishNamespace(final String releaseTitle, final String releaseComment) { - NamespaceReleaseDTO namespaceReleaseDTO = new NamespaceReleaseDTO(); - namespaceReleaseDTO.setReleaseTitle(releaseTitle); - namespaceReleaseDTO.setReleaseComment(releaseComment); - namespaceReleaseDTO.setReleasedBy(DEFAULT_USER); - - this.apolloOpenApiClient.publishNamespace( - apolloConfig.getAppId(), - apolloConfig.getEnv(), - apolloConfig.getClusterName(), - apolloConfig.getNamespace(), - namespaceReleaseDTO - ); - } -} diff --git a/shenyu-registry/shenyu-registry-apollo/src/main/java/org/apache/shenyu/registry/apollo/ApolloConfig.java b/shenyu-registry/shenyu-registry-apollo/src/main/java/org/apache/shenyu/registry/apollo/ApolloConfig.java deleted file mode 100644 index 6eb3c10cd1f1..000000000000 --- a/shenyu-registry/shenyu-registry-apollo/src/main/java/org/apache/shenyu/registry/apollo/ApolloConfig.java +++ /dev/null @@ -1,150 +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.apollo; - -public class ApolloConfig { - - /** - * appId. - */ - private String appId; - - /** - * portal url. - * e.g. localhost:8080 - */ - private String portalUrl; - - /** - * env. - * e.g. ENV - */ - private String env; - - /** - * cluster name. - */ - private String clusterName; - - /** - * namespace name. - */ - private String namespace; - - /** - * open api use token. - */ - private String token; - - /** - * get appId. - * @return appId - */ - public String getAppId() { - return appId; - } - - /** - * set app id. - * @param appId app id - */ - public void setAppId(final String appId) { - this.appId = appId; - } - - /** - * get portal url. - * @return portal url - */ - public String getPortalUrl() { - return portalUrl; - } - - /** - * set portal url. - * @param portalUrl portal url - */ - public void setPortalUrl(final String portalUrl) { - this.portalUrl = portalUrl; - } - - /** - * get env. - * @return env - */ - public String getEnv() { - return env; - } - - /** - * set env. - * @param env env - */ - public void setEnv(final String env) { - this.env = env; - } - - /** - * get cluster name. - * @return cluster name - */ - public String getClusterName() { - return clusterName; - } - - /** - * set cluster name. - * @param clusterName cluster name - */ - public void setClusterName(final String clusterName) { - this.clusterName = clusterName; - } - - /** - * get namespace name. - * @return namespace name - */ - public String getNamespace() { - return namespace; - } - - /** - * set namespace name. - * @param namespace namespace name - */ - public void setNamespace(final String namespace) { - this.namespace = namespace; - } - - /** - * get token. - * @return token - */ - public String getToken() { - return token; - } - - /** - * set token. - * @param token token - */ - public void setToken(final String token) { - this.token = token; - } -} - diff --git a/shenyu-registry/shenyu-registry-apollo/src/main/java/org/apache/shenyu/registry/apollo/ApolloInstanceRegisterRepository.java b/shenyu-registry/shenyu-registry-apollo/src/main/java/org/apache/shenyu/registry/apollo/ApolloInstanceRegisterRepository.java deleted file mode 100644 index 94e8c22444c2..000000000000 --- a/shenyu-registry/shenyu-registry-apollo/src/main/java/org/apache/shenyu/registry/apollo/ApolloInstanceRegisterRepository.java +++ /dev/null @@ -1,186 +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.apollo; - -import com.ctrip.framework.apollo.Config; -import com.ctrip.framework.apollo.ConfigChangeListener; -import com.ctrip.framework.apollo.ConfigService; -import com.ctrip.framework.apollo.core.ConfigConsts; -import com.google.common.collect.Maps; -import org.apache.shenyu.common.constant.Constants; -import org.apache.shenyu.common.utils.GsonUtils; -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.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.Optional; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Function; -import java.util.stream.Collectors; - -/** - * The type apollo instance register repository. - */ -@Join(isSingleton = false) -public class ApolloInstanceRegisterRepository implements ShenyuInstanceRegisterRepository { - - private static final String APOLLO_CLUSTER = "apollo.cluster"; - - private static final String PROP_APP_ID = "app.id"; - - private static final String PROP_APOLLO_META = "apollo.meta"; - - private static final String APOLLO_NAMESPACE = "apollo.bootstrap.namespace"; - - private static final Logger LOGGER = LoggerFactory.getLogger(ApolloInstanceRegisterRepository.class); - - private ApolloClient apolloClient; - - private final Map configChangeListenerMap = Maps.newConcurrentMap(); - - private final Map> watcherInstanceRegisterMap = new ConcurrentHashMap<>(); - - private String namespace; - - private Config configService; - - @Override - public void init(final RegisterConfig config) { - Properties properties = config.getProps(); - String meta = config.getServerLists(); - String appId = properties.getProperty("appId", "shenyu"); - String clusterName = properties.getProperty("clusterName", ConfigConsts.CLUSTER_NAME_DEFAULT); - String namespace = properties.getProperty("namespace", ConfigConsts.NAMESPACE_APPLICATION); - Optional.ofNullable(appId).ifPresent(x -> System.setProperty(PROP_APP_ID, x)); - Optional.ofNullable(meta).ifPresent(x -> System.setProperty(PROP_APOLLO_META, x)); - Optional.ofNullable(clusterName).ifPresent(x -> System.setProperty(APOLLO_CLUSTER, x)); - Optional.ofNullable(namespace).ifPresent(x -> System.setProperty(APOLLO_NAMESPACE, x)); - Optional.ofNullable(namespace).ifPresent(x -> System.setProperty(APOLLO_NAMESPACE, x)); - this.namespace = namespace; - this.configService = ConfigService.getAppConfig(); - buildClient(config); - } - - private void buildClient(final RegisterConfig config) { - // init apollo client - Properties properties = config.getProps(); - String appId = properties.getProperty("appId"); - String token = properties.getProperty("token"); - String env = properties.getProperty("env", "DEV"); - String clusterName = properties.getProperty("clusterName", ConfigConsts.CLUSTER_NAME_DEFAULT); - String namespace = properties.getProperty("namespace", ConfigConsts.NAMESPACE_APPLICATION); - String portalUrl = properties.getProperty("portalUrl", "http://localhost:8070"); - ApolloConfig apolloConfig = new ApolloConfig(); - apolloConfig.setAppId(appId); - apolloConfig.setPortalUrl(portalUrl); - apolloConfig.setToken(token); - apolloConfig.setEnv(env); - apolloConfig.setClusterName(clusterName); - apolloConfig.setNamespace(namespace); - this.apolloClient = new ApolloClient(apolloConfig); - } - - @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); - apolloClient.createOrUpdateItem(realNode, nodeData, "register instance"); - apolloClient.publishNamespace(namespace, "publish instance"); - LOGGER.info("apollo instance register success: {}", nodeData); - } - - @Override - public List selectInstances(final String selectKey) { - final String watchKey = InstancePathConstants.buildInstanceParentPath(selectKey); - - final Function, List> getInstanceRegisterFun = childrenList -> - childrenList.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()); - Map childrenList = new ConcurrentHashMap<>(); - - final List cachedInstances = watcherInstanceRegisterMap.get(selectKey); - if (Objects.nonNull(cachedInstances)) { - return cachedInstances; - } - - configService.getPropertyNames().forEach(key -> { - if (key.startsWith(watchKey)) { - String itemValue = apolloClient.getItemValue(key); - childrenList.put(key, itemValue); - } - }); - ConfigChangeListener configChangeListener = changeEvent -> { - Set keys = changeEvent.changedKeys(); - keys.forEach(key -> { - if (key.startsWith(watchKey)) { - switch (changeEvent.getChange(key).getChangeType()) { - case ADDED: - case MODIFIED: - childrenList.put(key, changeEvent.getChange(key).getNewValue()); - LOGGER.info("apollo instance register add or update {}", changeEvent.getChange(key).getNewValue()); - break; - case DELETED: - childrenList.remove(key); - LOGGER.info("apollo instance register delete success: {}", changeEvent.getChange(key).getOldValue()); - break; - default: - break; - } - watcherInstanceRegisterMap.put(selectKey, getInstanceRegisterFun.apply(childrenList)); - } - }); - }; - configService.addChangeListener(configChangeListener); - configChangeListenerMap.put(watchKey, configChangeListener); - final List instanceEntities = getInstanceRegisterFun.apply(childrenList); - watcherInstanceRegisterMap.put(selectKey, instanceEntities); - return instanceEntities; - } - - 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() { - configChangeListenerMap.forEach((key, value) -> configService.removeChangeListener(value)); - } -} diff --git a/shenyu-registry/shenyu-registry-apollo/src/main/resources/META-INF/shenyu/org.apache.shenyu.registry.api.ShenyuInstanceRegisterRepository b/shenyu-registry/shenyu-registry-apollo/src/main/resources/META-INF/shenyu/org.apache.shenyu.registry.api.ShenyuInstanceRegisterRepository deleted file mode 100644 index 201b52187adb..000000000000 --- a/shenyu-registry/shenyu-registry-apollo/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. - -apollo=org.apache.shenyu.registry.apollo.ApolloInstanceRegisterRepository diff --git a/shenyu-registry/shenyu-registry-apollo/src/test/java/org/apache/shenyu/registry/apollo/ApolloClientTest.java b/shenyu-registry/shenyu-registry-apollo/src/test/java/org/apache/shenyu/registry/apollo/ApolloClientTest.java deleted file mode 100644 index 7659847fbf63..000000000000 --- a/shenyu-registry/shenyu-registry-apollo/src/test/java/org/apache/shenyu/registry/apollo/ApolloClientTest.java +++ /dev/null @@ -1,98 +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.apollo; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@ContextConfiguration(classes = {ApolloConfig.class}) -@RunWith(SpringJUnit4ClassRunner.class) -public class ApolloClientTest { - - @MockBean - private ApolloClient apolloClient; - - @Test - public void testConstructor() { - ApolloConfig apolloConfig = new ApolloConfig(); - apolloConfig.setAppId("42"); - apolloConfig.setClusterName("Cluster Name"); - apolloConfig.setEnv("Env"); - apolloConfig.setNamespace("Namespace"); - apolloConfig.setPortalUrl("http://localhost:8080"); - apolloConfig.setToken("ABC123"); - new ApolloClient(apolloConfig); - assertEquals("42", apolloConfig.getAppId()); - assertEquals("ABC123", apolloConfig.getToken()); - assertEquals("http://localhost:8080", apolloConfig.getPortalUrl()); - assertEquals("Namespace", apolloConfig.getNamespace()); - assertEquals("Env", apolloConfig.getEnv()); - assertEquals("Cluster Name", apolloConfig.getClusterName()); - } - - /** - * Method under test: {@link ApolloClient#getItemValue(String)}. - */ - @Test - public void testGetItemValue() { - when(apolloClient.getItemValue(Mockito.any())).thenReturn("42"); - assertEquals("42", apolloClient.getItemValue("Key")); - verify(apolloClient).getItemValue(Mockito.any()); - } - - /** - * Method under test: {@link ApolloClient#createOrUpdateItem(String, Object, String)}. - */ - @Test - public void testCreateOrUpdateItem() { - doNothing().when(apolloClient) - .createOrUpdateItem(Mockito.any(), Mockito.any(), Mockito.any()); - apolloClient.createOrUpdateItem("Key", (Object) "Value", "Comment"); - verify(apolloClient).createOrUpdateItem(Mockito.any(), Mockito.any(), Mockito.any()); - } - - /** - * Method under test: {@link ApolloClient#removeItem(String)}. - */ - @Test - public void testRemoveItem() { - String keyToRemove = "KeyToRemove"; - apolloClient.removeItem(keyToRemove); - verify(apolloClient).removeItem(keyToRemove); - } - - /** - * Method under test: {@link ApolloClient#publishNamespace(String, String)}. - */ - @Test - public void testPublishNamespace() { - doNothing().when(apolloClient).publishNamespace(Mockito.any(), Mockito.any()); - apolloClient.publishNamespace("Dr", "1.0.2"); - verify(apolloClient).publishNamespace(Mockito.any(), Mockito.any()); - } -} - diff --git a/shenyu-registry/shenyu-registry-apollo/src/test/java/org/apache/shenyu/registry/apollo/ApolloConfigTest.java b/shenyu-registry/shenyu-registry-apollo/src/test/java/org/apache/shenyu/registry/apollo/ApolloConfigTest.java deleted file mode 100644 index f8542c398637..000000000000 --- a/shenyu-registry/shenyu-registry-apollo/src/test/java/org/apache/shenyu/registry/apollo/ApolloConfigTest.java +++ /dev/null @@ -1,61 +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.apollo; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class ApolloConfigTest { - /** - * Methods under test. - * - *
    - *
  • default or parameterless constructor of {@link ApolloConfig} - *
  • {@link ApolloConfig#setAppId(String)} - *
  • {@link ApolloConfig#setClusterName(String)} - *
  • {@link ApolloConfig#setEnv(String)} - *
  • {@link ApolloConfig#setNamespace(String)} - *
  • {@link ApolloConfig#setPortalUrl(String)} - *
  • {@link ApolloConfig#setToken(String)} - *
  • {@link ApolloConfig#getAppId()} - *
  • {@link ApolloConfig#getClusterName()} - *
  • {@link ApolloConfig#getEnv()} - *
  • {@link ApolloConfig#getNamespace()} - *
  • {@link ApolloConfig#getPortalUrl()} - *
  • {@link ApolloConfig#getToken()} - *
- */ - @Test - public void testConstructor() { - ApolloConfig actualApolloConfig = new ApolloConfig(); - actualApolloConfig.setAppId("42"); - actualApolloConfig.setClusterName("Cluster Name"); - actualApolloConfig.setEnv("Env"); - actualApolloConfig.setNamespace("Namespace"); - actualApolloConfig.setPortalUrl("https://example.org/example"); - actualApolloConfig.setToken("ABC123"); - assertEquals("42", actualApolloConfig.getAppId()); - assertEquals("Cluster Name", actualApolloConfig.getClusterName()); - assertEquals("Env", actualApolloConfig.getEnv()); - assertEquals("Namespace", actualApolloConfig.getNamespace()); - assertEquals("https://example.org/example", actualApolloConfig.getPortalUrl()); - assertEquals("ABC123", actualApolloConfig.getToken()); - } -} - diff --git a/shenyu-registry/shenyu-registry-apollo/src/test/java/org/apache/shenyu/registry/apollo/ApolloInstanceRegisterRepositoryTest.java b/shenyu-registry/shenyu-registry-apollo/src/test/java/org/apache/shenyu/registry/apollo/ApolloInstanceRegisterRepositoryTest.java deleted file mode 100644 index bc31e1c60c8e..000000000000 --- a/shenyu-registry/shenyu-registry-apollo/src/test/java/org/apache/shenyu/registry/apollo/ApolloInstanceRegisterRepositoryTest.java +++ /dev/null @@ -1,109 +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.apollo; - -import com.ctrip.framework.apollo.Config; -import com.ctrip.framework.apollo.ConfigChangeListener; -import com.ctrip.framework.apollo.enums.PropertyChangeType; -import com.ctrip.framework.apollo.model.ConfigChange; -import com.ctrip.framework.apollo.model.ConfigChangeEvent; -import org.apache.shenyu.common.utils.GsonUtils; -import org.apache.shenyu.registry.api.entity.InstanceEntity; -import org.apache.shenyu.registry.api.path.InstancePathConstants; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.springframework.test.util.ReflectionTestUtils; - -import java.net.URI; -import java.util.Collections; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public final class ApolloInstanceRegisterRepositoryTest { - - private ApolloInstanceRegisterRepository repository; - - private ConfigChangeListener listener; - - private String instanceKey; - - private String originalValue; - - @BeforeEach - public void setUp() { - repository = new ApolloInstanceRegisterRepository(); - Config config = mock(Config.class); - ApolloClient client = mock(ApolloClient.class); - ReflectionTestUtils.setField(repository, "configService", config); - ReflectionTestUtils.setField(repository, "apolloClient", client); - instanceKey = InstancePathConstants.buildRealNode(InstancePathConstants.buildInstanceParentPath("service"), "instance"); - originalValue = instanceJson("127.0.0.1", 8080); - when(config.getPropertyNames()).thenReturn(Collections.singleton(instanceKey)); - when(client.getItemValue(instanceKey)).thenReturn(originalValue); - assertEquals("127.0.0.1", repository.selectInstances("service").get(0).getHost()); - ArgumentCaptor captor = ArgumentCaptor.forClass(ConfigChangeListener.class); - verify(config).addChangeListener(captor.capture()); - listener = captor.getValue(); - } - - @Test - public void testModifiedInstanceRefreshesCache() { - publishChange(instanceKey, originalValue, instanceJson("127.0.0.2", 9090), PropertyChangeType.MODIFIED); - List instances = repository.selectInstances("service"); - assertEquals(1, instances.size()); - assertEquals("127.0.0.2", instances.get(0).getHost()); - assertEquals(9090, instances.get(0).getPort()); - assertEquals(URI.create("http://127.0.0.2:9090"), instances.get(0).getUri()); - } - - @Test - public void testAddedAndDeletedInstancesRefreshCache() { - String addedKey = instanceKey + "-second"; - String addedValue = instanceJson("127.0.0.2", 9090); - publishChange(addedKey, null, addedValue, PropertyChangeType.ADDED); - assertEquals(2, repository.selectInstances("service").size()); - publishChange(instanceKey, originalValue, null, PropertyChangeType.DELETED); - assertEquals("127.0.0.2", repository.selectInstances("service").get(0).getHost()); - publishChange(addedKey, addedValue, null, PropertyChangeType.DELETED); - assertTrue(repository.selectInstances("service").isEmpty()); - } - - @Test - public void testUnrelatedServiceChangeDoesNotAffectCache() { - String unrelatedKey = InstancePathConstants.buildRealNode(InstancePathConstants.buildInstanceParentPath("another-service"), "instance"); - publishChange(unrelatedKey, originalValue, instanceJson("127.0.0.2", 9090), PropertyChangeType.MODIFIED); - List instances = repository.selectInstances("service"); - assertEquals(1, instances.size()); - assertEquals("127.0.0.1", instances.get(0).getHost()); - } - - private void publishChange(final String key, final String oldValue, final String newValue, final PropertyChangeType type) { - ConfigChange change = new ConfigChange("application", key, oldValue, newValue, type); - listener.onChange(new ConfigChangeEvent("application", Collections.singletonMap(key, change))); - } - - private String instanceJson(final String host, final int port) { - return GsonUtils.getInstance().toJson(InstanceEntity.builder().appName("service").host(host).port(port).build()); - } -} diff --git a/shenyu-registry/shenyu-registry-apollo/src/test/java/org/apache/shenyu/registry/apollo/RegistrySpiTest.java b/shenyu-registry/shenyu-registry-apollo/src/test/java/org/apache/shenyu/registry/apollo/RegistrySpiTest.java deleted file mode 100644 index af130fd27912..000000000000 --- a/shenyu-registry/shenyu-registry-apollo/src/test/java/org/apache/shenyu/registry/apollo/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.apollo; - -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("apollo"); - assertEquals(ApolloInstanceRegisterRepository.class, repository.getClass()); - } -} 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..6e3e4ba2f366 100644 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/pom.xml +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/pom.xml @@ -32,7 +32,6 @@ shenyu-spring-boot-starter-sync-data-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-apollo/pom.xml b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-apollo/pom.xml deleted file mode 100644 index 3a20bd28a586..000000000000 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-apollo/pom.xml +++ /dev/null @@ -1,56 +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-apollo - - - - org.apache.shenyu - shenyu-sync-data-apollo - ${project.version} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - ${maven-shade-plugin.version} - - - - - package - - shade - - - - - - - diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-apollo/src/main/java/org/apache/shenyu/springboot/sync/data/apollo/ApolloSyncDataConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-apollo/src/main/java/org/apache/shenyu/springboot/sync/data/apollo/ApolloSyncDataConfiguration.java deleted file mode 100644 index 94f77d663d46..000000000000 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-apollo/src/main/java/org/apache/shenyu/springboot/sync/data/apollo/ApolloSyncDataConfiguration.java +++ /dev/null @@ -1,116 +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.apollo; - -import com.ctrip.framework.apollo.Config; -import com.ctrip.framework.apollo.ConfigService; -import org.apache.shenyu.common.config.ShenyuConfig; -import org.apache.shenyu.sync.data.api.AuthDataSubscriber; -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.DiscoveryUpstreamDataSubscriber; -import org.apache.shenyu.sync.data.apollo.ApolloDataService; -import org.apache.shenyu.sync.data.apollo.config.ApolloConfig; -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.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -/** - * Apollo sync data configuration for spring boot. - */ -@Configuration -@ConditionalOnClass(ApolloSyncDataConfiguration.class) -@ConditionalOnProperty(prefix = "shenyu.sync.apollo", name = "meta") -public class ApolloSyncDataConfiguration { - - private static final Logger LOGGER = LoggerFactory.getLogger(ApolloSyncDataConfiguration.class); - - private static final String APOLLO_CLUSTER = "apollo.cluster"; - - private static final String PROP_APP_ID = "app.id"; - - private static final String PROP_APOLLO_META = "apollo.meta"; - - private static final String PROP_APOLLO_SECRET = "apollo.access-key"; - - private static final String APOLLO_NAMESPACE = "apollo.bootstrap.namespace"; - - /** - * Apollo config apollo config. - * @param configService the config service - * @param pluginSubscriber the plugin subscriber - * @param metaSubscribers the meta subscribers - * @param authSubscribers the auth subscribers - * @param proxySelectorDataSubscriber the proxySelector subscribers - * @param discoveryUpstreamDataSubscribers the discoveryUpstream subscribers - * @param shenyuConfig the shenyu config - * - * @return the apollo config - */ - @Bean - public ApolloDataService apolloSyncDataService(final ObjectProvider configService, - final ObjectProvider pluginSubscriber, - final ObjectProvider> metaSubscribers, - final ObjectProvider> authSubscribers, - final ObjectProvider> proxySelectorDataSubscriber, - final ObjectProvider> discoveryUpstreamDataSubscribers, - final ObjectProvider shenyuConfig) { - LOGGER.info("you use apollo sync shenyu data......."); - return new ApolloDataService(configService.getIfAvailable(), pluginSubscriber.getIfAvailable(), - metaSubscribers.getIfAvailable(Collections::emptyList), authSubscribers.getIfAvailable(Collections::emptyList), proxySelectorDataSubscriber.getIfAvailable(Collections::emptyList), - discoveryUpstreamDataSubscribers.getIfAvailable(), shenyuConfig.getIfAvailable()); - } - - /** - * Apollo config config. - * - * @param apolloConfig the apollo config - * @return the config - */ - @Bean - public Config apolloConfigService(final ApolloConfig apolloConfig) { - Optional.ofNullable(apolloConfig.getAppId()).ifPresent(appId -> System.setProperty(PROP_APP_ID, appId)); - Optional.ofNullable(apolloConfig.getMeta()).ifPresent(meta -> System.setProperty(PROP_APOLLO_META, meta)); - Optional.ofNullable(apolloConfig.getClusterName()).ifPresent(cluster -> System.setProperty(APOLLO_CLUSTER, cluster)); - Optional.ofNullable(apolloConfig.getNamespace()).ifPresent(namespace -> System.setProperty(APOLLO_NAMESPACE, namespace)); - Optional.ofNullable(apolloConfig.getAccessKey()).ifPresent(accessKey -> System.setProperty(PROP_APOLLO_SECRET, accessKey)); - return ConfigService.getAppConfig(); - } - - /** - * apollo config. - * - * @return the apollo config - */ - @Bean - @ConfigurationProperties(prefix = "shenyu.sync.apollo") - public ApolloConfig apolloConfig() { - return new ApolloConfig(); - } -} - diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-apollo/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-apollo/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index e2cf78e021ce..000000000000 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-apollo/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.apollo.ApolloSyncDataConfiguration diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-apollo/src/test/java/org/apache/shenyu/springboot/sync/data/apollo/ApolloSyncDataConfigurationTest.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-apollo/src/test/java/org/apache/shenyu/springboot/sync/data/apollo/ApolloSyncDataConfigurationTest.java deleted file mode 100644 index cdf0a7aec06c..000000000000 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-apollo/src/test/java/org/apache/shenyu/springboot/sync/data/apollo/ApolloSyncDataConfigurationTest.java +++ /dev/null @@ -1,87 +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.apollo; - -import com.ctrip.framework.apollo.ConfigService; - -import org.apache.shenyu.common.config.ShenyuConfig; -import org.apache.shenyu.sync.data.api.SyncDataService; -import org.apache.shenyu.sync.data.apollo.ApolloDataService; -import org.apache.shenyu.sync.data.apollo.config.ApolloConfig; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Answers.CALLS_REAL_METHODS; - -@ExtendWith(SpringExtension.class) -@MockBean(ConfigService.class) -@EnableAutoConfiguration -@SpringBootTest( - classes = { - ApolloSyncDataConfiguration.class - }, - webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - properties = { - "shenyu.sync.apollo.meta=http://localhost:8080", - "shenyu.sync.apollo.appId=shenyu", - "shenyu.sync.apollo.env=dev", - "shenyu.sync.apollo.clusterName=test", - "shenyu.sync.apollo.namespace=application" - - }) -@MockBean(name = "shenyuConfig", value = ShenyuConfig.class, answer = CALLS_REAL_METHODS) -class ApolloSyncDataConfigurationTest { - - @Autowired - private ApolloConfig apolloConfig; - - @Autowired - private SyncDataService syncDataService; - - /** - * case to test {@link ApolloSyncDataConfiguration} to register bean {@link ApolloSyncDataConfiguration}. - */ - @Test - public void testApolloSyncDataConfigurationRegisterBeanSyncDataService() { - assertNotNull(syncDataService); - assertTrue(syncDataService instanceof ApolloDataService); - } - - /** - * case to test {@link ApolloSyncDataConfiguration} to register bean {@link ApolloSyncDataConfiguration}. - */ - @Test - public void testApolloSyncDataConfigurationRegisterBeanApolloConfig() { - assertThat(apolloConfig.getMeta(), is("http://localhost:8080")); - assertThat(apolloConfig.getAppId(), is("shenyu")); - assertThat(apolloConfig.getEnv(), is("dev")); - assertThat(apolloConfig.getClusterName(), is("test")); - assertThat(apolloConfig.getNamespace(), is("application")); - - } -} - diff --git a/shenyu-sync-data-center/pom.xml b/shenyu-sync-data-center/pom.xml index 7467a32ad790..697f420ccb43 100644 --- a/shenyu-sync-data-center/pom.xml +++ b/shenyu-sync-data-center/pom.xml @@ -33,6 +33,5 @@ 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-apollo/pom.xml b/shenyu-sync-data-center/shenyu-sync-data-apollo/pom.xml deleted file mode 100644 index 2461ecc66e39..000000000000 --- a/shenyu-sync-data-center/shenyu-sync-data-apollo/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - org.apache.shenyu - shenyu-sync-data-center - 2.7.2-SNAPSHOT - - 4.0.0 - shenyu-sync-data-apollo - - - - org.apache.shenyu - shenyu-sync-data-api - ${project.version} - - - com.ctrip.framework.apollo - apollo-client - - - - diff --git a/shenyu-sync-data-center/shenyu-sync-data-apollo/src/main/java/org/apache/shenyu/sync/data/apollo/ApolloDataService.java b/shenyu-sync-data-center/shenyu-sync-data-apollo/src/main/java/org/apache/shenyu/sync/data/apollo/ApolloDataService.java deleted file mode 100644 index e2f868042629..000000000000 --- a/shenyu-sync-data-center/shenyu-sync-data-apollo/src/main/java/org/apache/shenyu/sync/data/apollo/ApolloDataService.java +++ /dev/null @@ -1,175 +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.apollo; - -import com.ctrip.framework.apollo.Config; -import com.ctrip.framework.apollo.ConfigChangeListener; -import com.ctrip.framework.apollo.enums.PropertyChangeType; -import com.ctrip.framework.apollo.model.ConfigChange; -import org.apache.commons.lang3.ObjectUtils; -import org.apache.shenyu.common.config.ShenyuConfig; -import org.apache.shenyu.common.constant.ApolloPathConstants; -import org.apache.shenyu.common.constant.DefaultNodeConstants; -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.core.AbstractNodeDataSyncService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.function.Consumer; - -public class ApolloDataService extends AbstractNodeDataSyncService implements SyncDataService { - - private static final Logger LOG = LoggerFactory.getLogger(ApolloDataService.class); - - private final Config configService; - - private ConfigChangeListener watchConfigChangeListener; - - /** - * Instantiates a new Nacos sync data service. - * - * @param configService the config service - * @param pluginDataSubscriber the plugin data subscriber - * @param metaDataSubscribers the meta data subscribers - * @param authDataSubscribers the auth data subscribers - * @param proxySelectorDataSubscribers the proxy selector data subscribers - * @param discoveryUpstreamDataSubscribers the discovery upstream data subscribers - * @param shenyuConfig the shenyu config - */ - public ApolloDataService(final Config configService, final PluginDataSubscriber pluginDataSubscriber, - final List metaDataSubscribers, - final List authDataSubscribers, - final List proxySelectorDataSubscribers, - final List discoveryUpstreamDataSubscribers, - final ShenyuConfig shenyuConfig) { - super(new ChangeData(ApolloPathConstants.PLUGIN_DATA_ID, - ApolloPathConstants.SELECTOR_DATA_ID, - ApolloPathConstants.RULE_DATA_ID, - ApolloPathConstants.AUTH_DATA_ID, - ApolloPathConstants.META_DATA_ID, - ApolloPathConstants.PROXY_SELECTOR_DATA_ID, - ApolloPathConstants.DISCOVERY_DATA_ID), - pluginDataSubscriber, - metaDataSubscribers, - authDataSubscribers, - proxySelectorDataSubscribers, - discoveryUpstreamDataSubscribers, - shenyuConfig); - this.configService = configService; - - startWatch(); - apolloWatchPrefixes(shenyuConfig.getNamespace()); - } - - private void apolloWatchPrefixes(final String namespaceId) { - // apollo change keys are namespace-prefixed, e.g. {namespaceId}.plugin.{pluginName} - final String namespacePrefix = namespaceId + DefaultNodeConstants.JOIN_POINT; - final ConfigChangeListener listener = changeEvent -> changeEvent.changedKeys().forEach(changeKey -> { - try { - final ConfigChange configChange = changeEvent.getChange(changeKey); - if (Objects.isNull(configChange)) { - LOG.error("apollo watchPrefixes error configChange is null {}", changeKey); - return; - } - final String newValue = configChange.getNewValue(); - // skip last is "list" - final int lastListStrIndex = changeKey.length() - DefaultNodeConstants.LIST_STR.length(); - if (changeKey.lastIndexOf(DefaultNodeConstants.LIST_STR) == lastListStrIndex) { - return; - } - // check prefix - if (changeKey.startsWith(namespacePrefix + ApolloPathConstants.PLUGIN_DATA_ID)) { - if (PropertyChangeType.DELETED.equals(configChange.getChangeType())) { - unCachePluginData(changeKey); - } else { - cachePluginData(newValue); - } - } else if (changeKey.startsWith(namespacePrefix + ApolloPathConstants.SELECTOR_DATA_ID)) { - if (PropertyChangeType.DELETED.equals(configChange.getChangeType())) { - unCacheSelectorData(changeKey); - } else { - cacheSelectorData(newValue); - } - } else if (changeKey.startsWith(namespacePrefix + ApolloPathConstants.RULE_DATA_ID)) { - if (PropertyChangeType.DELETED.equals(configChange.getChangeType())) { - unCacheRuleData(changeKey); - } else { - cacheRuleData(newValue); - } - } else if (changeKey.startsWith(namespacePrefix + ApolloPathConstants.AUTH_DATA_ID)) { - if (PropertyChangeType.DELETED.equals(configChange.getChangeType())) { - unCacheAuthData(changeKey); - } else { - cacheAuthData(newValue); - } - } else if (changeKey.startsWith(namespacePrefix + ApolloPathConstants.META_DATA_ID)) { - if (PropertyChangeType.DELETED.equals(configChange.getChangeType())) { - unCacheMetaData(changeKey); - } else { - cacheMetaData(newValue); - } - } else if (changeKey.startsWith(namespacePrefix + ApolloPathConstants.PROXY_SELECTOR_DATA_ID)) { - if (PropertyChangeType.DELETED.equals(configChange.getChangeType())) { - unCacheProxySelectorData(changeKey); - } else { - cacheProxySelectorData(newValue); - } - } else if (changeKey.startsWith(namespacePrefix + ApolloPathConstants.DISCOVERY_DATA_ID)) { - if (PropertyChangeType.DELETED.equals(configChange.getChangeType())) { - unCacheDiscoveryUpstreamData(changeKey); - } else { - cacheDiscoveryUpstreamData(newValue); - } - } - } catch (Exception e) { - LOG.error("apollo sync listener change key handler error", e); - } - }); - watchConfigChangeListener = listener; - configService.addChangeListener(listener, Collections.emptySet(), ApolloPathConstants.pathKeySet(namespaceId)); - - } - - @Override - protected void doRemoveListener(final String key) { - // No need to implement - } - - @Override - protected String getServiceConfig(final String key, final Consumer updateHandler, final Consumer deleteHandler) { - return configService.getProperty(key, null); - } - - /** - * close. - */ - @Override - public void close() { - if (!ObjectUtils.isEmpty(watchConfigChangeListener)) { - configService.removeChangeListener(watchConfigChangeListener); - } - } -} diff --git a/shenyu-sync-data-center/shenyu-sync-data-apollo/src/main/java/org/apache/shenyu/sync/data/apollo/config/ApolloConfig.java b/shenyu-sync-data-center/shenyu-sync-data-apollo/src/main/java/org/apache/shenyu/sync/data/apollo/config/ApolloConfig.java deleted file mode 100644 index 42bcbccae629..000000000000 --- a/shenyu-sync-data-center/shenyu-sync-data-apollo/src/main/java/org/apache/shenyu/sync/data/apollo/config/ApolloConfig.java +++ /dev/null @@ -1,155 +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.apollo.config; - -public class ApolloConfig { - - /** - * appId. - */ - private String appId; - - /** - * apollo config service url. - */ - private String meta; - - /** - * env. - * e.g. ENV - */ - private String env; - - /** - * cluster name. - */ - private String clusterName; - - /** - * namespace name. - */ - private String namespace; - - /** - * accessKey. - */ - private String accessKey; - - /** - * constructor. - */ - public ApolloConfig() { - } - - /** - * getSecretKey. - * @return secretKey - */ - public String getAccessKey() { - return accessKey; - } - - /** - * set secretKey. - * @param accessKey accessKey - */ - public void setAccessKey(final String accessKey) { - this.accessKey = accessKey; - } - - /** - * get appId. - * @return appId - */ - public String getAppId() { - return appId; - } - - /** - * set appId. - * @param appId appId - */ - public void setAppId(final String appId) { - this.appId = appId; - } - - /** - * get meta. - * @return meta - */ - public String getMeta() { - return meta; - } - - /** - * set meta. - * @param meta meta - */ - public void setMeta(final String meta) { - this.meta = meta; - } - - /** - * get env. - * @return env - */ - public String getEnv() { - return env; - } - - /** - * set env. - * @param env env - */ - public void setEnv(final String env) { - this.env = env; - } - - /** - * get clusterName. - * @return clusterName - */ - public String getClusterName() { - return clusterName; - } - - /** - * set clusterName. - * @param clusterName clusterName - */ - public void setClusterName(final String clusterName) { - this.clusterName = clusterName; - } - - /** - * get namespace. - * @return namespace - */ - public String getNamespace() { - return namespace; - } - - /** - * set namespace. - * @param namespace namespace - */ - public void setNamespace(final String namespace) { - this.namespace = namespace; - } - -} diff --git a/shenyu-sync-data-center/shenyu-sync-data-apollo/src/test/java/org/apache/shenyu/sync/data/apollo/ApolloDataServiceIntegrationTest.java b/shenyu-sync-data-center/shenyu-sync-data-apollo/src/test/java/org/apache/shenyu/sync/data/apollo/ApolloDataServiceIntegrationTest.java deleted file mode 100644 index eb99b83e054c..000000000000 --- a/shenyu-sync-data-center/shenyu-sync-data-apollo/src/test/java/org/apache/shenyu/sync/data/apollo/ApolloDataServiceIntegrationTest.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.sync.data.apollo; - -import com.ctrip.framework.apollo.enums.ConfigSourceType; -import com.ctrip.framework.apollo.internals.ConfigRepository; -import com.ctrip.framework.apollo.internals.DefaultConfig; -import org.apache.shenyu.common.config.ShenyuConfig; -import org.apache.shenyu.common.dto.PluginData; -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.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.Collections; -import java.util.Properties; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -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.Mockito.doAnswer; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -/** - * Integration test case for {@link ApolloDataService} that flows through apollo-client's real - * change listener filtering (interested keys and prefixes are matched in {@link com.ctrip.framework.apollo.internals.AbstractConfig}). - */ -@ExtendWith(MockitoExtension.class) -class ApolloDataServiceIntegrationTest { - - private static final String NAMESPACE = "shenyu"; - - @Mock - private PluginDataSubscriber pluginDataSubscriber; - - @Mock - private MetaDataSubscriber metaDataSubscriber; - - @Mock - private AuthDataSubscriber authDataSubscriber; - - @Mock - private ProxySelectorDataSubscriber proxySelectorDataSubscriber; - - @Mock - private DiscoveryUpstreamDataSubscriber discoveryUpstreamDataSubscriber; - - @Test - void testIncrementalChangeEventFlowsThroughApolloPrefixFiltering() throws InterruptedException { - final DefaultConfig defaultConfig = createDefaultConfig(); - - final CountDownLatch latch = new CountDownLatch(1); - doAnswer(invocation -> { - latch.countDown(); - return null; - }).when(pluginDataSubscriber).onSubscribe(any()); - - new ApolloDataService(defaultConfig, - pluginDataSubscriber, - Collections.singletonList(metaDataSubscriber), - Collections.singletonList(authDataSubscriber), - Collections.singletonList(proxySelectorDataSubscriber), - Collections.singletonList(discoveryUpstreamDataSubscriber), - createShenyuConfig()); - - final Properties changedProperties = new Properties(); - changedProperties.setProperty(NAMESPACE + ".plugin.divide", "{\"id\":\"1\",\"name\":\"divide\"}"); - defaultConfig.onRepositoryChange(NAMESPACE, changedProperties); - - assertTrue(latch.await(5, TimeUnit.SECONDS), - "incremental change event should reach the subscriber through apollo prefix filtering"); - } - - @Test - void testDeletedEventFlowsThroughApolloPrefixFiltering() throws InterruptedException { - final DefaultConfig defaultConfig = createDefaultConfig(); - final Properties initialProperties = new Properties(); - initialProperties.setProperty(NAMESPACE + ".plugin.divide", "{\"id\":\"1\",\"name\":\"divide\"}"); - defaultConfig.onRepositoryChange(NAMESPACE, initialProperties); - - final CountDownLatch latch = new CountDownLatch(1); - doAnswer(invocation -> { - latch.countDown(); - return null; - }).when(pluginDataSubscriber).unSubscribe(any()); - - new ApolloDataService(defaultConfig, - pluginDataSubscriber, - Collections.singletonList(metaDataSubscriber), - Collections.singletonList(authDataSubscriber), - Collections.singletonList(proxySelectorDataSubscriber), - Collections.singletonList(discoveryUpstreamDataSubscriber), - createShenyuConfig()); - - defaultConfig.onRepositoryChange(NAMESPACE, new Properties()); - - assertTrue(latch.await(5, TimeUnit.SECONDS), - "deleted event should reach the subscriber through apollo prefix filtering"); - ArgumentCaptor captor = ArgumentCaptor.forClass(PluginData.class); - verify(pluginDataSubscriber).unSubscribe(captor.capture()); - assertEquals("divide", captor.getValue().getName()); - } - - private DefaultConfig createDefaultConfig() { - final ConfigRepository configRepository = mock(ConfigRepository.class); - when(configRepository.getConfig()).thenReturn(new Properties()); - when(configRepository.getSourceType()).thenReturn(ConfigSourceType.LOCAL); - return new DefaultConfig(NAMESPACE, configRepository); - } - - private ShenyuConfig createShenyuConfig() { - final ShenyuConfig shenyuConfig = new ShenyuConfig(); - shenyuConfig.setNamespace(NAMESPACE); - return shenyuConfig; - } -} 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 deleted file mode 100644 index 9db5392159e4..000000000000 --- a/shenyu-sync-data-center/shenyu-sync-data-apollo/src/test/java/org/apache/shenyu/sync/data/apollo/ApolloDataServiceTest.java +++ /dev/null @@ -1,391 +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.apollo; - -import com.ctrip.framework.apollo.Config; -import com.ctrip.framework.apollo.ConfigChangeListener; -import com.ctrip.framework.apollo.enums.PropertyChangeType; -import com.ctrip.framework.apollo.model.ConfigChange; -import com.ctrip.framework.apollo.model.ConfigChangeEvent; -import org.apache.shenyu.common.config.ShenyuConfig; -import org.apache.shenyu.common.constant.ApolloPathConstants; -import org.apache.shenyu.common.dto.PluginData; -import org.apache.shenyu.common.dto.ProxySelectorData; -import org.apache.shenyu.common.dto.RuleData; -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.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anySet; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.lenient; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; -import static org.mockito.Mockito.when; - -/** - * Test case for {@link ApolloDataService}. - */ -@ExtendWith(MockitoExtension.class) -class ApolloDataServiceTest { - - private static final String NAMESPACE = "shenyu"; - - @Mock - private Config configService; - - @Mock - private PluginDataSubscriber pluginDataSubscriber; - - @Mock - private MetaDataSubscriber metaDataSubscriber; - - @Mock - private AuthDataSubscriber authDataSubscriber; - - @Mock - private ProxySelectorDataSubscriber proxySelectorDataSubscriber; - - @Mock - private DiscoveryUpstreamDataSubscriber discoveryUpstreamDataSubscriber; - - private ShenyuConfig shenyuConfig; - - private ConfigChangeListener capturedListener; - - @BeforeEach - void setUp() { - shenyuConfig = new ShenyuConfig(); - shenyuConfig.setNamespace(NAMESPACE); - - lenient().when(configService.getProperty(anyString(), any())).thenReturn("[]"); - } - - @Test - void testConstructorAndClose() { - final ApolloDataService apolloDataService = new ApolloDataService( - configService, - pluginDataSubscriber, - Collections.singletonList(metaDataSubscriber), - Collections.singletonList(authDataSubscriber), - Collections.singletonList(proxySelectorDataSubscriber), - Collections.singletonList(discoveryUpstreamDataSubscriber), - shenyuConfig - ); - - ArgumentCaptor listenerCaptor = ArgumentCaptor.forClass(ConfigChangeListener.class); - verify(configService).addChangeListener(listenerCaptor.capture(), anySet(), eq(ApolloPathConstants.pathKeySet(NAMESPACE))); - - capturedListener = listenerCaptor.getValue(); - assertNotNull(capturedListener); - - apolloDataService.close(); - verify(configService).removeChangeListener(capturedListener); - } - - @Test - void testCloseWithNullListener() { - lenient().when(configService.getProperty(anyString(), any())).thenReturn(null); - - ApolloDataService apolloDataService = new ApolloDataService( - configService, - null, - Collections.emptyList(), - Collections.emptyList(), - Collections.emptyList(), - Collections.emptyList(), - shenyuConfig - ); - - apolloDataService.close(); - verify(configService, times(1)).removeChangeListener(any()); - } - - @Test - void testPluginDataChange() { - ApolloDataService apolloDataService = createApolloDataService(); - - ConfigChangeEvent event = mockConfigChangeEvent( - NAMESPACE + "." + ApolloPathConstants.PLUGIN_DATA_ID + ".test-plugin", - "{\"id\":\"1\",\"name\":\"test\"}", - PropertyChangeType.MODIFIED - ); - - capturedListener.onChange(event); - verify(pluginDataSubscriber, times(1)).onSubscribe(any()); - } - - @Test - void testPluginDataAdd() { - ApolloDataService apolloDataService = createApolloDataService(); - - ConfigChangeEvent event = mockConfigChangeEvent( - NAMESPACE + "." + ApolloPathConstants.PLUGIN_DATA_ID + ".new-plugin", - "{\"id\":\"2\",\"name\":\"new\"}", - PropertyChangeType.ADDED - ); - - capturedListener.onChange(event); - verify(pluginDataSubscriber, times(1)).onSubscribe(any()); - } - - @Test - void testPluginDataDeleted() { - ApolloDataService apolloDataService = createApolloDataService(); - - ConfigChangeEvent event = mockConfigChangeEvent( - NAMESPACE + "." + ApolloPathConstants.PLUGIN_DATA_ID + ".test-plugin", - null, - PropertyChangeType.DELETED - ); - - capturedListener.onChange(event); - ArgumentCaptor captor = ArgumentCaptor.forClass(PluginData.class); - verify(pluginDataSubscriber, times(1)).unSubscribe(captor.capture()); - assertEquals("test-plugin", captor.getValue().getName()); - } - - @Test - void testSelectorDataChange() { - ApolloDataService apolloDataService = createApolloDataService(); - - ConfigChangeEvent event = mockConfigChangeEvent( - NAMESPACE + "." + ApolloPathConstants.SELECTOR_DATA_ID + ".test-plugin.test-selector", - "{\"id\":\"1\",\"name\":\"test\"}", - PropertyChangeType.MODIFIED - ); - - capturedListener.onChange(event); - verify(pluginDataSubscriber, times(1)).onSelectorSubscribe(any()); - } - - @Test - void testRuleDataChange() { - ApolloDataService apolloDataService = createApolloDataService(); - - ConfigChangeEvent event = mockConfigChangeEvent( - NAMESPACE + "." + ApolloPathConstants.RULE_DATA_ID + ".test-plugin.test-selector.test-rule", - "{\"id\":\"1\",\"name\":\"test\"}", - PropertyChangeType.MODIFIED - ); - - capturedListener.onChange(event); - verify(pluginDataSubscriber, times(1)).onRuleSubscribe(any()); - } - - @Test - void testRuleDataDeleted() { - ApolloDataService apolloDataService = createApolloDataService(); - - ConfigChangeEvent event = mockConfigChangeEvent( - NAMESPACE + "." + ApolloPathConstants.RULE_DATA_ID + ".test-plugin.test-selector.test-rule", - null, - PropertyChangeType.DELETED - ); - - capturedListener.onChange(event); - ArgumentCaptor captor = ArgumentCaptor.forClass(RuleData.class); - verify(pluginDataSubscriber, times(1)).unRuleSubscribe(captor.capture()); - assertEquals("test-plugin", captor.getValue().getPluginName()); - assertEquals("test-selector", captor.getValue().getSelectorId()); - assertEquals("test-rule", captor.getValue().getId()); - } - - @Test - void testAuthDataChange() { - ApolloDataService apolloDataService = createApolloDataService(); - - ConfigChangeEvent event = mockConfigChangeEvent( - NAMESPACE + "." + ApolloPathConstants.AUTH_DATA_ID + ".test-auth", - "{\"appKey\":\"test\"}", - PropertyChangeType.MODIFIED - ); - - capturedListener.onChange(event); - verify(authDataSubscriber, times(1)).onSubscribe(any()); - } - - @Test - void testMetaDataChange() { - ApolloDataService apolloDataService = createApolloDataService(); - - ConfigChangeEvent event = mockConfigChangeEvent( - NAMESPACE + "." + ApolloPathConstants.META_DATA_ID + ".test-meta", - "{\"id\":\"1\",\"path\":\"/test\"}", - PropertyChangeType.MODIFIED - ); - - capturedListener.onChange(event); - verify(metaDataSubscriber, times(1)).onSubscribe(any()); - } - - @Test - void testProxySelectorDataChange() { - ApolloDataService apolloDataService = createApolloDataService(); - - ConfigChangeEvent event = mockConfigChangeEvent( - NAMESPACE + "." + ApolloPathConstants.PROXY_SELECTOR_DATA_ID + ".test-plugin.test-proxy", - "{\"id\":\"1\",\"name\":\"test\"}", - PropertyChangeType.MODIFIED - ); - - capturedListener.onChange(event); - verify(proxySelectorDataSubscriber, times(1)).onSubscribe(any()); - } - - @Test - void testProxySelectorDataDeleted() { - ApolloDataService apolloDataService = createApolloDataService(); - - ConfigChangeEvent event = mockConfigChangeEvent( - NAMESPACE + "." + ApolloPathConstants.PROXY_SELECTOR_DATA_ID + ".test-plugin.test-proxy", - null, - PropertyChangeType.DELETED - ); - - capturedListener.onChange(event); - 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()); - } - - @Test - void testDiscoveryDataChange() { - ApolloDataService apolloDataService = createApolloDataService(); - - ConfigChangeEvent event = mockConfigChangeEvent( - NAMESPACE + "." + ApolloPathConstants.DISCOVERY_DATA_ID + ".test-plugin.test-discovery", - "{\"name\":\"test\"}", - PropertyChangeType.MODIFIED - ); - - capturedListener.onChange(event); - verify(discoveryUpstreamDataSubscriber, times(1)).onSubscribe(any()); - } - - @Test - void testListKeySkipped() { - ApolloDataService apolloDataService = createApolloDataService(); - - ConfigChangeEvent event = mockConfigChangeEvent( - NAMESPACE + "." + ApolloPathConstants.PLUGIN_DATA_ID + ".list", - "[\"test-plugin\"]", - PropertyChangeType.MODIFIED - ); - - capturedListener.onChange(event); - verifyNoInteractions(pluginDataSubscriber); - } - - @Test - void testChangeKeyWithoutNamespacePrefixIgnored() { - ApolloDataService apolloDataService = createApolloDataService(); - - ConfigChangeEvent event = mockConfigChangeEvent( - "other-namespace." + ApolloPathConstants.PLUGIN_DATA_ID + ".test-plugin", - "{\"id\":\"1\",\"name\":\"test\"}", - PropertyChangeType.MODIFIED - ); - - capturedListener.onChange(event); - verifyNoInteractions(pluginDataSubscriber); - } - - @Test - void testNullConfigChange() { - final ApolloDataService apolloDataService = createApolloDataService(); - - ConfigChangeEvent event = mock(ConfigChangeEvent.class); - Set keys = new HashSet<>(); - keys.add("test-key"); - when(event.changedKeys()).thenReturn(keys); - when(event.getChange("test-key")).thenReturn(null); - - capturedListener.onChange(event); - // Should handle null config change gracefully - assertNotNull(apolloDataService); - } - - @Test - void testExceptionInChangeHandler() { - final ApolloDataService apolloDataService = createApolloDataService(); - - ConfigChangeEvent event = mock(ConfigChangeEvent.class); - Set keys = new HashSet<>(); - keys.add(NAMESPACE + "." + ApolloPathConstants.PLUGIN_DATA_ID + ".test"); - when(event.changedKeys()).thenReturn(keys); - when(event.getChange(anyString())).thenThrow(new RuntimeException("Test exception")); - - capturedListener.onChange(event); - // Should handle exception gracefully - assertNotNull(apolloDataService); - } - - private ApolloDataService createApolloDataService() { - ApolloDataService service = new ApolloDataService( - configService, - pluginDataSubscriber, - Collections.singletonList(metaDataSubscriber), - Collections.singletonList(authDataSubscriber), - Collections.singletonList(proxySelectorDataSubscriber), - Collections.singletonList(discoveryUpstreamDataSubscriber), - shenyuConfig - ); - - ArgumentCaptor listenerCaptor = ArgumentCaptor.forClass(ConfigChangeListener.class); - verify(configService).addChangeListener(listenerCaptor.capture(), anySet(), eq(ApolloPathConstants.pathKeySet(NAMESPACE))); - capturedListener = listenerCaptor.getValue(); - - return service; - } - - private ConfigChangeEvent mockConfigChangeEvent(final String key, final String newValue, final PropertyChangeType changeType) { - ConfigChangeEvent event = mock(ConfigChangeEvent.class); - ConfigChange configChange = mock(ConfigChange.class); - - Set keys = new HashSet<>(); - keys.add(key); - - when(event.changedKeys()).thenReturn(keys); - when(event.getChange(key)).thenReturn(configChange); - when(configChange.getNewValue()).thenReturn(newValue); - lenient().when(configChange.getChangeType()).thenReturn(changeType); - - return event; - } -} - diff --git a/shenyu-sync-data-center/shenyu-sync-data-apollo/src/test/java/org/apache/shenyu/sync/data/apollo/config/ApolloConfigTest.java b/shenyu-sync-data-center/shenyu-sync-data-apollo/src/test/java/org/apache/shenyu/sync/data/apollo/config/ApolloConfigTest.java deleted file mode 100644 index f98066238b7c..000000000000 --- a/shenyu-sync-data-center/shenyu-sync-data-apollo/src/test/java/org/apache/shenyu/sync/data/apollo/config/ApolloConfigTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.shenyu.sync.data.apollo.config; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class ApolloConfigTest { - - /** - * Methods under test. - * - *
    - *
  • default or parameterless constructor of {@link ApolloConfig} - *
  • {@link ApolloConfig#setAccessKey(String)} - *
  • {@link ApolloConfig#setAppId(String)} - *
  • {@link ApolloConfig#setClusterName(String)} - *
  • {@link ApolloConfig#setEnv(String)} - *
  • {@link ApolloConfig#setMeta(String)} - *
  • {@link ApolloConfig#setNamespace(String)} - *
  • {@link ApolloConfig#getAccessKey()} - *
  • {@link ApolloConfig#getAppId()} - *
  • {@link ApolloConfig#getClusterName()} - *
  • {@link ApolloConfig#getEnv()} - *
  • {@link ApolloConfig#getMeta()} - *
  • {@link ApolloConfig#getNamespace()} - *
- */ - @Test - public void testConstructor() { - ApolloConfig actualApolloConfig = new ApolloConfig(); - actualApolloConfig.setAccessKey("EXAMPLEakiAIOSFODNN7"); - actualApolloConfig.setAppId("42"); - actualApolloConfig.setClusterName("Cluster Name"); - actualApolloConfig.setEnv("Env"); - actualApolloConfig.setMeta("Meta"); - actualApolloConfig.setNamespace("Namespace"); - assertEquals("EXAMPLEakiAIOSFODNN7", actualApolloConfig.getAccessKey()); - assertEquals("42", actualApolloConfig.getAppId()); - assertEquals("Cluster Name", actualApolloConfig.getClusterName()); - assertEquals("Env", actualApolloConfig.getEnv()); - assertEquals("Meta", actualApolloConfig.getMeta()); - assertEquals("Namespace", actualApolloConfig.getNamespace()); - } -} - From cf88b9e82ac0d8062d3df3784fbf6e20a9b63f1b Mon Sep 17 00:00:00 2001 From: yangjj-iso <3202137046@qq.com> Date: Fri, 16 Oct 2026 14:47:40 +0800 Subject: [PATCH 03/11] 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 15459b6032803fc4f82065a729a982a3b9b15a1f Mon Sep 17 00:00:00 2001 From: yangjj-iso <3202137046@qq.com> Date: Fri, 16 Oct 2026 18:48:29 +0800 Subject: [PATCH 04/11] 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 e8ba9a9305c52df3ee6ddb4e89310f55ea354822 Mon Sep 17 00:00:00 2001 From: yangjj-iso <3202137046@qq.com> Date: Fri, 16 Oct 2026 18:51:38 +0800 Subject: [PATCH 05/11] 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 1933e9eb1f3698379e8262e562442e02694a19ab 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/11] 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 4474dd2f0df6cdd03222fa0b181fb39ba556c146 Mon Sep 17 00:00:00 2001 From: yangjj-iso <3202137046@qq.com> Date: Fri, 16 Oct 2026 19:09:40 +0800 Subject: [PATCH 07/11] 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 4812c2b205c205711231327557ab892ca35b7ebd 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/11] 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 d2e5f8dafa80a13b6c123529f915736542d6ee9e Mon Sep 17 00:00:00 2001 From: yangjj-iso <3202137046@qq.com> Date: Fri, 16 Oct 2026 19:16:24 +0800 Subject: [PATCH 09/11] ci: retry transient Maven Central dependency download From 18fd0b095967a7da0d2ea1758481730d69fb61e1 Mon Sep 17 00:00:00 2001 From: yangjj-iso <3202137046@qq.com> Date: Thu, 22 Oct 2026 09:32:11 +0800 Subject: [PATCH 10/11] test(ci): align cryptor failures and wait for usable SDK routes --- ...okeeperClientDiscoveryIntegrationTest.java | 12 ++++++++- .../CryptorResponsePluginTest.java | 26 ++++++++++++------- .../test/sdk/http/SdkHttpIntegratedTest.java | 19 ++++++++++++++ 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/discovery/ZookeeperClientDiscoveryIntegrationTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/discovery/ZookeeperClientDiscoveryIntegrationTest.java index 09e28e54a78b..830dac7a74c7 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/discovery/ZookeeperClientDiscoveryIntegrationTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/discovery/ZookeeperClientDiscoveryIntegrationTest.java @@ -41,6 +41,8 @@ import org.springframework.test.context.TestPropertySource; import java.io.InputStream; +import java.io.IOException; +import java.net.ServerSocket; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; @@ -79,6 +81,8 @@ public class ZookeeperClientDiscoveryIntegrationTest extends AbstractSpringInteg private final List clients = new CopyOnWriteArrayList<>(); + private final List backends = new CopyOnWriteArrayList<>(); + private final List snapshots = new CopyOnWriteArrayList<>(); private final HttpClient httpClient = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).build(); @@ -86,11 +90,14 @@ public class ZookeeperClientDiscoveryIntegrationTest extends AbstractSpringInteg private WebSocket websocket; @AfterEach - public void cleanup() { + public void cleanup() throws IOException { if (Objects.nonNull(websocket)) { websocket.abort(); } clients.forEach(this::stopInstance); + for (ServerSocket backend : backends) { + backend.close(); + } List discoveries = registeredDiscoveries(); discoveries.forEach(discovery -> processorHolder.chooseProcessor("zookeeper").removeDiscovery(discovery)); jdbcTemplate.update("DELETE FROM discovery_upstream WHERE discovery_handler_id IN " @@ -172,6 +179,9 @@ public CompletionStage onText(final WebSocket socket, final CharSequence data } private ShenyuInstanceRegisterRepository startInstance(final TestingServer server, final String app, final int port) throws Exception { + // The Admin health checker remains active while testing registry removal. + // Keep registered backends reachable so health eviction cannot replace that event. + backends.add(new ServerSocket(port)); String appName = "zk-6525-" + app; Properties properties = new Properties(); properties.setProperty("name", appName); diff --git a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/CryptorResponsePluginTest.java b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/CryptorResponsePluginTest.java index 75c6c28a06e5..bb426f7002c1 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/CryptorResponsePluginTest.java +++ b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/CryptorResponsePluginTest.java @@ -21,6 +21,7 @@ import com.google.gson.JsonObject; import org.apache.shenyu.common.dto.ConditionData; import org.apache.shenyu.common.enums.PluginEnum; +import org.apache.shenyu.common.utils.GsonUtils; import org.apache.shenyu.integratedtest.common.AbstractPluginDataInit; import org.apache.shenyu.integratedtest.common.dto.AdminResponse; import org.apache.shenyu.integratedtest.common.dto.UserDTO; @@ -49,6 +50,8 @@ import static org.apache.shenyu.plugin.cryptor.strategy.MapTypeEnum.FIELD; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.containsString; public class CryptorResponsePluginTest extends AbstractPluginDataInit { @@ -118,17 +121,20 @@ public void testWhenRuleHandleIsNull() throws Exception { } - @Test - @DisplayName("return original message when request doesnt exist filed") - public void testWhenDoesntExistFiled() throws Exception { + @ParameterizedTest + @ValueSource(strings = {"decrypt", "encrypt"}) + @DisplayName("reject a response missing the configured field") + public void testWhenConfiguredFieldDoesNotExist(final String way) throws Exception { initSelectorAndRules(PluginEnum.CRYPTOR_RESPONSE.getName(), - "", SINGLETON_CONDITION_LIST, buildRuleLocalDataList("data", "decrypt", FIELD.getMapType())); - - UserDTO actualUser = HttpHelper.INSTANCE.postGateway(TEST_PATH, originalBody, UserDTO.class); - - assertThat(actualUser.getUserId(), is(originalBody.getUserId())); - assertThat(actualUser.getUserName(), is(originalBody.getUserName())); - + "", SINGLETON_CONDITION_LIST, buildRuleLocalDataList("data", way, FIELD.getMapType())); + + String body = HttpHelper.INSTANCE.postGateway(TEST_PATH, originalBody, String.class); + AdminResponse response = GsonUtils.getInstance().fromJson(body, AdminResponse.class); + ShenyuResultEnum error = ShenyuResultEnum.CRYPTOR_RESPONSE_ERROR_CONFIGURATION; + assertThat(response.getCode(), is(error.getCode())); + assertThat(response.getMessage(), is(error.getMsg() + "[fieldNames]")); + assertThat(body, not(containsString(TEST_USER_ID))); + assertThat(body, not(containsString(TEST_USER_NAME))); } @DisplayName("return failed message when decrypt or encrypt failed") diff --git a/shenyu-integrated-test/shenyu-integrated-test-sdk-http/src/test/java/org/apache/shenyu/integrated/test/sdk/http/SdkHttpIntegratedTest.java b/shenyu-integrated-test/shenyu-integrated-test-sdk-http/src/test/java/org/apache/shenyu/integrated/test/sdk/http/SdkHttpIntegratedTest.java index e30e1a03e9ed..01bb356fc76a 100644 --- a/shenyu-integrated-test/shenyu-integrated-test-sdk-http/src/test/java/org/apache/shenyu/integrated/test/sdk/http/SdkHttpIntegratedTest.java +++ b/shenyu-integrated-test/shenyu-integrated-test-sdk-http/src/test/java/org/apache/shenyu/integrated/test/sdk/http/SdkHttpIntegratedTest.java @@ -21,16 +21,35 @@ import org.apache.shenyu.integrated.test.sdk.http.dto.SdkTestDto; import org.apache.shenyu.integratedtest.common.AbstractPluginDataInit; import org.apache.shenyu.integratedtest.common.helper.HttpHelper; +import org.junit.jupiter.api.BeforeAll; import java.io.IOException; +import java.time.Duration; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.awaitility.Awaitility.await; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; public class SdkHttpIntegratedTest extends AbstractPluginDataInit { + @BeforeAll + public static void awaitRegisteredRoutes() { + contextPortKeys().forEach(arguments -> { + Object[] values = arguments.get(); + await().alias("SDK route registration for " + values[0]).atMost(Duration.ofSeconds(60)) + .ignoreExceptionsMatching(error -> error instanceof IOException) + .pollInterval(Duration.ofMillis(500)).untilAsserted(() -> { + SdkTestDto response = HttpHelper.INSTANCE.getHttpService("http://localhost:" + values[1] + + "/sdk/" + values[0] + "/findById?id=10", null, SdkTestDto.class); + assertNotNull(response); + assertEquals("sdk-currentToken", response.getName()); + }); + }); + } + @ParameterizedTest(name = "{index} => test {0}") @MethodSource("contextPortKeys") public void testFindById(final String context, final String port) throws IOException { From fc40dda8eea3202f2226bf9274624aa19da9119a Mon Sep 17 00:00:00 2001 From: redyyang <3202137046@qq.com> Date: Fri, 6 Nov 2026 04:19:44 -0800 Subject: [PATCH 11/11] test: synchronize asynchronous cleanup and HTTP sync fixture startup --- .../service/ShenyuClusterServiceTest.java | 3 +- .../remote/RemoteResourceNetworkTest.java | 3 +- .../HttpClientPluginConfigurationTest.java | 30 ++++++++++++------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mode/cluster/service/ShenyuClusterServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mode/cluster/service/ShenyuClusterServiceTest.java index f4edbb18398d..e4db6d7af52c 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mode/cluster/service/ShenyuClusterServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mode/cluster/service/ShenyuClusterServiceTest.java @@ -37,6 +37,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import static org.awaitility.Awaitility.await; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -234,7 +235,7 @@ public void testSelectMasterErrorCountTracking() throws Exception { clusterService.start("127.0.0.1", 9195, "/shenyu"); assertTrue(errorsOccurred.await(5, TimeUnit.SECONDS)); - assertTrue(clusterService.getSelectMasterErrorCount() >= 2); + await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> assertTrue(clusterService.getSelectMasterErrorCount() >= 2)); clusterService.shutdown(); } diff --git a/shenyu-plugin/shenyu-plugin-agent-gateway/src/test/java/org/apache/shenyu/plugin/agent/gateway/remote/RemoteResourceNetworkTest.java b/shenyu-plugin/shenyu-plugin-agent-gateway/src/test/java/org/apache/shenyu/plugin/agent/gateway/remote/RemoteResourceNetworkTest.java index 8087c3ba20b5..73ae47ee6bd4 100644 --- a/shenyu-plugin/shenyu-plugin-agent-gateway/src/test/java/org/apache/shenyu/plugin/agent/gateway/remote/RemoteResourceNetworkTest.java +++ b/shenyu-plugin/shenyu-plugin-agent-gateway/src/test/java/org/apache/shenyu/plugin/agent/gateway/remote/RemoteResourceNetworkTest.java @@ -50,6 +50,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import static org.awaitility.Awaitility.await; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -115,7 +116,7 @@ void cancellingAnActualHttpReadDoesNotCancelItsPeer() throws Exception { assertTrue(fixture.started.await(5, TimeUnit.SECONDS)); assertEquals("orders:test://status", client.readResource("test://status").block(WAIT).path("contents").get(0).path("text").asText()); assertTrue(first.cancel(true)); - assertEquals(0, client.pending()); + await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> assertEquals(0, client.pending())); fixture.release.countDown(); assertEquals("orders:test://status/next", client.readResource("test://status/next").block(WAIT).path("contents").get(0).path("text").asText()); } finally { diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-http/src/test/java/org/apache/shenyu/springboot/starter/sync/data/http/HttpClientPluginConfigurationTest.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-http/src/test/java/org/apache/shenyu/springboot/starter/sync/data/http/HttpClientPluginConfigurationTest.java index 528fcc9f9c6f..5feeb5e2fc6f 100644 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-http/src/test/java/org/apache/shenyu/springboot/starter/sync/data/http/HttpClientPluginConfigurationTest.java +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-http/src/test/java/org/apache/shenyu/springboot/starter/sync/data/http/HttpClientPluginConfigurationTest.java @@ -24,7 +24,7 @@ import org.apache.shenyu.sync.data.api.PluginDataSubscriber; import org.apache.shenyu.sync.data.http.HttpSyncDataService; import org.apache.shenyu.sync.data.http.config.HttpConfig; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -32,6 +32,9 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; import wiremock.org.apache.hc.core5.http.ContentType; import wiremock.org.apache.hc.core5.http.HttpHeaders; @@ -61,48 +64,55 @@ }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { - "shenyu.sync.http.url=http://localhost:18848", "shenyu.sync.http.delayTime=3", "shenyu.sync.http.username=admin", "shenyu.sync.http.password=123456", "shenyu.sync.http.connectionTimeout=5", "spring.main.web-application-type=none" }) +@DirtiesContext @EnableAutoConfiguration @MockBean({PluginDataSubscriber.class, ServletWebServerFactory.class, ShenyuConfig.class}) public final class HttpClientPluginConfigurationTest { + private static final WireMockServer WIRE_MOCK_SERVER = new WireMockServer(options().dynamicPort()); + @Autowired private HttpConfig httpConfig; @Autowired private HttpSyncDataService httpSyncDataService; - @BeforeAll - public static void setUpWireMock() throws Exception { - WireMockServer wireMockServer = new WireMockServer(options().port(18848)); + @DynamicPropertySource + public static void setUpWireMock(final DynamicPropertyRegistry registry) throws Exception { - wireMockServer.stubFor(post(urlPathEqualTo("/platform/login")) + WIRE_MOCK_SERVER.stubFor(post(urlPathEqualTo("/platform/login")) .willReturn(aResponse() .withHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()) .withBody(mockLoginResponseJson()) .withStatus(200)) ); - wireMockServer.stubFor(get(urlPathEqualTo("/configs/fetch")) + WIRE_MOCK_SERVER.stubFor(get(urlPathEqualTo("/configs/fetch")) .willReturn(aResponse() .withHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()) .withBody(mockConfigsFetchResponseJson()) .withStatus(200)) ); - wireMockServer.stubFor(post(urlPathEqualTo("/configs/listener")) + WIRE_MOCK_SERVER.stubFor(post(urlPathEqualTo("/configs/listener")) .willReturn(aResponse() .withHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()) .withBody(mockConfigsListenResponseJson()) .withStatus(200)) ); - wireMockServer.start(); + WIRE_MOCK_SERVER.start(); + registry.add("shenyu.sync.http.url", WIRE_MOCK_SERVER::baseUrl); + } + + @AfterAll + public static void stopWireMock() { + WIRE_MOCK_SERVER.stop(); } @Test @@ -112,7 +122,7 @@ public void testHttpSyncDataService() { @Test public void testHttpConfig() { - assertThat(httpConfig.getUrl(), is("http://localhost:18848")); + assertThat(httpConfig.getUrl(), is(WIRE_MOCK_SERVER.baseUrl())); assertThat(httpConfig.getDelayTime(), is(3)); assertThat(httpConfig.getConnectionTimeout(), is(5)); }