brbzull0 commented on a change in pull request #8689:
URL: https://github.com/apache/trafficserver/pull/8689#discussion_r827910733



##########
File path: src/traffic_server/HostStatus.cc
##########
@@ -20,85 +20,32 @@
   See the License for the specific language governing permissions and
   limitations under the License.
  */
+#include <fstream>
 #include "HostStatus.h"
 #include "ProcessManager.h"
 
 #include "tscore/BufferWriter.h"
 #include "rpc/jsonrpc/JsonRPC.h"
+#include "shared/rpc/RPCRequests.h"
 
-ts::Rv<YAML::Node> server_set_status(std::string_view const &id, YAML::Node 
const &params);
-
-inline void
-getStatName(std::string &stat_name, const std::string_view name)
-{
-  stat_name.clear();
-  stat_name.append(stat_prefix).append(name);
-}
-
-static void
-mgmt_host_status_up_callback(ts::MemSpan<void> span)
+namespace
 {
-  MgmtInt op;
-  MgmtMarshallString name;
-  MgmtMarshallInt down_time;
-  MgmtMarshallString reason_str;
-  std::string stat_name;
-  char buf[1024]                         = {0};
-  char *data                             = static_cast<char *>(span.data());
-  auto len                               = span.size();
-  static const MgmtMarshallType fields[] = {MGMT_MARSHALL_INT, 
MGMT_MARSHALL_STRING, MGMT_MARSHALL_STRING, MGMT_MARSHALL_INT};
-  Debug("host_statuses", "%s:%s:%d - data: %s, len: %ld\n", __FILE__, 
__func__, __LINE__, data, len);
-
-  if (mgmt_message_parse(data, len, fields, countof(fields), &op, &name, 
&reason_str, &down_time) == -1) {
-    Error("Plugin message - RPC parsing error - message discarded.");
-  }
-  Debug("host_statuses", "op: %ld, name: %s, down_time: %d, reason_str: %s", 
static_cast<long>(op), name,
-        static_cast<int>(down_time), reason_str);
+const std::string STATUS_LIST_KEY{"statusList"};
+const std::string ERROR_LIST_KEY{"errorList"};
+const std::string HOST_NAME_KEY{"hostname"};
+const std::string STATUS_KEY{"status"};
 
-  unsigned int reason = Reason::getReason(reason_str);
-
-  getStatName(stat_name, name);
-  if (data != nullptr) {
-    Debug("host_statuses", "marking up server %s", data);
-    HostStatus &hs = HostStatus::instance();
-    if (hs.getHostStat(stat_name, buf, 1024) == REC_ERR_FAIL) {
-      hs.createHostStat(name);
-    }
-    hs.setHostStatus(name, TSHostStatus::TS_HOST_STATUS_UP, down_time, reason);
-  }
-}
-
-static void
-mgmt_host_status_down_callback(ts::MemSpan<void> span)
-{
-  MgmtInt op;
-  MgmtMarshallString name;
-  MgmtMarshallInt down_time;
-  MgmtMarshallString reason_str;
-  std::string stat_name;
-  char *data                             = static_cast<char *>(span.data());
-  char buf[1024]                         = {0};
-  auto len                               = span.size();
-  static const MgmtMarshallType fields[] = {MGMT_MARSHALL_INT, 
MGMT_MARSHALL_STRING, MGMT_MARSHALL_STRING, MGMT_MARSHALL_INT};
-  Debug("host_statuses", "%s:%s:%d - data: %s, len: %ld\n", __FILE__, 
__func__, __LINE__, data, len);
-
-  if (mgmt_message_parse(data, len, fields, countof(fields), &op, &name, 
&reason_str, &down_time) == -1) {
-    Error("Plugin message - RPC parsing error - message discarded.");
-  }
-  Debug("host_statuses", "op: %ld, name: %s, down_time: %d, reason_str: %s", 
static_cast<long>(op), name,
-        static_cast<int>(down_time), reason_str);
+struct HostCmdInfo {
+  TSHostStatus type{TSHostStatus::TS_HOST_STATUS_INIT};
+  unsigned int reasonType{0};
+  std::vector<std::string> hosts;
+  int time{0};
+};
 
-  unsigned int reason = Reason::getReason(reason_str);
+} // namespace
 
-  if (data != nullptr) {
-    Debug("host_statuses", "marking down server %s", name);
-    HostStatus &hs = HostStatus::instance();
-    if (hs.getHostStat(stat_name, buf, 1024) == REC_ERR_FAIL) {
-      hs.createHostStat(name);
-    }
-    hs.setHostStatus(name, TSHostStatus::TS_HOST_STATUS_DOWN, down_time, 
reason);
-  }
-}
+ts::Rv<YAML::Node> server_get_status(std::string_view const &id, YAML::Node 
const &params);
+ts::Rv<YAML::Node> server_set_status(std::string_view const &id, YAML::Node 
const &params);

Review comment:
       This is the RPC handler API:
   
   
https://github.com/apache/trafficserver/blob/68e69e27b87576abfaa7a1bbeb8394795c522e82/mgmt2/rpc/jsonrpc/JsonRPCManager.h#L64
   
   The reason is `const&` is becase I wanted  to make it clear that this should 
not mutate despite the fact that you cannot change it if it was only a 
`std::string_view`. I always thought that this is ambiguous and if someone try 
to change it well, good luck. Now kind of I am inclined to remove the `const &`
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to