mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-10-30 02:02:36 +00:00
Adding 'updateAllDevices' for venu configuration push.
This commit is contained in:
@@ -136,7 +136,7 @@ add_executable(owprov
|
||||
src/storage/storage_variables.cpp src/storage/storage_variables.h
|
||||
src/RESTAPI/RESTAPI_variables_handler.cpp src/RESTAPI/RESTAPI_variables_handler.h
|
||||
src/RESTAPI/RESTAPI_variables_list_handler.cpp src/RESTAPI/RESTAPI_variables_list_handler.h
|
||||
src/FileDownloader.cpp src/FileDownloader.h)
|
||||
src/FileDownloader.cpp src/FileDownloader.h src/Tasks/VenueConfigUpdater.cpp src/Tasks/VenueConfigUpdater.h)
|
||||
|
||||
target_link_libraries(owprov PUBLIC
|
||||
${Poco_LIBRARIES}
|
||||
|
||||
@@ -2067,6 +2067,12 @@ paths:
|
||||
type: boolean
|
||||
default: false
|
||||
required: false
|
||||
- in: query
|
||||
name: testUpdateOnly
|
||||
schema:
|
||||
type: boolean
|
||||
default: false
|
||||
required: false
|
||||
requestBody:
|
||||
description: Information used to modify the new venue
|
||||
content:
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||
#include "StorageService.h"
|
||||
#include "RESTAPI/RESTAPI_db_helpers.h"
|
||||
#include "Tasks/VenueConfigUpdater.h"
|
||||
|
||||
namespace OpenWifi{
|
||||
|
||||
@@ -200,13 +201,26 @@ namespace OpenWifi{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
auto testUpdateOnly = GetBoolParameter("testUpdateOnly");
|
||||
if(testUpdateOnly) {
|
||||
ProvObjects::SerialNumberList SNL;
|
||||
|
||||
Poco::JSON::Object Answer;
|
||||
SNL.serialNumbers = Existing.devices;
|
||||
SNL.to_json(Answer);
|
||||
return ReturnObject(Answer);
|
||||
}
|
||||
|
||||
auto updateAllDevices = GetBoolParameter("updateAllDevices");
|
||||
if(updateAllDevices) {
|
||||
ProvObjects::SerialNumberList SNL;
|
||||
|
||||
Poco::JSON::Object Answer;
|
||||
|
||||
SNL.serialNumbers = Existing.devices;
|
||||
|
||||
auto Task = new VenueConfigUpdater(UUID,UserInfo_.userinfo,0,Logger());
|
||||
Task->Start();
|
||||
|
||||
SNL.to_json(Answer);
|
||||
return ReturnObject(Answer);
|
||||
}
|
||||
|
||||
5
src/Tasks/VenueConfigUpdater.cpp
Normal file
5
src/Tasks/VenueConfigUpdater.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by stephane bourque on 2022-04-01.
|
||||
//
|
||||
|
||||
#include "VenueConfigUpdater.h"
|
||||
60
src/Tasks/VenueConfigUpdater.h
Normal file
60
src/Tasks/VenueConfigUpdater.h
Normal file
@@ -0,0 +1,60 @@
|
||||
//
|
||||
// Created by stephane bourque on 2022-04-01.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "framework/MicroService.h"
|
||||
#include "StorageService.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
class VenueConfigUpdater: public Poco::Runnable {
|
||||
public:
|
||||
explicit VenueConfigUpdater(const std::string & VenueUUID, const SecurityObjects::UserInfo &UI, uint64_t When, Poco::Logger &L) :
|
||||
VenueUUID_(VenueUUID),
|
||||
UI_(UI),
|
||||
When_(When),
|
||||
Logger_(L)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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_;
|
||||
|
||||
inline Poco::Logger & Logger() { return Logger_; }
|
||||
|
||||
void run() final {
|
||||
|
||||
if(When_ && When_>OpenWifi::Now())
|
||||
Poco::Thread::trySleep( (long) (When_ - OpenWifi::Now()) * 1000 );
|
||||
|
||||
Logger().information(fmt::format("Job {} Starting.", JobId_));
|
||||
|
||||
ProvObjects::Venue Venue;
|
||||
if(StorageService()->VenueDB().GetRecord("id",VenueUUID_,Venue)) {
|
||||
for(const Types::UUID_t &uuid:Venue.devices) {
|
||||
std::cout << "Updating device: " << uuid << std::endl;
|
||||
}
|
||||
} else {
|
||||
Logger().warning(fmt::format("Venue {} no longer exists.",VenueUUID_));
|
||||
}
|
||||
|
||||
Logger().information(fmt::format("Job {} Completed.", JobId_));
|
||||
delete this;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user