Merge pull request #92 from Telecominfraproject/main

https://telecominfraproject.atlassian.net/browse/WIFI-13200
This commit is contained in:
Stephane Bourque
2023-12-15 09:15:00 -08:00
committed by GitHub
19 changed files with 302 additions and 82 deletions

2
build
View File

@@ -1 +1 @@
2
10

View File

@@ -276,21 +276,19 @@ namespace OpenWifi {
auto testUpdateOnly = GetBoolParameter("testUpdateOnly");
if (testUpdateOnly) {
ProvObjects::SerialNumberList SNL;
StorageService()->InventoryDB().GetDevicesForVenue(UUID, SNL.serialNumbers);
Poco::JSON::Object Answer;
SNL.serialNumbers = Existing.devices;
SNL.to_json(Answer);
return ReturnObject(Answer);
}
if (GetBoolParameter("updateAllDevices")) {
ProvObjects::SerialNumberList SNL;
StorageService()->InventoryDB().GetDevicesForVenue(UUID, SNL.serialNumbers);
Poco::JSON::Object Answer;
SNL.serialNumbers = Existing.devices;
auto JobId = MicroServiceCreateUUID();
Types::StringVec Parameters{UUID};
;
auto NewJob = new VenueConfigUpdater(JobId, "VenueConfigurationUpdater", Parameters, 0,
UserInfo_.userinfo, Logger());
JobController()->AddJob(dynamic_cast<Job *>(NewJob));
@@ -302,11 +300,10 @@ namespace OpenWifi {
if (GetBoolParameter("upgradeAllDevices")) {
if (GetBoolParameter("revisionsAvailable")) {
std::set<std::string> DeviceTypes;
for (const auto &serialNumber : Existing.devices) {
ProvObjects::InventoryTag Device;
if (StorageService()->InventoryDB().GetRecord("id", serialNumber, Device)) {
DeviceTypes.insert(Device.deviceType);
}
std::vector<ProvObjects::InventoryTag> ExistingDevices;
StorageService()->InventoryDB().GetDevicesForVenue(UUID, ExistingDevices);
for (const auto &device : ExistingDevices) {
DeviceTypes.insert(device.deviceType);
}
// Get all the revisions for all the device types
@@ -374,18 +371,17 @@ namespace OpenWifi {
return ReturnObject(Answer);
}
ProvObjects::SerialNumberList SNL;
auto Revision = GetParameter("revision", "");
if (Revision.empty()) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
ProvObjects::SerialNumberList SNL;
StorageService()->InventoryDB().GetDevicesForVenue(UUID, SNL.serialNumbers);
Poco::JSON::Object Answer;
SNL.serialNumbers = Existing.devices;
auto JobId = MicroServiceCreateUUID();
Types::StringVec Parameters{UUID, Revision};
;
auto NewJob = new VenueUpgrade(JobId, "VenueFirmwareUpgrade", Parameters, 0,
UserInfo_.userinfo, Logger());
JobController()->AddJob(dynamic_cast<Job *>(NewJob));
@@ -396,9 +392,9 @@ namespace OpenWifi {
if (GetBoolParameter("rebootAllDevices")) {
ProvObjects::SerialNumberList SNL;
StorageService()->InventoryDB().GetDevicesForVenue(UUID, SNL.serialNumbers);
Poco::JSON::Object Answer;
SNL.serialNumbers = Existing.devices;
auto JobId = MicroServiceCreateUUID();
Types::StringVec Parameters{UUID};
;

View File

@@ -118,8 +118,9 @@ namespace OpenWifi {
Poco::ThreadPool Pool_;
std::list<VenueDeviceConfigUpdater *> JobList;
for (const auto &uuid : Venue.devices) {
std::vector<std::string> DeviceList;
StorageService()->InventoryDB().GetDevicesUUIDForVenue(Venue.info.id, DeviceList);
for (const auto &uuid : DeviceList) {
auto NewTask = new VenueDeviceConfigUpdater(uuid, Venue.info.name, Logger());
bool TaskAdded = false;
while (!TaskAdded) {

View File

@@ -68,8 +68,10 @@ namespace OpenWifi {
Poco::ThreadPool Pool_;
std::list<VenueDeviceRebooter *> JobList;
std::vector<std::string> DeviceList;
StorageService()->InventoryDB().GetDevicesUUIDForVenue(Venue.info.id, DeviceList);
for (const auto &uuid : Venue.devices) {
for (const auto &uuid : DeviceList) {
auto NewTask = new VenueDeviceRebooter(uuid, Venue.info.name, Logger());
bool TaskAdded = false;
while (!TaskAdded) {

View File

@@ -28,7 +28,7 @@ namespace OpenWifi {
Storage::ApplyRules(rules_, Device.deviceRules);
if (Device.deviceRules.firmwareUpgrade == "no") {
poco_debug(Logger(), fmt::format("Skipped Upgrade: {}", Device.serialNumber));
poco_debug(Logger(), fmt::format("Skipped Upgrade: {} : Venue rules prevent upgrading", Device.serialNumber));
skipped_++;
done_ = true;
return;
@@ -36,10 +36,15 @@ namespace OpenWifi {
FMSObjects::Firmware F;
if (SDK::FMS::Firmware::GetFirmware(Device.deviceType, revision_, F)) {
if (SDK::GW::Device::Upgrade(nullptr, Device.serialNumber, 0, F.uri)) {
Logger().debug(
fmt::format("{}: Upgraded to {}.", Device.serialNumber, revision_));
upgraded_++;
std::string Status;
if (SDK::GW::Device::Upgrade(nullptr, Device.serialNumber, 0, F.uri, Status)) {
if(Status=="pending") {
pending_++;
poco_debug(Logger(), fmt::format("Upgrade Pending: {} : {}", Device.serialNumber, Status));
} else {
upgraded_++;
poco_debug(Logger(), fmt::format("Upgrade Success: {} : {}", Device.serialNumber, Status));
}
} else {
poco_information(Logger(), fmt::format("{}: Not Upgraded to {}.",
Device.serialNumber, revision_));
@@ -53,10 +58,9 @@ namespace OpenWifi {
}
}
done_ = true;
// std::cout << "Done push for " << Device.serialNumber << std::endl;
}
std::uint64_t upgraded_ = 0, not_connected_ = 0, skipped_ = 0, no_firmware_ = 0;
std::uint64_t upgraded_ = 0, not_connected_ = 0, skipped_ = 0, no_firmware_ = 0, pending_ = 0;
bool started_ = false, done_ = false;
std::string SerialNumber;
@@ -85,7 +89,7 @@ namespace OpenWifi {
ProvWebSocketNotifications::VenueFWUpgradeList_t N;
ProvObjects::Venue Venue;
uint64_t upgraded_ = 0, not_connected_ = 0, skipped_ = 0, no_firmware_ = 0;
uint64_t upgraded_ = 0, not_connected_ = 0, skipped_ = 0, no_firmware_ = 0, pending_=0;
if (StorageService()->VenueDB().GetRecord("id", VenueUUID_, Venue)) {
N.content.title = fmt::format("Upgrading {} devices.", Venue.info.name);
@@ -96,8 +100,10 @@ namespace OpenWifi {
ProvObjects::DeviceRules Rules;
StorageService()->VenueDB().EvaluateDeviceRules(Venue.info.id, Rules);
std::vector<std::string> DeviceList;
StorageService()->InventoryDB().GetDevicesUUIDForVenue(Venue.info.id, DeviceList);
for (const auto &uuid : Venue.devices) {
for (const auto &uuid : DeviceList) {
auto NewTask =
new VenueDeviceUpgrade(uuid, Venue.info.name, Revision_, Rules, Logger());
bool TaskAdded = false;
@@ -121,10 +127,13 @@ namespace OpenWifi {
N.content.not_connected.push_back(current_job->SerialNumber);
else if (current_job->no_firmware_)
N.content.no_firmware.push_back(current_job->SerialNumber);
else if (current_job->pending_)
N.content.pending.push_back(current_job->SerialNumber);
upgraded_ += current_job->upgraded_;
skipped_ += current_job->skipped_;
no_firmware_ += current_job->no_firmware_;
not_connected_ += current_job->not_connected_;
pending_ += current_job->pending_;
job_it = JobList.erase(job_it);
delete current_job;
} else {
@@ -146,10 +155,13 @@ namespace OpenWifi {
N.content.not_connected.push_back(current_job->SerialNumber);
else if (current_job->no_firmware_)
N.content.no_firmware.push_back(current_job->SerialNumber);
else if (current_job->pending_)
N.content.pending.push_back(current_job->SerialNumber);
upgraded_ += current_job->upgraded_;
skipped_ += current_job->skipped_;
no_firmware_ += current_job->no_firmware_;
not_connected_ += current_job->not_connected_;
pending_ += current_job->pending_;
job_it = JobList.erase(job_it);
delete current_job;
} else {
@@ -158,8 +170,8 @@ namespace OpenWifi {
}
N.content.details = fmt::format(
"Job {} Completed: {} upgraded, {} not connected, {} skipped, {} no firmware.",
JobId(), upgraded_, not_connected_, skipped_, no_firmware_);
"Job {} Completed: {} upgraded, {} not connected, {} skipped, {} no firmware, {} pending.",
JobId(), upgraded_, not_connected_, skipped_, no_firmware_, pending_);
} else {
N.content.details = fmt::format("Venue {} no longer exists.", VenueUUID_);
Logger().warning(N.content.details);

View File

@@ -60,6 +60,7 @@ namespace OpenWifi::ProvWebSocketNotifications {
RESTAPI_utils::field_to_json(Obj, "success", success);
RESTAPI_utils::field_to_json(Obj, "notConnected", not_connected);
RESTAPI_utils::field_to_json(Obj, "noFirmware", no_firmware);
RESTAPI_utils::field_to_json(Obj, "pending", pending);
RESTAPI_utils::field_to_json(Obj, "skipped", skipped);
RESTAPI_utils::field_to_json(Obj, "timeStamp", timeStamp);
RESTAPI_utils::field_to_json(Obj, "details", details);
@@ -71,6 +72,7 @@ namespace OpenWifi::ProvWebSocketNotifications {
RESTAPI_utils::field_from_json(Obj, "jobId", jobId);
RESTAPI_utils::field_from_json(Obj, "success", success);
RESTAPI_utils::field_from_json(Obj, "notConnected", not_connected);
RESTAPI_utils::field_from_json(Obj, "pending", pending);
RESTAPI_utils::field_from_json(Obj, "noFirmware", no_firmware);
RESTAPI_utils::field_from_json(Obj, "skipped", skipped);
RESTAPI_utils::field_from_json(Obj, "timeStamp", timeStamp);

View File

@@ -32,7 +32,7 @@ namespace OpenWifi::ProvWebSocketNotifications {
struct FWUpgradeList {
std::string title, details, jobId;
std::vector<std::string> success, skipped, no_firmware, not_connected;
std::vector<std::string> success, skipped, no_firmware, not_connected, pending;
uint64_t timeStamp = OpenWifi::Utils::Now();
void to_json(Poco::JSON::Object &Obj) const;

View File

@@ -9,8 +9,6 @@
namespace OpenWifi {
EventBusManager::EventBusManager(Poco::Logger &L) : Logger_(L) {}
void EventBusManager::run() {
Running_ = true;
Utils::SetThreadName("fmwk:EventMgr");

View File

@@ -12,6 +12,16 @@ namespace OpenWifi {
class EventBusManager : public Poco::Runnable {
public:
EventBusManager() :
Logger_(Poco::Logger::create(
"EventBusManager", Poco::Logger::root().getChannel(), Poco::Logger::root().getLevel())) {
}
static auto instance() {
static auto instance_ = new EventBusManager;
return instance_;
}
explicit EventBusManager(Poco::Logger &L);
void run() final;
void Start();
@@ -24,4 +34,6 @@ namespace OpenWifi {
Poco::Logger &Logger_;
};
inline auto EventBusManager() { return EventBusManager::instance(); }
} // namespace OpenWifi

View File

@@ -33,9 +33,23 @@ namespace OpenWifi {
void MicroService::Exit(int Reason) { std::exit(Reason); }
static std::string MakeServiceListString(const Types::MicroServiceMetaMap &Services) {
std::string SvcList;
for (const auto &Svc : Services) {
if (SvcList.empty())
SvcList = Svc.second.Type;
else
SvcList += ", " + Svc.second.Type;
}
return SvcList;
}
void MicroService::BusMessageReceived([[maybe_unused]] const std::string &Key,
const std::string &Payload) {
std::lock_guard G(InfraMutex_);
Poco::Logger &BusLogger = EventBusManager()->Logger();
try {
Poco::JSON::Parser P;
auto Object = P.parse(Payload).extract<Poco::JSON::Object::Ptr>();
@@ -55,13 +69,10 @@ namespace OpenWifi {
Object->has(KafkaTopics::ServiceEvents::Fields::KEY)) {
auto PrivateEndPoint =
Object->get(KafkaTopics::ServiceEvents::Fields::PRIVATE).toString();
if (Event == KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE &&
Services_.find(PrivateEndPoint) != Services_.end()) {
Services_[PrivateEndPoint].LastUpdate = Utils::Now();
} else if (Event == KafkaTopics::ServiceEvents::EVENT_LEAVE) {
if (Event == KafkaTopics::ServiceEvents::EVENT_LEAVE) {
Services_.erase(PrivateEndPoint);
poco_debug(
logger(),
poco_information(
BusLogger,
fmt::format(
"Service {} ID={} leaving system.",
Object->get(KafkaTopics::ServiceEvents::Fields::PRIVATE)
@@ -69,14 +80,7 @@ namespace OpenWifi {
ID));
} else if (Event == KafkaTopics::ServiceEvents::EVENT_JOIN ||
Event == KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE) {
poco_debug(
logger(),
fmt::format(
"Service {} ID={} joining system.",
Object->get(KafkaTopics::ServiceEvents::Fields::PRIVATE)
.toString(),
ID));
Services_[PrivateEndPoint] = Types::MicroServiceMeta{
auto ServiceInfo = Types::MicroServiceMeta{
.Id = ID,
.Type = Poco::toLower(
Object->get(KafkaTopics::ServiceEvents::Fields::TYPE)
@@ -94,20 +98,46 @@ namespace OpenWifi {
.toString(),
.LastUpdate = Utils::Now()};
std::string SvcList;
for (const auto &Svc : Services_) {
if (SvcList.empty())
SvcList = Svc.second.Type;
else
SvcList += ", " + Svc.second.Type;
auto s1 = MakeServiceListString(Services_);
auto PreviousSize = Services_.size();
Services_[PrivateEndPoint] = ServiceInfo;
auto CurrentSize = Services_.size();
if(Event == KafkaTopics::ServiceEvents::EVENT_JOIN) {
if(!s1.empty()) {
poco_information(
BusLogger,
fmt::format(
"Service {} ID={} is joining the system.",
Object
->get(
KafkaTopics::ServiceEvents::Fields::PRIVATE)
.toString(),
ID));
}
std::string SvcList;
for (const auto &Svc : Services_) {
if (SvcList.empty())
SvcList = Svc.second.Type;
else
SvcList += ", " + Svc.second.Type;
}
poco_information(
BusLogger,
fmt::format("Current list of microservices: {}", SvcList));
} else if(CurrentSize!=PreviousSize) {
poco_information(
BusLogger,
fmt::format(
"Service {} ID={} is being added back in.",
Object
->get(KafkaTopics::ServiceEvents::Fields::PRIVATE)
.toString(),
ID));
}
poco_information(
logger(),
fmt::format("Current list of microservices: {}", SvcList));
}
} else {
poco_error(
logger(),
poco_information(
BusLogger,
fmt::format("KAFKA-MSG: invalid event '{}', missing a field.",
Event));
}
@@ -118,32 +148,39 @@ namespace OpenWifi {
Object->get(KafkaTopics::ServiceEvents::Fields::TOKEN).toString());
#endif
} else {
poco_error(
logger(),
poco_information(
BusLogger,
fmt::format("KAFKA-MSG: invalid event '{}', missing token", Event));
}
} else {
poco_error(logger(),
poco_information(BusLogger,
fmt::format("Unknown Event: {} Source: {}", Event, ID));
}
}
} else {
poco_error(logger(), "Bad bus message.");
std::ostringstream os;
Object->stringify(std::cout);
std::ostringstream os;
Object->stringify(std::cout);
poco_error(BusLogger, fmt::format("Bad bus message: {}", os.str()));
}
auto i = Services_.begin();
auto ServiceHint = Services_.begin();
auto now = Utils::Now();
for (; i != Services_.end();) {
if ((now - i->second.LastUpdate) > 60) {
i = Services_.erase(i);
auto si1 = Services_.size();
auto ss1 = MakeServiceListString(Services_);
while(ServiceHint!=Services_.end()) {
if ((now - ServiceHint->second.LastUpdate) > 120) {
poco_information(BusLogger, fmt::format("ZombieService: Removing service {}, ", ServiceHint->second.PublicEndPoint));
ServiceHint = Services_.erase(ServiceHint);
} else
++i;
++ServiceHint;
}
if(Services_.size() != si1) {
auto ss2 = MakeServiceListString(Services_);
poco_information(BusLogger, fmt::format("Current list of microservices: {} -> {}", ss1, ss2));
}
} catch (const Poco::Exception &E) {
logger().log(E);
BusLogger.log(E);
}
}
@@ -412,7 +449,7 @@ namespace OpenWifi {
try {
DataDir.createDirectory();
} catch (const Poco::Exception &E) {
logger().log(E);
Logger_.log(E);
}
}
WWWAssetsDir_ = ConfigPath("openwifi.restapi.wwwassets", "");
@@ -530,14 +567,12 @@ namespace OpenWifi {
for (auto i : SubSystems_) {
i->Start();
}
EventBusManager_ = std::make_unique<EventBusManager>(Poco::Logger::create(
"EventBusManager", Poco::Logger::root().getChannel(), Poco::Logger::root().getLevel()));
EventBusManager_->Start();
EventBusManager()->Start();
}
void MicroService::StopSubSystemServers() {
AddActivity("Stopping");
EventBusManager_->Stop();
EventBusManager()->Stop();
for (auto i = SubSystems_.rbegin(); i != SubSystems_.rend(); ++i) {
(*i)->Stop();
}
@@ -697,7 +732,7 @@ namespace OpenWifi {
auto APIKEY = Request.get("X-API-KEY");
return APIKEY == MyHash_;
} catch (const Poco::Exception &E) {
logger().log(E);
Logger_.log(E);
}
return false;
}

View File

@@ -201,7 +201,6 @@ namespace OpenWifi {
Poco::JWT::Signer Signer_;
Poco::Logger &Logger_;
Poco::ThreadPool TimerPool_{"timer:pool", 2, 32};
std::unique_ptr<EventBusManager> EventBusManager_;
};
inline MicroService *MicroService::instance_ = nullptr;

View File

@@ -47,6 +47,8 @@ namespace OpenWifi {
}
Poco::Data::SessionPool &Pool() { return *Pool_; }
private:
inline int Setup_SQLite();
inline int Setup_MySQL();

View File

@@ -576,8 +576,8 @@ namespace ORM {
bool UpdateRecord(field_name_t FieldName, const T &Value, const RecordType &R) {
try {
assert(ValidFieldName(FieldName));
Poco::Data::Session Session = Pool_.get();
Session.begin();
Poco::Data::Statement Update(Session);
RecordTuple RT;
@@ -593,6 +593,7 @@ namespace ORM {
Update.execute();
if (Cache_)
Cache_->UpdateCache(R);
Session.commit();
return true;
} catch (const Poco::Exception &E) {
Logger_.log(E);
@@ -662,6 +663,7 @@ namespace ORM {
assert(ValidFieldName(FieldName));
Poco::Data::Session Session = Pool_.get();
Session.begin();
Poco::Data::Statement Delete(Session);
std::string St = "delete from " + TableName_ + " where " + FieldName + "=?";
@@ -671,6 +673,7 @@ namespace ORM {
Delete.execute();
if (Cache_)
Cache_->Delete(FieldName, Value);
Session.commit();
return true;
} catch (const Poco::Exception &E) {
Logger_.log(E);
@@ -682,11 +685,13 @@ namespace ORM {
try {
assert(!WhereClause.empty());
Poco::Data::Session Session = Pool_.get();
Session.begin();
Poco::Data::Statement Delete(Session);
std::string St = "delete from " + TableName_ + " where " + WhereClause;
Delete << St;
Delete.execute();
Session.commit();
return true;
} catch (const Poco::Exception &E) {
Logger_.log(E);

View File

@@ -316,5 +316,90 @@ namespace OpenWifi::Utils {
uint32_t Port;
};
class CompressedString {
public:
CompressedString() {
DecompressedSize_ = 0;
};
explicit CompressedString(const std::string &Data) : DecompressedSize_(Data.size()) {
CompressIt(Data);
}
CompressedString(const CompressedString &Data) {
this->DecompressedSize_ = Data.DecompressedSize_;
this->CompressedData_ = Data.CompressedData_;
}
CompressedString& operator=(const CompressedString& rhs) {
if (this != &rhs) {
this->DecompressedSize_ = rhs.DecompressedSize_;
this->CompressedData_ = rhs.CompressedData_;
}
return *this;
}
CompressedString& operator=(CompressedString&& rhs) {
if (this != &rhs) {
this->DecompressedSize_ = rhs.DecompressedSize_;
this->CompressedData_ = rhs.CompressedData_;
}
return *this;
}
~CompressedString() = default;
operator std::string() const {
return DecompressIt();
}
CompressedString &operator=(const std::string &Data) {
DecompressedSize_ = Data.size();
CompressIt(Data);
return *this;
}
auto CompressedSize() const { return CompressedData_.size(); }
auto DecompressedSize() const { return DecompressedSize_; }
private:
std::string CompressedData_;
std::size_t DecompressedSize_;
inline void CompressIt(const std::string &Data) {
z_stream strm; // = {0};
CompressedData_.resize(Data.size());
strm.next_in = (Bytef *)Data.data();
strm.avail_in = Data.size();
strm.next_out = (Bytef *)CompressedData_.data();
strm.avail_out = Data.size();
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 + 16, 8, Z_DEFAULT_STRATEGY);
deflate(&strm, Z_FINISH);
deflateEnd(&strm);
CompressedData_.resize(strm.total_out);
}
[[nodiscard]] std::string DecompressIt() const {
std::string Result;
if(DecompressedSize_!=0) {
Result.resize(DecompressedSize_);
z_stream strm ; //= {0};
strm.next_in = (Bytef *)CompressedData_.data();
strm.avail_in = CompressedData_.size();
strm.next_out = (Bytef *)Result.data();
strm.avail_out = Result.size();
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
inflateInit2(&strm, 15 + 32);
inflate(&strm, Z_FINISH);
inflateEnd(&strm);
}
return Result;
}
};
} // namespace OpenWifi::Utils

View File

@@ -36,15 +36,18 @@ namespace OpenWifi::SDK::FMS {
static const std::string EndPoint{"/api/v1/firmwares"};
OpenWifi::OpenAPIRequestGet API(uSERVICE_FIRMWARE, EndPoint,
{{"deviceType", device_type}}, 50000);
{{"deviceType", device_type},
{"offset","0"},
{"limit","1000"}}, 50000);
auto CallResponse = Poco::makeShared<Poco::JSON::Object>();
auto StatusCode = API.Do(CallResponse);
if (StatusCode == Poco::Net::HTTPResponse::HTTP_OK) {
Poco::JSON::Array::Ptr FirmwareArr = CallResponse->getArray("firmwares");
for (uint64_t i = 0; i < FirmwareArr->size(); i++) {
for(const auto &firmware:*FirmwareArr) {
auto Object = firmware.extract<Poco::JSON::Object::Ptr>();
FMSObjects::Firmware F;
F.from_json(FirmwareArr->getObject(i));
F.from_json(Object);
FirmWares.emplace_back(F);
}
return true;

View File

@@ -79,7 +79,7 @@ namespace OpenWifi::SDK::GW {
}
bool Upgrade(RESTAPIHandler *client, const std::string &SerialNumber, uint64_t When,
const std::string &ImageName) {
const std::string &ImageName, std::string &status) {
Poco::JSON::Object Body;
Body.set(RESTAPI::Protocol::SERIALNUMBER, SerialNumber);
@@ -92,6 +92,7 @@ namespace OpenWifi::SDK::GW {
auto ResponseStatus =
API.Do(CallResponse, client ? client->UserInfo_.webtoken.access_token_ : "");
if (ResponseStatus == Poco::Net::HTTPResponse::HTTP_OK) {
status = CallResponse->get("status").toString();
return true;
}
return false;

View File

@@ -23,7 +23,7 @@ namespace OpenWifi::SDK::GW {
bool Configure(RESTAPIHandler *client, const std::string &Mac,
Poco::JSON::Object::Ptr &Configuration, Poco::JSON::Object::Ptr &Response);
bool Upgrade(RESTAPIHandler *client, const std::string &Mac, uint64_t When,
const std::string &ImageName);
const std::string &ImageName, std::string &status);
bool SetVenue(RESTAPIHandler *client, const std::string &SerialNumber,
const std::string &uuid);

View File

@@ -232,6 +232,69 @@ namespace OpenWifi {
}
return true;
}
bool InventoryDB::GetDevicesForVenue(const std::string &venue_uuid, std::vector<std::string> &devices) {
try {
std::vector<ProvObjects::InventoryTag> device_list;
if(GetRecords(0, 1000, device_list, fmt::format(" venue='{}' ", venue_uuid))) {
for(auto &i:device_list) {
devices.push_back(i.serialNumber);
}
return true;
}
} catch(const Poco::Exception &E) {
Logger().log(E);
return false;
} catch(const std::exception &E) {
Logger().error(fmt::format("std::exception: {}",E.what()));
return false;
} catch(...) {
Logger().error("Unknown exception");
return false;
}
return false;
}
bool InventoryDB::GetDevicesUUIDForVenue(const std::string &venue_uuid, std::vector<std::string> &devices) {
try {
std::vector<ProvObjects::InventoryTag> device_list;
if(GetRecords(0, 1000, device_list, fmt::format(" venue='{}' ", venue_uuid))) {
for(auto &i:device_list) {
devices.push_back(i.info.id);
}
return true;
}
} catch(const Poco::Exception &E) {
Logger().log(E);
return false;
} catch(const std::exception &E) {
Logger().error(fmt::format("std::exception: {}",E.what()));
return false;
} catch(...) {
Logger().error("Unknown exception");
return false;
}
return false;
}
bool InventoryDB::GetDevicesForVenue(const std::string &venue_uuid, std::vector<ProvObjects::InventoryTag> &devices) {
try {
return GetRecords(0, 1000, devices, fmt::format(" venue='{}' ", venue_uuid));
} catch(const Poco::Exception &E) {
Logger().log(E);
return false;
} catch(const std::exception &E) {
Logger().error(fmt::format("std::exception: {}",E.what()));
return false;
} catch(...) {
Logger().error("Unknown exception");
return false;
}
return false;
}
} // namespace OpenWifi
template <>

View File

@@ -38,6 +38,10 @@ namespace OpenWifi {
bool Upgrade(uint32_t from, uint32_t &to) override;
bool GetDevicesForVenue(const std::string &uuid, std::vector<std::string> &devices);
bool GetDevicesUUIDForVenue(const std::string &uuid, std::vector<std::string> &devices);
bool GetDevicesForVenue(const std::string &uuid, std::vector<ProvObjects::InventoryTag> &devices);
private:
bool EvaluateDeviceRules(const ProvObjects::InventoryTag &T,
ProvObjects::DeviceRules &Rules);