shwstppr commented on code in PR #9659:
URL: https://github.com/apache/cloudstack/pull/9659#discussion_r1871289972
##########
engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java:
##########
@@ -424,15 +428,78 @@ private void setEmptyAnswers(final Commands commands,
final Command[] cmds) {
}
}
+ protected int getTimeout(final Commands commands, int timeout) {
+ int result;
+ if (timeout > 0) {
+ result = timeout;
+ } else {
+ result = Wait.value();
+ }
+
+ int granularTimeout = getTimeoutFromGranularWaitTime(commands);
+ return (granularTimeout > 0) ? granularTimeout : result;
+ }
+
+ protected int getTimeoutFromGranularWaitTime(final Commands commands) {
+ int maxWait = 0;
+ if (MapUtils.isNotEmpty(_commandTimeouts)) {
+ for (final Command cmd : commands) {
+ String simpleCommandName = cmd.getClass().getSimpleName();
+ Integer commandTimeout =
_commandTimeouts.get(simpleCommandName);
+ if (commandTimeout != null && commandTimeout > maxWait) {
+ maxWait = commandTimeout;
+ }
+ }
+ }
+
+ return maxWait;
+ }
+
+ private void initializeCommandTimeouts() {
+ String commandWaits = GranularWaitTimeForCommands.value().trim();
+ if (StringUtils.isNotEmpty(commandWaits)) {
+ try {
+ _commandTimeouts = getCommandTimeoutsMap(commandWaits);
+ logger.info(String.format("Timeouts for management server
internal commands successfully initialized from global setting
commands.timeout: %s", _commandTimeouts));
+ } catch (Exception e) {
+ logger.error("Error initializing command timeouts map: " +
e.getMessage());
+ _commandTimeouts = new HashMap<>();
+ }
+ }
+ }
+
+ private Map<String, Integer> getCommandTimeoutsMap(String commandWaits) {
+ String[] commandPairs = commandWaits.split(",");
+ Map<String, Integer> commandTimeouts = new HashMap<>();
+
+ for (String commandPair : commandPairs) {
+ String[] parts = commandPair.trim().split("=");
+ if (parts.length == 2) {
+ String commandName = parts[0].trim();
+ int commandTimeout = Integer.parseInt(parts[1].trim());
Review Comment:
@harikrishna-patnala would it be better to handle null values and
NumberFormatException here instead of handling any exception in the caller? It
may allow ignoring a single wrong key-pair
##########
engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java:
##########
@@ -424,15 +428,78 @@ private void setEmptyAnswers(final Commands commands,
final Command[] cmds) {
}
}
+ protected int getTimeout(final Commands commands, int timeout) {
+ int result;
+ if (timeout > 0) {
+ result = timeout;
+ } else {
+ result = Wait.value();
+ }
+
+ int granularTimeout = getTimeoutFromGranularWaitTime(commands);
+ return (granularTimeout > 0) ? granularTimeout : result;
+ }
+
+ protected int getTimeoutFromGranularWaitTime(final Commands commands) {
+ int maxWait = 0;
+ if (MapUtils.isNotEmpty(_commandTimeouts)) {
+ for (final Command cmd : commands) {
+ String simpleCommandName = cmd.getClass().getSimpleName();
+ Integer commandTimeout =
_commandTimeouts.get(simpleCommandName);
+ if (commandTimeout != null && commandTimeout > maxWait) {
+ maxWait = commandTimeout;
+ }
+ }
+ }
+
+ return maxWait;
+ }
+
+ private void initializeCommandTimeouts() {
+ String commandWaits = GranularWaitTimeForCommands.value().trim();
+ if (StringUtils.isNotEmpty(commandWaits)) {
+ try {
+ _commandTimeouts = getCommandTimeoutsMap(commandWaits);
+ logger.info(String.format("Timeouts for management server
internal commands successfully initialized from global setting
commands.timeout: %s", _commandTimeouts));
+ } catch (Exception e) {
Review Comment:
why catch all?
##########
engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java:
##########
@@ -424,15 +428,78 @@ private void setEmptyAnswers(final Commands commands,
final Command[] cmds) {
}
}
+ protected int getTimeout(final Commands commands, int timeout) {
+ int result;
+ if (timeout > 0) {
+ result = timeout;
+ } else {
+ result = Wait.value();
+ }
+
+ int granularTimeout = getTimeoutFromGranularWaitTime(commands);
+ return (granularTimeout > 0) ? granularTimeout : result;
+ }
+
+ protected int getTimeoutFromGranularWaitTime(final Commands commands) {
+ int maxWait = 0;
+ if (MapUtils.isNotEmpty(_commandTimeouts)) {
+ for (final Command cmd : commands) {
+ String simpleCommandName = cmd.getClass().getSimpleName();
+ Integer commandTimeout =
_commandTimeouts.get(simpleCommandName);
+ if (commandTimeout != null && commandTimeout > maxWait) {
+ maxWait = commandTimeout;
+ }
+ }
+ }
+
+ return maxWait;
+ }
+
+ private void initializeCommandTimeouts() {
+ String commandWaits = GranularWaitTimeForCommands.value().trim();
+ if (StringUtils.isNotEmpty(commandWaits)) {
+ try {
+ _commandTimeouts = getCommandTimeoutsMap(commandWaits);
+ logger.info(String.format("Timeouts for management server
internal commands successfully initialized from global setting
commands.timeout: %s", _commandTimeouts));
+ } catch (Exception e) {
+ logger.error("Error initializing command timeouts map: " +
e.getMessage());
+ _commandTimeouts = new HashMap<>();
+ }
+ }
+ }
+
+ private Map<String, Integer> getCommandTimeoutsMap(String commandWaits) {
+ String[] commandPairs = commandWaits.split(",");
+ Map<String, Integer> commandTimeouts = new HashMap<>();
+
+ for (String commandPair : commandPairs) {
+ String[] parts = commandPair.trim().split("=");
+ if (parts.length == 2) {
+ String commandName = parts[0].trim();
+ int commandTimeout = Integer.parseInt(parts[1].trim());
+ commandTimeouts.put(commandName, commandTimeout);
+ } else {
+ logger.warn(String.format("Invalid format in commands.timeout
global setting: %s", commandPair));
+ }
+ }
+ return commandTimeouts;
+ }
+
@Override
public Answer[] send(final Long hostId, final Commands commands, int
timeout) throws AgentUnavailableException, OperationTimedoutException {
assert hostId != null : "Who's not checking the agent id before
sending? ... (finger wagging)";
if (hostId == null) {
throw new AgentUnavailableException(-1);
}
- if (timeout <= 0) {
- timeout = Wait.value();
+ int wait = getTimeout(commands, timeout);
+ logger.debug(String.format("Wait time setting on %s is %d seconds",
commands, wait));
+ for (Command cmd : commands) {
+ String simpleCommandName = cmd.getClass().getSimpleName();
+ Integer commandTimeout = _commandTimeouts.get(simpleCommandName);
+ if (commandTimeout != null) {
+ cmd.setWait(wait);
Review Comment:
Do we need to log timeout for a specific command, maybe just in trace? It
may help while troubleshooting
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]