22 #include "grpc++/grpc++.h" 23 #include "yaml-cpp/yaml.h" 29 #include "modules/map/tools/map_datachecker/proto/collection_service.grpc.pb.h" 34 template <
typename REQUEST_TYPE,
typename RESPONSE_TYPE>
38 YAML::Node node = YAML::LoadFile(FLAGS_client_conf_yaml);
39 std::string server_addr =
40 node[
"grpc_host_port"][
"grpc_host"].as<std::string>() +
":" +
41 node[
"grpc_host_port"][
"grpc_port"].as<std::string>();
42 check_period_ = node[
"alignment"][
"check_period"].as<
int>();
44 grpc::CreateChannel(server_addr, grpc::InsecureChannelCredentials()));
50 AERROR <<
"start alignment failed";
64 double progress = 0.0;
65 ret = Check(&progress);
67 AERROR <<
"alignment check failed";
70 AINFO <<
"alignment check progress: [" << progress <<
"]";
71 fprintf(
USER_STREAM,
"alignment progress: %.2lf%%\n", progress * 100);
72 if (fabs(progress - 1.0) < 1e-8) {
73 AINFO <<
"diff " << fabs(progress - 1.0);
76 std::this_thread::sleep_for(std::chrono::seconds(check_period_));
83 AERROR <<
"alignment stop failed";
89 int GrpcStub(REQUEST_TYPE* request, RESPONSE_TYPE* response) {
91 if (status.error_code() == grpc::StatusCode::UNAVAILABLE) {
92 AERROR <<
"FATAL Error. Map grpc service is UNAVAILABLE.";
93 fprintf(
USER_STREAM,
"You should start server first\n");
96 AINFO <<
"response error code: " << response->code();
97 if (response->code() != ErrorCode::SUCCESS) {
105 REQUEST_TYPE request;
106 request.set_cmd(CmdType::START);
107 AINFO <<
"alignment request: " 108 <<
"cmd: [" << request.cmd() <<
"]";
109 RESPONSE_TYPE response;
110 return GrpcStub(&request, &response);
113 int Check(
double* progress) {
114 REQUEST_TYPE request;
115 request.set_cmd(CmdType::CHECK);
116 AINFO <<
"alignment request: " 117 <<
"cmd: [" << request.cmd() <<
"]";
118 RESPONSE_TYPE response;
119 int ret =
GrpcStub(&request, &response);
120 *progress = response.progress();
125 REQUEST_TYPE request;
126 request.set_cmd(CmdType::STOP);
127 AINFO <<
"alignment request: " 128 <<
"cmd: [" << request.cmd() <<
"]";
129 RESPONSE_TYPE response;
130 return GrpcStub(&request, &response);
139 RESPONSE_TYPE* response) = 0;
144 StaticAlignResponse* response) {
145 grpc::ClientContext context;
146 return service_stub_->ServiceStaticAlign(&context, *request, response);
152 EightRouteResponse* response) {
153 grpc::ClientContext context;
154 return service_stub_->ServiceEightRoute(&context, *request, response);
virtual grpc::Status GrpcAlignmentStub(REQUEST_TYPE *request, RESPONSE_TYPE *response)=0
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: client_alignment.h:150
Definition: client_alignment.h:142
int PeriodicCheck()
Definition: client_alignment.h:61
#define USER_STREAM
Definition: client_common.h:33
Alignment()
Definition: client_alignment.h:37
std::unique_ptr< CollectionCheckerService::Stub > service_stub_
Definition: client_alignment.h:137
int GrpcStub(REQUEST_TYPE *request, RESPONSE_TYPE *response)
Definition: client_alignment.h:89
int SyncStop()
Definition: client_alignment.h:56
static int ExceptionHandlerFun(ErrorCode error_code)
Definition: client_alignment.h:35
#define AERROR
Definition: log.h:44
int SyncStart()
Definition: client_alignment.h:47
#define AINFO
Definition: log.h:42