mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-10-29 17:52:28 +00:00
Adding system relaod
This commit is contained in:
@@ -341,14 +341,23 @@ namespace OpenWifi {
|
||||
return false;
|
||||
}
|
||||
|
||||
void MicroService::Reload(const std::string &Sub) {
|
||||
for (auto i : SubSystems_) {
|
||||
if (Poco::toLower(Sub) == Poco::toLower(i->Name())) {
|
||||
i->reinitialize(Poco::Util::Application::instance());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Types::StringVec MicroService::GetSubSystems() const {
|
||||
Types::StringVec Result;
|
||||
for(auto i:SubSystems_)
|
||||
Result.push_back(i->Name());
|
||||
Result.push_back(Poco::toLower(i->Name()));
|
||||
return Result;
|
||||
}
|
||||
|
||||
Types::StringPairVec MicroService::GetLogLevels() const {
|
||||
Types::StringPairVec MicroService::GetLogLevels() {
|
||||
Types::StringPairVec Result;
|
||||
|
||||
for(auto &i:SubSystems_) {
|
||||
@@ -358,7 +367,7 @@ namespace OpenWifi {
|
||||
return Result;
|
||||
}
|
||||
|
||||
const Types::StringVec & MicroService::GetLogLevelNames() const {
|
||||
const Types::StringVec & MicroService::GetLogLevelNames() {
|
||||
static Types::StringVec LevelNames{"none", "fatal", "critical", "error", "warning", "notice", "information", "debug", "trace" };
|
||||
return LevelNames;
|
||||
}
|
||||
|
||||
@@ -113,8 +113,8 @@ namespace OpenWifi {
|
||||
[[nodiscard]] bool Debug() const { return DebugMode_; }
|
||||
[[nodiscard]] uint64_t ID() const { return ID_; }
|
||||
[[nodiscard]] Types::StringVec GetSubSystems() const;
|
||||
[[nodiscard]] Types::StringPairVec GetLogLevels() const;
|
||||
[[nodiscard]] const Types::StringVec & GetLogLevelNames() const;
|
||||
[[nodiscard]] Types::StringPairVec GetLogLevels() ;
|
||||
[[nodiscard]] static const Types::StringVec & GetLogLevelNames();
|
||||
[[nodiscard]] std::string ConfigGetString(const std::string &Key,const std::string & Default);
|
||||
[[nodiscard]] std::string ConfigGetString(const std::string &Key);
|
||||
[[nodiscard]] std::string ConfigPath(const std::string &Key,const std::string & Default);
|
||||
@@ -142,6 +142,7 @@ namespace OpenWifi {
|
||||
static inline uint64_t GetPID() { return Poco::Process::id(); };
|
||||
[[nodiscard]] inline const std::string GetPublicAPIEndPoint() { return MyPublicEndPoint_ + "/api/v1"; };
|
||||
[[nodiscard]] inline const std::string & GetUIURI() const { return UIURI_;};
|
||||
void Reload(const std::string &Name);
|
||||
|
||||
private:
|
||||
bool HelpRequested_ = false;
|
||||
|
||||
@@ -49,6 +49,13 @@ namespace OpenWifi {
|
||||
Logger_.information("Stopping ");
|
||||
for( const auto & svr : RESTServers_ )
|
||||
svr->stop();
|
||||
RESTServers_.clear();
|
||||
}
|
||||
|
||||
void RESTAPI_InternalServer::reinitialize(Poco::Util::Application &self) {
|
||||
Logger_.information("Reinitializing.");
|
||||
Stop();
|
||||
Start();
|
||||
}
|
||||
|
||||
Poco::Net::HTTPRequestHandler *InternalRequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest & Request) {
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace OpenWifi {
|
||||
|
||||
int Start() override;
|
||||
void Stop() override;
|
||||
void reinitialize(Poco::Util::Application &self) override;
|
||||
|
||||
private:
|
||||
static RESTAPI_InternalServer *instance_;
|
||||
|
||||
@@ -74,6 +74,8 @@ namespace OpenWifi::RESTAPI::Protocol {
|
||||
static const char * HOSTNAME = "hostname";
|
||||
static const char * PROCESSORS = "processors";
|
||||
static const char * REASON = "reason";
|
||||
static const char * RELOAD = "reload";
|
||||
static const char * SUBSYSTEMS = "subsystems";
|
||||
static const char * FILEUUID = "uuid";
|
||||
static const char * USERID = "userId";
|
||||
static const char * PASSWORD = "password";
|
||||
|
||||
@@ -93,6 +93,14 @@ namespace OpenWifi {
|
||||
Logger_.information("Stopping ");
|
||||
for( const auto & svr : RESTServers_ )
|
||||
svr->stop();
|
||||
RESTServers_.clear();
|
||||
}
|
||||
|
||||
void RESTAPI_server::reinitialize(Poco::Util::Application &self) {
|
||||
Logger_.information("Reinitializing.");
|
||||
Stop();
|
||||
Start();
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
@@ -32,6 +32,7 @@ namespace OpenWifi {
|
||||
}
|
||||
int Start() override;
|
||||
void Stop() override;
|
||||
void reinitialize(Poco::Util::Application &self) override;
|
||||
|
||||
private:
|
||||
static RESTAPI_server *instance_;
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
#include "Daemon.h"
|
||||
#include "RESTAPI_protocol.h"
|
||||
#include "RESTAPI_errors.h"
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace OpenWifi {
|
||||
void RESTAPI_system_command::DoPost() {
|
||||
@@ -23,7 +27,7 @@ namespace OpenWifi {
|
||||
if (Obj->has(RESTAPI::Protocol::PARAMETERS) &&
|
||||
Obj->isArray(RESTAPI::Protocol::PARAMETERS)) {
|
||||
auto ParametersBlock = Obj->getArray(RESTAPI::Protocol::PARAMETERS);
|
||||
for (const auto &i:*ParametersBlock) {
|
||||
for (const auto &i : *ParametersBlock) {
|
||||
Poco::JSON::Parser pp;
|
||||
auto InnerObj = pp.parse(i).extract<Poco::JSON::Object::Ptr>();
|
||||
if (InnerObj->has(RESTAPI::Protocol::TAG) &&
|
||||
@@ -31,7 +35,8 @@ namespace OpenWifi {
|
||||
auto Name = GetS(RESTAPI::Protocol::TAG, InnerObj);
|
||||
auto Value = GetS(RESTAPI::Protocol::VALUE, InnerObj);
|
||||
Daemon()->SetSubsystemLogLevel(Name, Value);
|
||||
Logger_.information(Poco::format("Setting log level for %s at %s", Name, Value));
|
||||
Logger_.information(
|
||||
Poco::format("Setting log level for %s at %s", Name, Value));
|
||||
}
|
||||
}
|
||||
OK();
|
||||
@@ -41,42 +46,59 @@ namespace OpenWifi {
|
||||
auto CurrentLogLevels = Daemon()->GetLogLevels();
|
||||
Poco::JSON::Object Result;
|
||||
Poco::JSON::Array Array;
|
||||
for(auto &[Name,Level]:CurrentLogLevels) {
|
||||
for (auto &[Name, Level] : CurrentLogLevels) {
|
||||
Poco::JSON::Object Pair;
|
||||
Pair.set( RESTAPI::Protocol::TAG,Name);
|
||||
Pair.set(RESTAPI::Protocol::VALUE,Level);
|
||||
Pair.set(RESTAPI::Protocol::TAG, Name);
|
||||
Pair.set(RESTAPI::Protocol::VALUE, Level);
|
||||
Array.add(Pair);
|
||||
}
|
||||
Result.set(RESTAPI::Protocol::TAGLIST,Array);
|
||||
Result.set(RESTAPI::Protocol::TAGLIST, Array);
|
||||
ReturnObject(Result);
|
||||
return;
|
||||
} else if (Command == RESTAPI::Protocol::GETLOGLEVELNAMES) {
|
||||
Poco::JSON::Object Result;
|
||||
Poco::JSON::Array LevelNamesArray;
|
||||
const Types::StringVec & LevelNames = Daemon()->GetLogLevelNames();
|
||||
for(const auto &i:LevelNames)
|
||||
const Types::StringVec &LevelNames = Daemon()->GetLogLevelNames();
|
||||
for (const auto &i : LevelNames)
|
||||
LevelNamesArray.add(i);
|
||||
Result.set(RESTAPI::Protocol::LIST,LevelNamesArray);
|
||||
Result.set(RESTAPI::Protocol::LIST, LevelNamesArray);
|
||||
ReturnObject(Result);
|
||||
return;
|
||||
} else if (Command == RESTAPI::Protocol::GETSUBSYSTEMNAMES) {
|
||||
Poco::JSON::Object Result;
|
||||
Poco::JSON::Array LevelNamesArray;
|
||||
const Types::StringVec & SubSystemNames = Daemon()->GetSubSystems();
|
||||
for(const auto &i:SubSystemNames)
|
||||
const Types::StringVec &SubSystemNames = Daemon()->GetSubSystems();
|
||||
for (const auto &i : SubSystemNames)
|
||||
LevelNamesArray.add(i);
|
||||
Result.set(RESTAPI::Protocol::LIST,LevelNamesArray);
|
||||
Result.set(RESTAPI::Protocol::LIST, LevelNamesArray);
|
||||
ReturnObject(Result);
|
||||
return;
|
||||
} else if (Command == RESTAPI::Protocol::STATS) {
|
||||
|
||||
} else if (Command == RESTAPI::Protocol::RELOAD) {
|
||||
if (Obj->has(RESTAPI::Protocol::SUBSYSTEMS) &&
|
||||
Obj->isArray(RESTAPI::Protocol::SUBSYSTEMS)) {
|
||||
auto SubSystems = Obj->getArray(RESTAPI::Protocol::SUBSYSTEMS);
|
||||
std::vector<std::string> Names;
|
||||
for (const auto &i : *SubSystems)
|
||||
Names.push_back(i.toString());
|
||||
std::thread ReloadThread([Names](){
|
||||
std::this_thread::sleep_for(10000ms);
|
||||
for(const auto &i:Names) {
|
||||
Daemon()->Reload(i);
|
||||
}
|
||||
});
|
||||
ReloadThread.detach();
|
||||
}
|
||||
OK();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
BadRequest("Unknown command.");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
BadRequest("Missing command.");
|
||||
}
|
||||
}
|
||||
|
||||
void RESTAPI_system_command::DoGet() {
|
||||
std::string Arg;
|
||||
|
||||
@@ -32,6 +32,7 @@ void SubSystemServer::initialize(Poco::Util::Application &self) {
|
||||
auto i = 0;
|
||||
bool good = true;
|
||||
|
||||
ConfigServersList_.clear();
|
||||
while (good) {
|
||||
std::string root{SubSystemConfigPrefix_ + ".host." + std::to_string(i) + "."};
|
||||
|
||||
@@ -81,10 +82,11 @@ void SubSystemServer::initialize(Poco::Util::Application &self) {
|
||||
}
|
||||
}
|
||||
|
||||
void SubSystemServer::uninitialize() {}
|
||||
void SubSystemServer::uninitialize() {
|
||||
}
|
||||
|
||||
void SubSystemServer::reinitialize(Poco::Util::Application &self) {
|
||||
// add your own reinitialization code here
|
||||
Logger_.information("Reloading of this subsystem is not supported.");
|
||||
}
|
||||
|
||||
void SubSystemServer::defineOptions(Poco::Util::OptionSet &options) {}
|
||||
|
||||
@@ -390,12 +390,28 @@ validateconfig() {
|
||||
}
|
||||
|
||||
systeminfo() {
|
||||
curl ${FLAGS} -X GET "https://${OWGW}/api/v1/system?command=info" \
|
||||
curl ${FLAGS} -X GET "https://${OWPROV}/api/v1/system?command=info" \
|
||||
-H "accept: application/json" \
|
||||
-H "Authorization: Bearer ${token}" > ${result_file}
|
||||
jq < ${result_file}
|
||||
}
|
||||
|
||||
getsubsystemnames() {
|
||||
payload="{ \"command\" : \"getsubsystemnames\" }"
|
||||
curl ${FLAGS} -X POST "https://${OWPROV}/api/v1/system" \
|
||||
-H "accept: application/json" \
|
||||
-H "Authorization: Bearer ${token}" \
|
||||
-d "$payload"
|
||||
}
|
||||
|
||||
reloadsubsystem() {
|
||||
payload="{ \"command\" : \"reload\", \"subsystems\" : [ \"OUIServer\" , \"CommandManager\" ] }"
|
||||
curl ${FLAGS} -X POST "https://${OWPROV}/api/v1/system" \
|
||||
-H "accept: application/json" \
|
||||
-H "Authorization: Bearer ${token}" \
|
||||
-d "$payload"
|
||||
}
|
||||
|
||||
shopt -s nocasematch
|
||||
case "$1" in
|
||||
"login") login; help ; logout ;;
|
||||
@@ -431,6 +447,8 @@ case "$1" in
|
||||
"addconfigfile") login; addconfigfile "$2" ; logout;;
|
||||
"validateconfig") login; validateconfig "$2"; logout;;
|
||||
"systeminfo") login; systeminfo ; logout;;
|
||||
"getsubsystemnames") login; getsubsystemnames; logout ;;
|
||||
"reloadsubsystem") login; reloadsubsystem; logout ;;
|
||||
*) help ;;
|
||||
esac
|
||||
|
||||
|
||||
Reference in New Issue
Block a user