aloyszhang commented on code in PR #9892:
URL: https://github.com/apache/inlong/pull/9892#discussion_r1542968505


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java:
##########
@@ -106,51 +120,110 @@ public String getCurrentMd5() {
         return currentMd5;
     }
 
+    public ModuleConfig getModule(Integer moduleId) {
+        return currentModules.get(moduleId);
+    }
+
     /**
-     * thread for core thread.
+     * Thread for core thread.
      *
      * @return runnable profile.
      */
     private Runnable coreThread() {
         return () -> {
-            Thread.currentThread().setName("task-manager-core");
+            Thread.currentThread().setName("module-manager-core");
+            restoreFromLocalFile(confPath);
             while (isRunnable()) {
                 try {
-                    AgentUtils.silenceSleepInMs(CORE_THREAD_SLEEP_TIME);
                     dealWithConfigQueue(configQueue);
                     
AuditUtils.add(AuditUtils.AUDIT_ID_AGENT_TASK_MGR_HEARTBEAT, "", "",
                             AgentUtils.getCurrentTime(), 1, 1);
+                    AgentUtils.silenceSleepInMs(CORE_THREAD_SLEEP_TIME);
                 } catch (Throwable ex) {
                     LOGGER.error("exception caught", ex);
                     ThreadUtils.threadThrowableHandler(Thread.currentThread(), 
ex);
+                    AgentUtils.silenceSleepInMs(CORE_THREAD_SLEEP_TIME);
                 }
             }
         };
     }
 
+    public void restoreFromLocalFile(String confPath) {
+        LOGGER.info("restore modules from local file");
+        Reader reader = null;
+        try {
+            InputStream inputStream = new FileInputStream(confPath + 
LOCAL_CONFIG_FILE);
+            if (inputStream != null) {
+                reader = new InputStreamReader(inputStream, 
StandardCharsets.UTF_8);
+                JsonElement tmpElement = 
JsonParser.parseReader(reader).getAsJsonObject();
+                ConfigResult curConfig = 
GSON.fromJson(tmpElement.getAsJsonObject(), ConfigResult.class);
+                if (curConfig.getMd5() != null && curConfig.getModuleList() != 
null) {
+                    currentMd5 = curConfig.getMd5();
+                    curConfig.getModuleList().forEach((module) -> {
+                        currentModules.put(module.getId(), module);
+                    });
+                } else {
+                    LOGGER.info("modules in local file invalid");
+                }
+            } else {
+                LOGGER.info("local module json file new FileInputStream 
failed");
+            }
+        } catch (FileNotFoundException e) {
+            LOGGER.info("local module json file not found");

Review Comment:
   LOGGER.warn or LOGGER.error for exception



-- 
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: commits-unsubscr...@inlong.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to