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

Method UpdateObject

lib/db_ido/dbconnection.cpp:444–501  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

442}
443
444void DbConnection::UpdateObject(const ConfigObject::Ptr& object)
445{
446 bool isShuttingDown = Application::IsShuttingDown();
447 bool isRestarting = Application::IsRestarting();
448
449#ifdef I2_DEBUG
450 if (isShuttingDown || isRestarting) {
451 //Log(LogDebug, "DbConnection")
452 // << "Updating object '" << object->GetName() << "' \t\t active '" << Convert::ToLong(object->IsActive())
453 // << "' shutting down '" << Convert::ToLong(isShuttingDown) << "' restarting '" << Convert::ToLong(isRestarting) << "'.";
454 }
455#endif /* I2_DEBUG */
456
457 /* Wait until a database connection is established on reconnect. */
458 if (!GetConnected())
459 return;
460
461 /* Don't update inactive objects during shutdown/reload/restart.
462 * They would be marked as deleted. This gets triggered with ConfigObject::StopObjects().
463 * During startup/reconnect this is fine, the handler is not active there.
464 */
465 if (isShuttingDown || isRestarting)
466 return;
467
468 DbObject::Ptr dbobj = DbObject::GetOrCreateByObject(object);
469
470 if (dbobj) {
471 bool dbActive = GetObjectActive(dbobj);
472 bool active = object->IsActive();
473
474 if (active) {
475 if (!dbActive)
476 ActivateObject(dbobj);
477
478 Dictionary::Ptr configFields = dbobj->GetConfigFields();
479 String configHash = dbobj->CalculateConfigHash(configFields);
480 ASSERT(configHash.GetLength() <= 64);
481 configFields->Set("config_hash", configHash);
482
483 String cachedHash = GetConfigHash(dbobj);
484
485 if (cachedHash != configHash) {
486 dbobj->SendConfigUpdateHeavy(configFields);
487 dbobj->SendStatusUpdate();
488 } else {
489 dbobj->SendConfigUpdateLight();
490 }
491 } else if (!active) {
492 /* This may happen on reload/restart actions too
493 * and is blocked above already.
494 *
495 * Deactivate the deleted object no matter
496 * which state it had in the database.
497 */
498 DeactivateObject(dbobj);
499 }
500 }
501}

Callers

nothing calls this directly

Calls 8

IsActiveMethod · 0.80
SendConfigUpdateHeavyMethod · 0.80
SendStatusUpdateMethod · 0.80
SendConfigUpdateLightMethod · 0.80
GetConfigFieldsMethod · 0.45
CalculateConfigHashMethod · 0.45
GetLengthMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected