Fixing framework.

This commit is contained in:
stephb9959
2022-04-03 18:37:32 -07:00
parent 3090e9b9b5
commit b51c2b76e0
7 changed files with 80 additions and 18 deletions

View File

@@ -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/Tasks/VenueConfigUpdater.cpp src/Tasks/VenueConfigUpdater.h)
src/FileDownloader.cpp src/FileDownloader.h src/Tasks/VenueConfigUpdater.cpp src/Tasks/VenueConfigUpdater.h src/Kafka_ProvUpdater.cpp src/Kafka_ProvUpdater.h)
target_link_libraries(owprov PUBLIC
${Poco_LIBRARIES}

2
build
View File

@@ -1 +1 @@
81
84

View File

@@ -0,0 +1,5 @@
//
// Created by stephane bourque on 2022-04-01.
//
#include "Kafka_ProvUpdater.h"

48
src/Kafka_ProvUpdater.h Normal file
View File

@@ -0,0 +1,48 @@
//
// Created by stephane bourque on 2022-04-01.
//
#pragma once
#include "framework/MicroService.h"
#include "RESTObjects/RESTAPI_ProvObjects.h"
namespace OpenWifi {
enum ProvisioningOperation {
creation=0, modification, removal
};
template <typename ObjectType> inline bool UpdateKafkaProvisioningObject( ProvisioningOperation op, const ObjectType & obj) {
static std::vector<std::string> Ops{ "creation", "modification", "removal" };
std::string OT{"object"};
if constexpr(std::is_same_v<ObjectType,ProvObjects::Venue>) {
OT = "Venue";
}
if constexpr(std::is_same_v<ObjectType,ProvObjects::Entity>) {
OT = "Entity";
}
if constexpr(std::is_same_v<ObjectType,ProvObjects::InventoryTag>) {
OT = "InventoryTag";
}
if constexpr(std::is_same_v<ObjectType,ProvObjects::Contact>) {
OT = "Contact";
}
if constexpr(std::is_same_v<ObjectType,ProvObjects::Location>) {
OT = "Location";
}
if constexpr(std::is_same_v<ObjectType,ProvObjects::DeviceConfiguration>) {
OT = "DeviceConfiguration";
}
Poco::JSON::Object Payload;
obj.to_json(Payload);
Payload.set("ObjectType",OT);
std::ostringstream OS;
Payload.stringify(OS);
KafkaManager()->PostMessage(KafkaTopics::PROVISIONING_CHANGE, Ops[op] , OS.str());
return true;
}
}

View File

@@ -14,6 +14,8 @@
#include "RESTAPI/RESTAPI_db_helpers.h"
#include "Tasks/VenueConfigUpdater.h"
#include "Kafka_ProvUpdater.h"
namespace OpenWifi{
static Types::UUIDvec_t GetDevices(const ProvObjects::Venue &V, bool GetChildren) {
@@ -101,6 +103,9 @@ namespace OpenWifi{
if(!Existing.entity.empty())
StorageService()->EntityDB().DeleteVenue("id",Existing.entity,UUID);
DB_.DeleteRecord("id",UUID);
UpdateKafkaProvisioningObject(ProvisioningOperation::removal,Existing);
return OK();
}
@@ -219,9 +224,10 @@ namespace OpenWifi{
SNL.serialNumbers = Existing.devices;
auto Task = new VenueConfigUpdater(UUID,UserInfo_.userinfo,0,Logger());
Task->Start();
auto JobId = Task->Start();
SNL.to_json(Answer);
Answer.set("jobId",JobId);
return ReturnObject(Answer);
}
@@ -328,6 +334,7 @@ namespace OpenWifi{
}
if(StorageService()->VenueDB().UpdateRecord("id", UUID, Existing)) {
UpdateKafkaProvisioningObject(ProvisioningOperation::modification,Existing);
MoveUsage(StorageService()->ContactDB(),DB_,MoveFromContacts, MoveToContacts, Existing.info.id);
MoveUsage(StorageService()->LocationDB(),DB_,MoveFromLocation, MoveToLocation, Existing.info.id);
MoveUsage(StorageService()->PolicyDB(),DB_,MoveFromPolicy,MoveToPolicy,Existing.info.id);

View File

@@ -18,6 +18,7 @@ namespace OpenWifi::KafkaTopics {
static const std::string SERVICE_EVENTS{"service_events"};
static const std::string DEVICE_EVENT_QUEUE{"device_event_queue"};
static const std::string DEVICE_TELEMETRY{"device_telemetry"};
static const std::string PROVISIONING_CHANGE{"provisioning_change"};
namespace ServiceEvents {
static const std::string EVENT_JOIN{"join"};

View File

@@ -3056,7 +3056,7 @@ namespace OpenWifi {
};
class SubSystemServer;
typedef std::map<uint64_t, MicroServiceMeta> MicroServiceMetaMap;
typedef std::map<std::string, MicroServiceMeta> MicroServiceMetaMap;
typedef std::vector<MicroServiceMeta> MicroServiceMetaVec;
typedef std::vector<SubSystemServer *> SubSystemVec;
@@ -3227,26 +3227,27 @@ namespace OpenWifi {
std::cout << "BUS MESSAGE:" << OOO.str() << std::endl;
*/
if (Object->has(KafkaTopics::ServiceEvents::Fields::ID) &&
Object->has(KafkaTopics::ServiceEvents::Fields::EVENT)) {
Object->has(KafkaTopics::ServiceEvents::Fields::EVENT)) {
uint64_t ID = Object->get(KafkaTopics::ServiceEvents::Fields::ID);
auto Event = Object->get(KafkaTopics::ServiceEvents::Fields::EVENT).toString();
if (ID != ID_) {
if( Event==KafkaTopics::ServiceEvents::EVENT_JOIN ||
Event==KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE ||
Event==KafkaTopics::ServiceEvents::EVENT_LEAVE ) {
Event==KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE ||
Event==KafkaTopics::ServiceEvents::EVENT_LEAVE ) {
if( Object->has(KafkaTopics::ServiceEvents::Fields::TYPE) &&
Object->has(KafkaTopics::ServiceEvents::Fields::PUBLIC) &&
Object->has(KafkaTopics::ServiceEvents::Fields::PRIVATE) &&
Object->has(KafkaTopics::ServiceEvents::Fields::VRSN) &&
Object->has(KafkaTopics::ServiceEvents::Fields::KEY)) {
if (Event == KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE && Services_.find(ID) != Services_.end()) {
Services_[ID].LastUpdate = std::time(nullptr);
Object->has(KafkaTopics::ServiceEvents::Fields::PUBLIC) &&
Object->has(KafkaTopics::ServiceEvents::Fields::PRIVATE) &&
Object->has(KafkaTopics::ServiceEvents::Fields::VRSN) &&
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 = std::time(nullptr);
} else if (Event == KafkaTopics::ServiceEvents::EVENT_LEAVE) {
Services_.erase(ID);
Services_.erase(PrivateEndPoint);
logger().information(fmt::format("Service {} ID={} leaving system.",Object->get(KafkaTopics::ServiceEvents::Fields::PRIVATE).toString(),ID));
} else if (Event == KafkaTopics::ServiceEvents::EVENT_JOIN || Event == KafkaTopics::ServiceEvents::EVENT_KEEP_ALIVE) {
logger().information(fmt::format("Service {} ID={} joining system.",Object->get(KafkaTopics::ServiceEvents::Fields::PRIVATE).toString(),ID));
Services_[ID] = MicroServiceMeta{
Services_[PrivateEndPoint] = MicroServiceMeta{
.Id = ID,
.Type = Poco::toLower(Object->get(KafkaTopics::ServiceEvents::Fields::TYPE).toString()),
.PrivateEndPoint = Object->get(KafkaTopics::ServiceEvents::Fields::PRIVATE).toString(),
@@ -3254,8 +3255,8 @@ namespace OpenWifi {
.AccessKey = Object->get(KafkaTopics::ServiceEvents::Fields::KEY).toString(),
.Version = Object->get(KafkaTopics::ServiceEvents::Fields::VRSN).toString(),
.LastUpdate = (uint64_t)std::time(nullptr)};
for (const auto &[Id, Svc] : Services_) {
logger().information(fmt::format("ID: {} Type: {} EndPoint: {}",Id,Svc.Type,Svc.PrivateEndPoint));
for (const auto &[PrivateEndPoint, Svc] : Services_) {
logger().information(fmt::format("ID: {} Type: {} EndPoint: {}",Svc.Id,Svc.Type,PrivateEndPoint));
}
}
} else {
@@ -3307,7 +3308,7 @@ namespace OpenWifi {
std::lock_guard G(InfraMutex_);
MicroServiceMetaVec Res;
for(const auto &[Id,ServiceRec]:Services_) {
for(const auto &[_,ServiceRec]:Services_) {
Res.push_back(ServiceRec);
}
return Res;