debug output

This commit is contained in:
Grant Limberg
2025-10-01 12:40:50 -07:00
parent b4f018b918
commit f028213c7f
2 changed files with 29 additions and 3 deletions

View File

@@ -314,12 +314,13 @@ bool CentralDB::save(nlohmann::json& record, bool notifyListeners)
}
const std::string objtype = record["objtype"];
if (objtype == "network") {
// fprintf(stderr, "network save\n");
fprintf(stderr, "CentralDB network save %s\n", record["id"].get<std::string>().c_str());
const uint64_t nwid = OSUtils::jsonIntHex(record["id"], 0ULL);
if (nwid) {
nlohmann::json old;
get(nwid, old);
if ((! old.is_object()) || (! _compareRecords(old, record))) {
fprintf(stderr, "posting network change to commit queue\n");
record["revision"] = OSUtils::jsonInt(record["revision"], 0ULL) + 1ULL;
_commitQueue.post(std::pair<nlohmann::json, bool>(record, notifyListeners));
modified = true;
@@ -331,12 +332,12 @@ bool CentralDB::save(nlohmann::json& record, bool notifyListeners)
std::string memberId = record["id"];
const uint64_t nwid = OSUtils::jsonIntHex(record["nwid"], 0ULL);
const uint64_t id = OSUtils::jsonIntHex(record["id"], 0ULL);
// fprintf(stderr, "member save %s-%s\n", networkId.c_str(), memberId.c_str());
fprintf(stderr, "member save %s-%s\n", networkId.c_str(), memberId.c_str());
if ((id) && (nwid)) {
nlohmann::json network, old;
get(nwid, network, id, old);
if ((! old.is_object()) || (! _compareRecords(old, record))) {
// fprintf(stderr, "commit queue post\n");
fprintf(stderr, "posting member change to commit queue\n");
record["revision"] = OSUtils::jsonInt(record["revision"], 0ULL) + 1ULL;
_commitQueue.post(std::pair<nlohmann::json, bool>(record, notifyListeners));
modified = true;

View File

@@ -140,13 +140,22 @@ void PubSubNetworkListener::onNotification(const std::string& payload)
nlohmann::json oldConfig, newConfig;
if (nc.has_old()) {
fprintf(stderr, "has old network config\n");
oldConfig = toJson(nc.old(), nc.change_source());
}
if (nc.has_new_()) {
fprintf(stderr, "has new network config\n");
newConfig = toJson(nc.new_(), nc.change_source());
}
if (! nc.has_old() && ! nc.has_new_()) {
fprintf(stderr, "NetworkChange message has no old or new network config\n");
span->SetAttribute("error", "NetworkChange message has no old or new network config");
span->SetStatus(opentelemetry::trace::StatusCode::kError, "No old or new config");
return;
}
if (oldConfig.is_object() && newConfig.is_object()) {
// network modification
std::string nwid = oldConfig["id"].get<std::string>();
@@ -186,6 +195,13 @@ void PubSubNetworkListener::onNotification(const std::string& payload)
span->SetStatus(opentelemetry::trace::StatusCode::kError, e.what());
return;
}
catch (...) {
fprintf(stderr, "PubSubNetworkListener Unknown exception in PubSubNetworkListener\n");
span->SetAttribute("error", "Unknown exception in PubSubNetworkListener");
span->SetStatus(opentelemetry::trace::StatusCode::kError, "Unknown exception");
return;
}
fprintf(stderr, "PubSubNetworkListener onNotification complete\n");
}
PubSubMemberListener::PubSubMemberListener(std::string controller_id, std::string project, std::string topic, DB* db)
@@ -220,13 +236,22 @@ void PubSubMemberListener::onNotification(const std::string& payload)
nlohmann::json oldConfig, newConfig;
if (mc.has_old()) {
fprintf(stderr, "has old member config\n");
oldConfig = toJson(mc.old(), mc.change_source());
}
if (mc.has_new_()) {
fprintf(stderr, "has new member config\n");
newConfig = toJson(mc.new_(), mc.change_source());
}
if (! mc.has_old() && ! mc.has_new_()) {
fprintf(stderr, "MemberChange message has no old or new member config\n");
span->SetAttribute("error", "MemberChange message has no old or new member config");
span->SetStatus(opentelemetry::trace::StatusCode::kError, "No old or new config");
return;
}
if (oldConfig.is_object() && newConfig.is_object()) {
// member modification
std::string memberID = oldConfig["id"].get<std::string>();