diff --git a/build b/build index 7813681..301160a 100644 --- a/build +++ b/build @@ -1 +1 @@ -5 \ No newline at end of file +8 \ No newline at end of file diff --git a/src/RESTAPI/RESTAPI_venue_handler.cpp b/src/RESTAPI/RESTAPI_venue_handler.cpp index af4abea..9c8eab2 100644 --- a/src/RESTAPI/RESTAPI_venue_handler.cpp +++ b/src/RESTAPI/RESTAPI_venue_handler.cpp @@ -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(NewJob)); @@ -302,11 +300,10 @@ namespace OpenWifi { if (GetBoolParameter("upgradeAllDevices")) { if (GetBoolParameter("revisionsAvailable")) { std::set DeviceTypes; - for (const auto &serialNumber : Existing.devices) { - ProvObjects::InventoryTag Device; - if (StorageService()->InventoryDB().GetRecord("id", serialNumber, Device)) { - DeviceTypes.insert(Device.deviceType); - } + std::vector 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(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}; ; diff --git a/src/storage/storage_inventory.cpp b/src/storage/storage_inventory.cpp index 7f6ef56..27fa8fd 100644 --- a/src/storage/storage_inventory.cpp +++ b/src/storage/storage_inventory.cpp @@ -232,6 +232,47 @@ namespace OpenWifi { } return true; } + + bool InventoryDB::GetDevicesForVenue(const std::string &venue_uuid, std::vector &devices) { + try { + std::vector device_list; + if(GetRecords(1, 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::GetDevicesForVenue(const std::string &venue_uuid, std::vector &devices) { + try { + return GetRecords(1, 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 <> diff --git a/src/storage/storage_inventory.h b/src/storage/storage_inventory.h index c1a1358..b96e271 100644 --- a/src/storage/storage_inventory.h +++ b/src/storage/storage_inventory.h @@ -38,6 +38,9 @@ namespace OpenWifi { bool Upgrade(uint32_t from, uint32_t &to) override; + bool GetDevicesForVenue(const std::string &uuid, std::vector &devices); + bool GetDevicesForVenue(const std::string &uuid, std::vector &devices); + private: bool EvaluateDeviceRules(const ProvObjects::InventoryTag &T, ProvObjects::DeviceRules &Rules);