This is an automated email from the ASF dual-hosted git repository.
Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 16e8d79183 refactor: externalize Polaris to plugin store (#7509)
16e8d79183 is described below
commit 16e8d7918354ac50195b8ac0b175886df415fbf0
Author: cloudbase-ai <[email protected]>
AuthorDate: Fri Oct 9 13:30:55 2026 +0800
refactor: externalize Polaris to plugin store (#7509)
Signed-off-by: cloudbase-ai <[email protected]>
Co-authored-by: cloudbase-ai
<[email protected]>
---
README.md | 2 +-
docs/polaris-plugin-store-migration.md | 53 +++
pom.xml | 7 -
shenyu-admin-listener/pom.xml | 1 -
.../shenyu-admin-listener-polaris/pom.xml | 47 --
.../admin/config/PolarisSyncConfiguration.java | 101 ----
.../admin/config/properties/PolarisProperties.java | 89 ----
.../listener/polaris/PolarisDataChangedInit.java | 71 ---
.../polaris/PolarisDataChangedListener.java | 100 ----
.../src/main/resources/META-INF/spring.factories | 19 -
.../src/main/resources/META-INF/spring.provides | 18 -
...rk.boot.autoconfigure.AutoConfiguration.imports | 18 -
.../admin/config/PolarisSyncConfigurationTest.java | 56 ---
.../config/properties/PolarisPropertiesTest.java | 38 --
.../polaris/PolarisDataChangedInitTest.java | 81 ----
.../polaris/PolarisDataChangedListenerTest.java | 168 -------
shenyu-admin/pom.xml | 6 -
shenyu-admin/src/main/resources/application.yml | 5 -
shenyu-bootstrap/pom.xml | 7 -
.../src/main/resources/application.yml | 4 -
.../src/main/release-docs/LICENSE | 1 -
.../src/main/release-docs/LICENSE | 1 -
shenyu-registry/pom.xml | 1 -
shenyu-registry/shenyu-registry-core/pom.xml | 5 -
shenyu-registry/shenyu-registry-polaris/pom.xml | 40 --
.../polaris/PolarisInstanceRegisterRepository.java | 146 ------
...u.registry.api.ShenyuInstanceRegisterRepository | 17 -
.../PolarisInstanceRegisterRepositoryTest.java | 120 -----
.../pom.xml | 1 -
.../pom.xml | 45 --
.../data/polaris/PolarisSyncDataConfiguration.java | 107 -----
...rk.boot.autoconfigure.AutoConfiguration.imports | 18 -
.../polaris/PolarisSyncDataConfigurationTest.java | 77 ----
shenyu-sync-data-center/pom.xml | 1 -
.../shenyu-sync-data-polaris/pom.xml | 41 --
.../sync/data/polaris/PolarisSyncDataService.java | 122 -----
.../sync/data/polaris/config/PolarisConfig.java | 84 ----
.../data/polaris/PolarisSyncDataServiceTest.java | 506 ---------------------
.../data/polaris/config/PolarisConfigTest.java | 59 ---
.../polaris/handler/PolarisMockConfigFile.java | 203 ---------
.../polaris/handler/PolarisMockConfigService.java | 111 -----
41 files changed, 54 insertions(+), 2543 deletions(-)
diff --git a/README.md b/README.md
index d5cfbbc3ab..6555713e26 100644
--- a/README.md
+++ b/README.md
@@ -38,7 +38,7 @@ Apache ShenYu is a Java-based gateway for service proxying,
protocol conversion,
| Registration and discovery | Client SDKs register service addresses and API
metadata with Admin. Registry integrations support discovery; an optional
Kubernetes controller reconciles Ingress and Endpoints resources. |
| Security and traffic control | WAF, signing, authentication plugins, load
balancing, rate limiting, and fault tolerance through Resilience4j and
Sentinel; deprecated Hystrix remains available as an external plugin (see
[plugin-store-hystrix](docs/plugin-store-hystrix.md)). |
| Caching and transformation | In-memory or Redis-backed response caching, URL
rewriting, redirection, and request/response transformation. |
-| Dynamic configuration | Admin persists plugins, selectors, rules, metadata,
and authentication data. WebSocket sync is the default; HTTP long polling,
ZooKeeper, Nacos, etcd, Consul, Apollo, and Polaris are available. 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, etcd, Consul, and Apollo are available. Gateway replicas
apply updates to their local caches. |
| Observability | Metrics and logging plugins, including Kafka, Pulsar,
Elasticsearch, and ClickHouse destinations; email and DingTalk alerts from
Admin. |
| AI and MCP | AI proxy, prompt processing, token limits, sensitive-word
filtering, AI request/response transformation, and an MCP server plugin with
SSE and Streamable HTTP. |
diff --git a/docs/polaris-plugin-store-migration.md
b/docs/polaris-plugin-store-migration.md
new file mode 100644
index 0000000000..d80dc8548b
--- /dev/null
+++ b/docs/polaris-plugin-store-migration.md
@@ -0,0 +1,53 @@
+<!--
+ 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.
+-->
+
+# Draft: Polaris Plugin Store Migration and Rollback
+
+This draft records the root-repository handoff for the Polaris plugin-store
extension. Root publishing and aggregator wiring remain separate review steps.
+
+The plugin store owns these Polaris artifacts:
+
+- `shenyu-admin-listener-polaris`
+- `shenyu-sync-data-polaris`
+- `shenyu-registry-polaris`
+- `shenyu-spring-boot-starter-sync-data-polaris`
+
+The validated store lane targets ShenYu API artifacts `2.7.2-SNAPSHOT` and
Polaris SDK `1.13.0`. Real-server tests use Docker API `1.44` (selected with
`-Dapi.version=1.44`) and the pinned Polaris standalone image
`polarismesh/polaris-standalone@sha256:22c75382080a260e5d9fc9839b6657ae73f3154e308b8da881e1fab58653911c`.
+
+## Migration draft
+
+1. Review and publish the plugin-store Polaris artifacts.
+2. Wire the root aggregator, dependency management, and CI paths only after
store artifact ownership is approved.
+3. Add the Polaris sync starter to gateways that should consume Polaris-backed
sync data.
+4. Configure admin listener and gateway sync settings with the same Polaris
config namespace and file group.
+5. Configure registry clients with the Polaris naming gRPC address when
Polaris instance discovery is required.
+6. Roll admin listener changes before gateway consumers so config files exist
before gateways subscribe.
+
+## Rollback draft
+
+1. Stop Polaris listener writes and restore the previous admin sync channel.
+2. Roll gateways back to the previous sync-data starter and settings.
+3. Roll registry clients back to the previous registry implementation.
+4. Keep Polaris config and naming state until no clients depend on it, then
clean it up operationally.
+
+## Tested boundary
+
+The store real-server tests prove the config path from
`PolarisDataChangedListener` through the real Polaris config SDK into
`PolarisSyncDataService`, `BaseDataCache`, and a real `ShenyuWebHandler` test
server. They cover create, update, delete, recreate, close, and
fresh-subscriber recovery.
+
+The registry real-server test proves `PolarisInstanceRegisterRepository` can
register and query an instance against a real Polaris naming server, deregister
that instance through the Polaris SDK boundary, observe removal through a fresh
repository query, and close clients.
+
+The tests do not start the full `shenyu-admin` Spring Boot app, do not cover
dashboard or database persistence, and do not cover client annotation
registration flows.
diff --git a/pom.xml b/pom.xml
index 8129d32bcd..80f5f3af80 100644
--- a/pom.xml
+++ b/pom.xml
@@ -161,7 +161,6 @@
<eureka.version>2.0.2</eureka.version>
<javatuples.version>1.2</javatuples.version>
<k8s-client.version>17.0.2</k8s-client.version>
- <polaris.version>1.13.0</polaris.version>
<bytebuddy.version>1.14.11</bytebuddy.version>
<spring-ldap.version>2.3.4.RELEASE</spring-ldap.version>
<jaxb.api.version>2.3.1</jaxb.api.version>
@@ -384,12 +383,6 @@
<version>${apollo.version}</version>
</dependency>
- <dependency>
- <groupId>com.tencent.polaris</groupId>
- <artifactId>polaris-all</artifactId>
- <version>${polaris.version}</version>
- </dependency>
-
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
diff --git a/shenyu-admin-listener/pom.xml b/shenyu-admin-listener/pom.xml
index b19960ebba..2d7db97b3d 100644
--- a/shenyu-admin-listener/pom.xml
+++ b/shenyu-admin-listener/pom.xml
@@ -33,7 +33,6 @@
<module>shenyu-admin-listener-consul</module>
<module>shenyu-admin-listener-etcd</module>
<module>shenyu-admin-listener-nacos</module>
- <module>shenyu-admin-listener-polaris</module>
<module>shenyu-admin-listener-zookeeper</module>
</modules>
diff --git a/shenyu-admin-listener/shenyu-admin-listener-polaris/pom.xml
b/shenyu-admin-listener/shenyu-admin-listener-polaris/pom.xml
deleted file mode 100644
index 4dfecc84ec..0000000000
--- a/shenyu-admin-listener/shenyu-admin-listener-polaris/pom.xml
+++ /dev/null
@@ -1,47 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.shenyu</groupId>
- <artifactId>shenyu-admin-listener</artifactId>
- <version>2.7.2-SNAPSHOT</version>
- </parent>
-
- <artifactId>shenyu-admin-listener-polaris</artifactId>
-
- <dependencies>
- <dependency>
- <groupId>com.tencent.polaris</groupId>
- <artifactId>polaris-all</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.shenyu</groupId>
- <artifactId>shenyu-admin-listener-api</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- <scope>provided</scope>
- </dependency>
- </dependencies>
-</project>
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-polaris/src/main/java/org/apache/shenyu/admin/config/PolarisSyncConfiguration.java
b/shenyu-admin-listener/shenyu-admin-listener-polaris/src/main/java/org/apache/shenyu/admin/config/PolarisSyncConfiguration.java
deleted file mode 100644
index 4d97d024ef..0000000000
---
a/shenyu-admin-listener/shenyu-admin-listener-polaris/src/main/java/org/apache/shenyu/admin/config/PolarisSyncConfiguration.java
+++ /dev/null
@@ -1,101 +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 com.tencent.polaris.configuration.api.core.ConfigFilePublishService;
-import com.tencent.polaris.configuration.api.core.ConfigFileService;
-import com.tencent.polaris.configuration.factory.ConfigFileServiceFactory;
-import
com.tencent.polaris.configuration.factory.ConfigFileServicePublishFactory;
-import com.tencent.polaris.factory.ConfigAPIFactory;
-import org.apache.shenyu.admin.config.properties.PolarisProperties;
-import org.apache.shenyu.admin.listener.DataChangedInit;
-import org.apache.shenyu.admin.listener.DataChangedListener;
-import org.apache.shenyu.admin.listener.polaris.PolarisDataChangedInit;
-import org.apache.shenyu.admin.listener.polaris.PolarisDataChangedListener;
-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;
-
-import java.util.Collections;
-
-/**
- * The type Polaris listener.
- */
-@Configuration
-@ConditionalOnProperty(prefix = "shenyu.sync.polaris", name = "url")
-@EnableConfigurationProperties(PolarisProperties.class)
-public class PolarisSyncConfiguration {
-
- /**
- * register configFileService in spring ioc.
- *
- * @param polarisProperties polarisProperties
- * @return ConfigFileService {@linkplain ConfigFileService}
- */
- @Bean
- @ConditionalOnMissingBean(ConfigFileService.class)
- public ConfigFileService polarisConfigFileService(final PolarisProperties
polarisProperties) {
- com.tencent.polaris.api.config.Configuration configuration =
ConfigAPIFactory.defaultConfig();
-
configuration.getConfigFile().getServerConnector().setAddresses(Collections.singletonList(polarisProperties.getUrl()));
- return ConfigFileServiceFactory.createConfigFileService(configuration);
- }
-
- /**
- * register configFilePublishService in spring ioc.
- *
- * @param polarisProperties polarisProperties
- * @return ConfigFilePublishService {@linkplain ConfigFilePublishService}
- */
- @Bean
- @ConditionalOnMissingBean(ConfigFilePublishService.class)
- public ConfigFilePublishService polarisConfigFilePublishService(final
PolarisProperties polarisProperties) {
- com.tencent.polaris.api.config.Configuration configuration =
ConfigAPIFactory.defaultConfig();
-
configuration.getConfigFile().getServerConnector().setAddresses(Collections.singletonList(polarisProperties.getUrl()));
- return
ConfigFileServicePublishFactory.createConfigFilePublishService(configuration);
- }
-
- /**
- * Data changed listener data changed listener.
- *
- * @param polarisProperties polarisProperties
- * @param configFilePublishService configFilePublishService
- * @param configFileService the config service
- * @return the data changed listener
- */
- @Bean
- @ConditionalOnMissingBean(PolarisDataChangedListener.class)
- public DataChangedListener polarisDataChangedListener(final
PolarisProperties polarisProperties, final ConfigFileService configFileService,
- final
ConfigFilePublishService configFilePublishService) {
- return new PolarisDataChangedListener(polarisProperties,
configFileService, configFilePublishService);
- }
-
- /**
- * Polaris data init polaris data init.
- *
- * @param polarisProperties polarisProperties
- * @param configFileService the config service
- * @return the polaris data init
- */
- @Bean
- @ConditionalOnMissingBean(PolarisDataChangedInit.class)
- public DataChangedInit polarisDataChangedInit(final PolarisProperties
polarisProperties, final ConfigFileService configFileService) {
- return new PolarisDataChangedInit(polarisProperties,
configFileService);
- }
-}
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-polaris/src/main/java/org/apache/shenyu/admin/config/properties/PolarisProperties.java
b/shenyu-admin-listener/shenyu-admin-listener-polaris/src/main/java/org/apache/shenyu/admin/config/properties/PolarisProperties.java
deleted file mode 100644
index 9f0e1300c0..0000000000
---
a/shenyu-admin-listener/shenyu-admin-listener-polaris/src/main/java/org/apache/shenyu/admin/config/properties/PolarisProperties.java
+++ /dev/null
@@ -1,89 +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.apache.commons.lang3.StringUtils;
-import org.apache.shenyu.common.constant.PolarisPathConstants;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-/**
- * The type Polaris config.
- */
-@ConfigurationProperties(prefix = "shenyu.sync.polaris")
-public class PolarisProperties {
-
- private String url;
-
- private String namespace;
-
- private String fileGroup;
-
- /**
- * Gets the value of url.
- *
- * @return the value of url
- */
- public String getUrl() {
- return url;
- }
-
- /**
- * Sets the url.
- *
- * @param url url
- */
- public void setUrl(final String url) {
- this.url = url;
- }
-
- /**
- * Gets the value of namespace.
- *
- * @return the value of namespace
- */
- public String getNamespace() {
- return namespace;
- }
-
- /**
- * Sets the namespace.
- *
- * @param namespace namespace
- */
- public void setNamespace(final String namespace) {
- this.namespace = StringUtils.isNotBlank(namespace) ? namespace :
PolarisPathConstants.NAMESPACE;
- }
-
- /**
- * Gets the value of fileGroup.
- *
- * @return the value of fileGroup.
- */
- public String getFileGroup() {
- return fileGroup;
- }
-
- /**
- * Sets the value of fileGroup.
- *
- * @param fileGroup fileGroup
- */
- public void setFileGroup(final String fileGroup) {
- this.fileGroup = StringUtils.isNotBlank(fileGroup) ? fileGroup :
PolarisPathConstants.FILE_GROUP;
- }
-}
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-polaris/src/main/java/org/apache/shenyu/admin/listener/polaris/PolarisDataChangedInit.java
b/shenyu-admin-listener/shenyu-admin-listener-polaris/src/main/java/org/apache/shenyu/admin/listener/polaris/PolarisDataChangedInit.java
deleted file mode 100644
index f3b5225d2f..0000000000
---
a/shenyu-admin-listener/shenyu-admin-listener-polaris/src/main/java/org/apache/shenyu/admin/listener/polaris/PolarisDataChangedInit.java
+++ /dev/null
@@ -1,71 +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.polaris;
-
-import com.tencent.polaris.api.exception.PolarisException;
-import com.tencent.polaris.configuration.api.core.ConfigFileService;
-import org.apache.shenyu.admin.config.properties.PolarisProperties;
-import org.apache.shenyu.admin.listener.AbstractDataChangedInit;
-import org.apache.shenyu.common.constant.PolarisPathConstants;
-import org.apache.shenyu.common.exception.ShenyuException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.stream.Stream;
-
-/**
- * The type Polaris data changed init.
- */
-public class PolarisDataChangedInit extends AbstractDataChangedInit {
-
- private static final Logger LOG =
LoggerFactory.getLogger(PolarisDataChangedInit.class);
-
- private final PolarisProperties polarisProperties;
-
- private final ConfigFileService configFileService;
-
- /**
- * Instantiates a new Polaris data changed init.
- *
- * @param polarisProperties polarisProperties
- * @param configFileService the configFileService
- */
- public PolarisDataChangedInit(final PolarisProperties polarisProperties,
final ConfigFileService configFileService) {
- this.polarisProperties = polarisProperties;
- this.configFileService = configFileService;
- }
-
- @Override
- protected boolean notExist() {
- return Stream.of(PolarisPathConstants.PLUGIN_DATA_FILE_NAME,
PolarisPathConstants.AUTH_DATA_ID_FILE_NAME,
- PolarisPathConstants.META_DATA_FILE_NAME,
PolarisPathConstants.PROXY_SELECTOR_FILE_NAME).allMatch(
- this::dataIdNotExist);
- }
-
- private boolean dataIdNotExist(final String pluginDataId) {
- try {
- return !configFileService.getConfigFile(
- polarisProperties.getNamespace(),
- polarisProperties.getFileGroup(),
- pluginDataId).hasContent();
- } catch (PolarisException e) {
- LOG.error("Get data from polaris error.", e);
- throw new ShenyuException(e.getMessage());
- }
- }
-}
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-polaris/src/main/java/org/apache/shenyu/admin/listener/polaris/PolarisDataChangedListener.java
b/shenyu-admin-listener/shenyu-admin-listener-polaris/src/main/java/org/apache/shenyu/admin/listener/polaris/PolarisDataChangedListener.java
deleted file mode 100644
index 97a3862277..0000000000
---
a/shenyu-admin-listener/shenyu-admin-listener-polaris/src/main/java/org/apache/shenyu/admin/listener/polaris/PolarisDataChangedListener.java
+++ /dev/null
@@ -1,100 +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.polaris;
-
-import com.tencent.polaris.api.exception.PolarisException;
-import com.tencent.polaris.configuration.api.core.ConfigFile;
-import com.tencent.polaris.configuration.api.core.ConfigFilePublishService;
-import com.tencent.polaris.configuration.api.core.ConfigFileService;
-import
com.tencent.polaris.configuration.client.internal.DefaultConfigFileMetadata;
-import org.apache.shenyu.admin.config.properties.PolarisProperties;
-import org.apache.shenyu.admin.listener.AbstractNodeDataChangedListener;
-import org.apache.shenyu.common.constant.NacosPathConstants;
-import org.apache.shenyu.common.constant.PolarisPathConstants;
-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.Objects;
-
-/**
- * Use polaris to push data changes.
- */
-public class PolarisDataChangedListener extends
AbstractNodeDataChangedListener {
-
- private static final Logger LOG =
LoggerFactory.getLogger(PolarisDataChangedListener.class);
-
- private final PolarisProperties polarisProperties;
-
- private final ConfigFileService configFileService;
-
- private final ConfigFilePublishService configFilePublishService;
-
- public PolarisDataChangedListener(final PolarisProperties
polarisProperties, final ConfigFileService configFileService, final
ConfigFilePublishService configFilePublishService) {
- super(new ChangeData(PolarisPathConstants.PLUGIN_DATA_FILE_NAME,
PolarisPathConstants.SELECTOR_DATA_FILE_NAME,
- PolarisPathConstants.RULE_DATA_FILE_NAME,
PolarisPathConstants.AUTH_DATA_ID_FILE_NAME,
- PolarisPathConstants.META_DATA_FILE_NAME,
PolarisPathConstants.PROXY_SELECTOR_FILE_NAME,
NacosPathConstants.DISCOVERY_DATA_ID));
- this.polarisProperties = polarisProperties;
- this.configFileService = configFileService;
- this.configFilePublishService = configFilePublishService;
- }
-
- @Override
- public void doPublishConfig(final String dataId, final Object data) {
- try {
- DefaultConfigFileMetadata metadata = new DefaultConfigFileMetadata(
- polarisProperties.getNamespace(),
- polarisProperties.getFileGroup(),
- dataId);
- if (isReleased(metadata)) {
- configFilePublishService.updateConfigFile(metadata,
Objects.isNull(data) ? "" : GsonUtils.getInstance().toJson(data));
- } else {
- configFilePublishService.createConfigFile(metadata,
GsonUtils.getInstance().toJson(data));
- }
- configFilePublishService.releaseConfigFile(metadata);
- } catch (PolarisException e) {
- LOG.error("Polaris Publish data to polaris error.", e);
- }
- }
-
- @Override
- public void doDelConfig(final String dataId) {
- doPublishConfig(dataId, null);
- }
-
- @Override
- public String getConfig(final String dataId) {
- try {
- ConfigFile configFile =
configFileService.getConfigFile(polarisProperties.getNamespace(),
polarisProperties.getFileGroup(), dataId);
- return configFile.hasContent() ? configFile.getContent() : null;
- } catch (PolarisException e) {
- LOG.error("Polaris Get data from polaris error.", e);
- throw new ShenyuException(e.getMessage());
- }
- }
-
- private boolean isReleased(final DefaultConfigFileMetadata metadata) {
- try {
- return
Objects.nonNull(configFileService.getConfigFile(metadata).getContent());
- } catch (PolarisException e) {
- LOG.error("Polaris Get data from polaris error.", e);
- throw new ShenyuException(e.getMessage());
- }
- }
-}
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-polaris/src/main/resources/META-INF/spring.factories
b/shenyu-admin-listener/shenyu-admin-listener-polaris/src/main/resources/META-INF/spring.factories
deleted file mode 100644
index 2e71695169..0000000000
---
a/shenyu-admin-listener/shenyu-admin-listener-polaris/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.PolarisSyncConfiguration
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-polaris/src/main/resources/META-INF/spring.provides
b/shenyu-admin-listener/shenyu-admin-listener-polaris/src/main/resources/META-INF/spring.provides
deleted file mode 100644
index 9893ff1dba..0000000000
---
a/shenyu-admin-listener/shenyu-admin-listener-polaris/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-polaris/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
b/shenyu-admin-listener/shenyu-admin-listener-polaris/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
deleted file mode 100644
index 5aa14795d3..0000000000
---
a/shenyu-admin-listener/shenyu-admin-listener-polaris/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.PolarisSyncConfiguration
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-polaris/src/test/java/org/apache/shenyu/admin/config/PolarisSyncConfigurationTest.java
b/shenyu-admin-listener/shenyu-admin-listener-polaris/src/test/java/org/apache/shenyu/admin/config/PolarisSyncConfigurationTest.java
deleted file mode 100644
index 5831f586af..0000000000
---
a/shenyu-admin-listener/shenyu-admin-listener-polaris/src/test/java/org/apache/shenyu/admin/config/PolarisSyncConfigurationTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shenyu.admin.config;
-
-import com.tencent.polaris.configuration.api.core.ConfigFilePublishService;
-import com.tencent.polaris.configuration.api.core.ConfigFileService;
-import org.apache.shenyu.admin.config.properties.PolarisProperties;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.mockito.Mockito.mock;
-
-public class PolarisSyncConfigurationTest {
-
- @Test
- public void testPolarisDataChangedListener() {
- PolarisSyncConfiguration polarisListener = new
PolarisSyncConfiguration();
- PolarisProperties polarisProperties = mock(PolarisProperties.class);
- ConfigFileService polarisConfigFileService =
mock(ConfigFileService.class);
- ConfigFilePublishService polarisConfigFilePublishService =
mock(ConfigFilePublishService.class);
-
assertNotNull(polarisListener.polarisDataChangedListener(polarisProperties,
polarisConfigFileService, polarisConfigFilePublishService));
- }
-
- @Test
- public void testPolarisDataInit() {
- PolarisSyncConfiguration polarisListener = new
PolarisSyncConfiguration();
- PolarisProperties polarisProperties = mock(PolarisProperties.class);
- ConfigFileService polarisConfigFileService =
mock(ConfigFileService.class);
-
assertNotNull(polarisListener.polarisDataChangedInit(polarisProperties,
polarisConfigFileService));
- }
-
- @Test
- public void polarisConfigServiceTest() {
- final PolarisProperties polarisProperties = new PolarisProperties();
- polarisProperties.setUrl("127.0.0.1:8093");
- polarisProperties.setNamespace("namespace");
- PolarisSyncConfiguration polarisListener = new
PolarisSyncConfiguration();
-
assertNotNull(polarisListener.polarisConfigFileService(polarisProperties));
-
assertNotNull(polarisListener.polarisConfigFilePublishService(polarisProperties));
- }
-}
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-polaris/src/test/java/org/apache/shenyu/admin/config/properties/PolarisPropertiesTest.java
b/shenyu-admin-listener/shenyu-admin-listener-polaris/src/test/java/org/apache/shenyu/admin/config/properties/PolarisPropertiesTest.java
deleted file mode 100644
index fc471c84ca..0000000000
---
a/shenyu-admin-listener/shenyu-admin-listener-polaris/src/test/java/org/apache/shenyu/admin/config/properties/PolarisPropertiesTest.java
+++ /dev/null
@@ -1,38 +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.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-/**
- * Test cases for {@link PolarisProperties}.
- */
-public class PolarisPropertiesTest {
-
- @Test
- public void polarisPropertiesTest() {
- final PolarisProperties polarisProperties = new PolarisProperties();
- polarisProperties.setUrl("url");
- polarisProperties.setNamespace("namespace");
- polarisProperties.setFileGroup("fileGroup");
- Assertions.assertEquals(polarisProperties.getUrl(), "url");
- Assertions.assertEquals(polarisProperties.getNamespace(), "namespace");
- Assertions.assertEquals(polarisProperties.getFileGroup(), "fileGroup");
- }
-}
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-polaris/src/test/java/org/apache/shenyu/admin/listener/polaris/PolarisDataChangedInitTest.java
b/shenyu-admin-listener/shenyu-admin-listener-polaris/src/test/java/org/apache/shenyu/admin/listener/polaris/PolarisDataChangedInitTest.java
deleted file mode 100644
index 8b080d248c..0000000000
---
a/shenyu-admin-listener/shenyu-admin-listener-polaris/src/test/java/org/apache/shenyu/admin/listener/polaris/PolarisDataChangedInitTest.java
+++ /dev/null
@@ -1,81 +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.polaris;
-
-import com.tencent.polaris.api.exception.PolarisException;
-import com.tencent.polaris.configuration.api.core.ConfigFile;
-import com.tencent.polaris.configuration.api.core.ConfigFileService;
-import org.apache.shenyu.admin.config.properties.PolarisProperties;
-import org.apache.shenyu.common.constant.PolarisPathConstants;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import static
org.apache.shenyu.common.constant.PolarisPathConstants.AUTH_DATA_ID_FILE_NAME;
-import static
org.apache.shenyu.common.constant.PolarisPathConstants.META_DATA_FILE_NAME;
-import static
org.apache.shenyu.common.constant.PolarisPathConstants.PLUGIN_DATA_FILE_NAME;
-import static
org.apache.shenyu.common.constant.PolarisPathConstants.PROXY_SELECTOR_FILE_NAME;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.when;
-
-/**
- * Test cases for {@link PolarisDataChangedInit}.
- */
-@ExtendWith(MockitoExtension.class)
-public class PolarisDataChangedInitTest {
-
- @Mock
- private ConfigFile configFile;
-
- @Mock
- private PolarisProperties polarisProperties;
-
- @Mock
- private ConfigFileService polarisConfigFileService;
-
- @Test
- public void testNotExist() throws PolarisException {
- PolarisDataChangedInit polarisDataChangedInit = new
PolarisDataChangedInit(polarisProperties, polarisConfigFileService);
-
- when(configFile.hasContent()).thenReturn(true);
-
when(polarisProperties.getNamespace()).thenReturn(PolarisPathConstants.NAMESPACE);
-
when(polarisProperties.getFileGroup()).thenReturn(PolarisPathConstants.FILE_GROUP);
-
-
when(polarisConfigFileService.getConfigFile(PolarisPathConstants.NAMESPACE,
PolarisPathConstants.FILE_GROUP, PLUGIN_DATA_FILE_NAME)).thenReturn(configFile);
- boolean pluginExist = polarisDataChangedInit.notExist();
- assertFalse(pluginExist, "plugin exist.");
- }
-
- @Test
- public void testExist() throws PolarisException {
- PolarisDataChangedInit polarisDataChangedInit = new
PolarisDataChangedInit(polarisProperties, polarisConfigFileService);
-
- when(configFile.hasContent()).thenReturn(false);
-
when(polarisProperties.getNamespace()).thenReturn(PolarisPathConstants.NAMESPACE);
-
when(polarisProperties.getFileGroup()).thenReturn(PolarisPathConstants.FILE_GROUP);
-
-
when(polarisConfigFileService.getConfigFile(PolarisPathConstants.NAMESPACE,
PolarisPathConstants.FILE_GROUP, PLUGIN_DATA_FILE_NAME)).thenReturn(configFile);
-
when(polarisConfigFileService.getConfigFile(PolarisPathConstants.NAMESPACE,
PolarisPathConstants.FILE_GROUP,
AUTH_DATA_ID_FILE_NAME)).thenReturn(configFile);
-
when(polarisConfigFileService.getConfigFile(PolarisPathConstants.NAMESPACE,
PolarisPathConstants.FILE_GROUP,
PROXY_SELECTOR_FILE_NAME)).thenReturn(configFile);
-
when(polarisConfigFileService.getConfigFile(PolarisPathConstants.NAMESPACE,
PolarisPathConstants.FILE_GROUP, META_DATA_FILE_NAME)).thenReturn(configFile);
- boolean pluginExist = polarisDataChangedInit.notExist();
- assertTrue(pluginExist, "plugin exist.");
- }
-}
diff --git
a/shenyu-admin-listener/shenyu-admin-listener-polaris/src/test/java/org/apache/shenyu/admin/listener/polaris/PolarisDataChangedListenerTest.java
b/shenyu-admin-listener/shenyu-admin-listener-polaris/src/test/java/org/apache/shenyu/admin/listener/polaris/PolarisDataChangedListenerTest.java
deleted file mode 100644
index 2ea93e713f..0000000000
---
a/shenyu-admin-listener/shenyu-admin-listener-polaris/src/test/java/org/apache/shenyu/admin/listener/polaris/PolarisDataChangedListenerTest.java
+++ /dev/null
@@ -1,168 +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.polaris;
-
-import com.google.common.collect.ImmutableList;
-import com.tencent.polaris.api.exception.PolarisException;
-import com.tencent.polaris.configuration.api.core.ConfigFile;
-import com.tencent.polaris.configuration.api.core.ConfigFilePublishService;
-import com.tencent.polaris.configuration.api.core.ConfigFileService;
-import
com.tencent.polaris.configuration.client.internal.DefaultConfigFileMetadata;
-import org.apache.shenyu.admin.config.properties.PolarisProperties;
-import org.apache.shenyu.common.constant.PolarisPathConstants;
-import org.apache.shenyu.common.dto.AppAuthData;
-import org.apache.shenyu.common.dto.MetaData;
-import org.apache.shenyu.common.dto.PluginData;
-import org.apache.shenyu.common.dto.RuleData;
-import org.apache.shenyu.common.dto.SelectorData;
-import org.apache.shenyu.common.enums.DataEventTypeEnum;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-/**
- * Test cases for {@link PolarisDataChangedListener}.
- */
-@ExtendWith(MockitoExtension.class)
-public class PolarisDataChangedListenerTest {
-
- private static final String MOCK_APP_KEY = "MOCK_APP_KEY";
-
- private static final String MOCK_APP_SECRET = "MOCK_APP_SECRET";
-
- private static final String MOCK_ID = "MOCK_ID";
-
- private static final String MOCK_PATH = "MOCK_PATH";
-
- private static final String MOCK_APP_NAME = "MOCK_APP_NAME";
-
- private static final String MOCK_NAME = "MOCK_NAME";
-
- private static final String MOCK_CONFIG = "MOCK_CONFIG";
-
- private static final String MOCK_PLUGIN_NAME = "MOCK_PLUGIN_NAME";
-
- private static final String MOCK_SELECTOR_ID = "MOCK_SELECTOR_ID";
-
- @Mock
- private ConfigFile configFile;
-
- @Mock
- private PolarisProperties polarisProperties;
-
- @Mock
- private ConfigFileService polarisConfigFileService;
-
- @Mock
- private ConfigFilePublishService polarisConfigFilePublishService;
-
- @InjectMocks
- private PolarisDataChangedListener polarisDataChangedListener;
-
- @Test
- public void testOnAppAuthChanged() throws PolarisException {
-
when(polarisProperties.getNamespace()).thenReturn(PolarisPathConstants.NAMESPACE);
-
when(polarisProperties.getFileGroup()).thenReturn(PolarisPathConstants.FILE_GROUP);
- when(configFile.hasContent()).thenReturn(false);
- when(configFile.getContent()).thenReturn(null);
-
when(polarisConfigFileService.getConfigFile(any())).thenReturn(configFile);
- when(polarisConfigFileService.getConfigFile(any(), any(),
any())).thenReturn(configFile);
- AppAuthData appAuthData =
AppAuthData.builder().appKey(MOCK_APP_KEY).appSecret(MOCK_APP_SECRET).build();
-
polarisDataChangedListener.onAppAuthChanged(ImmutableList.of(appAuthData),
DataEventTypeEnum.DELETE);
-
polarisDataChangedListener.onAppAuthChanged(ImmutableList.of(appAuthData),
DataEventTypeEnum.REFRESH);
-
polarisDataChangedListener.onAppAuthChanged(ImmutableList.of(appAuthData),
DataEventTypeEnum.MYSELF);
-
polarisDataChangedListener.onAppAuthChanged(ImmutableList.of(appAuthData),
DataEventTypeEnum.CREATE);
- verify(polarisConfigFilePublishService,
times(8)).createConfigFile(any(DefaultConfigFileMetadata.class),
any(String.class));
- verify(polarisConfigFilePublishService,
times(8)).releaseConfigFile(any(DefaultConfigFileMetadata.class));
- }
-
- @Test
- public void testOnPluginChanged() throws PolarisException {
-
when(polarisProperties.getNamespace()).thenReturn(PolarisPathConstants.NAMESPACE);
-
when(polarisProperties.getFileGroup()).thenReturn(PolarisPathConstants.FILE_GROUP);
- when(configFile.hasContent()).thenReturn(false);
- when(configFile.getContent()).thenReturn(null);
-
when(polarisConfigFileService.getConfigFile(any())).thenReturn(configFile);
- when(polarisConfigFileService.getConfigFile(any(), any(),
any())).thenReturn(configFile);
- PluginData pluginData =
PluginData.builder().id(MOCK_ID).name(MOCK_NAME).config(MOCK_CONFIG).build();
-
polarisDataChangedListener.onPluginChanged(ImmutableList.of(pluginData),
DataEventTypeEnum.DELETE);
-
polarisDataChangedListener.onPluginChanged(ImmutableList.of(pluginData),
DataEventTypeEnum.REFRESH);
-
polarisDataChangedListener.onPluginChanged(ImmutableList.of(pluginData),
DataEventTypeEnum.MYSELF);
-
polarisDataChangedListener.onPluginChanged(ImmutableList.of(pluginData),
DataEventTypeEnum.CREATE);
- verify(polarisConfigFilePublishService,
times(8)).createConfigFile(any(DefaultConfigFileMetadata.class),
any(String.class));
- verify(polarisConfigFilePublishService,
times(8)).releaseConfigFile(any(DefaultConfigFileMetadata.class));
- }
-
- @Test
- public void testOnSelectorChanged() throws PolarisException {
-
when(polarisProperties.getNamespace()).thenReturn(PolarisPathConstants.NAMESPACE);
-
when(polarisProperties.getFileGroup()).thenReturn(PolarisPathConstants.FILE_GROUP);
- when(configFile.hasContent()).thenReturn(false);
- when(configFile.getContent()).thenReturn(null);
-
when(polarisConfigFileService.getConfigFile(any())).thenReturn(configFile);
- when(polarisConfigFileService.getConfigFile(any(), any(),
any())).thenReturn(configFile);
- SelectorData selectorData =
SelectorData.builder().id(MOCK_ID).name(MOCK_NAME).pluginName(MOCK_PLUGIN_NAME).build();
-
polarisDataChangedListener.onSelectorChanged(ImmutableList.of(selectorData),
DataEventTypeEnum.DELETE);
-
polarisDataChangedListener.onSelectorChanged(ImmutableList.of(selectorData),
DataEventTypeEnum.REFRESH);
-
polarisDataChangedListener.onSelectorChanged(ImmutableList.of(selectorData),
DataEventTypeEnum.MYSELF);
-
polarisDataChangedListener.onSelectorChanged(ImmutableList.of(selectorData),
DataEventTypeEnum.CREATE);
- verify(polarisConfigFilePublishService,
times(8)).createConfigFile(any(DefaultConfigFileMetadata.class),
any(String.class));
- verify(polarisConfigFilePublishService,
times(8)).releaseConfigFile(any(DefaultConfigFileMetadata.class));
- }
-
- @Test
- public void testOnMetaDataChanged() throws PolarisException {
-
when(polarisProperties.getNamespace()).thenReturn(PolarisPathConstants.NAMESPACE);
-
when(polarisProperties.getFileGroup()).thenReturn(PolarisPathConstants.FILE_GROUP);
- when(configFile.hasContent()).thenReturn(false);
- when(configFile.getContent()).thenReturn(null);
-
when(polarisConfigFileService.getConfigFile(any())).thenReturn(configFile);
- when(polarisConfigFileService.getConfigFile(any(), any(),
any())).thenReturn(configFile);
- MetaData metaData =
MetaData.builder().id(MOCK_ID).path(MOCK_PATH).appName(MOCK_APP_NAME).build();
-
polarisDataChangedListener.onMetaDataChanged(ImmutableList.of(metaData),
DataEventTypeEnum.DELETE);
-
polarisDataChangedListener.onMetaDataChanged(ImmutableList.of(metaData),
DataEventTypeEnum.REFRESH);
-
polarisDataChangedListener.onMetaDataChanged(ImmutableList.of(metaData),
DataEventTypeEnum.MYSELF);
-
polarisDataChangedListener.onMetaDataChanged(ImmutableList.of(metaData),
DataEventTypeEnum.CREATE);
- verify(polarisConfigFilePublishService,
times(8)).createConfigFile(any(DefaultConfigFileMetadata.class),
any(String.class));
- verify(polarisConfigFilePublishService,
times(8)).releaseConfigFile(any(DefaultConfigFileMetadata.class));
- }
-
- @Test
- public void testOnRuleChanged() throws PolarisException {
-
when(polarisProperties.getNamespace()).thenReturn(PolarisPathConstants.NAMESPACE);
-
when(polarisProperties.getFileGroup()).thenReturn(PolarisPathConstants.FILE_GROUP);
- when(configFile.hasContent()).thenReturn(false);
- when(configFile.getContent()).thenReturn(null);
-
when(polarisConfigFileService.getConfigFile(any())).thenReturn(configFile);
- RuleData ruleData =
RuleData.builder().id(MOCK_ID).name(MOCK_NAME).pluginName(MOCK_PLUGIN_NAME).selectorId(MOCK_SELECTOR_ID).build();
- when(polarisConfigFileService.getConfigFile(any(), any(),
any())).thenReturn(configFile);
- polarisDataChangedListener.onRuleChanged(ImmutableList.of(ruleData),
DataEventTypeEnum.DELETE);
- polarisDataChangedListener.onRuleChanged(ImmutableList.of(ruleData),
DataEventTypeEnum.REFRESH);
- polarisDataChangedListener.onRuleChanged(ImmutableList.of(ruleData),
DataEventTypeEnum.MYSELF);
- polarisDataChangedListener.onRuleChanged(ImmutableList.of(ruleData),
DataEventTypeEnum.CREATE);
- verify(polarisConfigFilePublishService,
times(8)).createConfigFile(any(DefaultConfigFileMetadata.class),
any(String.class));
- verify(polarisConfigFilePublishService,
times(8)).releaseConfigFile(any(DefaultConfigFileMetadata.class));
- }
-}
diff --git a/shenyu-admin/pom.xml b/shenyu-admin/pom.xml
index 333671776d..570dabc715 100644
--- a/shenyu-admin/pom.xml
+++ b/shenyu-admin/pom.xml
@@ -327,12 +327,6 @@
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.shenyu</groupId>
- <artifactId>shenyu-admin-listener-polaris</artifactId>
- <version>${project.version}</version>
- </dependency>
-
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-admin-listener-zookeeper</artifactId>
diff --git a/shenyu-admin/src/main/resources/application.yml
b/shenyu-admin/src/main/resources/application.yml
index d85297cd9c..69af897f43 100755
--- a/shenyu-admin/src/main/resources/application.yml
+++ b/shenyu-admin/src/main/resources/application.yml
@@ -108,10 +108,6 @@ shenyu:
# namespace:
# accessKey:
# secretKey:
-# polaris:
-# url: 127.0.0.1:8093
-# namespace:
-# fileGroup:
# etcd:
# url: http://localhost:2379
# consul:
@@ -271,4 +267,3 @@ logging:
org.apache.shenyu.lottery: info
org.apache.shenyu: info
# org.apache.shenyu.admin.utils.HttpUtils: debug
-
diff --git a/shenyu-bootstrap/pom.xml b/shenyu-bootstrap/pom.xml
index 9f847c44a9..cdf2578002 100644
--- a/shenyu-bootstrap/pom.xml
+++ b/shenyu-bootstrap/pom.xml
@@ -479,13 +479,6 @@
</dependency>
<!--shenyu registry start-->
- <!--shenyu data sync start use polaris-->
- <dependency>
- <groupId>org.apache.shenyu</groupId>
-
<artifactId>shenyu-spring-boot-starter-sync-data-polaris</artifactId>
- <version>${project.version}</version>
- </dependency>
-
<!--shenyu instance start-->
<!--shenyu registry end-->
diff --git a/shenyu-bootstrap/src/main/resources/application.yml
b/shenyu-bootstrap/src/main/resources/application.yml
index 7f7bd424f8..6eee7fa52e 100644
--- a/shenyu-bootstrap/src/main/resources/application.yml
+++ b/shenyu-bootstrap/src/main/resources/application.yml
@@ -251,10 +251,6 @@ shenyu:
# namespace:
# accessKey:
# secretKey:
-# polaris:
-# url: 127.0.0.1:8093
-# namespace:
-# fileGroup:
# etcd:
# url: http://localhost:2379
# consul:
diff --git a/shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE
b/shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE
index 9af4e16042..ebc4573d02 100644
--- a/shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE
+++ b/shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE
@@ -523,7 +523,6 @@ The text of each license is also included at
licenses/LICENSE-[project].txt.
postgresql 42.3.8: https://github.com/pgjdbc/pgjdbc, BSD 2-Clause
protobuf-java 3.25.5: https://github.com/protocolbuffers/protobuf/, BSD
3-Clause
protobuf-java-util 3.21.1: https://github.com/protocolbuffers/protobuf/,
BSD 3-Clause
- polaris-all 1.13.0: https://github.com/polarismesh/polaris-java, BSD
3-Clause
antlr 2.7.7: http://www.antlr.org/, BSD-3-Clause
antlr-runtime 3.4: http://www.antlr.org/, BSD-3-Clause
stringtemplate 3.2.1: http://www.stringtemplate.org, BSD
diff --git a/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/LICENSE
b/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/LICENSE
index ba67f806ee..051c268f71 100644
--- a/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/LICENSE
+++ b/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/LICENSE
@@ -680,7 +680,6 @@ The text of each license is also included at
licenses/LICENSE-[project].txt.
hamcrest-core 2.2: https://github.com/hamcrest/JavaHamcrest ,BSD 3-Clause
asm 9.2: https://github.com/llbit/ow2-asm, BSD 3-Clause
asm-tree 9.2: https://asm.ow2.io/, BSD 3-Clause
- polaris-all 1.13.0: https://github.com/polarismesh/polaris-java, BSD
3-Clause
re2j 1.6: https://github.com/google/re2j, BSD 3-Clause
re2j 1.8: https://github.com/google/re2j, BSD 3-Clause
diff --git a/shenyu-registry/pom.xml b/shenyu-registry/pom.xml
index cee7001986..f8a45b7d77 100644
--- a/shenyu-registry/pom.xml
+++ b/shenyu-registry/pom.xml
@@ -35,7 +35,6 @@
<module>shenyu-registry-nacos</module>
<module>shenyu-registry-apollo</module>
<module>shenyu-registry-eureka</module>
- <module>shenyu-registry-polaris</module>
<module>shenyu-registry-kubernetes</module>
</modules>
diff --git a/shenyu-registry/shenyu-registry-core/pom.xml
b/shenyu-registry/shenyu-registry-core/pom.xml
index 66a25c124c..5118fd3229 100644
--- a/shenyu-registry/shenyu-registry-core/pom.xml
+++ b/shenyu-registry/shenyu-registry-core/pom.xml
@@ -51,11 +51,6 @@
<artifactId>shenyu-registry-nacos</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.shenyu</groupId>
- <artifactId>shenyu-registry-polaris</artifactId>
- <version>${project.version}</version>
- </dependency>
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-registry-eureka</artifactId>
diff --git a/shenyu-registry/shenyu-registry-polaris/pom.xml
b/shenyu-registry/shenyu-registry-polaris/pom.xml
deleted file mode 100644
index ba8a4f997d..0000000000
--- a/shenyu-registry/shenyu-registry-polaris/pom.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <groupId>org.apache.shenyu</groupId>
- <artifactId>shenyu-registry</artifactId>
- <version>2.7.2-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <artifactId>shenyu-registry-polaris</artifactId>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.shenyu</groupId>
- <artifactId>shenyu-registry-api</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.tencent.polaris</groupId>
- <artifactId>polaris-all</artifactId>
- </dependency>
- </dependencies>
-</project>
diff --git
a/shenyu-registry/shenyu-registry-polaris/src/main/java/org/apache/shenyu/registry/polaris/PolarisInstanceRegisterRepository.java
b/shenyu-registry/shenyu-registry-polaris/src/main/java/org/apache/shenyu/registry/polaris/PolarisInstanceRegisterRepository.java
deleted file mode 100644
index 59214d8992..0000000000
---
a/shenyu-registry/shenyu-registry-polaris/src/main/java/org/apache/shenyu/registry/polaris/PolarisInstanceRegisterRepository.java
+++ /dev/null
@@ -1,146 +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.polaris;
-
-import com.tencent.polaris.api.config.Configuration;
-import com.tencent.polaris.api.core.ConsumerAPI;
-import com.tencent.polaris.api.core.ProviderAPI;
-import com.tencent.polaris.api.exception.PolarisException;
-import com.tencent.polaris.api.pojo.Instance;
-import com.tencent.polaris.api.rpc.GetHealthyInstancesRequest;
-import com.tencent.polaris.api.rpc.InstanceRegisterRequest;
-import com.tencent.polaris.api.rpc.InstancesResponse;
-import com.tencent.polaris.client.api.SDKContext;
-import com.tencent.polaris.factory.ConfigAPIFactory;
-import com.tencent.polaris.factory.api.DiscoveryAPIFactory;
-import org.apache.shenyu.common.constant.Constants;
-import org.apache.shenyu.common.constant.PolarisPathConstants;
-import org.apache.shenyu.common.exception.ShenyuException;
-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.spi.Join;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * The type polaris instance register repository.
- */
-@Join(isSingleton = false)
-public class PolarisInstanceRegisterRepository implements
ShenyuInstanceRegisterRepository {
-
- private static final Logger LOGGER =
LoggerFactory.getLogger(PolarisInstanceRegisterRepository.class);
-
- private ConsumerAPI consumerAPI;
-
- private ProviderAPI providerAPI;
-
- private String namespace;
-
- /**
- * Init.
- * @param config the config
- */
- @Override
- public void init(final RegisterConfig config) {
- Configuration configuration = buildConfiguration(config);
- SDKContext sdkContext = SDKContext.initContextByConfig(configuration);
-
- this.consumerAPI =
DiscoveryAPIFactory.createConsumerAPIByContext(sdkContext);
- this.providerAPI =
DiscoveryAPIFactory.createProviderAPIByContext(sdkContext);
- this.namespace = config.getProps().getProperty(Constants.NAMESPACE,
PolarisPathConstants.NAMESPACE);
- }
-
- private Configuration buildConfiguration(final RegisterConfig config) {
- String serverLists = config.getServerLists();
- return ConfigAPIFactory.createConfigurationByAddress(serverLists);
- }
-
- /**
- * Persist instance.
- * @param instance instance
- */
- @Override
- public void persistInstance(final InstanceEntity instance) {
- final InstanceRegisterRequest req = new InstanceRegisterRequest();
- req.setInstanceId(buildInstanceNodeName(instance));
- req.setWeight(1);
- req.setHost(instance.getHost());
- req.setPort(instance.getPort());
- req.setService(instance.getAppName());
- req.setNamespace(namespace);
- try {
- providerAPI.registerInstance(req);
- } catch (PolarisException e) {
- throw new ShenyuException(e);
- }
- }
-
- private String buildInstanceNodeName(final InstanceEntity instance) {
- String host = instance.getHost();
- int port = instance.getPort();
- return String.join(Constants.COLONS, host, Integer.toString(port));
- }
-
- /**
- * selectInstances.
- * @param selectKey selectKey
- * @return {@link List}
- */
- @Override
- public List<InstanceEntity> selectInstances(final String selectKey) {
- List<InstanceEntity> result = new ArrayList<>();
- final GetHealthyInstancesRequest req = new
GetHealthyInstancesRequest();
- req.setService(selectKey);
- req.setNamespace(namespace);
- try {
- final InstancesResponse response =
consumerAPI.getHealthyInstances(req);
-
Arrays.stream(response.getInstances()).sequential().forEach(instance ->
result.add(convertFromInstance(instance)));
- } catch (Exception e) {
- LOGGER.error("getInstanceRegisterDTOS error", e);
- }
- return result;
- }
-
- private InstanceEntity convertFromInstance(final Instance instance) {
- InstanceEntity instanceEntity = new InstanceEntity();
- instanceEntity.setPort(instance.getPort());
- instanceEntity.setHost(instance.getHost());
- instanceEntity.setAppName(instance.getService());
- instanceEntity.setUri(URI.create(String.format("%s://%s:%s",
instance.getProtocol(), instance.getHost(), instance.getPort())));
- return instanceEntity;
- }
-
- /**
- * Close.
- */
- @Override
- public void close() {
- try {
- consumerAPI.close();
- providerAPI.close();
- } catch (Exception e) {
- throw new ShenyuException(e);
- }
- }
-}
diff --git
a/shenyu-registry/shenyu-registry-polaris/src/main/resources/META-INF/shenyu/org.apache.shenyu.registry.api.ShenyuInstanceRegisterRepository
b/shenyu-registry/shenyu-registry-polaris/src/main/resources/META-INF/shenyu/org.apache.shenyu.registry.api.ShenyuInstanceRegisterRepository
deleted file mode 100644
index 6ecd046f7a..0000000000
---
a/shenyu-registry/shenyu-registry-polaris/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.
-
-polaris=org.apache.shenyu.registry.polaris.PolarisInstanceRegisterRepository
diff --git
a/shenyu-registry/shenyu-registry-polaris/src/test/java/org/apache/shenyu/registry/polaris/PolarisInstanceRegisterRepositoryTest.java
b/shenyu-registry/shenyu-registry-polaris/src/test/java/org/apache/shenyu/registry/polaris/PolarisInstanceRegisterRepositoryTest.java
deleted file mode 100644
index eacabf18eb..0000000000
---
a/shenyu-registry/shenyu-registry-polaris/src/test/java/org/apache/shenyu/registry/polaris/PolarisInstanceRegisterRepositoryTest.java
+++ /dev/null
@@ -1,120 +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.polaris;
-
-import com.tencent.polaris.api.core.ConsumerAPI;
-import com.tencent.polaris.api.core.ProviderAPI;
-import com.tencent.polaris.api.exception.PolarisException;
-import com.tencent.polaris.api.pojo.Instance;
-import com.tencent.polaris.api.rpc.GetHealthyInstancesRequest;
-import com.tencent.polaris.api.rpc.InstanceRegisterRequest;
-import java.lang.reflect.Field;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.shenyu.registry.api.entity.InstanceEntity;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.mock;
-
-public class PolarisInstanceRegisterRepositoryTest {
-
- private PolarisInstanceRegisterRepository repository;
-
- private final Map<String, Instance> storage = new HashMap<>();
-
- @BeforeEach
- public void setUp() throws NoSuchFieldException, IllegalAccessException,
PolarisException {
- this.repository = new PolarisInstanceRegisterRepository();
- Class<? extends PolarisInstanceRegisterRepository> clazz =
this.repository.getClass();
-
- setField(clazz, "namespace", "shenyu");
- setField(clazz, "consumerAPI", mockConsumerAPI());
- setField(clazz, "providerAPI", mockProviderAPI());
-
- storage.clear();
- }
-
- private <T> void setField(final Class<T> clazz, final String fieldName,
final Object value) throws NoSuchFieldException, IllegalAccessException {
- Field field = clazz.getDeclaredField(fieldName);
- field.setAccessible(true);
- field.set(repository, value);
- field.setAccessible(false);
- }
-
- private ProviderAPI mockProviderAPI() throws PolarisException {
- ProviderAPI providerAPI = mock(ProviderAPI.class);
-
- doAnswer(invocationOnMock -> {
- final InstanceRegisterRequest req =
invocationOnMock.getArgument(0);
- storage.put(req.getService(),
Instance.createDefaultInstance(req.getInstanceId(), req.getNamespace(),
req.getService(), req.getHost(), req.getPort()));
- return null;
- }).when(providerAPI).registerInstance(any());
-
- doAnswer(invocationOnMock -> {
- storage.clear();
- return null;
- }).when(providerAPI).close();
- return providerAPI;
- }
-
- private ConsumerAPI mockConsumerAPI() throws PolarisException {
- ConsumerAPI consumerAPI = mock(ConsumerAPI.class);
-
- doAnswer(invocationOnMock -> {
- final GetHealthyInstancesRequest request =
invocationOnMock.getArgument(0);
- return
Collections.singletonList(storage.get(request.getService()));
- }).when(consumerAPI).getHealthyInstances(any());
-
- doAnswer(invocationOnMock -> {
- storage.clear();
- return null;
- }).when(consumerAPI).close();
- return consumerAPI;
- }
-
- @Test
- public void testPersistInstance() {
- InstanceEntity data = InstanceEntity.builder()
- .appName("shenyu-test")
- .host("shenyu-host")
- .port(9195)
- .build();
-
- final String key = "shenyu-test";
- repository.persistInstance(data);
- assertTrue(storage.containsKey(key));
-
- final Instance instance = storage.get(key);
- assertEquals(data.getHost(), instance.getHost());
- assertEquals(data.getPort(), instance.getPort());
- assertEquals(data.getAppName(), instance.getService());
- repository.close();
- }
-
- @Test
- public void testSelectInstancesAndWatcher() {
- String selectKey = "shenyu-instances";
- repository.selectInstances(selectKey);
- repository.close();
- }
-}
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 04f2a05a53..c9a8205cd3 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
@@ -34,7 +34,6 @@
<module>shenyu-spring-boot-starter-sync-data-etcd</module>
<module>shenyu-spring-boot-starter-sync-data-consul</module>
<module>shenyu-spring-boot-starter-sync-data-apollo</module>
- <module>shenyu-spring-boot-starter-sync-data-polaris</module>
</modules>
<dependencies>
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-polaris/pom.xml
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-polaris/pom.xml
deleted file mode 100644
index 9add68822d..0000000000
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-polaris/pom.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <groupId>org.apache.shenyu</groupId>
- <artifactId>shenyu-spring-boot-starter-sync-data-center</artifactId>
- <version>2.7.2-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>shenyu-spring-boot-starter-sync-data-polaris</artifactId>
-
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.shenyu</groupId>
- <artifactId>shenyu-sync-data-polaris</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter</artifactId>
- </dependency>
- </dependencies>
-</project>
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-polaris/src/main/java/org/apache/shenyu/springboot/starter/sync/data/polaris/PolarisSyncDataConfiguration.java
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-polaris/src/main/java/org/apache/shenyu/springboot/starter/sync/data/polaris/PolarisSyncDataConfiguration.java
deleted file mode 100644
index d26ce12bc8..0000000000
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-polaris/src/main/java/org/apache/shenyu/springboot/starter/sync/data/polaris/PolarisSyncDataConfiguration.java
+++ /dev/null
@@ -1,107 +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.starter.sync.data.polaris;
-
-import com.tencent.polaris.configuration.api.core.ConfigFileService;
-import com.tencent.polaris.configuration.factory.ConfigFileServiceFactory;
-import com.tencent.polaris.factory.ConfigAPIFactory;
-import org.apache.shenyu.common.config.ShenyuConfig;
-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.polaris.PolarisSyncDataService;
-import org.apache.shenyu.sync.data.polaris.config.PolarisConfig;
-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;
-
-/**
- * Polaris sync data configuration for spring boot.
- */
-@Configuration
-@ConditionalOnClass(PolarisSyncDataService.class)
-@ConditionalOnProperty(prefix = "shenyu.sync.polaris", name = "url")
-public class PolarisSyncDataConfiguration {
-
- private static final Logger LOGGER =
LoggerFactory.getLogger(PolarisSyncDataConfiguration.class);
-
- /**
- * Polaris sync data service.
- *
- * @param polarisConfig the polaris config
- * @param configFileServices the config service
- * @param pluginSubscriber the plugin subscriber
- * @param metaSubscribers the meta subscribers
- * @param authSubscribers the auth subscribers
- * @param proxySelectorSubscribers the auth subscribers
- * @param discoveryUpstreamDataSubscribers discoveryUpstreamDataSubscribers
- * @param shenyuConfig the shenyu config
- * @return the sync data service
- */
- @Bean
- public SyncDataService polarisSyncDataService(final
ObjectProvider<PolarisConfig> polarisConfig, final
ObjectProvider<ConfigFileService> configFileServices,
- final
ObjectProvider<PluginDataSubscriber> pluginSubscriber,
- final
ObjectProvider<List<MetaDataSubscriber>> metaSubscribers,
- final
ObjectProvider<List<AuthDataSubscriber>> authSubscribers,
- final
ObjectProvider<List<ProxySelectorDataSubscriber>> proxySelectorSubscribers,
- final
ObjectProvider<List<DiscoveryUpstreamDataSubscriber>>
discoveryUpstreamDataSubscribers,
- final
ObjectProvider<ShenyuConfig> shenyuConfig) {
- LOGGER.info("you use polaris sync shenyu data.......");
- return new PolarisSyncDataService(polarisConfig.getIfAvailable(),
configFileServices.getIfAvailable(), pluginSubscriber.getIfAvailable(),
- metaSubscribers.getIfAvailable(Collections::emptyList),
authSubscribers.getIfAvailable(Collections::emptyList),
- proxySelectorSubscribers.getIfAvailable(),
discoveryUpstreamDataSubscribers.getIfAvailable(),
- shenyuConfig.getIfAvailable());
- }
-
- /**
- * Polaris configFileService.
- *
- * @param polarisConfig the polaris config
- *
- * @return the config service
- */
- @Bean
- public ConfigFileService polarisConfigServices(final PolarisConfig
polarisConfig) {
- com.tencent.polaris.api.config.Configuration configuration =
ConfigAPIFactory.defaultConfig();
-
configuration.getConfigFile().getServerConnector().setAddresses(Collections.singletonList(polarisConfig.getUrl()));
- return ConfigFileServiceFactory.createConfigFileService(configuration);
- }
-
- /**
- * Polaris config service.
- *
- * @return the config.
- */
- @Bean
- @ConfigurationProperties(prefix = "shenyu.sync.polaris")
- public PolarisConfig polarisConfig() {
- return new PolarisConfig();
- }
-
-}
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-polaris/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-polaris/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
deleted file mode 100644
index 144e75a8ff..0000000000
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-polaris/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.starter.sync.data.polaris.PolarisSyncDataConfiguration
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-polaris/src/test/java/org/apache/shenyu/springboot/stater/sync/data/polaris/PolarisSyncDataConfigurationTest.java
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-polaris/src/test/java/org/apache/shenyu/springboot/stater/sync/data/polaris/PolarisSyncDataConfigurationTest.java
deleted file mode 100644
index a94151fce5..0000000000
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-sync-data-center/shenyu-spring-boot-starter-sync-data-polaris/src/test/java/org/apache/shenyu/springboot/stater/sync/data/polaris/PolarisSyncDataConfigurationTest.java
+++ /dev/null
@@ -1,77 +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.stater.sync.data.polaris;
-
-import com.tencent.polaris.client.api.SDKContext;
-import com.tencent.polaris.configuration.api.core.ConfigFileService;
-import com.tencent.polaris.configuration.client.DefaultConfigFileService;
-
-import org.apache.shenyu.common.config.ShenyuConfig;
-import
org.apache.shenyu.springboot.starter.sync.data.polaris.PolarisSyncDataConfiguration;
-import org.apache.shenyu.sync.data.api.SyncDataService;
-import org.apache.shenyu.sync.data.polaris.config.PolarisConfig;
-import org.junit.jupiter.api.Assertions;
-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.junit.jupiter.api.Assertions.assertInstanceOf;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Answers.CALLS_REAL_METHODS;
-
-/**
- * The test case for {@link PolarisSyncDataConfiguration}.
- */
-@ExtendWith(SpringExtension.class)
-@SpringBootTest(
- classes = PolarisSyncDataConfiguration.class,
- properties = {
- "shenyu.sync.polaris.url=" + PolarisSyncDataConfigurationTest.URL,
- "shenyu.sync.polaris.namespace=default",
- "shenyu.sync.polaris.fileGroup=fileGroup"
- })
-@EnableAutoConfiguration
-@MockBean(name = "shenyuConfig", value = ShenyuConfig.class, answer =
CALLS_REAL_METHODS)
-public final class PolarisSyncDataConfigurationTest {
-
- public static final String URL = "127.0.0.1:8093";
-
- @Autowired
- private SyncDataService syncDataService;
-
- @Autowired
- private PolarisConfig polarisConfig;
-
- @Test
- public void polarisConfigServiceTest() {
- assertNotNull(syncDataService);
- assertNotNull(polarisConfig);
- final PolarisSyncDataConfiguration polarisSyncDataConfiguration = new
PolarisSyncDataConfiguration();
-
- final ConfigFileService configFileService =
Assertions.assertDoesNotThrow(() ->
polarisSyncDataConfiguration.polarisConfigServices(polarisConfig));
- assertInstanceOf(DefaultConfigFileService.class, configFileService);
- DefaultConfigFileService defaultConfigFileService =
(DefaultConfigFileService) configFileService;
- final SDKContext sdkContext = defaultConfigFileService.getSDKContext();
-
assertTrue(sdkContext.getConfig().getConfigFile().getServerConnector().getAddresses().contains(PolarisSyncDataConfigurationTest.URL));
- }
-}
diff --git a/shenyu-sync-data-center/pom.xml b/shenyu-sync-data-center/pom.xml
index df7c5d4a5f..f8cbb92a04 100644
--- a/shenyu-sync-data-center/pom.xml
+++ b/shenyu-sync-data-center/pom.xml
@@ -35,6 +35,5 @@
<module>shenyu-sync-data-etcd</module>
<module>shenyu-sync-data-consul</module>
<module>shenyu-sync-data-apollo</module>
- <module>shenyu-sync-data-polaris</module>
</modules>
</project>
diff --git a/shenyu-sync-data-center/shenyu-sync-data-polaris/pom.xml
b/shenyu-sync-data-center/shenyu-sync-data-polaris/pom.xml
deleted file mode 100644
index 8b3fbab06b..0000000000
--- a/shenyu-sync-data-center/shenyu-sync-data-polaris/pom.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <groupId>org.apache.shenyu</groupId>
- <artifactId>shenyu-sync-data-center</artifactId>
- <version>2.7.2-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <artifactId>shenyu-sync-data-polaris</artifactId>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.shenyu</groupId>
- <artifactId>shenyu-sync-data-api</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.tencent.polaris</groupId>
- <artifactId>polaris-all</artifactId>
- <version>1.13.0</version>
- </dependency>
- </dependencies>
-</project>
diff --git
a/shenyu-sync-data-center/shenyu-sync-data-polaris/src/main/java/org/apache/shenyu/sync/data/polaris/PolarisSyncDataService.java
b/shenyu-sync-data-center/shenyu-sync-data-polaris/src/main/java/org/apache/shenyu/sync/data/polaris/PolarisSyncDataService.java
deleted file mode 100644
index 51c2fc0b72..0000000000
---
a/shenyu-sync-data-center/shenyu-sync-data-polaris/src/main/java/org/apache/shenyu/sync/data/polaris/PolarisSyncDataService.java
+++ /dev/null
@@ -1,122 +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.polaris;
-
-import com.tencent.polaris.configuration.api.core.ChangeType;
-import com.tencent.polaris.configuration.api.core.ConfigFile;
-import com.tencent.polaris.configuration.api.core.ConfigFileChangeListener;
-import com.tencent.polaris.configuration.api.core.ConfigFileService;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.shenyu.common.config.ShenyuConfig;
-import org.apache.shenyu.common.constant.NacosPathConstants;
-import org.apache.shenyu.common.constant.PolarisPathConstants;
-import org.apache.shenyu.common.exception.ShenyuException;
-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.apache.shenyu.sync.data.polaris.config.PolarisConfig;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Consumer;
-
-/**
- * The type Polaris sync data service.
- */
-public class PolarisSyncDataService extends AbstractNodeDataSyncService
implements SyncDataService {
-
- private static final Logger LOG =
LoggerFactory.getLogger(PolarisSyncDataService.class);
-
- private final PolarisConfig polarisConfig;
-
- private final ConfigFileService configFileService;
-
- private final Map<String, ConfigFileChangeListener> watchCache = new
ConcurrentHashMap<>();
-
- public PolarisSyncDataService(final PolarisConfig polarisConfig, final
ConfigFileService configFileService, final PluginDataSubscriber
pluginDataSubscriber,
- final List<MetaDataSubscriber>
metaDataSubscribers, final List<AuthDataSubscriber> authDataSubscribers,
- final List<ProxySelectorDataSubscriber>
proxySelectorDataSubscribers,
- final List<DiscoveryUpstreamDataSubscriber>
discoveryUpstreamDataSubscribers,
- final ShenyuConfig shenyuConfig) {
- super(new ChangeData(PolarisPathConstants.PLUGIN_DATA_FILE_NAME,
PolarisPathConstants.SELECTOR_DATA_FILE_NAME,
- PolarisPathConstants.RULE_DATA_FILE_NAME,
PolarisPathConstants.AUTH_DATA_ID_FILE_NAME,
- PolarisPathConstants.META_DATA_FILE_NAME,
PolarisPathConstants.PROXY_SELECTOR_FILE_NAME,
NacosPathConstants.DISCOVERY_DATA_ID),
- pluginDataSubscriber, metaDataSubscribers,
- authDataSubscribers, proxySelectorDataSubscribers,
discoveryUpstreamDataSubscribers, shenyuConfig);
- this.polarisConfig = polarisConfig;
- this.configFileService = configFileService;
- startWatch();
- }
-
- @Override
- protected String getServiceConfig(final String key, final Consumer<String>
updateHandler, final Consumer<String> deleteHandler) {
- if (watchCache.containsKey(key)) {
- return null;
- }
- try {
- final ConfigFileChangeListener listener = event -> {
- try {
- if (event.getChangeType().equals(ChangeType.DELETED) ||
StringUtils.isBlank(event.getNewValue())) {
-
Optional.ofNullable(deleteHandler).ifPresent(deleteHandler2 ->
deleteHandler2.accept(key));
- } else {
- if (event.getNewValue().equals(event.getOldValue())) {
- return;
- }
- updateHandler.accept(event.getNewValue());
- }
- } catch (Exception e) {
- LOG.error("Polaris sync listener receiveConfigInfo error",
e);
- }
- };
- final ConfigFile configFile =
configFileService.getConfigFile(polarisConfig.getNamespace(),
polarisConfig.getFileGroup(), key);
- configFile.addChangeListener(listener);
- watchCache.put(key, listener);
- return configFile.hasContent() ? configFile.getContent() : null;
- } catch (Exception e) {
- throw new ShenyuException(e);
- }
- }
-
- @Override
- protected void doRemoveListener(final String removeKey) {
- final ConfigFileChangeListener configFileChangeListener =
watchCache.remove(removeKey);
- if (Objects.nonNull(configFileChangeListener)) {
- final ConfigFile configFile =
configFileService.getConfigFile(polarisConfig.getNamespace(),
polarisConfig.getFileGroup(), removeKey);
- configFile.removeChangeListener(configFileChangeListener);
- }
- }
-
- @Override
- public void close() {
- watchCache.forEach((key, configFileChangeListener) -> {
- if (Objects.nonNull(configFileChangeListener)) {
- final ConfigFile configFile =
configFileService.getConfigFile(polarisConfig.getNamespace(),
polarisConfig.getFileGroup(), key);
- configFile.removeChangeListener(configFileChangeListener);
- }
- });
- }
-}
diff --git
a/shenyu-sync-data-center/shenyu-sync-data-polaris/src/main/java/org/apache/shenyu/sync/data/polaris/config/PolarisConfig.java
b/shenyu-sync-data-center/shenyu-sync-data-polaris/src/main/java/org/apache/shenyu/sync/data/polaris/config/PolarisConfig.java
deleted file mode 100644
index a8bdda8bed..0000000000
---
a/shenyu-sync-data-center/shenyu-sync-data-polaris/src/main/java/org/apache/shenyu/sync/data/polaris/config/PolarisConfig.java
+++ /dev/null
@@ -1,84 +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.polaris.config;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.shenyu.common.constant.PolarisPathConstants;
-
-public class PolarisConfig {
-
- private String url;
-
- private String namespace;
-
- private String fileGroup;
-
- /**
- * Gets the value of url.
- *
- * @return the value of url
- */
- public String getUrl() {
- return url;
- }
-
- /**
- * Sets the url.
- *
- * @param url url
- */
- public void setUrl(final String url) {
- this.url = url;
- }
-
- /**
- * Gets the value of namespace.
- *
- * @return the value of namespace
- */
- public String getNamespace() {
- return namespace;
- }
-
- /**
- * Sets the namespace.
- *
- * @param namespace namespace
- */
- public void setNamespace(final String namespace) {
- this.namespace = StringUtils.isNotBlank(namespace) ? namespace :
PolarisPathConstants.NAMESPACE;
- }
-
- /**
- * Gets the value of fileGroup.
- *
- * @return the value of fileGroup.
- */
- public String getFileGroup() {
- return fileGroup;
- }
-
- /**
- * Sets the value of fileGroup.
- *
- * @param fileGroup fileGroup
- */
- public void setFileGroup(final String fileGroup) {
- this.fileGroup = StringUtils.isNotBlank(fileGroup) ? fileGroup :
PolarisPathConstants.FILE_GROUP;
- }
-}
diff --git
a/shenyu-sync-data-center/shenyu-sync-data-polaris/src/test/java/org/apache/shenyu/sync/data/polaris/PolarisSyncDataServiceTest.java
b/shenyu-sync-data-center/shenyu-sync-data-polaris/src/test/java/org/apache/shenyu/sync/data/polaris/PolarisSyncDataServiceTest.java
deleted file mode 100644
index 4f0193cc1b..0000000000
---
a/shenyu-sync-data-center/shenyu-sync-data-polaris/src/test/java/org/apache/shenyu/sync/data/polaris/PolarisSyncDataServiceTest.java
+++ /dev/null
@@ -1,506 +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.polaris;
-
-import com.tencent.polaris.configuration.api.core.ChangeType;
-import com.tencent.polaris.configuration.api.core.ConfigFile;
-import com.tencent.polaris.configuration.api.core.ConfigFileChangeEvent;
-import com.tencent.polaris.configuration.api.core.ConfigFileChangeListener;
-import com.tencent.polaris.configuration.api.core.ConfigFileService;
-import org.apache.shenyu.common.config.ShenyuConfig;
-import org.apache.shenyu.common.exception.ShenyuException;
-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.polaris.config.PolarisConfig;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import java.util.Collections;
-
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.clearInvocations;
-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.when;
-
-/**
- * add test case for {@link PolarisSyncDataService}.
- */
-@ExtendWith(MockitoExtension.class)
-class PolarisSyncDataServiceTest {
-
- @Mock
- private ConfigFileService configFileService;
-
- @Mock
- private PluginDataSubscriber pluginDataSubscriber;
-
- @Mock
- private MetaDataSubscriber metaDataSubscriber;
-
- @Mock
- private AuthDataSubscriber authDataSubscriber;
-
- @Mock
- private ProxySelectorDataSubscriber proxySelectorDataSubscriber;
-
- @Mock
- private DiscoveryUpstreamDataSubscriber discoveryUpstreamDataSubscriber;
-
- @Mock
- private ConfigFile configFile;
-
- private PolarisConfig polarisConfig;
-
- private ShenyuConfig shenyuConfig;
-
- @BeforeEach
- void setup() {
- polarisConfig = new PolarisConfig();
- polarisConfig.setNamespace("test-namespace");
- polarisConfig.setFileGroup("test-group");
- shenyuConfig = new ShenyuConfig();
-
- lenient().when(configFileService.getConfigFile(anyString(),
anyString(), anyString())).thenReturn(configFile);
- lenient().when(configFile.hasContent()).thenReturn(true);
- lenient().when(configFile.getContent()).thenReturn("[]");
- }
-
- @Test
- void testConstructor() {
- PolarisSyncDataService service = new PolarisSyncDataService(
- polarisConfig,
- configFileService,
- pluginDataSubscriber,
- Collections.singletonList(metaDataSubscriber),
- Collections.singletonList(authDataSubscriber),
- Collections.singletonList(proxySelectorDataSubscriber),
- Collections.singletonList(discoveryUpstreamDataSubscriber),
- shenyuConfig
- );
-
- assertNotNull(service);
- verify(configFileService, atLeastOnce()).getConfigFile(anyString(),
anyString(), anyString());
- }
-
- @Test
- void testConfigFileWithNoContent() {
- when(configFile.hasContent()).thenReturn(false);
-
- PolarisSyncDataService service = new PolarisSyncDataService(
- polarisConfig,
- configFileService,
- pluginDataSubscriber,
- Collections.singletonList(metaDataSubscriber),
- Collections.singletonList(authDataSubscriber),
- Collections.singletonList(proxySelectorDataSubscriber),
- Collections.singletonList(discoveryUpstreamDataSubscriber),
- shenyuConfig
- );
-
- assertNotNull(service);
- }
-
- @Test
- void testListenerUpdateEvent() {
- new PolarisSyncDataService(
- polarisConfig,
- configFileService,
- pluginDataSubscriber,
- Collections.singletonList(metaDataSubscriber),
- Collections.singletonList(authDataSubscriber),
- Collections.singletonList(proxySelectorDataSubscriber),
- Collections.singletonList(discoveryUpstreamDataSubscriber),
- shenyuConfig
- );
-
- ArgumentCaptor<ConfigFileChangeListener> listenerCaptor =
ArgumentCaptor.forClass(ConfigFileChangeListener.class);
- verify(configFile,
atLeastOnce()).addChangeListener(listenerCaptor.capture());
-
- ConfigFileChangeEvent event = mock(ConfigFileChangeEvent.class);
- when(event.getChangeType()).thenReturn(ChangeType.MODIFIED);
- when(event.getOldValue()).thenReturn("old");
- when(event.getNewValue()).thenReturn("new");
-
- listenerCaptor.getValue().onChange(event);
- }
-
- @Test
- void testListenerDeleteEvent() {
- new PolarisSyncDataService(
- polarisConfig,
- configFileService,
- pluginDataSubscriber,
- Collections.singletonList(metaDataSubscriber),
- Collections.singletonList(authDataSubscriber),
- Collections.singletonList(proxySelectorDataSubscriber),
- Collections.singletonList(discoveryUpstreamDataSubscriber),
- shenyuConfig
- );
-
- ArgumentCaptor<ConfigFileChangeListener> listenerCaptor =
ArgumentCaptor.forClass(ConfigFileChangeListener.class);
- verify(configFile,
atLeastOnce()).addChangeListener(listenerCaptor.capture());
-
- ConfigFileChangeEvent event = mock(ConfigFileChangeEvent.class);
- when(event.getChangeType()).thenReturn(ChangeType.DELETED);
-
- listenerCaptor.getValue().onChange(event);
- }
-
- @Test
- void testListenerBlankNewValue() {
- new PolarisSyncDataService(
- polarisConfig,
- configFileService,
- pluginDataSubscriber,
- Collections.singletonList(metaDataSubscriber),
- Collections.singletonList(authDataSubscriber),
- Collections.singletonList(proxySelectorDataSubscriber),
- Collections.singletonList(discoveryUpstreamDataSubscriber),
- shenyuConfig
- );
-
- ArgumentCaptor<ConfigFileChangeListener> listenerCaptor =
ArgumentCaptor.forClass(ConfigFileChangeListener.class);
- verify(configFile,
atLeastOnce()).addChangeListener(listenerCaptor.capture());
-
- ConfigFileChangeEvent event = mock(ConfigFileChangeEvent.class);
- when(event.getChangeType()).thenReturn(ChangeType.MODIFIED);
- when(event.getNewValue()).thenReturn("");
-
- listenerCaptor.getValue().onChange(event);
- }
-
- @Test
- void testListenerSameOldAndNewValue() {
- new PolarisSyncDataService(
- polarisConfig,
- configFileService,
- pluginDataSubscriber,
- Collections.singletonList(metaDataSubscriber),
- Collections.singletonList(authDataSubscriber),
- Collections.singletonList(proxySelectorDataSubscriber),
- Collections.singletonList(discoveryUpstreamDataSubscriber),
- shenyuConfig
- );
-
- ArgumentCaptor<ConfigFileChangeListener> listenerCaptor =
ArgumentCaptor.forClass(ConfigFileChangeListener.class);
- verify(configFile,
atLeastOnce()).addChangeListener(listenerCaptor.capture());
-
- ConfigFileChangeEvent event = mock(ConfigFileChangeEvent.class);
- when(event.getChangeType()).thenReturn(ChangeType.MODIFIED);
- when(event.getOldValue()).thenReturn("same");
- when(event.getNewValue()).thenReturn("same");
-
- listenerCaptor.getValue().onChange(event);
- }
-
- @Test
- void testListenerException() {
- new PolarisSyncDataService(
- polarisConfig,
- configFileService,
- pluginDataSubscriber,
- Collections.singletonList(metaDataSubscriber),
- Collections.singletonList(authDataSubscriber),
- Collections.singletonList(proxySelectorDataSubscriber),
- Collections.singletonList(discoveryUpstreamDataSubscriber),
- shenyuConfig
- );
-
- ArgumentCaptor<ConfigFileChangeListener> listenerCaptor =
ArgumentCaptor.forClass(ConfigFileChangeListener.class);
- verify(configFile,
atLeastOnce()).addChangeListener(listenerCaptor.capture());
-
- ConfigFileChangeEvent event = mock(ConfigFileChangeEvent.class);
- when(event.getChangeType()).thenThrow(new RuntimeException("Test
exception"));
-
- listenerCaptor.getValue().onChange(event);
- }
-
- @Test
- void testGetServiceConfigException() {
- when(configFileService.getConfigFile(anyString(), anyString(),
anyString()))
- .thenThrow(new RuntimeException("Config error"));
-
- assertThrows(ShenyuException.class, () -> new PolarisSyncDataService(
- polarisConfig,
- configFileService,
- pluginDataSubscriber,
- Collections.singletonList(metaDataSubscriber),
- Collections.singletonList(authDataSubscriber),
- Collections.singletonList(proxySelectorDataSubscriber),
- Collections.singletonList(discoveryUpstreamDataSubscriber),
- shenyuConfig
- ));
- }
-
- @Test
- void testClose() {
- PolarisSyncDataService service = new PolarisSyncDataService(
- polarisConfig,
- configFileService,
- pluginDataSubscriber,
- Collections.singletonList(metaDataSubscriber),
- Collections.singletonList(authDataSubscriber),
- Collections.singletonList(proxySelectorDataSubscriber),
- Collections.singletonList(discoveryUpstreamDataSubscriber),
- shenyuConfig
- );
-
- service.close();
- verify(configFile,
atLeastOnce()).removeChangeListener(any(ConfigFileChangeListener.class));
- }
-
- @Test
- void testRemoveListenerAllowsListenerToBeAddedAgain() {
- PolarisSyncDataService service = new PolarisSyncDataService(
- polarisConfig,
- configFileService,
- pluginDataSubscriber,
- Collections.singletonList(metaDataSubscriber),
- Collections.singletonList(authDataSubscriber),
- Collections.singletonList(proxySelectorDataSubscriber),
- Collections.singletonList(discoveryUpstreamDataSubscriber),
- shenyuConfig
- );
- ArgumentCaptor<String> keyCaptor =
ArgumentCaptor.forClass(String.class);
- verify(configFileService, atLeastOnce()).getConfigFile(anyString(),
anyString(), keyCaptor.capture());
- String watchedKey = keyCaptor.getAllValues().get(0);
- clearInvocations(configFile);
-
- service.doRemoveListener(watchedKey);
- service.getServiceConfig(watchedKey, content -> { }, deletedKey -> {
});
-
-
verify(configFile).removeChangeListener(any(ConfigFileChangeListener.class));
- verify(configFile,
times(1)).addChangeListener(any(ConfigFileChangeListener.class));
- }
-
- @Test
- void testCloseWithNullListener() {
- when(configFile.hasContent()).thenReturn(false);
-
- PolarisSyncDataService service = new PolarisSyncDataService(
- polarisConfig,
- configFileService,
- null,
- Collections.emptyList(),
- Collections.emptyList(),
- Collections.emptyList(),
- Collections.emptyList(),
- shenyuConfig
- );
-
- service.close();
- verify(configFile,
atLeastOnce()).removeChangeListener(any(ConfigFileChangeListener.class));
- }
-
- @Test
- void testListenerWithDeleteHandler() {
- new PolarisSyncDataService(
- polarisConfig,
- configFileService,
- pluginDataSubscriber,
- Collections.singletonList(metaDataSubscriber),
- Collections.singletonList(authDataSubscriber),
- Collections.singletonList(proxySelectorDataSubscriber),
- Collections.singletonList(discoveryUpstreamDataSubscriber),
- shenyuConfig
- );
-
- ArgumentCaptor<ConfigFileChangeListener> listenerCaptor =
ArgumentCaptor.forClass(ConfigFileChangeListener.class);
- verify(configFile,
atLeastOnce()).addChangeListener(listenerCaptor.capture());
-
- ConfigFileChangeEvent event = mock(ConfigFileChangeEvent.class);
- when(event.getChangeType()).thenReturn(ChangeType.DELETED);
-
- listenerCaptor.getValue().onChange(event);
- }
-
- @Test
- void testListenerWithValidUpdate() {
- new PolarisSyncDataService(
- polarisConfig,
- configFileService,
- pluginDataSubscriber,
- Collections.singletonList(metaDataSubscriber),
- Collections.singletonList(authDataSubscriber),
- Collections.singletonList(proxySelectorDataSubscriber),
- Collections.singletonList(discoveryUpstreamDataSubscriber),
- shenyuConfig
- );
-
- ArgumentCaptor<ConfigFileChangeListener> listenerCaptor =
ArgumentCaptor.forClass(ConfigFileChangeListener.class);
- verify(configFile,
atLeastOnce()).addChangeListener(listenerCaptor.capture());
-
- ConfigFileChangeEvent event = mock(ConfigFileChangeEvent.class);
- when(event.getChangeType()).thenReturn(ChangeType.MODIFIED);
- when(event.getOldValue()).thenReturn("[]");
- when(event.getNewValue()).thenReturn("[{\"name\":\"test\"}]");
-
- listenerCaptor.getValue().onChange(event);
- }
-
- @Test
- void testGetServiceConfigReturnsContent() {
- String expectedContent = "[]";
- when(configFile.hasContent()).thenReturn(true);
- when(configFile.getContent()).thenReturn(expectedContent);
-
- new PolarisSyncDataService(
- polarisConfig,
- configFileService,
- pluginDataSubscriber,
- Collections.singletonList(metaDataSubscriber),
- Collections.singletonList(authDataSubscriber),
- Collections.singletonList(proxySelectorDataSubscriber),
- Collections.singletonList(discoveryUpstreamDataSubscriber),
- shenyuConfig
- );
-
- verify(configFile, atLeastOnce()).getContent();
- }
-
- @Test
- void testGetServiceConfigReturnsNull() {
- when(configFile.hasContent()).thenReturn(false);
-
- new PolarisSyncDataService(
- polarisConfig,
- configFileService,
- pluginDataSubscriber,
- Collections.singletonList(metaDataSubscriber),
- Collections.singletonList(authDataSubscriber),
- Collections.singletonList(proxySelectorDataSubscriber),
- Collections.singletonList(discoveryUpstreamDataSubscriber),
- shenyuConfig
- );
-
- verify(configFile, atLeastOnce()).hasContent();
- }
-
- @Test
- void testMultipleConfigFiles() {
- new PolarisSyncDataService(
- polarisConfig,
- configFileService,
- pluginDataSubscriber,
- Collections.singletonList(metaDataSubscriber),
- Collections.singletonList(authDataSubscriber),
- Collections.singletonList(proxySelectorDataSubscriber),
- Collections.singletonList(discoveryUpstreamDataSubscriber),
- shenyuConfig
- );
-
- verify(configFileService, atLeastOnce()).getConfigFile(anyString(),
anyString(), anyString());
- }
-
- @Test
- void testListenerAddedToAllConfigFiles() {
- new PolarisSyncDataService(
- polarisConfig,
- configFileService,
- pluginDataSubscriber,
- Collections.singletonList(metaDataSubscriber),
- Collections.singletonList(authDataSubscriber),
- Collections.singletonList(proxySelectorDataSubscriber),
- Collections.singletonList(discoveryUpstreamDataSubscriber),
- shenyuConfig
- );
-
- verify(configFile,
atLeastOnce()).addChangeListener(any(ConfigFileChangeListener.class));
- }
-
- @Test
- void testCloseRemovesAllListeners() {
- PolarisSyncDataService service = new PolarisSyncDataService(
- polarisConfig,
- configFileService,
- pluginDataSubscriber,
- Collections.singletonList(metaDataSubscriber),
- Collections.singletonList(authDataSubscriber),
- Collections.singletonList(proxySelectorDataSubscriber),
- Collections.singletonList(discoveryUpstreamDataSubscriber),
- shenyuConfig
- );
-
- service.close();
-
- verify(configFileService, atLeastOnce()).getConfigFile(anyString(),
anyString(), anyString());
- verify(configFile,
atLeastOnce()).removeChangeListener(any(ConfigFileChangeListener.class));
- }
-
- @Test
- void testListenerWithNullOldValue() {
- new PolarisSyncDataService(
- polarisConfig,
- configFileService,
- pluginDataSubscriber,
- Collections.singletonList(metaDataSubscriber),
- Collections.singletonList(authDataSubscriber),
- Collections.singletonList(proxySelectorDataSubscriber),
- Collections.singletonList(discoveryUpstreamDataSubscriber),
- shenyuConfig
- );
-
- ArgumentCaptor<ConfigFileChangeListener> listenerCaptor =
ArgumentCaptor.forClass(ConfigFileChangeListener.class);
- verify(configFile,
atLeastOnce()).addChangeListener(listenerCaptor.capture());
-
- ConfigFileChangeEvent event = mock(ConfigFileChangeEvent.class);
- when(event.getChangeType()).thenReturn(ChangeType.MODIFIED);
- when(event.getOldValue()).thenReturn(null);
- when(event.getNewValue()).thenReturn("{\"data\":\"new\"}");
-
- listenerCaptor.getValue().onChange(event);
- }
-
- @Test
- void testListenerWithAddedChangeType() {
- new PolarisSyncDataService(
- polarisConfig,
- configFileService,
- pluginDataSubscriber,
- Collections.singletonList(metaDataSubscriber),
- Collections.singletonList(authDataSubscriber),
- Collections.singletonList(proxySelectorDataSubscriber),
- Collections.singletonList(discoveryUpstreamDataSubscriber),
- shenyuConfig
- );
-
- ArgumentCaptor<ConfigFileChangeListener> listenerCaptor =
ArgumentCaptor.forClass(ConfigFileChangeListener.class);
- verify(configFile,
atLeastOnce()).addChangeListener(listenerCaptor.capture());
-
- ConfigFileChangeEvent event = mock(ConfigFileChangeEvent.class);
- when(event.getChangeType()).thenReturn(ChangeType.ADDED);
- when(event.getNewValue()).thenReturn("{\"data\":\"added\"}");
- when(event.getOldValue()).thenReturn(null);
-
- listenerCaptor.getValue().onChange(event);
- }
-}
diff --git
a/shenyu-sync-data-center/shenyu-sync-data-polaris/src/test/java/org/apache/shenyu/sync/data/polaris/config/PolarisConfigTest.java
b/shenyu-sync-data-center/shenyu-sync-data-polaris/src/test/java/org/apache/shenyu/sync/data/polaris/config/PolarisConfigTest.java
deleted file mode 100644
index 9072dc2696..0000000000
---
a/shenyu-sync-data-center/shenyu-sync-data-polaris/src/test/java/org/apache/shenyu/sync/data/polaris/config/PolarisConfigTest.java
+++ /dev/null
@@ -1,59 +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.polaris.config;
-
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-/**
- * add test case for {@link PolarisConfig}.
- */
-public class PolarisConfigTest {
-
- private static final String URL = "url";
-
- private static final String NAMESPACE = "nameSpace";
-
- private static final String FILEGROUP = "fileGroup";
-
- private PolarisConfig polarisConfig;
-
- private PolarisConfig that;
-
- @BeforeEach
- public void setUp() {
- polarisConfig = new PolarisConfig();
- polarisConfig.setUrl(URL);
- polarisConfig.setNamespace(NAMESPACE);
- polarisConfig.setFileGroup(FILEGROUP);
-
- that = new PolarisConfig();
- that.setUrl(URL);
- that.setNamespace(NAMESPACE);
- that.setFileGroup(FILEGROUP);
- }
-
- @Test
- public void testGetterSetter() {
- assertEquals(URL, polarisConfig.getUrl());
- assertEquals(NAMESPACE, polarisConfig.getNamespace());
- assertEquals(FILEGROUP, polarisConfig.getFileGroup());
- }
-}
diff --git
a/shenyu-sync-data-center/shenyu-sync-data-polaris/src/test/java/org/apache/shenyu/sync/data/polaris/handler/PolarisMockConfigFile.java
b/shenyu-sync-data-center/shenyu-sync-data-polaris/src/test/java/org/apache/shenyu/sync/data/polaris/handler/PolarisMockConfigFile.java
deleted file mode 100644
index fbf1d34703..0000000000
---
a/shenyu-sync-data-center/shenyu-sync-data-polaris/src/test/java/org/apache/shenyu/sync/data/polaris/handler/PolarisMockConfigFile.java
+++ /dev/null
@@ -1,203 +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.polaris.handler;
-
-import com.tencent.polaris.configuration.api.core.ConfigFile;
-import com.tencent.polaris.configuration.api.core.ConfigFileChangeListener;
-import com.tencent.polaris.configuration.api.core.ConfigFileMetadata;
-import com.tencent.polaris.configuration.api.core.ConfigKVFile;
-import com.tencent.polaris.configuration.api.core.ConfigKVFileChangeListener;
-import java.lang.reflect.Type;
-import java.util.Objects;
-import java.util.Properties;
-import java.util.Set;
-
-public class PolarisMockConfigFile implements ConfigFile, ConfigKVFile {
-
- private final Properties properties = new Properties();
-
- private final String namespace;
-
- private final String fileGroup;
-
- private String fileName;
-
- private final String content;
-
- public PolarisMockConfigFile(final ConfigFileMetadata configFileMetadata,
final String content) {
- this(configFileMetadata.getNamespace(),
configFileMetadata.getFileGroup(), configFileMetadata.getFileName(), content);
- }
-
- public PolarisMockConfigFile(final String namespace, final String
fileGroup, final String fileName) {
- this(namespace, fileGroup, fileName, null);
- }
-
- public PolarisMockConfigFile(final String namespace, final String
fileGroup, final String fileName, final String content) {
- this.namespace = namespace;
- this.fileGroup = fileGroup;
- this.fileName = fileName;
- this.content = content;
- }
-
- @Override
- public String getContent() {
- return content;
- }
-
- @Override
- public <T> T asJson(final Class<T> aClass, final T t) {
- return null;
- }
-
- @Override
- public <T> T asJson(final Type type, final T t) {
- return null;
- }
-
- @Override
- public boolean hasContent() {
- return Objects.nonNull(content);
- }
-
- @Override
- public void addChangeListener(final ConfigFileChangeListener
configFileChangeListener) {
-
- }
-
- @Override
- public void addChangeListener(final ConfigKVFileChangeListener listener) {
-
- }
-
- @Override
- public void removeChangeListener(final ConfigKVFileChangeListener
listener) {
-
- }
-
- @Override
- public void removeChangeListener(final ConfigFileChangeListener
configFileChangeListener) {
-
- }
-
- @Override
- public String getNamespace() {
- return namespace;
- }
-
- @Override
- public String getFileGroup() {
- return fileGroup;
- }
-
- /**
- * set file name.
- * @param fileName fileName
- */
- public void setFileName(final String fileName) {
- this.fileName = fileName;
- }
-
- @Override
- public String getFileName() {
- return fileName;
- }
-
- @Override
- public boolean equals(final Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof ConfigFileMetadata)) {
- return false;
- }
- final ConfigFileMetadata that = (ConfigFileMetadata) o;
- return Objects.equals(getNamespace(), that.getNamespace()) &&
Objects.equals(getFileGroup(), that.getFileGroup())
- && Objects.equals(getFileName(), that.getFileName());
- }
-
- @Override
- public int hashCode() {
- return com.google.common.base.Objects.hashCode(getNamespace(),
getFileGroup(), getFileName());
- }
-
- @Override
- public String getProperty(final String key, final String defaultValue) {
- return properties.getProperty(key, defaultValue);
- }
-
- @Override
- public Integer getIntProperty(final String key, final Integer
defaultValue) {
- return Integer.valueOf(getProperty(key,
Integer.toString(defaultValue)));
- }
-
- @Override
- public Long getLongProperty(final String key, final Long defaultValue) {
- return Long.valueOf(getProperty(key, Long.toString(defaultValue)));
- }
-
- @Override
- public Short getShortProperty(final String key, final Short defaultValue) {
- return Short.valueOf(getProperty(key, Short.toString(defaultValue)));
- }
-
- @Override
- public Float getFloatProperty(final String key, final Float defaultValue) {
- return Float.valueOf(getProperty(key, Float.toString(defaultValue)));
- }
-
- @Override
- public Double getDoubleProperty(final String key, final Double
defaultValue) {
- return Double.valueOf(getProperty(key, Double.toString(defaultValue)));
- }
-
- @Override
- public Byte getByteProperty(final String key, final Byte defaultValue) {
- return Byte.valueOf(getProperty(key, Byte.toString(defaultValue)));
- }
-
- @Override
- public Boolean getBooleanProperty(final String key, final Boolean
defaultValue) {
- return Boolean.valueOf(getProperty(key,
Boolean.toString(defaultValue)));
- }
-
- @Override
- public String[] getArrayProperty(final String key, final String delimiter,
final String[] defaultValue) {
- return new String[0];
- }
-
- @Override
- public <T extends Enum<T>> T getEnumProperty(final String key, final
Class<T> enumType, final T defaultValue) {
- return null;
- }
-
- @Override
- public <T> T getJsonProperty(final String key, final Class<T> clazz, final
T defaultValue) {
- return null;
- }
-
- @Override
- public <T> T getJsonProperty(final String key, final Type typeOfT, final T
defaultValue) {
- return null;
- }
-
- @Override
- public Set<String> getPropertyNames() {
- return null;
- }
-
-}
diff --git
a/shenyu-sync-data-center/shenyu-sync-data-polaris/src/test/java/org/apache/shenyu/sync/data/polaris/handler/PolarisMockConfigService.java
b/shenyu-sync-data-center/shenyu-sync-data-polaris/src/test/java/org/apache/shenyu/sync/data/polaris/handler/PolarisMockConfigService.java
deleted file mode 100644
index 79e04a3c2a..0000000000
---
a/shenyu-sync-data-center/shenyu-sync-data-polaris/src/test/java/org/apache/shenyu/sync/data/polaris/handler/PolarisMockConfigService.java
+++ /dev/null
@@ -1,111 +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.polaris.handler;
-
-import com.tencent.polaris.api.exception.ServerCodes;
-import com.tencent.polaris.api.plugin.configuration.ConfigFile;
-import com.tencent.polaris.api.plugin.configuration.ConfigFileResponse;
-import com.tencent.polaris.configuration.api.core.ConfigFileMetadata;
-import com.tencent.polaris.configuration.api.core.ConfigFilePublishService;
-import com.tencent.polaris.configuration.api.core.ConfigFileService;
-import com.tencent.polaris.configuration.api.core.ConfigKVFile;
-import
com.tencent.polaris.configuration.client.internal.DefaultConfigFileMetadata;
-import java.util.Map;
-
-public class PolarisMockConfigService implements ConfigFilePublishService,
ConfigFileService {
-
- private final Map<ConfigFileMetadata, String> store;
-
- public PolarisMockConfigService(final Map<ConfigFileMetadata, String>
store) {
- this.store = store;
- }
-
- @Override
- public ConfigFileResponse createConfigFile(final String namespace, final
String fileGroup, final String fileName, final String content) {
- final DefaultConfigFileMetadata configFileMetadata = new
DefaultConfigFileMetadata(namespace, fileGroup, fileName);
- store.put(configFileMetadata, content);
- final ConfigFile configFile = new ConfigFile(namespace, fileGroup,
fileName);
- configFile.setContent(content);
- return new ConfigFileResponse(ServerCodes.EXECUTE_SUCCESS, "success",
configFile);
- }
-
- @Override
- public ConfigFileResponse createConfigFile(final ConfigFileMetadata
configFileMetadata, final String content) {
- return createConfigFile(configFileMetadata.getNamespace(),
configFileMetadata.getFileGroup(), configFileMetadata.getFileName(), content);
- }
-
- @Override
- public ConfigFileResponse updateConfigFile(final String namespace, final
String fileGroup, final String fileName, final String content) {
- final DefaultConfigFileMetadata configFileMetadata = new
DefaultConfigFileMetadata(namespace, fileGroup, fileName);
- store.put(configFileMetadata, content);
- final ConfigFile configFile =
- new ConfigFile(namespace, fileGroup, fileName);
- configFile.setContent(content);
- return new ConfigFileResponse(ServerCodes.EXECUTE_SUCCESS, "success",
configFile);
- }
-
- @Override
- public ConfigFileResponse updateConfigFile(final ConfigFileMetadata
configFileMetadata, final String content) {
- return updateConfigFile(configFileMetadata.getNamespace(),
configFileMetadata.getFileGroup(), configFileMetadata.getFileName(), content);
- }
-
- @Override
- public ConfigFileResponse releaseConfigFile(final String namespace, final
String fileGroup, final String fileName) {
- final DefaultConfigFileMetadata configFileMetadata = new
DefaultConfigFileMetadata(namespace, fileGroup, fileName);
- final ConfigFile configFile = new ConfigFile(namespace, fileGroup,
fileName);
- configFile.setContent(store.getOrDefault(configFileMetadata, "{}"));
- return new ConfigFileResponse(ServerCodes.EXECUTE_SUCCESS, "success",
configFile);
- }
-
- @Override
- public ConfigFileResponse releaseConfigFile(final ConfigFileMetadata
configFileMetadata) {
- return releaseConfigFile(configFileMetadata.getNamespace(),
configFileMetadata.getFileGroup(), configFileMetadata.getFileName());
- }
-
- @Override
- public ConfigKVFile getConfigPropertiesFile(final String namespace, final
String fileGroup, final String fileName) {
- final DefaultConfigFileMetadata configFileMetadata = new
DefaultConfigFileMetadata(namespace, fileGroup, fileName);
- return new PolarisMockConfigFile(configFileMetadata,
store.getOrDefault(configFileMetadata, "{}"));
- }
-
- @Override
- public ConfigKVFile getConfigPropertiesFile(final ConfigFileMetadata
configFileMetadata) {
- return getConfigPropertiesFile(configFileMetadata.getNamespace(),
configFileMetadata.getFileGroup(), configFileMetadata.getFileName());
- }
-
- @Override
- public ConfigKVFile getConfigYamlFile(final String namespace, final String
fileGroup, final String fileName) {
- final DefaultConfigFileMetadata configFileMetadata = new
DefaultConfigFileMetadata(namespace, fileGroup, fileName);
- return new PolarisMockConfigFile(configFileMetadata,
store.getOrDefault(configFileMetadata, "{}"));
- }
-
- @Override
- public ConfigKVFile getConfigYamlFile(final ConfigFileMetadata
configFileMetadata) {
- return getConfigYamlFile(configFileMetadata.getNamespace(),
configFileMetadata.getFileGroup(), configFileMetadata.getFileName());
- }
-
- @Override
- public com.tencent.polaris.configuration.api.core.ConfigFile
getConfigFile(final String namespace, final String fileGroup, final String
fileName) {
- return getConfigFile(new DefaultConfigFileMetadata(namespace,
fileGroup, fileName));
- }
-
- @Override
- public com.tencent.polaris.configuration.api.core.ConfigFile
getConfigFile(final ConfigFileMetadata configFileMetadata) {
- return new PolarisMockConfigFile(configFileMetadata,
store.getOrDefault(configFileMetadata, null));
- }
-}