Merge pull request #56 from Telecominfraproject/main

https://telecominfraproject.atlassian.net/browse/WIFI-10040
This commit is contained in:
Stephane Bourque
2022-07-01 12:31:50 -07:00
committed by GitHub
6 changed files with 80 additions and 42 deletions

View File

@@ -17,4 +17,10 @@ jobs:
steps:
- run: |
export PR_BRANCH_TAG=$(echo ${GITHUB_HEAD_REF#refs/heads/} | tr '/' '-')
curl -uucentral:${{ secrets.DOCKER_REGISTRY_PASSWORD }} -X DELETE "https://tip.jfrog.io/artifactory/tip-wlan-cloud-ucentral/owsec/$PR_BRANCH_TAG"
if [[ ! $PR_BRANCH_TAG =~ (main|master|release-*) ]]; then
echo "PR branch is $PR_BRANCH_TAG, deleting Docker image"
curl -s -uucentral:${{ secrets.DOCKER_REGISTRY_PASSWORD }} -X DELETE "https://tip.jfrog.io/artifactory/tip-wlan-cloud-ucentral/owsec/$PR_BRANCH_TAG"
else
echo "PR branch is $PR_BRANCH_TAG, not deleting Docker image"
fi

2
build
View File

@@ -1 +1 @@
57
58

View File

@@ -24,6 +24,7 @@ namespace OpenWifi {
void ActionLinkManager::run() {
Running_ = true ;
Utils::SetThreadName("action-mgr");
while(Running_) {
Poco::Thread::trySleep(2000);

View File

@@ -65,7 +65,7 @@ namespace OpenWifi {
void SMTPMailerService::run() {
Running_ = true;
Utils::SetThreadName("smtp-mailer");
while(Running_) {
Poco::Thread::trySleep(10000);

View File

@@ -63,6 +63,7 @@ namespace OpenWifi {
}
void Archiver::onTimer([[maybe_unused]] Poco::Timer &timer) {
Utils::SetThreadName("archiver");
Poco::Logger &logger = Poco::Logger::get("STORAGE-ARCHIVER");
logger.information("Squiggy the DB: removing old tokens.");
StorageService()->SubTokenDB().CleanExpiredTokens();

View File

@@ -643,6 +643,27 @@ namespace OpenWifi::RESTAPI_utils {
namespace OpenWifi::Utils {
inline void SetThreadName(const char *name) {
#ifdef __linux__
Poco::Thread::current()->setName(name);
pthread_setname_np(pthread_self(), name);
#endif
#ifdef __APPLE__
Poco::Thread::current()->setName(name);
pthread_setname_np(name);
#endif
}
inline void SetThreadName(Poco::Thread &thr, const char *name) {
#ifdef __linux__
thr.setName(name);
pthread_setname_np(thr.tid(), name);
#endif
#ifdef __APPLE__
thr.setName(name);
#endif
}
enum MediaTypeEncodings {
PLAIN,
BINARY,
@@ -1167,6 +1188,7 @@ namespace OpenWifi {
static const std::string uSERVICE_SUBCRIBER{ "owsub"};
static const std::string uSERVICE_INSTALLER{ "owinst"};
static const std::string uSERVICE_ANALYTICS{ "owanalytics"};
static const std::string uSERVICE_OWRRM{ "owrrm"};
class ConfigurationEntry {
public:
@@ -1315,7 +1337,7 @@ namespace OpenWifi {
inline void Start();
inline void Stop();
private:
std::atomic_bool Running_ = false;
mutable std::atomic_bool Running_ = false;
Poco::Thread Thread_;
};
@@ -1846,7 +1868,8 @@ namespace OpenWifi {
Request = &RequestIn;
Response = &ResponseIn;
Poco::Thread::current()->setName("WebServerThread_" + std::to_string(TransactionId_));
std::string th_name = "restsvr_" + std::to_string(TransactionId_);
Utils::SetThreadName(th_name.c_str());
if(Request->getContentLength()>0) {
if(Request->getContentType().find("application/json")!=std::string::npos) {
@@ -1895,36 +1918,32 @@ namespace OpenWifi {
[[nodiscard]] inline bool NeedAdditionalInfo() const { return QB_.AdditionalInfo; }
[[nodiscard]] inline const std::vector<std::string> & SelectedRecords() const { return QB_.Select; }
/* [[nodiscard]] inline const Poco::JSON::Object::Ptr ParseStream() {
return IncomingParser_.parse(Request->stream()).extract<Poco::JSON::Object::Ptr>();
}
*/
inline static bool ParseBindings(const std::string & Request, const std::list<std::string> & EndPoints, BindingMap &bindings) {
bindings.clear();
auto PathItems = Poco::StringTokenizer(Request, "/");
inline static bool ParseBindings(const std::string & Request, const std::list<std::string> & EndPoints, BindingMap &bindings) {
bindings.clear();
std::vector<std::string> PathItems = Utils::Split(Request, '/');
for(const auto &EndPoint:EndPoints) {
auto ParamItems = Poco::StringTokenizer(EndPoint, "/");
if (PathItems.count() != ParamItems.count())
continue;
for(const auto &EndPoint:EndPoints) {
std::vector<std::string> ParamItems = Utils::Split(EndPoint, '/');
if (PathItems.size() != ParamItems.size())
continue;
bool Matched = true;
for (size_t i = 0; i != PathItems.size() && Matched; i++) {
if (PathItems[i] != ParamItems[i]) {
if (ParamItems[i][0] == '{') {
auto ParamName = ParamItems[i].substr(1, ParamItems[i].size() - 2);
bindings[Poco::toLower(ParamName)] = PathItems[i];
} else {
Matched = false;
}
}
}
if(Matched)
return true;
}
return false;
}
bool Matched = true;
for (size_t i = 0; i < PathItems.count(); i++) {
if (PathItems[i] != ParamItems[i]) {
if (ParamItems[i][0] == '{') {
auto ParamName = ParamItems[i].substr(1, ParamItems[i].size() - 2);
bindings[Poco::toLower(ParamName)] = PathItems[i];
} else {
Matched = false;
break;
}
}
}
if(Matched)
return true;
}
return false;
}
inline void PrintBindings() {
for (const auto &[key, value] : Bindings_)
@@ -2582,7 +2601,7 @@ namespace OpenWifi {
private:
std::recursive_mutex Mutex_;
Poco::Thread Worker_;
std::atomic_bool Running_=false;
mutable std::atomic_bool Running_=false;
Poco::NotificationQueue Queue_;
};
@@ -2608,7 +2627,7 @@ namespace OpenWifi {
private:
std::recursive_mutex Mutex_;
Poco::Thread Worker_;
std::atomic_bool Running_=false;
mutable std::atomic_bool Running_=false;
};
class KafkaDispatcher : public Poco::Runnable {
@@ -2665,6 +2684,7 @@ namespace OpenWifi {
inline void run() override {
Poco::AutoPtr<Poco::Notification> Note(Queue_.waitDequeueNotification());
Utils::SetThreadName("kafka-dispatch");
while(Note && Running_) {
auto Msg = dynamic_cast<KafkaMessage*>(Note.get());
if(Msg!= nullptr) {
@@ -2690,7 +2710,7 @@ namespace OpenWifi {
std::recursive_mutex Mutex_;
Types::NotifyTable Notifiers_;
Poco::Thread Worker_;
std::atomic_bool Running_=false;
mutable std::atomic_bool Running_=false;
uint64_t FunctionId_=1;
Poco::NotificationQueue Queue_;
};
@@ -2885,6 +2905,7 @@ namespace OpenWifi {
void handleRequest(Poco::Net::HTTPServerRequest& Request, Poco::Net::HTTPServerResponse& Response) override
{
Utils::SetThreadName("alb-request");
try {
if((id_ % 100) == 0) {
Logger_.debug(fmt::format("ALB-REQUEST({}): ALB Request {}.",
@@ -2953,7 +2974,7 @@ namespace OpenWifi {
std::unique_ptr<Poco::Net::HTTPServer> Server_;
std::unique_ptr<Poco::Net::ServerSocket> Socket_;
int Port_ = 0;
std::atomic_bool Running_=false;
mutable std::atomic_bool Running_=false;
};
inline auto ALBHealthCheckServer() { return ALBHealthCheckServer::instance(); }
@@ -2985,7 +3006,7 @@ namespace OpenWifi {
inline Poco::Net::HTTPRequestHandler *CallServer(const std::string &Path, uint64_t Id) {
RESTAPIHandler::BindingMap Bindings;
Poco::Thread::current()->setName(fmt::format("RESTAPI_ExtServer_{}",Id));
Utils::SetThreadName(fmt::format("rest_ext_{}",Id).c_str());
return RESTAPI_ExtRouter(Path, Bindings, Logger(), Server_, Id);
}
@@ -3009,7 +3030,7 @@ namespace OpenWifi {
inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override {
try {
Poco::URI uri(Request.getURI());
Poco::Thread::current()->setName(fmt::format("ExtWebServer_{}",TransactionId_));
Utils::SetThreadName(fmt::format("rest_ext_{}",TransactionId_).c_str());
return RESTAPI_ExtServer()->CallServer(uri.getPath(), TransactionId_++);
} catch (...) {
@@ -3118,7 +3139,7 @@ namespace OpenWifi {
inline Poco::Net::HTTPRequestHandler *CallServer(const std::string &Path, uint64_t Id) {
RESTAPIHandler::BindingMap Bindings;
Poco::Thread::current()->setName(fmt::format("RESTAPI_IntServer_{}",Id));
Utils::SetThreadName(fmt::format("rest_int_{}",Id).c_str());
return RESTAPI_IntRouter(Path, Bindings, Logger(), Server_, Id);
}
private:
@@ -3527,7 +3548,9 @@ namespace OpenWifi {
void DaemonPostInitialization(Poco::Util::Application &self);
inline void MicroService::initialize(Poco::Util::Application &self) {
// add the default services
// Utils::SetThreadName("microservice");
// add the default services
LoadConfigurationFile();
InitializeLoggingSystem();
@@ -3922,6 +3945,7 @@ namespace OpenWifi {
inline int MicroService::main([[maybe_unused]] const ArgVec &args) {
// Utils::SetThreadName("main");
MyErrorHandler ErrorHandler(*this);
Poco::ErrorHandler::set(&ErrorHandler);
@@ -4037,6 +4061,7 @@ namespace OpenWifi {
inline void BusEventManager::run() {
Running_ = true;
Utils::SetThreadName("BusEventManager");
auto Msg = MicroService::instance().MakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_JOIN);
KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS,MicroService::instance().PrivateEndPoint(),Msg, false);
while(Running_) {
@@ -4122,6 +4147,8 @@ namespace OpenWifi {
}
inline void KafkaProducer::run() {
Utils::SetThreadName("KafkaProducer");
cppkafka::Configuration Config({
{ "client.id", MicroService::instance().ConfigGetString("openwifi.kafka.client.id") },
{ "metadata.broker.list", MicroService::instance().ConfigGetString("openwifi.kafka.brokerlist") }
@@ -4160,6 +4187,8 @@ namespace OpenWifi {
}
inline void KafkaConsumer::run() {
Utils::SetThreadName("KafkaConsumer");
cppkafka::Configuration Config({
{ "client.id", MicroService::instance().ConfigGetString("openwifi.kafka.client.id") },
{ "metadata.broker.list", MicroService::instance().ConfigGetString("openwifi.kafka.brokerlist") },
@@ -4818,7 +4847,7 @@ namespace OpenWifi {
[[nodiscard]] bool SendToUser(const std::string &userName, const std::string &Payload);
void SendToAll(const std::string &Payload);
private:
std::atomic_bool Running_ = false;
mutable std::atomic_bool Running_ = false;
Poco::Thread Thr_;
// std::unique_ptr<MyParallelSocketReactor> ReactorPool_;
Poco::Net::SocketReactor Reactor_;
@@ -4915,6 +4944,7 @@ namespace OpenWifi {
inline void WebSocketClientServer::run() {
Running_ = true ;
Utils::SetThreadName("ws:clnt-svr");
while(Running_) {
Poco::Thread::trySleep(2000);