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

leonbao pushed a commit to branch 1.3.6-prepare
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git


The following commit(s) were added to refs/heads/1.3.6-prepare by this push:
     new f0f5dc6  [1.3.6-prepare][API] The API calls the workflow instance 
query interface and queries all the data when the time parameter is wrong #4817 
(#4915)
f0f5dc6 is described below

commit f0f5dc65c50058c44cc48794078c03dd63c403de
Author: Kirs <[email protected]>
AuthorDate: Tue Mar 9 17:44:17 2021 +0800

    [1.3.6-prepare][API] The API calls the workflow instance query interface 
and queries all the data when the time parameter is wrong #4817 (#4915)
---
 .../dolphinscheduler/api/service/BaseService.java  | 37 ++++++++++++++++++++++
 .../api/service/ProcessInstanceService.java        | 18 +++--------
 .../api/service/TaskInstanceService.java           | 18 +++--------
 .../api/service/ProcessInstanceServiceTest.java    | 19 ++++++++++-
 .../api/service/TaskInstanceServiceTest.java       |  9 +++++-
 .../apache/dolphinscheduler/common/Constants.java  |  4 +++
 6 files changed, 77 insertions(+), 28 deletions(-)

diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/BaseService.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/BaseService.java
index 3b81e2c..96bca0d 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/BaseService.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/BaseService.java
@@ -20,11 +20,15 @@ import org.apache.dolphinscheduler.api.enums.Status;
 import org.apache.dolphinscheduler.api.utils.Result;
 import org.apache.dolphinscheduler.common.Constants;
 import org.apache.dolphinscheduler.common.enums.UserType;
+import org.apache.dolphinscheduler.common.utils.DateUtils;
 import org.apache.dolphinscheduler.common.utils.HadoopUtils;
 import org.apache.dolphinscheduler.dao.entity.User;
 
 import java.text.MessageFormat;
+import java.util.Date;
+import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 
 /**
  * base service
@@ -128,4 +132,37 @@ public class BaseService {
     protected boolean hasPerm(User operateUser, int createUserId){
         return operateUser.getId() == createUserId || isAdmin(operateUser);
     }
+
+    /**
+     * check and parse date parameters
+     *
+     * @param startDateStr start date string
+     * @param endDateStr end date string
+     * @return map<status,startDate,endDate>
+     */
+    Map<String, Object> checkAndParseDateParameters(String startDateStr, 
String endDateStr){
+        Map<String, Object> result = new HashMap<>();
+        Date start = null;
+        if (StringUtils.isNotEmpty(startDateStr)) {
+            start = DateUtils.getScheduleDate(startDateStr);
+            if (Objects.isNull(start)) {
+                putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, 
Constants.START_END_DATE);
+                return result;
+            }
+        }
+        result.put(Constants.START_TIME, start);
+
+        Date end = null;
+        if (StringUtils.isNotEmpty(endDateStr)) {
+            end = DateUtils.getScheduleDate(endDateStr);
+            if (Objects.isNull(end)) {
+                putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, 
Constants.START_END_DATE);
+                return result;
+            }
+        }
+        result.put(Constants.END_TIME, end);
+
+        putMsg(result, Status.SUCCESS);
+        return result;
+    }
 }
diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java
index 365bb64..e16cb93 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java
@@ -158,20 +158,12 @@ public class ProcessInstanceService extends 
BaseDAGService {
         if (stateType != null) {
             statusArray = new int[]{stateType.ordinal()};
         }
-
-        Date start = null;
-        Date end = null;
-        try {
-            if (StringUtils.isNotEmpty(startDate)) {
-                start = DateUtils.getScheduleDate(startDate);
-            }
-            if (StringUtils.isNotEmpty(endDate)) {
-                end = DateUtils.getScheduleDate(endDate);
-            }
-        } catch (Exception e) {
-            putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, 
"startDate,endDate");
-            return result;
+        Map<String, Object> checkAndParseDateResult = 
checkAndParseDateParameters(startDate, endDate);
+        if (checkAndParseDateResult.get(Constants.STATUS) != Status.SUCCESS) {
+            return checkAndParseDateResult;
         }
+        Date start = (Date) checkAndParseDateResult.get(Constants.START_TIME);
+        Date end = (Date) checkAndParseDateResult.get(Constants.END_TIME);
 
         Page<ProcessInstance> page = new Page(pageNo, pageSize);
         PageInfo pageInfo = new PageInfo<ProcessInstance>(pageNo, pageSize);
diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java
index def1449..5c63c80 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java
@@ -97,20 +97,12 @@ public class TaskInstanceService extends BaseService {
             statusArray = new int[]{stateType.ordinal()};
         }
 
-        Date start = null;
-        Date end = null;
-        try {
-            if(StringUtils.isNotEmpty(startDate)){
-                start = DateUtils.getScheduleDate(startDate);
-            }
-            if(StringUtils.isNotEmpty( endDate)){
-                end = DateUtils.getScheduleDate(endDate);
-            }
-        } catch (Exception e) {
-            result.put(Constants.STATUS, 
Status.REQUEST_PARAMS_NOT_VALID_ERROR);
-            result.put(Constants.MSG, 
MessageFormat.format(Status.REQUEST_PARAMS_NOT_VALID_ERROR.getMsg(), 
"startDate,endDate"));
-            return result;
+        Map<String, Object> checkAndParseDateResult = 
checkAndParseDateParameters(startDate, endDate);
+        if (checkAndParseDateResult.get(Constants.STATUS) != Status.SUCCESS) {
+            return checkAndParseDateResult;
         }
+        Date start = (Date) checkAndParseDateResult.get(Constants.START_TIME);
+        Date end = (Date) checkAndParseDateResult.get(Constants.END_TIME);
 
         Page<TaskInstance> page = new Page(pageNo, pageSize);
         PageInfo pageInfo = new PageInfo<TaskInstance>(pageNo, pageSize);
diff --git 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java
 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java
index b356143..3207a12 100644
--- 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java
+++ 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java
@@ -107,9 +107,18 @@ public class ProcessInstanceServiceTest {
                 "192.168.xx.xx", 1, 10);
         Assert.assertEquals(Status.PROJECT_NOT_FOUNT, 
proejctAuthFailRes.get(Constants.STATUS));
 
-        //project auth success
+        // data parameter check
         putMsg(result, Status.SUCCESS, projectName);
         Project project = getProject(projectName);
+        when(projectMapper.queryByName(projectName)).thenReturn(project);
+        when(projectService.checkProjectAndAuth(loginUser, project, 
projectName)).thenReturn(result);
+        Map<String, Object> dataParameterRes = 
processInstanceService.queryProcessInstanceList(loginUser, projectName, 1, 
"20200101 00:00:00",
+                "20200102 00:00:00", "", loginUser.getUserName(), 
ExecutionStatus.SUBMITTED_SUCCESS,
+                "192.168.xx.xx", 1, 10);
+        Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, 
dataParameterRes.get(Constants.STATUS));
+
+        //project auth success
+        putMsg(result, Status.SUCCESS, projectName);
         Date start = DateUtils.getScheduleDate("2020-01-01 00:00:00");
         Date end = DateUtils.getScheduleDate("2020-01-02 00:00:00");
         ProcessInstance processInstance = getProcessInstance();
@@ -129,6 +138,14 @@ public class ProcessInstanceServiceTest {
                 "192.168.xx.xx", 1, 10);
         Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
 
+        // data parameter empty
+        
when(processInstanceMapper.queryProcessInstanceListPaging(Mockito.any(Page.class),
 eq(project.getId()), eq(1), eq(""), eq(-1), Mockito.any(),
+                eq("192.168.xx.xx"), eq(null), 
eq(null))).thenReturn(pageReturn);
+        successRes = 
processInstanceService.queryProcessInstanceList(loginUser, projectName, 1, "",
+                "", "", loginUser.getUserName(), 
ExecutionStatus.SUBMITTED_SUCCESS,
+                "192.168.xx.xx", 1, 10);
+        Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
+
         //executor null
         when(usersService.queryUser(loginUser.getId())).thenReturn(null);
         
when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(-1);
diff --git 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java
 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java
index ebb6139..18c5a02 100644
--- 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java
+++ 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java
@@ -88,10 +88,17 @@ public class TaskInstanceServiceTest {
                 "test_user", "2019-02-26 19:48:00", "2019-02-26 19:48:22", "", 
null, "", 1, 20);
         Assert.assertEquals(Status.PROJECT_NOT_FOUNT, 
proejctAuthFailRes.get(Constants.STATUS));
 
+        // data parameter check
+        putMsg(result, Status.SUCCESS, projectName);
+        Project project = getProject(projectName);
+        
when(projectMapper.queryByName(Mockito.anyString())).thenReturn(project);
+        when(projectService.checkProjectAndAuth(loginUser, project, 
projectName)).thenReturn(result);
+        Map<String, Object> dataParameterRes = 
taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "",
+                "test_user", "20200101 00:00:00", "2020-01-02 00:00:00", 
ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20);
+        Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, 
dataParameterRes.get(Constants.STATUS));
 
         //project
         putMsg(result, Status.SUCCESS, projectName);
-        Project project = getProject(projectName);
         Date start = DateUtils.getScheduleDate("2020-01-01 00:00:00");
         Date end = DateUtils.getScheduleDate("2020-01-02 00:00:00");
         ProcessInstance processInstance = getProcessInstance();
diff --git 
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java
 
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java
index cc92383..7f7421f 100644
--- 
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java
+++ 
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java
@@ -991,6 +991,10 @@ public final class Constants {
     public static final int NORAML_NODE_STATUS = 0;
     public static final int ABNORMAL_NODE_STATUS = 1;
 
+    public static final String START_TIME = "start time";
+    public static final String END_TIME = "end time";
+    public static final String START_END_DATE = "startDate,endDate";
+
     /**
      * datasource encryption salt
      */

Reply via email to