cloudstack-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CLOUDSTACK-10132) Multiple Management Servers Support for agents
Date Wed, 15 Nov 2017 08:53:00 GMT

    [ https://issues.apache.org/jira/browse/CLOUDSTACK-10132?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16253128#comment-16253128
] 

ASF GitHub Bot commented on CLOUDSTACK-10132:
---------------------------------------------

rhtyd commented on a change in pull request #2309: CLOUDSTACK-10132: Multiple Management Servers
Support for agents
URL: https://github.com/apache/cloudstack/pull/2309#discussion_r151064254
 
 

 ##########
 File path: agent/src/com/cloud/agent/Agent.java
 ##########
 @@ -699,16 +721,102 @@ public void processResponse(final Response response, final Link link)
{
         }
     }
 
-    public void processReadyCommand(final Command cmd) {
+    /**
+     * Checks if received list is different to actual management server list (in order and
size)
+     * @param actual actual list
+     * @param received received list
+     * @return true if list is updated, false if not
+     */
+    private boolean isReceivedListUpdated(List<String> actual, List<String> received)
{
+        if (actual.size() != received.size()) {
+            return true;
+        }
+        for (int i = 0; i < received.size(); i++) {
+            if (!received.get(i).equals(actual.get(i))) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Persist newly received management servers list
+     * @param msList management servers list
+     */
+    private void persistNewManagementServersList(List<String> msList) {
+        final String newHosts = StringUtils.toCSVList(msList);
+        _shell.setHosts(newHosts);
+        _shell.setPersistentProperty(null, "host", newHosts);
+        s_logger.info("Saved new management servers list: " + msList);
+    }
+
+    /**
+     * Try reconnecting to preferred management server after new list is received.
+     * If connection is not performed, host counter is reset
+     */
+    private void attemptReconnectionToPrimaryHost() {
+        boolean connection = false;
+        String preferred = _shell.getNextHost();
+        try {
+            if (_link != null) {
+                boolean isHostUp = true;
+                try (final Socket socket = new Socket()) {
+                    socket.connect(new InetSocketAddress(preferred, _shell.getPort()), 5000);
+                } catch (final IOException e) {
+                    isHostUp = false;
+                    if (s_logger.isDebugEnabled()) {
+                        s_logger.debug("Preferred host: " + preferred + " is not reachable");
+                    }
+                }
+                if (isHostUp && _link != null && _inProgress.get() == 0)
{
+                    if (s_logger.isDebugEnabled()) {
+                        s_logger.debug("Preferred host: " +  preferred + " is found to be
reachable, trying to reconnect");
+                    }
+                    reconnect(_link);
+                    connection = true;
+                    _shell.updateConnectedHost();
+                }
+            }
+        } catch (Exception e) {
+            s_logger.warn("Couldn't reconnect to preferred host: " + preferred + " received
on management servers list");
+        } finally {
+            if (!connection) {
+                _shell.resetHostCounter();
+            }
+        }
+    }
 
+    /**
+     * Checks if primary host on received list has changed
+     * @param currentList current hosts list
+     * @param newList new hosts list
+     * @return true if primary host has changed, false if not
+     */
+    private boolean hasPrimaryHostChanged(List<String> currentList, List<String>
newList) {
+        return !newList.get(0).equals(currentList.get(0));
+    }
+
+    public void processReadyCommand(final Command cmd) {
         final ReadyCommand ready = (ReadyCommand)cmd;
 
-        s_logger.info("Proccess agent ready command, agent id = " + ready.getHostId());
+        s_logger.info("Processing agent ready command, agent id = " + ready.getHostId());
         if (ready.getHostId() != null) {
             setId(ready.getHostId());
         }
-        s_logger.info("Ready command is processed: agent id = " + getId());
 
+        final List<String> msList = ready.getMsList();
+        if (msList != null && msList.size() > 0) {
+            final List<String> hosts = Arrays.asList(_shell.getHosts());
+            s_logger.info("Received management servers list: " + msList + ", current list:
" + hosts);
+            if (isReceivedListUpdated(hosts, msList)) {
+                persistNewManagementServersList(msList);
+                _shell.resetHostCounter();
+                if (hasPrimaryHostChanged(hosts, msList)) {
+                    attemptReconnectionToPrimaryHost();
 
 Review comment:
   @nvazquez this can be removed, the ReadyCommand handler should not be responsible for reconnection/switching.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Multiple Management Servers Support for agents
> ----------------------------------------------
>
>                 Key: CLOUDSTACK-10132
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-10132
>             Project: CloudStack
>          Issue Type: Improvement
>      Security Level: Public(Anyone can view this level - this is the default.) 
>    Affects Versions: 4.11.0.0
>            Reporter: Nicolas Vazquez
>            Assignee: Nicolas Vazquez
>
> Multiple Management Servers Support for agents



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message