Skip to content

Commit

Permalink
Merge pull request #92 from Telecominfraproject/main
Browse files Browse the repository at this point in the history
  • Loading branch information
stephb9959 authored Dec 15, 2023
2 parents e930cc5 + b7b5819 commit c34c10b
Show file tree
Hide file tree
Showing 19 changed files with 302 additions and 82 deletions.
2 changes: 1 addition & 1 deletion build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2
10
24 changes: 10 additions & 14 deletions src/RESTAPI/RESTAPI_venue_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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
Expand Down Expand Up @@ -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));
Expand All @@ -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};
;
Expand Down
5 changes: 3 additions & 2 deletions src/Tasks/VenueConfigUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion src/Tasks/VenueRebooter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
34 changes: 23 additions & 11 deletions src/Tasks/VenueUpgrade.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,23 @@ 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;
}

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_));
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/UI_Prov_WebSocketNotifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/UI_Prov_WebSocketNotifications.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/framework/EventBusManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

namespace OpenWifi {

EventBusManager::EventBusManager(Poco::Logger &L) : Logger_(L) {}

void EventBusManager::run() {
Running_ = true;
Utils::SetThreadName("fmwk:EventMgr");
Expand Down
12 changes: 12 additions & 0 deletions src/framework/EventBusManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -24,4 +34,6 @@ namespace OpenWifi {
Poco::Logger &Logger_;
};

inline auto EventBusManager() { return EventBusManager::instance(); }

} // namespace OpenWifi
Loading

0 comments on commit c34c10b

Please sign in to comment.