瀏覽代碼

debug output

Grant Limberg 3 周之前
父節點
當前提交
f028213c7f
共有 2 個文件被更改,包括 29 次插入3 次删除
  1. 4 3
      nonfree/controller/CentralDB.cpp
  2. 25 0
      nonfree/controller/PubSubListener.cpp

+ 4 - 3
nonfree/controller/CentralDB.cpp

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

+ 25 - 0
nonfree/controller/PubSubListener.cpp

@@ -140,13 +140,22 @@ void PubSubNetworkListener::onNotification(const std::string& payload)
 		nlohmann::json oldConfig, newConfig;
 		nlohmann::json oldConfig, newConfig;
 
 
 		if (nc.has_old()) {
 		if (nc.has_old()) {
+			fprintf(stderr, "has old network config\n");
 			oldConfig = toJson(nc.old(), nc.change_source());
 			oldConfig = toJson(nc.old(), nc.change_source());
 		}
 		}
 
 
 		if (nc.has_new_()) {
 		if (nc.has_new_()) {
+			fprintf(stderr, "has new network config\n");
 			newConfig = toJson(nc.new_(), nc.change_source());
 			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()) {
 		if (oldConfig.is_object() && newConfig.is_object()) {
 			// network modification
 			// network modification
 			std::string nwid = oldConfig["id"].get<std::string>();
 			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());
 		span->SetStatus(opentelemetry::trace::StatusCode::kError, e.what());
 		return;
 		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)
 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;
 		nlohmann::json oldConfig, newConfig;
 
 
 		if (mc.has_old()) {
 		if (mc.has_old()) {
+			fprintf(stderr, "has old member config\n");
 			oldConfig = toJson(mc.old(), mc.change_source());
 			oldConfig = toJson(mc.old(), mc.change_source());
 		}
 		}
 
 
 		if (mc.has_new_()) {
 		if (mc.has_new_()) {
+			fprintf(stderr, "has new member config\n");
 			newConfig = toJson(mc.new_(), mc.change_source());
 			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()) {
 		if (oldConfig.is_object() && newConfig.is_object()) {
 			// member modification
 			// member modification
 			std::string memberID = oldConfig["id"].get<std::string>();
 			std::string memberID = oldConfig["id"].get<std::string>();