MCPcopy Create free account
hub / github.com/Icinga/icinga2 / GetCompositeKey

Method GetCompositeKey

lib/icinga/dependency-group.cpp:286–310  ·  view source on GitHub ↗

* Retrieve the unique composite key of the current dependency group. * * The composite key consists of some unique data of the group members, and should be used to generate * a unique deterministic hash for the dependency group. Additionally, for explicitly configured redundancy * groups, the non-unique dependency group name is also included on top of the composite keys. * * @return - Return

Source from the content-addressed store, hash-verified

284 * @return - Returns the composite key of the current dependency group.
285 */
286String DependencyGroup::GetCompositeKey()
287{
288 // This a copy of the CompositeKeyType definition but with the String type instead of Checkable* and TimePeriod*.
289 // This is because we need to produce a deterministic value from the composite key after each restart and that's
290 // not achievable using pointers.
291 using StringTuple = std::tuple<String, String, int, bool>;
292 std::vector<StringTuple> compositeKeys;
293 for (auto& [compositeKey, _] : m_Members) {
294 auto [parent, tp, stateFilter, ignoreSoftStates] = compositeKey;
295 compositeKeys.emplace_back(parent->GetName(), tp ? tp->GetName() : "", stateFilter, ignoreSoftStates);
296 }
297
298 // IMPORTANT: The order of the composite keys must be sorted to ensure the deterministic hash value.
299 std::sort(compositeKeys.begin(), compositeKeys.end());
300
301 Array::Ptr data(new Array{GetRedundancyGroupName()});
302 for (auto& compositeKey : compositeKeys) {
303 // std::apply is used to unpack the composite key tuple and add its elements to the data array.
304 // It's like manually expanding the tuple into x variables and then adding them one by one to the array.
305 // See https://en.cppreference.com/w/cpp/language/fold for more information.
306 std::apply([&data](auto&&... args) { (data->Add(std::move(args)), ...); }, std::move(compositeKey));
307 }
308
309 return PackObject(data);
310}
311
312/**
313 * Retrieve the state of the current dependency group.

Calls 4

GetNameMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected