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

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


The following commit(s) were added to refs/heads/dev by this push:
     new f7c4b0f  [Improvement-3556] remove unnecessary try catch, and do the 
unittest … (#3563)
f7c4b0f is described below

commit f7c4b0f3514284941f8e5625bb0d7e836e94b512
Author: geosmart <[email protected]>
AuthorDate: Tue Aug 25 10:51:02 2020 +0800

    [Improvement-3556] remove unnecessary try catch, and do the unittest … 
(#3563)
    
    * [Improvement-3556] remove unnecessary try catch, and do the unittest to 
full coverage.
    
    * [Improvement-3556] add REQUEST_PARAMS_NOT_VALID_ERROR res when param is 
not valid
    
    * [fix-3548] Monitor gauge chart display blank with same pid
    
    Co-authored-by: wanggang <[email protected]>
---
 .../api/service/TaskInstanceService.java           | 61 ++++++++++++++--------
 .../api/service/TaskInstanceServiceTest.java       | 23 ++++++--
 .../home/pages/monitor/pages/servers/master.vue    |  1 +
 .../home/pages/monitor/pages/servers/worker.vue    |  1 +
 4 files changed, 60 insertions(+), 26 deletions(-)

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 c5a0900..695b76b 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
@@ -17,8 +17,6 @@
 package org.apache.dolphinscheduler.api.service;
 
 
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.apache.dolphinscheduler.api.enums.Status;
 import org.apache.dolphinscheduler.api.utils.PageInfo;
 import org.apache.dolphinscheduler.common.Constants;
@@ -32,11 +30,20 @@ import org.apache.dolphinscheduler.dao.entity.User;
 import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
 import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper;
 import org.apache.dolphinscheduler.service.process.ProcessService;
+
+import java.text.MessageFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.text.MessageFormat;
-import java.util.*;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 
 /**
  * task instance service
@@ -79,10 +86,10 @@ public class TaskInstanceService extends BaseService {
      * @param pageSize page size
      * @return task list page
      */
-    public Map<String,Object> queryTaskListPaging(User loginUser, String 
projectName,
-                                                  Integer processInstanceId, 
String taskName, String executorName, String startDate,
-                                                  String endDate, String 
searchVal, ExecutionStatus stateType,String host,
-                                                  Integer pageNo, Integer 
pageSize) {
+    public Map<String, Object> queryTaskListPaging(User loginUser, String 
projectName,
+                                                   Integer processInstanceId, 
String taskName, String executorName, String startDate,
+                                                   String endDate, String 
searchVal, ExecutionStatus stateType, String host,
+                                                   Integer pageNo, Integer 
pageSize) {
         Map<String, Object> result = new HashMap<>();
         Project project = projectMapper.queryByName(projectName);
 
@@ -93,23 +100,23 @@ public class TaskInstanceService extends BaseService {
         }
 
         int[] statusArray = null;
-        if(stateType != null){
+        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(startDate)) {
+            start = DateUtils.getScheduleDate(startDate);
+            if (start == null) {
+                return generateInvalidParamRes(result, "startDate");
             }
-            if(StringUtils.isNotEmpty( endDate)){
-                end = DateUtils.getScheduleDate(endDate);
+        }
+        if (StringUtils.isNotEmpty(endDate)) {
+            end = DateUtils.getScheduleDate(endDate);
+            if (end == null) {
+                return generateInvalidParamRes(result, "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;
         }
 
         Page<TaskInstance> page = new Page(pageNo, pageSize);
@@ -124,18 +131,30 @@ public class TaskInstanceService extends BaseService {
         exclusionSet.add("taskJson");
         List<TaskInstance> taskInstanceList = taskInstanceIPage.getRecords();
 
-        for(TaskInstance taskInstance : taskInstanceList){
+        for (TaskInstance taskInstance : taskInstanceList) {
             
taskInstance.setDuration(DateUtils.differSec(taskInstance.getStartTime(), 
taskInstance.getEndTime()));
             User executor = 
usersService.queryUser(taskInstance.getExecutorId());
             if (null != executor) {
                 taskInstance.setExecutorName(executor.getUserName());
             }
         }
-        pageInfo.setTotalCount((int)taskInstanceIPage.getTotal());
-        
pageInfo.setLists(CollectionUtils.getListByExclusion(taskInstanceIPage.getRecords(),exclusionSet));
+        pageInfo.setTotalCount((int) taskInstanceIPage.getTotal());
+        
pageInfo.setLists(CollectionUtils.getListByExclusion(taskInstanceIPage.getRecords(),
 exclusionSet));
         result.put(Constants.DATA_LIST, pageInfo);
         putMsg(result, Status.SUCCESS);
 
         return result;
     }
+
+    /***
+     * generate {@link 
org.apache.dolphinscheduler.api.enums.Status#REQUEST_PARAMS_NOT_VALID_ERROR} 
res with  param name
+     * @param result exist result map
+     * @param params invalid params name
+     * @return update result map
+     */
+    private Map<String, Object> generateInvalidParamRes(Map<String, Object> 
result, String params) {
+        result.put(Constants.STATUS, Status.REQUEST_PARAMS_NOT_VALID_ERROR);
+        result.put(Constants.MSG, 
MessageFormat.format(Status.REQUEST_PARAMS_NOT_VALID_ERROR.getMsg(), params));
+        return result;
+    }
 }
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 f93ed05..16547b3 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
@@ -16,6 +16,7 @@
  */
 package org.apache.dolphinscheduler.api.service;
 
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.when;
 
@@ -75,14 +76,10 @@ public class TaskInstanceServiceTest {
     TaskInstanceMapper taskInstanceMapper;
 
     @Mock
-    ProcessInstanceService processInstanceService;
-
-    @Mock
     UsersService usersService;
 
     @Test
     public void queryTaskListPaging() {
-
         String projectName = "project_test1";
         User loginUser = getAdminUser();
         Map<String, Object> result = new HashMap<>();
@@ -95,7 +92,6 @@ 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));
 
-
         //project
         putMsg(result, Status.SUCCESS, projectName);
         Project project = getProject(projectName);
@@ -133,6 +129,23 @@ public class TaskInstanceServiceTest {
         Map<String, Object> executorNullRes = 
taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "",
                 "test_user", "2020-01-01 00:00:00", "2020-01-02 00:00:00", "", 
ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20);
         Assert.assertEquals(Status.SUCCESS, 
executorNullRes.get(Constants.STATUS));
+
+        //start/end date null
+        
when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), 
eq(project.getId()), eq(1), eq(""), eq(""),
+                eq(0), Mockito.any(), eq("192.168.xx.xx"), any(), 
any())).thenReturn(pageReturn);
+        Map<String, Object> executorNullDateRes = 
taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "",
+                "", null, null, "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 
1, 20);
+        Assert.assertEquals(Status.SUCCESS, 
executorNullDateRes.get(Constants.STATUS));
+
+        //start date error format
+        
when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), 
eq(project.getId()), eq(1), eq(""), eq(""),
+                eq(0), Mockito.any(), eq("192.168.xx.xx"), any(), 
any())).thenReturn(pageReturn);
+        Map<String, Object> executorErrorStartDateRes = 
taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "",
+                "", "error date", null, "", ExecutionStatus.SUCCESS, 
"192.168.xx.xx", 1, 20);
+        Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, 
executorErrorStartDateRes.get(Constants.STATUS));
+        Map<String, Object> executorErrorEndDateRes = 
taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "",
+                "", null, "error date", "", ExecutionStatus.SUCCESS, 
"192.168.xx.xx", 1, 20);
+        Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, 
executorErrorEndDateRes.get(Constants.STATUS));
     }
 
     /**
diff --git 
a/dolphinscheduler-ui/src/js/conf/home/pages/monitor/pages/servers/master.vue 
b/dolphinscheduler-ui/src/js/conf/home/pages/monitor/pages/servers/master.vue
index 5b5032c..8182dac 100644
--- 
a/dolphinscheduler-ui/src/js/conf/home/pages/monitor/pages/servers/master.vue
+++ 
b/dolphinscheduler-ui/src/js/conf/home/pages/monitor/pages/servers/master.vue
@@ -95,6 +95,7 @@
       this.getMasterData().then(res => {
         this.masterList = _.map(res, (v, i) => {
           return _.assign(v, {
+            id: v.host + "_" + v.id,
             resInfo: JSON.parse(v.resInfo)
           })
         })
diff --git 
a/dolphinscheduler-ui/src/js/conf/home/pages/monitor/pages/servers/worker.vue 
b/dolphinscheduler-ui/src/js/conf/home/pages/monitor/pages/servers/worker.vue
index aa2deca..609987e 100644
--- 
a/dolphinscheduler-ui/src/js/conf/home/pages/monitor/pages/servers/worker.vue
+++ 
b/dolphinscheduler-ui/src/js/conf/home/pages/monitor/pages/servers/worker.vue
@@ -115,6 +115,7 @@
       this.getWorkerData().then(res => {
         this.workerList = _.map(res, (v, i) => {
           return _.assign(v, {
+            id: v.host + "_" + v.id,
             resInfo: JSON.parse(v.resInfo)
           })
         })

Reply via email to