Skip to content

Commit

Permalink
[Fix] fix datasource heartbeat error (DataLinkDC#3298)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzm0809 authored Mar 19, 2024
1 parent 6b19222 commit 436ea7e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,12 @@ public Result<Void> testConnect(@RequestBody DataBaseDTO dataBaseDTO) {
public Result<Void> checkHeartBeatByDataSourceId(@RequestParam Integer id) {
DataBase dataBase = databaseService.getById(id);
Asserts.checkNotNull(dataBase, Status.DATASOURCE_NOT_EXIST.getMessage());
String error = "";
try {
databaseService.checkHeartBeat(dataBase);
} catch (Exception e) {
error = e.getMessage();
}
String checkedHeartBeat = databaseService.checkHeartBeat(dataBase);
databaseService.updateById(dataBase);
if (Asserts.isNotNullString(error)) {
return Result.failed(error);
if (dataBase.getStatus()) {
return Result.succeed(Status.DATASOURCE_CONNECT_NORMAL);
}
return Result.succeed(Status.DATASOURCE_CONNECT_NORMAL);
return Result.paramsError(Status.DATASOURCE_CONNECT_ERROR, checkedHeartBeat);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public interface DataBaseService extends ISuperService<DataBase> {
* @param dataBase {@link DataBase}
* @return {@link Boolean}
*/
Boolean checkHeartBeat(DataBase dataBase);
String checkHeartBeat(DataBase dataBase);

/**
* save or update database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,14 @@ public String testConnect(DataBaseDTO db) {
}

@Override
public Boolean checkHeartBeat(DataBase db) {
boolean isHealthy = false;
public String checkHeartBeat(DataBase db) {
String result = "";
db.setHeartbeatTime(LocalDateTime.now());
try {
isHealthy = Asserts.isEquals(
CommonConstant.HEALTHY,
Driver.buildUnconnected(db.getName(), db.getType(), db.getConnectConfig())
.test());
if (isHealthy) {
db.setHealthTime(LocalDateTime.now());
}
} catch (Exception e) {
isHealthy = false;
throw e;
} finally {
db.setStatus(isHealthy);
}
return isHealthy;
result = Driver.buildUnconnected(db.getName(), db.getType(), db.getConnectConfig())
.test();
db.setStatus(Asserts.isEquals(CommonConstant.HEALTHY, result));

return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public enum Status {

DATASOURCE_EXIST_RELATIONSHIP(11006, "datasource.exist.relationship"),

DATASOURCE_CONNECT_ERROR(11007, "datasource.connect.error"),
/**
* job or task about
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ change.password.failed=Change Password Failed
menu.name.exist=Menu Already Exists
ds.task.type.not.support=DolphinScheduler Type Is [{}] Not Support, Not DINKY Type
datasource.connect.normal=DataSource Connect Normal
datasource.connect.error=DataSource Connect Error: {0}
restart.success=Restart Successfully
test.msg.job.log.url=Click to view the exception log for this task
user.assign.role.success=User Assign Role Success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ change.password.failed=修改密码失败
menu.name.exist=菜单已存在
ds.task.type.not.support=海豚调度类型为 [{}] 不支持,非DINKY类型
datasource.connect.normal=数据源连接正常
datasource.connect.error=数据源连接异常: {0}
restart.success=重启成功
test.msg.job.log.url=点击查看该任务的异常日志
user.assign.role.success=用户分配角色成功
Expand Down

0 comments on commit 436ea7e

Please sign in to comment.