Skip to content

Commit a2d99b8

Browse files
committed
Dropping stat creation from HostStatus
1 parent 515c1a3 commit a2d99b8

2 files changed

Lines changed: 65 additions & 1 deletion

File tree

src/traffic_server/HostStatus.cc

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "tscore/BufferWriter.h"
2727
#include "rpc/jsonrpc/JsonRPC.h"
2828

29+
ts::Rv<YAML::Node> server_get_status(std::string_view const &id, YAML::Node const &params);
2930
ts::Rv<YAML::Node> server_set_status(std::string_view const &id, YAML::Node const &params);
3031

3132
inline void
@@ -214,6 +215,7 @@ HostStatus::HostStatus()
214215
pmgmt->registerMgmtCallback(MGMT_EVENT_HOST_STATUS_DOWN, &mgmt_host_status_down_callback);
215216

216217
rpc::add_method_handler("admin_host_set_status", &server_set_status, &rpc::core_ats_rpc_service_provider_handle);
218+
rpc::add_method_handler("admin_host_get_status", &server_get_status, &rpc::core_ats_rpc_service_provider_handle);
217219
}
218220

219221
HostStatus::~HostStatus()
@@ -466,6 +468,13 @@ struct HostCmdInfo {
466468
int time{0};
467469
};
468470

471+
struct Host {
472+
std::string hostName;
473+
std::string status;
474+
475+
Host(){};
476+
};
477+
469478
} // namespace
470479

471480
namespace YAML
@@ -513,8 +522,63 @@ template <> struct convert<HostCmdInfo> {
513522
return true;
514523
}
515524
};
525+
526+
// encodes a vector of Host's to YAML
527+
template <> struct convert<std::vector<Host>> {
528+
static Node
529+
encode(std::vector<Host> const &hst)
530+
{
531+
YAML::Node node;
532+
for (unsigned long i = 0; i < hst.size(); i++) {
533+
YAML::Node n;
534+
n["hostname"] = hst[i].hostName;
535+
n["status"] = hst[i].status;
536+
node["hosts"].push_back(n);
537+
}
538+
return node;
539+
}
540+
};
516541
} // namespace YAML
517542

543+
ts::Rv<YAML::Node>
544+
server_get_status(std::string_view const &id, YAML::Node const &params)
545+
{
546+
namespace err = rpc::handlers::errors;
547+
ts::Rv<YAML::Node> resp;
548+
std::vector<Host> statuses;
549+
std::stringstream s;
550+
551+
try {
552+
if (!params.IsNull()) {
553+
auto cmdInfo = params.as<HostCmdInfo>();
554+
555+
for (auto const &name : cmdInfo.hosts) {
556+
HostStatRec *host_rec = nullptr;
557+
HostStatus &hs = HostStatus::instance();
558+
host_rec = hs.getHostStatus(name);
559+
if (host_rec == nullptr) {
560+
Debug("host_statuses", "no record for %s was found", name.c_str());
561+
continue;
562+
} else {
563+
Host host;
564+
host.hostName = name;
565+
s << host_rec;
566+
host.status = s.str();
567+
s.str(std::string());
568+
statuses.push_back(host);
569+
}
570+
}
571+
resp.result().push_back(statuses);
572+
} else {
573+
resp.errata().push(err::make_errata(err::Codes::SERVER, "Invalid input parameters, null"));
574+
}
575+
} catch (std::exception const &ex) {
576+
Debug("host_statuses", "Got an error HostCmdInfo decoding: %s", ex.what());
577+
resp.errata().push(err::make_errata(err::Codes::SERVER, "Error found during host status set: {}", ex.what()));
578+
}
579+
return resp;
580+
}
581+
518582
ts::Rv<YAML::Node>
519583
server_set_status(std::string_view const &id, YAML::Node const &params)
520584
{

src/traffic_server/RpcAdminPubHandlers.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ register_admin_jsonrpc_handlers()
6060
rpc::add_method_handler("admin_storage_set_device_offline", &set_storage_offline, &core_ats_rpc_service_provider_handle);
6161
rpc::add_method_handler("admin_storage_get_device_status", &get_storage_status, &core_ats_rpc_service_provider_handle);
6262
}
63-
} // namespace rpc::admin
63+
} // namespace rpc::admin

0 commit comments

Comments
 (0)