DaanHoogland commented on code in PR #14002:
URL: https://github.com/apache/cloudstack/pull/14002#discussion_r4357287843
##########
agent/src/main/java/com/cloud/agent/AgentShell.java:
##########
@@ -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;
+ }
Review Comment:
I think these can be top of method comments. If the Override's behaviour is
special for `getHosts()` it should be mentioned there anyway.
The matching comment can be a separate testable method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]