|
51 | 51 | import org.apache.cloudstack.managed.context.ManagedContextRunnable; |
52 | 52 | import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao; |
53 | 53 | import org.apache.cloudstack.utils.identity.ManagementServerNode; |
54 | | -import org.apache.commons.collections.MapUtils; |
55 | 54 | import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; |
| 55 | +import org.apache.commons.collections.MapUtils; |
56 | 56 | import org.apache.commons.lang3.BooleanUtils; |
57 | 57 | import org.apache.commons.lang3.StringUtils; |
58 | 58 | import org.apache.logging.log4j.ThreadContext; |
@@ -210,6 +210,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl |
210 | 210 | "Number of maximum concurrent new connections server allows for remote agents. " + |
211 | 211 | "If set to zero (default value) then no limit will be enforced on concurrent new connections", |
212 | 212 | 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); |
213 | 215 | protected final ConfigKey<Integer> AlertWait = new ConfigKey<Integer>("Advanced", Integer.class, "alert.wait", "1800", |
214 | 216 | "Seconds to wait before alerting on a disconnected agent", true); |
215 | 217 | protected final ConfigKey<Integer> DirectAgentLoadSize = new ConfigKey<Integer>("Advanced", Integer.class, "direct.agent.load.size", "16", |
@@ -726,9 +728,9 @@ public boolean start() { |
726 | 728 |
|
727 | 729 | _monitorExecutor.scheduleWithFixedDelay(new MonitorTask(), mgmtServiceConf.getPingInterval(), mgmtServiceConf.getPingInterval(), TimeUnit.SECONDS); |
728 | 730 |
|
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); |
732 | 734 |
|
733 | 735 | return true; |
734 | 736 | } |
@@ -1857,27 +1859,21 @@ protected class AgentNewConnectionsMonitorTask extends ManagedContextRunnable { |
1857 | 1859 | @Override |
1858 | 1860 | protected void runInContext() { |
1859 | 1861 | logger.trace("Agent New Connections Monitor is started."); |
1860 | | - final int cleanupTime = Wait.value(); |
| 1862 | + final int cleanupTime = RemoteAgentNewConnectionsMonitorInterval.value(); |
1861 | 1863 | 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); |
1881 | 1877 | } |
1882 | 1878 | } |
1883 | 1879 | } |
@@ -1958,7 +1954,8 @@ public String getConfigComponentName() { |
1958 | 1954 | public ConfigKey<?>[] getConfigKeys() { |
1959 | 1955 | return new ConfigKey<?>[] { CheckTxnBeforeSending, Workers, Port, Wait, AlertWait, DirectAgentLoadSize, |
1960 | 1956 | DirectAgentPoolSize, DirectAgentThreadCap, EnableKVMAutoEnableDisable, ReadyCommandWait, |
1961 | | - GranularWaitTimeForCommands, RemoteAgentSslHandshakeTimeout, RemoteAgentMaxConcurrentNewConnections }; |
| 1957 | + GranularWaitTimeForCommands, RemoteAgentSslHandshakeTimeout, RemoteAgentMaxConcurrentNewConnections, |
| 1958 | + RemoteAgentNewConnectionsMonitorInterval }; |
1962 | 1959 | } |
1963 | 1960 |
|
1964 | 1961 | protected class SetHostParamsListener implements Listener { |
|
0 commit comments