This is an automated email from the ASF dual-hosted git repository.

dahn pushed a commit to branch 4.20
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.20 by this push:
     new 9f229600e6a Add new config (non-dynamic) for  agent connections 
monitor thread, and keep timeunit to secs (in sync with the earlier Wait 
config) (#10525)
9f229600e6a is described below

commit 9f229600e6a267fddaf2fd46d60533318b537e0e
Author: Suresh Kumar Anaparti <sureshkumar.anapa...@gmail.com>
AuthorDate: Mon Apr 28 19:02:03 2025 +0530

    Add new config (non-dynamic) for  agent connections monitor thread, and 
keep timeunit to secs (in sync with the earlier Wait config) (#10525)
---
 .../main/java/com/cloud/agent/AgentManager.java    |  4 +-
 .../com/cloud/agent/manager/AgentManagerImpl.java  | 47 ++++++++++------------
 .../com/cloud/vm/VirtualMachineManagerImpl.java    |  2 +-
 .../java/com/cloud/utils/nio/NioConnection.java    |  1 -
 4 files changed, 25 insertions(+), 29 deletions(-)

diff --git 
a/engine/components-api/src/main/java/com/cloud/agent/AgentManager.java 
b/engine/components-api/src/main/java/com/cloud/agent/AgentManager.java
index 81525ca13f1..b29eb38395f 100644
--- a/engine/components-api/src/main/java/com/cloud/agent/AgentManager.java
+++ b/engine/components-api/src/main/java/com/cloud/agent/AgentManager.java
@@ -37,7 +37,7 @@ import com.cloud.resource.ServerResource;
  * AgentManager manages hosts. It directly coordinates between the DAOs and 
the connections it manages.
  */
 public interface AgentManager {
-    static final ConfigKey<Integer> Wait = new ConfigKey<Integer>("Advanced", 
Integer.class, "wait", "1800", "Time in seconds to wait for control commands to 
return",
+    ConfigKey<Integer> Wait = new ConfigKey<Integer>("Advanced", 
Integer.class, "wait", "1800", "Time in seconds to wait for control commands to 
return",
             true);
     ConfigKey<Boolean> EnableKVMAutoEnableDisable = new 
ConfigKey<>(Boolean.class,
                     "enable.kvm.host.auto.enable.disable",
@@ -54,7 +54,7 @@ public interface AgentManager {
             "This timeout overrides the wait global config. This holds a comma 
separated key value pairs containing timeout (in seconds) for specific 
commands. " +
                     "For example: DhcpEntryCommand=600, 
SavePasswordCommand=300, VmDataCommand=300", false);
 
-    public enum TapAgentsAction {
+    enum TapAgentsAction {
         Add, Del, Contains,
     }
 
diff --git 
a/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java
 
b/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java
index 592d4567805..1abb78b32e9 100644
--- 
a/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java
+++ 
b/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java
@@ -51,8 +51,8 @@ import 
org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext;
 import org.apache.cloudstack.managed.context.ManagedContextRunnable;
 import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao;
 import org.apache.cloudstack.utils.identity.ManagementServerNode;
-import org.apache.commons.collections.MapUtils;
 import 
org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
+import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang3.BooleanUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.logging.log4j.ThreadContext;
@@ -210,6 +210,8 @@ public class AgentManagerImpl extends ManagerBase 
implements AgentManager, Handl
             "Number of maximum concurrent new connections server allows for 
remote agents. " +
                     "If set to zero (default value) then no limit will be 
enforced on concurrent new connections",
             false);
+    protected final ConfigKey<Integer> 
RemoteAgentNewConnectionsMonitorInterval = new ConfigKey<>("Advanced", 
Integer.class, "agent.connections.monitor.interval", "1800",
+            "Time in seconds to monitor the new agent connections and cleanup 
the expired connections.", false);
     protected final ConfigKey<Integer> AlertWait = new 
ConfigKey<Integer>("Advanced", Integer.class, "alert.wait", "1800",
             "Seconds to wait before alerting on a disconnected agent", true);
     protected final ConfigKey<Integer> DirectAgentLoadSize = new 
ConfigKey<Integer>("Advanced", Integer.class, "direct.agent.load.size", "16",
@@ -726,9 +728,9 @@ public class AgentManagerImpl extends ManagerBase 
implements AgentManager, Handl
 
         _monitorExecutor.scheduleWithFixedDelay(new MonitorTask(), 
mgmtServiceConf.getPingInterval(), mgmtServiceConf.getPingInterval(), 
TimeUnit.SECONDS);
 
-        final int cleanupTime = Wait.value();
-        newAgentConnectionsMonitor.scheduleAtFixedRate(new 
AgentNewConnectionsMonitorTask(), cleanupTime,
-                cleanupTime, TimeUnit.MINUTES);
+        final int agentConnectionsMonitorTimeInSecs = 
RemoteAgentNewConnectionsMonitorInterval.value();
+        newAgentConnectionsMonitor.scheduleAtFixedRate(new 
AgentNewConnectionsMonitorTask(), agentConnectionsMonitorTimeInSecs,
+                agentConnectionsMonitorTimeInSecs, TimeUnit.SECONDS);
 
         return true;
     }
@@ -1857,27 +1859,21 @@ public class AgentManagerImpl extends ManagerBase 
implements AgentManager, Handl
         @Override
         protected void runInContext() {
             logger.trace("Agent New Connections Monitor is started.");
-            final int cleanupTime = Wait.value();
+            final int cleanupTime = 
RemoteAgentNewConnectionsMonitorInterval.value();
             Set<Map.Entry<String, Long>> entrySet = 
newAgentConnections.entrySet();
-            long cutOff = System.currentTimeMillis() - (cleanupTime * 60 * 
1000L);
-            if (logger.isDebugEnabled()) {
-                List<String> expiredConnections = 
newAgentConnections.entrySet()
-                        .stream()
-                        .filter(e -> e.getValue() <= cutOff)
-                        .map(Map.Entry::getKey)
-                        .collect(Collectors.toList());
-                logger.debug(String.format("Currently %d active new 
connections, of which %d have expired - %s",
-                        entrySet.size(),
-                        expiredConnections.size(),
-                        StringUtils.join(expiredConnections)));
-            }
-            for (Map.Entry<String, Long> entry : entrySet) {
-                if (entry.getValue() <= cutOff) {
-                    if (logger.isTraceEnabled()) {
-                        logger.trace(String.format("Cleaning up new agent 
connection for %s", entry.getKey()));
-                    }
-                    newAgentConnections.remove(entry.getKey());
-                }
+            long cutOff = System.currentTimeMillis() - (cleanupTime * 1000L);
+            List<String> expiredConnections = newAgentConnections.entrySet()
+                    .stream()
+                    .filter(e -> e.getValue() <= cutOff)
+                    .map(Map.Entry::getKey)
+                    .collect(Collectors.toList());
+            logger.debug("Currently {} active new connections, of which {} 
have expired - {}",
+                    entrySet.size(),
+                    expiredConnections.size(),
+                    StringUtils.join(expiredConnections));
+            for (String connection : expiredConnections) {
+                logger.trace("Cleaning up new agent connection for {}", 
connection);
+                newAgentConnections.remove(connection);
             }
         }
     }
@@ -1958,7 +1954,8 @@ public class AgentManagerImpl extends ManagerBase 
implements AgentManager, Handl
     public ConfigKey<?>[] getConfigKeys() {
         return new ConfigKey<?>[] { CheckTxnBeforeSending, Workers, Port, 
Wait, AlertWait, DirectAgentLoadSize,
                 DirectAgentPoolSize, DirectAgentThreadCap, 
EnableKVMAutoEnableDisable, ReadyCommandWait,
-                GranularWaitTimeForCommands, RemoteAgentSslHandshakeTimeout, 
RemoteAgentMaxConcurrentNewConnections };
+                GranularWaitTimeForCommands, RemoteAgentSslHandshakeTimeout, 
RemoteAgentMaxConcurrentNewConnections,
+                RemoteAgentNewConnectionsMonitorInterval };
     }
 
     protected class SetHostParamsListener implements Listener {
diff --git 
a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
 
b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
index 576f7793565..15e3110f51b 100755
--- 
a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
+++ 
b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -427,7 +427,7 @@ public class VirtualMachineManagerImpl extends ManagerBase 
implements VirtualMac
     static final ConfigKey<Long> VmOpCleanupInterval = new 
ConfigKey<Long>("Advanced", Long.class, "vm.op.cleanup.interval", "86400",
             "Interval to run the thread that cleans up the vm operations (in 
seconds)", false);
     static final ConfigKey<Long> VmOpCleanupWait = new 
ConfigKey<Long>("Advanced", Long.class, "vm.op.cleanup.wait", "3600",
-            "Time (in seconds) to wait before cleanuping up any vm work 
items", true);
+            "Time (in seconds) to wait before cleaning up any vm work items", 
true);
     static final ConfigKey<Long> VmOpCancelInterval = new 
ConfigKey<Long>("Advanced", Long.class, "vm.op.cancel.interval", "3600",
             "Time (in seconds) to wait before cancelling a operation", false);
     static final ConfigKey<Boolean> VmDestroyForcestop = new 
ConfigKey<Boolean>("Advanced", Boolean.class, "vm.destroy.forcestop", "false",
diff --git a/utils/src/main/java/com/cloud/utils/nio/NioConnection.java 
b/utils/src/main/java/com/cloud/utils/nio/NioConnection.java
index 2a157b9c001..d2e2e8c8956 100644
--- a/utils/src/main/java/com/cloud/utils/nio/NioConnection.java
+++ b/utils/src/main/java/com/cloud/utils/nio/NioConnection.java
@@ -219,7 +219,6 @@ public abstract class NioConnection implements 
Callable<Boolean> {
         return true;
     }
 
-
     protected void accept(final SelectionKey key) throws IOException {
         final ServerSocketChannel serverSocketChannel = 
(ServerSocketChannel)key.channel();
         final SocketChannel socketChannel = serverSocketChannel.accept();

Reply via email to