forked from apache/dolphinscheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cherry-pick Use AdHoc datasource client in sqlTask apache#14631
- Loading branch information
1 parent
64b9200
commit 50a6973
Showing
77 changed files
with
1,432 additions
and
1,030 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
431 changes: 207 additions & 224 deletions
431
...uler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataSourceServiceTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...a/org/apache/dolphinscheduler/plugin/datasource/api/client/BaseAdHocDataSourceClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
.../org/apache/dolphinscheduler/plugin/datasource/api/client/BasePooledDataSourceClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
|
||
} |
123 changes: 0 additions & 123 deletions
123
...java/org/apache/dolphinscheduler/plugin/datasource/api/client/CommonDataSourceClient.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.