From 8b8faa68169164f6e404d76681c7fc57174d8143 Mon Sep 17 00:00:00 2001 From: justinwwhuang Date: Mon, 4 Nov 2024 14:23:03 +0800 Subject: [PATCH] [INLONG-11451][Agent] When the installer detects that the process does not exist, it increases the wait for retry to prevent misjudgment (#11452) --- .../inlong/agent/installer/ModuleManager.java | 37 +++++++++++-------- .../java/installer/TestModuleManager.java | 2 +- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java b/inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java index cb92576c3c2..de05a9d0f72 100755 --- a/inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java +++ b/inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java @@ -80,6 +80,7 @@ public class ModuleManager extends AbstractDaemon { public static final String LOCAL_CONFIG_FILE = "modules.json"; private static final Logger LOGGER = LoggerFactory.getLogger(ModuleManager.class); public static final int MAX_MODULE_SIZE = 10; + public static final int CHECK_PROCESS_TIMES = 20; private final InstallerConfiguration conf; private final String confPath; private final BlockingQueue configQueue; @@ -345,7 +346,7 @@ private void checkModules() { } break; case INSTALLED: - if (!isProcessAllStarted(module)) { + if (!isProcessAllStarted(module, CHECK_PROCESS_TIMES)) { LOGGER.info("module {}({}) process not all started try to start", module.getId(), module.getName()); if (!startModule(module)) { @@ -495,7 +496,7 @@ private boolean startModule(ModuleConfig module) { String ret = ExcuteLinux.exeCmd(module.getStartCommand()); LOGGER.info("start module {}({}) proc[{}] return {} ", module.getId(), module.getName(), i, ret); } - if (isProcessAllStarted(module)) { + if (isProcessAllStarted(module, CHECK_PROCESS_TIMES)) { LOGGER.info("start module {}({}) success", module.getId(), module.getName()); return true; } else { @@ -517,21 +518,27 @@ private void uninstallModule(ModuleConfig module) { LOGGER.info("uninstall module {}({}) return {} ", module.getId(), module.getName(), ret); } - private boolean isProcessAllStarted(ModuleConfig module) { - String ret = ExcuteLinux.exeCmd(module.getCheckCommand()); - if (ret == null) { - LOGGER.error("get module {}({}) process num failed", module.getId(), module.getName()); - return false; - } - String[] processArray = ret.split("\n"); - int cnt = 0; - for (int i = 0; i < processArray.length; i++) { - if (processArray[i].length() > 0) { - cnt++; + private boolean isProcessAllStarted(ModuleConfig module, int times) { + for (int check = 0; check < times; check++) { + AgentUtils.silenceSleepInSeconds(1); + String ret = ExcuteLinux.exeCmd(module.getCheckCommand()); + if (ret == null) { + LOGGER.error("[{}] get module {}({}) process num failed", check, module.getId(), module.getName()); + continue; + } + String[] processArray = ret.split("\n"); + int cnt = 0; + for (int i = 0; i < processArray.length; i++) { + if (processArray[i].length() > 0) { + cnt++; + } + } + LOGGER.info("[{}] get module {}({}) process num {}", check, module.getId(), module.getName(), cnt); + if (cnt >= module.getProcessesNum()) { + return true; } } - LOGGER.info("get module {}({}) process num {}", module.getId(), module.getName(), cnt); - return cnt >= module.getProcessesNum(); + return false; } private boolean downloadModule(ModuleConfig module) { diff --git a/inlong-agent/agent-installer/src/test/java/installer/TestModuleManager.java b/inlong-agent/agent-installer/src/test/java/installer/TestModuleManager.java index ecd2383bf03..240fc7357f5 100755 --- a/inlong-agent/agent-installer/src/test/java/installer/TestModuleManager.java +++ b/inlong-agent/agent-installer/src/test/java/installer/TestModuleManager.java @@ -138,7 +138,7 @@ private void mockFunctions() { PowerMockito.doAnswer(invocation -> { ModuleConfig module = invocation.getArgument(0); return true; - }).when(manager, "isProcessAllStarted", Mockito.any()); + }).when(manager, "isProcessAllStarted", Mockito.any(), Mockito.anyInt()); PowerMockito.doReturn(null).when(manager, "getHttpManager", Mockito.any()); } catch (Exception e) {