You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ki...@apache.org on 2022/01/07 13:31:31 UTC

[dolphinscheduler] branch dev updated: [python] Fix database error handler about no datasource name (#7631)

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

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


The following commit(s) were added to refs/heads/dev by this push:
     new 6532215  [python] Fix database error handler about no datasource name (#7631)
6532215 is described below

commit 65322155a3b27d8f3def00e1d1ce7c11ad68c6c7
Author: Jiajie Zhong <zh...@hotmail.com>
AuthorDate: Fri Jan 7 21:29:37 2022 +0800

    [python] Fix database error handler about no datasource name (#7631)
    
    * [python] Fix database error handler about no datasource name
    
    The original code show too many unrelated log when database name
    do not exists. BTW, it would continue the code when error miss.
    This patch is try to fix it.
    
    close: #7616
    
    * Use java exception instead of self define
    
    * Enhance
---
 .../pydolphinscheduler/src/pydolphinscheduler/core/database.py   | 9 ++++++++-
 .../org/apache/dolphinscheduler/server/PythonGatewayServer.java  | 8 ++++----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/database.py b/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/database.py
index f87ffef..b6602a6 100644
--- a/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/database.py
+++ b/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/database.py
@@ -19,6 +19,9 @@
 
 from typing import Dict
 
+from py4j.protocol import Py4JJavaError
+
+from pydolphinscheduler.exceptions import PyDSParamException
 from pydolphinscheduler.java_gateway import launch_gateway
 
 
@@ -52,5 +55,9 @@ class Database(dict):
             return self._database
         else:
             gateway = launch_gateway()
-            self._database = gateway.entry_point.getDatasourceInfo(name)
+            try:
+                self._database = gateway.entry_point.getDatasourceInfo(name)
+            # Handler database source do not exists error, for now we just terminate the process.
+            except Py4JJavaError as ex:
+                raise PyDSParamException(str(ex.java_exception))
             return self._database
diff --git a/dolphinscheduler-python/src/main/java/org/apache/dolphinscheduler/server/PythonGatewayServer.java b/dolphinscheduler-python/src/main/java/org/apache/dolphinscheduler/server/PythonGatewayServer.java
index 73d66b1..9489894 100644
--- a/dolphinscheduler-python/src/main/java/org/apache/dolphinscheduler/server/PythonGatewayServer.java
+++ b/dolphinscheduler-python/src/main/java/org/apache/dolphinscheduler/server/PythonGatewayServer.java
@@ -392,12 +392,12 @@ public class PythonGatewayServer extends SpringBootServletInitializer {
     public Map<String, Object> getDatasourceInfo(String datasourceName) {
         Map<String, Object> result = new HashMap<>();
         List<DataSource> dataSourceList = dataSourceMapper.queryDataSourceByName(datasourceName);
-        if (dataSourceList.size() > 1) {
-            String msg = String.format("Get more than one datasource by name %s", datasourceName);
+        if (dataSourceList == null || dataSourceList.isEmpty()) {
+            String msg = String.format("Can not find any datasource by name %s", datasourceName);
             logger.error(msg);
             throw new IllegalArgumentException(msg);
-        } else if (dataSourceList.size() == 0) {
-            String msg = String.format("Can not find any datasource by name %s", datasourceName);
+        } else if (dataSourceList.size() > 1) {
+            String msg = String.format("Get more than one datasource by name %s", datasourceName);
             logger.error(msg);
             throw new IllegalArgumentException(msg);
         } else {