Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
add heartbeat detection (#4)
Browse files Browse the repository at this point in the history
* add heartbeat detect

* add for db ut

* fix ut stop shell

* fix db ut

* add heartbeat count

* add test for self increment jobid and getting job status by id

* fix ut, fix proto

* fix ut

* fix ut
  • Loading branch information
SonglinLyu authored Oct 21, 2023
1 parent 6998d24 commit 6dcacc0
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.antgroup.tugraph;

public interface HeartbeatService {
TuGraphDBManagement.HeartbeatResponse detectHeartbeat(TuGraphDBManagement.HeartbeatRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.antgroup.tugraph;

import com.baidu.cloud.starlight.springcloud.server.annotation.RpcService;
import lombok.extern.slf4j.Slf4j;

@RpcService
@Slf4j
public class HeartbeatServiceImpl implements HeartbeatService {

@Override
public TuGraphDBManagement.HeartbeatResponse detectHeartbeat(TuGraphDBManagement.HeartbeatRequest request) {
log.info("get heartbeat request");
String reqMsg = request.getRequestMsg();
log.info(reqMsg);
String respMsg = "This is a heartbeat response message.";
int heartbeatCount = request.getHeartbeatCount();
TuGraphDBManagement.HeartbeatResponse.Builder respBuilder =
TuGraphDBManagement.HeartbeatResponse
.newBuilder();
respBuilder
.setResponseMsg(respMsg)
.setHeartbeatCount(heartbeatCount + 1);
return respBuilder.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ public TuGraphDBManagement.ReadJobResponse handleReadJobRequest(TuGraphDBManagem
TuGraphDBManagement.ReadJobResponse
.newBuilder();
TuGraphDBManagement.ReadJobResponse resp;
try {
List<Job> tempJobList = jobService.listStatus();
for (Job tempJob: tempJobList) {
if (request.hasJobId()) {
try {
Job tempJob = jobService.getStatusById(request.getJobId());
TuGraphDBManagement.Job Job =
TuGraphDBManagement.Job.newBuilder()
.setDbId(tempJob.getDbId())
Expand All @@ -149,14 +149,41 @@ public TuGraphDBManagement.ReadJobResponse handleReadJobRequest(TuGraphDBManagem
.setCreateTime(tempJob.getCreateTime())
.build();
respBuilder.addJob(Job);
resp = respBuilder
.setResponseCode(TuGraphDBManagement.ResponseCode.SUCCESS)
.build();
} catch (Exception e) {
resp = respBuilder
.setResponseCode(TuGraphDBManagement.ResponseCode.FAILED)
.build();
}
} else {
try {
List<Job> tempJobList = jobService.listStatus();
for (Job tempJob: tempJobList) {
TuGraphDBManagement.Job Job =
TuGraphDBManagement.Job.newBuilder()
.setDbId(tempJob.getDbId())
.setJobId(tempJob.getJobId())
.setStartTime(tempJob.getStartTime())
.setPeriod(tempJob.getPeriod())
.setProcedureName(tempJob.getProcedureName())
.setProcedureType(tempJob.getProcedureType())
.setStatus(tempJob.getStatus())
.setRuntime(tempJob.getRuntime())
.setUser(tempJob.getUser())
.setCreateTime(tempJob.getCreateTime())
.build();
respBuilder.addJob(Job);
}
resp = respBuilder
.setResponseCode(TuGraphDBManagement.ResponseCode.SUCCESS)
.build();
} catch (Exception e) {
resp = respBuilder
.setResponseCode(TuGraphDBManagement.ResponseCode.FAILED)
.build();
}
resp = respBuilder
.setResponseCode(TuGraphDBManagement.ResponseCode.SUCCESS)
.build();
} catch (Exception e) {
resp = respBuilder
.setResponseCode(TuGraphDBManagement.ResponseCode.FAILED)
.build();
}

return resp;
Expand Down
74 changes: 44 additions & 30 deletions src/main/proto/tugraph_db_management.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,37 @@ enum ResponseCode {
message Job {
required string db_id = 1;
required int32 job_id = 2;
required int64 start_time = 4;
required string period = 5;
required string procedure_name = 6;
required string procedure_type = 7;
required string status = 8;
required int64 runtime = 3;
required int64 start_time = 3;
required string period = 4;
required string procedure_name = 5;
required string procedure_type = 6;
required string status = 7;
required int64 runtime = 8;
required string user = 9;
required int64 create_time = 10;
}

message JobResult {
required int32 job_id = 2;
required string result = 1;
required int32 job_id = 1;
required string result = 2;
}

message CreateJobRequest {
required int64 start_time = 3;
required string period = 4;
required string procedure_name = 5;
required string procedure_type = 6;
required string user = 7;
required int64 create_time = 8;
required int64 start_time = 1;
required string period = 2;
required string procedure_name = 3;
required string procedure_type = 4;
required string user = 5;
required int64 create_time = 6;
}

message CreateJobResponse {
required int32 job_id = 2;
required ResponseCode response_code = 1;
required int32 job_id = 1;
required ResponseCode response_code = 2;
}

message ReadJobRequest {

optional int32 job_id = 1;
}

message ReadJobResponse {
Expand Down Expand Up @@ -96,28 +96,42 @@ message DeleteJobResponse {
}

message JobManagementRequest {
required string db_host = 5;
required string db_port = 6;
required string db_host = 1;
required string db_port = 2;
oneof Req {
CreateJobRequest create_job_request = 1;
ReadJobRequest read_job_request = 2;
ReadJobResultRequest read_job_result_request = 7;
UpdateJobRequest update_job_request = 3;
DeleteJobRequest delete_job_request = 4;
CreateJobRequest create_job_request = 3;
ReadJobRequest read_job_request = 4;
ReadJobResultRequest read_job_result_request = 5;
UpdateJobRequest update_job_request = 6;
DeleteJobRequest delete_job_request = 7;
};
};

message JobManagementResponse {
required ResponseCode response_code = 5;
required ResponseCode response_code = 1;
oneof Resp {
CreateJobResponse create_job_response = 1;
ReadJobResponse read_job_response = 2;
ReadJobResultResponse read_job_result_response = 6;
UpdateJobResponse update_job_response = 3;
DeleteJobResponse delete_job_response = 4;
CreateJobResponse create_job_response = 2;
ReadJobResponse read_job_response = 3;
ReadJobResultResponse read_job_result_response = 4;
UpdateJobResponse update_job_response = 5;
DeleteJobResponse delete_job_response = 6;
};
};

message HeartbeatRequest {
required string request_msg = 1;
required int32 heartbeat_count = 2;
};

message HeartbeatResponse {
required string response_msg = 1;
required int32 heartbeat_count = 2;
};

service JobManagementService {
rpc handleRequest(JobManagementRequest) returns (JobManagementResponse);
};

service HeartbeatService {
rpc detectHeartbeat(HeartbeatRequest) returns (HeartbeatResponse);
}
14 changes: 14 additions & 0 deletions src/main/resources/application-ut.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Application Name
spring.application.name=TuGraphDB Management
spring.profiles.active=ut
server.port=5071
# logging path
logging.path=./logs

starlight.server.enable = true
starlight.server.port = 5091

spring.datasource.driver-class-name=org.sqlite.JDBC
spring.datasource.url=jdbc:sqlite:tugraph_db_management_ut.db
spring.main.allow-bean-definition-overriding=true

Loading

0 comments on commit 6dcacc0

Please sign in to comment.