| 49 | } |
| 50 | |
| 51 | void AFCNetServiceManagerModule::HealthCheck(uint64_t timer_id, const AFGUID& entity_id) |
| 52 | { |
| 53 | // check if I need to connect other servers from consul center. |
| 54 | std::vector<ARK_APP_TYPE> target_list; |
| 55 | m_pBusModule->GetTargetBusRelations(target_list); |
| 56 | |
| 57 | if (target_list.empty()) |
| 58 | { |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | auto reg_center = m_pBusModule->GetRegCenter(); |
| 63 | for (auto target : target_list) |
| 64 | { |
| 65 | const auto& name = m_pBusModule->GetAppName(target); |
| 66 | if (name.empty()) |
| 67 | { |
| 68 | continue; |
| 69 | } |
| 70 | |
| 71 | auto ret = m_pConsulModule->GetHealthServices(reg_center.service_name, name); |
| 72 | ret.Then([=](const std::pair<bool, std::string>& response) { |
| 73 | if (!response.first) |
| 74 | { |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | using json = nlohmann::json; |
| 79 | |
| 80 | json resp_json = json::parse(response.second); |
| 81 | if (!resp_json.is_array()) |
| 82 | { |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | for (json::iterator iter = resp_json.begin(); iter != resp_json.end(); ++iter) |
| 87 | { |
| 88 | auto& health_check_json = iter.value(); |
| 89 | auto& service_json = health_check_json["Service"]; |
| 90 | if (!service_json.is_object()) |
| 91 | { |
| 92 | continue; |
| 93 | } |
| 94 | |
| 95 | consul::service_data service_msg; |
| 96 | google::protobuf::util::JsonParseOptions option; |
| 97 | option.ignore_unknown_fields = true; |
| 98 | auto status = google::protobuf::util::JsonStringToMessage(service_json.dump(), &service_msg, option); |
| 99 | if (!status.ok()) |
| 100 | { |
| 101 | continue; |
| 102 | } |
| 103 | |
| 104 | auto find_iter = service_msg.meta().find("busid"); |
| 105 | if (find_iter == service_msg.meta().end()) |
| 106 | { |
| 107 | ARK_LOG_ERROR("service={} do not have Meta=busid, please check it.", service_msg.id()); |
| 108 | return; |
nothing calls this directly
no test coverage detected