You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by le...@apache.org on 2019/12/06 10:18:21 UTC
[incubator-dolphinscheduler] branch dev-db updated:
[dolphinscheduler-1345] [newfeature] Add DB2 Datasource (#1391)
This is an automated email from the ASF dual-hosted git repository.
leonbao pushed a commit to branch dev-db
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git
The following commit(s) were added to refs/heads/dev-db by this push:
new d1f8df1 [dolphinscheduler-1345] [newfeature] Add DB2 Datasource (#1391)
d1f8df1 is described below
commit d1f8df1f354037489ace6dbf80b7ff97e33946a1
Author: zhukai <bo...@qq.com>
AuthorDate: Fri Dec 6 18:18:11 2019 +0800
[dolphinscheduler-1345] [newfeature] Add DB2 Datasource (#1391)
---
.../api/service/DataSourceService.java | 13 +++-
.../apache/dolphinscheduler/common/Constants.java | 10 +++
.../dolphinscheduler/common/enums/DbType.java | 4 +-
.../common/job/db/DB2ServerDataSource.java | 75 ++++++++++++++++++++++
.../common/job/db/DataSourceFactory.java | 5 ++
.../pages/list/_source/createDataSource.vue | 8 ++-
.../src/js/conf/home/store/dag/state.js | 5 ++
7 files changed, 117 insertions(+), 3 deletions(-)
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataSourceService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataSourceService.java
index 80394fe..5d33b46 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataSourceService.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataSourceService.java
@@ -405,9 +405,14 @@ public class DataSourceService extends BaseService{
datasource = JSONObject.parseObject(parameter, SQLServerDataSource.class);
Class.forName(Constants.COM_SQLSERVER_JDBC_DRIVER);
break;
+ case DB2:
+ datasource = JSONObject.parseObject(parameter, DB2ServerDataSource.class);
+ Class.forName(Constants.COM_DB2_JDBC_DRIVER);
+ break;
default:
break;
}
+
if(datasource != null){
connection = DriverManager.getConnection(datasource.getJdbcUrl(), datasource.getUser(), datasource.getPassword());
}
@@ -487,6 +492,7 @@ public class DataSourceService extends BaseService{
separator = "&";
} else if (Constants.HIVE.equals(type.name())
|| Constants.SPARK.equals(type.name())
+ || Constants.DB2.equals(type.name())
|| Constants.SQLSERVER.equals(type.name())) {
separator = ";";
}
@@ -509,7 +515,9 @@ public class DataSourceService extends BaseService{
for (Map.Entry<String, String> entry: map.entrySet()) {
otherSb.append(String.format("%s=%s%s", entry.getKey(), entry.getValue(), separator));
}
- otherSb.deleteCharAt(otherSb.length() - 1);
+ if (!Constants.DB2.equals(type.name())) {
+ otherSb.deleteCharAt(otherSb.length() - 1);
+ }
parameterMap.put(Constants.OTHER, otherSb);
}
@@ -549,6 +557,9 @@ public class DataSourceService extends BaseService{
} else if (Constants.SQLSERVER.equals(type.name())) {
sb.append(Constants.JDBC_SQLSERVER);
sb.append(host).append(":").append(port);
+ }else if (Constants.DB2.equals(type.name())) {
+ sb.append(Constants.JDBC_DB2);
+ sb.append(host).append(":").append(port);
}
return sb.toString();
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 7029a00..efcb4e1 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
@@ -652,6 +652,13 @@ public final class Constants {
*/
public static final String JDBC_SQLSERVER_CLASS_NAME = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
+
+ /**
+ * DB2
+ */
+ public static final String JDBC_DB2_CLASS_NAME = "com.ibm.db2.jcc.DB2Driver";
+
+
/**
* spark params constant
*/
@@ -1003,6 +1010,7 @@ public final class Constants {
public static final String COM_CLICKHOUSE_JDBC_DRIVER = "ru.yandex.clickhouse.ClickHouseDriver";
public static final String COM_ORACLE_JDBC_DRIVER = "oracle.jdbc.driver.OracleDriver";
public static final String COM_SQLSERVER_JDBC_DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
+ public static final String COM_DB2_JDBC_DRIVER = "com.ibm.db2.jcc.DB2Driver";
/**
* database type
@@ -1014,6 +1022,7 @@ public final class Constants {
public static final String CLICKHOUSE = "CLICKHOUSE";
public static final String ORACLE = "ORACLE";
public static final String SQLSERVER = "SQLSERVER";
+ public static final String DB2 = "DB2";
/**
* jdbc url
@@ -1024,6 +1033,7 @@ public final class Constants {
public static final String JDBC_CLICKHOUSE = "jdbc:clickhouse://";
public static final String JDBC_ORACLE = "jdbc:oracle:thin:@//";
public static final String JDBC_SQLSERVER = "jdbc:sqlserver://";
+ public static final String JDBC_DB2 = "jdbc:db2://";
public static final String ADDRESS = "address";
diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/DbType.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/DbType.java
index cc2624f..4637771 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/DbType.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/DbType.java
@@ -32,6 +32,7 @@ public enum DbType {
* 4 clickhouse
* 5 oracle
* 6 sqlserver
+ * 7 db2
*/
MYSQL(0, "mysql"),
POSTGRESQL(1, "postgresql"),
@@ -39,7 +40,8 @@ public enum DbType {
SPARK(3, "spark"),
CLICKHOUSE(4, "clickhouse"),
ORACLE(5, "oracle"),
- SQLSERVER(6, "sqlserver");
+ SQLSERVER(6, "sqlserver"),
+ DB2(7, "db2");
DbType(int code, String descp){
this.code = code;
diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/job/db/DB2ServerDataSource.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/job/db/DB2ServerDataSource.java
new file mode 100644
index 0000000..8783c8e
--- /dev/null
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/job/db/DB2ServerDataSource.java
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+package org.apache.dolphinscheduler.common.job.db;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.dolphinscheduler.common.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+/**
+ * data source of DB2 Server
+ */
+public class DB2ServerDataSource extends BaseDataSource {
+ private static final Logger logger = LoggerFactory.getLogger(DB2ServerDataSource.class);
+
+ /**
+ * gets the JDBC url for the data source connection
+ * @return
+ */
+ @Override
+ public String getJdbcUrl() {
+ String jdbcUrl = getAddress();
+ if (jdbcUrl.lastIndexOf("/") != (jdbcUrl.length() - 1)) {
+ jdbcUrl += "/";
+ }
+
+ jdbcUrl += getDatabase();
+
+ if (StringUtils.isNotEmpty(getOther())) {
+ jdbcUrl += ":" + getOther();
+ }
+ return jdbcUrl;
+ }
+
+ /**
+ * test whether the data source can be connected successfully
+ * @throws Exception
+ */
+ @Override
+ public void isConnectable() throws Exception {
+ Connection con = null;
+ try {
+ Class.forName(Constants.COM_DB2_JDBC_DRIVER);
+ con = DriverManager.getConnection(getJdbcUrl(), getUser(), getPassword());
+ } finally {
+ if (con != null) {
+ try {
+ con.close();
+ } catch (SQLException e) {
+ logger.error("DB2 Server datasource try conn close conn error", e);
+ throw e;
+ }
+ }
+ }
+
+ }
+}
diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/job/db/DataSourceFactory.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/job/db/DataSourceFactory.java
index 86492d8..6dec9ba 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/job/db/DataSourceFactory.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/job/db/DataSourceFactory.java
@@ -46,6 +46,8 @@ public class DataSourceFactory {
return JSONUtils.parseObject(parameter, OracleDataSource.class);
case SQLSERVER:
return JSONUtils.parseObject(parameter, SQLServerDataSource.class);
+ case DB2:
+ return JSONUtils.parseObject(parameter, DB2ServerDataSource.class);
default:
return null;
}
@@ -83,6 +85,9 @@ public class DataSourceFactory {
case SQLSERVER:
Class.forName(Constants.JDBC_SQLSERVER_CLASS_NAME);
break;
+ case DB2:
+ Class.forName(Constants.JDBC_DB2_CLASS_NAME);
+ break;
default:
logger.error("not support sql type: {},can't load class", dbType);
throw new IllegalArgumentException("not support sql type,can't load class");
diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/datasource/pages/list/_source/createDataSource.vue b/dolphinscheduler-ui/src/js/conf/home/pages/datasource/pages/list/_source/createDataSource.vue
index ec88a96..8c55887 100644
--- a/dolphinscheduler-ui/src/js/conf/home/pages/datasource/pages/list/_source/createDataSource.vue
+++ b/dolphinscheduler-ui/src/js/conf/home/pages/datasource/pages/list/_source/createDataSource.vue
@@ -32,6 +32,7 @@
<x-radio :label="'CLICKHOUSE'">CLICKHOUSE</x-radio>
<x-radio :label="'ORACLE'">ORACLE</x-radio>
<x-radio :label="'SQLSERVER'">SQLSERVER</x-radio>
+ <x-radio :label="'DB2'" class="radio-label-last" >DB2</x-radio>
</x-radio-group>
</template>
</m-list-box-f>
@@ -362,7 +363,7 @@
})
}
},
-
+
mounted () {
},
components: { mPopup, mListBoxF }
@@ -402,5 +403,10 @@
}
}
}
+ .radio-label-last {
+ margin-left: 0px !important;
+ }
}
+
+
</style>
diff --git a/dolphinscheduler-ui/src/js/conf/home/store/dag/state.js b/dolphinscheduler-ui/src/js/conf/home/store/dag/state.js
index 1228399..9eb4d74 100644
--- a/dolphinscheduler-ui/src/js/conf/home/store/dag/state.js
+++ b/dolphinscheduler-ui/src/js/conf/home/store/dag/state.js
@@ -87,6 +87,11 @@ export default {
id: 6,
code: 'SQLSERVER',
disabled: false
+ },
+ {
+ id: 7,
+ code: 'DB2',
+ disabled: false
}
],
// Alarm interface