Skip to content

Commit 8243686

Browse files
authored
Merge pull request #1808 from aaaandychen/apollo-dynamic-config
feat(dynamic config): implement apollo dynamic config crud methods
2 parents 28d6c76 + bfa664b commit 8243686

File tree

17 files changed

+1706
-0
lines changed

17 files changed

+1706
-0
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
<nexus.staging.plugin.version>1.6.7</nexus.staging.plugin.version>
8686
<central.publishing.maven.plugin.version>0.5.0</central.publishing.maven.plugin.version>
8787
<frontend.plugin.version>1.12.1</frontend.plugin.version>
88+
<apollo.version>2.4.0</apollo.version>
8889

8990
<sermant.name>sermant-agent</sermant.name>
9091
<sermant.basedir>${pom.basedir}</sermant.basedir>

sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/dynamicconfig/common/DynamicConfigServiceType.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
* @since 2021-12-27
2424
*/
2525
public enum DynamicConfigServiceType {
26+
27+
/**
28+
* apollo configuration center
29+
*/
30+
APOLLO,
2631
/**
2732
* zookeeper configuration center
2833
*/

sermant-agentcore/sermant-agentcore-implement/pom.xml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@
126126
<artifactId>zookeeper</artifactId>
127127
<version>${zookeeper.version}</version>
128128
</dependency>
129+
<dependency>
130+
<groupId>com.ctrip.framework.apollo</groupId>
131+
<artifactId>apollo-client</artifactId>
132+
<version>${apollo.version}</version>
133+
</dependency>
134+
<dependency>
135+
<groupId>com.ctrip.framework.apollo</groupId>
136+
<artifactId>apollo-openapi</artifactId>
137+
<version>${apollo.version}</version>
138+
</dependency>
139+
<dependency>
140+
<groupId>com.ctrip.framework.apollo</groupId>
141+
<artifactId>apollo-core</artifactId>
142+
<version>${apollo.version}</version>
143+
</dependency>
129144
<dependency>
130145
<groupId>com.alibaba.nacos</groupId>
131146
<artifactId>nacos-client</artifactId>
@@ -345,6 +360,50 @@
345360
</execution>
346361
</executions>
347362
</plugin>
363+
364+
<plugin>
365+
<groupId>org.apache.maven.plugins</groupId>
366+
<artifactId>maven-surefire-plugin</artifactId>
367+
<version>3.0.0-M5</version>
368+
<executions>
369+
<execution>
370+
<id>apollo-test-isolated</id>
371+
<phase>test</phase>
372+
<goals>
373+
<goal>test</goal>
374+
</goals>
375+
<configuration>
376+
<forkCount>1</forkCount>
377+
<reuseForks>false</reuseForks>
378+
<includes>
379+
<include>**/ApolloDynamicConfigServiceTest.java</include>
380+
</includes>
381+
<excludes>
382+
</excludes>
383+
</configuration>
384+
</execution>
385+
386+
<execution>
387+
<id>default-test</id>
388+
<phase>test</phase>
389+
<goals>
390+
<goal>test</goal>
391+
</goals>
392+
<configuration>
393+
<forkCount>1</forkCount>
394+
<reuseForks>true</reuseForks>
395+
<excludes>
396+
<exclude>**/ApolloDynamicConfigServiceTest.java</exclude>
397+
</excludes>
398+
<includes>
399+
<include>**/*Test.java</include>
400+
<include>**/*Tests.java</include>
401+
<include>**/*TestCase.java</include>
402+
</includes>
403+
</configuration>
404+
</execution>
405+
</executions>
406+
</plugin>
348407
</plugins>
349408
</build>
350409
</project>

sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/service/dynamicconfig/BufferedDynamicConfigService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import io.sermant.core.service.dynamicconfig.DynamicConfigService;
2020
import io.sermant.core.service.dynamicconfig.common.DynamicConfigListener;
21+
import io.sermant.implement.service.dynamicconfig.apollo.ApolloDynamicConfigService;
2122
import io.sermant.implement.service.dynamicconfig.kie.KieDynamicConfigService;
2223
import io.sermant.implement.service.dynamicconfig.nacos.NacosDynamicConfigService;
2324
import io.sermant.implement.service.dynamicconfig.zookeeper.ZooKeeperDynamicConfigService;
@@ -50,6 +51,9 @@ public BufferedDynamicConfigService() {
5051
case NACOS:
5152
service = new NacosDynamicConfigService();
5253
break;
54+
case APOLLO:
55+
service = new ApolloDynamicConfigService();
56+
break;
5357
default:
5458
service = new ZooKeeperDynamicConfigService();
5559
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Copyright (C) 2025-2025 Sermant Authors. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.sermant.implement.service.dynamicconfig.apollo;
18+
19+
import com.ctrip.framework.apollo.ConfigChangeListener;
20+
21+
import java.io.Closeable;
22+
import java.util.List;
23+
import java.util.Map;
24+
import java.util.logging.Logger;
25+
26+
/**
27+
* wraps the Apollo open apis and client to provides easier apis
28+
*
29+
* @author Chen Zhenyang
30+
* @since 2025-08-07
31+
*/
32+
public class ApolloBufferedClient implements Closeable {
33+
private static final Logger LOGGER = Logger.getLogger(ApolloBufferedClient.class.getName());
34+
private final ApolloClient apolloClient;
35+
36+
/**
37+
* constructor
38+
*/
39+
public ApolloBufferedClient() {
40+
apolloClient = new ApolloClient();
41+
}
42+
43+
@Override
44+
public void close() {
45+
apolloClient.close();
46+
}
47+
48+
/**
49+
* publish config
50+
*
51+
* @param key apollo key
52+
* @param group apollo namespace
53+
* @param content apollo value
54+
* @return check if publish success
55+
*/
56+
public boolean publishConfig(String key, String group, String content) {
57+
return apolloClient.publishConfig(key, group, content);
58+
}
59+
60+
/**
61+
* remove config
62+
*
63+
* @param key apollo key
64+
* @param group apollo namespace
65+
* @return check if remove success
66+
*/
67+
public boolean removeConfig(String key, String group) {
68+
return apolloClient.removeConfig(key, group);
69+
}
70+
71+
/**
72+
* get key list from group
73+
*
74+
* @param group apollo namespace
75+
* @return List of keys from group
76+
*/
77+
public List<String> getListKeysFromGroup(String group) {
78+
Map<String, List<String>> res = apolloClient.getConfigList(null, group, true);
79+
return res.get(group);
80+
}
81+
82+
/**
83+
* get config
84+
*
85+
* @param key apollo key
86+
* @param group apollo namespace
87+
* @return value of the key
88+
*/
89+
public String getConfig(String key, String group) {
90+
return apolloClient.getConfig(key, group);
91+
}
92+
93+
/**
94+
* add group listener
95+
*
96+
* @param group apollo namespace
97+
* @param apolloListener apollo listener
98+
* @return check if add group listener success
99+
*/
100+
public boolean addGroupListener(String group, ConfigChangeListener apolloListener) {
101+
return apolloClient.addGroupListener(group, apolloListener);
102+
}
103+
104+
/**
105+
* add config listener
106+
*
107+
* @param key apollo key
108+
* @param group apollo namespace
109+
* @param apolloListener apollo listener
110+
* @return check if add config listener success
111+
*/
112+
public boolean addConfigListener(String key, String group, ConfigChangeListener apolloListener) {
113+
return apolloClient.addConfigListener(key, group, apolloListener);
114+
}
115+
116+
/**
117+
* remove listener
118+
*
119+
* @param validGroup apollo namespace
120+
* @param ccl apollo listener
121+
* @return check if remove listener success
122+
*/
123+
public boolean removeConfigListener(String validGroup, ConfigChangeListener ccl) {
124+
return apolloClient.removeConfigListener(validGroup, ccl);
125+
}
126+
}

0 commit comments

Comments
 (0)