diff --git a/docs/docs/en/guide/datasource/dameng.md b/docs/docs/en/guide/datasource/dameng.md new file mode 100644 index 0000000000..0073a4c924 --- /dev/null +++ b/docs/docs/en/guide/datasource/dameng.md @@ -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. + diff --git a/docs/docs/zh/guide/datasource/dameng.md b/docs/docs/zh/guide/datasource/dameng.md new file mode 100644 index 0000000000..bc4c6a12e7 --- /dev/null +++ b/docs/docs/zh/guide/datasource/dameng.md @@ -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) 中的 "数据源中心" 章节激活数据源。 diff --git a/docs/img/new_ui/dev/datasource/dameng.png b/docs/img/new_ui/dev/datasource/dameng.png new file mode 100644 index 0000000000..ccbb80ec7b Binary files /dev/null and b/docs/img/new_ui/dev/datasource/dameng.png differ diff --git a/dolphinscheduler-bom/pom.xml b/dolphinscheduler-bom/pom.xml index ec543f6a6d..4743ef0f28 100644 --- a/dolphinscheduler-bom/pom.xml +++ b/dolphinscheduler-bom/pom.xml @@ -60,6 +60,7 @@ 2.1.210 8.0.16 21.5.0.0 + 8.1.2.79 1.7.36 4.1.2 3.1.0 @@ -382,6 +383,12 @@ test + + com.dameng + DmJdbcDriver18 + ${dameng-jdbc.version} + + com.h2database h2 diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/constants/DataSourceConstants.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/constants/DataSourceConstants.java index 4bb1296914..7400636a9d 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/constants/DataSourceConstants.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/constants/DataSourceConstants.java @@ -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 @@ -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 @@ -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 diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-all/pom.xml b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-all/pom.xml index aa81a85b35..4030b07bd6 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-all/pom.xml +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-all/pom.xml @@ -97,5 +97,10 @@ dolphinscheduler-datasource-azure-sql ${project.version} + + org.apache.dolphinscheduler + dolphinscheduler-datasource-dameng + ${project.version} + diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/pom.xml b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/pom.xml new file mode 100644 index 0000000000..f965b1df8f --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/pom.xml @@ -0,0 +1,51 @@ + + + + 4.0.0 + + org.apache.dolphinscheduler + dolphinscheduler-datasource-plugin + dev-SNAPSHOT + + + dolphinscheduler-datasource-dameng + jar + ${project.artifactId} + + + + + org.apache.dolphinscheduler + dolphinscheduler-spi + provided + + + + org.apache.dolphinscheduler + dolphinscheduler-datasource-api + ${project.version} + + + + com.dameng + DmJdbcDriver18 + + + + diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengDataSourceChannel.java new file mode 100644 index 0000000000..6fa197c3ba --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengDataSourceChannel.java @@ -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); + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengDataSourceChannelFactory.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengDataSourceChannelFactory.java new file mode 100644 index 0000000000..945f6610c0 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengDataSourceChannelFactory.java @@ -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(); + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengDataSourceClient.java new file mode 100644 index 0000000000..85261afb7d --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengDataSourceClient.java @@ -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); + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/param/DamengConnectionParam.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/param/DamengConnectionParam.java new file mode 100644 index 0000000000..2f03da8077 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/param/DamengConnectionParam.java @@ -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 + '\'' + + '}'; + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/param/DamengDataSourceParamDTO.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/param/DamengDataSourceParamDTO.java new file mode 100644 index 0000000000..f4dd9046fc --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/param/DamengDataSourceParamDTO.java @@ -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; + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/param/DamengDataSourceProcessor.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/param/DamengDataSourceProcessor.java new file mode 100644 index 0000000000..b15345864d --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/param/DamengDataSourceProcessor.java @@ -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 paramMap) { + if (MapUtils.isEmpty(paramMap)) { + return null; + } + List otherList = new ArrayList<>(); + paramMap.forEach((key, value) -> otherList.add(String.format("%s=%s", key, value))); + return String.join("&", otherList); + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/test/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengDataSourceChannelFactoryTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/test/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengDataSourceChannelFactoryTest.java new file mode 100644 index 0000000000..5288fb521d --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/test/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengDataSourceChannelFactoryTest.java @@ -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); + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/test/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengDataSourceChannelTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/test/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengDataSourceChannelTest.java new file mode 100644 index 0000000000..d47b671c25 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/test/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengDataSourceChannelTest.java @@ -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)); + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/test/java/org/apache/dolphinscheduler/plugin/datasource/dameng/param/DamengDataSourceProcessorTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/test/java/org/apache/dolphinscheduler/plugin/datasource/dameng/param/DamengDataSourceProcessorTest.java new file mode 100644 index 0000000000..b724a3c106 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/test/java/org/apache/dolphinscheduler/plugin/datasource/dameng/param/DamengDataSourceProcessorTest.java @@ -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 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()); + } + +} diff --git a/dolphinscheduler-datasource-plugin/pom.xml b/dolphinscheduler-datasource-plugin/pom.xml index ab04eae4f9..f9f82f8736 100644 --- a/dolphinscheduler-datasource-plugin/pom.xml +++ b/dolphinscheduler-datasource-plugin/pom.xml @@ -44,6 +44,7 @@ dolphinscheduler-datasource-trino dolphinscheduler-datasource-starrocks dolphinscheduler-datasource-azure-sql + dolphinscheduler-datasource-dameng diff --git a/dolphinscheduler-dist/release-docs/LICENSE b/dolphinscheduler-dist/release-docs/LICENSE index 48f3cf5c7d..2eb79349d3 100644 --- a/dolphinscheduler-dist/release-docs/LICENSE +++ b/dolphinscheduler-dist/release-docs/LICENSE @@ -516,7 +516,7 @@ The text of each license is also included at licenses/LICENSE-[project].txt. reactor-core 3.4.22: https://mvnrepository.com/artifact/io.projectreactor/reactor-core/3.4.22, Apache 2.0 reactor-netty-core 1.0.22: https://mvnrepository.com/artifact/io.projectreactor.netty/reactor-netty-core/1.0.22, Apache 2.0 reactor-netty-http 1.0.22: https://mvnrepository.com/artifact/io.projectreactor.netty/reactor-netty-http/1.0.22, Apache 2.0 - + DmJdbcDriver18 8.1.2.79: https://mvnrepository.com/artifact/com.dameng/DmJdbcDriver18/8.1.2.79, Apache 2.0 jna-platform diff --git a/dolphinscheduler-dist/release-docs/NOTICE b/dolphinscheduler-dist/release-docs/NOTICE index 904f9098df..21c28d6dcb 100644 --- a/dolphinscheduler-dist/release-docs/NOTICE +++ b/dolphinscheduler-dist/release-docs/NOTICE @@ -2096,3 +2096,13 @@ perfmark NOTICE * agent/src/main/resources/io/perfmark/agent/third_party/asm/LICENSE (BSD style License) * HOMEPAGE: * https://asm.ow2.io/ + +======================================================================== + + +Dameng DmJdbcDriver18 NOTICE + +======================================================================== + +Dameng DmJdbcDriver18 +Copyright 2000-2022 Dameng Group Holding Ltd. diff --git a/dolphinscheduler-dist/release-docs/licenses/LICENSE-DmJdbcDriver18.txt b/dolphinscheduler-dist/release-docs/licenses/LICENSE-DmJdbcDriver18.txt new file mode 100644 index 0000000000..87efe005aa --- /dev/null +++ b/dolphinscheduler-dist/release-docs/licenses/LICENSE-DmJdbcDriver18.txt @@ -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. \ No newline at end of file diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/enums/DbType.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/enums/DbType.java index 0a2a0ef5ce..c2d4977bf5 100644 --- a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/enums/DbType.java +++ b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/enums/DbType.java @@ -42,7 +42,8 @@ public enum DbType { ATHENA(11, "athena"), TRINO(12, "trino"), STARROCKS(13, "starrocks"), - AZURESQL(14, "azuresql"); + AZURESQL(14, "azuresql"), + DAMENG(15, "dameng"); private static final Map DB_TYPE_MAP = Arrays.stream(DbType.values()).collect(toMap(DbType::getCode, Functions.identity())); diff --git a/dolphinscheduler-ui/src/service/modules/data-source/types.ts b/dolphinscheduler-ui/src/service/modules/data-source/types.ts index 1ad7fb7ad1..0d0b3e8867 100644 --- a/dolphinscheduler-ui/src/service/modules/data-source/types.ts +++ b/dolphinscheduler-ui/src/service/modules/data-source/types.ts @@ -30,6 +30,7 @@ type IDataBase = | 'TRINO' | 'AZURESQL' | 'STARROCKS' + | 'DAMENG' type IDataBaseLabel = | 'MYSQL' @@ -46,6 +47,7 @@ type IDataBaseLabel = | 'TRINO' | 'AZURESQL' | 'STARROCKS' +| 'DAMENG' interface IDataSource { id?: number diff --git a/dolphinscheduler-ui/src/views/datasource/list/use-form.ts b/dolphinscheduler-ui/src/views/datasource/list/use-form.ts index 371129ea04..dcf15e766c 100644 --- a/dolphinscheduler-ui/src/views/datasource/list/use-form.ts +++ b/dolphinscheduler-ui/src/views/datasource/list/use-form.ts @@ -367,6 +367,11 @@ export const datasourceType: IDataBaseOptionKeys = { value: 'STARROCKS', label: 'STARROCKS', defaultPort: 9030 + }, + DAMENG: { + value: 'DAMENG', + label: 'DAMENG', + defaultPort: 5236 } } diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-datasource.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-datasource.ts index 30cddc65cd..984ad08b69 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-datasource.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-datasource.ts @@ -108,6 +108,11 @@ export function useDatasource( code: 'AZURESQL', disabled: false }, + { + id: 15, + code: 'DAMENG', + disabled: false + } ] const getDatasourceTypes = async () => { diff --git a/tools/dependencies/known-dependencies.txt b/tools/dependencies/known-dependencies.txt index f3e9efc5d3..5e7b64c525 100644 --- a/tools/dependencies/known-dependencies.txt +++ b/tools/dependencies/known-dependencies.txt @@ -398,3 +398,4 @@ oauth2-oidc-sdk-9.35.jar reactor-core-3.4.22.jar reactor-netty-core-1.0.22.jar reactor-netty-http-1.0.22.jar +DmJdbcDriver18-8.1.2.79.jar