|
53 | 53 | import org.apache.cloudstack.managed.context.ManagedContextRunnable; |
54 | 54 | import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao; |
55 | 55 | import org.apache.cloudstack.utils.identity.ManagementServerNode; |
| 56 | +import org.apache.commons.collections.MapUtils; |
56 | 57 | import org.apache.commons.lang3.BooleanUtils; |
57 | 58 |
|
58 | 59 | import com.cloud.agent.AgentManager; |
@@ -139,6 +140,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl |
139 | 140 | protected List<Pair<Integer, Listener>> _cmdMonitors = new ArrayList<Pair<Integer, Listener>>(17); |
140 | 141 | protected List<Pair<Integer, StartupCommandProcessor>> _creationMonitors = new ArrayList<Pair<Integer, StartupCommandProcessor>>(17); |
141 | 142 | protected List<Long> _loadingAgents = new ArrayList<Long>(); |
| 143 | + protected Map<String, Integer> _commandTimeouts = new HashMap<>(); |
142 | 144 | private int _monitorId = 0; |
143 | 145 | private final Lock _agentStatusLock = new ReentrantLock(); |
144 | 146 |
|
@@ -241,6 +243,8 @@ public boolean configure(final String name, final Map<String, Object> params) th |
241 | 243 |
|
242 | 244 | _monitorExecutor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("AgentMonitor")); |
243 | 245 |
|
| 246 | + initializeCommandTimeouts(); |
| 247 | + |
244 | 248 | return true; |
245 | 249 | } |
246 | 250 |
|
@@ -437,32 +441,33 @@ protected int getTimeout(final Commands commands, int timeout) { |
437 | 441 | } |
438 | 442 |
|
439 | 443 | protected int getTimeoutFromGranularWaitTime(final Commands commands) { |
440 | | - String commandWaits = GranularWaitTimeForCommands.value().trim(); |
441 | | - |
442 | 444 | 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; |
456 | 451 | } |
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())); |
460 | 452 | } |
461 | 453 | } |
462 | 454 |
|
463 | 455 | return maxWait; |
464 | 456 | } |
465 | 457 |
|
| 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 | + |
466 | 471 | private Map<String, Integer> getCommandTimeoutsMap(String commandWaits) { |
467 | 472 | String[] commandPairs = commandWaits.split(","); |
468 | 473 | Map<String, Integer> commandTimeouts = new HashMap<>(); |
|
0 commit comments