This is an automated email from the ASF dual-hosted git repository.

dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new 150fd4cf4f [INLONG-10754][Manager] Add start and end time check for 
schedule info (#10755)
150fd4cf4f is described below

commit 150fd4cf4f9a199387914c49b867197e5c9b04a7
Author: AloysZhang <aloyszh...@apache.org>
AuthorDate: Wed Aug 7 20:50:44 2024 +0800

    [INLONG-10754][Manager] Add start and end time check for schedule info 
(#10755)
    
    Co-authored-by: Aloys Zhang <aloyszh...@apche.org>
---
 .../service/group/InlongGroupServiceImpl.java      | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/group/InlongGroupServiceImpl.java
 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/group/InlongGroupServiceImpl.java
index 6431cd9e48..99fae2bf86 100644
--- 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/group/InlongGroupServiceImpl.java
+++ 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/group/InlongGroupServiceImpl.java
@@ -104,6 +104,7 @@ import 
org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 
+import java.sql.Timestamp;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -221,6 +222,7 @@ public class InlongGroupServiceImpl implements 
InlongGroupService {
 
         // save schedule info for offline group
         if (DATASYNC_OFFLINE_MODE.equals(request.getInlongGroupMode())) {
+            constrainStartAndEndTime(request);
             scheduleOperator.saveOpt(CommonBeanUtils.copyProperties(request, 
ScheduleInfoRequest::new), operator);
         }
 
@@ -228,6 +230,29 @@ public class InlongGroupServiceImpl implements 
InlongGroupService {
         return groupId;
     }
 
+    /**
+     * Add constraints to the start and end time of the offline 
synchronization group.
+     * 1. startTime must >= current time
+     * 2. endTime must >= startTime
+     * */
+    private void constrainStartAndEndTime(InlongGroupRequest request) {
+        Timestamp startTime = request.getStartTime();
+        Timestamp endTime = request.getEndTime();
+        Preconditions.expectTrue(startTime != null && endTime != null, "start 
time or end time cannot be empty");
+        long currentTime = System.currentTimeMillis();
+        if (startTime.getTime() < currentTime) {
+            Timestamp newStartTime = new Timestamp(currentTime);
+            request.setStartTime(newStartTime);
+            LOGGER.warn("start time is less than current time, re-set to 
current time for groupId={}, "
+                    + "startTime={}, newStartTime={}", 
request.getInlongGroupId(), startTime, newStartTime);
+        }
+        if (request.getStartTime().getTime() > endTime.getTime()) {
+            request.setEndTime(request.getStartTime());
+            LOGGER.warn("end time is less than start time, re-set end time to 
start time for groupId={}, "
+                    + "endTime={}, newEndTime={}", request.getInlongGroupId(), 
endTime, request.getEndTime());
+        }
+    }
+
     @Override
     @Transactional(rollbackFor = Throwable.class)
     public List<BatchResult> batchSave(List<InlongGroupRequest> 
groupRequestList, String operator) {
@@ -498,6 +523,7 @@ public class InlongGroupServiceImpl implements 
InlongGroupService {
 
         // save schedule info for offline group
         if (DATASYNC_OFFLINE_MODE.equals(request.getInlongGroupMode())) {
+            constrainStartAndEndTime(request);
             
scheduleOperator.updateAndRegister(CommonBeanUtils.copyProperties(request, 
ScheduleInfoRequest::new),
                     operator);
         }

Reply via email to