diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataSourceController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataSourceController.java index 6dbdea39aa7c..57d2ef748388 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataSourceController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataSourceController.java @@ -35,6 +35,7 @@ import org.apache.dolphinscheduler.api.audit.enums.AuditType; import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ApiException; +import org.apache.dolphinscheduler.api.exceptions.ServiceException; import org.apache.dolphinscheduler.api.service.DataSourceService; import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.api.utils.Result; @@ -202,7 +203,6 @@ public Result queryDataSourceListPaging(@Parameter(hidden = true) @Reque /** * connect datasource * - * @param loginUser login user * @param jsonStr datasource param * example: {"type":"MYSQL","name":"txx","note":"","host":"localhost","port":3306,"principal":"","javaSecurityKrb5Conf":"","loginUserKeytabUsername":"","loginUserKeytabPath":"","userName":"root","password":"xxx","database":"ds","connectType":"","other":{"serverTimezone":"GMT-8"},"id":2} * @return connect result code @@ -211,8 +211,7 @@ public Result queryDataSourceListPaging(@Parameter(hidden = true) @Reque @PostMapping(value = "/connect") @ResponseStatus(HttpStatus.OK) @ApiException(CONNECT_DATASOURCE_FAILURE) - public Result connectDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "dataSourceParam") @RequestBody String jsonStr) { + public Result connectDataSource(@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "dataSourceParam") @RequestBody String jsonStr) { BaseDataSourceParamDTO dataSourceParam = DataSourceUtils.buildDatasourceParam(jsonStr); DataSourceUtils.checkDatasourceParam(dataSourceParam); ConnectionParam connectionParams = DataSourceUtils.buildConnectionParams(dataSourceParam); @@ -264,9 +263,8 @@ public Result deleteDataSource(@Parameter(hidden = true) @RequestAttrib /** * verify datasource name * - * @param loginUser login user * @param name data source name - * @return true if data source name not exists, otherwise return false + * @return true if data source name not exists, otherwise throw a {@link ServiceException} */ @Operation(summary = "verifyDataSourceName", description = "VERIFY_DATA_SOURCE_NOTES") @Parameters({ @@ -275,8 +273,7 @@ public Result deleteDataSource(@Parameter(hidden = true) @RequestAttrib @GetMapping(value = "/verify-name") @ResponseStatus(HttpStatus.OK) @ApiException(VERIFY_DATASOURCE_NAME_FAILURE) - public Result verifyDataSourceName(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "name") String name) { + public Result verifyDataSourceName(@RequestParam(value = "name") String name) { dataSourceService.verifyDataSourceName(name); return Result.success(true); } @@ -323,16 +320,15 @@ public Result authedDatasource(@Parameter(hidden = true) @RequestAttribu } /** - * get user info + * Checks the startup status of Kerberos authentication. * - * @param loginUser login user - * @return user info data + * @return a boolean indicating whether Kerberos is currently active */ - @Operation(summary = "getKerberosStartupState", description = "GET_USER_INFO_NOTES") + @Operation(summary = "getKerberosStartupState", description = "GET_KERBEROS_STARTUP_STATE") @GetMapping(value = "/kerberos-startup-state") @ResponseStatus(HttpStatus.OK) @ApiException(KERBEROS_STARTUP_STATE) - public Result getKerberosStartupState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { + public Result getKerberosStartupState() { // if upload resource is HDFS and kerberos startup is true , else false return success(Status.SUCCESS.getMsg(), CommonUtils.getKerberosStartupState()); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataSourceService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataSourceService.java index 1cdf76faa968..e3d9c351d632 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataSourceService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataSourceService.java @@ -17,6 +17,7 @@ package org.apache.dolphinscheduler.api.service; +import org.apache.dolphinscheduler.api.exceptions.ServiceException; import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.dao.entity.DataSource; import org.apache.dolphinscheduler.dao.entity.User; @@ -28,33 +29,36 @@ import java.util.List; /** - * data source service + * datasource service */ public interface DataSourceService { /** - * create data source + * create a new datasource. * * @param loginUser login user - * @param datasourceParam datasource parameter - * @return create result code + * @param datasourceParam datasource configuration DTO + * @return created {@link DataSource} entity (sensitive fields masked) + * @throws ServiceException if permission denied, security check fails, or connection test fails */ DataSource createDataSource(User loginUser, BaseDataSourceParamDTO datasourceParam); /** - * updateWorkflowInstance datasource + * update datasource * * @param loginUser login user - * @param dataSourceParam data source params - * @return update result code + * @param dataSourceParam datasource params + * @return updated {@link DataSource} entity (sensitive fields masked) + * @throws ServiceException if permission denied, security check fails, or connection test fails */ DataSource updateDataSource(User loginUser, BaseDataSourceParamDTO dataSourceParam); /** - * updateWorkflowInstance datasource + * query datasource * + * @param loginUser login user * @param id datasource id - * @return data source detail + * @return a {@link BaseDataSourceParamDTO} entity (sensitive fields masked) */ BaseDataSourceParamDTO queryDataSource(int id, User loginUser); @@ -65,7 +69,7 @@ public interface DataSourceService { * @param searchVal search value * @param pageNo page number * @param pageSize page size - * @return data source list page + * @return datasource list page */ PageInfo queryDataSourceListPaging(User loginUser, String searchVal, Integer pageNo, Integer pageSize); @@ -73,27 +77,34 @@ public interface DataSourceService { * query data resource list * * @param loginUser login user - * @param type data source type - * @return data source list page + * @param type datasource type + * @return datasource list */ List queryDataSourceList(User loginUser, Integer type); /** - * verify datasource exists + * verify whether a datasource name already exists. + *

+ * If the name already exists, a {@link ServiceException} is thrown. + * If the name is available (does not exist), the method completes successfully without returning a value. * - * @param name datasource name - * @return true if data datasource not exists, otherwise return false + * @param name the datasource name to verify + * @throws ServiceException if the datasource name already exists (Status.DATASOURCE_EXIST) */ void verifyDataSourceName(String name); /** - * check connection + * Checks the connectivity of a datasource based on the provided type and parameters. + *

+ * This method attempts to establish a connection. + * - If the connection is successful, the method returns normally (void). + * - If the connection fails, a {@link ServiceException} is thrown. * - * @param type data source type - * @param parameter data source parameters - * @return true if connect successfully, otherwise false + * @param type the type of the datasource (e.g., MYSQL, POSTGRESQL) + * @param connectionParam the connection parameters containing host, port, credentials, etc. + * @throws ServiceException if the connection test fails (Status.CONNECTION_TEST_FAILURE) */ - void checkConnection(DbType type, ConnectionParam parameter); + void checkConnection(DbType type, ConnectionParam connectionParam); /** * test connection @@ -104,11 +115,11 @@ public interface DataSourceService { void connectionTest(int id); /** - * delete datasource + * delete a datasource by ID. * - * @param loginUser login user - * @param datasourceId data source id - * @return delete result code + * @param loginUser the current logged-in user + * @param datasourceId the unique identifier of the datasource to delete + * @throws ServiceException if checks fail or deletion encounters an error */ void delete(User loginUser, int datasourceId); @@ -117,7 +128,7 @@ public interface DataSourceService { * * @param loginUser login user * @param userId user id - * @return unauthed data source result code + * @return a list of {@link DataSource} objects that are available to be authorized to the target user */ List unAuthDatasource(User loginUser, Integer userId); @@ -126,7 +137,7 @@ public interface DataSourceService { * * @param loginUser login user * @param userId user id - * @return authorized result code + * @return a list of {@link DataSource} objects that are authorized to the target user */ List authedDatasource(User loginUser, Integer userId); 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 7f298a7d841d..38c831dd6539 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 @@ -86,13 +86,6 @@ public class DataSourceServiceImpl extends BaseServiceImpl implements DataSource private static final String TABLE_NAME = "TABLE_NAME"; private static final String COLUMN_NAME = "COLUMN_NAME"; - /** - * create data source - * - * @param loginUser login user - * @param datasourceParam datasource parameters - * @return create result code - */ @Override public DataSource createDataSource(User loginUser, BaseDataSourceParamDTO datasourceParam) { DataSourceUtils.checkDatasourceParam(datasourceParam); @@ -129,12 +122,6 @@ public DataSource createDataSource(User loginUser, BaseDataSourceParamDTO dataso } } - /** - * updateWorkflowInstance datasource - * - * @param loginUser login user - * @return update result code - */ @Override public DataSource updateDataSource(User loginUser, BaseDataSourceParamDTO dataSourceParam) { DataSourceUtils.checkDatasourceParam(dataSourceParam); @@ -188,12 +175,6 @@ private boolean checkName(String name) { return queryDataSource != null && !queryDataSource.isEmpty(); } - /** - * updateWorkflowInstance datasource - * - * @param id datasource id - * @return data source detail - */ @Override public BaseDataSourceParamDTO queryDataSource(int id, User loginUser) { DataSource dataSource = dataSourceMapper.selectById(id); @@ -202,7 +183,7 @@ public BaseDataSourceParamDTO queryDataSource(int id, User loginUser) { throw new ServiceException(Status.RESOURCE_NOT_EXIST); } - if (!canOperatorPermissions(loginUser, new Object[]{dataSource.getId()}, AuthorizationType.DATASOURCE, + if (!canOperatorPermissions(loginUser, new Object[]{id}, AuthorizationType.DATASOURCE, ApiFuncIdentificationConstant.DATASOURCE)) { throw new ServiceException(Status.USER_NO_OPERATION_PERM); } @@ -218,15 +199,6 @@ public BaseDataSourceParamDTO queryDataSource(int id, User loginUser) { return baseDataSourceParamDTO; } - /** - * query datasource list by keyword - * - * @param loginUser login user - * @param searchVal search value - * @param pageNo page number - * @param pageSize page size - * @return data source list page - */ @Override public PageInfo queryDataSourceListPaging(User loginUser, String searchVal, Integer pageNo, Integer pageSize) { @@ -272,13 +244,6 @@ private String getHiddenPassword() { return Constants.XXXXXX; } - /** - * query data resource list - * - * @param loginUser login user - * @param type data source type - * @return data source list page - */ @Override public List queryDataSourceList(User loginUser, Integer type) { @@ -298,12 +263,6 @@ public List queryDataSourceList(User loginUser, Integer type) { return datasourceList; } - /** - * verify datasource exists - * - * @param name datasource name - * @return true if data datasource not exists, otherwise return false - */ @Override public void verifyDataSourceName(String name) { List dataSourceList = dataSourceMapper.queryDataSourceByName(name); @@ -312,14 +271,6 @@ public void verifyDataSourceName(String name) { } } - /** - * check connection - * - * @param type data source type - * @param connectionParam connectionParam - * @return true if connect successfully, otherwise false - * @return true if connect successfully, otherwise false - */ @Override public void checkConnection(DbType type, ConnectionParam connectionParam) { DataSourceProcessor sshDataSourceProcessor = DataSourceUtils.getDatasourceProcessor(type); @@ -346,36 +297,25 @@ public void connectionTest(int id) { DataSourceUtils.buildConnectionParams(dataSource.getType(), dataSource.getConnectionParams())); } - /** - * delete datasource - * - * @param loginUser login user - * @param datasourceId data source id - * @return delete result code - */ @Override @Transactional public void delete(User loginUser, int datasourceId) { // query datasource by id DataSource dataSource = dataSourceMapper.selectById(datasourceId); + if (dataSource == null) { throw new ServiceException(Status.RESOURCE_NOT_EXIST); } - if (!canOperatorPermissions(loginUser, new Object[]{dataSource.getId()}, AuthorizationType.DATASOURCE, + + if (!canOperatorPermissions(loginUser, new Object[]{datasourceId}, AuthorizationType.DATASOURCE, DATASOURCE_DELETE)) { throw new ServiceException(Status.USER_NO_OPERATION_PERM); } + dataSourceMapper.deleteById(datasourceId); datasourceUserMapper.deleteByDatasourceId(datasourceId); } - /** - * unauthorized datasource - * - * @param loginUser login user - * @param userId user id - * @return unauthed data source result code - */ @Override public List unAuthDatasource(User loginUser, Integer userId) { List datasourceList; @@ -403,13 +343,6 @@ public List unAuthDatasource(User loginUser, Integer userId) { return resultList; } - /** - * authorized datasource - * - * @param loginUser login user - * @param userId user id - * @return authorized result code - */ @Override public List authedDatasource(User loginUser, Integer userId) { List authedDatasourceList = dataSourceMapper.queryAuthedDatasource(userId); diff --git a/dolphinscheduler-api/src/main/resources/i18n/messages.properties b/dolphinscheduler-api/src/main/resources/i18n/messages.properties index 7f56c1eb8d39..16f488ab0ab1 100644 --- a/dolphinscheduler-api/src/main/resources/i18n/messages.properties +++ b/dolphinscheduler-api/src/main/resources/i18n/messages.properties @@ -224,6 +224,7 @@ DELETE_DATA_SOURCE_NOTES=delete data source VERIFY_DATA_SOURCE_NOTES=verify data source UNAUTHORIZED_DATA_SOURCE_NOTES=unauthorized data source AUTHORIZED_DATA_SOURCE_NOTES=authorized data source +GET_KERBEROS_STARTUP_STATE=get the Kerberos startup state DELETE_SCHEDULE_NOTES=delete schedule by id QUERY_ALERT_GROUP_LIST_PAGING_NOTES=query alert group list paging QUERY_AUTHORIZED_AND_USER_CREATED_PROJECT_NOTES= query authorized and user created project diff --git a/dolphinscheduler-api/src/main/resources/i18n/messages_en_US.properties b/dolphinscheduler-api/src/main/resources/i18n/messages_en_US.properties index 71e5dc091d83..239da8f6309a 100644 --- a/dolphinscheduler-api/src/main/resources/i18n/messages_en_US.properties +++ b/dolphinscheduler-api/src/main/resources/i18n/messages_en_US.properties @@ -257,6 +257,7 @@ DELETE_DATA_SOURCE_NOTES=delete data source VERIFY_DATA_SOURCE_NOTES=verify data source UNAUTHORIZED_DATA_SOURCE_NOTES=unauthorized data source AUTHORIZED_DATA_SOURCE_NOTES=authorized data source +GET_KERBEROS_STARTUP_STATE=get the Kerberos startup state DELETE_SCHEDULE_NOTES=delete schedule by id QUERY_ALERT_GROUP_LIST_PAGING_NOTES=query alert group list paging QUERY_AUTHORIZED_AND_USER_CREATED_PROJECT_NOTES=query authorized and user created project diff --git a/dolphinscheduler-api/src/main/resources/i18n/messages_zh_CN.properties b/dolphinscheduler-api/src/main/resources/i18n/messages_zh_CN.properties index 243c41c0685c..a6e7c6b99951 100644 --- a/dolphinscheduler-api/src/main/resources/i18n/messages_zh_CN.properties +++ b/dolphinscheduler-api/src/main/resources/i18n/messages_zh_CN.properties @@ -256,6 +256,7 @@ DELETE_DATA_SOURCE_NOTES=\u5220\u9664\u6570\u636E\u6E90 VERIFY_DATA_SOURCE_NOTES=\u9A8C\u8BC1\u6570\u636E\u6E90 UNAUTHORIZED_DATA_SOURCE_NOTES=\u672A\u6388\u6743\u7684\u6570\u636E\u6E90 AUTHORIZED_DATA_SOURCE_NOTES=\u6388\u6743\u7684\u6570\u636E\u6E90 +GET_KERBEROS_STARTUP_STATE=\u83B7\u53D6Kerberos\u542F\u52A8\u72B6\u6001 DELETE_SCHEDULE_NOTES=\u6839\u636E\u5B9A\u65F6id\u5220\u9664\u5B9A\u65F6\u6570\u636E QUERY_ALERT_GROUP_LIST_PAGING_NOTES=\u5206\u9875\u67E5\u8BE2\u544A\u8B66\u7EC4\u5217\u8868 QUERY_AUTHORIZED_AND_USER_CREATED_PROJECT_NOTES=\u67E5\u8BE2\u6388\u6743\u548C\u7528\u6237\u521B\u5EFA\u7684\u9879\u76EE