vernedeng commented on code in PR #10637:
URL: https://github.com/apache/inlong/pull/10637#discussion_r1679052833


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/cluster/node/AgentClusterNodeOperator.java:
##########
@@ -88,4 +164,94 @@ protected void setTargetEntity(ClusterNodeRequest request, 
InlongClusterNodeEnti
                     String.format("serialize extParams of Agent ClusterNode 
failure: %s", e.getMessage()));
         }
     }
+
+    public void updateModuleConfig(String ip, String clusterName) {
+        try {
+            ConfigRequest configRequest = new ConfigRequest();
+            LOGGER.info("begin to update module config for cluster name={}, 
ip={}", clusterName, ip);
+            if (StringUtils.isBlank(clusterName) || StringUtils.isBlank(ip)) {
+                LOGGER.info("no need to update module config when ip or 
cluster name is null");
+                return;
+            }
+            configRequest.setLocalIp(ip);
+            configRequest.setClusterName(clusterName);
+            ConfigResult configResult = loadModuleConfigs(configRequest);
+            AgentTaskConfigEntity existEntity = 
agentTaskConfigEntityMapper.selectByIdentifier(ip, clusterName);
+            AgentTaskConfigEntity agentTaskConfigEntity = new 
AgentTaskConfigEntity();
+            if (existEntity != null) {
+                agentTaskConfigEntity = 
CommonBeanUtils.copyProperties(existEntity, AgentTaskConfigEntity::new, true);
+            }
+            agentTaskConfigEntity.setAgentIp(ip);
+            agentTaskConfigEntity.setClusterName(clusterName);
+            
agentTaskConfigEntity.setModuleParams(objectMapper.writeValueAsString(configResult));
+            if (existEntity == null) {
+                agentTaskConfigEntityMapper.insert(agentTaskConfigEntity);
+            } else {
+                
agentTaskConfigEntityMapper.updateByIdSelective(agentTaskConfigEntity);
+            }
+            LOGGER.info("success to update module config for cluster name={}, 
ip={}", clusterName, ip);
+        } catch (Exception e) {
+            LOGGER.error("load module config failed", e);
+            throw new BusinessException("load module config faield");
+        }
+    }
+
+    private ConfigResult loadModuleConfigs(ConfigRequest request) {
+        final String clusterName = request.getClusterName();
+        final String ip = request.getLocalIp();
+        LOGGER.debug("begin to load config for installer = {}", request);
+        Preconditions.expectTrue(StringUtils.isNotBlank(clusterName), "cluster 
name is blank");
+        InlongClusterEntity clusterEntity = 
clusterMapper.selectByNameAndType(clusterName, ClusterType.AGENT);
+        List<ModuleConfig> configs = new ArrayList<>();
+        if (clusterEntity != null) {
+            List<InlongClusterNodeEntity> clusterNodeEntityList =
+                    
clusterNodeMapper.selectByParentIdAndIp(clusterEntity.getId(), ip);
+            if (CollectionUtils.isNotEmpty(clusterNodeEntityList)) {
+                AgentClusterNodeDTO dto = 
AgentClusterNodeDTO.getFromJson(clusterNodeEntityList.get(0).getExtParams());
+                configs = getModuleConfigs(dto);
+            }
+        }
+        String jsonStr = GSON.toJson(configs);
+        String configMd5 = DigestUtils.md5Hex(jsonStr);
+
+        ConfigResult configResult = 
ConfigResult.builder().moduleList(configs).md5(configMd5)
+                .code(AgentResponseCode.SUCCESS)
+                .build();
+        LOGGER.info("success load module config, size = {}", 
configResult.getModuleList().size());
+        return configResult;
+    }
+
+    private List<ModuleConfig> getModuleConfigs(AgentClusterNodeDTO dto) {
+        List<Integer> moduleIdList = dto.getModuleIdList();
+        List<ModuleConfig> configs = new ArrayList<>();
+        if (CollectionUtils.isEmpty(moduleIdList)) {
+            return configs;
+        }
+        for (Integer moduleId : moduleIdList) {
+            ModuleConfigEntity moduleConfigEntity = 
moduleConfigEntityMapper.selectByPrimaryKey(moduleId);
+            ModuleConfig moduleConfig = 
CommonBeanUtils.copyProperties(moduleConfigEntity, ModuleConfig::new);

Review Comment:
   may produce NPE?



-- 
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]

Reply via email to