Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feautre/Incremental…
Browse files Browse the repository at this point in the history
…Sync

# Conflicts:
#	pom.xml
  • Loading branch information
jackie-coming committed Dec 8, 2024
2 parents f654cb3 + d4b76f8 commit 44b70fa
Show file tree
Hide file tree
Showing 183 changed files with 8,894 additions and 906 deletions.
16 changes: 9 additions & 7 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ Changes by Version
==================
Release Notes.

Apollo Java 2.2.0
Apollo Java 2.4.0

------------------
* [refactor(apollo-client): Optimize the exception message when failing to retrieve configuration information.](https://github.com/apolloconfig/apollo-java/pull/22)
* [Add JUnit5 extension support for apollo mock server.](https://github.com/apolloconfig/apollo-java/pull/25)
* [Support concurrent loading of Config for different namespaces.](https://github.com/apolloconfig/apollo-java/pull/31)
* [Fix snakeyaml 2.x compatibility issues](https://github.com/apolloconfig/apollo-java/pull/35)
* [feat(openapi): create app](https://github.com/apolloconfig/apollo-java/pull/32)

* [Fix the Cannot enhance @Configuration bean definition issue](https://github.com/apolloconfig/apollo-java/pull/82)
* [Feature openapi query namespace support not fill item](https://github.com/apolloconfig/apollo-java/pull/83)
* [Add more observability in apollo config client](https://github.com/apolloconfig/apollo-java/pull/74)
* [Feature Support Kubernetes ConfigMap cache for Apollo java, golang client](https://github.com/apolloconfig/apollo-java/pull/79)
* [Feature support pulling configuration information from multiple AppIds](https://github.com/apolloconfig/apollo-java/pull/70)


------------------
All issues and pull requests are [here](https://github.com/apolloconfig/apollo-java/milestone/2?closed=1)
All issues and pull requests are [here](https://github.com/apolloconfig/apollo-java/milestone/4?closed=1)
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ public PureApolloConfig(String namespace,
super(namespace, configRepository);
}

/**
* Constructor.
*
* @param appId the appId of this config instance
* @param namespace the namespace of this config instance
* @param configRepository the config repository for this config instance
*/
public PureApolloConfig(String appId, String namespace,
ConfigRepository configRepository) {
super(appId, namespace, configRepository);
}

@Override
public String getProperty(String key, String defaultValue) {
// step 1: check local cached properties file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class PureApolloConfigFactory extends DefaultConfigFactory implements ConfigFactory {

@Override
protected Config createRepositoryConfig(String namespace, ConfigRepository configRepository) {
return new PureApolloConfig(namespace, configRepository);
protected Config createRepositoryConfig(String appId, String namespace, ConfigRepository configRepository) {
return new PureApolloConfig(appId, namespace, configRepository);
}
}
21 changes: 21 additions & 0 deletions apollo-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java</artifactId>
<optional>true</optional>
</dependency>
<!-- test -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
Expand All @@ -92,6 +97,22 @@
<artifactId>log4j-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-netty</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.noconnor</groupId>
<artifactId>junitperf</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- end of test -->
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public interface ConfigFile {
*/
boolean hasContent();

/**
* Get the appId of this config file instance
* @return the appId
*
* @since 2.4.0
*/
default String getAppId(){
return null;
}

/**
* Get the namespace of this config file instance
* @return the namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.core.utils.StringUtils;
import com.ctrip.framework.apollo.internals.ConfigManager;
import com.ctrip.framework.apollo.internals.ConfigMonitorInitializer;
import com.ctrip.framework.apollo.monitor.api.ConfigMonitor;
import com.ctrip.framework.apollo.spi.ConfigFactory;
import com.ctrip.framework.apollo.spi.ConfigRegistry;
import com.ctrip.framework.apollo.util.ConfigUtil;

/**
* Entry point for client config use
Expand All @@ -30,19 +34,31 @@
*/
public class ConfigService {
private static final ConfigService s_instance = new ConfigService();

private volatile ConfigMonitor m_configMonitor;
private volatile ConfigManager m_configManager;
private volatile ConfigRegistry m_configRegistry;


private ConfigMonitor getMonitor() {
getManager();
if (m_configMonitor == null) {
synchronized (this) {
if (m_configMonitor == null) {
m_configMonitor = ApolloInjector.getInstance(ConfigMonitor.class);
}
}
}
return m_configMonitor;
}

private ConfigManager getManager() {
if (m_configManager == null) {
synchronized (this) {
if (m_configManager == null) {
m_configManager = ApolloInjector.getInstance(ConfigManager.class);
ConfigMonitorInitializer.initialize();
}
}
}

return m_configManager;
}

Expand Down Expand Up @@ -77,10 +93,18 @@ public static Config getConfig(String namespace) {
return s_instance.getManager().getConfig(namespace);
}

public static Config getConfig(String appId, String namespace) {
return s_instance.getManager().getConfig(appId, namespace);
}

public static ConfigFile getConfigFile(String namespace, ConfigFileFormat configFileFormat) {
return s_instance.getManager().getConfigFile(namespace, configFileFormat);
}

public static ConfigMonitor getConfigMonitor(){
return s_instance.getMonitor();
}

static void setConfig(Config config) {
setConfig(ConfigConsts.NAMESPACE_APPLICATION, config);
}
Expand All @@ -93,16 +117,32 @@ static void setConfig(Config config) {
*/
static void setConfig(String namespace, final Config config) {
s_instance.getRegistry().register(namespace, new ConfigFactory() {

private final ConfigUtil m_configUtil = ApolloInjector.getInstance(ConfigUtil.class);

@Override
public Config create(String namespace) {
return config;
}

@Override
public Config create(String appId, String namespace) {
if(!StringUtils.equals(appId, m_configUtil.getAppId())){
throw new IllegalArgumentException("Provided appId '" + appId + "' does not match the default appId '" + m_configUtil.getAppId() + "'");
}
return config;
}

@Override
public ConfigFile createConfigFile(String namespace, ConfigFileFormat configFileFormat) {
return null;
}

@Override
public ConfigFile createConfigFile(String appId, String namespace, ConfigFileFormat configFileFormat) {
return null;
}

});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
* @since 1.1.0
*/
public enum ConfigSourceType {
REMOTE("Loaded from remote config service"), LOCAL("Loaded from local cache"), NONE("Load failed");
REMOTE("Loaded from remote config service"),
LOCAL("Loaded from local cache"),
CONFIGMAP("Loaded from k8s config map"),
NONE("Load failed");

private final String description;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
public abstract class AbstractConfig implements Config {
private static final Logger logger = LoggerFactory.getLogger(AbstractConfig.class);

private static final ExecutorService m_executorService;
protected static final ExecutorService m_executorService;

private final List<ConfigChangeListener> m_listeners = Lists.newCopyOnWriteArrayList();
private final Map<ConfigChangeListener, Set<String>> m_interestedKeys = Maps.newConcurrentMap();
Expand Down Expand Up @@ -454,15 +454,15 @@ protected void clearConfigCache() {
/**
* @param changes map's key is config property's key
*/
protected void fireConfigChange(String namespace, Map<String, ConfigChange> changes) {
protected void fireConfigChange(String appId, String namespace, Map<String, ConfigChange> changes) {
final Set<String> changedKeys = changes.keySet();
final List<ConfigChangeListener> listeners = this.findMatchedConfigChangeListeners(changedKeys);

// notify those listeners
for (ConfigChangeListener listener : listeners) {
Set<String> interestedChangedKeys = resolveInterestedChangedKeys(listener, changedKeys);
InterestedConfigChangeEvent interestedConfigChangeEvent = new InterestedConfigChangeEvent(
namespace, changes, interestedChangedKeys);
appId, namespace, changes, interestedChangedKeys);
this.notifyAsync(listener, interestedConfigChangeEvent);
}
}
Expand Down Expand Up @@ -567,7 +567,7 @@ private Set<String> resolveInterestedChangedKeys(ConfigChangeListener configChan
return Collections.unmodifiableSet(interestedChangedKeys);
}

List<ConfigChange> calcPropertyChanges(String namespace, Properties previous,
List<ConfigChange> calcPropertyChanges(String appId, String namespace, Properties previous,
Properties current) {
if (previous == null) {
previous = propertiesFactory.getPropertiesInstance();
Expand All @@ -587,12 +587,12 @@ List<ConfigChange> calcPropertyChanges(String namespace, Properties previous,
List<ConfigChange> changes = Lists.newArrayList();

for (String newKey : newKeys) {
changes.add(new ConfigChange(namespace, newKey, null, current.getProperty(newKey),
changes.add(new ConfigChange(appId, namespace, newKey, null, current.getProperty(newKey),
PropertyChangeType.ADDED));
}

for (String removedKey : removedKeys) {
changes.add(new ConfigChange(namespace, removedKey, previous.getProperty(removedKey), null,
changes.add(new ConfigChange(appId, namespace, removedKey, previous.getProperty(removedKey), null,
PropertyChangeType.DELETED));
}

Expand All @@ -602,7 +602,7 @@ List<ConfigChange> calcPropertyChanges(String namespace, Properties previous,
if (Objects.equal(previousValue, currentValue)) {
continue;
}
changes.add(new ConfigChange(namespace, commonKey, previousValue, currentValue,
changes.add(new ConfigChange(appId, namespace, commonKey, previousValue, currentValue,
PropertyChangeType.MODIFIED));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package com.ctrip.framework.apollo.internals;


import static com.ctrip.framework.apollo.monitor.internal.ApolloClientMonitorConstant.*;
import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.core.utils.DeferredLoggerFactory;
import com.ctrip.framework.apollo.enums.ConfigSourceType;
Expand Down Expand Up @@ -43,8 +45,9 @@
*/
public abstract class AbstractConfigFile implements ConfigFile, RepositoryChangeListener {
private static final Logger logger = DeferredLoggerFactory.getLogger(AbstractConfigFile.class);
private static ExecutorService m_executorService;
protected static ExecutorService m_executorService;
protected final ConfigRepository m_configRepository;
protected final String m_appId;
protected final String m_namespace;
protected final AtomicReference<Properties> m_configProperties;
private final List<ConfigFileChangeListener> m_listeners = Lists.newCopyOnWriteArrayList();
Expand All @@ -57,8 +60,9 @@ public abstract class AbstractConfigFile implements ConfigFile, RepositoryChange
.create("ConfigFile", true));
}

public AbstractConfigFile(String namespace, ConfigRepository configRepository) {
public AbstractConfigFile(String appId, String namespace, ConfigRepository configRepository) {
m_configRepository = configRepository;
m_appId = appId;
m_namespace = namespace;
m_configProperties = new AtomicReference<>();
propertiesFactory = ApolloInjector.getInstance(PropertiesFactory.class);
Expand All @@ -80,6 +84,11 @@ private void initialize() {
}
}

@Override
public String getAppId() {
return m_appId;
}

@Override
public String getNamespace() {
return m_namespace;
Expand All @@ -89,6 +98,11 @@ public String getNamespace() {

@Override
public synchronized void onRepositoryChange(String namespace, Properties newProperties) {
this.onRepositoryChange(m_appId, m_namespace, newProperties);
}

@Override
public synchronized void onRepositoryChange(String appId, String namespace, Properties newProperties) {
if (newProperties.equals(m_configProperties.get())) {
return;
}
Expand All @@ -110,9 +124,9 @@ public synchronized void onRepositoryChange(String namespace, Properties newProp
changeType = PropertyChangeType.DELETED;
}

this.fireConfigChange(new ConfigFileChangeEvent(m_namespace, oldValue, newValue, changeType));
this.fireConfigChange(new ConfigFileChangeEvent(m_appId, m_namespace, oldValue, newValue, changeType));

Tracer.logEvent("Apollo.Client.ConfigChanges", m_namespace);
Tracer.logEvent(APOLLO_CLIENT_CONFIGCHANGES, m_namespace);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.ctrip.framework.apollo.internals;

import static com.ctrip.framework.apollo.monitor.internal.ApolloClientMonitorConstant.*;
import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.util.factory.PropertiesFactory;
import java.util.List;
Expand All @@ -41,7 +42,7 @@ protected boolean trySync() {
sync();
return true;
} catch (Throwable ex) {
Tracer.logEvent("ApolloConfigException", ExceptionUtil.getDetailMessage(ex));
Tracer.logEvent(APOLLO_CONFIG_EXCEPTION, ExceptionUtil.getDetailMessage(ex));
logger
.warn("Sync config failed, will retry. Repository {}, reason: {}", this.getClass(), ExceptionUtil
.getDetailMessage(ex));
Expand All @@ -63,14 +64,19 @@ public void removeChangeListener(RepositoryChangeListener listener) {
m_listeners.remove(listener);
}

protected void fireRepositoryChange(String namespace, Properties newProperties) {
protected void fireRepositoryChange(String appId, String namespace, Properties newProperties) {
for (RepositoryChangeListener listener : m_listeners) {
try {
listener.onRepositoryChange(namespace, newProperties);
listener.onRepositoryChange(appId, namespace, newProperties);
} catch (Throwable ex) {
Tracer.logError(ex);
logger.error("Failed to invoke repository change listener {}", listener.getClass(), ex);
}
}
}

@Override
public void initialize() {
this.sync();
}
}
Loading

0 comments on commit 44b70fa

Please sign in to comment.