Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<nexus.staging.plugin.version>1.6.7</nexus.staging.plugin.version>
<central.publishing.maven.plugin.version>0.5.0</central.publishing.maven.plugin.version>
<frontend.plugin.version>1.12.1</frontend.plugin.version>
<apollo.version>2.4.0</apollo.version>

<sermant.name>sermant-agent</sermant.name>
<sermant.basedir>${pom.basedir}</sermant.basedir>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
* @since 2021-12-27
*/
public enum DynamicConfigServiceType {

/**
* apollo configuration center
*/
APOLLO,
/**
* zookeeper configuration center
*/
Expand Down
59 changes: 59 additions & 0 deletions sermant-agentcore/sermant-agentcore-implement/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@
<artifactId>zookeeper</artifactId>
<version>${zookeeper.version}</version>
</dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>${apollo.version}</version>
</dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-openapi</artifactId>
<version>${apollo.version}</version>
</dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-core</artifactId>
<version>${apollo.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
Expand Down Expand Up @@ -345,6 +360,50 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<executions>
<execution>
<id>apollo-test-isolated</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<includes>
<include>**/ApolloDynamicConfigServiceTest.java</include>
</includes>
<excludes>
</excludes>
</configuration>
</execution>

<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
<excludes>
<exclude>**/ApolloDynamicConfigServiceTest.java</exclude>
</excludes>
<includes>
<include>**/*Test.java</include>
<include>**/*Tests.java</include>
<include>**/*TestCase.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import io.sermant.core.service.dynamicconfig.DynamicConfigService;
import io.sermant.core.service.dynamicconfig.common.DynamicConfigListener;
import io.sermant.implement.service.dynamicconfig.apollo.ApolloDynamicConfigService;
import io.sermant.implement.service.dynamicconfig.kie.KieDynamicConfigService;
import io.sermant.implement.service.dynamicconfig.nacos.NacosDynamicConfigService;
import io.sermant.implement.service.dynamicconfig.zookeeper.ZooKeeperDynamicConfigService;
Expand Down Expand Up @@ -50,6 +51,9 @@ public BufferedDynamicConfigService() {
case NACOS:
service = new NacosDynamicConfigService();
break;
case APOLLO:
service = new ApolloDynamicConfigService();
break;
default:
service = new ZooKeeperDynamicConfigService();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Copyright (C) 2025-2025 Sermant Authors. All rights reserved.
*
* Licensed 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 io.sermant.implement.service.dynamicconfig.apollo;

import com.ctrip.framework.apollo.ConfigChangeListener;

import java.io.Closeable;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

/**
* wraps the Apollo open apis and client to provides easier apis
*
* @author Chen Zhenyang
* @since 2025-08-07
*/
public class ApolloBufferedClient implements Closeable {
private static final Logger LOGGER = Logger.getLogger(ApolloBufferedClient.class.getName());
private final ApolloClient apolloClient;

/**
* constructor
*/
public ApolloBufferedClient() {
apolloClient = new ApolloClient();
}

@Override
public void close() {
apolloClient.close();
}

/**
* publish config
*
* @param key apollo key
* @param group apollo namespace
* @param content apollo value
* @return check if publish success
*/
public boolean publishConfig(String key, String group, String content) {
return apolloClient.publishConfig(key, group, content);
}

/**
* remove config
*
* @param key apollo key
* @param group apollo namespace
* @return check if remove success
*/
public boolean removeConfig(String key, String group) {
return apolloClient.removeConfig(key, group);
}

/**
* get key list from group
*
* @param group apollo namespace
* @return List of keys from group
*/
public List<String> getListKeysFromGroup(String group) {
Map<String, List<String>> res = apolloClient.getConfigList(null, group, true);
return res.get(group);
}

/**
* get config
*
* @param key apollo key
* @param group apollo namespace
* @return value of the key
*/
public String getConfig(String key, String group) {
return apolloClient.getConfig(key, group);
}

/**
* add group listener
*
* @param group apollo namespace
* @param apolloListener apollo listener
* @return check if add group listener success
*/
public boolean addGroupListener(String group, ConfigChangeListener apolloListener) {
return apolloClient.addGroupListener(group, apolloListener);
}

/**
* add config listener
*
* @param key apollo key
* @param group apollo namespace
* @param apolloListener apollo listener
* @return check if add config listener success
*/
public boolean addConfigListener(String key, String group, ConfigChangeListener apolloListener) {
return apolloClient.addConfigListener(key, group, apolloListener);
}

/**
* remove listener
*
* @param validGroup apollo namespace
* @param ccl apollo listener
* @return check if remove listener success
*/
public boolean removeConfigListener(String validGroup, ConfigChangeListener ccl) {
return apolloClient.removeConfigListener(validGroup, ccl);
}
}
Loading
Loading