Skip to content

Commit 0b31ca0

Browse files
committed
Add validation for the setting values
1 parent d5cb403 commit 0b31ca0

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
220220
private boolean _reconcileCommandsEnabled = false;
221221
private Integer _reconcileCommandInterval;
222222

223+
private static final int AGENT_CONNECT_CORE_POOL_SIZE = 100;
224+
private static final int AGENT_CONNECT_MAX_POOL_SIZE = 500;
225+
223226
@Inject
224227
ResourceManager _resourceMgr;
225228
@Inject
@@ -427,11 +430,28 @@ public void onManagementServerCancelMaintenance() {
427430
}
428431

429432
private void initConnectExecutor() {
430-
_connectExecutor = new ThreadPoolExecutor(AgentConnectExecutorCorePoolSize.value(), AgentConnectExecutorMaxPoolSize.value(), 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new NamedThreadFactory("AgentConnectTaskPool"));
433+
Pair<Integer, Integer> poolSizeValues = retrieveAgentConnectPoolCoreSizeAndMaxSize();
434+
_connectExecutor = new ThreadPoolExecutor(poolSizeValues.first(), poolSizeValues.second(), 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new NamedThreadFactory("AgentConnectTaskPool"));
431435
// allow core threads to time out even when there are no items in the queue
432436
_connectExecutor.allowCoreThreadTimeOut(true);
433437
}
434438

439+
private Pair<Integer, Integer> retrieveAgentConnectPoolCoreSizeAndMaxSize() {
440+
Integer agentConnectCorePoolSize = AgentConnectExecutorCorePoolSize.value();
441+
Integer agentConnectMaxSize = AgentConnectExecutorMaxPoolSize.value();
442+
if (agentConnectCorePoolSize == null || agentConnectCorePoolSize < 0 || agentConnectMaxSize == null || agentConnectMaxSize < 0) {
443+
logger.warn("Invalid agent connect pool size values. Defaulting to core pool size {} and max pool size {}", AGENT_CONNECT_CORE_POOL_SIZE, AGENT_CONNECT_MAX_POOL_SIZE);
444+
return new Pair<>(AGENT_CONNECT_CORE_POOL_SIZE, AGENT_CONNECT_MAX_POOL_SIZE);
445+
446+
}
447+
if (agentConnectMaxSize > agentConnectCorePoolSize) {
448+
logger.warn("Max agent connect pool size {} is greater than core pool size {}. " +
449+
"Defaulting to core pool size {} and max pool size {}", agentConnectMaxSize, agentConnectCorePoolSize, AGENT_CONNECT_CORE_POOL_SIZE, AGENT_CONNECT_MAX_POOL_SIZE);
450+
return new Pair<>(AGENT_CONNECT_CORE_POOL_SIZE, AGENT_CONNECT_MAX_POOL_SIZE);
451+
}
452+
return new Pair<>(agentConnectCorePoolSize, agentConnectMaxSize);
453+
}
454+
435455
private void initAndScheduleMonitorExecutor() {
436456
_monitorExecutor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("AgentMonitor"));
437457
_monitorExecutor.scheduleWithFixedDelay(new MonitorTask(), mgmtServiceConf.getPingInterval(), mgmtServiceConf.getPingInterval(), TimeUnit.SECONDS);

0 commit comments

Comments
 (0)