2017-06-16 17:00:49 +08:00
|
|
|
/**
|
|
|
|
* Copyright (C) 2015-2018
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* AUTHOR(S)
|
|
|
|
* Zheng Shuxin
|
|
|
|
* E-mail: zhengshuxin@qiyi.com
|
|
|
|
*
|
|
|
|
* VERSION
|
|
|
|
* Fri 16 Jun 2017 10:48:20 AM CST
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "master/master_api.h"
|
2017-09-22 18:05:34 +08:00
|
|
|
#include "manage/http_client.h"
|
2017-06-16 17:00:49 +08:00
|
|
|
#include "service_list.h"
|
|
|
|
|
|
|
|
void service_list::add_one(list_res_t& res, const ACL_MASTER_SERV* serv)
|
|
|
|
{
|
|
|
|
serv_info_t info;
|
|
|
|
|
2017-07-21 09:37:13 +08:00
|
|
|
info.status = 200;
|
2017-06-16 17:00:49 +08:00
|
|
|
info.name = serv->name;
|
2017-06-26 12:34:23 +08:00
|
|
|
info.type = serv->type;
|
2018-01-03 18:59:37 +08:00
|
|
|
info.start = serv->start;
|
2017-06-16 17:00:49 +08:00
|
|
|
info.path = serv->path;
|
2017-07-17 15:30:52 +08:00
|
|
|
info.conf = serv->conf;
|
2018-01-23 18:57:29 +08:00
|
|
|
info.version = serv->version;
|
2017-06-16 17:00:49 +08:00
|
|
|
info.proc_max = serv->max_proc;
|
|
|
|
info.proc_prefork = serv->prefork_proc;
|
|
|
|
info.proc_total = serv->total_proc;
|
|
|
|
info.proc_avail = serv->avail_proc;
|
|
|
|
info.throttle_delay = serv->throttle_delay;
|
|
|
|
info.listen_fd_count = serv->listen_fd_count;
|
|
|
|
|
|
|
|
if (serv->owner && *serv->owner)
|
|
|
|
info.owner = serv->owner;
|
|
|
|
if (serv->notify_addr && *serv->notify_addr)
|
|
|
|
info.notify_addr = serv->notify_addr;
|
|
|
|
if (serv->notify_recipients && *serv->notify_recipients)
|
|
|
|
info.notify_recipients = serv->notify_recipients;
|
|
|
|
|
|
|
|
ACL_ITER iter;
|
2017-09-24 21:10:28 +08:00
|
|
|
acl_foreach(iter, serv->children_env) {
|
2017-06-16 17:00:49 +08:00
|
|
|
ACL_MASTER_NV* v = (ACL_MASTER_NV *) iter.data;
|
|
|
|
info.env[v->name] = v->value;
|
|
|
|
}
|
|
|
|
|
2017-07-24 16:06:29 +08:00
|
|
|
ACL_RING_ITER iter2;
|
2017-09-24 21:10:28 +08:00
|
|
|
acl_ring_foreach(iter2, &serv->children) {
|
2017-07-24 16:06:29 +08:00
|
|
|
ACL_MASTER_PROC* proc = (ACL_MASTER_PROC *)
|
|
|
|
acl_ring_to_appl(iter2.ptr, ACL_MASTER_PROC, me);
|
|
|
|
proc_info_t pi;
|
|
|
|
pi.pid = proc->pid;
|
|
|
|
pi.start = proc->start;
|
|
|
|
info.procs.push_back(pi);
|
2017-07-21 15:38:28 +08:00
|
|
|
}
|
|
|
|
|
2017-06-16 17:00:49 +08:00
|
|
|
res.data.push_back(info);
|
|
|
|
}
|
|
|
|
|
2017-09-22 18:05:34 +08:00
|
|
|
bool service_list::run(acl::json& json)
|
|
|
|
{
|
|
|
|
list_req_t req;
|
|
|
|
list_res_t res;
|
|
|
|
|
2017-09-24 21:10:28 +08:00
|
|
|
if (deserialize<list_req_t>(json, req) == false) {
|
2017-09-22 18:05:34 +08:00
|
|
|
res.status = 400;
|
|
|
|
res.msg = "invalid json";
|
|
|
|
client_.reply<list_res_t>(res.status, res);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return handle(req, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool service_list::handle(const list_req_t&, list_res_t& res)
|
2017-06-16 17:00:49 +08:00
|
|
|
{
|
|
|
|
ACL_MASTER_SERV *serv;
|
|
|
|
|
|
|
|
for (serv = acl_var_master_head; serv != 0; serv = serv->next)
|
|
|
|
add_one(res, serv);
|
|
|
|
|
|
|
|
res.status = 200;
|
|
|
|
res.msg = "ok";
|
|
|
|
|
2018-01-19 10:16:14 +08:00
|
|
|
client_.reply<list_res_t>(res.status, res, false);
|
2017-09-22 18:05:34 +08:00
|
|
|
client_.on_finish();
|
|
|
|
|
2017-06-16 17:00:49 +08:00
|
|
|
return true;
|
|
|
|
}
|