mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-10-30 10:12:29 +00:00
Adding link between prov<->gw
This commit is contained in:
@@ -90,7 +90,7 @@ add_executable(owprov
|
|||||||
src/storage_setup.cpp
|
src/storage_setup.cpp
|
||||||
src/storage_configurations.cpp src/storage_configurations.h
|
src/storage_configurations.cpp src/storage_configurations.h
|
||||||
src/RESTAPI_configurations_handler.cpp src/RESTAPI_configurations_handler.h
|
src/RESTAPI_configurations_handler.cpp src/RESTAPI_configurations_handler.h
|
||||||
src/RESTAPI_webSocketServer.h src/RESTAPI_webSocketServer.cpp src/RESTAPI_contact_list_handler.cpp src/RESTAPI_contact_list_handler.h src/RESTAPI_location_list_handler.cpp src/RESTAPI_location_list_handler.h src/RESTAPI_venue_list_handler.cpp src/RESTAPI_venue_list_handler.h src/RESTAPI_managementPolicy_list_handler.cpp src/RESTAPI_managementPolicy_list_handler.h src/RESTAPI_managementRole_handler.cpp src/RESTAPI_managementRole_handler.h src/RESTAPI_managementRole_list_handler.cpp src/RESTAPI_managementRole_list_handler.h src/RESTAPI_configurations_list_handler.cpp src/RESTAPI_configurations_list_handler.h src/SecurityDBProxy.cpp src/SecurityDBProxy.h src/APConfig.cpp src/APConfig.h src/RESTAPI_errors.h src/ConfigurationValidator.cpp src/ConfigurationValidator.h src/RESTAPI_GenericServer.cpp src/RESTAPI_GenericServer.h src/AutoDiscovery.cpp src/AutoDiscovery.h src/CIDRUtils.cpp src/CIDRUtils.h)
|
src/RESTAPI_webSocketServer.h src/RESTAPI_webSocketServer.cpp src/RESTAPI_contact_list_handler.cpp src/RESTAPI_contact_list_handler.h src/RESTAPI_location_list_handler.cpp src/RESTAPI_location_list_handler.h src/RESTAPI_venue_list_handler.cpp src/RESTAPI_venue_list_handler.h src/RESTAPI_managementPolicy_list_handler.cpp src/RESTAPI_managementPolicy_list_handler.h src/RESTAPI_managementRole_handler.cpp src/RESTAPI_managementRole_handler.h src/RESTAPI_managementRole_list_handler.cpp src/RESTAPI_managementRole_list_handler.h src/RESTAPI_configurations_list_handler.cpp src/RESTAPI_configurations_list_handler.h src/SecurityDBProxy.cpp src/SecurityDBProxy.h src/APConfig.cpp src/APConfig.h src/RESTAPI_errors.h src/ConfigurationValidator.cpp src/ConfigurationValidator.h src/RESTAPI_GenericServer.cpp src/RESTAPI_GenericServer.h src/AutoDiscovery.cpp src/AutoDiscovery.h src/CIDRUtils.cpp src/CIDRUtils.h src/SDK_stubs.cpp src/SDK_stubs.h)
|
||||||
|
|
||||||
target_link_libraries(owprov PUBLIC
|
target_link_libraries(owprov PUBLIC
|
||||||
${Poco_LIBRARIES} ${MySQL_LIBRARIES}
|
${Poco_LIBRARIES} ${MySQL_LIBRARIES}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ namespace OpenWifi {
|
|||||||
}
|
}
|
||||||
if(!SerialNumber.empty()) {
|
if(!SerialNumber.empty()) {
|
||||||
// std::cout << "SerialNUmber: " << SerialNumber << " CID: " << ConnectedIP << " DeviceType: " << DeviceType << std::endl;
|
// std::cout << "SerialNUmber: " << SerialNumber << " CID: " << ConnectedIP << " DeviceType: " << DeviceType << std::endl;
|
||||||
Storage()->InventoryDB().CreateFromInventory(SerialNumber,ConnectedIP,DeviceType);
|
Storage()->InventoryDB().CreateFromConnection(SerialNumber,ConnectedIP,DeviceType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (const Poco::Exception &E) {
|
} catch (const Poco::Exception &E) {
|
||||||
|
|||||||
@@ -69,4 +69,60 @@ namespace OpenWifi {
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OpenAPIRequestPut::OpenAPIRequestPut( std::string ServiceType,
|
||||||
|
std::string EndPoint,
|
||||||
|
Types::StringPairVec & QueryData,
|
||||||
|
Poco::JSON::Object Body,
|
||||||
|
uint64_t msTimeout) :
|
||||||
|
Type_(std::move(ServiceType)),
|
||||||
|
EndPoint_(std::move(EndPoint)),
|
||||||
|
QueryData_(QueryData),
|
||||||
|
msTimeout_(msTimeout),
|
||||||
|
Body_(std::move(Body)){}
|
||||||
|
|
||||||
|
int OpenAPIRequestPut::Do(Poco::JSON::Object::Ptr &ResponseObject) {
|
||||||
|
try {
|
||||||
|
auto Services = Daemon()->GetServices(Type_);
|
||||||
|
for(auto const &Svc:Services) {
|
||||||
|
Poco::URI URI(Svc.PrivateEndPoint);
|
||||||
|
Poco::Net::HTTPSClientSession Session(URI.getHost(), URI.getPort());
|
||||||
|
|
||||||
|
URI.setPath(EndPoint_);
|
||||||
|
for (const auto &qp : QueryData_)
|
||||||
|
URI.addQueryParameter(qp.first, qp.second);
|
||||||
|
|
||||||
|
std::string Path(URI.getPathAndQuery());
|
||||||
|
Session.setTimeout(Poco::Timespan(msTimeout_/1000, msTimeout_ % 1000));
|
||||||
|
|
||||||
|
Poco::Net::HTTPRequest Request(Poco::Net::HTTPRequest::HTTP_POST,
|
||||||
|
Path,
|
||||||
|
Poco::Net::HTTPMessage::HTTP_1_1);
|
||||||
|
std::ostringstream obody;
|
||||||
|
Poco::JSON::Stringifier::stringify(Body_,obody);
|
||||||
|
|
||||||
|
Request.setContentType("application/json");
|
||||||
|
Request.setContentLength(obody.str().size());
|
||||||
|
|
||||||
|
Request.add("X-API-KEY", Svc.AccessKey);
|
||||||
|
Request.add("X-INTERNAL-NAME", Daemon()->PublicEndPoint());
|
||||||
|
|
||||||
|
std::ostream & os = Session.sendRequest(Request);
|
||||||
|
os << obody.str();
|
||||||
|
|
||||||
|
Poco::Net::HTTPResponse Response;
|
||||||
|
std::istream &is = Session.receiveResponse(Response);
|
||||||
|
if(Response.getStatus()==Poco::Net::HTTPResponse::HTTP_OK) {
|
||||||
|
Poco::JSON::Parser P;
|
||||||
|
ResponseObject = P.parse(is).extract<Poco::JSON::Object::Ptr>();
|
||||||
|
}
|
||||||
|
return Response.getStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const Poco::Exception &E)
|
||||||
|
{
|
||||||
|
std::cerr << E.displayText() << std::endl;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,22 @@ namespace OpenWifi {
|
|||||||
Types::StringPairVec QueryData_;
|
Types::StringPairVec QueryData_;
|
||||||
uint64_t msTimeout_;
|
uint64_t msTimeout_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class OpenAPIRequestPut {
|
||||||
|
public:
|
||||||
|
explicit OpenAPIRequestPut( std::string Type,
|
||||||
|
std::string EndPoint,
|
||||||
|
Types::StringPairVec & QueryData,
|
||||||
|
Poco::JSON::Object Body,
|
||||||
|
uint64_t msTimeout);
|
||||||
|
int Do(Poco::JSON::Object::Ptr &ResponseObject);
|
||||||
|
private:
|
||||||
|
std::string Type_;
|
||||||
|
std::string EndPoint_;
|
||||||
|
Types::StringPairVec QueryData_;
|
||||||
|
uint64_t msTimeout_;
|
||||||
|
Poco::JSON::Object Body_;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // UCENTRALGW_OPENAPIREQUEST_H
|
#endif // UCENTRALGW_OPENAPIREQUEST_H
|
||||||
|
|||||||
28
src/SDK_stubs.cpp
Normal file
28
src/SDK_stubs.cpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// Created by stephane bourque on 2021-09-29.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "SDK_stubs.h"
|
||||||
|
#include "Daemon.h"
|
||||||
|
#include "Poco/Net/HTTPResponse.h"
|
||||||
|
|
||||||
|
namespace OpenWifi::SDK {
|
||||||
|
|
||||||
|
bool DeviceSetVenue(const std::string & SerialNumber, const std::string &uuid, Poco::JSON::Object::Ptr & Response) {
|
||||||
|
Types::StringPairVec QueryData;
|
||||||
|
Poco::JSON::Object Body;
|
||||||
|
|
||||||
|
Body.set("serialNumber", SerialNumber);
|
||||||
|
Body.set("venue", uuid);
|
||||||
|
OpenWifi::OpenAPIRequestPut R(OpenWifi::uSERVICE_GATEWAY,
|
||||||
|
"/api/v1/device/" +SerialNumber,
|
||||||
|
QueryData,
|
||||||
|
Body,
|
||||||
|
10000);
|
||||||
|
if(R.Do(Response) == Poco::Net::HTTPResponse::HTTP_OK) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
18
src/SDK_stubs.h
Normal file
18
src/SDK_stubs.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
//
|
||||||
|
// Created by stephane bourque on 2021-09-29.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef OWPROV_SDK_STUBS_H
|
||||||
|
#define OWPROV_SDK_STUBS_H
|
||||||
|
|
||||||
|
#include "OpenAPIRequest.h"
|
||||||
|
|
||||||
|
namespace OpenWifi::SDK {
|
||||||
|
|
||||||
|
bool DeviceSetVenue(const std::string & SerialNumber, const std::string &uuid, Poco::JSON::Object::Ptr & Response);
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //OWPROV_SDK_STUBS_H
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
#include "RESTAPI_SecurityObjects.h"
|
#include "RESTAPI_SecurityObjects.h"
|
||||||
#include "Daemon.h"
|
#include "Daemon.h"
|
||||||
#include "StorageService.h"
|
#include "StorageService.h"
|
||||||
|
#include "SDK_stubs.h"
|
||||||
|
|
||||||
namespace OpenWifi {
|
namespace OpenWifi {
|
||||||
|
|
||||||
@@ -54,7 +55,7 @@ namespace OpenWifi {
|
|||||||
InventoryDB::InventoryDB( ORM::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L) :
|
InventoryDB::InventoryDB( ORM::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L) :
|
||||||
DB(T, "inventory", InventoryDB_Fields, InventoryDB_Indexes, P, L, "inv") {}
|
DB(T, "inventory", InventoryDB_Fields, InventoryDB_Indexes, P, L, "inv") {}
|
||||||
|
|
||||||
bool InventoryDB::CreateFromInventory(const std::string &SerialNumber, const std::string &ConnectionInfo,
|
bool InventoryDB::CreateFromConnection(const std::string &SerialNumber, const std::string &ConnectionInfo,
|
||||||
const std::string &DeviceType) {
|
const std::string &DeviceType) {
|
||||||
std::string SNum{SerialNumber};
|
std::string SNum{SerialNumber};
|
||||||
if(!Exists("serialNumber",SNum)) {
|
if(!Exists("serialNumber",SNum)) {
|
||||||
@@ -81,10 +82,23 @@ namespace OpenWifi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(CreateRecord(NewDevice)) {
|
if(CreateRecord(NewDevice)) {
|
||||||
if(!NewDevice.entity.empty())
|
std::string FullUUID;
|
||||||
|
if(!NewDevice.entity.empty()) {
|
||||||
Storage()->EntityDB().AddDevice("id",NewDevice.entity,NewDevice.info.id);
|
Storage()->EntityDB().AddDevice("id",NewDevice.entity,NewDevice.info.id);
|
||||||
else if(!NewDevice.venue.empty())
|
FullUUID = Storage()->EntityDB().Prefix() + ":" + NewDevice.entity;
|
||||||
|
}
|
||||||
|
else if(!NewDevice.venue.empty()) {
|
||||||
Storage()->VenueDB().AddDevice("id",NewDevice.venue,NewDevice.info.id);
|
Storage()->VenueDB().AddDevice("id",NewDevice.venue,NewDevice.info.id);
|
||||||
|
FullUUID = Storage()->VenueDB().Prefix() + ":" + NewDevice.venue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!FullUUID.empty()) {
|
||||||
|
Poco::JSON::Object::Ptr Response;
|
||||||
|
if(SDK::DeviceSetVenue(NewDevice.serialNumber,FullUUID,Response)) {
|
||||||
|
Logger().information(Poco::format("%s: GW set entity/venue property.", NewDevice.serialNumber));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Logger().information(Poco::format("Adding %s to inventory.",SerialNumber));
|
Logger().information(Poco::format("Adding %s to inventory.",SerialNumber));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace OpenWifi {
|
|||||||
class InventoryDB : public ORM::DB<InventoryDBRecordType, ProvObjects::InventoryTag> {
|
class InventoryDB : public ORM::DB<InventoryDBRecordType, ProvObjects::InventoryTag> {
|
||||||
public:
|
public:
|
||||||
InventoryDB( ORM::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L);
|
InventoryDB( ORM::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L);
|
||||||
bool CreateFromInventory(const std::string & SerialNumber, const std::string & ConnectionInfo, const std::string & DeviceType);
|
bool CreateFromConnection(const std::string & SerialNumber, const std::string & ConnectionInfo, const std::string & DeviceType);
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user