fuweng11 commented on code in PR #10602:
URL: https://github.com/apache/inlong/pull/10602#discussion_r1673588240


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/source/AbstractSourceOperator.java:
##########
@@ -346,4 +403,222 @@ public void syncSourceFieldInfo(SourceRequest request, 
String operator) {
     public Integer addDataAddTask(DataAddTaskRequest request, String operator) 
{
         throw new BusinessException(String.format("not support data add task 
for type =%s", request.getSourceType()));
     }
+
+    private void updateAgentTaskConfig(SourceRequest request, String operator) 
{
+        try {
+            if (SourceType.AUTO_PUSH.equals(request.getSourceType())) {
+                return;
+            }
+            final String clusterName = request.getInlongClusterName();
+            final String ip = request.getAgentIp();
+            final String uuid = request.getUuid();
+            if (StringUtils.isBlank(clusterName) || StringUtils.isBlank(ip)) {
+                return;
+            }
+            AgentTaskConfigEntity existEntity = 
agentTaskConfigEntityMapper.selectByIdentifier(ip, clusterName);
+            AgentTaskConfigEntity agentTaskConfigEntity = new 
AgentTaskConfigEntity();
+            if (existEntity != null) {
+                agentTaskConfigEntity = 
CommonBeanUtils.copyProperties(existEntity, AgentTaskConfigEntity::new, true);
+            }
+            List<StreamSourceEntity> normalSourceEntities = 
sourceMapper.selectByStatusAndCluster(
+                    
SourceStatus.NORMAL_STATUS_SET.stream().map(SourceStatus::getCode)
+                            .collect(Collectors.toList()),
+                    clusterName, ip, uuid);
+            List<StreamSourceEntity> taskLists = new 
ArrayList<>(normalSourceEntities);
+            List<StreamSourceEntity> stopSourceEntities = 
sourceMapper.selectByStatusAndCluster(
+                    
SourceStatus.STOP_STATUS_SET.stream().map(SourceStatus::getCode)
+                            .collect(Collectors.toList()),
+                    clusterName, ip, uuid);
+            taskLists.addAll(stopSourceEntities);
+            LOGGER.debug("success to add task : {}", taskLists.size());
+            List<DataConfig> runningTaskConfig = Lists.newArrayList();
+            List<CmdConfig> cmdConfigs = 
sourceCmdConfigMapper.queryCmdByAgentIp(request.getAgentIp()).stream()
+                    .map(cmd -> {
+                        CmdConfig cmdConfig = new CmdConfig();
+                        cmdConfig.setDataTime(cmd.getSpecifiedDataTime());
+                        cmdConfig.setOp(cmd.getCmdType());
+                        cmdConfig.setId(cmd.getId());
+                        cmdConfig.setTaskId(cmd.getTaskId());
+                        return cmdConfig;
+                    }).collect(Collectors.toList());
+            if (CollectionUtils.isEmpty(taskLists)) {
+                
agentTaskConfigEntity.setIsDeleted(agentTaskConfigEntity.getId());
+                
agentTaskConfigEntityMapper.updateByIdSelective(agentTaskConfigEntity);
+                return;
+            }
+            for (StreamSourceEntity sourceEntity : taskLists) {
+                int op = sourceEntity.getStatus() % MODULUS_100;
+                DataConfig dataConfig = getDataConfig(sourceEntity, op);
+                runningTaskConfig.add(dataConfig);
+            }
+            TaskResult taskResult =
+                    
TaskResult.builder().dataConfigs(runningTaskConfig).cmdConfigs(cmdConfigs).build();
+            String md5 = DigestUtils.md5Hex(GSON.toJson(taskResult));
+            taskResult.setMd5(md5);
+            taskResult.setCode(AgentResponseCode.SUCCESS);
+            agentTaskConfigEntity.setAgentIp(request.getAgentIp());
+            
agentTaskConfigEntity.setClusterName(request.getInlongClusterName());
+            
agentTaskConfigEntity.setTaskParams(objectMapper.writeValueAsString(taskResult));
+
+            LOGGER.debug("begin to get agent config info for {}", request);
+            Set<String> tagSet = new HashSet<>(16);
+            List<StreamSourceEntity> sourceEntities =

Review Comment:
   Fixed.



##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/source/AbstractSourceOperator.java:
##########
@@ -346,4 +403,222 @@ public void syncSourceFieldInfo(SourceRequest request, 
String operator) {
     public Integer addDataAddTask(DataAddTaskRequest request, String operator) 
{
         throw new BusinessException(String.format("not support data add task 
for type =%s", request.getSourceType()));
     }
+
+    private void updateAgentTaskConfig(SourceRequest request, String operator) 
{
+        try {
+            if (SourceType.AUTO_PUSH.equals(request.getSourceType())) {
+                return;
+            }
+            final String clusterName = request.getInlongClusterName();
+            final String ip = request.getAgentIp();
+            final String uuid = request.getUuid();
+            if (StringUtils.isBlank(clusterName) || StringUtils.isBlank(ip)) {

Review Comment:
   Fixed.



##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/AgentServiceImpl.java:
##########
@@ -293,6 +302,43 @@ public void report(TaskRequest request) {
         }
     }
 
+    @Transactional(rollbackFor = Exception.class)
+    public void reload() {
+        LOGGER.debug("start to reload agent task config.");
+        try {
+            Map<String, TaskResult> tempTaskConfigMap = new 
ConcurrentHashMap<>();
+            Map<String, AgentConfigInfo> tempAgentConfigMap = new 
ConcurrentHashMap<>();
+            List<AgentTaskConfigEntity> agentTaskConfigEntityList = 
configLoader.loadAllAgentTaskConfigEntity();
+            agentTaskConfigEntityList.forEach(agentTaskConfigEntity -> {
+                try {
+                    String key = agentTaskConfigEntity.getAgentIp() + 
InlongConstants.UNDERSCORE
+                            + agentTaskConfigEntity.getClusterName();
+                    TaskResult taskResult = 
JsonUtils.parseObject(agentTaskConfigEntity.getTaskParams(),
+                            TaskResult.class);
+                    if (taskResult != null) {
+                        
taskResult.setVersion(agentTaskConfigEntity.getVersion());
+                        tempTaskConfigMap.putIfAbsent(key, taskResult);
+                    }
+                    AgentConfigInfo agentConfigInfo = 
JsonUtils.parseObject(agentTaskConfigEntity.getConfigParams(),
+                            AgentConfigInfo.class);
+                    if (agentConfigInfo != null) {
+                        
agentConfigInfo.setVersion(agentTaskConfigEntity.getVersion());
+                        tempAgentConfigMap.putIfAbsent(key, agentConfigInfo);
+                    }
+                } catch (Exception e) {
+                    LOGGER.error("failed to get agent task confgi for agent 
ip={}, cluster name={}",

Review Comment:
   60000L



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