Skip to content

Commit 9f22960

Browse files
Add new config (non-dynamic) for agent connections monitor thread, and keep timeunit to secs (in sync with the earlier Wait config) (#10525)
1 parent 0785ba0 commit 9f22960

File tree

4 files changed

+25
-29
lines changed

4 files changed

+25
-29
lines changed

engine/components-api/src/main/java/com/cloud/agent/AgentManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* AgentManager manages hosts. It directly coordinates between the DAOs and the connections it manages.
3838
*/
3939
public interface AgentManager {
40-
static final ConfigKey<Integer> Wait = new ConfigKey<Integer>("Advanced", Integer.class, "wait", "1800", "Time in seconds to wait for control commands to return",
40+
ConfigKey<Integer> Wait = new ConfigKey<Integer>("Advanced", Integer.class, "wait", "1800", "Time in seconds to wait for control commands to return",
4141
true);
4242
ConfigKey<Boolean> EnableKVMAutoEnableDisable = new ConfigKey<>(Boolean.class,
4343
"enable.kvm.host.auto.enable.disable",
@@ -54,7 +54,7 @@ public interface AgentManager {
5454
"This timeout overrides the wait global config. This holds a comma separated key value pairs containing timeout (in seconds) for specific commands. " +
5555
"For example: DhcpEntryCommand=600, SavePasswordCommand=300, VmDataCommand=300", false);
5656

57-
public enum TapAgentsAction {
57+
enum TapAgentsAction {
5858
Add, Del, Contains,
5959
}
6060

engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
5252
import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao;
5353
import org.apache.cloudstack.utils.identity.ManagementServerNode;
54-
import org.apache.commons.collections.MapUtils;
5554
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
55+
import org.apache.commons.collections.MapUtils;
5656
import org.apache.commons.lang3.BooleanUtils;
5757
import org.apache.commons.lang3.StringUtils;
5858
import org.apache.logging.log4j.ThreadContext;
@@ -210,6 +210,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
210210
"Number of maximum concurrent new connections server allows for remote agents. " +
211211
"If set to zero (default value) then no limit will be enforced on concurrent new connections",
212212
false);
213+
protected final ConfigKey<Integer> RemoteAgentNewConnectionsMonitorInterval = new ConfigKey<>("Advanced", Integer.class, "agent.connections.monitor.interval", "1800",
214+
"Time in seconds to monitor the new agent connections and cleanup the expired connections.", false);
213215
protected final ConfigKey<Integer> AlertWait = new ConfigKey<Integer>("Advanced", Integer.class, "alert.wait", "1800",
214216
"Seconds to wait before alerting on a disconnected agent", true);
215217
protected final ConfigKey<Integer> DirectAgentLoadSize = new ConfigKey<Integer>("Advanced", Integer.class, "direct.agent.load.size", "16",
@@ -726,9 +728,9 @@ public boolean start() {
726728

727729
_monitorExecutor.scheduleWithFixedDelay(new MonitorTask(), mgmtServiceConf.getPingInterval(), mgmtServiceConf.getPingInterval(), TimeUnit.SECONDS);
728730

729-
final int cleanupTime = Wait.value();
730-
newAgentConnectionsMonitor.scheduleAtFixedRate(new AgentNewConnectionsMonitorTask(), cleanupTime,
731-
cleanupTime, TimeUnit.MINUTES);
731+
final int agentConnectionsMonitorTimeInSecs = RemoteAgentNewConnectionsMonitorInterval.value();
732+
newAgentConnectionsMonitor.scheduleAtFixedRate(new AgentNewConnectionsMonitorTask(), agentConnectionsMonitorTimeInSecs,
733+
agentConnectionsMonitorTimeInSecs, TimeUnit.SECONDS);
732734

733735
return true;
734736
}
@@ -1857,27 +1859,21 @@ protected class AgentNewConnectionsMonitorTask extends ManagedContextRunnable {
18571859
@Override
18581860
protected void runInContext() {
18591861
logger.trace("Agent New Connections Monitor is started.");
1860-
final int cleanupTime = Wait.value();
1862+
final int cleanupTime = RemoteAgentNewConnectionsMonitorInterval.value();
18611863
Set<Map.Entry<String, Long>> entrySet = newAgentConnections.entrySet();
1862-
long cutOff = System.currentTimeMillis() - (cleanupTime * 60 * 1000L);
1863-
if (logger.isDebugEnabled()) {
1864-
List<String> expiredConnections = newAgentConnections.entrySet()
1865-
.stream()
1866-
.filter(e -> e.getValue() <= cutOff)
1867-
.map(Map.Entry::getKey)
1868-
.collect(Collectors.toList());
1869-
logger.debug(String.format("Currently %d active new connections, of which %d have expired - %s",
1870-
entrySet.size(),
1871-
expiredConnections.size(),
1872-
StringUtils.join(expiredConnections)));
1873-
}
1874-
for (Map.Entry<String, Long> entry : entrySet) {
1875-
if (entry.getValue() <= cutOff) {
1876-
if (logger.isTraceEnabled()) {
1877-
logger.trace(String.format("Cleaning up new agent connection for %s", entry.getKey()));
1878-
}
1879-
newAgentConnections.remove(entry.getKey());
1880-
}
1864+
long cutOff = System.currentTimeMillis() - (cleanupTime * 1000L);
1865+
List<String> expiredConnections = newAgentConnections.entrySet()
1866+
.stream()
1867+
.filter(e -> e.getValue() <= cutOff)
1868+
.map(Map.Entry::getKey)
1869+
.collect(Collectors.toList());
1870+
logger.debug("Currently {} active new connections, of which {} have expired - {}",
1871+
entrySet.size(),
1872+
expiredConnections.size(),
1873+
StringUtils.join(expiredConnections));
1874+
for (String connection : expiredConnections) {
1875+
logger.trace("Cleaning up new agent connection for {}", connection);
1876+
newAgentConnections.remove(connection);
18811877
}
18821878
}
18831879
}
@@ -1958,7 +1954,8 @@ public String getConfigComponentName() {
19581954
public ConfigKey<?>[] getConfigKeys() {
19591955
return new ConfigKey<?>[] { CheckTxnBeforeSending, Workers, Port, Wait, AlertWait, DirectAgentLoadSize,
19601956
DirectAgentPoolSize, DirectAgentThreadCap, EnableKVMAutoEnableDisable, ReadyCommandWait,
1961-
GranularWaitTimeForCommands, RemoteAgentSslHandshakeTimeout, RemoteAgentMaxConcurrentNewConnections };
1957+
GranularWaitTimeForCommands, RemoteAgentSslHandshakeTimeout, RemoteAgentMaxConcurrentNewConnections,
1958+
RemoteAgentNewConnectionsMonitorInterval };
19621959
}
19631960

19641961
protected class SetHostParamsListener implements Listener {

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
427427
static final ConfigKey<Long> VmOpCleanupInterval = new ConfigKey<Long>("Advanced", Long.class, "vm.op.cleanup.interval", "86400",
428428
"Interval to run the thread that cleans up the vm operations (in seconds)", false);
429429
static final ConfigKey<Long> VmOpCleanupWait = new ConfigKey<Long>("Advanced", Long.class, "vm.op.cleanup.wait", "3600",
430-
"Time (in seconds) to wait before cleanuping up any vm work items", true);
430+
"Time (in seconds) to wait before cleaning up any vm work items", true);
431431
static final ConfigKey<Long> VmOpCancelInterval = new ConfigKey<Long>("Advanced", Long.class, "vm.op.cancel.interval", "3600",
432432
"Time (in seconds) to wait before cancelling a operation", false);
433433
static final ConfigKey<Boolean> VmDestroyForcestop = new ConfigKey<Boolean>("Advanced", Boolean.class, "vm.destroy.forcestop", "false",

utils/src/main/java/com/cloud/utils/nio/NioConnection.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ protected boolean rejectConnectionIfBusy(final SocketChannel socketChannel) thro
219219
return true;
220220
}
221221

222-
223222
protected void accept(final SelectionKey key) throws IOException {
224223
final ServerSocketChannel serverSocketChannel = (ServerSocketChannel)key.channel();
225224
final SocketChannel socketChannel = serverSocketChannel.accept();

0 commit comments

Comments
 (0)