Repository navigation
Store last successful MS host for agent reconnection fallback #14002
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
Open
Pearl1594
wants to merge
6
commits into
4.20
Choose a base branch
from
store-lastsuccessful-MS
base: 4.20
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
6 commits
Select commit
Hold shift + click to select a range
a4d05c2
Store last successful MS host for agent reconnection fallback
mprokopchuk f064f5d
Addressed code review comments
mprokopchuk ab30cf8
Potential fix for pull request finding
mprokopchuk 3ee9608
remove unused import
Pearl1594 d42e2aa
fix test
Pearl1594 24ae1f0
address comment on log
Pearl1594 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| import java.lang.reflect.Constructor; | ||
| import java.lang.reflect.InvocationTargetException; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.Enumeration; | ||
| import java.util.HashMap; | ||
|
|
@@ -154,7 +155,27 @@ public void resetHostCounter() { | |
|
|
||
| @Override | ||
| public String[] getHosts() { | ||
| return _host.split(","); | ||
| String lastSetupCompletedHost = getLastSetupCompletedHost(); | ||
| String host; | ||
| // Add the last successful setup host as a fallback option at the end of the host list. | ||
| // This host is tried only after all configured hosts have failed, providing a | ||
| // last-resort connection option since this host previously completed setup successfully. | ||
| if (StringUtils.isNotBlank(lastSetupCompletedHost) && StringUtils.isNotBlank(_host)) { | ||
| final String candidate = lastSetupCompletedHost.trim(); | ||
| // Match against the exact comma-separated entries so a substring (e.g. 10.0.0.1 in | ||
| // 10.0.0.10) does not wrongly suppress the fallback. | ||
| final boolean alreadyPresent = Arrays.stream(_host.split(",")) | ||
| .map(String::trim) | ||
| .anyMatch(candidate::equalsIgnoreCase); | ||
| host = alreadyPresent ? _host : _host + "," + candidate; | ||
| if (!alreadyPresent) { | ||
| LOGGER.warn("Using last successful host [{}] as fallback; it is not in the configured host list [{}]", candidate, _host); | ||
| } | ||
| } else { | ||
| host = _host; | ||
| } | ||
|
Comment on lines
+160
to
+176
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these can be top of method comments. If the Override's behaviour is special for |
||
|
|
||
| return host.split(","); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -464,6 +485,26 @@ public Integer getSslHandshakeTimeout() { | |
| return AgentPropertiesFileHandler.getPropertyValue(AgentProperties.SSL_HANDSHAKE_TIMEOUT); | ||
| } | ||
|
|
||
| @Override | ||
| public void setLastSetupCompletedHost(String host) { | ||
| if (StringUtils.isNotBlank(host)) { | ||
| setPersistentProperty(null, AgentProperties.LAST_SETUP_COMPLETED_HOST.getName(), host); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Gets the last host where the agent successfully completed its setup process | ||
| * and received a Ready command. | ||
| * | ||
| * @return the hostname or IP address of the last successfully setup host, or null if none exists | ||
| */ | ||
| private String getLastSetupCompletedHost() { | ||
| if (_storage != null) { | ||
| return getPersistentProperty(null, AgentProperties.LAST_SETUP_COMPLETED_HOST.getName()); | ||
| } | ||
| return AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LAST_SETUP_COMPLETED_HOST); | ||
| } | ||
|
|
||
| public synchronized int getNextAgentId() { | ||
| return _nextAgentId++; | ||
| } | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
should we log a warning when the agent ends up on this fallback host? otherwise the hosts show up again and nobody notices the host list is still wrong