JSON-RPC method to mark up or down a host.
| 479 | |
| 480 | // JSON-RPC method to mark up or down a host. |
| 481 | swoc::Rv<YAML::Node> |
| 482 | server_set_status(std::string_view id, YAML::Node const ¶ms) |
| 483 | { |
| 484 | Dbg(dbg_ctl_host_statuses, "id=%s", id.data()); |
| 485 | namespace err = rpc::handlers::errors; |
| 486 | swoc::Rv<YAML::Node> resp; |
| 487 | |
| 488 | try { |
| 489 | if (!params.IsNull()) { |
| 490 | auto cmdInfo = params.as<HostCmdInfo>(); |
| 491 | |
| 492 | for (auto const &name : cmdInfo.hosts) { |
| 493 | HostStatus &hs = HostStatus::instance(); |
| 494 | std::string statName = stat_prefix + name; |
| 495 | Dbg(dbg_ctl_host_statuses, "marking server %s : %s", name.c_str(), |
| 496 | (cmdInfo.type == TSHostStatus::TS_HOST_STATUS_UP ? "up" : "down")); |
| 497 | hs.setHostStatus(name.c_str(), cmdInfo.type, cmdInfo.time, cmdInfo.reasonType); |
| 498 | } |
| 499 | } else { |
| 500 | resp.errata().assign(std::error_code{rpc::handlers::errors::Codes::SERVER}).note("Invalid input parameters, null"); |
| 501 | } |
| 502 | |
| 503 | // schedule a write to the persistent store. |
| 504 | Dbg(dbg_ctl_host_statuses, "updating persistent store"); |
| 505 | eventProcessor.schedule_imm(HostStatusSync::new_instance(), ET_TASK); |
| 506 | } catch (std::exception const &ex) { |
| 507 | Dbg(dbg_ctl_host_statuses, "Got an error HostCmdInfo decoding: %s", ex.what()); |
| 508 | resp.errata() |
| 509 | .assign(std::error_code{rpc::handlers::errors::Codes::SERVER}) |
| 510 | .note("Error found during host status set: {}", ex.what()); |
| 511 | } |
| 512 | return resp; |
| 513 | } |
| 514 | |
| 515 | // method to write host status records to the persistent store. |
| 516 | void |
nothing calls this directly
no test coverage detected