diff --git a/config/plugins_config b/config/plugins_config index eff859100fe5..38209fe174da 100644 --- a/config/plugins_config +++ b/config/plugins_config @@ -44,6 +44,7 @@ dolphinscheduler-datasource-databend dolphinscheduler-datasource-db2 dolphinscheduler-datasource-doris dolphinscheduler-datasource-hana +dolphinscheduler-datasource-cache dolphinscheduler-datasource-hive dolphinscheduler-datasource-k8s dolphinscheduler-datasource-kyuubi diff --git a/docs/configs/docsdev.js b/docs/configs/docsdev.js index 0fa7adf2612d..52eef492e24d 100644 --- a/docs/configs/docsdev.js +++ b/docs/configs/docsdev.js @@ -355,6 +355,10 @@ export default { title: 'doris', link: '/en-us/docs/dev/user_doc/guide/datasource/doris.html', }, + { + title: 'Caché', + link: '/en-us/docs/dev/user_doc/guide/datasource/cache.html', + }, { title: 'Vertica', link: '/en-us/docs/dev/user_doc/guide/datasource/vertica.html', diff --git a/docs/docs/en/guide/datasource/cache.md b/docs/docs/en/guide/datasource/cache.md new file mode 100644 index 000000000000..7ba4e2d01844 --- /dev/null +++ b/docs/docs/en/guide/datasource/cache.md @@ -0,0 +1,29 @@ +# CACHE + +![cache](../../../../img/new_ui/dev/datasource/cache-en.png) + +## Datasource Parameters + +| **Datasource** | **Description** | +|----------------------------|---------------------------------------------------------------------------------------| +| Datasource | Select CACHE. | +| Datasource name | Enter the name of the DataSource. | +| Description | Enter a description of the DataSource. | +| IP/Host Name | Enter the CACHE service IP.(If there are multiple IPs, please separate them with `,`) | +| Port | Enter the CACHE service port. | +| Username | Set the username for CACHE connection. | +| Password | Set the password for CACHE connection. | +| Database name | Enter the database name of the CACHE connection. | +| Jdbc connection parameters | Parameter settings for CACHE connection, in JSON format. | + +## Native Supported + +Yes, could use this datasource by default. + +## Data Source Information + +> InterSystems Caché® is a high-performance database that powers transaction processing applications around the world. It is used for everything from mapping a billion stars in the Milky Way, to processing a billion equity trades in a day, to managing smart energy grids. + +For more Caché related documentation, please refer to +[Official Website](https://www.intersystems.com/products/cache/) +[Official Documentation](https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=BGJD_coding) diff --git a/docs/docs/zh/guide/datasource/cache.md b/docs/docs/zh/guide/datasource/cache.md new file mode 100644 index 000000000000..9b1b3942bf62 --- /dev/null +++ b/docs/docs/zh/guide/datasource/cache.md @@ -0,0 +1,27 @@ +# CACHE 数据源 + +![CACHE](../../../../img/new_ui/dev/datasource/cache.png) + +- 数据源:选择 CACHE +- 数据源名称:输入数据源的名称 +- 描述:输入数据源的描述 +- IP 主机名:输入连接 CACHE 的 IP(如有多个IP,请用`,`分隔) +- 端口:输入连接 CACHE 的端口 +- 用户名:设置连接 CACHE 的用户名 +- 密码:设置连接 CACHE 的密码 +- 数据库名:输入连接 CACHE 的数据库名称 +- Jdbc 连接参数:用于 CACHE 连接的参数设置,以 JSON 形式填写 + +## 是否原生支持 + +是,数据源不需要任务附加操作即可使用。 + +## 数据源信息 + +> InterSystems Caché® 是一款高性能数据库, +> 为全球交易处理应用程序提供支持。它用于各种用途, +> 从绘制银河系十亿颗恒星的地图,到一天处理十亿笔股票交易,再到管理智能电网。 + +更多的Caché相关文档,请参考 +[官方网站](https://www.intersystems.com/products/cache/) +[官方文档](https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=BGJD_coding) diff --git a/docs/img/new_ui/dev/datasource/cache-en.png b/docs/img/new_ui/dev/datasource/cache-en.png new file mode 100644 index 000000000000..03f102cc53af Binary files /dev/null and b/docs/img/new_ui/dev/datasource/cache-en.png differ diff --git a/docs/img/new_ui/dev/datasource/cache.png b/docs/img/new_ui/dev/datasource/cache.png new file mode 100644 index 000000000000..16710841689c Binary files /dev/null and b/docs/img/new_ui/dev/datasource/cache.png differ diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/constants/DataSourceConstants.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/constants/DataSourceConstants.java index 11347942bde4..f3cc96ad33fd 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/constants/DataSourceConstants.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/constants/DataSourceConstants.java @@ -43,6 +43,7 @@ public class DataSourceConstants { public static final String NET_SNOWFLAKE_JDBC_DRIVER = "net.snowflake.client.jdbc.SnowflakeDriver"; public static final String COM_VERTICA_JDBC_DRIVER = "com.vertica.jdbc.Driver"; public static final String COM_HANA_DB_JDBC_DRIVER = "com.sap.db.jdbc.Driver"; + public static final String COM_INTERSYS_JDBC_CACHE_DRIVER = "com.intersys.jdbc.CacheDriver"; /** * validation Query @@ -66,6 +67,7 @@ public class DataSourceConstants { public static final String VERTICA_VALIDATION_QUERY = "select 1"; public static final String HANA_VALIDATION_QUERY = "select 1 from DUMMY"; + public static final String CACHE_VALIDATION_QUERY = "select 1"; /** * jdbc url @@ -91,6 +93,7 @@ public class DataSourceConstants { public static final String JDBC_SNOWFLAKE = "jdbc:snowflake://"; public static final String JDBC_VERTICA = "jdbc:vertica://"; public static final String JDBC_HANA = "jdbc:sap://"; + public static final String JDBC_CACHE = "jdbc:Cache://"; /** * database type diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-all/pom.xml b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-all/pom.xml index b62a3ce414a9..c5ab260ba376 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-all/pom.xml +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-all/pom.xml @@ -163,5 +163,10 @@ dolphinscheduler-datasource-aliyunserverlessspark ${project.version} + + org.apache.dolphinscheduler + dolphinscheduler-datasource-cache + ${project.version} + diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/pom.xml b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/pom.xml new file mode 100644 index 000000000000..e0b6aa78c118 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/pom.xml @@ -0,0 +1,53 @@ + + + + 4.0.0 + + org.apache.dolphinscheduler + dolphinscheduler-datasource-plugin + dev-SNAPSHOT + + + dolphinscheduler-datasource-cache + jar + ${project.artifactId} + + + + org.apache.dolphinscheduler + dolphinscheduler-spi + ${project.version} + provided + + + + org.apache.dolphinscheduler + dolphinscheduler-datasource-api + ${project.version} + provided + + + org.apache.dolphinscheduler + dolphinscheduler-common + ${project.version} + provided + + + + diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/CacheAdHocDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/CacheAdHocDataSourceClient.java new file mode 100644 index 000000000000..8ecc72fe3b5b --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/CacheAdHocDataSourceClient.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.cache; + +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 CacheAdHocDataSourceClient extends BaseAdHocDataSourceClient { + + public CacheAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/CacheDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/CacheDataSourceChannel.java new file mode 100644 index 000000000000..efbcd1a346eb --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/CacheDataSourceChannel.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.datasource.cache; + +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.PooledDataSourceClient; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class CacheDataSourceChannel implements DataSourceChannel { + + @Override + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new CacheAdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new CachePooledDataSourceClient(baseConnectionParam, dbType); + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/CacheDataSourceChannelFactory.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/CacheDataSourceChannelFactory.java new file mode 100644 index 000000000000..437900e0630c --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/CacheDataSourceChannelFactory.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.datasource.cache; + +import org.apache.dolphinscheduler.spi.datasource.DataSourceChannel; +import org.apache.dolphinscheduler.spi.datasource.DataSourceChannelFactory; + +import com.google.auto.service.AutoService; + +@AutoService(DataSourceChannelFactory.class) +public class CacheDataSourceChannelFactory implements DataSourceChannelFactory { + + @Override + public String getName() { + return "cache"; + } + + @Override + public DataSourceChannel create() { + return new CacheDataSourceChannel(); + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/CachePooledDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/CachePooledDataSourceClient.java new file mode 100644 index 000000000000..d8f938e04f68 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/CachePooledDataSourceClient.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.cache; + +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 CachePooledDataSourceClient extends BasePooledDataSourceClient { + + public CachePooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + super(baseConnectionParam, dbType); + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/param/CacheConnectionParam.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/param/CacheConnectionParam.java new file mode 100644 index 000000000000..49cc31ed6489 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/param/CacheConnectionParam.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.datasource.cache.param; + +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; + +public class CacheConnectionParam extends BaseConnectionParam { + + @Override + public String toString() { + return "CacheConnectionParam{" + + "user='" + user + '\'' + + ", password='" + password + '\'' + + ", address='" + address + '\'' + + ", database='" + database + '\'' + + ", jdbcUrl='" + jdbcUrl + '\'' + + ", driverLocation='" + driverLocation + '\'' + + ", driverClassName='" + driverClassName + '\'' + + ", validationQuery='" + validationQuery + '\'' + + ", other='" + other + '\'' + + '}'; + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/param/CacheDataSourceParamDTO.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/param/CacheDataSourceParamDTO.java new file mode 100644 index 000000000000..5d09c987519e --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/param/CacheDataSourceParamDTO.java @@ -0,0 +1,43 @@ +/* + * 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.cache.param; + +import org.apache.dolphinscheduler.plugin.datasource.api.datasource.BaseDataSourceParamDTO; +import org.apache.dolphinscheduler.spi.enums.DbType; + +public class CacheDataSourceParamDTO extends BaseDataSourceParamDTO { + + @Override + public String toString() { + return "CacheDataSourceParamDTO{" + + "name='" + name + '\'' + + ", note='" + note + '\'' + + ", host='" + host + '\'' + + ", port=" + port + + ", database='" + database + '\'' + + ", userName='" + userName + '\'' + + ", password='" + password + '\'' + + ", other='" + other + '\'' + + '}'; + } + + @Override + public DbType getType() { + return DbType.CACHE; + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/param/CacheDataSourceProcessor.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/param/CacheDataSourceProcessor.java new file mode 100644 index 000000000000..1b3b3a29e28b --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/main/java/org/apache/dolphinscheduler/plugin/datasource/cache/param/CacheDataSourceProcessor.java @@ -0,0 +1,176 @@ +/* + * 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.cache.param; + +import org.apache.dolphinscheduler.common.constants.Constants; +import org.apache.dolphinscheduler.common.constants.DataSourceConstants; +import org.apache.dolphinscheduler.common.utils.JSONUtils; +import org.apache.dolphinscheduler.plugin.datasource.api.datasource.AbstractDataSourceProcessor; +import org.apache.dolphinscheduler.plugin.datasource.api.datasource.BaseDataSourceParamDTO; +import org.apache.dolphinscheduler.plugin.datasource.api.datasource.DataSourceProcessor; +import org.apache.dolphinscheduler.plugin.datasource.api.utils.PasswordUtils; +import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; +import org.apache.dolphinscheduler.spi.datasource.ConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +import org.apache.commons.collections4.MapUtils; + +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.auto.service.AutoService; + +@AutoService(DataSourceProcessor.class) +public class CacheDataSourceProcessor extends AbstractDataSourceProcessor { + + private static final Logger log = LoggerFactory.getLogger(CacheDataSourceProcessor.class); + + @Override + public BaseDataSourceParamDTO castDatasourceParamDTO(String paramJson) { + return JSONUtils.parseObject(paramJson, CacheDataSourceParamDTO.class); + } + + @Override + public BaseDataSourceParamDTO createDatasourceParamDTO(String connectionJson) { + CacheConnectionParam connectionParams = (CacheConnectionParam) createConnectionParams(connectionJson); + CacheDataSourceParamDTO mysqlDatasourceParamDTO = new CacheDataSourceParamDTO(); + mysqlDatasourceParamDTO.setUserName(connectionParams.getUser()); + mysqlDatasourceParamDTO.setDatabase(connectionParams.getDatabase()); + String address = connectionParams.getAddress(); + try { + String[] hostPortSplit = getHostPortSplit(address); + mysqlDatasourceParamDTO.setPort(Integer.parseInt(hostPortSplit[1])); + mysqlDatasourceParamDTO.setHost(hostPortSplit[0]); + } catch (NumberFormatException e) { + log.error("Invalid port number", e); + } + return mysqlDatasourceParamDTO; + } + + public static String[] getHostPortSplit(String address) { + String[] hostSeperator = address.split(Constants.DOUBLE_SLASH); + if (hostSeperator.length < 2) { + log.error("Invalid address format"); + } + String[] hostPortArray = hostSeperator[hostSeperator.length - 1].split(Constants.COMMA); + if (hostPortArray.length < 1) { + log.error("Invalid hostPortArray format"); + } + String[] hostPortSplit = hostPortArray[0].split(Constants.COLON); + if (hostPortSplit.length < 2) { + log.error("Invalid hostPortSplit format"); + } + return hostPortSplit; + } + + @Override + public BaseConnectionParam createConnectionParams(BaseDataSourceParamDTO dataSourceParam) { + CacheDataSourceParamDTO cacheDatasourceParam = (CacheDataSourceParamDTO) dataSourceParam; + String address = String.format("%s%s:%s", DataSourceConstants.JDBC_CACHE, cacheDatasourceParam.getHost(), + cacheDatasourceParam.getPort()); + String jdbcUrl = String.format("%s/%s", address, cacheDatasourceParam.getDatabase()); + + CacheConnectionParam CacheConnectionParam = new CacheConnectionParam(); + CacheConnectionParam.setJdbcUrl(jdbcUrl); + CacheConnectionParam.setValidationQuery(getValidationQuery()); + CacheConnectionParam.setDatabase(cacheDatasourceParam.getDatabase()); + CacheConnectionParam.setAddress(address); + CacheConnectionParam.setUser(cacheDatasourceParam.getUserName()); + CacheConnectionParam.setPassword(PasswordUtils.encodePassword(cacheDatasourceParam.getPassword())); + CacheConnectionParam.setDriverClassName(getDatasourceDriver()); + CacheConnectionParam.setOther(cacheDatasourceParam.getOther()); + + return CacheConnectionParam; + } + + @Override + public ConnectionParam createConnectionParams(String connectionJson) { + return JSONUtils.parseObject(connectionJson, CacheConnectionParam.class); + } + + @Override + public String getDatasourceDriver() { + return DataSourceConstants.COM_INTERSYS_JDBC_CACHE_DRIVER; + } + + @Override + public String getValidationQuery() { + return DataSourceConstants.CACHE_VALIDATION_QUERY; + } + + @Override + public String getJdbcUrl(ConnectionParam connectionParam) { + CacheConnectionParam CacheConnectionParam = (CacheConnectionParam) connectionParam; + String jdbcUrl = CacheConnectionParam.getJdbcUrl(); + Map other = CacheConnectionParam.getOther(); + if (MapUtils.isNotEmpty(other)) { + return String.format("%s?%s", jdbcUrl, transformOther(other)); + } + return jdbcUrl; + } + + String transformOther(Map otherMap) { + if (otherMap == null || otherMap.isEmpty()) { + return ""; + } + + StringBuilder sb = new StringBuilder(); + for (Map.Entry entry : otherMap.entrySet()) { + try { + String encodedKey = URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8.toString()); + String encodedValue = URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.toString()); + sb.append(encodedKey).append("=").append(encodedValue).append("&"); + } catch (Exception e) { + log.error("Error encoding key-value pair: {}={}", entry.getKey(), entry.getValue(), e); + } + } + + // 移除最后一个多余的 "&" + if (sb.length() > 0) { + sb.setLength(sb.length() - 1); + } + + return sb.toString(); + } + + @Override + public Connection getConnection(ConnectionParam connectionParam) throws ClassNotFoundException, SQLException { + CacheConnectionParam mysqlConnectionParam = (CacheConnectionParam) connectionParam; + Class.forName(getDatasourceDriver()); + String user = mysqlConnectionParam.getUser(); + String password = PasswordUtils.decodePassword(mysqlConnectionParam.getPassword()); + return DriverManager.getConnection(getJdbcUrl(connectionParam), user, password); + } + + @Override + public DbType getDbType() { + return DbType.CACHE; + } + + @Override + public DataSourceProcessor create() { + return new CacheDataSourceProcessor(); + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/test/java/org/apache/dolphinscheduler/plugin/datasource/cache/CacheDataSourceChannelFactoryTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/test/java/org/apache/dolphinscheduler/plugin/datasource/cache/CacheDataSourceChannelFactoryTest.java new file mode 100644 index 000000000000..421a48070e15 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/test/java/org/apache/dolphinscheduler/plugin/datasource/cache/CacheDataSourceChannelFactoryTest.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.datasource.cache; + +import org.apache.dolphinscheduler.spi.datasource.DataSourceChannel; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class CacheDataSourceChannelFactoryTest { + + @Test + void testCreate() { + CacheDataSourceChannelFactory sourceChannelFactory = new CacheDataSourceChannelFactory(); + DataSourceChannel dataSourceChannel = sourceChannelFactory.create(); + Assertions.assertNotNull(dataSourceChannel); + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/test/java/org/apache/dolphinscheduler/plugin/datasource/cache/CacheDataSourceChannelTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/test/java/org/apache/dolphinscheduler/plugin/datasource/cache/CacheDataSourceChannelTest.java new file mode 100644 index 000000000000..49572b1d831a --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/test/java/org/apache/dolphinscheduler/plugin/datasource/cache/CacheDataSourceChannelTest.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.plugin.datasource.cache; + +import org.apache.dolphinscheduler.plugin.datasource.cache.param.CacheConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class CacheDataSourceChannelTest { + + @Test + void testCreateDataSourceClient() { + CacheDataSourceChannel sourceChannel = Mockito.mock(CacheDataSourceChannel.class); + CachePooledDataSourceClient dataSourceClient = Mockito.mock(CachePooledDataSourceClient.class); + Mockito.when(sourceChannel.createPooledDataSourceClient(Mockito.any(), Mockito.any())) + .thenReturn(dataSourceClient); + Assertions.assertNotNull(sourceChannel.createPooledDataSourceClient(new CacheConnectionParam(), DbType.CACHE)); + } +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/test/java/org/apache/dolphinscheduler/plugin/datasource/cache/param/CacheDataSourceProcessorTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/test/java/org/apache/dolphinscheduler/plugin/datasource/cache/param/CacheDataSourceProcessorTest.java new file mode 100644 index 000000000000..0069e553ac2c --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/test/java/org/apache/dolphinscheduler/plugin/datasource/cache/param/CacheDataSourceProcessorTest.java @@ -0,0 +1,146 @@ +/* + * 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.cache.param; + +import org.apache.dolphinscheduler.common.constants.DataSourceConstants; +import org.apache.dolphinscheduler.plugin.datasource.api.utils.PasswordUtils; +import org.apache.dolphinscheduler.spi.enums.DbType; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class CacheDataSourceProcessorTest { + + @InjectMocks + private CacheDataSourceProcessor cacheDataSourceProcessor; + + @Test + public void testTransformOtherWithValidMap() { + Map otherMap = new HashMap<>(); + otherMap.put("key1", "value1"); + otherMap.put("key2", "value2"); + + String result = cacheDataSourceProcessor.transformOther(otherMap); + + Assertions.assertEquals("key1=value1&key2=value2", result); + } + + @Test + public void testTransformOtherWithEmptyMap() { + Map otherMap = new HashMap<>(); + String result = cacheDataSourceProcessor.transformOther(otherMap); + Assertions.assertEquals("", result); + } + + @Test + void testCreateConnectionParams() { + Map props = new HashMap<>(); + props.put("service principal", "null"); + props.put("TransactionIsolationLevel", "TRANSACTION_READ_UNCOMMITTED"); + CacheDataSourceParamDTO mysqlDatasourceParamDTO = new CacheDataSourceParamDTO(); + mysqlDatasourceParamDTO.setUserName("root"); + mysqlDatasourceParamDTO.setPassword("123456"); + mysqlDatasourceParamDTO.setHost("localhost"); + mysqlDatasourceParamDTO.setPort(1972); + mysqlDatasourceParamDTO.setDatabase("default"); + mysqlDatasourceParamDTO.setOther(props); + + try (MockedStatic ignored = Mockito.mockStatic(PasswordUtils.class)) { + Mockito.when(PasswordUtils.encodePassword(Mockito.anyString())).thenReturn("123456"); + CacheConnectionParam connectionParams = (CacheConnectionParam) cacheDataSourceProcessor + .createConnectionParams(mysqlDatasourceParamDTO); + Assertions.assertEquals("jdbc:Cache://localhost:1972", connectionParams.getAddress()); + Assertions.assertEquals("123456", connectionParams.getPassword()); + Assertions.assertEquals("jdbc:Cache://localhost:1972/default", + connectionParams.getJdbcUrl()); + String jdbcUrl = cacheDataSourceProcessor.getJdbcUrl(connectionParams); + Assertions.assertEquals( + "jdbc:Cache://localhost:1972/default?service+principal=null&TransactionIsolationLevel=TRANSACTION_READ_UNCOMMITTED", + jdbcUrl); + + } + } + + @Test + void testCreateConnectionParams2() { + String connectionJson = + "{\"user\":\"root\",\"password\":\"123456\",\"address\":\"jdbc:Cache://localhost:1972\"" + + ",\"database\":\"default\",\"jdbcUrl\":\"jdbc:Cache://localhost:1972/default\"}"; + CacheConnectionParam connectionParams = (CacheConnectionParam) cacheDataSourceProcessor + .createConnectionParams(connectionJson); + Assertions.assertNotNull(connectionJson); + Assertions.assertEquals("root", connectionParams.getUser()); + } + + @Test + void testGetDatasourceDriver() { + Assertions.assertEquals(DataSourceConstants.COM_INTERSYS_JDBC_CACHE_DRIVER, + cacheDataSourceProcessor.getDatasourceDriver()); + } + + @Test + void testGetDbType() { + Assertions.assertEquals(DbType.CACHE, cacheDataSourceProcessor.getDbType()); + } + + @Test + void testGetValidationQuery() { + Assertions.assertEquals(DataSourceConstants.CACHE_VALIDATION_QUERY, + cacheDataSourceProcessor.getValidationQuery()); + } + + @Test + void testGetDatasourceUniqueId() { + CacheConnectionParam mysqlConnectionParam = new CacheConnectionParam(); + mysqlConnectionParam.setJdbcUrl("jdbc:Cache://localhost:1972/default"); + mysqlConnectionParam.setUser("root"); + mysqlConnectionParam.setPassword("123456"); + try (MockedStatic mockedPasswordUtils = Mockito.mockStatic(PasswordUtils.class)) { + Mockito.when(PasswordUtils.encodePassword(Mockito.anyString())).thenReturn("123456"); + Assertions.assertEquals("cache@root@123456@jdbc:Cache://localhost:1972/default", + cacheDataSourceProcessor.getDatasourceUniqueId(mysqlConnectionParam, DbType.CACHE)); + } + } + + @Test + void testGetHostPortSplit() { + String address = "jdbc:Cache://localhost:1972"; + String[] expected = {"localhost", "1972"}; + String[] result = CacheDataSourceProcessor.getHostPortSplit(address); + Assertions.assertArrayEquals(expected, result); + } + + @Test + void testGetHostPortSplit_InvalidFormat() { + String invalidAddress = "invalid-format"; + String[] hostPortSplit = CacheDataSourceProcessor.getHostPortSplit(invalidAddress); + Assertions.assertEquals("[invalid-format]", Arrays.toString(hostPortSplit)); + + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/test/java/org/apache/dolphinscheduler/plugin/datasource/cache/provider/JDBCDataSourceProviderTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/test/java/org/apache/dolphinscheduler/plugin/datasource/cache/provider/JDBCDataSourceProviderTest.java new file mode 100644 index 000000000000..6cf33f9b3b43 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/test/java/org/apache/dolphinscheduler/plugin/datasource/cache/provider/JDBCDataSourceProviderTest.java @@ -0,0 +1,64 @@ +/* + * 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.cache.provider; + +import org.apache.dolphinscheduler.plugin.datasource.api.provider.JDBCDataSourceProvider; +import org.apache.dolphinscheduler.plugin.datasource.cache.param.CacheConnectionParam; +import org.apache.dolphinscheduler.spi.enums.DbType; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +import com.zaxxer.hikari.HikariDataSource; + +@ExtendWith(MockitoExtension.class) +class JDBCDataSourceProviderTest { + + @Test + void testCreateJdbcDataSource() { + try ( + MockedStatic mockedJDBCDataSourceProvider = + Mockito.mockStatic(JDBCDataSourceProvider.class)) { + HikariDataSource dataSource = Mockito.mock(HikariDataSource.class); + mockedJDBCDataSourceProvider + .when(() -> JDBCDataSourceProvider.createOneSessionJdbcDataSource(Mockito.any(), Mockito.any())) + .thenReturn(dataSource); + Assertions.assertNotNull( + JDBCDataSourceProvider.createOneSessionJdbcDataSource(new CacheConnectionParam(), DbType.CACHE)); + } + } + + @Test + void testCreateOneSessionJdbcDataSource() { + try ( + MockedStatic mockedJDBCDataSourceProvider = + Mockito.mockStatic(JDBCDataSourceProvider.class)) { + HikariDataSource dataSource = Mockito.mock(HikariDataSource.class); + mockedJDBCDataSourceProvider + .when(() -> JDBCDataSourceProvider.createOneSessionJdbcDataSource(Mockito.any(), Mockito.any())) + .thenReturn(dataSource); + Assertions.assertNotNull( + JDBCDataSourceProvider.createOneSessionJdbcDataSource(new CacheConnectionParam(), DbType.CACHE)); + } + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/test/java/org/apache/dolphinscheduler/plugin/datasource/cache/utils/DataSourceUtilsTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/test/java/org/apache/dolphinscheduler/plugin/datasource/cache/utils/DataSourceUtilsTest.java new file mode 100644 index 000000000000..c3b300babff3 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-cache/src/test/java/org/apache/dolphinscheduler/plugin/datasource/cache/utils/DataSourceUtilsTest.java @@ -0,0 +1,147 @@ +/* + * 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.cache.utils; + +import org.apache.dolphinscheduler.common.utils.JSONUtils; +import org.apache.dolphinscheduler.common.utils.PropertyUtils; +import org.apache.dolphinscheduler.plugin.datasource.api.plugin.DataSourceClientProvider; +import org.apache.dolphinscheduler.plugin.datasource.api.utils.CommonUtils; +import org.apache.dolphinscheduler.plugin.datasource.api.utils.DataSourceUtils; +import org.apache.dolphinscheduler.plugin.datasource.api.utils.PasswordUtils; +import org.apache.dolphinscheduler.plugin.datasource.cache.param.CacheConnectionParam; +import org.apache.dolphinscheduler.plugin.datasource.cache.param.CacheDataSourceParamDTO; +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; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class DataSourceUtilsTest { + + @Test + void testCheckDatasourceParam() { + CacheDataSourceParamDTO cacheDataSourceParamDTO = new CacheDataSourceParamDTO(); + cacheDataSourceParamDTO.setHost("localhost"); + cacheDataSourceParamDTO.setDatabase("default"); + Map other = new HashMap<>(); + other.put("reconnect", "true"); + cacheDataSourceParamDTO.setOther(other); + DataSourceUtils.checkDatasourceParam(cacheDataSourceParamDTO); + Assertions.assertTrue(true); + } + + @Test + void testBuildConnectionParams() { + CacheDataSourceParamDTO cacheDataSourceParamDTO = new CacheDataSourceParamDTO(); + cacheDataSourceParamDTO.setHost("localhost"); + cacheDataSourceParamDTO.setDatabase("default"); + cacheDataSourceParamDTO.setUserName("root"); + cacheDataSourceParamDTO.setPort(1972); + cacheDataSourceParamDTO.setPassword("123456"); + + try ( + MockedStatic mockedStaticPasswordUtils = Mockito.mockStatic(PasswordUtils.class); + MockedStatic mockedStaticCommonUtils = Mockito.mockStatic(CommonUtils.class)) { + mockedStaticPasswordUtils.when(() -> PasswordUtils.encodePassword(Mockito.anyString())) + .thenReturn("123456"); + mockedStaticCommonUtils.when(CommonUtils::getKerberosStartupState).thenReturn(false); + ConnectionParam connectionParam = DataSourceUtils.buildConnectionParams(cacheDataSourceParamDTO); + Assertions.assertNotNull(connectionParam); + } + } + + @Test + void testBuildConnectionParams2() { + CacheDataSourceParamDTO cacheDatasourceParamDTO = new CacheDataSourceParamDTO(); + cacheDatasourceParamDTO.setHost("localhost"); + cacheDatasourceParamDTO.setDatabase("default"); + cacheDatasourceParamDTO.setUserName("root"); + cacheDatasourceParamDTO.setPort(1972); + cacheDatasourceParamDTO.setPassword("123456"); + ConnectionParam connectionParam = + DataSourceUtils.buildConnectionParams(DbType.CACHE, JSONUtils.toJsonString(cacheDatasourceParamDTO)); + Assertions.assertNotNull(connectionParam); + } + + @Test + 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); + + Connection connection = Mockito.mock(Connection.class); + + Mockito.when(DataSourceClientProvider.getAdHocConnection(Mockito.any(), Mockito.any())) + .thenReturn(connection); + CacheConnectionParam connectionParam = new CacheConnectionParam(); + connectionParam.setUser("root"); + connectionParam.setPassword("123456"); + + Assertions.assertNotNull(connection); + } + } + + @Test + void testGetJdbcUrl() { + CacheConnectionParam cacheConnectionParam = new CacheConnectionParam(); + cacheConnectionParam.setJdbcUrl("jdbc:Cache://localhost:1972"); + String jdbcUrl = DataSourceUtils.getJdbcUrl(DbType.CACHE, cacheConnectionParam); + Assertions.assertEquals( + "jdbc:Cache://localhost:1972", + jdbcUrl); + } + + @Test + void testBuildDatasourceParamDTO() { + CacheConnectionParam connectionParam = new CacheConnectionParam(); + connectionParam.setJdbcUrl( + "jdbc:Cache://localhost:1972?reconnect=true"); + connectionParam.setAddress("jdbc:mysql://localhost:1972"); + connectionParam.setUser("root"); + connectionParam.setPassword("123456"); + + Assertions.assertNotNull( + DataSourceUtils.buildDatasourceParamDTO(DbType.CACHE, JSONUtils.toJsonString(connectionParam))); + + } + + @Test + void testGetDatasourceProcessor() { + Assertions.assertNotNull(DataSourceUtils.getDatasourceProcessor(DbType.CACHE)); + } + + @Test + void testGetDatasourceProcessorError() { + Assertions.assertThrows(Exception.class, () -> { + DataSourceUtils.getDatasourceProcessor(null); + }); + } +} diff --git a/dolphinscheduler-datasource-plugin/pom.xml b/dolphinscheduler-datasource-plugin/pom.xml index 313b3cdea7b8..f84a8ab64efe 100644 --- a/dolphinscheduler-datasource-plugin/pom.xml +++ b/dolphinscheduler-datasource-plugin/pom.xml @@ -57,6 +57,7 @@ dolphinscheduler-datasource-k8s dolphinscheduler-datasource-hana dolphinscheduler-datasource-aliyunserverlessspark + dolphinscheduler-datasource-cache diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/enums/DbType.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/enums/DbType.java index 639f8d573983..3ec4da5697ac 100644 --- a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/enums/DbType.java +++ b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/enums/DbType.java @@ -57,10 +57,9 @@ public enum DbType { DORIS(23, "doris", "doris"), ZEPPELIN(24, "zeppelin", "zeppelin"), SAGEMAKER(25, "sagemaker", "sagemaker"), - K8S(26, "k8s", "k8s"), - - ALIYUN_SERVERLESS_SPARK(27, "aliyun_serverless_spark", "aliyun serverless spark"); + ALIYUN_SERVERLESS_SPARK(27, "aliyun_serverless_spark", "aliyun serverless spark"), + CACHE(28, "cache", "Caché"); private static final Map DB_TYPE_MAP = Arrays.stream(DbType.values()).collect(toMap(DbType::getCode, Functions.identity())); diff --git a/dolphinscheduler-ui/src/service/modules/data-source/types.ts b/dolphinscheduler-ui/src/service/modules/data-source/types.ts index 135a8cc55393..2f32c9388273 100644 --- a/dolphinscheduler-ui/src/service/modules/data-source/types.ts +++ b/dolphinscheduler-ui/src/service/modules/data-source/types.ts @@ -42,6 +42,7 @@ type IDataBase = | 'ZEPPELIN' | 'SAGEMAKER' | 'K8S' + | 'CACHE' | 'ALIYUN_SERVERLESS_SPARK' type IDataBaseLabel = @@ -66,6 +67,7 @@ type IDataBaseLabel = | 'ZEPPELIN' | 'SAGEMAKER' | 'K8S' + | 'CACHE' | 'ALIYUN_SERVERLESS_SPARK' interface IDataSource { diff --git a/dolphinscheduler-ui/src/views/datasource/list/use-form.ts b/dolphinscheduler-ui/src/views/datasource/list/use-form.ts index 4b229868a642..a6cc0e1aff42 100644 --- a/dolphinscheduler-ui/src/views/datasource/list/use-form.ts +++ b/dolphinscheduler-ui/src/views/datasource/list/use-form.ts @@ -493,6 +493,11 @@ export const datasourceType: IDataBaseOptionKeys = { label: 'K8S', defaultPort: 6443 }, + CACHE: { + value: 'CACHE', + label: 'CACHE', + defaultPort: 1972 + }, ALIYUN_SERVERLESS_SPARK: { value: 'ALIYUN_SERVERLESS_SPARK', label: 'ALIYUN_SERVERLESS_SPARK', diff --git a/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-datasource.ts b/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-datasource.ts index 907ee147b309..3348ccf0bc23 100644 --- a/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-datasource.ts +++ b/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-datasource.ts @@ -162,6 +162,11 @@ export function useDatasource( id: 27, code: 'ALIYUN_SERVERLESS_SPARK', disabled: false + }, + { + id: 28, + code: 'CACHE', + disabled: false } ]