From 4aab0b234f8d5e93a727181a16411441ebfed123 Mon Sep 17 00:00:00 2001 From: Wenjun Ruan Date: Wed, 26 Jul 2023 08:58:50 +0800 Subject: [PATCH] Use AdHoc datasource client in sqlTask (#14631) * Use AdHoc datasource client in sqlTask * Add method in DataSourceChannel to create PooledDataSourceClient and AdHocDataSourceClient --- .github/workflows/e2e.yml | 2 +- .../en/contribute/backend/spi/datasource.md | 2 +- .../zh/contribute/backend/spi/datasource.md | 2 +- .../service/impl/DataSourceServiceImpl.java | 2 +- .../api/service/DataSourceServiceTest.java | 9 +- .../api/client/BaseAdHocDataSourceClient.java | 51 ++++++++ .../client/BasePooledDataSourceClient.java | 87 +++++++++++++ .../api/client/CommonDataSourceClient.java | 123 ------------------ .../api/plugin/DataSourceClientProvider.java | 71 +++++----- .../api/plugin/DataSourcePluginManager.java | 8 +- .../plugin/DataSourceProcessorProvider.java | 22 +--- .../api/provider/JDBCDataSourceProvider.java | 26 ---- .../datasource/api/utils/CommonUtils.java | 9 +- .../datasource/api/utils/DataSourceUtils.java | 2 +- .../BasePooledDataSourceClientTest.java | 42 ++++++ .../client/CommonDataSourceClientTest.java | 88 ------------- ....java => AthenaAdHocDataSourceClient.java} | 6 +- .../athena/AthenaDataSourceChannel.java | 13 +- .../athena/AthenaPooledDataSourceClient.java | 29 +++++ .../AzureSQLAdHocDataSourceClient.java | 29 +++++ .../azuresql/AzureSQLDataSourceChannel.java | 12 +- ...va => AzureSQLPooledDataSourceClient.java} | 41 +----- .../SQLServerDataSourceChannelTest.java | 8 +- ...a => ClickHouseAdHocDataSourceClient.java} | 7 +- .../ClickHouseDataSourceChannel.java | 12 +- .../ClickHousePooledDataSourceClient.java | 30 +++++ .../ClickHouseDataSourceChannelTest.java | 7 +- ....java => DamengAdHocDataSourceClient.java} | 7 +- .../dameng/DamengDataSourceChannel.java | 12 +- .../dameng/DamengPooledDataSourceClient.java | 30 +++++ .../dameng/DamengDataSourceChannelTest.java | 8 +- ...ava => DatabendAdHocDataSourceClient.java} | 7 +- .../databend/DatabendDataSourceChannel.java | 12 +- .../DatabendPooledDataSourceClient.java | 30 +++++ .../DatabendDataSourceChannelTest.java | 7 +- ...ent.java => DB2AdHocDataSourceClient.java} | 7 +- .../datasource/db2/DB2DataSourceChannel.java | 12 +- .../db2/DB2PooledDataSourceClient.java | 30 +++++ .../db2/DB2DataSourceChannelTest.java | 7 +- ...t.java => DorisAdHocDataSourceClient.java} | 7 +- .../plugin/doris/DorisDataSourceChannel.java | 12 +- .../doris/DorisPooledDataSourceClient.java | 28 ++++ .../doris/DorisDataSourceChannelTest.java | 7 +- .../provider/JDBCDataSourceProviderTest.java | 14 -- .../doris/utils/DataSourceUtilsTest.java | 11 +- .../hive/HiveAdHocDataSourceClient.java | 29 +++++ .../hive/HiveDataSourceChannel.java | 12 +- ...t.java => HivePooledDataSourceClient.java} | 45 ++----- .../hive/HiveDataSourceChannelTest.java | 7 +- .../kyuubi/KyuubiAdHocDataSourceClient.java | 29 +++++ .../kyuubi/KyuubiDataSourceChannel.java | 12 +- .../kyuubi/KyuubiDataSourceClient.java | 75 ----------- .../kyuubi/KyuubiPooledDataSourceClient.java} | 24 +++- .../param/KyuubiDataSourceProcessor.java | 1 + .../kyuubi/KyuubiDataSourceChannelTest.java | 7 +- .../kyuubi/KyuubiDataSourceClientTest.java | 73 ----------- .../KyuubiPooledDataSourceClientTest.java | 44 +++++++ .../KyuubiJDBCDataSourceProviderTest.java | 14 -- ...t.java => MySQLAdHocDataSourceClient.java} | 7 +- .../mysql/MySQLDataSourceChannel.java | 12 +- .../mysql/MySQLPooledDataSourceClient.java | 30 +++++ .../mysql/MySQLDataSourceChannelTest.java | 7 +- .../provider/JDBCDataSourceProviderTest.java | 14 -- .../mysql/utils/DataSourceUtilsTest.java | 9 +- ...va => OceanBaseAdHocDataSourceClient.java} | 6 +- .../oceanbase/OceanBaseDataSourceChannel.java | 12 +- .../OceanBasePooledDataSourceClient.java | 29 +++++ .../oracle/OracleAdHocDataSourceClient.java | 29 +++++ .../oracle/OracleDataSourceChannel.java | 12 +- .../oracle/OraclePooledDataSourceClient.java | 30 +++++ .../oracle/OracleDataSourceChannelTest.java | 8 +- ...a => PostgreAdHocSQLDataSourceClient.java} | 7 +- .../PostgrePooledSQLDataSourceClient.java | 30 +++++ .../PostgreSQLDataSourceChannel.java | 12 +- .../PostgreSQLDataSourceChannelTest.java | 7 +- ....java => PrestoAdHocDataSourceClient.java} | 7 +- .../presto/PrestoDataSourceChannel.java | 12 +- .../presto/PrestoPooledDataSourceClient.java | 30 +++++ .../presto/PrestoDataSourceChannelTest.java | 8 +- .../RedshiftAdHocDataSourceClient.java | 29 +++++ .../redshift/RedshiftDataSourceChannel.java | 12 +- ...va => RedshiftPooledDataSourceClient.java} | 40 +----- ...va => SnowflakeAdHocDataSourceClient.java} | 7 +- .../snowflake/SnowflakeDataSourceChannel.java | 12 +- .../SnowflakePooledDataSourceClient.java | 30 +++++ .../SnowflakeDataSourceChannelTest.java | 8 +- ... SnowflakePooledDataSourceClientTest.java} | 17 +-- .../SnowflakeJDBCDataSourceProviderTest.java | 14 -- .../spark/SparkAdHocDataSourceClient.java | 29 +++++ .../spark/SparkDataSourceChannel.java | 12 +- ....java => SparkPooledDataSourceClient.java} | 6 +- .../spark/SparkDataSourceChannelTest.java | 7 +- ...va => SQLServerAdHocDataSourceClient.java} | 7 +- .../sqlserver/SQLServerDataSourceChannel.java | 12 +- .../SQLServerPooledDataSourceClient.java | 30 +++++ .../SQLServerDataSourceChannelTest.java | 8 +- .../datasource/ssh/SSHDataSourceChannel.java | 11 +- ...va => StarRocksAdHocDataSourceClient.java} | 7 +- .../starrocks/StarRocksDataSourceChannel.java | 12 +- .../StarRocksPooledDataSourceClient.java | 30 +++++ ...t.java => TrinoAdHocDataSourceClient.java} | 7 +- .../trino/TrinoDataSourceChannel.java | 12 +- .../trino/TrinoPooledDataSourceClient.java | 30 +++++ .../trino/TrinoDataSourceChannelTest.java | 2 +- ...java => VerticaAdHocDataSourceClient.java} | 7 +- .../vertica/VerticaDataSourceChannel.java | 12 +- .../VerticaPooledDataSourceClient.java | 30 +++++ .../vertica/VerticaDataSourceChannelTest.java | 8 +- .../provider/JDBCDataSourceProviderTest.java | 14 -- .../vertica/utils/DataSourceUtilsTest.java | 10 +- .../spi/datasource/AdHocDataSourceClient.java | 25 ++++ .../spi/datasource/DataSourceChannel.java | 10 +- .../spi/datasource/DataSourceClient.java | 10 +- .../datasource/PooledDataSourceClient.java | 15 ++- .../plugin/task/datax/DataxTask.java | 2 +- .../plugin/task/datax/DataxTaskTest.java | 5 +- .../plugin/task/procedure/ProcedureTask.java | 6 +- .../plugin/task/sql/SqlTask.java | 11 +- 118 files changed, 1373 insertions(+), 861 deletions(-) create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/client/BaseAdHocDataSourceClient.java create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/client/BasePooledDataSourceClient.java delete mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/client/CommonDataSourceClient.java create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/test/java/org/apache/dolphinscheduler/plugin/datasource/api/client/BasePooledDataSourceClientTest.java delete mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/test/java/org/apache/dolphinscheduler/plugin/datasource/api/client/CommonDataSourceClientTest.java rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-athena/src/main/java/org/apache/dolphinscheduler/plugin/datasource/athena/{AthenaDataSourceClient.java => AthenaAdHocDataSourceClient.java} (84%) create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-athena/src/main/java/org/apache/dolphinscheduler/plugin/datasource/athena/AthenaPooledDataSourceClient.java create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-azure-sql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/azuresql/AzureSQLAdHocDataSourceClient.java rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-azure-sql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/azuresql/{AzureSQLDataSourceClient.java => AzureSQLPooledDataSourceClient.java} (50%) rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-clickhouse/src/main/java/org/apache/dolphinscheduler/plugin/datasource/clickhouse/{ClickHouseDataSourceClient.java => ClickHouseAdHocDataSourceClient.java} (84%) create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-clickhouse/src/main/java/org/apache/dolphinscheduler/plugin/datasource/clickhouse/ClickHousePooledDataSourceClient.java rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/{DamengDataSourceClient.java => DamengAdHocDataSourceClient.java} (84%) create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengPooledDataSourceClient.java rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-databend/src/main/java/org/apache/dolphinscheduler/plugin/datasource/databend/{DatabendDataSourceClient.java => DatabendAdHocDataSourceClient.java} (84%) create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-databend/src/main/java/org/apache/dolphinscheduler/plugin/datasource/databend/DatabendPooledDataSourceClient.java rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-db2/src/main/java/org/apache/dolphinscheduler/plugin/datasource/db2/{DB2DataSourceClient.java => DB2AdHocDataSourceClient.java} (84%) create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-db2/src/main/java/org/apache/dolphinscheduler/plugin/datasource/db2/DB2PooledDataSourceClient.java rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/main/java/org/apache/dolphinscheduler/plugin/doris/{DorisDataSourceClient.java => DorisAdHocDataSourceClient.java} (84%) create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/main/java/org/apache/dolphinscheduler/plugin/doris/DorisPooledDataSourceClient.java create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hive/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hive/HiveAdHocDataSourceClient.java rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hive/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hive/{HiveDataSourceClient.java => HivePooledDataSourceClient.java} (72%) create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/main/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiAdHocDataSourceClient.java delete mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/main/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiDataSourceClient.java rename dolphinscheduler-datasource-plugin/{dolphinscheduler-datasource-oracle/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oracle/OracleDataSourceClient.java => dolphinscheduler-datasource-kyuubi/src/main/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiPooledDataSourceClient.java} (64%) delete mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/test/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiDataSourceClientTest.java create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/test/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiPooledDataSourceClientTest.java rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/mysql/{MySQLDataSourceClient.java => MySQLAdHocDataSourceClient.java} (84%) create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/mysql/MySQLPooledDataSourceClient.java rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oceanbase/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oceanbase/{OceanBaseDataSourceClient.java => OceanBaseAdHocDataSourceClient.java} (84%) create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oceanbase/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oceanbase/OceanBasePooledDataSourceClient.java create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oracle/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oracle/OracleAdHocDataSourceClient.java create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oracle/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oracle/OraclePooledDataSourceClient.java rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-postgresql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/postgresql/{PostgreSQLDataSourceClient.java => PostgreAdHocSQLDataSourceClient.java} (84%) create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-postgresql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/postgresql/PostgrePooledSQLDataSourceClient.java rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-presto/src/main/java/org/apache/dolphinscheduler/plugin/datasource/presto/{PrestoDataSourceClient.java => PrestoAdHocDataSourceClient.java} (84%) create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-presto/src/main/java/org/apache/dolphinscheduler/plugin/datasource/presto/PrestoPooledDataSourceClient.java create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-redshift/src/main/java/org/apache/dolphinscheduler/plugin/datasource/redshift/RedshiftAdHocDataSourceClient.java rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-redshift/src/main/java/org/apache/dolphinscheduler/plugin/datasource/redshift/{RedshiftDataSourceClient.java => RedshiftPooledDataSourceClient.java} (50%) rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/main/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/{SnowflakeDataSourceClient.java => SnowflakeAdHocDataSourceClient.java} (84%) create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/main/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakePooledDataSourceClient.java rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/test/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/{SnowflakeDataSourceClientTest.java => SnowflakePooledDataSourceClientTest.java} (72%) create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-spark/src/main/java/org/apache/dolphinscheduler/plugin/datasource/spark/SparkAdHocDataSourceClient.java rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-spark/src/main/java/org/apache/dolphinscheduler/plugin/datasource/spark/{SparkDataSourceClient.java => SparkPooledDataSourceClient.java} (79%) rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-sqlserver/src/main/java/org/apache/dolphinscheduler/plugin/datasource/sqlserver/{SQLServerDataSourceClient.java => SQLServerAdHocDataSourceClient.java} (84%) create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-sqlserver/src/main/java/org/apache/dolphinscheduler/plugin/datasource/sqlserver/SQLServerPooledDataSourceClient.java rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-starrocks/src/main/java/org/apache/dolphinscheduler/plugin/datasource/starrocks/{StarRocksDataSourceClient.java => StarRocksAdHocDataSourceClient.java} (84%) create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-starrocks/src/main/java/org/apache/dolphinscheduler/plugin/datasource/starrocks/StarRocksPooledDataSourceClient.java rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-trino/src/main/java/org/apache/dolphinscheduler/plugin/datasource/trino/{TrinoDataSourceClient.java => TrinoAdHocDataSourceClient.java} (84%) create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-trino/src/main/java/org/apache/dolphinscheduler/plugin/datasource/trino/TrinoPooledDataSourceClient.java rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/main/java/org/apache/dolphinscheduler/plugin/datasource/vertica/{VerticaDataSourceClient.java => VerticaAdHocDataSourceClient.java} (84%) create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/main/java/org/apache/dolphinscheduler/plugin/datasource/vertica/VerticaPooledDataSourceClient.java create mode 100644 dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/datasource/AdHocDataSourceClient.java rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-ssh/src/main/java/org/apache/dolphinscheduler/plugin/datasource/ssh/SSHDataSourceClient.java => dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/datasource/PooledDataSourceClient.java (67%) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 0cd4488db0..be46f4fb48 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -139,7 +139,7 @@ jobs: path: /tmp - name: Load Docker Images run: | - docker load -i /tmp/standalone-image.tar + docker load -i /tmp/standalone-image.tar - name: Run Test run: | ./mvnw -B -f dolphinscheduler-e2e/pom.xml -am \ diff --git a/docs/docs/en/contribute/backend/spi/datasource.md b/docs/docs/en/contribute/backend/spi/datasource.md index caf8a5be46..4cb2ff5776 100644 --- a/docs/docs/en/contribute/backend/spi/datasource.md +++ b/docs/docs/en/contribute/backend/spi/datasource.md @@ -10,7 +10,7 @@ If you are using MySQL or ORACLE data source, you need to place the correspondin org.apache.dolphinscheduler.spi.datasource.DataSourceChannel org.apache.dolphinscheduler.spi.datasource.DataSourceChannelFactory -org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient +org.apache.dolphinscheduler.spi.datasource.client.DataSourceClient 1. In the first step, the data source plug-in can implement the above interfaces and inherit the general client. For details, refer to the implementation of data source plug-ins such as sqlserver and mysql. The addition methods of all RDBMS plug-ins are the same. diff --git a/docs/docs/zh/contribute/backend/spi/datasource.md b/docs/docs/zh/contribute/backend/spi/datasource.md index a2fc4b59de..2b012fe186 100644 --- a/docs/docs/zh/contribute/backend/spi/datasource.md +++ b/docs/docs/zh/contribute/backend/spi/datasource.md @@ -10,7 +10,7 @@ org.apache.dolphinscheduler.spi.datasource.DataSourceChannel org.apache.dolphinscheduler.spi.datasource.DataSourceChannelFactory -org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient +org.apache.dolphinscheduler.spi.datasource.client.DataSourceClient 1. 第一步数据源插件实现以上接口和继承通用client即可,具体可以参考sqlserver、mysql等数据源插件实现,所有RDBMS插件的添加方式都是一样的。 2. 在数据源插件pom.xml添加驱动配置 diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java index cc659f02ce..6f0e5c50d7 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java @@ -369,7 +369,7 @@ public class DataSourceServiceImpl extends BaseServiceImpl implements DataSource } return result; } - try (Connection connection = DataSourceClientProvider.getInstance().getConnection(type, connectionParam)) { + try (Connection connection = DataSourceClientProvider.getAdHocConnection(type, connectionParam)) { if (connection == null) { log.error("Connection test to {} datasource failed, connectionParam:{}.", type.getDescp(), connectionParam); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataSourceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataSourceServiceTest.java index c1117c27c3..bc1616cb7e 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataSourceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataSourceServiceTest.java @@ -133,8 +133,6 @@ public class DataSourceServiceTest { try ( MockedStatic mockedStaticDataSourceClientProvider = Mockito.mockStatic(DataSourceClientProvider.class)) { - DataSourceClientProvider clientProvider = Mockito.mock(DataSourceClientProvider.class); - mockedStaticDataSourceClientProvider.when(DataSourceClientProvider::getInstance).thenReturn(clientProvider); Mockito.when(dataSourceMapper.queryDataSourceByName(dataSourceName.trim())).thenReturn(null); @@ -199,9 +197,6 @@ public class DataSourceServiceTest { MockedStatic mockedStaticDataSourceClientProvider = Mockito.mockStatic(DataSourceClientProvider.class)) { // DATASOURCE_CONNECT_FAILED - DataSourceClientProvider clientProvider = Mockito.mock(DataSourceClientProvider.class); - mockedStaticDataSourceClientProvider.when(DataSourceClientProvider::getInstance).thenReturn(clientProvider); - Mockito.when(dataSourceMapper.queryDataSourceByName(postgreSqlDatasourceParam.getName())).thenReturn(null); // SUCCESS @@ -509,13 +504,13 @@ public class DataSourceServiceTest { MockedStatic mockedStaticDataSourceClientProvider = Mockito.mockStatic(DataSourceClientProvider.class)) { DataSourceClientProvider clientProvider = Mockito.mock(DataSourceClientProvider.class); - mockedStaticDataSourceClientProvider.when(DataSourceClientProvider::getInstance).thenReturn(clientProvider); Result result = dataSourceService.checkConnection(dataSourceType, connectionParam); Assertions.assertEquals(Status.CONNECTION_TEST_FAILURE.getCode(), result.getCode().intValue()); Connection connection = Mockito.mock(Connection.class); - Mockito.when(clientProvider.getConnection(Mockito.any(), Mockito.any())).thenReturn(connection); + Mockito.when(DataSourceClientProvider.getAdHocConnection(Mockito.any(), Mockito.any())) + .thenReturn(connection); result = dataSourceService.checkConnection(dataSourceType, connectionParam); Assertions.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/client/BaseAdHocDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/client/BaseAdHocDataSourceClient.java new file mode 100644 index 0000000000..fcede5b44d --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/client/BaseAdHocDataSourceClient.java @@ -0,0 +1,51 @@ +/* + * 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.plugin.DataSourceProcessorProvider; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +import java.sql.Connection; +import java.sql.SQLException; + +public abstract class BaseAdHocDataSourceClient implements AdHocDataSourceClient { + + private final BaseConnectionParam baseConnectionParam; + private final DbType dbType; + + protected BaseAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + this.baseConnectionParam = baseConnectionParam; + this.dbType = dbType; + } + + @Override + public Connection getConnection() throws SQLException { + try { + return DataSourceProcessorProvider.getDataSourceProcessor(dbType).getConnection(baseConnectionParam); + } catch (Exception e) { + throw new SQLException("Create adhoc connection error", e); + } + } + + @Override + public void close() { + // do nothing + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/client/BasePooledDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/client/BasePooledDataSourceClient.java new file mode 100644 index 0000000000..f5078df121 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/client/BasePooledDataSourceClient.java @@ -0,0 +1,87 @@ +/* + * 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 static com.google.common.base.Preconditions.checkNotNull; + +import org.apache.dolphinscheduler.common.constants.DataSourceConstants; +import org.apache.dolphinscheduler.common.utils.PropertyUtils; +import org.apache.dolphinscheduler.plugin.datasource.api.utils.DataSourceUtils; +import org.apache.dolphinscheduler.plugin.datasource.api.utils.PasswordUtils; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.datasource.PooledDataSourceClient; +import org.apache.dolphinscheduler.spi.enums.DbType; + +import org.apache.commons.collections4.MapUtils; + +import java.sql.Connection; +import java.sql.SQLException; + +import lombok.extern.slf4j.Slf4j; + +import com.zaxxer.hikari.HikariDataSource; + +@Slf4j +public abstract class BasePooledDataSourceClient implements PooledDataSourceClient { + + protected final BaseConnectionParam baseConnectionParam; + protected HikariDataSource dataSource; + + public BasePooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + + this.baseConnectionParam = checkNotNull(baseConnectionParam, "baseConnectionParam is null"); + this.dataSource = createDataSourcePool(baseConnectionParam, checkNotNull(dbType, "dbType is null")); + } + + // todo: support multiple version databases + @Override + public HikariDataSource createDataSourcePool(BaseConnectionParam baseConnectionParam, DbType dbType) { + + HikariDataSource dataSource = new HikariDataSource(); + + dataSource.setDriverClassName(baseConnectionParam.getDriverClassName()); + dataSource.setJdbcUrl(DataSourceUtils.getJdbcUrl(dbType, baseConnectionParam)); + dataSource.setUsername(baseConnectionParam.getUser()); + dataSource.setPassword(PasswordUtils.decodePassword(baseConnectionParam.getPassword())); + + dataSource.setMinimumIdle(PropertyUtils.getInt(DataSourceConstants.SPRING_DATASOURCE_MIN_IDLE, 5)); + dataSource.setMaximumPoolSize(PropertyUtils.getInt(DataSourceConstants.SPRING_DATASOURCE_MAX_ACTIVE, 50)); + dataSource.setConnectionTestQuery(baseConnectionParam.getValidationQuery()); + + if (MapUtils.isNotEmpty(baseConnectionParam.getOther())) { + baseConnectionParam.getOther().forEach(dataSource::addDataSourceProperty); + } + + log.info("Creating HikariDataSource for {} success.", dbType.name()); + return dataSource; + } + + @Override + public Connection getConnection() throws SQLException { + return dataSource.getConnection(); + } + + @Override + public void close() { + log.info("do close dataSource {}.", baseConnectionParam.getDatabase()); + try (HikariDataSource closedDatasource = dataSource) { + // only close the resource + } + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/client/CommonDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/client/CommonDataSourceClient.java deleted file mode 100644 index c87b3453a1..0000000000 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/client/CommonDataSourceClient.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * 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 lombok.extern.slf4j.Slf4j; - -import org.springframework.jdbc.core.JdbcTemplate; - -import com.google.common.base.Stopwatch; -import com.zaxxer.hikari.HikariDataSource; - -@Slf4j -public class CommonDataSourceClient implements DataSourceClient { - - public static final String COMMON_USER = "root"; - public static final String COMMON_VALIDATION_QUERY = "select 1"; - - protected final BaseConnectionParam baseConnectionParam; - protected HikariDataSource dataSource; - protected JdbcTemplate jdbcTemplate; - - public CommonDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - this.baseConnectionParam = baseConnectionParam; - preInit(); - checkEnv(baseConnectionParam); - initClient(baseConnectionParam, dbType); - checkClient(); - } - - protected void preInit() { - log.info("preInit in CommonDataSourceClient"); - } - - protected void checkEnv(BaseConnectionParam baseConnectionParam) { - checkValidationQuery(baseConnectionParam); - checkUser(baseConnectionParam); - } - - protected void initClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - this.dataSource = JDBCDataSourceProvider.createJdbcDataSource(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()); - } catch (Exception e) { - throw new RuntimeException("JDBC connect failed", e); - } finally { - log.info("Time to execute check jdbc client with sql {} for {} ms ", - this.baseConnectionParam.getValidationQuery(), stopwatch.elapsed(TimeUnit.MILLISECONDS)); - } - } - - @Override - public Connection getConnection() { - try { - return this.dataSource.getConnection(); - } catch (SQLException e) { - log.error("get druidDataSource Connection fail SQLException: {}", e.getMessage(), e); - return null; - } - } - - @Override - public void close() { - log.info("do close dataSource {}.", baseConnectionParam.getDatabase()); - try (HikariDataSource closedDatasource = dataSource) { - // only close the resource - } - this.jdbcTemplate = null; - } - -} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/plugin/DataSourceClientProvider.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/plugin/DataSourceClientProvider.java index 29e1549385..f0b7fbb0a3 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/plugin/DataSourceClientProvider.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/plugin/DataSourceClientProvider.java @@ -20,13 +20,16 @@ package org.apache.dolphinscheduler.plugin.datasource.api.plugin; import org.apache.dolphinscheduler.common.utils.PropertyUtils; import org.apache.dolphinscheduler.plugin.datasource.api.utils.DataSourceUtils; import org.apache.dolphinscheduler.plugin.task.api.TaskConstants; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.datasource.ConnectionParam; import org.apache.dolphinscheduler.spi.datasource.DataSourceChannel; import org.apache.dolphinscheduler.spi.datasource.DataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; import java.sql.Connection; +import java.sql.SQLException; import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -41,48 +44,58 @@ import com.google.common.cache.RemovalListener; public class DataSourceClientProvider { private static final long duration = PropertyUtils.getLong(TaskConstants.KERBEROS_EXPIRE_TIME, 24); - private static final Cache uniqueId2dataSourceClientCache = CacheBuilder.newBuilder() - .expireAfterWrite(duration, TimeUnit.HOURS) - .removalListener((RemovalListener) notification -> { - try (DataSourceClient closedClient = notification.getValue()) { - log.info("Datasource: {} is removed from cache due to expire", notification.getKey()); - } - }) - .maximumSize(100) - .build(); - private DataSourcePluginManager dataSourcePluginManager; - private DataSourceClientProvider() { - initDataSourcePlugin(); - } - - private static class DataSourceClientProviderHolder { - - private static final DataSourceClientProvider INSTANCE = new DataSourceClientProvider(); - } + // We use the cache here to avoid creating a new datasource client every time, + // One DataSourceClient corresponds to one unique datasource. + private static final Cache POOLED_DATASOURCE_CLIENT_CACHE = + CacheBuilder.newBuilder() + .expireAfterWrite(duration, TimeUnit.HOURS) + .removalListener((RemovalListener) notification -> { + try (PooledDataSourceClient closedClient = notification.getValue()) { + log.info("Datasource: {} is removed from cache due to expire", notification.getKey()); + } catch (Exception e) { + log.error("Close datasource client error", e); + } + }) + .maximumSize(100) + .build(); + private static final DataSourcePluginManager dataSourcePluginManager = new DataSourcePluginManager(); - public static DataSourceClientProvider getInstance() { - return DataSourceClientProviderHolder.INSTANCE; + static { + dataSourcePluginManager.installPlugin(); } - public Connection getConnection(DbType dbType, ConnectionParam connectionParam) throws ExecutionException { + public static DataSourceClient getPooledDataSourceClient(DbType dbType, + ConnectionParam connectionParam) throws ExecutionException { BaseConnectionParam baseConnectionParam = (BaseConnectionParam) connectionParam; String datasourceUniqueId = DataSourceUtils.getDatasourceUniqueId(baseConnectionParam, dbType); - log.info("Get connection from datasource {}", datasourceUniqueId); - - DataSourceClient dataSourceClient = uniqueId2dataSourceClientCache.get(datasourceUniqueId, () -> { + return POOLED_DATASOURCE_CLIENT_CACHE.get(datasourceUniqueId, () -> { Map dataSourceChannelMap = dataSourcePluginManager.getDataSourceChannelMap(); DataSourceChannel dataSourceChannel = dataSourceChannelMap.get(dbType.getDescp()); if (null == dataSourceChannel) { throw new RuntimeException(String.format("datasource plugin '%s' is not found", dbType.getDescp())); } - return dataSourceChannel.createDataSourceClient(baseConnectionParam, dbType); + return dataSourceChannel.createPooledDataSourceClient(baseConnectionParam, dbType); }); - return dataSourceClient.getConnection(); } - private void initDataSourcePlugin() { - dataSourcePluginManager = new DataSourcePluginManager(); - dataSourcePluginManager.installPlugin(); + public static Connection getPooledConnection(DbType dbType, + ConnectionParam connectionParam) throws SQLException, ExecutionException { + return getPooledDataSourceClient(dbType, connectionParam).getConnection(); + } + + public static AdHocDataSourceClient getAdHocDataSourceClient(DbType dbType, ConnectionParam connectionParam) { + BaseConnectionParam baseConnectionParam = (BaseConnectionParam) connectionParam; + Map dataSourceChannelMap = dataSourcePluginManager.getDataSourceChannelMap(); + DataSourceChannel dataSourceChannel = dataSourceChannelMap.get(dbType.getDescp()); + if (null == dataSourceChannel) { + throw new RuntimeException(String.format("datasource plugin '%s' is not found", dbType.getDescp())); + } + return dataSourceChannel.createAdHocDataSourceClient(baseConnectionParam, dbType); + } + + public static Connection getAdHocConnection(DbType dbType, + ConnectionParam connectionParam) throws SQLException, ExecutionException { + return getAdHocDataSourceClient(dbType, connectionParam).getConnection(); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/plugin/DataSourcePluginManager.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/plugin/DataSourcePluginManager.java index f1d4391221..7c4b61d829 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/plugin/DataSourcePluginManager.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/plugin/DataSourcePluginManager.java @@ -32,10 +32,10 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class DataSourcePluginManager { - private final Map datasourceClientMap = new ConcurrentHashMap<>(); + private final Map datasourceChannelMap = new ConcurrentHashMap<>(); public Map getDataSourceChannelMap() { - return Collections.unmodifiableMap(datasourceClientMap); + return Collections.unmodifiableMap(datasourceChannelMap); } public void installPlugin() { @@ -48,7 +48,7 @@ public class DataSourcePluginManager { log.info("Registering datasource plugin: {}", name); - if (datasourceClientMap.containsKey(name)) { + if (datasourceChannelMap.containsKey(name)) { throw new IllegalStateException(format("Duplicate datasource plugins named '%s'", name)); } @@ -60,6 +60,6 @@ public class DataSourcePluginManager { private void loadDatasourceClient(DataSourceChannelFactory datasourceChannelFactory) { DataSourceChannel datasourceChannel = datasourceChannelFactory.create(); - datasourceClientMap.put(datasourceChannelFactory.getName(), datasourceChannel); + datasourceChannelMap.put(datasourceChannelFactory.getName(), datasourceChannel); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/plugin/DataSourceProcessorProvider.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/plugin/DataSourceProcessorProvider.java index 4ec1124325..751ac1ba08 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/plugin/DataSourceProcessorProvider.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/plugin/DataSourceProcessorProvider.java @@ -28,31 +28,21 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class DataSourceProcessorProvider { - private DataSourceProcessorManager dataSourcePluginManager; + private static final DataSourceProcessorManager dataSourcePluginManager = new DataSourceProcessorManager(); - private DataSourceProcessorProvider() { - initDataSourceProcessorPlugin(); - } - - private static class DataSourceClientProviderHolder { - - private static final DataSourceProcessorProvider INSTANCE = new DataSourceProcessorProvider(); + static { + dataSourcePluginManager.installProcessor(); } - public static DataSourceProcessorProvider getInstance() { - return DataSourceClientProviderHolder.INSTANCE; + private DataSourceProcessorProvider() { } - public DataSourceProcessor getDataSourceProcessor(@NonNull DbType dbType) { + public static DataSourceProcessor getDataSourceProcessor(@NonNull DbType dbType) { return dataSourcePluginManager.getDataSourceProcessorMap().get(dbType.name()); } - public Map getDataSourceProcessorMap() { + public static Map getDataSourceProcessorMap() { return dataSourcePluginManager.getDataSourceProcessorMap(); } - private void initDataSourceProcessorPlugin() { - dataSourcePluginManager = new DataSourceProcessorManager(); - dataSourcePluginManager.installProcessor(); - } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/provider/JDBCDataSourceProvider.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/provider/JDBCDataSourceProvider.java index 386b4ec822..d4651b224d 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/provider/JDBCDataSourceProvider.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/provider/JDBCDataSourceProvider.java @@ -40,32 +40,6 @@ import com.zaxxer.hikari.HikariDataSource; @Slf4j public class JDBCDataSourceProvider { - public static HikariDataSource createJdbcDataSource(BaseConnectionParam properties, DbType dbType) { - log.info("Creating HikariDataSource pool for maxActive:{}", - PropertyUtils.getInt(DataSourceConstants.SPRING_DATASOURCE_MAX_ACTIVE, 50)); - HikariDataSource dataSource = new HikariDataSource(); - - // TODO Support multiple versions of data sources - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - loaderJdbcDriver(classLoader, properties, dbType); - - dataSource.setDriverClassName(properties.getDriverClassName()); - dataSource.setJdbcUrl(DataSourceUtils.getJdbcUrl(dbType, properties)); - dataSource.setUsername(properties.getUser()); - dataSource.setPassword(PasswordUtils.decodePassword(properties.getPassword())); - - dataSource.setMinimumIdle(PropertyUtils.getInt(DataSourceConstants.SPRING_DATASOURCE_MIN_IDLE, 5)); - dataSource.setMaximumPoolSize(PropertyUtils.getInt(DataSourceConstants.SPRING_DATASOURCE_MAX_ACTIVE, 50)); - dataSource.setConnectionTestQuery(properties.getValidationQuery()); - - if (MapUtils.isNotEmpty(properties.getOther())) { - properties.getOther().forEach(dataSource::addDataSourceProperty); - } - - log.info("Creating HikariDataSource pool success."); - return dataSource; - } - /** * @return One Session Jdbc DataSource */ diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/utils/CommonUtils.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/utils/CommonUtils.java index 35432774bf..e6ecef287a 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/utils/CommonUtils.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/utils/CommonUtils.java @@ -84,13 +84,14 @@ public class CommonUtils { /** * load kerberos configuration * - * @param javaSecurityKrb5Conf javaSecurityKrb5Conf + * @param javaSecurityKrb5Conf javaSecurityKrb5Conf * @param loginUserKeytabUsername loginUserKeytabUsername - * @param loginUserKeytabPath loginUserKeytabPath + * @param loginUserKeytabPath loginUserKeytabPath * @throws IOException errors */ - public static void loadKerberosConf(String javaSecurityKrb5Conf, String loginUserKeytabUsername, - String loginUserKeytabPath) throws IOException { + public static synchronized void loadKerberosConf(String javaSecurityKrb5Conf, + String loginUserKeytabUsername, + String loginUserKeytabPath) throws IOException { Configuration configuration = new Configuration(); configuration.setClassLoader(configuration.getClass().getClassLoader()); loadKerberosConf(javaSecurityKrb5Conf, loginUserKeytabUsername, loginUserKeytabPath, configuration); diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/utils/DataSourceUtils.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/utils/DataSourceUtils.java index af8a99eb26..e3e43e52f0 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/utils/DataSourceUtils.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/utils/DataSourceUtils.java @@ -84,7 +84,7 @@ public class DataSourceUtils { public static DataSourceProcessor getDatasourceProcessor(DbType dbType) { Map dataSourceProcessorMap = - DataSourceProcessorProvider.getInstance().getDataSourceProcessorMap(); + DataSourceProcessorProvider.getDataSourceProcessorMap(); if (!dataSourceProcessorMap.containsKey(dbType.name())) { throw new IllegalArgumentException("illegal datasource type"); } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/test/java/org/apache/dolphinscheduler/plugin/datasource/api/client/BasePooledDataSourceClientTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/test/java/org/apache/dolphinscheduler/plugin/datasource/api/client/BasePooledDataSourceClientTest.java new file mode 100644 index 0000000000..af5fea9a18 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/test/java/org/apache/dolphinscheduler/plugin/datasource/api/client/BasePooledDataSourceClientTest.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.api.client; + +import java.sql.Connection; +import java.sql.SQLException; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public class BasePooledDataSourceClientTest { + + @Mock + private BasePooledDataSourceClient basePooledDataSourceClient; + + @Test + public void testGetConnection() throws SQLException { + Connection connection = Mockito.mock(Connection.class); + Mockito.when(basePooledDataSourceClient.getConnection()).thenReturn(connection); + Assertions.assertNotNull(basePooledDataSourceClient.getConnection()); + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/test/java/org/apache/dolphinscheduler/plugin/datasource/api/client/CommonDataSourceClientTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/test/java/org/apache/dolphinscheduler/plugin/datasource/api/client/CommonDataSourceClientTest.java deleted file mode 100644 index c3b57a5755..0000000000 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/test/java/org/apache/dolphinscheduler/plugin/datasource/api/client/CommonDataSourceClientTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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.datasource.MySQLConnectionParam; -import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; -import org.apache.dolphinscheduler.spi.enums.DbType; - -import java.sql.Connection; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; - -@ExtendWith(MockitoExtension.class) -public class CommonDataSourceClientTest { - - @Mock - private CommonDataSourceClient commonDataSourceClient; - - @Test - public void testPreInit() { - Mockito.doNothing().when(commonDataSourceClient).preInit(); - commonDataSourceClient.preInit(); - Mockito.verify(commonDataSourceClient).preInit(); - } - - @Test - public void testCheckEnv() { - BaseConnectionParam baseConnectionParam = new MySQLConnectionParam(); - Mockito.doNothing().when(commonDataSourceClient).checkEnv(Mockito.any(BaseConnectionParam.class)); - commonDataSourceClient.checkEnv(baseConnectionParam); - Mockito.verify(commonDataSourceClient).checkEnv(Mockito.any(BaseConnectionParam.class)); - - Mockito.doNothing().when(commonDataSourceClient).checkValidationQuery(Mockito.any(BaseConnectionParam.class)); - commonDataSourceClient.checkValidationQuery(baseConnectionParam); - Mockito.verify(commonDataSourceClient).checkValidationQuery(Mockito.any(BaseConnectionParam.class)); - - Mockito.doNothing().when(commonDataSourceClient).checkUser(Mockito.any(BaseConnectionParam.class)); - commonDataSourceClient.checkUser(baseConnectionParam); - Mockito.verify(commonDataSourceClient).checkUser(Mockito.any(BaseConnectionParam.class)); - - Mockito.doNothing().when(commonDataSourceClient).setDefaultUsername(Mockito.any(BaseConnectionParam.class)); - commonDataSourceClient.setDefaultUsername(baseConnectionParam); - Mockito.verify(commonDataSourceClient).setDefaultUsername(Mockito.any(BaseConnectionParam.class)); - } - - @Test - public void testInitClient() { - BaseConnectionParam baseConnectionParam = new MySQLConnectionParam(); - Mockito.doNothing().when(commonDataSourceClient).initClient(Mockito.any(BaseConnectionParam.class), - Mockito.any()); - commonDataSourceClient.initClient(baseConnectionParam, DbType.MYSQL); - Mockito.verify(commonDataSourceClient).initClient(Mockito.any(BaseConnectionParam.class), Mockito.any()); - } - - @Test - public void testCheckClient() { - Mockito.doNothing().when(this.commonDataSourceClient).checkClient(); - this.commonDataSourceClient.checkClient(); - Mockito.verify(this.commonDataSourceClient).checkClient(); - } - - @Test - public void testGetConnection() { - Connection connection = Mockito.mock(Connection.class); - Mockito.when(commonDataSourceClient.getConnection()).thenReturn(connection); - Assertions.assertNotNull(commonDataSourceClient.getConnection()); - } -} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-athena/src/main/java/org/apache/dolphinscheduler/plugin/datasource/athena/AthenaDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-athena/src/main/java/org/apache/dolphinscheduler/plugin/datasource/athena/AthenaAdHocDataSourceClient.java similarity index 84% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-athena/src/main/java/org/apache/dolphinscheduler/plugin/datasource/athena/AthenaDataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-athena/src/main/java/org/apache/dolphinscheduler/plugin/datasource/athena/AthenaAdHocDataSourceClient.java index 20755d2f30..d390041441 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-athena/src/main/java/org/apache/dolphinscheduler/plugin/datasource/athena/AthenaDataSourceClient.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-athena/src/main/java/org/apache/dolphinscheduler/plugin/datasource/athena/AthenaAdHocDataSourceClient.java @@ -17,13 +17,13 @@ package org.apache.dolphinscheduler.plugin.datasource.athena; -import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; -public class AthenaDataSourceClient extends CommonDataSourceClient { +public class AthenaAdHocDataSourceClient extends BaseAdHocDataSourceClient { - public AthenaDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + public AthenaAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { super(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-athena/src/main/java/org/apache/dolphinscheduler/plugin/datasource/athena/AthenaDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-athena/src/main/java/org/apache/dolphinscheduler/plugin/datasource/athena/AthenaDataSourceChannel.java index a83c6b9fb7..3209db08d1 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-athena/src/main/java/org/apache/dolphinscheduler/plugin/datasource/athena/AthenaDataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-athena/src/main/java/org/apache/dolphinscheduler/plugin/datasource/athena/AthenaDataSourceChannel.java @@ -17,15 +17,22 @@ package org.apache.dolphinscheduler.plugin.datasource.athena; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class AthenaDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new AthenaDataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new AthenaAdHocDataSourceClient(baseConnectionParam, dbType); } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new AthenaPooledDataSourceClient(baseConnectionParam, dbType); + } + } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-athena/src/main/java/org/apache/dolphinscheduler/plugin/datasource/athena/AthenaPooledDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-athena/src/main/java/org/apache/dolphinscheduler/plugin/datasource/athena/AthenaPooledDataSourceClient.java new file mode 100644 index 0000000000..58e8847baa --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-athena/src/main/java/org/apache/dolphinscheduler/plugin/datasource/athena/AthenaPooledDataSourceClient.java @@ -0,0 +1,29 @@ +/* + * 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.athena; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BasePooledDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class AthenaPooledDataSourceClient extends BasePooledDataSourceClient { + + public AthenaPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-azure-sql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/azuresql/AzureSQLAdHocDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-azure-sql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/azuresql/AzureSQLAdHocDataSourceClient.java new file mode 100644 index 0000000000..9a0535dc89 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-azure-sql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/azuresql/AzureSQLAdHocDataSourceClient.java @@ -0,0 +1,29 @@ +/* + * 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.azuresql; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class AzureSQLAdHocDataSourceClient extends BaseAdHocDataSourceClient { + + public AzureSQLAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-azure-sql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/azuresql/AzureSQLDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-azure-sql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/azuresql/AzureSQLDataSourceChannel.java index 188ae0eb40..b794c4fa68 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-azure-sql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/azuresql/AzureSQLDataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-azure-sql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/azuresql/AzureSQLDataSourceChannel.java @@ -17,15 +17,21 @@ package org.apache.dolphinscheduler.plugin.datasource.azuresql; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class AzureSQLDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new AzureSQLDataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new AzureSQLAdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new AzureSQLPooledDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-azure-sql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/azuresql/AzureSQLDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-azure-sql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/azuresql/AzureSQLPooledDataSourceClient.java similarity index 50% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-azure-sql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/azuresql/AzureSQLDataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-azure-sql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/azuresql/AzureSQLPooledDataSourceClient.java index cf7db2e3b2..1b5fa387a0 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-azure-sql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/azuresql/AzureSQLDataSourceClient.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-azure-sql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/azuresql/AzureSQLPooledDataSourceClient.java @@ -17,7 +17,7 @@ package org.apache.dolphinscheduler.plugin.datasource.azuresql; -import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; +import org.apache.dolphinscheduler.plugin.datasource.api.client.BasePooledDataSourceClient; import org.apache.dolphinscheduler.plugin.datasource.azuresql.param.AzureSQLAuthMode; import org.apache.dolphinscheduler.plugin.datasource.azuresql.param.AzureSQLConnectionParam; import org.apache.dolphinscheduler.plugin.datasource.azuresql.param.AzureSQLDataSourceProcessor; @@ -26,22 +26,18 @@ import org.apache.dolphinscheduler.spi.enums.DbType; import java.sql.Connection; import java.sql.SQLException; -import java.sql.Statement; -import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; -import com.google.common.base.Stopwatch; - @Slf4j -public class AzureSQLDataSourceClient extends CommonDataSourceClient { +public class AzureSQLPooledDataSourceClient extends BasePooledDataSourceClient { - public AzureSQLDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + public AzureSQLPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { super(baseConnectionParam, dbType); } @Override - public Connection getConnection() { + public Connection getConnection() throws SQLException { AzureSQLConnectionParam connectionParam = (AzureSQLConnectionParam) this.baseConnectionParam; if (!connectionParam.getMode().equals(AzureSQLAuthMode.ACCESSTOKEN)) { return super.getConnection(); @@ -49,33 +45,4 @@ public class AzureSQLDataSourceClient extends CommonDataSourceClient { return AzureSQLDataSourceProcessor.tokenGetConnection(connectionParam); } - @Override - public void checkClient() { - - AzureSQLConnectionParam connectionParam = (AzureSQLConnectionParam) this.baseConnectionParam; - Stopwatch stopwatch = Stopwatch.createStarted(); - String validationQuery = this.baseConnectionParam.getValidationQuery(); - if (!connectionParam.getMode().equals(AzureSQLAuthMode.ACCESSTOKEN)) { - // Checking data source client - try { - this.jdbcTemplate.execute(validationQuery); - } catch (Exception e) { - throw new RuntimeException("JDBC connect failed", e); - } finally { - log.info("Time to execute check jdbc client with sql {} for {} ms ", - this.baseConnectionParam.getValidationQuery(), stopwatch.elapsed(TimeUnit.MILLISECONDS)); - } - } else { - try (Statement statement = getConnection().createStatement()) { - if (!statement.execute(validationQuery)) { - throw new SQLException("execute check azure sql token client failed : " + validationQuery); - } - } catch (SQLException e) { - throw new RuntimeException(e); - } finally { - log.info("Time to execute check azure sql token client with sql {} for {} ms ", - this.baseConnectionParam.getValidationQuery(), stopwatch.elapsed(TimeUnit.MILLISECONDS)); - } - } - } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-azure-sql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/azuresql/SQLServerDataSourceChannelTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-azure-sql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/azuresql/SQLServerDataSourceChannelTest.java index 9c8ae335a3..33a83df455 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-azure-sql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/azuresql/SQLServerDataSourceChannelTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-azure-sql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/azuresql/SQLServerDataSourceChannelTest.java @@ -32,9 +32,11 @@ public class SQLServerDataSourceChannelTest { @Test public void testCreateDataSourceClient() { AzureSQLDataSourceChannel sourceChannel = Mockito.mock(AzureSQLDataSourceChannel.class); - AzureSQLDataSourceClient dataSourceClient = Mockito.mock(AzureSQLDataSourceClient.class); - Mockito.when(sourceChannel.createDataSourceClient(Mockito.any(), Mockito.any())).thenReturn(dataSourceClient); + AzureSQLPooledDataSourceClient dataSourceClient = Mockito.mock(AzureSQLPooledDataSourceClient.class); + Mockito.when(sourceChannel.createPooledDataSourceClient(Mockito.any(), Mockito.any())) + .thenReturn(dataSourceClient); Assertions - .assertNotNull(sourceChannel.createDataSourceClient(new AzureSQLConnectionParam(), DbType.AZURESQL)); + .assertNotNull( + sourceChannel.createPooledDataSourceClient(new AzureSQLConnectionParam(), DbType.AZURESQL)); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-clickhouse/src/main/java/org/apache/dolphinscheduler/plugin/datasource/clickhouse/ClickHouseDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-clickhouse/src/main/java/org/apache/dolphinscheduler/plugin/datasource/clickhouse/ClickHouseAdHocDataSourceClient.java similarity index 84% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-clickhouse/src/main/java/org/apache/dolphinscheduler/plugin/datasource/clickhouse/ClickHouseDataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-clickhouse/src/main/java/org/apache/dolphinscheduler/plugin/datasource/clickhouse/ClickHouseAdHocDataSourceClient.java index 36e5a59e3b..f7fdae848b 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-clickhouse/src/main/java/org/apache/dolphinscheduler/plugin/datasource/clickhouse/ClickHouseDataSourceClient.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-clickhouse/src/main/java/org/apache/dolphinscheduler/plugin/datasource/clickhouse/ClickHouseAdHocDataSourceClient.java @@ -17,14 +17,13 @@ package org.apache.dolphinscheduler.plugin.datasource.clickhouse; -import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; -public class ClickHouseDataSourceClient extends CommonDataSourceClient { +public class ClickHouseAdHocDataSourceClient extends BaseAdHocDataSourceClient { - public ClickHouseDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + public ClickHouseAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { super(baseConnectionParam, dbType); } - } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-clickhouse/src/main/java/org/apache/dolphinscheduler/plugin/datasource/clickhouse/ClickHouseDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-clickhouse/src/main/java/org/apache/dolphinscheduler/plugin/datasource/clickhouse/ClickHouseDataSourceChannel.java index ac8835c47a..d967b3c6fd 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-clickhouse/src/main/java/org/apache/dolphinscheduler/plugin/datasource/clickhouse/ClickHouseDataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-clickhouse/src/main/java/org/apache/dolphinscheduler/plugin/datasource/clickhouse/ClickHouseDataSourceChannel.java @@ -17,15 +17,21 @@ package org.apache.dolphinscheduler.plugin.datasource.clickhouse; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class ClickHouseDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new ClickHouseDataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new ClickHouseAdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new ClickHousePooledDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-clickhouse/src/main/java/org/apache/dolphinscheduler/plugin/datasource/clickhouse/ClickHousePooledDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-clickhouse/src/main/java/org/apache/dolphinscheduler/plugin/datasource/clickhouse/ClickHousePooledDataSourceClient.java new file mode 100644 index 0000000000..79d8b2a67e --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-clickhouse/src/main/java/org/apache/dolphinscheduler/plugin/datasource/clickhouse/ClickHousePooledDataSourceClient.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.clickhouse; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BasePooledDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class ClickHousePooledDataSourceClient extends BasePooledDataSourceClient { + + public ClickHousePooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-clickhouse/src/test/java/org/apache/dolphinscheduler/plugin/datasource/clickhouse/ClickHouseDataSourceChannelTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-clickhouse/src/test/java/org/apache/dolphinscheduler/plugin/datasource/clickhouse/ClickHouseDataSourceChannelTest.java index c2eba2f510..ad09f281aa 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-clickhouse/src/test/java/org/apache/dolphinscheduler/plugin/datasource/clickhouse/ClickHouseDataSourceChannelTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-clickhouse/src/test/java/org/apache/dolphinscheduler/plugin/datasource/clickhouse/ClickHouseDataSourceChannelTest.java @@ -32,9 +32,10 @@ public class ClickHouseDataSourceChannelTest { @Test public void testCreateDataSourceClient() { ClickHouseDataSourceChannel sourceChannel = Mockito.mock(ClickHouseDataSourceChannel.class); - ClickHouseDataSourceClient dataSourceClient = Mockito.mock(ClickHouseDataSourceClient.class); - Mockito.when(sourceChannel.createDataSourceClient(Mockito.any(), Mockito.any())).thenReturn(dataSourceClient); + ClickHousePooledDataSourceClient dataSourceClient = Mockito.mock(ClickHousePooledDataSourceClient.class); + Mockito.when(sourceChannel.createPooledDataSourceClient(Mockito.any(), Mockito.any())) + .thenReturn(dataSourceClient); Assertions.assertNotNull( - sourceChannel.createDataSourceClient(new ClickHouseConnectionParam(), DbType.CLICKHOUSE)); + sourceChannel.createPooledDataSourceClient(new ClickHouseConnectionParam(), DbType.CLICKHOUSE)); } } 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/DamengAdHocDataSourceClient.java similarity index 84% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengDataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengAdHocDataSourceClient.java index 85261afb7d..8f38ab5d33 100644 --- 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/DamengAdHocDataSourceClient.java @@ -17,14 +17,13 @@ package org.apache.dolphinscheduler.plugin.datasource.dameng; -import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; -public class DamengDataSourceClient extends CommonDataSourceClient { +public class DamengAdHocDataSourceClient extends BaseAdHocDataSourceClient { - public DamengDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + public DamengAdHocDataSourceClient(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/DamengDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengDataSourceChannel.java index 6fa197c3ba..01416bec41 100644 --- 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 @@ -17,15 +17,21 @@ package org.apache.dolphinscheduler.plugin.datasource.dameng; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; 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); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new DamengAdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new DamengPooledDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengPooledDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengPooledDataSourceClient.java new file mode 100644 index 0000000000..d78b76458d --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-dameng/src/main/java/org/apache/dolphinscheduler/plugin/datasource/dameng/DamengPooledDataSourceClient.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.BasePooledDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class DamengPooledDataSourceClient extends BasePooledDataSourceClient { + + public DamengPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } + +} 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 index d47b671c25..2a795fdac7 100644 --- 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 @@ -32,9 +32,11 @@ 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)); + DamengPooledDataSourceClient dataSourceClient = Mockito.mock(DamengPooledDataSourceClient.class); + Mockito.when(sourceChannel.createPooledDataSourceClient(Mockito.any(), Mockito.any())) + .thenReturn(dataSourceClient); + Assertions + .assertNotNull(sourceChannel.createPooledDataSourceClient(new DamengConnectionParam(), DbType.DAMENG)); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-databend/src/main/java/org/apache/dolphinscheduler/plugin/datasource/databend/DatabendDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-databend/src/main/java/org/apache/dolphinscheduler/plugin/datasource/databend/DatabendAdHocDataSourceClient.java similarity index 84% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-databend/src/main/java/org/apache/dolphinscheduler/plugin/datasource/databend/DatabendDataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-databend/src/main/java/org/apache/dolphinscheduler/plugin/datasource/databend/DatabendAdHocDataSourceClient.java index df94966d00..22904b473b 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-databend/src/main/java/org/apache/dolphinscheduler/plugin/datasource/databend/DatabendDataSourceClient.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-databend/src/main/java/org/apache/dolphinscheduler/plugin/datasource/databend/DatabendAdHocDataSourceClient.java @@ -17,14 +17,13 @@ package org.apache.dolphinscheduler.plugin.datasource.databend; -import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; -public class DatabendDataSourceClient extends CommonDataSourceClient { +public class DatabendAdHocDataSourceClient extends BaseAdHocDataSourceClient { - public DatabendDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + public DatabendAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { super(baseConnectionParam, dbType); } - } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-databend/src/main/java/org/apache/dolphinscheduler/plugin/datasource/databend/DatabendDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-databend/src/main/java/org/apache/dolphinscheduler/plugin/datasource/databend/DatabendDataSourceChannel.java index e872f6539f..54e38258dd 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-databend/src/main/java/org/apache/dolphinscheduler/plugin/datasource/databend/DatabendDataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-databend/src/main/java/org/apache/dolphinscheduler/plugin/datasource/databend/DatabendDataSourceChannel.java @@ -17,15 +17,21 @@ package org.apache.dolphinscheduler.plugin.datasource.databend; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class DatabendDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new DatabendDataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new DatabendAdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new DatabendPooledDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-databend/src/main/java/org/apache/dolphinscheduler/plugin/datasource/databend/DatabendPooledDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-databend/src/main/java/org/apache/dolphinscheduler/plugin/datasource/databend/DatabendPooledDataSourceClient.java new file mode 100644 index 0000000000..131d497ee3 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-databend/src/main/java/org/apache/dolphinscheduler/plugin/datasource/databend/DatabendPooledDataSourceClient.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.databend; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BasePooledDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class DatabendPooledDataSourceClient extends BasePooledDataSourceClient { + + public DatabendPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-databend/src/test/java/org/apache/dolphinscheduler/plugin/datasource/databend/DatabendDataSourceChannelTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-databend/src/test/java/org/apache/dolphinscheduler/plugin/datasource/databend/DatabendDataSourceChannelTest.java index e4dcc4b9a5..278d4cfa84 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-databend/src/test/java/org/apache/dolphinscheduler/plugin/datasource/databend/DatabendDataSourceChannelTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-databend/src/test/java/org/apache/dolphinscheduler/plugin/datasource/databend/DatabendDataSourceChannelTest.java @@ -32,9 +32,10 @@ public class DatabendDataSourceChannelTest { @Test public void testCreateDataSourceClient() { DatabendDataSourceChannel sourceChannel = Mockito.mock(DatabendDataSourceChannel.class); - DatabendDataSourceClient dataSourceClient = Mockito.mock(DatabendDataSourceClient.class); - Mockito.when(sourceChannel.createDataSourceClient(Mockito.any(), Mockito.any())).thenReturn(dataSourceClient); + DatabendPooledDataSourceClient dataSourceClient = Mockito.mock(DatabendPooledDataSourceClient.class); + Mockito.when(sourceChannel.createPooledDataSourceClient(Mockito.any(), Mockito.any())) + .thenReturn(dataSourceClient); Assertions.assertNotNull( - sourceChannel.createDataSourceClient(new DatabendConnectionParam(), DbType.DATABEND)); + sourceChannel.createPooledDataSourceClient(new DatabendConnectionParam(), DbType.DATABEND)); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-db2/src/main/java/org/apache/dolphinscheduler/plugin/datasource/db2/DB2DataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-db2/src/main/java/org/apache/dolphinscheduler/plugin/datasource/db2/DB2AdHocDataSourceClient.java similarity index 84% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-db2/src/main/java/org/apache/dolphinscheduler/plugin/datasource/db2/DB2DataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-db2/src/main/java/org/apache/dolphinscheduler/plugin/datasource/db2/DB2AdHocDataSourceClient.java index 5db789f223..b38e0f5e3d 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-db2/src/main/java/org/apache/dolphinscheduler/plugin/datasource/db2/DB2DataSourceClient.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-db2/src/main/java/org/apache/dolphinscheduler/plugin/datasource/db2/DB2AdHocDataSourceClient.java @@ -17,14 +17,13 @@ package org.apache.dolphinscheduler.plugin.datasource.db2; -import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; -public class DB2DataSourceClient extends CommonDataSourceClient { +public class DB2AdHocDataSourceClient extends BaseAdHocDataSourceClient { - public DB2DataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + public DB2AdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { super(baseConnectionParam, dbType); } - } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-db2/src/main/java/org/apache/dolphinscheduler/plugin/datasource/db2/DB2DataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-db2/src/main/java/org/apache/dolphinscheduler/plugin/datasource/db2/DB2DataSourceChannel.java index fac46b0802..5e49f63c6e 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-db2/src/main/java/org/apache/dolphinscheduler/plugin/datasource/db2/DB2DataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-db2/src/main/java/org/apache/dolphinscheduler/plugin/datasource/db2/DB2DataSourceChannel.java @@ -17,15 +17,21 @@ package org.apache.dolphinscheduler.plugin.datasource.db2; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class DB2DataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new DB2DataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new DB2AdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new DB2PooledDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-db2/src/main/java/org/apache/dolphinscheduler/plugin/datasource/db2/DB2PooledDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-db2/src/main/java/org/apache/dolphinscheduler/plugin/datasource/db2/DB2PooledDataSourceClient.java new file mode 100644 index 0000000000..373bc2a373 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-db2/src/main/java/org/apache/dolphinscheduler/plugin/datasource/db2/DB2PooledDataSourceClient.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.db2; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BasePooledDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class DB2PooledDataSourceClient extends BasePooledDataSourceClient { + + public DB2PooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-db2/src/test/java/org/apache/dolphinscheduler/plugin/datasource/db2/DB2DataSourceChannelTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-db2/src/test/java/org/apache/dolphinscheduler/plugin/datasource/db2/DB2DataSourceChannelTest.java index b1a8f1ba39..ce9d24e635 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-db2/src/test/java/org/apache/dolphinscheduler/plugin/datasource/db2/DB2DataSourceChannelTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-db2/src/test/java/org/apache/dolphinscheduler/plugin/datasource/db2/DB2DataSourceChannelTest.java @@ -32,8 +32,9 @@ public class DB2DataSourceChannelTest { @Test public void testCreateDataSourceClient() { DB2DataSourceChannel sourceChannel = Mockito.mock(DB2DataSourceChannel.class); - DB2DataSourceClient dataSourceClient = Mockito.mock(DB2DataSourceClient.class); - Mockito.when(sourceChannel.createDataSourceClient(Mockito.any(), Mockito.any())).thenReturn(dataSourceClient); - Assertions.assertNotNull(sourceChannel.createDataSourceClient(new Db2ConnectionParam(), DbType.DB2)); + DB2PooledDataSourceClient dataSourceClient = Mockito.mock(DB2PooledDataSourceClient.class); + Mockito.when(sourceChannel.createPooledDataSourceClient(Mockito.any(), Mockito.any())) + .thenReturn(dataSourceClient); + Assertions.assertNotNull(sourceChannel.createPooledDataSourceClient(new Db2ConnectionParam(), DbType.DB2)); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/main/java/org/apache/dolphinscheduler/plugin/doris/DorisDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/main/java/org/apache/dolphinscheduler/plugin/doris/DorisAdHocDataSourceClient.java similarity index 84% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/main/java/org/apache/dolphinscheduler/plugin/doris/DorisDataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/main/java/org/apache/dolphinscheduler/plugin/doris/DorisAdHocDataSourceClient.java index ae84cbbb8a..0e44ab449a 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/main/java/org/apache/dolphinscheduler/plugin/doris/DorisDataSourceClient.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/main/java/org/apache/dolphinscheduler/plugin/doris/DorisAdHocDataSourceClient.java @@ -14,15 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.dolphinscheduler.plugin.doris; -import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; -public class DorisDataSourceClient extends CommonDataSourceClient { +public class DorisAdHocDataSourceClient extends BaseAdHocDataSourceClient { - public DorisDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + public DorisAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { super(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/main/java/org/apache/dolphinscheduler/plugin/doris/DorisDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/main/java/org/apache/dolphinscheduler/plugin/doris/DorisDataSourceChannel.java index 33e0a9c501..6ef5978e96 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/main/java/org/apache/dolphinscheduler/plugin/doris/DorisDataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/main/java/org/apache/dolphinscheduler/plugin/doris/DorisDataSourceChannel.java @@ -16,15 +16,21 @@ */ package org.apache.dolphinscheduler.plugin.doris; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class DorisDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return null; + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new DorisAdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new DorisPooledDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/main/java/org/apache/dolphinscheduler/plugin/doris/DorisPooledDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/main/java/org/apache/dolphinscheduler/plugin/doris/DorisPooledDataSourceClient.java new file mode 100644 index 0000000000..8ad3660699 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/main/java/org/apache/dolphinscheduler/plugin/doris/DorisPooledDataSourceClient.java @@ -0,0 +1,28 @@ +/* + * 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.doris; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BasePooledDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class DorisPooledDataSourceClient extends BasePooledDataSourceClient { + + public DorisPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/test/java/org/apache/dolphinscheduler/plugin/doris/DorisDataSourceChannelTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/test/java/org/apache/dolphinscheduler/plugin/doris/DorisDataSourceChannelTest.java index 114dd7aa9d..e719181a10 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/test/java/org/apache/dolphinscheduler/plugin/doris/DorisDataSourceChannelTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/test/java/org/apache/dolphinscheduler/plugin/doris/DorisDataSourceChannelTest.java @@ -32,8 +32,9 @@ public class DorisDataSourceChannelTest { @Test public void testCreateDataSourceClient() { DorisDataSourceChannel sourceChannel = Mockito.mock(DorisDataSourceChannel.class); - DorisDataSourceClient dataSourceClient = Mockito.mock(DorisDataSourceClient.class); - Mockito.when(sourceChannel.createDataSourceClient(Mockito.any(), Mockito.any())).thenReturn(dataSourceClient); - Assertions.assertNotNull(sourceChannel.createDataSourceClient(new DorisConnectionParam(), DbType.DORIS)); + DorisPooledDataSourceClient dataSourceClient = Mockito.mock(DorisPooledDataSourceClient.class); + Mockito.when(sourceChannel.createPooledDataSourceClient(Mockito.any(), Mockito.any())) + .thenReturn(dataSourceClient); + Assertions.assertNotNull(sourceChannel.createPooledDataSourceClient(new DorisConnectionParam(), DbType.DORIS)); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/test/java/org/apache/dolphinscheduler/plugin/doris/provider/JDBCDataSourceProviderTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/test/java/org/apache/dolphinscheduler/plugin/doris/provider/JDBCDataSourceProviderTest.java index d12420a071..e99096d7d0 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/test/java/org/apache/dolphinscheduler/plugin/doris/provider/JDBCDataSourceProviderTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/test/java/org/apache/dolphinscheduler/plugin/doris/provider/JDBCDataSourceProviderTest.java @@ -33,20 +33,6 @@ import com.zaxxer.hikari.HikariDataSource; @ExtendWith(MockitoExtension.class) public class JDBCDataSourceProviderTest { - @Test - public void testCreateJdbcDataSource() { - try ( - MockedStatic mockedJDBCDataSourceProvider = - Mockito.mockStatic(JDBCDataSourceProvider.class)) { - HikariDataSource dataSource = Mockito.mock(HikariDataSource.class); - mockedJDBCDataSourceProvider - .when(() -> JDBCDataSourceProvider.createJdbcDataSource(Mockito.any(), Mockito.any())) - .thenReturn(dataSource); - Assertions.assertNotNull( - JDBCDataSourceProvider.createJdbcDataSource(new DorisConnectionParam(), DbType.DORIS)); - } - } - @Test public void testCreateOneSessionJdbcDataSource() { try ( diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/test/java/org/apache/dolphinscheduler/plugin/doris/utils/DataSourceUtilsTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/test/java/org/apache/dolphinscheduler/plugin/doris/utils/DataSourceUtilsTest.java index 010ea2971f..8ee24ee8f9 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/test/java/org/apache/dolphinscheduler/plugin/doris/utils/DataSourceUtilsTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/test/java/org/apache/dolphinscheduler/plugin/doris/utils/DataSourceUtilsTest.java @@ -29,6 +29,7 @@ import org.apache.dolphinscheduler.spi.datasource.ConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; import java.sql.Connection; +import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -92,22 +93,20 @@ public class DataSourceUtilsTest { } @Test - public void testGetConnection() throws ExecutionException { + public void testGetConnection() throws ExecutionException, SQLException { try ( MockedStatic mockedStaticPropertyUtils = Mockito.mockStatic(PropertyUtils.class); MockedStatic mockedStaticDataSourceClientProvider = Mockito.mockStatic(DataSourceClientProvider.class)) { - mockedStaticPropertyUtils.when(() -> PropertyUtils.getLong("kerberos.expire.time", 24L)).thenReturn(24L); - DataSourceClientProvider clientProvider = Mockito.mock(DataSourceClientProvider.class); - mockedStaticDataSourceClientProvider.when(DataSourceClientProvider::getInstance).thenReturn(clientProvider); Connection connection = Mockito.mock(Connection.class); - Mockito.when(clientProvider.getConnection(Mockito.any(), Mockito.any())).thenReturn(connection); + Mockito.when(DataSourceClientProvider.getAdHocConnection(Mockito.any(), Mockito.any())) + .thenReturn(connection); DorisConnectionParam connectionParam = new DorisConnectionParam(); connectionParam.setUser("root"); connectionParam.setPassword("123456"); - connection = DataSourceClientProvider.getInstance().getConnection(DbType.DORIS, connectionParam); + connection = DataSourceClientProvider.getAdHocConnection(DbType.DORIS, connectionParam); Assertions.assertNotNull(connection); } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hive/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hive/HiveAdHocDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hive/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hive/HiveAdHocDataSourceClient.java new file mode 100644 index 0000000000..644c429e75 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hive/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hive/HiveAdHocDataSourceClient.java @@ -0,0 +1,29 @@ +/* + * 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.hive; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class HiveAdHocDataSourceClient extends BaseAdHocDataSourceClient { + + public HiveAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hive/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hive/HiveDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hive/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hive/HiveDataSourceChannel.java index fbacbfbf01..cf13c61722 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hive/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hive/HiveDataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hive/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hive/HiveDataSourceChannel.java @@ -17,15 +17,21 @@ package org.apache.dolphinscheduler.plugin.datasource.hive; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class HiveDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new HiveDataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new HiveAdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new HivePooledDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hive/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hive/HiveDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hive/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hive/HivePooledDataSourceClient.java similarity index 72% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hive/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hive/HiveDataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hive/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hive/HivePooledDataSourceClient.java index 15270f60a3..f1d2ec0121 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hive/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hive/HiveDataSourceClient.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hive/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hive/HivePooledDataSourceClient.java @@ -22,8 +22,7 @@ import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.JAVA_SEC import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.JAVA_SECURITY_KRB5_CONF_PATH; import org.apache.dolphinscheduler.common.utils.PropertyUtils; -import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; -import org.apache.dolphinscheduler.plugin.datasource.api.provider.JDBCDataSourceProvider; +import org.apache.dolphinscheduler.plugin.datasource.api.client.BasePooledDataSourceClient; import org.apache.dolphinscheduler.plugin.datasource.hive.security.UserGroupInformationFactory; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; @@ -38,37 +37,22 @@ import java.sql.SQLException; import lombok.extern.slf4j.Slf4j; -import org.springframework.jdbc.core.JdbcTemplate; +import com.zaxxer.hikari.HikariDataSource; @Slf4j -public class HiveDataSourceClient extends CommonDataSourceClient { +public class HivePooledDataSourceClient extends BasePooledDataSourceClient { - public HiveDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + public HivePooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { super(baseConnectionParam, dbType); } - @Override - protected void preInit() { - log.info("PreInit in {}", getClass().getName()); - } - - @Override - protected void initClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - log.info("Create UserGroupInformation."); - UserGroupInformationFactory.login(baseConnectionParam.getUser()); - log.info("Create ugi success."); - - this.dataSource = JDBCDataSourceProvider.createOneSessionJdbcDataSource(baseConnectionParam, dbType); - this.jdbcTemplate = new JdbcTemplate(dataSource); - log.info("Init {} success.", getClass().getName()); - } - - @Override - protected void checkEnv(BaseConnectionParam baseConnectionParam) { - super.checkEnv(baseConnectionParam); + public HikariDataSource createDataSourcePool(BaseConnectionParam baseConnectionParam, DbType dbType) { checkKerberosEnv(); + UserGroupInformationFactory.login(baseConnectionParam.getUser()); + return super.createDataSourcePool(baseConnectionParam, dbType); } + // used in constructor private void checkKerberosEnv() { String krb5File = PropertyUtils.getString(JAVA_SECURITY_KRB5_CONF_PATH); Boolean kerberosStartupState = PropertyUtils.getBoolean(HADOOP_SECURITY_AUTHENTICATION_STARTUP_STATE, false); @@ -87,17 +71,16 @@ public class HiveDataSourceClient extends CommonDataSourceClient { } @Override - public Connection getConnection() { - Connection connection = null; - while (connection == null) { - try { - connection = dataSource.getConnection(); - } catch (SQLException e) { + public Connection getConnection() throws SQLException { + try { + return dataSource.getConnection(); + } catch (SQLException e) { + synchronized (HikariDataSource.class) { UserGroupInformationFactory.logout(baseConnectionParam.getUser()); UserGroupInformationFactory.login(baseConnectionParam.getUser()); + return dataSource.getConnection(); } } - return connection; } @Override diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hive/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hive/HiveDataSourceChannelTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hive/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hive/HiveDataSourceChannelTest.java index 402f29a03e..15e237b05f 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hive/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hive/HiveDataSourceChannelTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hive/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hive/HiveDataSourceChannelTest.java @@ -32,8 +32,9 @@ public class HiveDataSourceChannelTest { @Test public void testCreateDataSourceClient() { HiveDataSourceChannel sourceChannel = Mockito.mock(HiveDataSourceChannel.class); - HiveDataSourceClient dataSourceClient = Mockito.mock(HiveDataSourceClient.class); - Mockito.when(sourceChannel.createDataSourceClient(Mockito.any(), Mockito.any())).thenReturn(dataSourceClient); - Assertions.assertNotNull(sourceChannel.createDataSourceClient(new HiveConnectionParam(), DbType.HIVE)); + HivePooledDataSourceClient dataSourceClient = Mockito.mock(HivePooledDataSourceClient.class); + Mockito.when(sourceChannel.createPooledDataSourceClient(Mockito.any(), Mockito.any())) + .thenReturn(dataSourceClient); + Assertions.assertNotNull(sourceChannel.createPooledDataSourceClient(new HiveConnectionParam(), DbType.HIVE)); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/main/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiAdHocDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/main/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiAdHocDataSourceClient.java new file mode 100644 index 0000000000..d9e4c02842 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/main/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiAdHocDataSourceClient.java @@ -0,0 +1,29 @@ +/* + * 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.kyuubi; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class KyuubiAdHocDataSourceClient extends BaseAdHocDataSourceClient { + + public KyuubiAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/main/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/main/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiDataSourceChannel.java index 28c85c8a2c..89fae447e2 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/main/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiDataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/main/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiDataSourceChannel.java @@ -17,15 +17,21 @@ package org.apache.dolphinscheduler.plugin.datasource.kyuubi; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class KyuubiDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new KyuubiDataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new KyuubiAdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new KyuubiPooledDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/main/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/main/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiDataSourceClient.java deleted file mode 100644 index 3e0af69577..0000000000 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/main/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiDataSourceClient.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.kyuubi; - -import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; -import org.apache.dolphinscheduler.plugin.datasource.api.provider.JDBCDataSourceProvider; -import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; -import org.apache.dolphinscheduler.spi.enums.DbType; - -import java.sql.Connection; -import java.sql.SQLException; - -import lombok.extern.slf4j.Slf4j; - -import org.springframework.jdbc.core.JdbcTemplate; - -@Slf4j -public class KyuubiDataSourceClient extends CommonDataSourceClient { - - public KyuubiDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - super(baseConnectionParam, dbType); - } - - @Override - protected void preInit() { - log.info("PreInit in {}", getClass().getName()); - } - - @Override - protected void initClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - - this.dataSource = JDBCDataSourceProvider.createOneSessionJdbcDataSource(baseConnectionParam, dbType); - this.jdbcTemplate = new JdbcTemplate(dataSource); - log.info("Init {} success.", getClass().getName()); - } - - @Override - protected void checkEnv(BaseConnectionParam baseConnectionParam) { - super.checkEnv(baseConnectionParam); - } - - @Override - public Connection getConnection() { - Connection connection = null; - while (connection == null) { - try { - connection = dataSource.getConnection(); - } catch (SQLException e) { - log.error("Failed to get Kyuubi Connection.", e); - } - } - return connection; - } - - @Override - public void close() { - super.close(); - log.info("Closed Kyuubi datasource client."); - } -} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oracle/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oracle/OracleDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/main/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiPooledDataSourceClient.java similarity index 64% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oracle/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oracle/OracleDataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/main/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiPooledDataSourceClient.java index 0df61e00cb..1997bf2945 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oracle/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oracle/OracleDataSourceClient.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/main/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiPooledDataSourceClient.java @@ -15,22 +15,32 @@ * limitations under the License. */ -package org.apache.dolphinscheduler.plugin.datasource.oracle; +package org.apache.dolphinscheduler.plugin.datasource.kyuubi; -import org.apache.dolphinscheduler.common.constants.DataSourceConstants; -import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; +import org.apache.dolphinscheduler.plugin.datasource.api.client.BasePooledDataSourceClient; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; -public class OracleDataSourceClient extends CommonDataSourceClient { +import java.sql.Connection; +import java.sql.SQLException; - public OracleDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class KyuubiPooledDataSourceClient extends BasePooledDataSourceClient { + + public KyuubiPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { super(baseConnectionParam, dbType); } @Override - protected void setDefaultValidationQuery(BaseConnectionParam baseConnectionParam) { - baseConnectionParam.setValidationQuery(DataSourceConstants.ORACLE_VALIDATION_QUERY); + public Connection getConnection() throws SQLException { + return dataSource.getConnection(); } + @Override + public void close() { + super.close(); + log.info("Closed Kyuubi datasource client."); + } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/main/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/param/KyuubiDataSourceProcessor.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/main/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/param/KyuubiDataSourceProcessor.java index 37fa9ab929..760153d718 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/main/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/param/KyuubiDataSourceProcessor.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/main/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/param/KyuubiDataSourceProcessor.java @@ -121,6 +121,7 @@ public class KyuubiDataSourceProcessor extends AbstractDataSourceProcessor { public Connection getConnection(ConnectionParam connectionParam) throws ClassNotFoundException, SQLException { KyuubiConnectionParam kyuubiConnectionParam = (KyuubiConnectionParam) connectionParam; Class.forName(getDatasourceDriver()); + // todo: return DriverManager.getConnection(getJdbcUrl(connectionParam), kyuubiConnectionParam.getUser(), PasswordUtils.decodePassword(kyuubiConnectionParam.getPassword())); } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/test/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiDataSourceChannelTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/test/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiDataSourceChannelTest.java index 78e3a33d2b..90e486c524 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/test/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiDataSourceChannelTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/test/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiDataSourceChannelTest.java @@ -32,9 +32,10 @@ public class KyuubiDataSourceChannelTest { @Test public void testCreateDataSourceClient() { KyuubiDataSourceChannel sourceChannel = Mockito.mock(KyuubiDataSourceChannel.class); - KyuubiDataSourceClient dataSourceClient = Mockito.mock(KyuubiDataSourceClient.class); - Mockito.when(sourceChannel.createDataSourceClient(Mockito.any(), Mockito.any())).thenReturn(dataSourceClient); + KyuubiPooledDataSourceClient dataSourceClient = Mockito.mock(KyuubiPooledDataSourceClient.class); + Mockito.when(sourceChannel.createPooledDataSourceClient(Mockito.any(), Mockito.any())) + .thenReturn(dataSourceClient); Assertions - .assertNotNull(sourceChannel.createDataSourceClient(new KyuubiConnectionParam(), DbType.KYUUBI)); + .assertNotNull(sourceChannel.createPooledDataSourceClient(new KyuubiConnectionParam(), DbType.KYUUBI)); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/test/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiDataSourceClientTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/test/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiDataSourceClientTest.java deleted file mode 100644 index 041420cc48..0000000000 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/test/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiDataSourceClientTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.kyuubi; - -import org.apache.dolphinscheduler.plugin.datasource.kyuubi.param.KyuubiConnectionParam; -import org.apache.dolphinscheduler.spi.enums.DbType; - -import java.sql.Connection; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; - -@ExtendWith(MockitoExtension.class) -public class KyuubiDataSourceClientTest { - - @Mock - private KyuubiDataSourceClient kyuubiDataSourceClient; - - @Test - public void testPreInit() { - kyuubiDataSourceClient.preInit(); - Mockito.verify(kyuubiDataSourceClient).preInit(); - } - - @Test - public void testCheckEnv() { - - KyuubiConnectionParam kyuubiConnectionParam = new KyuubiConnectionParam(); - kyuubiDataSourceClient.checkEnv(kyuubiConnectionParam); - Mockito.verify(kyuubiDataSourceClient).checkEnv(kyuubiConnectionParam); - } - - @Test - public void testInitClient() { - KyuubiConnectionParam kyuubiConnectionParam = new KyuubiConnectionParam(); - kyuubiDataSourceClient.initClient(kyuubiConnectionParam, DbType.KYUUBI); - Mockito.verify(kyuubiDataSourceClient).initClient(kyuubiConnectionParam, DbType.KYUUBI); - } - - @Test - public void testCheckClient() { - kyuubiDataSourceClient.checkClient(); - Mockito.verify(kyuubiDataSourceClient).checkClient(); - } - - @Test - public void testGetConnection() { - Connection connection = Mockito.mock(Connection.class); - Mockito.when(kyuubiDataSourceClient.getConnection()).thenReturn(connection); - Assertions.assertNotNull(kyuubiDataSourceClient.getConnection()); - - } - -} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/test/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiPooledDataSourceClientTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/test/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiPooledDataSourceClientTest.java new file mode 100644 index 0000000000..438682d835 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/test/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/KyuubiPooledDataSourceClientTest.java @@ -0,0 +1,44 @@ +/* + * 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.kyuubi; + +import java.sql.Connection; +import java.sql.SQLException; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public class KyuubiPooledDataSourceClientTest { + + @Mock + private KyuubiPooledDataSourceClient kyuubiPooledDataSourceClient; + + @Test + public void testGetConnection() throws SQLException { + Connection connection = Mockito.mock(Connection.class); + Mockito.when(kyuubiPooledDataSourceClient.getConnection()).thenReturn(connection); + Assertions.assertNotNull(kyuubiPooledDataSourceClient.getConnection()); + + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/test/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/provider/KyuubiJDBCDataSourceProviderTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/test/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/provider/KyuubiJDBCDataSourceProviderTest.java index 5c135f5004..335eb6a920 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/test/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/provider/KyuubiJDBCDataSourceProviderTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/test/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/provider/KyuubiJDBCDataSourceProviderTest.java @@ -30,20 +30,6 @@ import com.zaxxer.hikari.HikariDataSource; public class KyuubiJDBCDataSourceProviderTest { - @Test - public void testCreateJdbcDataSource() { - try ( - MockedStatic mockedJDBCDataSourceProvider = - Mockito.mockStatic(JDBCDataSourceProvider.class)) { - HikariDataSource dataSource = Mockito.mock(HikariDataSource.class); - mockedJDBCDataSourceProvider - .when(() -> JDBCDataSourceProvider.createJdbcDataSource(Mockito.any(), Mockito.any())) - .thenReturn(dataSource); - Assertions.assertNotNull( - JDBCDataSourceProvider.createJdbcDataSource(new KyuubiConnectionParam(), DbType.KYUUBI)); - } - } - @Test public void testCreateOneSessionJdbcDataSource() { try ( diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/mysql/MySQLDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/mysql/MySQLAdHocDataSourceClient.java similarity index 84% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/mysql/MySQLDataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/mysql/MySQLAdHocDataSourceClient.java index 4e7660caa1..af3daf87b3 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/mysql/MySQLDataSourceClient.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/mysql/MySQLAdHocDataSourceClient.java @@ -17,14 +17,13 @@ package org.apache.dolphinscheduler.plugin.datasource.mysql; -import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; -public class MySQLDataSourceClient extends CommonDataSourceClient { +public class MySQLAdHocDataSourceClient extends BaseAdHocDataSourceClient { - public MySQLDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + public MySQLAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { super(baseConnectionParam, dbType); } - } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/mysql/MySQLDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/mysql/MySQLDataSourceChannel.java index e50896838d..e86e685439 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/mysql/MySQLDataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/mysql/MySQLDataSourceChannel.java @@ -17,15 +17,21 @@ package org.apache.dolphinscheduler.plugin.datasource.mysql; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class MySQLDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new MySQLDataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new MySQLAdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new MySQLPooledDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/mysql/MySQLPooledDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/mysql/MySQLPooledDataSourceClient.java new file mode 100644 index 0000000000..64ef84cb85 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/mysql/MySQLPooledDataSourceClient.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.mysql; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BasePooledDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class MySQLPooledDataSourceClient extends BasePooledDataSourceClient { + + public MySQLPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/mysql/MySQLDataSourceChannelTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/mysql/MySQLDataSourceChannelTest.java index 8cf726406a..377436ee09 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/mysql/MySQLDataSourceChannelTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/mysql/MySQLDataSourceChannelTest.java @@ -32,8 +32,9 @@ public class MySQLDataSourceChannelTest { @Test public void testCreateDataSourceClient() { MySQLDataSourceChannel sourceChannel = Mockito.mock(MySQLDataSourceChannel.class); - MySQLDataSourceClient dataSourceClient = Mockito.mock(MySQLDataSourceClient.class); - Mockito.when(sourceChannel.createDataSourceClient(Mockito.any(), Mockito.any())).thenReturn(dataSourceClient); - Assertions.assertNotNull(sourceChannel.createDataSourceClient(new MySQLConnectionParam(), DbType.MYSQL)); + MySQLPooledDataSourceClient dataSourceClient = Mockito.mock(MySQLPooledDataSourceClient.class); + Mockito.when(sourceChannel.createPooledDataSourceClient(Mockito.any(), Mockito.any())) + .thenReturn(dataSourceClient); + Assertions.assertNotNull(sourceChannel.createPooledDataSourceClient(new MySQLConnectionParam(), DbType.MYSQL)); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/mysql/provider/JDBCDataSourceProviderTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/mysql/provider/JDBCDataSourceProviderTest.java index 10fc9a92cd..a597ff6b13 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/mysql/provider/JDBCDataSourceProviderTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/mysql/provider/JDBCDataSourceProviderTest.java @@ -33,20 +33,6 @@ import com.zaxxer.hikari.HikariDataSource; @ExtendWith(MockitoExtension.class) public class JDBCDataSourceProviderTest { - @Test - public void testCreateJdbcDataSource() { - try ( - MockedStatic mockedJDBCDataSourceProvider = - Mockito.mockStatic(JDBCDataSourceProvider.class)) { - HikariDataSource dataSource = Mockito.mock(HikariDataSource.class); - mockedJDBCDataSourceProvider - .when(() -> JDBCDataSourceProvider.createJdbcDataSource(Mockito.any(), Mockito.any())) - .thenReturn(dataSource); - Assertions.assertNotNull( - JDBCDataSourceProvider.createJdbcDataSource(new MySQLConnectionParam(), DbType.MYSQL)); - } - } - @Test public void testCreateOneSessionJdbcDataSource() { try ( diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/mysql/utils/DataSourceUtilsTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/mysql/utils/DataSourceUtilsTest.java index 07d73782c7..8a065e2e6c 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/mysql/utils/DataSourceUtilsTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/mysql/utils/DataSourceUtilsTest.java @@ -29,6 +29,7 @@ import org.apache.dolphinscheduler.spi.datasource.ConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; import java.sql.Connection; +import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -91,22 +92,20 @@ public class DataSourceUtilsTest { } @Test - public void testGetConnection() throws ExecutionException { + public void testGetConnection() throws ExecutionException, SQLException { try ( MockedStatic mockedStaticPropertyUtils = Mockito.mockStatic(PropertyUtils.class); MockedStatic mockedStaticDataSourceClientProvider = Mockito.mockStatic(DataSourceClientProvider.class)) { mockedStaticPropertyUtils.when(() -> PropertyUtils.getLong("kerberos.expire.time", 24L)).thenReturn(24L); - DataSourceClientProvider clientProvider = Mockito.mock(DataSourceClientProvider.class); - mockedStaticDataSourceClientProvider.when(DataSourceClientProvider::getInstance).thenReturn(clientProvider); Connection connection = Mockito.mock(Connection.class); - Mockito.when(clientProvider.getConnection(Mockito.any(), Mockito.any())).thenReturn(connection); + Mockito.when(DataSourceClientProvider.getAdHocConnection(Mockito.any(), Mockito.any())) + .thenReturn(connection); MySQLConnectionParam connectionParam = new MySQLConnectionParam(); connectionParam.setUser("root"); connectionParam.setPassword("123456"); - connection = DataSourceClientProvider.getInstance().getConnection(DbType.MYSQL, connectionParam); Assertions.assertNotNull(connection); } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oceanbase/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oceanbase/OceanBaseDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oceanbase/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oceanbase/OceanBaseAdHocDataSourceClient.java similarity index 84% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oceanbase/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oceanbase/OceanBaseDataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oceanbase/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oceanbase/OceanBaseAdHocDataSourceClient.java index 4097ae47d2..5454083beb 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oceanbase/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oceanbase/OceanBaseDataSourceClient.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oceanbase/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oceanbase/OceanBaseAdHocDataSourceClient.java @@ -17,13 +17,13 @@ package org.apache.dolphinscheduler.plugin.datasource.oceanbase; -import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; -public class OceanBaseDataSourceClient extends CommonDataSourceClient { +public class OceanBaseAdHocDataSourceClient extends BaseAdHocDataSourceClient { - public OceanBaseDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + public OceanBaseAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { super(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oceanbase/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oceanbase/OceanBaseDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oceanbase/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oceanbase/OceanBaseDataSourceChannel.java index 0dac1d768c..8d37d310f1 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oceanbase/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oceanbase/OceanBaseDataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oceanbase/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oceanbase/OceanBaseDataSourceChannel.java @@ -17,15 +17,21 @@ package org.apache.dolphinscheduler.plugin.datasource.oceanbase; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class OceanBaseDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new OceanBaseDataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new OceanBaseAdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new OceanBasePooledDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oceanbase/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oceanbase/OceanBasePooledDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oceanbase/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oceanbase/OceanBasePooledDataSourceClient.java new file mode 100644 index 0000000000..ed6975a617 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oceanbase/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oceanbase/OceanBasePooledDataSourceClient.java @@ -0,0 +1,29 @@ +/* + * 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.oceanbase; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BasePooledDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class OceanBasePooledDataSourceClient extends BasePooledDataSourceClient { + + public OceanBasePooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oracle/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oracle/OracleAdHocDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oracle/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oracle/OracleAdHocDataSourceClient.java new file mode 100644 index 0000000000..fae5c67897 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oracle/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oracle/OracleAdHocDataSourceClient.java @@ -0,0 +1,29 @@ +/* + * 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.oracle; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class OracleAdHocDataSourceClient extends BaseAdHocDataSourceClient { + + public OracleAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oracle/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oracle/OracleDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oracle/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oracle/OracleDataSourceChannel.java index 65584b0f9c..4f0d2ca999 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oracle/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oracle/OracleDataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oracle/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oracle/OracleDataSourceChannel.java @@ -17,15 +17,21 @@ package org.apache.dolphinscheduler.plugin.datasource.oracle; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class OracleDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new OracleDataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new OracleAdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new OraclePooledDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oracle/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oracle/OraclePooledDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oracle/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oracle/OraclePooledDataSourceClient.java new file mode 100644 index 0000000000..2bd77e5a2a --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oracle/src/main/java/org/apache/dolphinscheduler/plugin/datasource/oracle/OraclePooledDataSourceClient.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.oracle; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BasePooledDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class OraclePooledDataSourceClient extends BasePooledDataSourceClient { + + public OraclePooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oracle/src/test/java/org/apache/dolphinscheduler/plugin/datasource/oracle/OracleDataSourceChannelTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oracle/src/test/java/org/apache/dolphinscheduler/plugin/datasource/oracle/OracleDataSourceChannelTest.java index c3b83af92c..d6f418f01d 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oracle/src/test/java/org/apache/dolphinscheduler/plugin/datasource/oracle/OracleDataSourceChannelTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-oracle/src/test/java/org/apache/dolphinscheduler/plugin/datasource/oracle/OracleDataSourceChannelTest.java @@ -32,8 +32,10 @@ public class OracleDataSourceChannelTest { @Test public void testCreateDataSourceClient() { OracleDataSourceChannel sourceChannel = Mockito.mock(OracleDataSourceChannel.class); - OracleDataSourceClient dataSourceClient = Mockito.mock(OracleDataSourceClient.class); - Mockito.when(sourceChannel.createDataSourceClient(Mockito.any(), Mockito.any())).thenReturn(dataSourceClient); - Assertions.assertNotNull(sourceChannel.createDataSourceClient(new OracleConnectionParam(), DbType.ORACLE)); + OraclePooledDataSourceClient dataSourceClient = Mockito.mock(OraclePooledDataSourceClient.class); + Mockito.when(sourceChannel.createPooledDataSourceClient(Mockito.any(), Mockito.any())) + .thenReturn(dataSourceClient); + Assertions + .assertNotNull(sourceChannel.createPooledDataSourceClient(new OracleConnectionParam(), DbType.ORACLE)); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-postgresql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/postgresql/PostgreSQLDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-postgresql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/postgresql/PostgreAdHocSQLDataSourceClient.java similarity index 84% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-postgresql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/postgresql/PostgreSQLDataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-postgresql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/postgresql/PostgreAdHocSQLDataSourceClient.java index c92b255cee..28ed880a4e 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-postgresql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/postgresql/PostgreSQLDataSourceClient.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-postgresql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/postgresql/PostgreAdHocSQLDataSourceClient.java @@ -17,14 +17,13 @@ package org.apache.dolphinscheduler.plugin.datasource.postgresql; -import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; -public class PostgreSQLDataSourceClient extends CommonDataSourceClient { +public class PostgreAdHocSQLDataSourceClient extends BaseAdHocDataSourceClient { - public PostgreSQLDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + public PostgreAdHocSQLDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { super(baseConnectionParam, dbType); } - } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-postgresql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/postgresql/PostgrePooledSQLDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-postgresql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/postgresql/PostgrePooledSQLDataSourceClient.java new file mode 100644 index 0000000000..585098d28a --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-postgresql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/postgresql/PostgrePooledSQLDataSourceClient.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.postgresql; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BasePooledDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class PostgrePooledSQLDataSourceClient extends BasePooledDataSourceClient { + + public PostgrePooledSQLDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-postgresql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/postgresql/PostgreSQLDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-postgresql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/postgresql/PostgreSQLDataSourceChannel.java index 2e2823da8d..8eabc5d3af 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-postgresql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/postgresql/PostgreSQLDataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-postgresql/src/main/java/org/apache/dolphinscheduler/plugin/datasource/postgresql/PostgreSQLDataSourceChannel.java @@ -17,15 +17,21 @@ package org.apache.dolphinscheduler.plugin.datasource.postgresql; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class PostgreSQLDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new PostgreSQLDataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new PostgreAdHocSQLDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new PostgrePooledSQLDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-postgresql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/postgresql/PostgreSQLDataSourceChannelTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-postgresql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/postgresql/PostgreSQLDataSourceChannelTest.java index 1e92203947..71cf02ea91 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-postgresql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/postgresql/PostgreSQLDataSourceChannelTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-postgresql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/postgresql/PostgreSQLDataSourceChannelTest.java @@ -32,9 +32,10 @@ public class PostgreSQLDataSourceChannelTest { @Test public void testCreateDataSourceClient() { PostgreSQLDataSourceChannel sourceChannel = Mockito.mock(PostgreSQLDataSourceChannel.class); - PostgreSQLDataSourceClient dataSourceClient = Mockito.mock(PostgreSQLDataSourceClient.class); - Mockito.when(sourceChannel.createDataSourceClient(Mockito.any(), Mockito.any())).thenReturn(dataSourceClient); + PostgrePooledSQLDataSourceClient dataSourceClient = Mockito.mock(PostgrePooledSQLDataSourceClient.class); + Mockito.when(sourceChannel.createPooledDataSourceClient(Mockito.any(), Mockito.any())) + .thenReturn(dataSourceClient); Assertions.assertNotNull( - sourceChannel.createDataSourceClient(new PostgreSQLConnectionParam(), DbType.POSTGRESQL)); + sourceChannel.createPooledDataSourceClient(new PostgreSQLConnectionParam(), DbType.POSTGRESQL)); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-presto/src/main/java/org/apache/dolphinscheduler/plugin/datasource/presto/PrestoDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-presto/src/main/java/org/apache/dolphinscheduler/plugin/datasource/presto/PrestoAdHocDataSourceClient.java similarity index 84% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-presto/src/main/java/org/apache/dolphinscheduler/plugin/datasource/presto/PrestoDataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-presto/src/main/java/org/apache/dolphinscheduler/plugin/datasource/presto/PrestoAdHocDataSourceClient.java index bb5917150d..39deaab7f0 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-presto/src/main/java/org/apache/dolphinscheduler/plugin/datasource/presto/PrestoDataSourceClient.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-presto/src/main/java/org/apache/dolphinscheduler/plugin/datasource/presto/PrestoAdHocDataSourceClient.java @@ -17,14 +17,13 @@ package org.apache.dolphinscheduler.plugin.datasource.presto; -import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; -public class PrestoDataSourceClient extends CommonDataSourceClient { +public class PrestoAdHocDataSourceClient extends BaseAdHocDataSourceClient { - public PrestoDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + public PrestoAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { super(baseConnectionParam, dbType); } - } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-presto/src/main/java/org/apache/dolphinscheduler/plugin/datasource/presto/PrestoDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-presto/src/main/java/org/apache/dolphinscheduler/plugin/datasource/presto/PrestoDataSourceChannel.java index 1ea69feea8..b09a23f60d 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-presto/src/main/java/org/apache/dolphinscheduler/plugin/datasource/presto/PrestoDataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-presto/src/main/java/org/apache/dolphinscheduler/plugin/datasource/presto/PrestoDataSourceChannel.java @@ -17,15 +17,21 @@ package org.apache.dolphinscheduler.plugin.datasource.presto; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class PrestoDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new PrestoDataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new PrestoAdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new PrestoPooledDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-presto/src/main/java/org/apache/dolphinscheduler/plugin/datasource/presto/PrestoPooledDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-presto/src/main/java/org/apache/dolphinscheduler/plugin/datasource/presto/PrestoPooledDataSourceClient.java new file mode 100644 index 0000000000..c4e92cce3c --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-presto/src/main/java/org/apache/dolphinscheduler/plugin/datasource/presto/PrestoPooledDataSourceClient.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.presto; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BasePooledDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class PrestoPooledDataSourceClient extends BasePooledDataSourceClient { + + public PrestoPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-presto/src/test/java/org/apache/dolphinscheduler/plugin/datasource/presto/PrestoDataSourceChannelTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-presto/src/test/java/org/apache/dolphinscheduler/plugin/datasource/presto/PrestoDataSourceChannelTest.java index 94b08ee9ee..b1ba577ba7 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-presto/src/test/java/org/apache/dolphinscheduler/plugin/datasource/presto/PrestoDataSourceChannelTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-presto/src/test/java/org/apache/dolphinscheduler/plugin/datasource/presto/PrestoDataSourceChannelTest.java @@ -32,8 +32,10 @@ public class PrestoDataSourceChannelTest { @Test public void testCreateDataSourceClient() { PrestoDataSourceChannel sourceChannel = Mockito.mock(PrestoDataSourceChannel.class); - PrestoDataSourceClient dataSourceClient = Mockito.mock(PrestoDataSourceClient.class); - Mockito.when(sourceChannel.createDataSourceClient(Mockito.any(), Mockito.any())).thenReturn(dataSourceClient); - Assertions.assertNotNull(sourceChannel.createDataSourceClient(new PrestoConnectionParam(), DbType.PRESTO)); + PrestoPooledDataSourceClient dataSourceClient = Mockito.mock(PrestoPooledDataSourceClient.class); + Mockito.when(sourceChannel.createPooledDataSourceClient(Mockito.any(), Mockito.any())) + .thenReturn(dataSourceClient); + Assertions + .assertNotNull(sourceChannel.createPooledDataSourceClient(new PrestoConnectionParam(), DbType.PRESTO)); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-redshift/src/main/java/org/apache/dolphinscheduler/plugin/datasource/redshift/RedshiftAdHocDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-redshift/src/main/java/org/apache/dolphinscheduler/plugin/datasource/redshift/RedshiftAdHocDataSourceClient.java new file mode 100644 index 0000000000..7dbea08b82 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-redshift/src/main/java/org/apache/dolphinscheduler/plugin/datasource/redshift/RedshiftAdHocDataSourceClient.java @@ -0,0 +1,29 @@ +/* + * 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.redshift; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class RedshiftAdHocDataSourceClient extends BaseAdHocDataSourceClient { + + public RedshiftAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-redshift/src/main/java/org/apache/dolphinscheduler/plugin/datasource/redshift/RedshiftDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-redshift/src/main/java/org/apache/dolphinscheduler/plugin/datasource/redshift/RedshiftDataSourceChannel.java index 9992f51199..5a35d2e0bf 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-redshift/src/main/java/org/apache/dolphinscheduler/plugin/datasource/redshift/RedshiftDataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-redshift/src/main/java/org/apache/dolphinscheduler/plugin/datasource/redshift/RedshiftDataSourceChannel.java @@ -17,15 +17,21 @@ package org.apache.dolphinscheduler.plugin.datasource.redshift; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class RedshiftDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new RedshiftDataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new RedshiftAdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new RedshiftPooledDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-redshift/src/main/java/org/apache/dolphinscheduler/plugin/datasource/redshift/RedshiftDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-redshift/src/main/java/org/apache/dolphinscheduler/plugin/datasource/redshift/RedshiftPooledDataSourceClient.java similarity index 50% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-redshift/src/main/java/org/apache/dolphinscheduler/plugin/datasource/redshift/RedshiftDataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-redshift/src/main/java/org/apache/dolphinscheduler/plugin/datasource/redshift/RedshiftPooledDataSourceClient.java index 186e5afd19..2119217a47 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-redshift/src/main/java/org/apache/dolphinscheduler/plugin/datasource/redshift/RedshiftDataSourceClient.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-redshift/src/main/java/org/apache/dolphinscheduler/plugin/datasource/redshift/RedshiftPooledDataSourceClient.java @@ -17,7 +17,7 @@ package org.apache.dolphinscheduler.plugin.datasource.redshift; -import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; +import org.apache.dolphinscheduler.plugin.datasource.api.client.BasePooledDataSourceClient; import org.apache.dolphinscheduler.plugin.datasource.redshift.param.RedshiftAuthMode; import org.apache.dolphinscheduler.plugin.datasource.redshift.param.RedshiftConnectionParam; import org.apache.dolphinscheduler.plugin.datasource.redshift.param.RedshiftDataSourceProcessor; @@ -26,22 +26,18 @@ import org.apache.dolphinscheduler.spi.enums.DbType; import java.sql.Connection; import java.sql.SQLException; -import java.sql.Statement; -import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; -import com.google.common.base.Stopwatch; - @Slf4j -public class RedshiftDataSourceClient extends CommonDataSourceClient { +public class RedshiftPooledDataSourceClient extends BasePooledDataSourceClient { - public RedshiftDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + public RedshiftPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { super(baseConnectionParam, dbType); } @Override - public Connection getConnection() { + public Connection getConnection() throws SQLException { RedshiftConnectionParam connectionParam = (RedshiftConnectionParam) this.baseConnectionParam; if (connectionParam.getMode().equals(RedshiftAuthMode.PASSWORD)) { return super.getConnection(); @@ -49,32 +45,4 @@ public class RedshiftDataSourceClient extends CommonDataSourceClient { return RedshiftDataSourceProcessor.getConnectionByIAM(connectionParam); } - @Override - public void checkClient() { - RedshiftConnectionParam connectionParam = (RedshiftConnectionParam) this.baseConnectionParam; - Stopwatch stopwatch = Stopwatch.createStarted(); - String validationQuery = this.baseConnectionParam.getValidationQuery(); - if (connectionParam.getMode().equals(RedshiftAuthMode.PASSWORD)) { - // Checking data source client - try { - this.jdbcTemplate.execute(validationQuery); - } catch (Exception e) { - throw new RuntimeException("JDBC connect failed", e); - } finally { - log.info("Time to execute check jdbc client with sql {} for {} ms ", - this.baseConnectionParam.getValidationQuery(), stopwatch.elapsed(TimeUnit.MILLISECONDS)); - } - } else { - try (Statement statement = getConnection().createStatement()) { - if (!statement.execute(validationQuery)) { - throw new SQLException("execute check redshift access key failed : " + validationQuery); - } - } catch (SQLException e) { - throw new RuntimeException(e); - } finally { - log.info("Time to execute check redshift access key with sql {} for {} ms ", - this.baseConnectionParam.getValidationQuery(), stopwatch.elapsed(TimeUnit.MILLISECONDS)); - } - } - } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/main/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakeDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/main/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakeAdHocDataSourceClient.java similarity index 84% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/main/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakeDataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/main/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakeAdHocDataSourceClient.java index 2649cc0c4d..49d3d0d213 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/main/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakeDataSourceClient.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/main/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakeAdHocDataSourceClient.java @@ -17,14 +17,13 @@ package org.apache.dolphinscheduler.plugin.datasource.snowflake; -import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; -public class SnowflakeDataSourceClient extends CommonDataSourceClient { +public class SnowflakeAdHocDataSourceClient extends BaseAdHocDataSourceClient { - public SnowflakeDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + public SnowflakeAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { super(baseConnectionParam, dbType); } - } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/main/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakeDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/main/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakeDataSourceChannel.java index da21967f4b..5df974946b 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/main/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakeDataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/main/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakeDataSourceChannel.java @@ -17,15 +17,21 @@ package org.apache.dolphinscheduler.plugin.datasource.snowflake; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class SnowflakeDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new SnowflakeDataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new SnowflakeAdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new SnowflakePooledDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/main/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakePooledDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/main/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakePooledDataSourceClient.java new file mode 100644 index 0000000000..fdf78f5b1b --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/main/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakePooledDataSourceClient.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.snowflake; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BasePooledDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class SnowflakePooledDataSourceClient extends BasePooledDataSourceClient { + + public SnowflakePooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/test/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakeDataSourceChannelTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/test/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakeDataSourceChannelTest.java index 42e5f056b2..3e6eb8637d 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/test/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakeDataSourceChannelTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/test/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakeDataSourceChannelTest.java @@ -32,9 +32,11 @@ public class SnowflakeDataSourceChannelTest { @Test public void testCreateDataSourceClient() { SnowflakeDataSourceChannel sourceChannel = Mockito.mock(SnowflakeDataSourceChannel.class); - SnowflakeDataSourceClient dataSourceClient = Mockito.mock(SnowflakeDataSourceClient.class); - Mockito.when(sourceChannel.createDataSourceClient(Mockito.any(), Mockito.any())).thenReturn(dataSourceClient); + SnowflakePooledDataSourceClient dataSourceClient = Mockito.mock(SnowflakePooledDataSourceClient.class); + Mockito.when(sourceChannel.createPooledDataSourceClient(Mockito.any(), Mockito.any())) + .thenReturn(dataSourceClient); Assertions - .assertNotNull(sourceChannel.createDataSourceClient(new SnowflakeConnectionParam(), DbType.SNOWFLAKE)); + .assertNotNull( + sourceChannel.createPooledDataSourceClient(new SnowflakeConnectionParam(), DbType.SNOWFLAKE)); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/test/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakeDataSourceClientTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/test/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakePooledDataSourceClientTest.java similarity index 72% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/test/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakeDataSourceClientTest.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/test/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakePooledDataSourceClientTest.java index b7da5385f9..edc2b468aa 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/test/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakeDataSourceClientTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/test/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/SnowflakePooledDataSourceClientTest.java @@ -18,6 +18,7 @@ package org.apache.dolphinscheduler.plugin.datasource.snowflake; import java.sql.Connection; +import java.sql.SQLException; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -27,22 +28,16 @@ import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -public class SnowflakeDataSourceClientTest { +public class SnowflakePooledDataSourceClientTest { @Mock - private SnowflakeDataSourceClient snowflakeDataSourceClient; + private SnowflakePooledDataSourceClient snowflakePooledDataSourceClient; @Test - public void testCheckClient() { - snowflakeDataSourceClient.checkClient(); - Mockito.verify(snowflakeDataSourceClient).checkClient(); - } - - @Test - public void testGetConnection() { + public void testGetConnection() throws SQLException { Connection connection = Mockito.mock(Connection.class); - Mockito.when(snowflakeDataSourceClient.getConnection()).thenReturn(connection); - Assertions.assertNotNull(snowflakeDataSourceClient.getConnection()); + Mockito.when(snowflakePooledDataSourceClient.getConnection()).thenReturn(connection); + Assertions.assertNotNull(snowflakePooledDataSourceClient.getConnection()); } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/test/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/provider/SnowflakeJDBCDataSourceProviderTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/test/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/provider/SnowflakeJDBCDataSourceProviderTest.java index 69dc1c0f56..2b3dffb7b2 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/test/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/provider/SnowflakeJDBCDataSourceProviderTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/test/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/provider/SnowflakeJDBCDataSourceProviderTest.java @@ -33,20 +33,6 @@ import com.zaxxer.hikari.HikariDataSource; @ExtendWith(MockitoExtension.class) public class SnowflakeJDBCDataSourceProviderTest { - @Test - public void testCreateJdbcDataSource() { - try ( - MockedStatic mockedJDBCDataSourceProvider = - Mockito.mockStatic(JDBCDataSourceProvider.class)) { - HikariDataSource dataSource = Mockito.mock(HikariDataSource.class); - mockedJDBCDataSourceProvider - .when(() -> JDBCDataSourceProvider.createJdbcDataSource(Mockito.any(), Mockito.any())) - .thenReturn(dataSource); - Assertions.assertNotNull( - JDBCDataSourceProvider.createJdbcDataSource(new SnowflakeConnectionParam(), DbType.SNOWFLAKE)); - } - } - @Test public void testCreateOneSessionJdbcDataSource() { try ( diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-spark/src/main/java/org/apache/dolphinscheduler/plugin/datasource/spark/SparkAdHocDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-spark/src/main/java/org/apache/dolphinscheduler/plugin/datasource/spark/SparkAdHocDataSourceClient.java new file mode 100644 index 0000000000..3c030c619c --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-spark/src/main/java/org/apache/dolphinscheduler/plugin/datasource/spark/SparkAdHocDataSourceClient.java @@ -0,0 +1,29 @@ +/* + * 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.spark; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class SparkAdHocDataSourceClient extends BaseAdHocDataSourceClient { + + public SparkAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-spark/src/main/java/org/apache/dolphinscheduler/plugin/datasource/spark/SparkDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-spark/src/main/java/org/apache/dolphinscheduler/plugin/datasource/spark/SparkDataSourceChannel.java index d24e0d137e..2337114dd1 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-spark/src/main/java/org/apache/dolphinscheduler/plugin/datasource/spark/SparkDataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-spark/src/main/java/org/apache/dolphinscheduler/plugin/datasource/spark/SparkDataSourceChannel.java @@ -17,15 +17,21 @@ package org.apache.dolphinscheduler.plugin.datasource.spark; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class SparkDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new SparkDataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new SparkAdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new SparkPooledDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-spark/src/main/java/org/apache/dolphinscheduler/plugin/datasource/spark/SparkDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-spark/src/main/java/org/apache/dolphinscheduler/plugin/datasource/spark/SparkPooledDataSourceClient.java similarity index 79% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-spark/src/main/java/org/apache/dolphinscheduler/plugin/datasource/spark/SparkDataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-spark/src/main/java/org/apache/dolphinscheduler/plugin/datasource/spark/SparkPooledDataSourceClient.java index 8354dfa392..6c4233880e 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-spark/src/main/java/org/apache/dolphinscheduler/plugin/datasource/spark/SparkDataSourceClient.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-spark/src/main/java/org/apache/dolphinscheduler/plugin/datasource/spark/SparkPooledDataSourceClient.java @@ -17,13 +17,13 @@ package org.apache.dolphinscheduler.plugin.datasource.spark; -import org.apache.dolphinscheduler.plugin.datasource.hive.HiveDataSourceClient; +import org.apache.dolphinscheduler.plugin.datasource.hive.HivePooledDataSourceClient; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; -public class SparkDataSourceClient extends HiveDataSourceClient { +public class SparkPooledDataSourceClient extends HivePooledDataSourceClient { - public SparkDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + public SparkPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { super(baseConnectionParam, dbType); } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-spark/src/test/java/org/apache/dolphinscheduler/plugin/datasource/spark/SparkDataSourceChannelTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-spark/src/test/java/org/apache/dolphinscheduler/plugin/datasource/spark/SparkDataSourceChannelTest.java index 99f3a91255..33111a3952 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-spark/src/test/java/org/apache/dolphinscheduler/plugin/datasource/spark/SparkDataSourceChannelTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-spark/src/test/java/org/apache/dolphinscheduler/plugin/datasource/spark/SparkDataSourceChannelTest.java @@ -32,8 +32,9 @@ public class SparkDataSourceChannelTest { @Test public void testCreateDataSourceClient() { SparkDataSourceChannel sourceChannel = Mockito.mock(SparkDataSourceChannel.class); - SparkDataSourceClient dataSourceClient = Mockito.mock(SparkDataSourceClient.class); - Mockito.when(sourceChannel.createDataSourceClient(Mockito.any(), Mockito.any())).thenReturn(dataSourceClient); - Assertions.assertNotNull(sourceChannel.createDataSourceClient(new SparkConnectionParam(), DbType.SPARK)); + SparkPooledDataSourceClient dataSourceClient = Mockito.mock(SparkPooledDataSourceClient.class); + Mockito.when(sourceChannel.createPooledDataSourceClient(Mockito.any(), Mockito.any())) + .thenReturn(dataSourceClient); + Assertions.assertNotNull(sourceChannel.createPooledDataSourceClient(new SparkConnectionParam(), DbType.SPARK)); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-sqlserver/src/main/java/org/apache/dolphinscheduler/plugin/datasource/sqlserver/SQLServerDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-sqlserver/src/main/java/org/apache/dolphinscheduler/plugin/datasource/sqlserver/SQLServerAdHocDataSourceClient.java similarity index 84% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-sqlserver/src/main/java/org/apache/dolphinscheduler/plugin/datasource/sqlserver/SQLServerDataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-sqlserver/src/main/java/org/apache/dolphinscheduler/plugin/datasource/sqlserver/SQLServerAdHocDataSourceClient.java index 4857e0fe11..4912e298cb 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-sqlserver/src/main/java/org/apache/dolphinscheduler/plugin/datasource/sqlserver/SQLServerDataSourceClient.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-sqlserver/src/main/java/org/apache/dolphinscheduler/plugin/datasource/sqlserver/SQLServerAdHocDataSourceClient.java @@ -17,14 +17,13 @@ package org.apache.dolphinscheduler.plugin.datasource.sqlserver; -import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; -public class SQLServerDataSourceClient extends CommonDataSourceClient { +public class SQLServerAdHocDataSourceClient extends BaseAdHocDataSourceClient { - public SQLServerDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + public SQLServerAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { super(baseConnectionParam, dbType); } - } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-sqlserver/src/main/java/org/apache/dolphinscheduler/plugin/datasource/sqlserver/SQLServerDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-sqlserver/src/main/java/org/apache/dolphinscheduler/plugin/datasource/sqlserver/SQLServerDataSourceChannel.java index 7141f9fb3b..1fc2757a21 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-sqlserver/src/main/java/org/apache/dolphinscheduler/plugin/datasource/sqlserver/SQLServerDataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-sqlserver/src/main/java/org/apache/dolphinscheduler/plugin/datasource/sqlserver/SQLServerDataSourceChannel.java @@ -17,15 +17,21 @@ package org.apache.dolphinscheduler.plugin.datasource.sqlserver; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class SQLServerDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new SQLServerDataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new SQLServerAdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new SQLServerPooledDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-sqlserver/src/main/java/org/apache/dolphinscheduler/plugin/datasource/sqlserver/SQLServerPooledDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-sqlserver/src/main/java/org/apache/dolphinscheduler/plugin/datasource/sqlserver/SQLServerPooledDataSourceClient.java new file mode 100644 index 0000000000..5f6085c752 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-sqlserver/src/main/java/org/apache/dolphinscheduler/plugin/datasource/sqlserver/SQLServerPooledDataSourceClient.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.sqlserver; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BasePooledDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class SQLServerPooledDataSourceClient extends BasePooledDataSourceClient { + + public SQLServerPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-sqlserver/src/test/java/org/apache/dolphinscheduler/plugin/datasource/sqlserver/SQLServerDataSourceChannelTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-sqlserver/src/test/java/org/apache/dolphinscheduler/plugin/datasource/sqlserver/SQLServerDataSourceChannelTest.java index 4adbf447a6..d3882985a3 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-sqlserver/src/test/java/org/apache/dolphinscheduler/plugin/datasource/sqlserver/SQLServerDataSourceChannelTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-sqlserver/src/test/java/org/apache/dolphinscheduler/plugin/datasource/sqlserver/SQLServerDataSourceChannelTest.java @@ -32,9 +32,11 @@ public class SQLServerDataSourceChannelTest { @Test public void testCreateDataSourceClient() { SQLServerDataSourceChannel sourceChannel = Mockito.mock(SQLServerDataSourceChannel.class); - SQLServerDataSourceClient dataSourceClient = Mockito.mock(SQLServerDataSourceClient.class); - Mockito.when(sourceChannel.createDataSourceClient(Mockito.any(), Mockito.any())).thenReturn(dataSourceClient); + SQLServerPooledDataSourceClient dataSourceClient = Mockito.mock(SQLServerPooledDataSourceClient.class); + Mockito.when(sourceChannel.createPooledDataSourceClient(Mockito.any(), Mockito.any())) + .thenReturn(dataSourceClient); Assertions - .assertNotNull(sourceChannel.createDataSourceClient(new SQLServerConnectionParam(), DbType.SQLSERVER)); + .assertNotNull( + sourceChannel.createPooledDataSourceClient(new SQLServerConnectionParam(), DbType.SQLSERVER)); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-ssh/src/main/java/org/apache/dolphinscheduler/plugin/datasource/ssh/SSHDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-ssh/src/main/java/org/apache/dolphinscheduler/plugin/datasource/ssh/SSHDataSourceChannel.java index 73d7228979..f7a26de7fd 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-ssh/src/main/java/org/apache/dolphinscheduler/plugin/datasource/ssh/SSHDataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-ssh/src/main/java/org/apache/dolphinscheduler/plugin/datasource/ssh/SSHDataSourceChannel.java @@ -17,16 +17,21 @@ package org.apache.dolphinscheduler.plugin.datasource.ssh; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class SSHDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new SSHDataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + throw new UnsupportedOperationException("SSH AdHocDataSourceClient is not supported"); } + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + throw new UnsupportedOperationException("SSH PooledDataSourceClient is not supported"); + } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-starrocks/src/main/java/org/apache/dolphinscheduler/plugin/datasource/starrocks/StarRocksDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-starrocks/src/main/java/org/apache/dolphinscheduler/plugin/datasource/starrocks/StarRocksAdHocDataSourceClient.java similarity index 84% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-starrocks/src/main/java/org/apache/dolphinscheduler/plugin/datasource/starrocks/StarRocksDataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-starrocks/src/main/java/org/apache/dolphinscheduler/plugin/datasource/starrocks/StarRocksAdHocDataSourceClient.java index f4786efdf8..eef691f2c4 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-starrocks/src/main/java/org/apache/dolphinscheduler/plugin/datasource/starrocks/StarRocksDataSourceClient.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-starrocks/src/main/java/org/apache/dolphinscheduler/plugin/datasource/starrocks/StarRocksAdHocDataSourceClient.java @@ -17,14 +17,13 @@ package org.apache.dolphinscheduler.plugin.datasource.starrocks; -import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; -public class StarRocksDataSourceClient extends CommonDataSourceClient { +public class StarRocksAdHocDataSourceClient extends BaseAdHocDataSourceClient { - public StarRocksDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + public StarRocksAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { super(baseConnectionParam, dbType); } - } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-starrocks/src/main/java/org/apache/dolphinscheduler/plugin/datasource/starrocks/StarRocksDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-starrocks/src/main/java/org/apache/dolphinscheduler/plugin/datasource/starrocks/StarRocksDataSourceChannel.java index 7975ec752b..b394b4e77b 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-starrocks/src/main/java/org/apache/dolphinscheduler/plugin/datasource/starrocks/StarRocksDataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-starrocks/src/main/java/org/apache/dolphinscheduler/plugin/datasource/starrocks/StarRocksDataSourceChannel.java @@ -17,15 +17,21 @@ package org.apache.dolphinscheduler.plugin.datasource.starrocks; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class StarRocksDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new StarRocksDataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new StarRocksAdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new StarRocksPooledDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-starrocks/src/main/java/org/apache/dolphinscheduler/plugin/datasource/starrocks/StarRocksPooledDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-starrocks/src/main/java/org/apache/dolphinscheduler/plugin/datasource/starrocks/StarRocksPooledDataSourceClient.java new file mode 100644 index 0000000000..bea79db241 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-starrocks/src/main/java/org/apache/dolphinscheduler/plugin/datasource/starrocks/StarRocksPooledDataSourceClient.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.starrocks; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BasePooledDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class StarRocksPooledDataSourceClient extends BasePooledDataSourceClient { + + public StarRocksPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-trino/src/main/java/org/apache/dolphinscheduler/plugin/datasource/trino/TrinoDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-trino/src/main/java/org/apache/dolphinscheduler/plugin/datasource/trino/TrinoAdHocDataSourceClient.java similarity index 84% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-trino/src/main/java/org/apache/dolphinscheduler/plugin/datasource/trino/TrinoDataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-trino/src/main/java/org/apache/dolphinscheduler/plugin/datasource/trino/TrinoAdHocDataSourceClient.java index cfa8f9b3aa..8a01c17f21 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-trino/src/main/java/org/apache/dolphinscheduler/plugin/datasource/trino/TrinoDataSourceClient.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-trino/src/main/java/org/apache/dolphinscheduler/plugin/datasource/trino/TrinoAdHocDataSourceClient.java @@ -17,14 +17,13 @@ package org.apache.dolphinscheduler.plugin.datasource.trino; -import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; -public class TrinoDataSourceClient extends CommonDataSourceClient { +public class TrinoAdHocDataSourceClient extends BaseAdHocDataSourceClient { - public TrinoDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + public TrinoAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { super(baseConnectionParam, dbType); } - } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-trino/src/main/java/org/apache/dolphinscheduler/plugin/datasource/trino/TrinoDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-trino/src/main/java/org/apache/dolphinscheduler/plugin/datasource/trino/TrinoDataSourceChannel.java index 2ca06a89d7..ee8be5f9b5 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-trino/src/main/java/org/apache/dolphinscheduler/plugin/datasource/trino/TrinoDataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-trino/src/main/java/org/apache/dolphinscheduler/plugin/datasource/trino/TrinoDataSourceChannel.java @@ -17,15 +17,21 @@ package org.apache.dolphinscheduler.plugin.datasource.trino; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class TrinoDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new TrinoDataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new TrinoAdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new TrinoPooledDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-trino/src/main/java/org/apache/dolphinscheduler/plugin/datasource/trino/TrinoPooledDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-trino/src/main/java/org/apache/dolphinscheduler/plugin/datasource/trino/TrinoPooledDataSourceClient.java new file mode 100644 index 0000000000..eaaa33d589 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-trino/src/main/java/org/apache/dolphinscheduler/plugin/datasource/trino/TrinoPooledDataSourceClient.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.trino; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BasePooledDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class TrinoPooledDataSourceClient extends BasePooledDataSourceClient { + + public TrinoPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-trino/src/test/java/org/apache/dolphinscheduler/plugin/datasource/trino/TrinoDataSourceChannelTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-trino/src/test/java/org/apache/dolphinscheduler/plugin/datasource/trino/TrinoDataSourceChannelTest.java index 17f4098c52..c34261e36d 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-trino/src/test/java/org/apache/dolphinscheduler/plugin/datasource/trino/TrinoDataSourceChannelTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-trino/src/test/java/org/apache/dolphinscheduler/plugin/datasource/trino/TrinoDataSourceChannelTest.java @@ -37,7 +37,7 @@ public class TrinoDataSourceChannelTest { trinoConnectionParam.setDriverLocation(DataSourceConstants.COM_TRINO_JDBC_DRIVER); trinoConnectionParam.setDriverClassName(DataSourceConstants.COM_TRINO_JDBC_DRIVER); try { - sourceChannel.createDataSourceClient(trinoConnectionParam, DbType.TRINO); + sourceChannel.createPooledDataSourceClient(trinoConnectionParam, DbType.TRINO); } catch (Exception e) { Assertions.assertEquals(RuntimeException.class, e.getClass()); } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/main/java/org/apache/dolphinscheduler/plugin/datasource/vertica/VerticaDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/main/java/org/apache/dolphinscheduler/plugin/datasource/vertica/VerticaAdHocDataSourceClient.java similarity index 84% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/main/java/org/apache/dolphinscheduler/plugin/datasource/vertica/VerticaDataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/main/java/org/apache/dolphinscheduler/plugin/datasource/vertica/VerticaAdHocDataSourceClient.java index 8e71d5cfdd..47a59e5bf6 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/main/java/org/apache/dolphinscheduler/plugin/datasource/vertica/VerticaDataSourceClient.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/main/java/org/apache/dolphinscheduler/plugin/datasource/vertica/VerticaAdHocDataSourceClient.java @@ -17,14 +17,13 @@ package org.apache.dolphinscheduler.plugin.datasource.vertica; -import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; +import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; -public class VerticaDataSourceClient extends CommonDataSourceClient { +public class VerticaAdHocDataSourceClient extends BaseAdHocDataSourceClient { - public VerticaDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + public VerticaAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { super(baseConnectionParam, dbType); } - } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/main/java/org/apache/dolphinscheduler/plugin/datasource/vertica/VerticaDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/main/java/org/apache/dolphinscheduler/plugin/datasource/vertica/VerticaDataSourceChannel.java index 3616be438f..59848762e4 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/main/java/org/apache/dolphinscheduler/plugin/datasource/vertica/VerticaDataSourceChannel.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/main/java/org/apache/dolphinscheduler/plugin/datasource/vertica/VerticaDataSourceChannel.java @@ -17,15 +17,21 @@ package org.apache.dolphinscheduler.plugin.datasource.vertica; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; 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.datasource.PooledDataSourceClient; import org.apache.dolphinscheduler.spi.enums.DbType; public class VerticaDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new VerticaDataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new VerticaAdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new VerticaPooledDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/main/java/org/apache/dolphinscheduler/plugin/datasource/vertica/VerticaPooledDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/main/java/org/apache/dolphinscheduler/plugin/datasource/vertica/VerticaPooledDataSourceClient.java new file mode 100644 index 0000000000..b1fd734905 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/main/java/org/apache/dolphinscheduler/plugin/datasource/vertica/VerticaPooledDataSourceClient.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.vertica; + +import org.apache.dolphinscheduler.plugin.datasource.api.client.BasePooledDataSourceClient; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class VerticaPooledDataSourceClient extends BasePooledDataSourceClient { + + public VerticaPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/test/java/org/apache/dolphinscheduler/plugin/datasource/vertica/VerticaDataSourceChannelTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/test/java/org/apache/dolphinscheduler/plugin/datasource/vertica/VerticaDataSourceChannelTest.java index 49012585e0..6060403998 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/test/java/org/apache/dolphinscheduler/plugin/datasource/vertica/VerticaDataSourceChannelTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/test/java/org/apache/dolphinscheduler/plugin/datasource/vertica/VerticaDataSourceChannelTest.java @@ -32,8 +32,10 @@ public class VerticaDataSourceChannelTest { @Test public void testCreateDataSourceClient() { VerticaDataSourceChannel sourceChannel = Mockito.mock(VerticaDataSourceChannel.class); - VerticaDataSourceClient dataSourceClient = Mockito.mock(VerticaDataSourceClient.class); - Mockito.when(sourceChannel.createDataSourceClient(Mockito.any(), Mockito.any())).thenReturn(dataSourceClient); - Assertions.assertNotNull(sourceChannel.createDataSourceClient(new VerticaConnectionParam(), DbType.VERTICA)); + VerticaPooledDataSourceClient dataSourceClient = Mockito.mock(VerticaPooledDataSourceClient.class); + Mockito.when(sourceChannel.createPooledDataSourceClient(Mockito.any(), Mockito.any())) + .thenReturn(dataSourceClient); + Assertions.assertNotNull( + sourceChannel.createPooledDataSourceClient(new VerticaConnectionParam(), DbType.VERTICA)); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/test/java/org/apache/dolphinscheduler/plugin/datasource/vertica/provider/JDBCDataSourceProviderTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/test/java/org/apache/dolphinscheduler/plugin/datasource/vertica/provider/JDBCDataSourceProviderTest.java index 7dbd75d46b..85b7b8688b 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/test/java/org/apache/dolphinscheduler/plugin/datasource/vertica/provider/JDBCDataSourceProviderTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/test/java/org/apache/dolphinscheduler/plugin/datasource/vertica/provider/JDBCDataSourceProviderTest.java @@ -33,20 +33,6 @@ import com.zaxxer.hikari.HikariDataSource; @ExtendWith(MockitoExtension.class) public class JDBCDataSourceProviderTest { - @Test - public void testCreateJdbcDataSource() { - try ( - MockedStatic mockedJDBCDataSourceProvider = - Mockito.mockStatic(JDBCDataSourceProvider.class)) { - HikariDataSource dataSource = Mockito.mock(HikariDataSource.class); - mockedJDBCDataSourceProvider - .when(() -> JDBCDataSourceProvider.createJdbcDataSource(Mockito.any(), Mockito.any())) - .thenReturn(dataSource); - Assertions.assertNotNull( - JDBCDataSourceProvider.createJdbcDataSource(new VerticaConnectionParam(), DbType.VERTICA)); - } - } - @Test public void testCreateOneSessionJdbcDataSource() { try ( diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/test/java/org/apache/dolphinscheduler/plugin/datasource/vertica/utils/DataSourceUtilsTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/test/java/org/apache/dolphinscheduler/plugin/datasource/vertica/utils/DataSourceUtilsTest.java index 1c10d2b726..bd75000e65 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/test/java/org/apache/dolphinscheduler/plugin/datasource/vertica/utils/DataSourceUtilsTest.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/test/java/org/apache/dolphinscheduler/plugin/datasource/vertica/utils/DataSourceUtilsTest.java @@ -29,6 +29,7 @@ import org.apache.dolphinscheduler.spi.datasource.ConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; import java.sql.Connection; +import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -91,22 +92,21 @@ public class DataSourceUtilsTest { } @Test - public void testGetConnection() throws ExecutionException { + public void testGetConnection() throws ExecutionException, SQLException { try ( MockedStatic mockedStaticPropertyUtils = Mockito.mockStatic(PropertyUtils.class); MockedStatic mockedStaticDataSourceClientProvider = Mockito.mockStatic(DataSourceClientProvider.class)) { mockedStaticPropertyUtils.when(() -> PropertyUtils.getLong("kerberos.expire.time", 24L)).thenReturn(24L); - DataSourceClientProvider clientProvider = Mockito.mock(DataSourceClientProvider.class); - mockedStaticDataSourceClientProvider.when(DataSourceClientProvider::getInstance).thenReturn(clientProvider); Connection connection = Mockito.mock(Connection.class); - Mockito.when(clientProvider.getConnection(Mockito.any(), Mockito.any())).thenReturn(connection); + Mockito.when(DataSourceClientProvider.getAdHocConnection(Mockito.any(), Mockito.any())) + .thenReturn(connection); VerticaConnectionParam connectionParam = new VerticaConnectionParam(); connectionParam.setUser("root"); connectionParam.setPassword("123456"); - connection = DataSourceClientProvider.getInstance().getConnection(DbType.VERTICA, connectionParam); + connection = DataSourceClientProvider.getAdHocConnection(DbType.VERTICA, connectionParam); Assertions.assertNotNull(connection); } diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/datasource/AdHocDataSourceClient.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/datasource/AdHocDataSourceClient.java new file mode 100644 index 0000000000..8aa5fa8c16 --- /dev/null +++ b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/datasource/AdHocDataSourceClient.java @@ -0,0 +1,25 @@ +/* + * 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.spi.datasource; + +/** + * This is a marker interface for pooled data source client, the connection generated from this client should not be pooled. + */ +public interface AdHocDataSourceClient extends DataSourceClient { + +} diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/datasource/DataSourceChannel.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/datasource/DataSourceChannel.java index 98b67352f7..bd99b15759 100644 --- a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/datasource/DataSourceChannel.java +++ b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/datasource/DataSourceChannel.java @@ -21,5 +21,13 @@ import org.apache.dolphinscheduler.spi.enums.DbType; public interface DataSourceChannel { - DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType); + /** + * Create a AdHocDataSourceClient, this client should not be pooled. + */ + AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType); + + /** + * Create a PooledDataSourceClient, this client should be pooled. + */ + PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType); } diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/datasource/DataSourceClient.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/datasource/DataSourceClient.java index 82eb1f02cb..e93725735f 100644 --- a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/datasource/DataSourceClient.java +++ b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/datasource/DataSourceClient.java @@ -18,13 +18,13 @@ package org.apache.dolphinscheduler.spi.datasource; import java.sql.Connection; +import java.sql.SQLException; +/** + * Interface used to get connection of a data source. + */ public interface DataSourceClient extends AutoCloseable { - void checkClient(); - - @Override - void close(); + Connection getConnection() throws SQLException; - Connection getConnection(); } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-ssh/src/main/java/org/apache/dolphinscheduler/plugin/datasource/ssh/SSHDataSourceClient.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/datasource/PooledDataSourceClient.java similarity index 67% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-ssh/src/main/java/org/apache/dolphinscheduler/plugin/datasource/ssh/SSHDataSourceClient.java rename to dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/datasource/PooledDataSourceClient.java index fd9ce7d646..d14918b02e 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-ssh/src/main/java/org/apache/dolphinscheduler/plugin/datasource/ssh/SSHDataSourceClient.java +++ b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/datasource/PooledDataSourceClient.java @@ -15,16 +15,17 @@ * limitations under the License. */ -package org.apache.dolphinscheduler.plugin.datasource.ssh; +package org.apache.dolphinscheduler.spi.datasource; -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 SSHDataSourceClient extends CommonDataSourceClient { +import javax.sql.DataSource; - public SSHDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - super(baseConnectionParam, dbType); - } +/** + * This is a marker interface for pooled data source client, which means the connection is pooled. + */ +public interface PooledDataSourceClient extends DataSourceClient { + + DataSource createDataSourcePool(BaseConnectionParam baseConnectionParam, DbType dbType); } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/main/java/org/apache/dolphinscheduler/plugin/task/datax/DataxTask.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/main/java/org/apache/dolphinscheduler/plugin/task/datax/DataxTask.java index fc553ebfe6..9b55f00fc9 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/main/java/org/apache/dolphinscheduler/plugin/task/datax/DataxTask.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/main/java/org/apache/dolphinscheduler/plugin/task/datax/DataxTask.java @@ -520,7 +520,7 @@ public class DataxTask extends AbstractTask { try ( Connection connection = - DataSourceClientProvider.getInstance().getConnection(sourceType, baseDataSource); + DataSourceClientProvider.getAdHocConnection(sourceType, baseDataSource); PreparedStatement stmt = connection.prepareStatement(sql); ResultSet resultSet = stmt.executeQuery()) { diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/test/java/org/apache/dolphinscheduler/plugin/task/datax/DataxTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/test/java/org/apache/dolphinscheduler/plugin/task/datax/DataxTaskTest.java index 933e47f451..fbd5c59aa7 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/test/java/org/apache/dolphinscheduler/plugin/task/datax/DataxTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/test/java/org/apache/dolphinscheduler/plugin/task/datax/DataxTaskTest.java @@ -204,12 +204,9 @@ public class DataxTaskTest { try ( MockedStatic mockedStaticDataSourceClientProvider = mockStatic(DataSourceClientProvider.class)) { - DataSourceClientProvider clientProvider = mock(DataSourceClientProvider.class); - when(DataSourceClientProvider.getInstance()).thenReturn(clientProvider); - mockedStaticDataSourceClientProvider.when(DataSourceClientProvider::getInstance).thenReturn(clientProvider); Connection connection = mock(Connection.class); - when(clientProvider.getConnection(Mockito.any(), Mockito.any())).thenReturn(connection); + when(DataSourceClientProvider.getAdHocConnection(Mockito.any(), Mockito.any())).thenReturn(connection); PreparedStatement stmt = mock(PreparedStatement.class); when(connection.prepareStatement(anyString())).thenReturn(stmt); diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-procedure/src/main/java/org/apache/dolphinscheduler/plugin/task/procedure/ProcedureTask.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-procedure/src/main/java/org/apache/dolphinscheduler/plugin/task/procedure/ProcedureTask.java index cff003d26d..2bdbcd5e23 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-procedure/src/main/java/org/apache/dolphinscheduler/plugin/task/procedure/ProcedureTask.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-procedure/src/main/java/org/apache/dolphinscheduler/plugin/task/procedure/ProcedureTask.java @@ -22,6 +22,7 @@ import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.EXIT_COD import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.plugin.datasource.api.datasource.DataSourceProcessor; +import org.apache.dolphinscheduler.plugin.datasource.api.plugin.DataSourceClientProvider; import org.apache.dolphinscheduler.plugin.datasource.api.plugin.DataSourceProcessorProvider; import org.apache.dolphinscheduler.plugin.task.api.AbstractTask; import org.apache.dolphinscheduler.plugin.task.api.TaskCallBack; @@ -96,11 +97,10 @@ public class ProcedureTask extends AbstractTask { procedureParameters.getLocalParams()); DbType dbType = DbType.valueOf(procedureParameters.getType()); - DataSourceProcessor dataSourceProcessor = - DataSourceProcessorProvider.getInstance().getDataSourceProcessor(dbType); + DataSourceProcessor dataSourceProcessor = DataSourceProcessorProvider.getDataSourceProcessor(dbType); ConnectionParam connectionParams = dataSourceProcessor.createConnectionParams(procedureTaskExecutionContext.getConnectionParams()); - try (Connection connection = dataSourceProcessor.getConnection(connectionParams)) { + try (Connection connection = DataSourceClientProvider.getAdHocConnection(dbType, connectionParams)) { Map sqlParamsMap = new HashMap<>(); Map paramsMap = taskExecutionContext.getPrepareParamsMap() == null ? Maps.newHashMap() : taskExecutionContext.getPrepareParamsMap(); diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java index b8dfde23f3..bc8a4f08f5 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java @@ -223,12 +223,11 @@ public class SqlTask extends AbstractTask { List preStatementsBinds, List postStatementsBinds, List createFuncs) throws Exception { - Connection connection = null; - try { + try ( + Connection connection = + DataSourceClientProvider.getAdHocConnection(DbType.valueOf(sqlParameters.getType()), + baseConnectionParam)) { - // create connection - connection = DataSourceClientProvider.getInstance().getConnection(DbType.valueOf(sqlParameters.getType()), - baseConnectionParam); // create temp function if (CollectionUtils.isNotEmpty(createFuncs)) { createTempFunction(connection, createFuncs); @@ -256,8 +255,6 @@ public class SqlTask extends AbstractTask { } catch (Exception e) { log.error("execute sql error: {}", e.getMessage()); throw e; - } finally { - close(connection); } }