Damans227 commented on code in PR #14002:
URL: https://github.com/apache/cloudstack/pull/14002#discussion_r4270876378


##########
agent/src/main/java/com/cloud/agent/AgentShell.java:
##########
@@ -154,7 +155,24 @@ 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;

Review Comment:
   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



-- 
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]

Reply via email to