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


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/schedule/ScheduleOperatorImpl.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.manager.service.schedule;
+
+import org.apache.inlong.manager.common.consts.InlongConstants;
+import org.apache.inlong.manager.common.util.CommonBeanUtils;
+import org.apache.inlong.manager.dao.entity.InlongGroupExtEntity;
+import org.apache.inlong.manager.dao.mapper.InlongGroupExtEntityMapper;
+import org.apache.inlong.manager.dao.mapper.ScheduleEntityMapper;
+import org.apache.inlong.manager.pojo.schedule.ScheduleInfo;
+import org.apache.inlong.manager.pojo.schedule.ScheduleInfoRequest;
+import org.apache.inlong.manager.schedule.ScheduleClientFactory;
+import org.apache.inlong.manager.schedule.ScheduleEngineClient;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import static org.apache.inlong.manager.common.enums.ScheduleStatus.APPROVED;
+import static org.apache.inlong.manager.common.enums.ScheduleStatus.REGISTERED;
+import static org.apache.inlong.manager.common.enums.ScheduleStatus.UPDATED;
+
+@Service
+public class ScheduleOperatorImpl implements ScheduleOperator {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(ScheduleOperatorImpl.class);
+
+    @Autowired
+    private ScheduleService scheduleService;
+
+    @Autowired
+    private InlongGroupExtEntityMapper groupExtMapper;
+
+    @Autowired
+    private ScheduleEntityMapper scheduleMapper;
+
+    @Autowired
+    private ScheduleClientFactory scheduleClientFactory;
+
+    private ScheduleEngineClient scheduleEngineClient;
+
+    @Override
+    public int saveOpt(ScheduleInfoRequest request, String operator) {
+        // save schedule info first
+        int res = scheduleService.save(request, operator);
+        LOGGER.info("Save schedule info success for group {}", 
request.getInlongGroupId());
+        // process new schedule info for approved inlong group
+        
registerScheduleInfoForApprovedGroup(CommonBeanUtils.copyProperties(request, 
ScheduleInfo::new), operator);
+        return res;
+    }
+
+    /**
+     * If an inlong group in DATASYNC_OFFLINE_MODE created first without 
schedule info and has been approved, it should
+     * be registered to schedule engine once the schedule info for this group 
is added.
+     * */
+    private void registerScheduleInfoForApprovedGroup(ScheduleInfo 
scheduleInfo, String operator) {
+        String groupId = scheduleInfo.getInlongGroupId();
+        InlongGroupExtEntity scheduleStatusExt =
+                groupExtMapper.selectByUniqueKey(groupId, 
InlongConstants.REGISTER_SCHEDULE_STATUS);
+        if 
(InlongConstants.REGISTERED.equalsIgnoreCase(scheduleStatusExt.getKeyValue())) {
+            // change schedule state to approved
+            scheduleService.updateStatus(scheduleInfo.getInlongGroupId(), 
APPROVED, operator);
+            getScheduleEngineClient().register(scheduleInfo);
+            // change schedule state to registered
+            scheduleService.updateStatus(scheduleInfo.getInlongGroupId(), 
REGISTERED, operator);
+            LOGGER.info("Register schedule info success for group {}", 
groupId);
+        }
+    }
+
+    private ScheduleEngineClient getScheduleEngineClient() {
+        if (scheduleEngineClient == null) {
+            scheduleEngineClient = scheduleClientFactory.getInstance();
+        }
+        return scheduleEngineClient;
+    }
+
+    @Override
+    public Boolean scheduleInfoExist(String groupId) {
+        return scheduleService.exist(groupId);
+    }
+
+    @Override
+    public ScheduleInfo getScheduleInfo(String groupId) {
+        return scheduleService.get(groupId);
+    }
+
+    @Override
+    public Boolean updateOpt(ScheduleInfoRequest request, String operator) {
+        // if the inlong group exist without schedule info
+        // then, save the new schedule info when updating inlong group
+        if (!scheduleInfoExist(request.getInlongGroupId())) {
+            saveOpt(request, operator);
+            return true;
+        }
+        ScheduleInfo scheduleInfo = CommonBeanUtils.copyProperties(request, 
ScheduleInfo::new);
+        if (!needUpdate(scheduleInfo)) {
+            LOGGER.info("schedule info not changed for group {}", 
request.getInlongGroupId());
+            return false;
+        }
+        // update schedule info
+        scheduleService.update(request, operator);
+        LOGGER.info("Update schedule info success for group {}", 
request.getInlongGroupId());
+        // update register to schedule engine
+        boolean res = getScheduleEngineClient().update(scheduleInfo);
+        scheduleService.updateStatus(request.getInlongGroupId(), UPDATED, 
operator);
+        LOGGER.info("Update schedule info success for group {}", 
request.getInlongGroupId());

Review Comment:
   Duplicate logs.



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