* Inserts the dependency data for a Checkable object into the given Redis HMSETs and runtime updates. * * This function is responsible for serializing the in memory representation Checkable dependencies into * Redis HMSETs and runtime updates (if any) according to the Icinga DB schema. The serialized data consists * of the following Redis HMSETs: * - dependency:node: Contains dependency node
| 1143 | * @param onlyDependencyGroup If set, only process dependency objects from this group. |
| 1144 | */ |
| 1145 | void IcingaDB::InsertCheckableDependencies( |
| 1146 | const Checkable::Ptr& checkable, |
| 1147 | std::map<RedisConnection::QueryArg, RedisConnection::Query>& hMSets, |
| 1148 | std::vector<Dictionary::Ptr>* runtimeUpdates, |
| 1149 | const DependencyGroup::Ptr& onlyDependencyGroup |
| 1150 | ) |
| 1151 | { |
| 1152 | // Only generate a dependency node event if the Checkable is actually part of some dependency graph. |
| 1153 | // That's, it either depends on other Checkables or others depend on it, and in both cases, we have |
| 1154 | // to at least generate a dependency node entry for it. |
| 1155 | if (!checkable->HasAnyDependencies()) { |
| 1156 | return; |
| 1157 | } |
| 1158 | |
| 1159 | // First and foremost, generate a dependency node entry for the provided Checkable object and insert it into |
| 1160 | // the HMSETs map and if set, the `runtimeUpdates` vector. |
| 1161 | auto [host, service] = GetHostService(checkable); |
| 1162 | auto checkableId(GetObjectIdentifier(checkable)); |
| 1163 | { |
| 1164 | Dictionary::Ptr data(new Dictionary{{"environment_id", m_EnvironmentId}, {"host_id", GetObjectIdentifier(host)}}); |
| 1165 | if (service) { |
| 1166 | data->Set("service_id", checkableId); |
| 1167 | } |
| 1168 | |
| 1169 | AddDataToHmSets(hMSets, CONFIG_REDIS_KEY_PREFIX "dependency:node", checkableId, data); |
| 1170 | if (runtimeUpdates) { |
| 1171 | AddObjectDataToRuntimeUpdates(*runtimeUpdates, checkableId, CONFIG_REDIS_KEY_PREFIX "dependency:node", data); |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | // If `onlyDependencyGroup` is provided, process the dependencies only from that group; otherwise, |
| 1176 | // retrieve all the dependency groups that the Checkable object is part of. |
| 1177 | std::vector<DependencyGroup::Ptr> dependencyGroups{onlyDependencyGroup}; |
| 1178 | if (!onlyDependencyGroup) { |
| 1179 | dependencyGroups = checkable->GetDependencyGroups(); |
| 1180 | } |
| 1181 | |
| 1182 | for (auto& dependencyGroup : dependencyGroups) { |
| 1183 | String edgeFromNodeId(checkableId); |
| 1184 | bool syncSharedEdgeState(false); |
| 1185 | |
| 1186 | if (!dependencyGroup->IsRedundancyGroup()) { |
| 1187 | // Non-redundant dependency groups are just placeholders and never get synced to Redis, thus just figure |
| 1188 | // out whether we have to sync the shared edge state. For runtime updates the states are sent via the |
| 1189 | // UpdateDependenciesState() method, thus we don't have to sync them here. |
| 1190 | syncSharedEdgeState = !runtimeUpdates && m_DumpedGlobals.DependencyGroup.IsNew(dependencyGroup->GetCompositeKey()); |
| 1191 | } else { |
| 1192 | auto redundancyGroupId(HashValue(new Array{m_EnvironmentId, dependencyGroup->GetCompositeKey()})); |
| 1193 | dependencyGroup->SetIcingaDBIdentifier(redundancyGroupId); |
| 1194 | |
| 1195 | edgeFromNodeId = redundancyGroupId; |
| 1196 | |
| 1197 | // During the initial config sync, multiple children can depend on the same redundancy group, sync it only |
| 1198 | // the first time it is encountered. Though, if this is a runtime update, we have to re-serialize and sync |
| 1199 | // the redundancy group unconditionally, as we don't know whether it was already synced or the context that |
| 1200 | // triggered this update. |
| 1201 | if (runtimeUpdates || m_DumpedGlobals.DependencyGroup.IsNew(redundancyGroupId)) { |
| 1202 | Dictionary::Ptr groupData(new Dictionary{ |
nothing calls this directly
no test coverage detected