Browse Source
* [Feature-9467][DataSource] add DAMENG (达梦) data source * [Feature-9467] add DM datasource doc (Issue #9467) * [Feature-9467] add DM IDataBaseOptionKeys * [Feature-9467] add DM DataSource: DmDataSourceChannelFactoryTest remove testGetDmConnection method * [Feature-9467] modification package dm to dameng; * [Feature-9467] add Dameng DmJdbcDriver18 License * [Feature-9467] add DM DataSource: remove DruidDataSourceClient Co-authored-by: lenian <yuenian@mananacare.com>3.2.0-release
lenian
2 years ago
committed by
GitHub
25 changed files with 636 additions and 2 deletions
@ -0,0 +1,22 @@
|
||||
# DAMENG |
||||
|
||||
![dameng](../../../../img/new_ui/dev/datasource/dameng.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. |
||||
|
@ -0,0 +1,17 @@
|
||||
# DAMENG数据源 |
||||
|
||||
![dameng](../../../../img/new_ui/dev/datasource/dameng.png) |
||||
|
||||
- 数据源:选择 DAMENG |
||||
- 数据源名称:输入数据源的名称 |
||||
- 描述:输入数据源的描述 |
||||
- IP 主机名:输入连接 DAMENG 的 IP |
||||
- 端口:输入连接 DAMENG 的端口 |
||||
- 用户名:设置连接 DAMENG 的用户名 |
||||
- 密码:设置连接 DAMENG 的密码 |
||||
- 数据库名:输入连接 DAMENG 的 schema |
||||
- Jdbc 连接参数:用于 DAMENG 连接的参数设置,以 JSON 形式填写 |
||||
|
||||
## 是否原生支持 |
||||
|
||||
否,使用前需请参考 [数据源配置](../howto/datasource-setting.md) 中的 "数据源中心" 章节激活数据源。 |
After Width: | Height: | Size: 27 KiB |
@ -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> |
@ -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); |
||||
} |
||||
} |
@ -0,0 +1,38 @@
|
||||
/* |
||||
* 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.DataSourceChannel; |
||||
import org.apache.dolphinscheduler.spi.datasource.DataSourceChannelFactory; |
||||
import org.apache.dolphinscheduler.spi.enums.DbType; |
||||
|
||||
import com.google.auto.service.AutoService; |
||||
|
||||
@AutoService(DataSourceChannelFactory.class) |
||||
public class DamengDataSourceChannelFactory implements DataSourceChannelFactory { |
||||
|
||||
@Override |
||||
public String getName() { |
||||
return DbType.DAMENG.getDescp(); |
||||
} |
||||
|
||||
@Override |
||||
public DataSourceChannel create() { |
||||
return new DamengDataSourceChannel(); |
||||
} |
||||
} |
@ -0,0 +1,30 @@
|
||||
/* |
||||
* 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.plugin.datasource.api.client.CommonDataSourceClient; |
||||
import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; |
||||
import org.apache.dolphinscheduler.spi.enums.DbType; |
||||
|
||||
public class DamengDataSourceClient extends CommonDataSourceClient { |
||||
|
||||
public DamengDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { |
||||
super(baseConnectionParam, dbType); |
||||
} |
||||
|
||||
} |
@ -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. |
||||
*/ |
||||
|
||||
package org.apache.dolphinscheduler.plugin.datasource.dameng.param; |
||||
|
||||
import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; |
||||
|
||||
public class DamengConnectionParam extends BaseConnectionParam { |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "DamengConnectionParam{" |
||||
+ "user='" + user + '\'' |
||||
+ ", address='" + address + '\'' |
||||
+ ", database='" + database + '\'' |
||||
+ ", jdbcUrl='" + jdbcUrl + '\'' |
||||
+ ", driverLocation='" + driverLocation + '\'' |
||||
+ ", driverClassName='" + driverClassName + '\'' |
||||
+ ", validationQuery='" + validationQuery + '\'' |
||||
+ ", other='" + other + '\'' |
||||
+ '}'; |
||||
} |
||||
} |
@ -0,0 +1,42 @@
|
||||
/* |
||||
* 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.param; |
||||
|
||||
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.BaseDataSourceParamDTO; |
||||
import org.apache.dolphinscheduler.spi.enums.DbType; |
||||
|
||||
public class DamengDataSourceParamDTO extends BaseDataSourceParamDTO { |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "DamengDatasourceParamDTO{" |
||||
+ "name='" + name + '\'' |
||||
+ ", note='" + note + '\'' |
||||
+ ", host='" + host + '\'' |
||||
+ ", port=" + port |
||||
+ ", database='" + database + '\'' |
||||
+ ", userName='" + userName + '\'' |
||||
+ ", other='" + other + '\'' |
||||
+ '}'; |
||||
} |
||||
|
||||
@Override |
||||
public DbType getType() { |
||||
return DbType.DAMENG; |
||||
} |
||||
} |
@ -0,0 +1,149 @@
|
||||
/* |
||||
* 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.param; |
||||
|
||||
import org.apache.dolphinscheduler.common.constants.Constants; |
||||
import org.apache.dolphinscheduler.common.constants.DataSourceConstants; |
||||
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
||||
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.AbstractDataSourceProcessor; |
||||
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.BaseDataSourceParamDTO; |
||||
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.DataSourceProcessor; |
||||
import org.apache.dolphinscheduler.plugin.datasource.api.utils.PasswordUtils; |
||||
import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; |
||||
import org.apache.dolphinscheduler.spi.datasource.ConnectionParam; |
||||
import org.apache.dolphinscheduler.spi.enums.DbType; |
||||
|
||||
import org.apache.commons.collections4.MapUtils; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
|
||||
import java.sql.Connection; |
||||
import java.sql.DriverManager; |
||||
import java.sql.SQLException; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import com.google.auto.service.AutoService; |
||||
|
||||
@AutoService(DataSourceProcessor.class) |
||||
public class DamengDataSourceProcessor extends AbstractDataSourceProcessor { |
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(DamengDataSourceProcessor.class); |
||||
|
||||
@Override |
||||
public BaseDataSourceParamDTO castDatasourceParamDTO(String paramJson) { |
||||
return JSONUtils.parseObject(paramJson, DamengDataSourceParamDTO.class); |
||||
} |
||||
|
||||
@Override |
||||
public BaseDataSourceParamDTO createDatasourceParamDTO(String connectionJson) { |
||||
DamengConnectionParam connectionParams = (DamengConnectionParam) createConnectionParams(connectionJson); |
||||
DamengDataSourceParamDTO damengDatasourceParamDTO = new DamengDataSourceParamDTO(); |
||||
|
||||
damengDatasourceParamDTO.setUserName(connectionParams.getUser()); |
||||
damengDatasourceParamDTO.setDatabase(connectionParams.getDatabase()); |
||||
damengDatasourceParamDTO.setOther(connectionParams.getOther()); |
||||
|
||||
String address = connectionParams.getAddress(); |
||||
String[] hostSeperator = address.split(Constants.DOUBLE_SLASH); |
||||
String[] hostPortArray = hostSeperator[hostSeperator.length - 1].split(Constants.COMMA); |
||||
damengDatasourceParamDTO.setPort(Integer.parseInt(hostPortArray[0].split(Constants.COLON)[1])); |
||||
damengDatasourceParamDTO.setHost(hostPortArray[0].split(Constants.COLON)[0]); |
||||
|
||||
return damengDatasourceParamDTO; |
||||
} |
||||
|
||||
@Override |
||||
public BaseConnectionParam createConnectionParams(BaseDataSourceParamDTO dataSourceParam) { |
||||
DamengDataSourceParamDTO dmDatasourceParam = (DamengDataSourceParamDTO) dataSourceParam; |
||||
String address = String |
||||
.format("%s%s:%s", DataSourceConstants.JDBC_DAMENG, dmDatasourceParam.getHost(), |
||||
dmDatasourceParam.getPort()); |
||||
String jdbcUrl = StringUtils.isEmpty(dmDatasourceParam.getDatabase()) ? address |
||||
: String.format("%s/%s", address, |
||||
dmDatasourceParam.getDatabase()); |
||||
|
||||
DamengConnectionParam damengConnectionParam = new DamengConnectionParam(); |
||||
damengConnectionParam.setJdbcUrl(jdbcUrl); |
||||
damengConnectionParam.setDatabase(damengConnectionParam.getDatabase()); |
||||
damengConnectionParam.setAddress(address); |
||||
damengConnectionParam.setUser(dmDatasourceParam.getUserName()); |
||||
damengConnectionParam.setPassword(PasswordUtils.encodePassword(dmDatasourceParam.getPassword())); |
||||
damengConnectionParam.setDriverClassName(getDatasourceDriver()); |
||||
damengConnectionParam.setValidationQuery(getValidationQuery()); |
||||
damengConnectionParam.setOther(dmDatasourceParam.getOther()); |
||||
|
||||
return damengConnectionParam; |
||||
} |
||||
|
||||
@Override |
||||
public ConnectionParam createConnectionParams(String connectionJson) { |
||||
return JSONUtils.parseObject(connectionJson, DamengConnectionParam.class); |
||||
} |
||||
|
||||
@Override |
||||
public String getDatasourceDriver() { |
||||
return DataSourceConstants.COM_DAMENG_JDBC_DRIVER; |
||||
} |
||||
|
||||
@Override |
||||
public String getValidationQuery() { |
||||
return DataSourceConstants.DAMENG_VALIDATION_QUERY; |
||||
} |
||||
|
||||
@Override |
||||
public String getJdbcUrl(ConnectionParam connectionParam) { |
||||
DamengConnectionParam damengConnectionParam = (DamengConnectionParam) connectionParam; |
||||
String jdbcUrl = damengConnectionParam.getJdbcUrl(); |
||||
if (MapUtils.isNotEmpty(damengConnectionParam.getOther())) { |
||||
return String.format("%s?%s", jdbcUrl, transformOther(damengConnectionParam.getOther())); |
||||
} |
||||
return jdbcUrl; |
||||
} |
||||
|
||||
@Override |
||||
public Connection getConnection(ConnectionParam connectionParam) throws ClassNotFoundException, SQLException { |
||||
DamengConnectionParam damengConnectionParam = (DamengConnectionParam) connectionParam; |
||||
Class.forName(getDatasourceDriver()); |
||||
return DriverManager.getConnection(getJdbcUrl(damengConnectionParam), damengConnectionParam.getUser(), |
||||
PasswordUtils.decodePassword(damengConnectionParam.getPassword())); |
||||
} |
||||
|
||||
@Override |
||||
public DbType getDbType() { |
||||
return DbType.DAMENG; |
||||
} |
||||
|
||||
@Override |
||||
public DataSourceProcessor create() { |
||||
return new DamengDataSourceProcessor(); |
||||
} |
||||
|
||||
private String transformOther(Map<String, String> paramMap) { |
||||
if (MapUtils.isEmpty(paramMap)) { |
||||
return null; |
||||
} |
||||
List<String> otherList = new ArrayList<>(); |
||||
paramMap.forEach((key, value) -> otherList.add(String.format("%s=%s", key, value))); |
||||
return String.join("&", otherList); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,33 @@
|
||||
/* |
||||
* 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.DataSourceChannel; |
||||
|
||||
import org.junit.jupiter.api.Assertions; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
public class DamengDataSourceChannelFactoryTest { |
||||
|
||||
@Test |
||||
public void testCreate() { |
||||
DamengDataSourceChannelFactory sourceChannelFactory = new DamengDataSourceChannelFactory(); |
||||
DataSourceChannel dataSourceChannel = sourceChannelFactory.create(); |
||||
Assertions.assertNotNull(dataSourceChannel); |
||||
} |
||||
} |
@ -0,0 +1,40 @@
|
||||
/* |
||||
* 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.plugin.datasource.dameng.param.DamengConnectionParam; |
||||
import org.apache.dolphinscheduler.spi.enums.DbType; |
||||
|
||||
import org.junit.jupiter.api.Assertions; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.extension.ExtendWith; |
||||
import org.mockito.Mockito; |
||||
import org.mockito.junit.jupiter.MockitoExtension; |
||||
|
||||
@ExtendWith(MockitoExtension.class) |
||||
public class DamengDataSourceChannelTest { |
||||
|
||||
@Test |
||||
public void testCreateDataSourceClient() { |
||||
DamengDataSourceChannel sourceChannel = Mockito.mock(DamengDataSourceChannel.class); |
||||
DamengDataSourceClient dataSourceClient = Mockito.mock(DamengDataSourceClient.class); |
||||
Mockito.when(sourceChannel.createDataSourceClient(Mockito.any(), Mockito.any())).thenReturn(dataSourceClient); |
||||
Assertions.assertNotNull(sourceChannel.createDataSourceClient(new DamengConnectionParam(), DbType.DAMENG)); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,91 @@
|
||||
/* |
||||
* 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.param; |
||||
|
||||
import org.apache.dolphinscheduler.common.constants.DataSourceConstants; |
||||
import org.apache.dolphinscheduler.plugin.datasource.api.utils.PasswordUtils; |
||||
import org.apache.dolphinscheduler.spi.enums.DbType; |
||||
|
||||
import org.junit.jupiter.api.Assertions; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.extension.ExtendWith; |
||||
import org.mockito.MockedStatic; |
||||
import org.mockito.Mockito; |
||||
import org.mockito.junit.jupiter.MockitoExtension; |
||||
|
||||
@ExtendWith(MockitoExtension.class) |
||||
public class DamengDataSourceProcessorTest { |
||||
|
||||
private DamengDataSourceProcessor damengDatasourceProcessor = new DamengDataSourceProcessor(); |
||||
|
||||
@Test |
||||
public void testCreateConnectionParams() { |
||||
DamengDataSourceParamDTO damengDatasourceParamDTO = new DamengDataSourceParamDTO(); |
||||
damengDatasourceParamDTO.setUserName("SYSDBA"); |
||||
damengDatasourceParamDTO.setPassword("SYSDBA"); |
||||
damengDatasourceParamDTO.setHost("localhost"); |
||||
damengDatasourceParamDTO.setPort(5236); |
||||
damengDatasourceParamDTO.setDatabase("PERSON"); |
||||
|
||||
try (MockedStatic<PasswordUtils> mockedPasswordUtils = Mockito.mockStatic(PasswordUtils.class)) { |
||||
Mockito.when(PasswordUtils.encodePassword(Mockito.anyString())).thenReturn("test"); |
||||
DamengConnectionParam connectionParams = (DamengConnectionParam) damengDatasourceProcessor |
||||
.createConnectionParams(damengDatasourceParamDTO); |
||||
Assertions.assertEquals("jdbc:dm://localhost:5236", connectionParams.getAddress()); |
||||
Assertions.assertEquals("jdbc:dm://localhost:5236/PERSON", connectionParams.getJdbcUrl()); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void testCreateConnectionParams2() { |
||||
String connectionJson = "{\"user\":\"SYSDBA\",\"password\":\"SYSDBA\"," |
||||
+ "\"address\":\"jdbc:dm://localhost:5236\"" |
||||
+ ",\"database\":\"PERSON\",\"jdbcUrl\":\"jdbc:dm://localhost:5236/PERSON\"}"; |
||||
DamengConnectionParam connectionParams = (DamengConnectionParam) damengDatasourceProcessor |
||||
.createConnectionParams(connectionJson); |
||||
Assertions.assertNotNull(connectionJson); |
||||
Assertions.assertEquals("SYSDBA", connectionParams.getUser()); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetDatasourceDriver() { |
||||
Assertions.assertEquals(DataSourceConstants.COM_DAMENG_JDBC_DRIVER, |
||||
damengDatasourceProcessor.getDatasourceDriver()); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetJdbcUrl() { |
||||
DamengConnectionParam damengConnectionParam = new DamengConnectionParam(); |
||||
damengConnectionParam.setJdbcUrl("jdbc:dm://localhost:5236/PERSON"); |
||||
Assertions.assertEquals( |
||||
"jdbc:dm://localhost:5236/PERSON", |
||||
damengDatasourceProcessor.getJdbcUrl(damengConnectionParam)); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetDbType() { |
||||
Assertions.assertEquals(DbType.DAMENG, damengDatasourceProcessor.getDbType()); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetValidationQuery() { |
||||
Assertions.assertEquals(DataSourceConstants.DAMENG_VALIDATION_QUERY, |
||||
damengDatasourceProcessor.getValidationQuery()); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,13 @@
|
||||
Copyright 2000-2022 Dameng Group Holding Ltd. |
||||
|
||||
Licensed 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. |
Loading…
Reference in new issue