增加获取版本号API
This commit is contained in:
@@ -329,6 +329,46 @@ void doris_http_server_file_cb(struct evhttp_request *req, void *arg)
|
||||
evhttp_clear_headers(¶ms);
|
||||
}
|
||||
|
||||
void doris_http_server_version_cb(struct evhttp_request *req, void *arg)
|
||||
{
|
||||
struct evkeyvalq params;
|
||||
const char *bizname;
|
||||
struct doris_business *business;
|
||||
map<string, struct doris_business*>::iterator iter;
|
||||
char verbuf[32];
|
||||
|
||||
if(evhttp_parse_query(evhttp_request_get_uri(req), ¶ms))
|
||||
{
|
||||
FS_operate(g_doris_server_info.fsstat_handle, g_doris_server_info.fsstat_field[DRS_FSSTAT_CLIENT_INVALID_REQ], 0, FS_OP_ADD, 1);
|
||||
evhttp_send_error(req, HTTP_BADREQUEST, "Parameters invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
if(NULL == (bizname = evhttp_find_header(¶ms, "business")))
|
||||
{
|
||||
FS_operate(g_doris_server_info.fsstat_handle, g_doris_server_info.fsstat_field[DRS_FSSTAT_CLIENT_INVALID_REQ], 0, FS_OP_ADD, 1);
|
||||
evhttp_clear_headers(¶ms);
|
||||
evhttp_send_error(req, HTTP_BADREQUEST, "Parameters invalid, no business found");
|
||||
return;
|
||||
}
|
||||
if((iter = g_doris_server_info.name2business->find(string(bizname)))==g_doris_server_info.name2business->end())
|
||||
{
|
||||
FS_operate(g_doris_server_info.fsstat_handle, g_doris_server_info.fsstat_field[DRS_FSSTAT_CLIENT_INVALID_REQ], 0, FS_OP_ADD, 1);
|
||||
evhttp_clear_headers(¶ms);
|
||||
evhttp_send_error(req, HTTP_BADREQUEST, "Parameters invalid, business invalid");
|
||||
return;
|
||||
}
|
||||
evhttp_clear_headers(¶ms);
|
||||
business = iter->second;
|
||||
|
||||
pthread_rwlock_rdlock(&business->rwlock);
|
||||
sprintf(verbuf, "%lu", business->cfgver_head->latest_version);
|
||||
pthread_rwlock_unlock(&business->rwlock);
|
||||
|
||||
evhttp_add_header(evhttp_request_get_output_headers(req), "X-Latest-Version", verbuf);
|
||||
evhttp_send_reply(req, HTTP_OK, "OK", NULL);
|
||||
}
|
||||
|
||||
void doris_http_server_generic_cb(struct evhttp_request *req, void *arg)
|
||||
{
|
||||
evhttp_send_error(req, HTTP_BADREQUEST, "Not Supported.");
|
||||
@@ -448,6 +488,7 @@ void* thread_doris_http_server(void *arg)
|
||||
|
||||
evhttp_set_cb(worker_http, "/configmeta", doris_http_server_meta_cb, NULL);
|
||||
evhttp_set_cb(worker_http, "/configfile", doris_http_server_file_cb, NULL);
|
||||
evhttp_set_cb(worker_http, "/latestversion", doris_http_server_version_cb, NULL);
|
||||
evhttp_set_gencb(worker_http, doris_http_server_generic_cb, NULL);
|
||||
evhttp_set_allowed_methods(worker_http, EVHTTP_REQ_GET|EVHTTP_REQ_HEAD);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user