Skip to content

Commit 0cba793

Browse files
authored
[Improvement-18084][API] Address the inconsistent class comments in DataSourceService and DataSourceServiceImpl classes. (#18086)
1 parent 40493c3 commit 0cba793

6 files changed

Lines changed: 86 additions & 138 deletions

File tree

dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataSourceController.java

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
3636
import org.apache.dolphinscheduler.api.enums.Status;
3737
import org.apache.dolphinscheduler.api.exceptions.ApiException;
38+
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
3839
import org.apache.dolphinscheduler.api.service.DataSourceService;
3940
import org.apache.dolphinscheduler.api.utils.PageInfo;
4041
import org.apache.dolphinscheduler.api.utils.Result;
@@ -83,12 +84,13 @@ public class DataSourceController extends BaseController {
8384
private DataSourceService dataSourceService;
8485

8586
/**
86-
* create data source
87+
* create a new data source
8788
*
8889
* @param loginUser login user
8990
* @param jsonStr datasource param
9091
* 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}
91-
* @return create result code
92+
* @return the created DataSource object
93+
* @throws ServiceException if the data source name already exists or parameters are invalid
9294
*/
9395
@Operation(summary = "createDataSource", description = "CREATE_DATA_SOURCE_NOTES")
9496
@PostMapping()
@@ -103,18 +105,19 @@ public Result<DataSource> createDataSource(@Parameter(hidden = true) @RequestAtt
103105
}
104106

105107
/**
106-
* updateWorkflowInstance data source
108+
* update an existing data source
107109
*
108110
* @param loginUser login user
109111
* @param id datasource id
110112
* @param jsonStr datasource param
111113
* 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}
112-
* @return update result code
114+
* @return the updated DataSource object
115+
* @throws ServiceException if the data source does not exist or parameters are invalid
113116
*/
114117
@Operation(summary = "updateDataSource", description = "UPDATE_DATA_SOURCE_NOTES")
115118
@Parameters({
116119
@Parameter(name = "id", description = "DATA_SOURCE_ID", required = true, schema = @Schema(implementation = int.class)),
117-
@Parameter(name = "dataSourceParam", description = "DATA_SOURCE_PARAM", required = true, schema = @Schema(implementation = BaseDataSourceParamDTO.class))
120+
@Parameter(name = "jsonStr", description = "DATA_SOURCE_PARAM", required = true, schema = @Schema(implementation = BaseDataSourceParamDTO.class))
118121
})
119122
@PutMapping(value = "/{id}")
120123
@ResponseStatus(HttpStatus.OK)
@@ -200,19 +203,18 @@ public Result<Object> queryDataSourceListPaging(@Parameter(hidden = true) @Reque
200203
}
201204

202205
/**
203-
* connect datasource
206+
* test the connection to a data source
204207
*
205-
* @param loginUser login user
206208
* @param jsonStr datasource param
207209
* 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}
208-
* @return connect result code
210+
* @return {@code true} if the connection test was successful
211+
* @throws ServiceException if the connection fails or parameters are invalid
209212
*/
210213
@Operation(summary = "connectDataSource", description = "CONNECT_DATA_SOURCE_NOTES")
211214
@PostMapping(value = "/connect")
212215
@ResponseStatus(HttpStatus.OK)
213216
@ApiException(CONNECT_DATASOURCE_FAILURE)
214-
public Result<Boolean> connectDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
215-
@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "dataSourceParam") @RequestBody String jsonStr) {
217+
public Result<Boolean> connectDataSource(@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "dataSourceParam") @RequestBody String jsonStr) {
216218
BaseDataSourceParamDTO dataSourceParam = DataSourceUtils.buildDatasourceParam(jsonStr);
217219
DataSourceUtils.checkDatasourceParam(dataSourceParam);
218220
ConnectionParam connectionParams = DataSourceUtils.buildConnectionParams(dataSourceParam);
@@ -221,11 +223,12 @@ public Result<Boolean> connectDataSource(@Parameter(hidden = true) @RequestAttri
221223
}
222224

223225
/**
224-
* connection test
226+
* test the connection to an existing data source
225227
*
226228
* @param loginUser login user
227229
* @param id data source id
228-
* @return A Result wrapping {@code true} if the connection is successful; otherwise, throws an exception.
230+
* @return {@code true} if the connection test was successful
231+
* @throws ServiceException if the connection fails or the data source does not exist
229232
*/
230233
@Operation(summary = "connectionTest", description = "CONNECT_DATA_SOURCE_TEST_NOTES")
231234
@Parameters({
@@ -245,7 +248,8 @@ public Result<Boolean> connectionTest(@Parameter(hidden = true) @RequestAttribut
245248
*
246249
* @param loginUser login user
247250
* @param id datasource id
248-
* @return delete result
251+
* @return {@code true} if the deletion was successful
252+
* @throws ServiceException if the data source does not exist or if the user lacks permission
249253
*/
250254
@Operation(summary = "deleteDataSource", description = "DELETE_DATA_SOURCE_NOTES")
251255
@Parameters({
@@ -262,11 +266,11 @@ public Result<Boolean> deleteDataSource(@Parameter(hidden = true) @RequestAttrib
262266
}
263267

264268
/**
265-
* verify datasource name
269+
* verify if a data source name is available
266270
*
267-
* @param loginUser login user
268271
* @param name data source name
269-
* @return true if data source name not exists, otherwise return false
272+
* @return {@code true} if the name is available (does not exist)
273+
* @throws ServiceException if the name already exists
270274
*/
271275
@Operation(summary = "verifyDataSourceName", description = "VERIFY_DATA_SOURCE_NOTES")
272276
@Parameters({
@@ -275,18 +279,17 @@ public Result<Boolean> deleteDataSource(@Parameter(hidden = true) @RequestAttrib
275279
@GetMapping(value = "/verify-name")
276280
@ResponseStatus(HttpStatus.OK)
277281
@ApiException(VERIFY_DATASOURCE_NAME_FAILURE)
278-
public Result<Boolean> verifyDataSourceName(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
279-
@RequestParam(value = "name") String name) {
282+
public Result<Boolean> verifyDataSourceName(@RequestParam(value = "name") String name) {
280283
dataSourceService.verifyDataSourceName(name);
281284
return Result.success(true);
282285
}
283286

284287
/**
285-
* unauthorized datasource
288+
* query the list of unauthorized data sources for a specific user
286289
*
287290
* @param loginUser login user
288291
* @param userId user id
289-
* @return unauthorized data source result code
292+
* @return a list of unauthorized DataSource objects
290293
*/
291294
@Operation(summary = "unauthorizedDatasource", description = "UNAUTHORIZED_DATA_SOURCE_NOTES")
292295
@Parameters({
@@ -295,19 +298,19 @@ public Result<Boolean> verifyDataSourceName(@Parameter(hidden = true) @RequestAt
295298
@GetMapping(value = "/unauth-datasource")
296299
@ResponseStatus(HttpStatus.OK)
297300
@ApiException(UNAUTHORIZED_DATASOURCE)
298-
public Result<Object> unAuthDatasource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
299-
@RequestParam("userId") Integer userId) {
301+
public Result<Object> getUnauthorizedDatasourceList(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
302+
@RequestParam("userId") Integer userId) {
300303

301304
List<DataSource> unAuthDatasourceList = dataSourceService.unAuthDatasource(loginUser, userId);
302305
return Result.success(unAuthDatasourceList);
303306
}
304307

305308
/**
306-
* authorized datasource
309+
* query the list of data sources authorized for a specific user
307310
*
308311
* @param loginUser login user
309312
* @param userId user id
310-
* @return authorized result code
313+
* @return a list of authorized DataSource objects
311314
*/
312315
@Operation(summary = "authedDatasource", description = "AUTHORIZED_DATA_SOURCE_NOTES")
313316
@Parameters({
@@ -316,29 +319,28 @@ public Result<Object> unAuthDatasource(@Parameter(hidden = true) @RequestAttribu
316319
@GetMapping(value = "/authed-datasource")
317320
@ResponseStatus(HttpStatus.OK)
318321
@ApiException(AUTHORIZED_DATA_SOURCE)
319-
public Result<Object> authedDatasource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
320-
@RequestParam("userId") Integer userId) {
322+
public Result<Object> getAuthorizedDatasourceList(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
323+
@RequestParam("userId") Integer userId) {
321324
List<DataSource> authedDatasourceList = dataSourceService.authedDatasource(loginUser, userId);
322325
return Result.success(authedDatasourceList);
323326
}
324327

325328
/**
326-
* get user info
329+
* check the active status of Kerberos authentication
327330
*
328-
* @param loginUser login user
329-
* @return user info data
331+
* @return {@code true} if Kerberos is active and configured for HDFS; {@code false} otherwise
330332
*/
331-
@Operation(summary = "getKerberosStartupState", description = "GET_USER_INFO_NOTES")
333+
@Operation(summary = "getKerberosStartupState", description = "GET_KERBEROS_STARTUP_STATE")
332334
@GetMapping(value = "/kerberos-startup-state")
333335
@ResponseStatus(HttpStatus.OK)
334336
@ApiException(KERBEROS_STARTUP_STATE)
335-
public Result<Object> getKerberosStartupState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
337+
public Result<Object> getKerberosStartupState() {
336338
// if upload resource is HDFS and kerberos startup is true , else false
337339
return success(Status.SUCCESS.getMsg(), CommonUtils.getKerberosStartupState());
338340
}
339341

340342
/**
341-
* Retrieves the list of tables within a specific database of a data source.
343+
* query the list of tables within a specific database of a data source
342344
*
343345
* @param loginUser the current logged-in user (injected from session)
344346
* @param datasourceId the unique identifier of the data source
@@ -361,7 +363,7 @@ public Result<Object> getTables(@Parameter(hidden = true) @RequestAttribute(valu
361363
}
362364

363365
/**
364-
* Retrieves the column details (schema) for a specific table.
366+
* query the column details (schema) for a specific table
365367
*
366368
* @param loginUser the current logged-in user (injected from session)
367369
* @param datasourceId the unique identifier of the data source
@@ -387,7 +389,7 @@ public Result<Object> getTableColumns(@Parameter(hidden = true) @RequestAttribut
387389
}
388390

389391
/**
390-
* Retrieves the list of databases available in a specific data source.
392+
* query the list of databases available in a specific data source
391393
*
392394
* @param loginUser the current logged-in user (injected from session)
393395
* @param datasourceId the unique identifier of the data source

dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataSourceService.java

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,36 @@
2929
import java.util.List;
3030

3131
/**
32-
* data source service
32+
* datasource service
3333
*/
3434
public interface DataSourceService {
3535

3636
/**
37-
* create data source
37+
* create a new datasource
3838
*
3939
* @param loginUser login user
40-
* @param datasourceParam datasource parameter
41-
* @return create result code
40+
* @param datasourceParam datasource configuration DTO
41+
* @return created {@link DataSource} entity (sensitive fields masked)
42+
* @throws ServiceException if permission denied, security check fails, or connection test fails
4243
*/
4344
DataSource createDataSource(User loginUser, BaseDataSourceParamDTO datasourceParam);
4445

4546
/**
46-
* updateWorkflowInstance datasource
47+
* update datasource
4748
*
4849
* @param loginUser login user
49-
* @param dataSourceParam data source params
50-
* @return update result code
50+
* @param dataSourceParam datasource params
51+
* @return updated {@link DataSource} entity (sensitive fields masked)
52+
* @throws ServiceException if permission denied, security check fails, or connection test fails
5153
*/
5254
DataSource updateDataSource(User loginUser, BaseDataSourceParamDTO dataSourceParam);
5355

5456
/**
55-
* updateWorkflowInstance datasource
57+
* query datasource
5658
*
59+
* @param loginUser login user
5760
* @param id datasource id
58-
* @return data source detail
61+
* @return a {@link BaseDataSourceParamDTO} entity (sensitive fields masked)
5962
*/
6063
BaseDataSourceParamDTO queryDataSource(int id, User loginUser);
6164

@@ -66,38 +69,45 @@ public interface DataSourceService {
6669
* @param searchVal search value
6770
* @param pageNo page number
6871
* @param pageSize page size
69-
* @return data source list page
72+
* @return datasource list page
7073
*/
7174
PageInfo<DataSource> queryDataSourceListPaging(User loginUser, String searchVal, Integer pageNo, Integer pageSize);
7275

7376
/**
7477
* query data resource list
7578
*
7679
* @param loginUser login user
77-
* @param type data source type
78-
* @return data source list page
80+
* @param type datasource type
81+
* @return datasource list
7982
*/
8083
List<DataSource> queryDataSourceList(User loginUser, Integer type);
8184

8285
/**
83-
* verify datasource exists
86+
* verify whether a datasource name already exists
87+
* <p>
88+
* If the name already exists, a {@link ServiceException} is thrown.
89+
* If the name is available (does not exist), the method completes successfully without returning a value.
8490
*
85-
* @param name datasource name
86-
* @return true if data datasource not exists, otherwise return false
91+
* @param name the datasource name to verify
92+
* @throws ServiceException if the datasource name already exists (Status.DATASOURCE_EXIST)
8793
*/
8894
void verifyDataSourceName(String name);
8995

9096
/**
91-
* check connection
97+
* check the connectivity of a datasource based on the provided type and parameters
98+
* <p>
99+
* This method attempts to establish a connection.
100+
* - If the connection is successful, the method returns normally (void).
101+
* - If the connection fails, a {@link ServiceException} is thrown.
92102
*
93-
* @param type data source type
94-
* @param parameter data source parameters
95-
* @return true if connect successfully, otherwise false
103+
* @param type the type of the datasource (e.g., MYSQL, POSTGRESQL)
104+
* @param connectionParam the connection parameters containing host, port, credentials, etc.
105+
* @throws ServiceException if the connection test fails (Status.CONNECTION_TEST_FAILURE)
96106
*/
97-
void checkConnection(DbType type, ConnectionParam parameter);
107+
void checkConnection(DbType type, ConnectionParam connectionParam);
98108

99109
/**
100-
* Tests the connectivity of a specific data source.
110+
* test the connectivity of a specific data source
101111
*
102112
* @param loginUser the current logged-in user (required for permission check)
103113
* @param id the unique identifier of the data source to test
@@ -106,34 +116,34 @@ public interface DataSourceService {
106116
void connectionTest(User loginUser, int id);
107117

108118
/**
109-
* delete datasource
119+
* delete a datasource by ID
110120
*
111-
* @param loginUser login user
112-
* @param datasourceId data source id
113-
* @return delete result code
121+
* @param loginUser the current logged-in user
122+
* @param datasourceId the unique identifier of the datasource to delete
123+
* @throws ServiceException if checks fail or deletion encounters an error
114124
*/
115125
void delete(User loginUser, int datasourceId);
116126

117127
/**
118-
* unauthorized datasource
128+
* query the list of unauthorized data sources for a specific user
119129
*
120130
* @param loginUser login user
121131
* @param userId user id
122-
* @return unauthed data source result code
132+
* @return a list of {@link DataSource} objects that are available to be authorized to the target user
123133
*/
124134
List<DataSource> unAuthDatasource(User loginUser, Integer userId);
125135

126136
/**
127-
* authorized datasource
137+
* query the list of data sources authorized for a specific user
128138
*
129139
* @param loginUser login user
130140
* @param userId user id
131-
* @return authorized result code
141+
* @return a list of {@link DataSource} objects that are authorized to the target user
132142
*/
133143
List<DataSource> authedDatasource(User loginUser, Integer userId);
134144

135145
/**
136-
* Retrieves the list of tables from a specific database within a data source.
146+
* query the list of tables from a specific database within a data source
137147
*
138148
* @param loginUser the current logged-in user (required for permission check)
139149
* @param datasourceId the unique identifier of the data source
@@ -144,7 +154,7 @@ public interface DataSourceService {
144154
List<ParamsOptions> getTables(User loginUser, Integer datasourceId, String database);
145155

146156
/**
147-
* Retrieves the list of columns for a specific table in a data source.
157+
* query the list of columns for a specific table in a data source
148158
*
149159
* @param loginUser current logged-in user
150160
* @param datasourceId ID of the data source
@@ -156,7 +166,7 @@ public interface DataSourceService {
156166
List<ParamsOptions> getTableColumns(User loginUser, Integer datasourceId, String database, String tableName);
157167

158168
/**
159-
* Retrieves the list of databases (or schemas) available in a specific data source.
169+
* query the list of databases (or schemas) available in a specific data source
160170
*
161171
* @param loginUser current logged-in user
162172
* @param datasourceId ID of the data source

0 commit comments

Comments
 (0)