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 408278893cd9..d5da9a8f21ed 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 393a0bb1c4d0..84a968bc8edc 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -2,6 +2,11 @@ ### API Changes +- The planned later Apollo cutover retains the `apollo` type, stored keys and + `ApolloPathConstants` compatibility shim (#7599). It must not merge in the + deprecation release; the preceding released cycle and external publication + remain required. See [the migration guide](docs/plugin-store-apollo.md). + - WASM loaders support opt-in startup execution deadlines and per-instance linear-memory ceilings. Defaults remain disabled. Timed execution owns bounded workers, propagates interruption and replaces interrupted instances after physical exit. See diff --git a/docs/plugin-store-apollo.md b/docs/plugin-store-apollo.md index 1c6bd65baeb2..79b8056f9da6 100644 --- a/docs/plugin-store-apollo.md +++ b/docs/plugin-store-apollo.md @@ -18,12 +18,13 @@ 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 removal PR is a draft and must not be merged in that deprecation release. +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 can be reviewed in advance and must not be merged in that deprecation release. | Stage | Required action | | --- | --- | diff --git a/pom.xml b/pom.xml index 02b102a0a168..db5b9ae329c4 100644 --- a/pom.xml +++ b/pom.xml @@ -202,7 +202,6 @@ 2.9.3 4.1.5 9.2 - 2.1.0 1.7.1 1.8.3 6.1.2.RELEASE @@ -429,18 +428,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 0ff72ea20c7f..5330a3997004 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 1fe47c641b22..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.3-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 2e1efce2a5b6..c06324214400 100755 --- a/shenyu-admin/src/main/resources/application.yml +++ b/shenyu-admin/src/main/resources/application.yml @@ -89,14 +89,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 9565990b4fd0..990b4e8f38df 100644 --- a/shenyu-bootstrap/src/main/resources/application.yml +++ b/shenyu-bootstrap/src/main/resources/application.yml @@ -244,12 +244,6 @@ shenyu: trusted-master-hosts: # Explicitly allow a wss connection to follow a plaintext ws advertised master. allow-insecure-master-redirect: false -# apollo: -# appId: shenyu -# meta: http://localhost:8080 -# env: dev -# clusterName: test -# namespace: application # zookeeper: # url: localhost:2181 # sessionTimeoutMilliseconds: 5000 diff --git a/shenyu-integrated-test/shenyu-integrated-test-k8s-ingress-apache-dubbo/src/main/resources/application.yml b/shenyu-integrated-test/shenyu-integrated-test-k8s-ingress-apache-dubbo/src/main/resources/application.yml index 6786c934de68..0e30ea29fad9 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 6786c934de68..0e30ea29fad9 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 6786c934de68..0e30ea29fad9 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 @@ -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-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-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 edaf5ce05294..8c2965f41951 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 1359ef8f3028..000000000000 --- a/shenyu-registry/shenyu-registry-apollo/pom.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - org.apache.shenyu - shenyu-registry - 2.7.3-SNAPSHOT - - 4.0.0 - shenyu-registry-apollo - - - - com.google.guava - guava - - - - 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 98d9bbc0b15d..39984b2fa601 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 @@ -33,7 +33,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 40ff9d51afc3..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.3-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-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)); } diff --git a/shenyu-sync-data-center/pom.xml b/shenyu-sync-data-center/pom.xml index 361a29aa5404..86be155bff03 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 b4d7da0243ca..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.3-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 6a4fe8f53864..000000000000 --- a/shenyu-sync-data-center/shenyu-sync-data-apollo/src/main/java/org/apache/shenyu/sync/data/apollo/ApolloDataService.java +++ /dev/null @@ -1,174 +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 list index keys. - if (changeKey.endsWith(DefaultNodeConstants.POINT_LIST)) { - 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 9c54483b6eaf..000000000000 --- a/shenyu-sync-data-center/shenyu-sync-data-apollo/src/test/java/org/apache/shenyu/sync/data/apollo/ApolloDataServiceTest.java +++ /dev/null @@ -1,460 +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.AppAuthData; -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.common.dto.SelectorData; -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.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; -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()); - } - - @ParameterizedTest - @EnumSource(PropertyChangeType.class) - void testPluginDataKeyEndingWithList(final PropertyChangeType changeType) { - createApolloDataService(); - - final ConfigChangeEvent event = mockConfigChangeEvent( - NAMESPACE + "." + ApolloPathConstants.PLUGIN_DATA_ID + ".blacklist", - PropertyChangeType.DELETED.equals(changeType) ? null : "{\"name\":\"blacklist\"}", - changeType - ); - - capturedListener.onChange(event); - final ArgumentCaptor captor = ArgumentCaptor.forClass(PluginData.class); - if (PropertyChangeType.DELETED.equals(changeType)) { - verify(pluginDataSubscriber).unSubscribe(captor.capture()); - } else { - verify(pluginDataSubscriber).onSubscribe(captor.capture()); - } - assertEquals("blacklist", 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()); - } - - @ParameterizedTest - @EnumSource(PropertyChangeType.class) - void testSelectorDataKeyEndingWithList(final PropertyChangeType changeType) { - createApolloDataService(); - - final ConfigChangeEvent event = mockConfigChangeEvent( - NAMESPACE + "." + ApolloPathConstants.SELECTOR_DATA_ID + ".test-plugin.selector-whitelist", - PropertyChangeType.DELETED.equals(changeType) ? null : "{\"id\":\"selector-whitelist\",\"pluginName\":\"test-plugin\"}", - changeType - ); - - capturedListener.onChange(event); - final ArgumentCaptor captor = ArgumentCaptor.forClass(SelectorData.class); - if (PropertyChangeType.DELETED.equals(changeType)) { - verify(pluginDataSubscriber).unSelectorSubscribe(captor.capture()); - } else { - verify(pluginDataSubscriber).onSelectorSubscribe(captor.capture()); - } - assertEquals("selector-whitelist", captor.getValue().getId()); - assertEquals("test-plugin", captor.getValue().getPluginName()); - } - - @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()); - } - - @ParameterizedTest - @EnumSource(PropertyChangeType.class) - void testAuthDataKeyEndingWithList(final PropertyChangeType changeType) { - createApolloDataService(); - - final ConfigChangeEvent event = mockConfigChangeEvent( - NAMESPACE + "." + ApolloPathConstants.AUTH_DATA_ID + ".whitelist", - PropertyChangeType.DELETED.equals(changeType) ? null : "{\"appKey\":\"whitelist\"}", - changeType - ); - - capturedListener.onChange(event); - final ArgumentCaptor captor = ArgumentCaptor.forClass(AppAuthData.class); - if (PropertyChangeType.DELETED.equals(changeType)) { - verify(authDataSubscriber).unSubscribe(captor.capture()); - } else { - verify(authDataSubscriber).onSubscribe(captor.capture()); - } - assertEquals("whitelist", captor.getValue().getAppKey()); - } - - @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.selector-id", - 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("selector-id", captor.getValue().getId()); - } - - @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()); - } - - @ParameterizedTest - @EnumSource(PropertyChangeType.class) - void testListKeySkipped(final PropertyChangeType changeType) { - ApolloDataService apolloDataService = createApolloDataService(); - - ConfigChangeEvent event = mockConfigChangeEvent( - NAMESPACE + "." + ApolloPathConstants.PLUGIN_DATA_ID + ".list", - "[\"test-plugin\"]", - changeType - ); - - 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()); - } -} -