Skip to content

Commit 1de0cda

Browse files
Converted the global setting to non-dynamic
1 parent 7f8f927 commit 1de0cda

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public interface AgentManager {
5252

5353
ConfigKey<String> GranularWaitTimeForCommands = new ConfigKey<>("Advanced", String.class, "commands.timeout", "",
5454
"This timeout overrides the wait global config. This holds a comma separated key value pairs containing timeout (in seconds) for specific commands. " +
55-
"For example: DhcpEntryCommand=600, SavePasswordCommand=300, VmDataCommand=300", true);
55+
"For example: DhcpEntryCommand=600, SavePasswordCommand=300, VmDataCommand=300", false);
5656

5757
public enum TapAgentsAction {
5858
Add, Del, Contains,

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

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
5454
import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao;
5555
import org.apache.cloudstack.utils.identity.ManagementServerNode;
56+
import org.apache.commons.collections.MapUtils;
5657
import org.apache.commons.lang3.BooleanUtils;
5758

5859
import com.cloud.agent.AgentManager;
@@ -139,6 +140,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
139140
protected List<Pair<Integer, Listener>> _cmdMonitors = new ArrayList<Pair<Integer, Listener>>(17);
140141
protected List<Pair<Integer, StartupCommandProcessor>> _creationMonitors = new ArrayList<Pair<Integer, StartupCommandProcessor>>(17);
141142
protected List<Long> _loadingAgents = new ArrayList<Long>();
143+
protected Map<String, Integer> _commandTimeouts = new HashMap<>();
142144
private int _monitorId = 0;
143145
private final Lock _agentStatusLock = new ReentrantLock();
144146

@@ -241,6 +243,8 @@ public boolean configure(final String name, final Map<String, Object> params) th
241243

242244
_monitorExecutor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("AgentMonitor"));
243245

246+
initializeCommandTimeouts();
247+
244248
return true;
245249
}
246250

@@ -437,32 +441,33 @@ protected int getTimeout(final Commands commands, int timeout) {
437441
}
438442

439443
protected int getTimeoutFromGranularWaitTime(final Commands commands) {
440-
String commandWaits = GranularWaitTimeForCommands.value().trim();
441-
442444
int maxWait = 0;
443-
if (StringUtils.isNotEmpty(commandWaits)) {
444-
try {
445-
Map<String, Integer> commandTimeouts = getCommandTimeoutsMap(commandWaits);
446-
447-
for (final Command cmd : commands) {
448-
String simpleCommandName = cmd.getClass().getSimpleName();
449-
Integer commandTimeout = commandTimeouts.get(simpleCommandName);
450-
451-
if (commandTimeout != null) {
452-
if (commandTimeout > maxWait) {
453-
maxWait = commandTimeout;
454-
}
455-
}
445+
if (MapUtils.isNotEmpty(_commandTimeouts)) {
446+
for (final Command cmd : commands) {
447+
String simpleCommandName = cmd.getClass().getSimpleName();
448+
Integer commandTimeout = _commandTimeouts.get(simpleCommandName);
449+
if (commandTimeout != null && commandTimeout > maxWait) {
450+
maxWait = commandTimeout;
456451
}
457-
} catch (Exception e) {
458-
logger.error(String.format("Error while processing the commands.timeout global setting for the granular timeouts for the command, " +
459-
"falling back to the command timeout: %s", e.getMessage()));
460452
}
461453
}
462454

463455
return maxWait;
464456
}
465457

458+
private void initializeCommandTimeouts() {
459+
String commandWaits = GranularWaitTimeForCommands.value().trim();
460+
if (StringUtils.isNotEmpty(commandWaits)) {
461+
try {
462+
_commandTimeouts = getCommandTimeoutsMap(commandWaits);
463+
logger.info(String.format("Timeouts for management server internal commands successfully initialized from global setting commands.timeout: %s", _commandTimeouts));
464+
} catch (Exception e) {
465+
logger.error("Error initializing command timeouts map: " + e.getMessage());
466+
_commandTimeouts = new HashMap<>();
467+
}
468+
}
469+
}
470+
466471
private Map<String, Integer> getCommandTimeoutsMap(String commandWaits) {
467472
String[] commandPairs = commandWaits.split(",");
468473
Map<String, Integer> commandTimeouts = new HashMap<>();

0 commit comments

Comments
 (0)