| 201 | } |
| 202 | |
| 203 | void |
| 204 | HostStatus::setHostStatus(const std::string_view name, TSHostStatus status, const unsigned int down_time, const unsigned int reason) |
| 205 | { |
| 206 | std::string stat_name; |
| 207 | |
| 208 | // update / insert status. |
| 209 | // using the hash table pointer to store the TSHostStatus value. |
| 210 | HostStatRec *host_stat = nullptr; |
| 211 | ink_rwlock_wrlock(&host_status_rwlock); |
| 212 | { |
| 213 | if (auto it = hosts_statuses.find(std::string(name)); it != hosts_statuses.end()) { |
| 214 | host_stat = it->second; |
| 215 | } else { |
| 216 | host_stat = static_cast<HostStatRec *>(ats_malloc(sizeof(HostStatRec))); |
| 217 | bzero(static_cast<void *>(host_stat), sizeof(HostStatRec)); |
| 218 | hosts_statuses.emplace(name, host_stat); |
| 219 | } |
| 220 | if (reason & Reason::ACTIVE) { |
| 221 | Dbg(dbg_ctl_host_statuses, "for host %.*s set status: %s, Reason:ACTIVE", int(name.size()), name.data(), |
| 222 | HostStatusNames[status]); |
| 223 | if (status == TSHostStatus::TS_HOST_STATUS_DOWN) { |
| 224 | host_stat->active_marked_down = time(0); |
| 225 | host_stat->active_down_time = down_time; |
| 226 | host_stat->reasons |= Reason::ACTIVE; |
| 227 | } else { |
| 228 | host_stat->active_marked_down = 0; |
| 229 | host_stat->active_down_time = 0; |
| 230 | if (host_stat->reasons & Reason::ACTIVE) { |
| 231 | host_stat->reasons ^= Reason::ACTIVE; |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | if (reason & Reason::LOCAL) { |
| 236 | Dbg(dbg_ctl_host_statuses, "for host %.*s set status: %s, Reason:LOCAL", int(name.size()), name.data(), |
| 237 | HostStatusNames[status]); |
| 238 | if (status == TSHostStatus::TS_HOST_STATUS_DOWN) { |
| 239 | host_stat->local_marked_down = time(0); |
| 240 | host_stat->local_down_time = down_time; |
| 241 | host_stat->reasons |= Reason::LOCAL; |
| 242 | } else { |
| 243 | host_stat->local_marked_down = 0; |
| 244 | host_stat->local_down_time = 0; |
| 245 | if (host_stat->reasons & Reason::LOCAL) { |
| 246 | host_stat->reasons ^= Reason::LOCAL; |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | if (reason & Reason::MANUAL) { |
| 251 | Dbg(dbg_ctl_host_statuses, "for host %.*s set status: %s, Reason:MANUAL", int(name.size()), name.data(), |
| 252 | HostStatusNames[status]); |
| 253 | if (status == TSHostStatus::TS_HOST_STATUS_DOWN) { |
| 254 | host_stat->manual_marked_down = time(0); |
| 255 | host_stat->manual_down_time = down_time; |
| 256 | host_stat->reasons |= Reason::MANUAL; |
| 257 | } else { |
| 258 | host_stat->manual_marked_down = 0; |
| 259 | host_stat->manual_down_time = 0; |
| 260 | if (host_stat->reasons & Reason::MANUAL) { |
no test coverage detected