Skip to content

Commit

Permalink
Fixed log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
harikrishna-patnala committed Sep 11, 2024
1 parent f603974 commit 58b66f6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public interface AgentManager {
"60", "Time in seconds to wait for Ready command to return", true);

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

public enum TapAgentsAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ protected int getTimeout(final Commands commands, int timeout) {
if (timeout > 0) {
result = timeout;
} else {
logger.debug(String.format("Considering the Wait global setting %d, since wait time set on command is 0", Wait.value()));
result = Wait.value();
}

Expand All @@ -439,7 +438,6 @@ protected int getTimeout(final Commands commands, int timeout) {
}

protected int getTimeoutFromGranularWaitTime(final Commands commands) {
logger.debug("Looking for the commands.timeout global setting for any command-specific timeout value");
String commandWaits = GranularWaitTimeForCommands.value().trim();

int maxWait = 0;
Expand All @@ -452,7 +450,6 @@ protected int getTimeoutFromGranularWaitTime(final Commands commands) {
Integer commandTimeout = commandTimeouts.get(simpleCommandName);

if (commandTimeout != null) {
logger.debug(String.format("Timeout %d found for command %s in commands.timeout global setting", commandTimeout, cmd.toString()));
if (commandTimeout > maxWait) {
maxWait = commandTimeout;
}
Expand Down Expand Up @@ -492,6 +489,7 @@ public Answer[] send(final Long hostId, final Commands commands, int timeout) th
}

int wait = getTimeout(commands, timeout);
logger.debug(String.format("Wait time setting on %s is %d seconds", commands, wait));
for (Command cmd : commands) {
cmd.setWait(wait);
}
Expand Down Expand Up @@ -1055,7 +1053,6 @@ public Answer[] send(final Long hostId, final Commands cmds) throws AgentUnavail
}

for (final Command cmd : cmds) {
logger.debug(String.format("Wait time set on the command %s is %d", cmd, cmd.getWait()));
if (cmd.getWait() > wait) {
wait = cmd.getWait();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1389,39 +1389,39 @@ protected Pair<Boolean, String> validateCommaSeparatedKeyValueConfigWithPositive
for (String command : commands) {
command = command.trim();
if (!command.contains("=")) {
String errorMessage = "Validation failed: Command '" + command + "' does not contain '='.";
String errorMessage = String.format("Validation failed: Command '%s' does not contain '='.", command);
return new Pair<>(false, errorMessage);
}

String[] parts = command.split("=");
if (parts.length != 2) {
String errorMessage = "Validation failed: Command '" + command + "' is not properly formatted.";
String errorMessage = String.format("Validation failed: Command '%s' is not properly formatted.", command);
return new Pair<>(false, errorMessage);
}

String commandName = parts[0].trim();
String valueString = parts[1].trim();

if (commandName.isEmpty()) {
String errorMessage = "Validation failed: Command name is missing in '" + command + "'.";
String errorMessage = String.format("Validation failed: Command name is missing in '%s'.", commandName);
return new Pair<>(false, errorMessage);
}

try {
int num = Integer.parseInt(valueString);
if (num <= 0) {
String errorMessage = "Validation failed: The value for command '" + commandName + "' is not greater than 0. Invalid value: " + num;
String errorMessage = String.format("Validation failed: The value for command '%s' is not greater than 0. Invalid value: %d", commandName, num);
return new Pair<>(false, errorMessage);
}
} catch (NumberFormatException e) {
String errorMessage = "Validation failed: The value for command '" + commandName + "' is not a valid integer. Invalid value: " + valueString;
String errorMessage = String.format("Validation failed: The value for command '%s' is not a valid integer. Invalid value: %s", commandName, valueString);
return new Pair<>(false, errorMessage);
}
}

return new Pair<>(true, "");
} catch (Exception e) {
String errorMessage = "Validation failed: An error occurred while parsing the command string. Error: " + e.getMessage();
String errorMessage = String.format("Validation failed: An error occurred while parsing the command string. Error: %s", e.getMessage());
return new Pair<>(false, errorMessage);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@ public void testValidateSpecificConfigurationValues_ValidFormatWithPositiveInteg
try {
configurationMgr.validateSpecificConfigurationValues(name, validValue, String.class);
} catch (InvalidParameterValueException e) {
Assert.fail("Exception should not be thrown for a valid command string with positive integers.");
Assert.fail("Exception should not be thrown for a valid command string with positive integers, but there is an error " + e);
}
}

Expand Down

0 comments on commit 58b66f6

Please sign in to comment.