Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature-9467] add DAMENG DataSource #12860

Merged
merged 24 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e5357f1
[Feature-9467][DataSource] add DM(达梦) data source
Nov 9, 2022
c2b365c
[Feature-9467] add DM datasource doc (Issue #9467)
Nov 10, 2022
fe43cf3
[Feature-9467] add DM IDataBaseOptionKeys
Nov 10, 2022
3b54440
[Feature-9467] add DM DataSource:1、remove DmJdbcDriver18 test scope; …
Nov 12, 2022
bccd90e
[Feature-9467] add DM DataSource: DmDataSourceParamDTO remove passwor…
Nov 12, 2022
ce54f59
[Feature-9467][DataSource] add DM(达梦) data source
Nov 9, 2022
5f0efa8
[Feature-9467] add DM datasource doc (Issue #9467)
Nov 10, 2022
885dbab
[Feature-9467] add DM IDataBaseOptionKeys
Nov 10, 2022
2f589a0
[Feature-9467] add DM DataSource:1、remove DmJdbcDriver18 test scope; …
Nov 12, 2022
66a13f4
[Feature-9467] add DM DataSource: DmDataSourceParamDTO remove passwor…
Nov 12, 2022
923665c
Merge remote-tracking branch 'origin/feat_dm_9467' into feat_dm_9467
Nov 12, 2022
a64e13c
[Feature-9467] add DM DataSource: DmDataSourceChannelFactoryTest remo…
Nov 12, 2022
cbc3aa4
[Feature-9467] add DM DataSource: add the dependency DmJdbcDriver18-8…
Nov 12, 2022
7a27b9c
[Feature-9467] add DM DataSource: add dm english doc
Nov 15, 2022
6198f23
[Feature-9467] add DM DataSource: DruidDataSourceClient optimized code
Nov 24, 2022
0f9fe20
Merge remote-tracking branch 'origin/dev' into feat_dm_9467
Nov 27, 2022
ca52089
[Feature-9467] add DM DataSource: resolving code conflicts
Nov 27, 2022
22969a2
[Feature-9467] add DM DataSource:
Dec 7, 2022
c642406
[Feature-9467] add DM DataSource: update dameng doc
Dec 7, 2022
a7d455a
Merge remote-tracking branch 'origin/dev' into feat_dm_9467
Dec 29, 2022
29f1dcf
[Feature-9467] add DM DataSource: update DamengConnectionParam
Dec 30, 2022
631efb8
[Feature-9467] add DM DataSource: remove DruidDataSourceClient
Dec 30, 2022
7a12dc7
[Feature-9467] add DM DataSource: remove unnecessary changes
Jan 4, 2023
3799dcb
[Feature-9467] add DM DataSource: doc use English screenshot
Jan 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/docs/en/guide/datasource/dameng.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# DAMENG

![dameng](../../../../img/new_ui/dev/datasource/dameng_en.png)

## Datasource Parameters

| **Datasource** | **Description** |
|----------------------------|-----------------------------------------------------------|
| Datasource | Select DAMENG. |
| Datasource name | Enter the name of the DataSource. |
| Description | Enter a description of the DataSource. |
| IP/Host Name | Enter the DAMENG service IP. |
| Port | Enter the DAMENG service port. |
| Username | Set the username for DAMENG connection. |
| Password | Set the password for DAMENG connection. |
| Database name | Enter the schema name of the DAMENG connection. |
| Jdbc connection parameters | Parameter settings for DAMENG connection, in JSON format. |

## Native Supported

No, read section example in [datasource-setting](../howto/datasource-setting.md) `DataSource Center` section to activate this datasource.

17 changes: 17 additions & 0 deletions docs/docs/zh/guide/datasource/dameng.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# DAMENG数据源

![dameng](../../../../img/new_ui/dev/datasource/dameng_cn.png)
SbloodyS marked this conversation as resolved.
Show resolved Hide resolved

- 数据源:选择 DAMENG
- 数据源名称:输入数据源的名称
- 描述:输入数据源的描述
- IP 主机名:输入连接 DAMENG 的 IP
- 端口:输入连接 DAMENG 的端口
- 用户名:设置连接 DAMENG 的用户名
- 密码:设置连接 DAMENG 的密码
- 数据库名:输入连接 DAMENG 的 schema
- Jdbc 连接参数:用于 DAMENG 连接的参数设置,以 JSON 形式填写

## 是否原生支持

否,使用前需请参考 [数据源配置](../howto/datasource-setting.md) 中的 "数据源中心" 章节激活数据源。
Binary file added docs/img/new_ui/dev/datasource/dameng_cn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/new_ui/dev/datasource/dameng_en.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions dolphinscheduler-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<h2.version>2.1.210</h2.version>
<mysql-connector.version>8.0.16</mysql-connector.version>
<oracle-jdbc.version>21.5.0.0</oracle-jdbc.version>
<dameng-jdbc.version>8.1.2.79</dameng-jdbc.version>
<slf4j.version>1.7.36</slf4j.version>
<poi.version>4.1.2</poi.version>
<javax.servlet-api.version>3.1.0</javax.servlet-api.version>
Expand Down Expand Up @@ -382,6 +383,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.dameng</groupId>
<artifactId>DmJdbcDriver18</artifactId>
<version>${dameng-jdbc.version}</version>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class DataSourceConstants {
public static final String COM_REDSHIFT_JDBC_DRIVER = "com.amazon.redshift.jdbc42.Driver";
public static final String COM_ATHENA_JDBC_DRIVER = "com.simba.athena.jdbc.Driver";
public static final String COM_TRINO_JDBC_DRIVER = "io.trino.jdbc.TrinoDriver";
public static final String COM_DAMENG_JDBC_DRIVER = "dm.jdbc.driver.DmDriver";

/**
* validation Query
Expand All @@ -51,6 +52,7 @@ public class DataSourceConstants {
public static final String REDHIFT_VALIDATION_QUERY = "select 1";
public static final String ATHENA_VALIDATION_QUERY = "select 1";
public static final String TRINO_VALIDATION_QUERY = "select 1";
public static final String DAMENG_VALIDATION_QUERY = "select 1";

/**
* jdbc url
Expand All @@ -67,6 +69,7 @@ public class DataSourceConstants {
public static final String JDBC_REDSHIFT = "jdbc:redshift://";
public static final String JDBC_ATHENA = "jdbc:awsathena://";
public static final String JDBC_TRINO = "jdbc:trino://";
public static final String JDBC_DAMENG = "jdbc:dm://";

/**
* database type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,10 @@
<artifactId>dolphinscheduler-datasource-azure-sql</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler-datasource-dameng</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,10 @@
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove unnessnary change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll remove the unnecessary changes right away

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
</dependencies>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you introducing a new database connection pool? we already have HikariCP.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HikariCP does not support Dameng, druid supports Dameng

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand, it's just a data source connector management, why doesn't it support dm, can you explain why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks,I just tested the DaMeng database with HikariCP,HikariCP supports DaMeng

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* 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.plugin.datasource.api.client;

import org.apache.dolphinscheduler.plugin.datasource.api.provider.JDBCDataSourceProvider;
import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam;
import org.apache.dolphinscheduler.spi.datasource.DataSourceClient;
import org.apache.dolphinscheduler.spi.enums.DbType;

import org.apache.commons.lang3.StringUtils;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;

import com.alibaba.druid.pool.DruidDataSource;
import com.google.common.base.Stopwatch;

public class DruidDataSourceClient implements DataSourceClient {

private static final Logger logger = LoggerFactory.getLogger(DruidDataSourceClient.class);

public static final String COMMON_USER = "root";
public static final String COMMON_VALIDATION_QUERY = "select 1";

protected final BaseConnectionParam baseConnectionParam;
protected DruidDataSource dataSource;
protected JdbcTemplate jdbcTemplate;

public DruidDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) {
this.baseConnectionParam = baseConnectionParam;
preInit();
checkEnv(baseConnectionParam);
initClient(baseConnectionParam, dbType);
checkClient();
}

protected void preInit() {
logger.info("preInit in DruidDataSourceClient");
}

protected void checkEnv(BaseConnectionParam baseConnectionParam) {
checkValidationQuery(baseConnectionParam);
checkUser(baseConnectionParam);
}

/**
* HikariCP does not support Dameng, druid supports Dameng
* @param baseConnectionParam
* @param dbType
*/
protected void initClient(BaseConnectionParam baseConnectionParam, DbType dbType) {
this.dataSource = JDBCDataSourceProvider.createDruidDataSource(baseConnectionParam, dbType);
this.jdbcTemplate = new JdbcTemplate(dataSource);
}

protected void checkUser(BaseConnectionParam baseConnectionParam) {
if (StringUtils.isBlank(baseConnectionParam.getUser())) {
setDefaultUsername(baseConnectionParam);
}
}

protected void setDefaultUsername(BaseConnectionParam baseConnectionParam) {
baseConnectionParam.setUser(COMMON_USER);
}

protected void checkValidationQuery(BaseConnectionParam baseConnectionParam) {
if (StringUtils.isBlank(baseConnectionParam.getValidationQuery())) {
setDefaultValidationQuery(baseConnectionParam);
}
}

protected void setDefaultValidationQuery(BaseConnectionParam baseConnectionParam) {
baseConnectionParam.setValidationQuery(COMMON_VALIDATION_QUERY);
}

@Override
public void checkClient() {
// Checking data source client
Stopwatch stopwatch = Stopwatch.createStarted();
try {
this.jdbcTemplate.execute(this.baseConnectionParam.getValidationQuery());
logger.info("Time to execute check jdbc client with sql {} for {} ms ",
this.baseConnectionParam.getValidationQuery(), stopwatch.elapsed(TimeUnit.MILLISECONDS));
} catch (Exception e) {
throw new RuntimeException("JDBC connect failed", e);
}
}

@Override
public Connection getConnection() {
try {
return this.dataSource.getConnection();
} catch (SQLException e) {
logger.error("get druidDataSource Connection fail SQLException: ", e);
return null;
}
}

@Override
public void close() {
logger.info("do close dataSource {}.", baseConnectionParam.getDatabase());
try (DruidDataSource closedDatasource = dataSource) {
// only close the resource
}
this.jdbcTemplate = null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.druid.pool.DruidDataSource;
import com.zaxxer.hikari.HikariDataSource;

/**
Expand Down Expand Up @@ -68,6 +69,36 @@ public static HikariDataSource createJdbcDataSource(BaseConnectionParam properti
return dataSource;
}

/**
* Create druid connection pool for Dameng
* @param properties jdbc connection param
* @param dbType database type
* @return
*/
public static DruidDataSource createDruidDataSource(BaseConnectionParam properties, DbType dbType) {
logger.info("Creating DruidDataSource pool for maxActive:{}",
PropertyUtils.getInt(DataSourceConstants.SPRING_DATASOURCE_MAX_ACTIVE, 50));
DruidDataSource dataSource = new DruidDataSource();

loaderJdbcDriver(Thread.currentThread().getContextClassLoader(), properties, dbType);

dataSource.setDriverClassName(properties.getDriverClassName());
dataSource.setUrl(DataSourceUtils.getJdbcUrl(dbType, properties));
dataSource.setUsername(properties.getUser());
dataSource.setPassword(PasswordUtils.decodePassword(properties.getPassword()));

dataSource.setMinIdle(PropertyUtils.getInt(DataSourceConstants.SPRING_DATASOURCE_MIN_IDLE, 5));
dataSource.setMaxActive(PropertyUtils.getInt(DataSourceConstants.SPRING_DATASOURCE_MAX_ACTIVE, 50));
dataSource.setValidationQuery(properties.getValidationQuery());

if (properties.getProps() != null) {
properties.getProps().forEach(dataSource::addConnectionProperty);
}

logger.info("Creating DruidDataSource pool success.");
return dataSource;
}

/**
* @return One Session Jdbc DataSource
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler-datasource-plugin</artifactId>
<version>dev-SNAPSHOT</version>
</parent>

<artifactId>dolphinscheduler-datasource-dameng</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>

<dependencies>

<dependency>
<groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler-spi</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler-datasource-api</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.dameng</groupId>
<artifactId>DmJdbcDriver18</artifactId>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.plugin.datasource.dameng;

import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam;
import org.apache.dolphinscheduler.spi.datasource.DataSourceChannel;
import org.apache.dolphinscheduler.spi.datasource.DataSourceClient;
import org.apache.dolphinscheduler.spi.enums.DbType;

public class DamengDataSourceChannel implements DataSourceChannel {

@Override
public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) {
return new DamengDataSourceClient(baseConnectionParam, dbType);
}
}
Loading