You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by li...@apache.org on 2020/02/10 08:37:59 UTC

[incubator-dolphinscheduler] branch dev updated: Add modify user name for process definition (#1919)

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

lidongdai 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 d937a6a  Add modify user name for process definition (#1919)
d937a6a is described below

commit d937a6ae9421b4df20a524de0ca8e93524e96d12
Author: Yelli <am...@my.com>
AuthorDate: Mon Feb 10 16:37:51 2020 +0800

    Add modify user name for process definition (#1919)
    
    * class overrides equals() and should therefore also override hashCode()
    
    * #1862 add modify user in process difinition list
    
    * #1862 add pg-1.2.2 ddl.sql
    
    * modify ScriptRunnerTest
    
    * add updateProessDifinition UT
    
    * modify updateProcessDifinition UT
    
    * modify updateProcessDifinition UT
    
    * modify mysql 1.2.2 ddl.sql&dml.sql
    
    * add scope test to mysql in pom
    
    * modify pg-1.2.2 ddl.sql
---
 .../api/service/ProcessDefinitionService.java      |  2 +
 .../api/service/ProcessDefinitionServiceTest.java  | 27 ++++++++++++
 .../common/utils/ScriptRunner.java                 |  4 +-
 .../common/utils/ScriptRunnerTest.java             |  4 +-
 .../dao/entity/ProcessDefinition.java              | 48 ++++++++++++++--------
 .../pages/definition/pages/list/_source/list.vue   |  7 ++++
 .../src/js/module/i18n/locale/en_US.js             |  1 +
 .../src/js/module/i18n/locale/zh_CN.js             |  1 +
 pom.xml                                            |  1 +
 sql/dolphinscheduler-postgre.sql                   |  1 +
 sql/dolphinscheduler_mysql.sql                     |  1 +
 .../1.2.2_schema/mysql/dolphinscheduler_ddl.sql    | 37 +++++++++++++++++
 .../1.2.2_schema/mysql/dolphinscheduler_dml.sql    | 16 ++++++++
 .../postgresql/dolphinscheduler_ddl.sql            | 34 +++++++++++++++
 .../postgresql/dolphinscheduler_dml.sql            | 16 ++++++++
 15 files changed, 180 insertions(+), 20 deletions(-)

diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java
index 5fe708c..8a762d7 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java
@@ -143,6 +143,7 @@ public class ProcessDefinitionService extends BaseDAGService {
         processDefine.setConnects(connects);
         processDefine.setTimeout(processData.getTimeout());
         processDefine.setTenantId(processData.getTenantId());
+        processDefine.setModifyBy(loginUser.getUserName());
 
         //custom global params
         List<Property> globalParamsList = processData.getGlobalParams();
@@ -308,6 +309,7 @@ public class ProcessDefinitionService extends BaseDAGService {
         processDefine.setConnects(connects);
         processDefine.setTimeout(processData.getTimeout());
         processDefine.setTenantId(processData.getTenantId());
+        processDefine.setModifyBy(loginUser.getUserName());
 
         //custom global params
         List<Property> globalParamsList = new ArrayList<>();
diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java
index b30a919..a4b07e1 100644
--- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java
+++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java
@@ -27,6 +27,7 @@ import org.apache.dolphinscheduler.common.enums.*;
 import org.apache.dolphinscheduler.common.utils.DateUtils;
 import org.apache.dolphinscheduler.common.utils.FileUtils;
 import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.dolphinscheduler.dao.ProcessDao;
 import org.apache.dolphinscheduler.dao.entity.*;
 import org.apache.dolphinscheduler.dao.mapper.*;
 import org.apache.http.entity.ContentType;
@@ -77,6 +78,9 @@ public class ProcessDefinitionServiceTest {
     @Mock
     private WorkerGroupMapper workerGroupMapper;
 
+    @Mock
+    private ProcessDao processDao;
+
     private String sqlDependentJson = "{\"globalParams\":[]," +
             "\"tasks\":[{\"type\":\"SQL\",\"id\":\"tasks-27297\",\"name\":\"sql\"," +
             "\"params\":{\"type\":\"MYSQL\",\"datasource\":1,\"sql\":\"select * from test\"," +
@@ -422,6 +426,27 @@ public class ProcessDefinitionServiceTest {
         Assert.assertTrue(deleteFlag);
     }
 
+    @Test
+    public void testUpdateProcessDefinition () {
+        User loginUser = new User();
+        loginUser.setId(1);
+        loginUser.setUserType(UserType.ADMIN_USER);
+
+        Map<String, Object> result = new HashMap<>(5);
+        putMsg(result, Status.SUCCESS);
+
+        String projectName = "project_test1";
+        Project project = getProject(projectName);
+
+        Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName));
+        Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
+        Mockito.when(processDao.findProcessDefineById(1)).thenReturn(getProcessDefinition());
+
+        Map<String, Object> updateResult = processDefinitionService.updateProcessDefinition(loginUser, projectName, 1, "test",
+                sqlDependentJson, "", "", "");
+
+        Assert.assertEquals(Status.UPDATE_PROCESS_DEFINITION_ERROR, updateResult.get(Constants.STATUS));
+    }
 
     /**
      * get mock datasource
@@ -443,6 +468,8 @@ public class ProcessDefinitionServiceTest {
         processDefinition.setId(46);
         processDefinition.setName("testProject");
         processDefinition.setProjectId(2);
+        processDefinition.setTenantId(1);
+        processDefinition.setDescription("");
         return  processDefinition;
     }
 
diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ScriptRunner.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ScriptRunner.java
index bbc937c..f92839b 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ScriptRunner.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ScriptRunner.java
@@ -169,13 +169,13 @@ public class ScriptRunner {
                             if (stopOnError && rs != null) {
                                 ResultSetMetaData md = rs.getMetaData();
                                 int cols = md.getColumnCount();
-                                for (int i = 0; i < cols; i++) {
+                                for (int i = 1; i < cols; i++) {
                                     String name = md.getColumnLabel(i);
                                     logger.info("{} \t", name);
                                 }
                                 logger.info("");
                                 while (rs.next()) {
-                                    for (int i = 0; i < cols; i++) {
+                                    for (int i = 1; i < cols; i++) {
                                         String value = rs.getString(i);
                                         logger.info("{} \t", value);
                                     }
diff --git a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/ScriptRunnerTest.java b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/ScriptRunnerTest.java
index 0eb1cce..155d52a 100644
--- a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/ScriptRunnerTest.java
+++ b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/ScriptRunnerTest.java
@@ -48,7 +48,7 @@ public class ScriptRunnerTest {
             Mockito.when(st.getResultSet()).thenReturn(rs);
             ResultSetMetaData md = Mockito.mock(ResultSetMetaData.class);
             Mockito.when(rs.getMetaData()).thenReturn(md);
-            Mockito.when(md.getColumnCount()).thenReturn(1);
+            Mockito.when(md.getColumnCount()).thenReturn(2);
             Mockito.when(rs.next()).thenReturn(true, false);
             ScriptRunner s = new ScriptRunner(conn, true, true);
             if (dbName.isEmpty()) {
@@ -56,7 +56,7 @@ public class ScriptRunnerTest {
             } else {
                 s.runScript(new StringReader("select 1;"), dbName);
             }
-            Mockito.verify(md).getColumnLabel(0);
+            Mockito.verify(md).getColumnLabel(1);
         } catch(Exception e) {
             Assert.assertNotNull(e);
         }
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java
index cd0494e..6e7ea7d 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java
@@ -29,6 +29,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.stream.Collectors;
 
 
@@ -158,6 +159,11 @@ public class ProcessDefinition {
      */
     private int tenantId;
 
+    /**
+     * modify user name
+     */
+    private String modifyBy;
+
 
     public String getName() {
         return name;
@@ -337,6 +343,30 @@ public class ProcessDefinition {
         this.timeout = timeout;
     }
 
+    public int getTenantId() {
+        return tenantId;
+    }
+
+    public void setTenantId(int tenantId) {
+        this.tenantId = tenantId;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getModifyBy() {
+        return modifyBy;
+    }
+
+    public void setModifyBy(String modifyBy) {
+        this.modifyBy = modifyBy;
+    }
+
     @Override
     public String toString() {
         return "ProcessDefinition{" +
@@ -346,6 +376,7 @@ public class ProcessDefinition {
                 ", releaseState=" + releaseState +
                 ", projectId=" + projectId +
                 ", processDefinitionJson='" + processDefinitionJson + '\'' +
+                ", description='" + description + '\'' +
                 ", globalParams='" + globalParams + '\'' +
                 ", globalParamList=" + globalParamList +
                 ", globalParamMap=" + globalParamMap +
@@ -362,22 +393,7 @@ public class ProcessDefinition {
                 ", scheduleReleaseState=" + scheduleReleaseState +
                 ", timeout=" + timeout +
                 ", tenantId=" + tenantId +
+                ", modifyBy='" + modifyBy + '\'' +
                 '}';
     }
-
-    public int getTenantId() {
-        return tenantId;
-    }
-
-    public void setTenantId(int tenantId) {
-        this.tenantId = tenantId;
-    }
-
-    public String getDescription() {
-        return description;
-    }
-
-    public void setDescription(String description) {
-        this.description = description;
-    }
 }
diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/list.vue b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/list.vue
index 5550864..53939f3 100644
--- a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/list.vue
+++ b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/definition/pages/list/_source/list.vue
@@ -40,6 +40,9 @@
           <th scope="col">
             <span>{{$t('Description')}}</span>
           </th>
+          <th scope="col" width="130">
+            <span>{{$t('Modify User')}}</span>
+          </th>
           <th scope="col" width="90">
             <span>{{$t('Timing state')}}</span>
           </th>
@@ -73,6 +76,10 @@
             <span v-else>-</span>
           </td>
           <td>
+            <span v-if="item.modifyBy">{{item.modifyBy}}</span>
+            <span v-else>-</span>
+          </td>
+          <td>
             <span v-if="item.scheduleReleaseState === 'OFFLINE'">{{$t('offline')}}</span>
             <span v-if="item.scheduleReleaseState === 'ONLINE'">{{$t('online')}}</span>
             <span v-if="!item.scheduleReleaseState">-</span>
diff --git a/dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js b/dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js
index 6e8c113..0402d7e 100644
--- a/dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js
+++ b/dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js
@@ -518,4 +518,5 @@ export default {
   'SpeedRecord': 'speed(record count)',
   '0 means unlimited by byte': '0 means unlimited',
   '0 means unlimited by count': '0 means unlimited',
+  'Modify User': 'Modify User'
 }
diff --git a/dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js b/dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js
index 52a9877..95eb4a1 100644
--- a/dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js
+++ b/dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js
@@ -518,4 +518,5 @@ export default {
   'SpeedRecord': '限流(记录数)',
   '0 means unlimited by byte': 'KB,0代表不限制',
   '0 means unlimited by count': '0代表不限制',
+  'Modify User': '修改用户'
 }
diff --git a/pom.xml b/pom.xml
index 875577c..307db31 100644
--- a/pom.xml
+++ b/pom.xml
@@ -343,6 +343,7 @@
                 <groupId>mysql</groupId>
                 <artifactId>mysql-connector-java</artifactId>
                 <version>${mysql.connector.version}</version>
+                <scope>test</scope>
             </dependency>
             <dependency>
                 <groupId>org.slf4j</groupId>
diff --git a/sql/dolphinscheduler-postgre.sql b/sql/dolphinscheduler-postgre.sql
index b3c61eb..c68fd17 100644
--- a/sql/dolphinscheduler-postgre.sql
+++ b/sql/dolphinscheduler-postgre.sql
@@ -319,6 +319,7 @@ CREATE TABLE t_ds_process_definition (
   timeout int DEFAULT '0' ,
   tenant_id int NOT NULL DEFAULT '-1' ,
   update_time timestamp DEFAULT NULL ,
+  modify_by varchar(36) DEFAULT '' ,
   PRIMARY KEY (id)
 ) ;
 
diff --git a/sql/dolphinscheduler_mysql.sql b/sql/dolphinscheduler_mysql.sql
index fec2771..ea0f9cb 100644
--- a/sql/dolphinscheduler_mysql.sql
+++ b/sql/dolphinscheduler_mysql.sql
@@ -366,6 +366,7 @@ CREATE TABLE `t_ds_process_definition` (
   `timeout` int(11) DEFAULT '0' COMMENT 'time out',
   `tenant_id` int(11) NOT NULL DEFAULT '-1' COMMENT 'tenant id',
   `update_time` datetime DEFAULT NULL COMMENT 'update time',
+  `modify_by` varchar(36) DEFAULT '' COMMENT 'modify user',
   PRIMARY KEY (`id`),
   KEY `process_definition_index` (`project_id`,`id`) USING BTREE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
diff --git a/sql/upgrade/1.2.2_schema/mysql/dolphinscheduler_ddl.sql b/sql/upgrade/1.2.2_schema/mysql/dolphinscheduler_ddl.sql
new file mode 100644
index 0000000..9fe246a
--- /dev/null
+++ b/sql/upgrade/1.2.2_schema/mysql/dolphinscheduler_ddl.sql
@@ -0,0 +1,37 @@
+/*
+ * 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.
+*/
+
+SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
+-- uc_dolphin_T_t_ds_process_definition_A_modify_by
+drop PROCEDURE if EXISTS uc_dolphin_T_t_ds_process_definition_A_modify_by;
+delimiter d//
+CREATE PROCEDURE uc_dolphin_T_t_ds_process_definition_A_modify_by()
+   BEGIN
+       IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
+           WHERE TABLE_NAME='t_ds_process_definition'
+           AND TABLE_SCHEMA=(SELECT DATABASE())
+           AND COLUMN_NAME ='modify_by')
+   THEN
+         ALTER TABLE t_ds_process_definition ADD `modify_by` varchar(36) DEFAULT '' COMMENT 'modify user';
+       END IF;
+ END;
+
+d//
+
+delimiter ;
+CALL uc_dolphin_T_t_ds_process_definition_A_modify_by;
+DROP PROCEDURE uc_dolphin_T_t_ds_process_definition_A_modify_by;
diff --git a/sql/upgrade/1.2.2_schema/mysql/dolphinscheduler_dml.sql b/sql/upgrade/1.2.2_schema/mysql/dolphinscheduler_dml.sql
new file mode 100644
index 0000000..38964cc
--- /dev/null
+++ b/sql/upgrade/1.2.2_schema/mysql/dolphinscheduler_dml.sql
@@ -0,0 +1,16 @@
+/*
+ * 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.
+*/
\ No newline at end of file
diff --git a/sql/upgrade/1.2.2_schema/postgresql/dolphinscheduler_ddl.sql b/sql/upgrade/1.2.2_schema/postgresql/dolphinscheduler_ddl.sql
new file mode 100644
index 0000000..7fc1290
--- /dev/null
+++ b/sql/upgrade/1.2.2_schema/postgresql/dolphinscheduler_ddl.sql
@@ -0,0 +1,34 @@
+/*
+ * 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.
+*/
+-- uc_dolphin_T_t_ds_process_definition_A_modify_by
+delimiter d//
+CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_process_definition_A_modify_by() RETURNS void AS $$
+BEGIN
+       IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS
+          WHERE TABLE_NAME='t_ds_process_definition'
+                            AND COLUMN_NAME ='modify_by')
+      THEN
+         ALTER TABLE t_ds_process_definition ADD COLUMN modify_by varchar(36) DEFAULT '';
+       END IF;
+END;
+$$ LANGUAGE plpgsql;
+d//
+
+delimiter ;
+SELECT uc_dolphin_T_t_ds_process_definition_A_modify_by();
+DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_process_definition_A_modify_by();
+
diff --git a/sql/upgrade/1.2.2_schema/postgresql/dolphinscheduler_dml.sql b/sql/upgrade/1.2.2_schema/postgresql/dolphinscheduler_dml.sql
new file mode 100644
index 0000000..38964cc
--- /dev/null
+++ b/sql/upgrade/1.2.2_schema/postgresql/dolphinscheduler_dml.sql
@@ -0,0 +1,16 @@
+/*
+ * 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.
+*/
\ No newline at end of file