Skip to content

Commit 448361b

Browse files
Fix cutoff time in agent connections monitor thread
Co-authored-by: [email protected]
1 parent 53441a1 commit 448361b

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

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

Lines changed: 14 additions & 20 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;
@@ -1859,25 +1859,19 @@ protected void runInContext() {
18591859
logger.trace("Agent New Connections Monitor is started.");
18601860
final int cleanupTime = Wait.value();
18611861
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-
}
1862+
long cutOff = System.currentTimeMillis() - (cleanupTime * 1000L);
1863+
List<String> expiredConnections = newAgentConnections.entrySet()
1864+
.stream()
1865+
.filter(e -> e.getValue() <= cutOff)
1866+
.map(Map.Entry::getKey)
1867+
.collect(Collectors.toList());
1868+
logger.debug("Currently {} active new connections, of which {} have expired - {}",
1869+
entrySet.size(),
1870+
expiredConnections.size(),
1871+
StringUtils.join(expiredConnections));
1872+
for (String connection : expiredConnections) {
1873+
logger.trace("Cleaning up new agent connection for {}", connection);
1874+
newAgentConnections.remove(connection);
18811875
}
18821876
}
18831877
}

0 commit comments

Comments
 (0)