mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-10-29 17:52:28 +00:00
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
This commit is contained in:
@@ -33,12 +33,9 @@ namespace OpenWifi {
|
||||
|
||||
std::lock_guard G(Mutex_);
|
||||
|
||||
std::cout << jobs_.size() << " jobs in queue." << std::endl;
|
||||
|
||||
for(auto &job:jobs_) {
|
||||
if(job!=nullptr) {
|
||||
if(job->Started()==0 && Pool_.used()<Pool_.available()) {
|
||||
std::cout << "Starting: " << job->Name() << " ID:" << job->JobId() << std::endl;
|
||||
job->Logger().information(fmt::format("Starting {}: {}",job->JobId(),job->Name()));
|
||||
job->Start();
|
||||
Pool_.start(*job);
|
||||
@@ -46,11 +43,10 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << Pool_.used() << " jobs running. Max jobs: " << Pool_.available() << std::endl;
|
||||
for(auto it = jobs_.begin(); it!=jobs_.end();) {
|
||||
if(*it!=nullptr && (*it)->Completed()!=0) {
|
||||
auto tmp = it;
|
||||
std::cout << "Completed: " << (*it)->Name() << " ID:" << (*it)->JobId() << std::endl;
|
||||
(*it)->Logger().information(fmt::format("Completed {}: {}",(*it)->JobId(),(*it)->Name()));
|
||||
it = jobs_.erase(it);
|
||||
delete *tmp;
|
||||
} else {
|
||||
|
||||
@@ -246,9 +246,12 @@ namespace OpenWifi{
|
||||
|
||||
Poco::JSON::Object Answer;
|
||||
SNL.serialNumbers = Existing.devices;
|
||||
|
||||
auto Task = new VenueUpgrade(UUID,UserInfo_.userinfo,0,Logger());
|
||||
auto JobId = Task->Start();
|
||||
auto JobId = MicroService::instance().CreateUUID();
|
||||
Types::StringVec Parameters{UUID};;
|
||||
auto NewJob = new VenueUpgrade(JobId,"VenueFirmwareUpgrade", Parameters, 0, UserInfo_.userinfo, Logger());
|
||||
std::cout << "Adding new job" << std::endl;
|
||||
JobController()->AddJob(dynamic_cast<Job*>(NewJob));
|
||||
std::cout << "Job added" << std::endl;
|
||||
|
||||
SNL.to_json(Answer);
|
||||
Answer.set("jobId",JobId);
|
||||
@@ -260,9 +263,12 @@ namespace OpenWifi{
|
||||
|
||||
Poco::JSON::Object Answer;
|
||||
SNL.serialNumbers = Existing.devices;
|
||||
|
||||
auto Task = new VenueRebooter(UUID,UserInfo_.userinfo,0,Logger());
|
||||
auto JobId = Task->Start();
|
||||
auto JobId = MicroService::instance().CreateUUID();
|
||||
Types::StringVec Parameters{UUID};;
|
||||
auto NewJob = new VenueRebooter(JobId,"VenueFirmwareUpgrade", Parameters, 0, UserInfo_.userinfo, Logger());
|
||||
std::cout << "Adding new job" << std::endl;
|
||||
JobController()->AddJob(dynamic_cast<Job*>(NewJob));
|
||||
std::cout << "Job added" << std::endl;
|
||||
|
||||
SNL.to_json(Answer);
|
||||
Answer.set("jobId",JobId);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "StorageService.h"
|
||||
#include "APConfig.h"
|
||||
#include "sdks/SDK_gw.h"
|
||||
#include "JobController.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
@@ -48,44 +49,19 @@ namespace OpenWifi {
|
||||
inline Poco::Logger & Logger() { return Logger_; }
|
||||
};
|
||||
|
||||
class VenueRebooter: public Poco::Runnable {
|
||||
class VenueRebooter: public Job {
|
||||
public:
|
||||
explicit VenueRebooter(const std::string & VenueUUID, const SecurityObjects::UserInfo &UI, uint64_t When, Poco::Logger &L) :
|
||||
VenueUUID_(VenueUUID),
|
||||
UI_(UI),
|
||||
When_(When),
|
||||
Logger_(L)
|
||||
{
|
||||
VenueRebooter(const std::string &JobID, const std::string &name, const std::vector<std::string> & parameters, uint64_t when, const SecurityObjects::UserInfo &UI, Poco::Logger &L) :
|
||||
Job(JobID, name, parameters, when, UI, L) {
|
||||
|
||||
}
|
||||
|
||||
inline std::string Start() {
|
||||
JobId_ = MicroService::CreateUUID();
|
||||
Worker_.start(*this);
|
||||
return JobId_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string VenueUUID_;
|
||||
SecurityObjects::UserInfo UI_;
|
||||
uint64_t When_;
|
||||
Poco::Logger &Logger_;
|
||||
Poco::Thread Worker_;
|
||||
std::string JobId_;
|
||||
Poco::ThreadPool Pool_{2,16,300};
|
||||
|
||||
inline Poco::Logger & Logger() { return Logger_; }
|
||||
|
||||
inline void run() final {
|
||||
inline virtual void run() final {
|
||||
|
||||
Utils::SetThreadName("venue-reboot");
|
||||
|
||||
if(When_ && When_>OpenWifi::Now())
|
||||
Poco::Thread::trySleep( (long) (When_ - OpenWifi::Now()) * 1000 );
|
||||
|
||||
WebSocketClientNotificationVenueRebootList_t N;
|
||||
|
||||
Logger().information(fmt::format("Job {} Starting.", JobId_));
|
||||
auto VenueUUID_ = Parameter(0);
|
||||
|
||||
ProvObjects::Venue Venue;
|
||||
uint64_t rebooted_ = 0, failed_ = 0;
|
||||
@@ -97,7 +73,7 @@ namespace OpenWifi {
|
||||
};
|
||||
|
||||
N.content.title = fmt::format("Rebooting {} devices.", Venue.info.name);
|
||||
N.content.jobId = JobId_;
|
||||
N.content.jobId = JobId();
|
||||
|
||||
std::array<tState,MaxThreads> Tasks;
|
||||
|
||||
@@ -162,20 +138,18 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
N.content.details = fmt::format("Job {} Completed: {} rebooted, {} failed to reboot.",
|
||||
JobId_, rebooted_ ,failed_);
|
||||
JobId(), rebooted_ ,failed_);
|
||||
|
||||
} else {
|
||||
N.content.details = fmt::format("Venue {} no longer exists.",VenueUUID_);
|
||||
Logger().warning(N.content.details);
|
||||
}
|
||||
|
||||
WebSocketClientNotificationVenueRebootCompletionToUser(UI_.email,N);
|
||||
WebSocketClientNotificationVenueRebootCompletionToUser(UserInfo().email,N);
|
||||
Logger().information(fmt::format("Job {} Completed: {} rebooted, {} failed to reboot.",
|
||||
JobId_, rebooted_ ,failed_));
|
||||
|
||||
JobId(), rebooted_ ,failed_));
|
||||
Utils::SetThreadName("free");
|
||||
|
||||
delete this;
|
||||
Complete();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "APConfig.h"
|
||||
#include "sdks/SDK_gw.h"
|
||||
#include "sdks/SDK_fms.h"
|
||||
#include "JobController.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
class VenueDeviceUpgrade : public Poco::Runnable {
|
||||
@@ -69,45 +70,20 @@ namespace OpenWifi {
|
||||
inline Poco::Logger & Logger() { return Logger_; }
|
||||
};
|
||||
|
||||
class VenueUpgrade: public Poco::Runnable {
|
||||
class VenueUpgrade: public Job {
|
||||
public:
|
||||
explicit VenueUpgrade(const std::string & VenueUUID, const SecurityObjects::UserInfo &UI, uint64_t When, Poco::Logger &L) :
|
||||
VenueUUID_(VenueUUID),
|
||||
UI_(UI),
|
||||
When_(When),
|
||||
Logger_(L)
|
||||
{
|
||||
VenueUpgrade(const std::string &JobID, const std::string &name, const std::vector<std::string> & parameters, uint64_t when, const SecurityObjects::UserInfo &UI, Poco::Logger &L) :
|
||||
Job(JobID, name, parameters, when, UI, L) {
|
||||
|
||||
}
|
||||
|
||||
inline std::string Start() {
|
||||
JobId_ = MicroService::CreateUUID();
|
||||
Worker_.start(*this);
|
||||
return JobId_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string VenueUUID_;
|
||||
SecurityObjects::UserInfo UI_;
|
||||
uint64_t When_;
|
||||
Poco::Logger &Logger_;
|
||||
Poco::Thread Worker_;
|
||||
std::string JobId_;
|
||||
Poco::ThreadPool Pool_{2,16,300};
|
||||
|
||||
inline Poco::Logger & Logger() { return Logger_; }
|
||||
|
||||
inline void run() final {
|
||||
inline virtual void run() final {
|
||||
|
||||
Utils::SetThreadName("venue-upgr");
|
||||
|
||||
if(When_ && When_>OpenWifi::Now())
|
||||
Poco::Thread::trySleep( (long) (When_ - OpenWifi::Now()) * 1000 );
|
||||
auto VenueUUID_ = Parameter(0);
|
||||
|
||||
WebSocketClientNotificationVenueRebootList_t N;
|
||||
|
||||
Logger().information(fmt::format("Job {} Starting.", JobId_));
|
||||
|
||||
ProvObjects::Venue Venue;
|
||||
uint64_t upgraded_ = 0, failed_ = 0;
|
||||
if(StorageService()->VenueDB().GetRecord("id",VenueUUID_,Venue)) {
|
||||
@@ -118,7 +94,7 @@ namespace OpenWifi {
|
||||
};
|
||||
|
||||
N.content.title = fmt::format("Upgrading {} devices.", Venue.info.name);
|
||||
N.content.jobId = JobId_;
|
||||
N.content.jobId = JobId();
|
||||
|
||||
std::array<tState,MaxThreads> Tasks;
|
||||
ProvObjects::DeviceRules Rules;
|
||||
@@ -186,19 +162,19 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
N.content.details = fmt::format("Job {} Completed: {} upgraded, {} failed to upgrade.",
|
||||
JobId_, upgraded_ ,failed_);
|
||||
JobId(), upgraded_ ,failed_);
|
||||
|
||||
} else {
|
||||
N.content.details = fmt::format("Venue {} no longer exists.",VenueUUID_);
|
||||
Logger().warning(N.content.details);
|
||||
}
|
||||
|
||||
WebSocketClientNotificationVenueRebootCompletionToUser(UI_.email,N);
|
||||
WebSocketClientNotificationVenueRebootCompletionToUser(UserInfo().email,N);
|
||||
Logger().information(fmt::format("Job {} Completed: {} upgraded, {} failed to upgrade.",
|
||||
JobId_, upgraded_ ,failed_));
|
||||
JobId(), upgraded_ ,failed_));
|
||||
Utils::SetThreadName("free");
|
||||
|
||||
delete this;
|
||||
Complete();
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user