-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support incremental configuration synchronization client #5288
Open
jackie-coming
wants to merge
20
commits into
apolloconfig:master
Choose a base branch
from
jackie-coming:feautre/IncrementalSync
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4e8a699
init
jackie-coming 26a0e1b
init config
jackie-coming 2dd9352
code review
jackie-coming b13968c
add test
jackie-coming 24bda1d
add test
jackie-coming cf5145f
add test
jackie-coming 8cafda2
code format
jackie-coming 72676c0
code format
jackie-coming 065a092
feat: support incremental configuration synchronization client
jackie-coming e69f098
Merge remote-tracking branch 'origin/feautre/IncrementalSync' into fe…
jackie-coming a6a412a
code format
jackie-coming 07bb41c
feat: support incremental configuration synchronization client
jackie-coming a4b356c
code format
jackie-coming 5e37f55
update pom version
jackie-coming 8512776
code format
jackie-coming 5a76da9
code format
jackie-coming a4a2d05
code format
jackie-coming 04f50ac
Merge branch 'master' into feautre/IncrementalSync
nobodyiam 1b20e4e
update flag
jackie-coming 4f06613
Merge remote-tracking branch 'origin/feautre/IncrementalSync' into fe…
jackie-coming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,16 @@ | |
import com.ctrip.framework.apollo.core.ConfigConsts; | ||
import com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages; | ||
|
||
import com.ctrip.framework.apollo.core.dto.ConfigurationChange; | ||
import com.google.common.base.Strings; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.google.common.collect.Sets; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author Jason Song([email protected]) | ||
|
@@ -93,6 +100,52 @@ private Release findRelease(String clientAppId, String clientIp, String clientLa | |
return release; | ||
} | ||
|
||
public List<ConfigurationChange> calcConfigurationChanges( | ||
Map<String, String> latestReleaseConfigurations, Map<String, String> historyConfigurations) { | ||
if (latestReleaseConfigurations == null) { | ||
latestReleaseConfigurations = new HashMap<>(); | ||
} | ||
|
||
if (historyConfigurations == null) { | ||
historyConfigurations = new HashMap<>(); | ||
} | ||
|
||
Set<String> previousKeys = historyConfigurations.keySet(); | ||
Set<String> currentKeys = latestReleaseConfigurations.keySet(); | ||
|
||
Set<String> commonKeys = Sets.intersection(previousKeys, currentKeys); | ||
Set<String> newKeys = Sets.difference(currentKeys, commonKeys); | ||
Set<String> removedKeys = Sets.difference(previousKeys, commonKeys); | ||
|
||
List<ConfigurationChange> changes = Lists.newArrayList(); | ||
|
||
for (String newKey : newKeys) { | ||
changes.add(new ConfigurationChange(newKey, latestReleaseConfigurations.get(newKey), | ||
"ADDED")); | ||
} | ||
|
||
for (String removedKey : removedKeys) { | ||
changes.add(new ConfigurationChange(removedKey, null, "DELETED")); | ||
} | ||
|
||
for (String commonKey : commonKeys) { | ||
String previousValue = historyConfigurations.get(commonKey); | ||
String currentValue = latestReleaseConfigurations.get(commonKey); | ||
if (com.google.common.base.Objects.equal(previousValue, currentValue)) { | ||
continue; | ||
} | ||
changes.add( | ||
new ConfigurationChange(commonKey, currentValue, "MODIFIED")); | ||
} | ||
|
||
return changes; | ||
} | ||
|
||
@Override | ||
public Map<String, Release> findReleasesByReleaseKeys(Set<String> releaseKeys) { | ||
return null; | ||
} | ||
|
||
/** | ||
* Find active release by id | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
/** | ||
* @author Jason Song([email protected]) | ||
*/ | ||
public interface ConfigService extends ReleaseMessageListener { | ||
public interface ConfigService extends ReleaseMessageListener, IncrementalSyncConfigService { | ||
|
||
/** | ||
* Load config | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for configuration change calculation
The configuration change calculation lacks error handling for potential failures.
Add try-catch block:
📝 Committable suggestion