mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-11-01 11:07:46 +00:00
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
This commit is contained in:
@@ -16,9 +16,9 @@ namespace OpenWifi {
|
|||||||
KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(), Msg,
|
KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(), Msg,
|
||||||
false);
|
false);
|
||||||
while (Running_) {
|
while (Running_) {
|
||||||
Poco::Thread::trySleep((unsigned long)MicroServiceDaemonBusTimer());
|
if(!Poco::Thread::trySleep((unsigned long)MicroServiceDaemonBusTimer())) {
|
||||||
if (!Running_)
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
Msg = (MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE));
|
Msg = (MicroServiceMakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE));
|
||||||
KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(),
|
KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS, MicroServicePrivateEndPoint(),
|
||||||
Msg, false);
|
Msg, false);
|
||||||
@@ -29,7 +29,7 @@ namespace OpenWifi {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void EventBusManager::Start() {
|
void EventBusManager::Start() {
|
||||||
poco_information(Logger(), "Starting...");
|
poco_information(Logger_, "Starting...");
|
||||||
if (KafkaManager()->Enabled()) {
|
if (KafkaManager()->Enabled()) {
|
||||||
Thread_.start(*this);
|
Thread_.start(*this);
|
||||||
}
|
}
|
||||||
@@ -37,11 +37,11 @@ namespace OpenWifi {
|
|||||||
|
|
||||||
void EventBusManager::Stop() {
|
void EventBusManager::Stop() {
|
||||||
if (KafkaManager()->Enabled()) {
|
if (KafkaManager()->Enabled()) {
|
||||||
poco_information(Logger(), "Stopping...");
|
poco_information(Logger_, "Stopping...");
|
||||||
Running_ = false;
|
Running_ = false;
|
||||||
Thread_.wakeUp();
|
Thread_.wakeUp();
|
||||||
Thread_.join();
|
Thread_.join();
|
||||||
poco_information(Logger(), "Stopped...");
|
poco_information(Logger_, "Stopped...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ namespace OpenWifi {
|
|||||||
return instance_;
|
return instance_;
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit EventBusManager(Poco::Logger &L);
|
|
||||||
void run() final;
|
void run() final;
|
||||||
void Start();
|
void Start();
|
||||||
void Stop();
|
void Stop();
|
||||||
|
|||||||
@@ -29,9 +29,11 @@
|
|||||||
#include "framework/WebSocketLogger.h"
|
#include "framework/WebSocketLogger.h"
|
||||||
#include "framework/utils.h"
|
#include "framework/utils.h"
|
||||||
|
|
||||||
namespace OpenWifi {
|
#ifdef USE_MEDUSA_CLIENT
|
||||||
|
#include <medusa/MedusaClient.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
void MicroService::Exit(int Reason) { std::exit(Reason); }
|
namespace OpenWifi {
|
||||||
|
|
||||||
static std::string MakeServiceListString(const Types::MicroServiceMetaMap &Services) {
|
static std::string MakeServiceListString(const Types::MicroServiceMetaMap &Services) {
|
||||||
std::string SvcList;
|
std::string SvcList;
|
||||||
@@ -204,9 +206,11 @@ namespace OpenWifi {
|
|||||||
Res.push_back(ServiceRec);
|
Res.push_back(ServiceRec);
|
||||||
}
|
}
|
||||||
return Res;
|
return Res;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MicroService::LoadConfigurationFile() {
|
void MicroService::LoadConfigurationFile() {
|
||||||
|
if(ConfigContent_.empty()) {
|
||||||
std::string Location = Poco::Environment::get(DAEMON_CONFIG_ENV_VAR, ".");
|
std::string Location = Poco::Environment::get(DAEMON_CONFIG_ENV_VAR, ".");
|
||||||
ConfigFileName_ =
|
ConfigFileName_ =
|
||||||
ConfigFileName_.empty() ? Location + "/" + DAEMON_PROPERTIES_FILENAME : ConfigFileName_;
|
ConfigFileName_.empty() ? Location + "/" + DAEMON_PROPERTIES_FILENAME : ConfigFileName_;
|
||||||
@@ -220,9 +224,11 @@ namespace OpenWifi {
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
std::exit(Poco::Util::Application::EXIT_CONFIG);
|
std::exit(Poco::Util::Application::EXIT_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadConfiguration(ConfigFile.toString());
|
|
||||||
PropConfigurationFile_ = new Poco::Util::PropertyFileConfiguration(ConfigFile.toString());
|
PropConfigurationFile_ = new Poco::Util::PropertyFileConfiguration(ConfigFile.toString());
|
||||||
|
} else {
|
||||||
|
std::istringstream is(ConfigContent_);
|
||||||
|
PropConfigurationFile_ = new Poco::Util::PropertyFileConfiguration(is);
|
||||||
|
}
|
||||||
configPtr()->addWriteable(PropConfigurationFile_, PRIO_DEFAULT);
|
configPtr()->addWriteable(PropConfigurationFile_, PRIO_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,11 +431,13 @@ namespace OpenWifi {
|
|||||||
|
|
||||||
void DaemonPostInitialization(Poco::Util::Application &self);
|
void DaemonPostInitialization(Poco::Util::Application &self);
|
||||||
|
|
||||||
void MicroService::initialize(Poco::Util::Application &self) {
|
void MicroService::StartEverything(Poco::Util::Application &self) {
|
||||||
// add the default services
|
|
||||||
LoadConfigurationFile();
|
LoadConfigurationFile();
|
||||||
InitializeLoggingSystem();
|
InitializeLoggingSystem();
|
||||||
|
|
||||||
|
static bool InitializedBaseService=false;
|
||||||
|
if(!InitializedBaseService) {
|
||||||
|
InitializedBaseService = true;
|
||||||
SubSystems_.push_back(KafkaManager());
|
SubSystems_.push_back(KafkaManager());
|
||||||
SubSystems_.push_back(ALBHealthCheckServer());
|
SubSystems_.push_back(ALBHealthCheckServer());
|
||||||
SubSystems_.push_back(RESTAPI_ExtServer());
|
SubSystems_.push_back(RESTAPI_ExtServer());
|
||||||
@@ -437,11 +445,13 @@ namespace OpenWifi {
|
|||||||
#ifndef TIP_SECURITY_SERVICE
|
#ifndef TIP_SECURITY_SERVICE
|
||||||
SubSystems_.push_back(AuthClient());
|
SubSystems_.push_back(AuthClient());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Poco::Net::initializeSSL();
|
Poco::Net::initializeSSL();
|
||||||
Poco::Net::HTTPStreamFactory::registerFactory();
|
Poco::Net::HTTPStreamFactory::registerFactory();
|
||||||
Poco::Net::HTTPSStreamFactory::registerFactory();
|
Poco::Net::HTTPSStreamFactory::registerFactory();
|
||||||
Poco::Net::FTPStreamFactory::registerFactory();
|
Poco::Net::FTPStreamFactory::registerFactory();
|
||||||
Poco::Net::FTPSStreamFactory::registerFactory();
|
Poco::Net::FTPSStreamFactory::registerFactory();
|
||||||
|
}
|
||||||
|
|
||||||
Poco::File DataDir(ConfigPath("openwifi.system.data"));
|
Poco::File DataDir(ConfigPath("openwifi.system.data"));
|
||||||
DataDir_ = DataDir.path();
|
DataDir_ = DataDir.path();
|
||||||
@@ -470,6 +480,12 @@ namespace OpenWifi {
|
|||||||
KafkaManager()->RegisterTopicWatcher(KafkaTopics::SERVICE_EVENTS, F);
|
KafkaManager()->RegisterTopicWatcher(KafkaTopics::SERVICE_EVENTS, F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MicroService::initialize([[maybe_unused]] Poco::Util::Application &self) {
|
||||||
|
#ifndef USE_MEDUSA_CLIENT
|
||||||
|
StartEverything(self);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void MicroService::uninitialize() {
|
void MicroService::uninitialize() {
|
||||||
// add your own uninitialization code here
|
// add your own uninitialization code here
|
||||||
ServerApplication::uninitialize();
|
ServerApplication::uninitialize();
|
||||||
@@ -753,6 +769,8 @@ namespace OpenWifi {
|
|||||||
MicroServiceErrorHandler ErrorHandler(*this);
|
MicroServiceErrorHandler ErrorHandler(*this);
|
||||||
Poco::ErrorHandler::set(&ErrorHandler);
|
Poco::ErrorHandler::set(&ErrorHandler);
|
||||||
|
|
||||||
|
Args_ = args;
|
||||||
|
|
||||||
if (!HelpRequested_) {
|
if (!HelpRequested_) {
|
||||||
SavePID();
|
SavePID();
|
||||||
|
|
||||||
@@ -768,11 +786,18 @@ namespace OpenWifi {
|
|||||||
poco_information(logger, "Starting as a daemon.");
|
poco_information(logger, "Starting as a daemon.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_MEDUSA_CLIENT
|
||||||
|
MedusaClient::instance()->SetSubSystems(SubSystems_);
|
||||||
|
MedusaClient::instance()->Start();
|
||||||
|
waitForTerminationRequest();
|
||||||
|
MedusaClient::instance()->Stop();
|
||||||
|
#else
|
||||||
poco_information(logger, fmt::format("System ID set to {}", ID_));
|
poco_information(logger, fmt::format("System ID set to {}", ID_));
|
||||||
StartSubSystemServers();
|
StartSubSystemServers();
|
||||||
waitForTerminationRequest();
|
waitForTerminationRequest();
|
||||||
StopSubSystemServers();
|
StopSubSystemServers();
|
||||||
logger.notice(fmt::format("Stopped {}...", DAEMON_APP_NAME));
|
logger.notice(fmt::format("Stopped {}...", DAEMON_APP_NAME));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return Application::EXIT_OK;
|
return Application::EXIT_OK;
|
||||||
|
|||||||
@@ -55,9 +55,6 @@ namespace OpenWifi {
|
|||||||
#include "nlohmann/json.hpp"
|
#include "nlohmann/json.hpp"
|
||||||
#include "ow_version.h"
|
#include "ow_version.h"
|
||||||
|
|
||||||
#define _OWDEBUG_ std::cout << __FILE__ << ":" << __LINE__ << std::endl;
|
|
||||||
// #define _OWDEBUG_ Logger().debug(Poco::format("%s: %lu",__FILE__,__LINE__));
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
namespace OpenWifi {
|
||||||
|
|
||||||
class MicroService : public Poco::Util::ServerApplication {
|
class MicroService : public Poco::Util::ServerApplication {
|
||||||
@@ -70,7 +67,6 @@ namespace OpenWifi {
|
|||||||
SubSystems_(std::move(Subsystems)), Logger_(Poco::Logger::get("FRAMEWORK")) {
|
SubSystems_(std::move(Subsystems)), Logger_(Poco::Logger::get("FRAMEWORK")) {
|
||||||
instance_ = this;
|
instance_ = this;
|
||||||
RandomEngine_.seed(std::chrono::steady_clock::now().time_since_epoch().count());
|
RandomEngine_.seed(std::chrono::steady_clock::now().time_since_epoch().count());
|
||||||
// Logger_ = Poco::Logger::root().get("BASE-SVC");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static const char *ExtraConfigurationFilename = "/configuration_override.json";
|
inline static const char *ExtraConfigurationFilename = "/configuration_override.json";
|
||||||
@@ -92,7 +88,7 @@ namespace OpenWifi {
|
|||||||
inline uint64_t DaemonBusTimer() const { return DAEMON_BUS_TIMER; };
|
inline uint64_t DaemonBusTimer() const { return DAEMON_BUS_TIMER; };
|
||||||
[[nodiscard]] const std::string &AppName() { return DAEMON_APP_NAME; }
|
[[nodiscard]] const std::string &AppName() { return DAEMON_APP_NAME; }
|
||||||
static inline uint64_t GetPID() { return Poco::Process::id(); };
|
static inline uint64_t GetPID() { return Poco::Process::id(); };
|
||||||
[[nodiscard]] inline const std::string GetPublicAPIEndPoint() {
|
[[nodiscard]] inline std::string GetPublicAPIEndPoint() const {
|
||||||
return MyPublicEndPoint_ + "/api/v1";
|
return MyPublicEndPoint_ + "/api/v1";
|
||||||
};
|
};
|
||||||
[[nodiscard]] inline const std::string &GetUIURI() const { return UIURI_; };
|
[[nodiscard]] inline const std::string &GetUIURI() const { return UIURI_; };
|
||||||
@@ -107,7 +103,8 @@ namespace OpenWifi {
|
|||||||
}
|
}
|
||||||
static MicroService &instance() { return *instance_; }
|
static MicroService &instance() { return *instance_; }
|
||||||
|
|
||||||
inline void Exit(int Reason);
|
inline void Exit(int Reason) { std::exit(Reason); }
|
||||||
|
|
||||||
void BusMessageReceived(const std::string &Key, const std::string &Payload);
|
void BusMessageReceived(const std::string &Key, const std::string &Payload);
|
||||||
Types::MicroServiceMetaVec GetServices(const std::string &Type);
|
Types::MicroServiceMetaVec GetServices(const std::string &Type);
|
||||||
Types::MicroServiceMetaVec GetServices();
|
Types::MicroServiceMetaVec GetServices();
|
||||||
@@ -115,6 +112,7 @@ namespace OpenWifi {
|
|||||||
void Reload();
|
void Reload();
|
||||||
void LoadMyConfig();
|
void LoadMyConfig();
|
||||||
void initialize(Poco::Util::Application &self) override;
|
void initialize(Poco::Util::Application &self) override;
|
||||||
|
void StartEverything(Poco::Util::Application &self);
|
||||||
void uninitialize() override;
|
void uninitialize() override;
|
||||||
void reinitialize(Poco::Util::Application &self) override;
|
void reinitialize(Poco::Util::Application &self) override;
|
||||||
void defineOptions(Poco::Util::OptionSet &options) override;
|
void defineOptions(Poco::Util::OptionSet &options) override;
|
||||||
@@ -132,7 +130,7 @@ namespace OpenWifi {
|
|||||||
void Reload(const std::string &Sub);
|
void Reload(const std::string &Sub);
|
||||||
Types::StringVec GetSubSystems() const;
|
Types::StringVec GetSubSystems() const;
|
||||||
Types::StringPairVec GetLogLevels();
|
Types::StringPairVec GetLogLevels();
|
||||||
const Types::StringVec &GetLogLevelNames();
|
static const Types::StringVec &GetLogLevelNames();
|
||||||
uint64_t ConfigGetInt(const std::string &Key, uint64_t Default);
|
uint64_t ConfigGetInt(const std::string &Key, uint64_t Default);
|
||||||
uint64_t ConfigGetInt(const std::string &Key);
|
uint64_t ConfigGetInt(const std::string &Key);
|
||||||
uint64_t ConfigGetBool(const std::string &Key, bool Default);
|
uint64_t ConfigGetBool(const std::string &Key, bool Default);
|
||||||
@@ -166,12 +164,16 @@ namespace OpenWifi {
|
|||||||
const std::string &FormatterPattern,
|
const std::string &FormatterPattern,
|
||||||
const std::string &root_env_var);
|
const std::string &root_env_var);
|
||||||
inline bool AllowExternalMicroServices() const { return AllowExternalMicroServices_; }
|
inline bool AllowExternalMicroServices() const { return AllowExternalMicroServices_; }
|
||||||
|
const ArgVec &Args() const { return Args_; }
|
||||||
|
|
||||||
|
inline void SetConfigContent(const std::string &Content) { ConfigContent_ = Content; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static MicroService *instance_;
|
static MicroService *instance_;
|
||||||
bool HelpRequested_ = false;
|
bool HelpRequested_ = false;
|
||||||
std::string LogDir_;
|
std::string LogDir_;
|
||||||
std::string ConfigFileName_;
|
std::string ConfigFileName_;
|
||||||
|
std::string ConfigContent_;
|
||||||
uint64_t ID_ = 1;
|
uint64_t ID_ = 1;
|
||||||
Poco::SharedPtr<Poco::Crypto::RSAKey> AppKey_;
|
Poco::SharedPtr<Poco::Crypto::RSAKey> AppKey_;
|
||||||
bool DebugMode_ = false;
|
bool DebugMode_ = false;
|
||||||
@@ -201,6 +203,7 @@ namespace OpenWifi {
|
|||||||
Poco::JWT::Signer Signer_;
|
Poco::JWT::Signer Signer_;
|
||||||
Poco::Logger &Logger_;
|
Poco::Logger &Logger_;
|
||||||
Poco::ThreadPool TimerPool_{"timer:pool", 2, 32};
|
Poco::ThreadPool TimerPool_{"timer:pool", 2, 32};
|
||||||
|
ArgVec Args_;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline MicroService *MicroService::instance_ = nullptr;
|
inline MicroService *MicroService::instance_ = nullptr;
|
||||||
|
|||||||
@@ -58,11 +58,9 @@ namespace OpenWifi {
|
|||||||
void UI_WebSocketClientServer::run() {
|
void UI_WebSocketClientServer::run() {
|
||||||
Running_ = true;
|
Running_ = true;
|
||||||
while (Running_) {
|
while (Running_) {
|
||||||
Poco::Thread::trySleep(2000);
|
if(!Poco::Thread::trySleep(2000)) {
|
||||||
|
|
||||||
if (!Running_)
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
std::lock_guard G(LocalMutex_);
|
std::lock_guard G(LocalMutex_);
|
||||||
for (const auto i : ToBeRemoved_) {
|
for (const auto i : ToBeRemoved_) {
|
||||||
// std::cout << "Erasing old WS UI connection..." << std::endl;
|
// std::cout << "Erasing old WS UI connection..." << std::endl;
|
||||||
|
|||||||
@@ -565,6 +565,7 @@ namespace OpenWifi::RESTAPI::Protocol {
|
|||||||
|
|
||||||
static const char *TRANSFER = "transfer";
|
static const char *TRANSFER = "transfer";
|
||||||
static const char *CERTUPDATE = "certupdate";
|
static const char *CERTUPDATE = "certupdate";
|
||||||
|
static const char *POWERCYCLE = "powercycle";
|
||||||
static const char *RRM = "rrm";
|
static const char *RRM = "rrm";
|
||||||
|
|
||||||
static const char *REQUIREMENTS = "requirements";
|
static const char *REQUIREMENTS = "requirements";
|
||||||
@@ -687,6 +688,7 @@ namespace OpenWifi::uCentralProtocol {
|
|||||||
|
|
||||||
static const char *TRANSFER = "transfer";
|
static const char *TRANSFER = "transfer";
|
||||||
static const char *CERTUPDATE = "certupdate";
|
static const char *CERTUPDATE = "certupdate";
|
||||||
|
static const char *POWERCYCLE = "powercycle";
|
||||||
static const char *RRM = "rrm";
|
static const char *RRM = "rrm";
|
||||||
static const char *ACTIONS = "actions";
|
static const char *ACTIONS = "actions";
|
||||||
|
|
||||||
@@ -785,6 +787,7 @@ namespace OpenWifi::APCommands {
|
|||||||
rrm,
|
rrm,
|
||||||
certupdate,
|
certupdate,
|
||||||
transfer,
|
transfer,
|
||||||
|
powercycle,
|
||||||
unknown
|
unknown
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -799,7 +802,7 @@ namespace OpenWifi::APCommands {
|
|||||||
RESTAPI::Protocol::EVENTQUEUE, RESTAPI::Protocol::TELEMETRY,
|
RESTAPI::Protocol::EVENTQUEUE, RESTAPI::Protocol::TELEMETRY,
|
||||||
RESTAPI::Protocol::PING, RESTAPI::Protocol::SCRIPT,
|
RESTAPI::Protocol::PING, RESTAPI::Protocol::SCRIPT,
|
||||||
RESTAPI::Protocol::RRM, RESTAPI::Protocol::CERTUPDATE,
|
RESTAPI::Protocol::RRM, RESTAPI::Protocol::CERTUPDATE,
|
||||||
RESTAPI::Protocol::TRANSFER
|
RESTAPI::Protocol::TRANSFER, RESTAPI::Protocol::POWERCYCLE
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const char *to_string(Commands Cmd) { return uCentralAPCommands[(uint8_t)Cmd]; }
|
inline const char *to_string(Commands Cmd) { return uCentralAPCommands[(uint8_t)Cmd]; }
|
||||||
|
|||||||
Reference in New Issue
Block a user