Skip to content

Commit

Permalink
https://telecominfraproject.atlassian.net/browse/WIFI-13172
Browse files Browse the repository at this point in the history
Signed-off-by: stephb9959 <[email protected]>
  • Loading branch information
stephb9959 committed Dec 3, 2023
1 parent 7d5c130 commit 13d2d39
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/framework/MicroService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ namespace OpenWifi {
void MicroService::BusMessageReceived([[maybe_unused]] const std::string &Key,
const std::string &Payload) {
std::lock_guard G(InfraMutex_);

Poco::Logger &BusLogger = Poco::Logger::create(
"BusMessageReceived", Poco::Logger::root().getChannel(), Poco::Logger::root().getLevel());
try {
Poco::JSON::Parser P;
auto Object = P.parse(Payload).extract<Poco::JSON::Object::Ptr>();
Expand All @@ -69,7 +72,7 @@ namespace OpenWifi {
if (Event == KafkaTopics::ServiceEvents::EVENT_LEAVE) {
Services_.erase(PrivateEndPoint);
poco_information(
Logger_,
BusLogger,
fmt::format(
"Service {} ID={} leaving system.",
Object->get(KafkaTopics::ServiceEvents::Fields::PRIVATE)
Expand Down Expand Up @@ -99,7 +102,7 @@ namespace OpenWifi {
Services_[PrivateEndPoint] = ServiceInfo;
if(Event == KafkaTopics::ServiceEvents::EVENT_JOIN) {
poco_information(
Logger_,
BusLogger,
fmt::format(
"Service {} ID={} is joining the system. old={}",
Object->get(KafkaTopics::ServiceEvents::Fields::PRIVATE)
Expand All @@ -113,13 +116,13 @@ namespace OpenWifi {
SvcList += ", " + Svc.second.Type;
}
poco_information(
Logger_,
BusLogger,
fmt::format("Current list of microservices: {}", SvcList));
}
}
} else {
poco_information(
Logger_,
BusLogger,
fmt::format("KAFKA-MSG: invalid event '{}', missing a field.",
Event));
}
Expand All @@ -131,18 +134,18 @@ namespace OpenWifi {
#endif
} else {
poco_information(
Logger_,
BusLogger,
fmt::format("KAFKA-MSG: invalid event '{}', missing token", Event));
}
} else {
poco_information(Logger_,
poco_information(BusLogger,
fmt::format("Unknown Event: {} Source: {}", Event, ID));
}
}
} else {
std::ostringstream os;
Object->stringify(std::cout);
poco_error(Logger_, fmt::format("Bad bus message: {}", os.str()));
poco_error(BusLogger, fmt::format("Bad bus message: {}", os.str()));
}

auto ServiceHint = Services_.begin();
Expand All @@ -151,18 +154,18 @@ namespace OpenWifi {
auto ss1 = MakeServiceListString(Services_);
while(ServiceHint!=Services_.end()) {
if ((now - ServiceHint->second.LastUpdate) > 120) {
poco_information(Logger_, fmt::format("ZombieService: Removing service {}, ", ServiceHint->second.PublicEndPoint));
poco_information(BusLogger, fmt::format("ZombieService: Removing service {}, ", ServiceHint->second.PublicEndPoint));
ServiceHint = Services_.erase(ServiceHint);
} else
++ServiceHint;
}
if(Services_.size() != si1) {
auto ss2 = MakeServiceListString(Services_);
poco_information(Logger_, fmt::format("Current list of microservices: {} -> {}", ss1, ss2));
poco_information(BusLogger, fmt::format("Current list of microservices: {} -> {}", ss1, ss2));
}

} catch (const Poco::Exception &E) {
Logger_.log(E);
BusLogger.log(E);
}
}

Expand Down

0 comments on commit 13d2d39

Please sign in to comment.