From 76abf5dde00dceb25bbc749bc8b9d2e1a0f529f5 Mon Sep 17 00:00:00 2001 From: Harikrishna Patnala Date: Wed, 11 Sep 2024 11:03:31 +0530 Subject: [PATCH] Fixed log messages --- .../src/main/java/com/cloud/agent/AgentManager.java | 2 +- .../com/cloud/agent/manager/AgentManagerImpl.java | 5 +---- .../configuration/ConfigurationManagerImpl.java | 12 ++++++------ .../configuration/ConfigurationManagerTest.java | 2 +- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/engine/components-api/src/main/java/com/cloud/agent/AgentManager.java b/engine/components-api/src/main/java/com/cloud/agent/AgentManager.java index c810fdfbefd4..f7a000f78dd3 100644 --- a/engine/components-api/src/main/java/com/cloud/agent/AgentManager.java +++ b/engine/components-api/src/main/java/com/cloud/agent/AgentManager.java @@ -51,7 +51,7 @@ public interface AgentManager { "60", "Time in seconds to wait for Ready command to return", true); ConfigKey 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 { diff --git a/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java b/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java index 74494dde7a18..d15e5ea359c7 100644 --- a/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java +++ b/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java @@ -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(); } @@ -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; @@ -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; } @@ -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); } @@ -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(); } diff --git a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java index e2d2fca32efd..16aa168dba01 100644 --- a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java @@ -1389,13 +1389,13 @@ protected Pair 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); } @@ -1403,25 +1403,25 @@ protected Pair validateCommaSeparatedKeyValueConfigWithPositive 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); } } diff --git a/server/src/test/java/com/cloud/configuration/ConfigurationManagerTest.java b/server/src/test/java/com/cloud/configuration/ConfigurationManagerTest.java index d9143acda6fe..86ce9b79b21f 100644 --- a/server/src/test/java/com/cloud/configuration/ConfigurationManagerTest.java +++ b/server/src/test/java/com/cloud/configuration/ConfigurationManagerTest.java @@ -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); } }