From 0a6ee4ea47368b82f80a44b804e04a245eac8d56 Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Sun, 24 Jul 2022 12:28:40 -0700 Subject: [PATCH] https://telecominfraproject.atlassian.net/browse/WIFI-10345 Signed-off-by: stephb9959 --- CMakeLists.txt | 2 +- build | 2 +- src/RESTAPI/RESTAPI_routers.cpp | 3 +- src/framework/MicroService.h | 76 +++++++++++++++++++-------------- 4 files changed, 48 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d5ac2b..81b968f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.13) -project(owsec VERSION 2.6.0) +project(owsec VERSION 2.7.0) set(CMAKE_CXX_STANDARD 17) diff --git a/build b/build index 2b82dfe..d8263ee 100644 --- a/build +++ b/build @@ -1 +1 @@ -60 \ No newline at end of file +2 \ No newline at end of file diff --git a/src/RESTAPI/RESTAPI_routers.cpp b/src/RESTAPI/RESTAPI_routers.cpp index d46c545..98315d6 100644 --- a/src/RESTAPI/RESTAPI_routers.cpp +++ b/src/RESTAPI/RESTAPI_routers.cpp @@ -29,7 +29,8 @@ namespace OpenWifi { Poco::Net::HTTPRequestHandler * RESTAPI_ExtRouter(const std::string &Path, RESTAPIHandler::BindingMap &Bindings, - Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t TransactionId) { + Poco::Logger & L, RESTAPI_GenericServer & S, + uint64_t TransactionId) { return RESTAPI_Router< RESTAPI_oauth2_handler, RESTAPI_user_handler, diff --git a/src/framework/MicroService.h b/src/framework/MicroService.h index 5e2f977..9a0277e 100644 --- a/src/framework/MicroService.h +++ b/src/framework/MicroService.h @@ -1399,13 +1399,14 @@ namespace OpenWifi { [[nodiscard]] inline const std::string &Address() const { return address_; }; [[nodiscard]] inline uint32_t Port() const { return port_; }; - [[nodiscard]] inline const std::string &KeyFile() const { return key_file_; }; - [[nodiscard]] inline const std::string &CertFile() const { return cert_file_; }; - [[nodiscard]] inline const std::string &RootCA() const { return root_ca_; }; - [[nodiscard]] inline const std::string &KeyFilePassword() const { return key_file_password_; }; - [[nodiscard]] inline const std::string &IssuerCertFile() const { return issuer_cert_file_; }; - [[nodiscard]] inline const std::string &Name() const { return name_; }; + [[nodiscard]] inline auto KeyFile() const { return key_file_; }; + [[nodiscard]] inline auto CertFile() const { return cert_file_; }; + [[nodiscard]] inline auto RootCA() const { return root_ca_; }; + [[nodiscard]] inline auto KeyFilePassword() const { return key_file_password_; }; + [[nodiscard]] inline auto IssuerCertFile() const { return issuer_cert_file_; }; + [[nodiscard]] inline auto Name() const { return name_; }; [[nodiscard]] inline int Backlog() const { return backlog_; } + [[nodiscard]] inline auto Cas() const { return cas_; } [[nodiscard]] inline Poco::Net::SecureServerSocket CreateSecureSocket(Poco::Logger &L) const { Poco::Net::Context::Params P; @@ -1885,8 +1886,8 @@ namespace OpenWifi { Request = &RequestIn; Response = &ResponseIn; - std::string th_name = "restsvr_" + std::to_string(TransactionId_); - Utils::SetThreadName(th_name.c_str()); +// 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) { @@ -2712,7 +2713,7 @@ namespace OpenWifi { inline void run() override { Poco::AutoPtr Note(Queue_.waitDequeueNotification()); - Utils::SetThreadName("kafka-dispatch"); + Utils::SetThreadName("kafka:dispatch"); while(Note && Running_) { auto Msg = dynamic_cast(Note.get()); if(Msg!= nullptr) { @@ -3034,18 +3035,17 @@ namespace OpenWifi { inline Poco::Net::HTTPRequestHandler *CallServer(const std::string &Path, uint64_t Id) { RESTAPIHandler::BindingMap Bindings; - Utils::SetThreadName(fmt::format("rest_ext_{}",Id).c_str()); + Utils::SetThreadName(fmt::format("x-rest:{}",Id).c_str()); return RESTAPI_ExtRouter(Path, Bindings, Logger(), Server_, Id); } private: std::vector> RESTServers_; - Poco::ThreadPool Pool_; + Poco::ThreadPool Pool_{"x-rest",2,32}; RESTAPI_GenericServer Server_; RESTAPI_ExtServer() noexcept: - SubSystemServer("RESTAPI_ExtServer", "RESTAPIServer", "openwifi.restapi"), - Pool_("RESTAPI_ExtServer",4,50,120) + SubSystemServer("RESTAPI_ExtServer", "RESTAPIServer", "openwifi.restapi") { } }; @@ -3058,7 +3058,7 @@ namespace OpenWifi { inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override { try { Poco::URI uri(Request.getURI()); - Utils::SetThreadName(fmt::format("rest_ext_{}",TransactionId_).c_str()); + Utils::SetThreadName(fmt::format("x-rest:{}",TransactionId_).c_str()); return RESTAPI_ExtServer()->CallServer(uri.getPath(), TransactionId_++); } catch (...) { @@ -3167,17 +3167,16 @@ namespace OpenWifi { inline Poco::Net::HTTPRequestHandler *CallServer(const std::string &Path, uint64_t Id) { RESTAPIHandler::BindingMap Bindings; - Utils::SetThreadName(fmt::format("rest_int_{}",Id).c_str()); + Utils::SetThreadName(fmt::format("i-rest:{}",Id).c_str()); return RESTAPI_IntRouter(Path, Bindings, Logger(), Server_, Id); } private: std::vector> RESTServers_; - Poco::ThreadPool Pool_; + Poco::ThreadPool Pool_{"i-rest",2,16}; RESTAPI_GenericServer Server_; RESTAPI_IntServer() noexcept: - SubSystemServer("RESTAPI_IntServer", "REST-ISRV", "openwifi.internal.restapi"), - Pool_("RESTAPI_IntServer",4,50,120) + SubSystemServer("RESTAPI_IntServer", "REST-ISRV", "openwifi.internal.restapi") { } }; @@ -3188,6 +3187,7 @@ namespace OpenWifi { public: inline IntRequestHandlerFactory() = default; inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override { + Utils::SetThreadName(fmt::format("i-rest:{}",TransactionId_).c_str()); Poco::URI uri(Request.getURI()); return RESTAPI_IntServer()->CallServer(uri.getPath(), TransactionId_); } @@ -3231,7 +3231,6 @@ namespace OpenWifi { } [[nodiscard]] std::string Version() { return Version_; } - // [[nodiscard]] const Poco::SharedPtr & Key() { return AppKey_; } [[nodiscard]] inline const std::string & DataDir() { return DataDir_; } [[nodiscard]] inline const std::string & WWWAssetsDir() { return WWWAssetsDir_; } [[nodiscard]] bool Debug() const { return DebugMode_; } @@ -3264,7 +3263,12 @@ namespace OpenWifi { return Poco::Logger::get(Name); } - static inline void Exit(int Reason); + virtual void GetExtraConfiguration(Poco::JSON::Object & Cfg) { + Cfg.set("additionalConfiguration",false); + } + + + static inline void Exit(int Reason); inline void BusMessageReceived(const std::string &Key, const std::string & Payload); inline MicroServiceMetaVec GetServices(const std::string & Type); inline MicroServiceMetaVec GetServices(); @@ -3330,6 +3334,9 @@ namespace OpenWifi { return Signer_.sign(T,Algo); } } + + inline Poco::ThreadPool & TimerPool() { return TimerPool_; } + private: static MicroService * instance_; bool HelpRequested_ = false; @@ -3364,6 +3371,7 @@ namespace OpenWifi { bool NoBuiltInCrypto_=false; Poco::JWT::Signer Signer_; Poco::Logger &Logger_; + Poco::ThreadPool TimerPool_{"timer:pool",2,16}; }; inline void MicroService::Exit(int Reason) { @@ -3576,8 +3584,6 @@ namespace OpenWifi { void DaemonPostInitialization(Poco::Util::Application &self); inline void MicroService::initialize(Poco::Util::Application &self) { - // Utils::SetThreadName("microservice"); - // add the default services LoadConfigurationFile(); InitializeLoggingSystem(); @@ -3919,6 +3925,7 @@ namespace OpenWifi { Params->setMaxThreads(50); Params->setMaxQueued(200); Params->setKeepAlive(true); + Params->setName("ws:xrest"); std::unique_ptr NewServer; if(MicroService::instance().NoAPISecurity()) { @@ -3955,6 +3962,7 @@ namespace OpenWifi { Params->setMaxThreads(50); Params->setMaxQueued(200); Params->setKeepAlive(true); + Params->setName("ws:irest"); std::unique_ptr NewServer; if(MicroService::instance().NoAPISecurity()) { @@ -3972,8 +3980,6 @@ namespace OpenWifi { } inline int MicroService::main([[maybe_unused]] const ArgVec &args) { - - // Utils::SetThreadName("main"); MyErrorHandler ErrorHandler(*this); Poco::ErrorHandler::set(&ErrorHandler); @@ -4080,6 +4086,7 @@ namespace OpenWifi { Port_ = (int)MicroService::instance().ConfigGetInt("alb.port",15015); Socket_ = std::make_unique(Port_); auto Params = new Poco::Net::HTTPServerParams; + Params->setName("ws:alb"); Server_ = std::make_unique(new ALBRequestHandlerFactory(Logger()), *Socket_, Params); Server_->start(); } @@ -4089,7 +4096,7 @@ namespace OpenWifi { inline void BusEventManager::run() { Running_ = true; - Utils::SetThreadName("BusEventManager"); + Utils::SetThreadName("fmwk:EventMgr"); auto Msg = MicroService::instance().MakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_JOIN); KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS,MicroService::instance().PrivateEndPoint(),Msg, false); while(Running_) { @@ -4176,7 +4183,7 @@ namespace OpenWifi { inline void KafkaProducer::run() { - Utils::SetThreadName("KafkaProducer"); + Utils::SetThreadName("Kafka:Prod"); cppkafka::Configuration Config({ { "client.id", MicroService::instance().ConfigGetString("openwifi.kafka.client.id") }, { "metadata.broker.list", MicroService::instance().ConfigGetString("openwifi.kafka.brokerlist") } @@ -4215,7 +4222,7 @@ namespace OpenWifi { } inline void KafkaConsumer::run() { - Utils::SetThreadName("KafkaConsumer"); + Utils::SetThreadName("Kafka:Cons"); cppkafka::Configuration Config({ { "client.id", MicroService::instance().ConfigGetString("openwifi.kafka.client.id") }, @@ -4355,6 +4362,11 @@ namespace OpenWifi { Answer.set("certificates", Certificates); return ReturnObject(Answer); } + if(GetBoolParameter("extraConfiguration")) { + Poco::JSON::Object Answer; + MicroService::instance().GetExtraConfiguration(Answer); + return ReturnObject(Answer); + } BadRequest(RESTAPI::Errors::InvalidCommand); } @@ -4876,7 +4888,7 @@ namespace OpenWifi { void SendToAll(const std::string &Payload); private: mutable std::atomic_bool Running_ = false; - Poco::Thread Thr_; + Poco::Thread Thr_; // std::unique_ptr ReactorPool_; Poco::Net::SocketReactor Reactor_; Poco::Thread ReactorThread_; @@ -4966,13 +4978,13 @@ namespace OpenWifi { [[nodiscard]] inline bool SendToUser(const std::string &userName, const std::string &Payload); inline WebSocketClientServer::WebSocketClientServer() noexcept: - SubSystemServer("WebSocketClientServer", "WSCLNT-SVR", "websocketclients") + SubSystemServer("WebSocketClientServer", "UI-WSCLNT-SVR", "websocketclients") { } inline void WebSocketClientServer::run() { Running_ = true ; - Utils::SetThreadName("ws:clnt-svr"); + Utils::SetThreadName("ws:uiclnt-svr"); while(Running_) { Poco::Thread::trySleep(2000); @@ -5065,7 +5077,7 @@ namespace OpenWifi { case Poco::Net::WebSocket::FRAME_OP_PONG: { } break; case Poco::Net::WebSocket::FRAME_OP_CLOSE: { - Logger().warning(Poco::format("CLOSE(%s): Client is closing its connection.", Id_)); + Logger().warning(Poco::format("CLOSE(%s): UI Client is closing its connection.", Id_)); Done = true; } break; case Poco::Net::WebSocket::FRAME_OP_TEXT: { @@ -5204,7 +5216,7 @@ namespace OpenWifi { try { Poco::Net::WebSocket WS(*Request, *Response); - Logger().information("WebSocket connection established."); + Logger().information("UI-WebSocket connection established."); auto Id = MicroService::CreateUUID(); WebSocketClientServer()->NewClient(WS,Id); }