Reword with microservice arch.

This commit is contained in:
stephb9959
2021-07-13 21:32:56 -07:00
parent 35da7833b8
commit aa7e4b69b1
9 changed files with 95 additions and 171 deletions

View File

@@ -75,7 +75,7 @@ add_executable( ucentralfms
src/RESTAPI_utils.cpp src/RESTAPI_utils.h
src/RESTAPI_FMSObjects.cpp src/RESTAPI_FMSObjects.h
src/storage_firmwares.h src/storage_history.cpp
src/storage_history.h src/storage_deviceTypes.cpp src/storage_deviceTypes.h src/RESTAPI_historyHandler.cpp src/RESTAPI_historyHandler.h src/NewConnectionHandler.cpp src/NewConnectionHandler.h src/LatestFirmwareCache.cpp src/LatestFirmwareCache.h)
src/storage_history.h src/storage_deviceTypes.cpp src/storage_deviceTypes.h src/RESTAPI_historyHandler.cpp src/RESTAPI_historyHandler.h src/NewConnectionHandler.cpp src/NewConnectionHandler.h src/LatestFirmwareCache.cpp src/LatestFirmwareCache.h src/DeviceCache.cpp src/DeviceCache.h)
target_link_libraries(ucentralfms PUBLIC
${Poco_LIBRARIES} ${MySQL_LIBRARIES}

View File

@@ -125,39 +125,6 @@ components:
items:
$ref: '#/components/schemas/FirmwareDetails'
DeviceType:
type: object
properties:
id:
type: string
format: uuid
deviceType:
type: string
manufacturer:
type: string
model:
type: string
policy:
type: string
notes:
type: array
items:
$ref: '#/components/schemas/NoteInfo'
lastUpdate:
type: integer
format: int64
created:
type: integer
format: int64
DeviceTypeList:
type: object
properties:
deviceTypes:
type: array
items:
$ref: '#/components/schemas/DeviceType'
RevisionHistoryEntry:
type: object
properties:
@@ -423,122 +390,6 @@ paths:
404:
$ref: '#/components/responses/NotFound'
/deviceTypes:
get:
tags:
- DeviceTypes
summary: List all the defined device types
operationId: getDeviceTypes
parameters:
- in: query
description: Pagination start (starts at 1. If not specified, 1 is assumed)
name: offset
schema:
type: integer
required: false
- in: query
description: Maximum number of entries to return (if absent, no limit is assumed)
name: limit
schema:
type: integer
required: false
- in: query
description: Filter the results
name: filter
schema:
type: string
required: false
responses:
200:
description: List of known device types.
content:
application/json:
schema:
$ref: '#/components/schemas/DeviceTypeList'
403:
$ref: '#/components/responses/Unauthorized'
404:
$ref: '#/components/responses/NotFound'
/deviceType/{id}:
get:
tags:
- DeviceTypes
summary: Get a specific DeviceType
operationId: getDeviceType
parameters:
- in: path
description: ID of deviceType to retrieve
name: id
schema:
type: string
format: uuid
required: true
responses:
200:
description: Get a single device type.
content:
application/json:
schema:
$ref: '#/components/schemas/DeviceType'
403:
$ref: '#/components/responses/Unauthorized'
404:
$ref: '#/components/responses/NotFound'
delete:
tags:
- DeviceTypes
summary: Delete a specific DeviceType
operationId: deleteDeviceType
parameters:
- in: path
description: ID of deviceType to retrieve
name: id
schema:
type: string
format: uuid
required: true
responses:
200:
$ref: '#/components/responses/Success'
403:
$ref: '#/components/responses/Unauthorized'
404:
$ref: '#/components/responses/NotFound'
put:
tags:
- DeviceTypes
summary: Modify a specific DeviceType
operationId: modifyDeviceType
parameters:
- in: path
description: ID of deviceType to modify
name: id
schema:
type: string
format: uuid
required: true
requestBody:
description: Modifications for the DeviceType
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/DeviceType'
responses:
200:
description: Get a single device type.
content:
application/json:
schema:
$ref: '#/components/schemas/DeviceType'
403:
$ref: '#/components/responses/Unauthorized'
404:
$ref: '#/components/responses/NotFound'
/revisionHistory/{serialNumber}:
get:
tags:

View File

@@ -24,6 +24,7 @@
#include "KafkaManager.h"
#include "NewConnectionHandler.h"
#include "LatestFirmwareCache.h"
#include "DeviceCache.h"
namespace uCentral {
class Daemon *Daemon::instance_ = nullptr;
@@ -37,6 +38,7 @@ namespace uCentral {
vDAEMON_BUS_TIMER,
Types::SubSystemVec{Storage(),
LatestFirmwareCache(),
DeviceCache(),
NewConnectionHandler(),
RESTAPI_server(),
RESTAPI_InternalServer(),

28
src/DeviceCache.cpp Normal file
View File

@@ -0,0 +1,28 @@
//
// Created by stephane bourque on 2021-07-13.
//
#include "DeviceCache.h"
namespace uCentral {
class DeviceCache *DeviceCache::instance_ = nullptr;
int DeviceCache::Start() {
return 0;
}
void DeviceCache::Stop() {
}
void DeviceCache::AddToCache(
const std::string &serialNumber, const std::string & DeviceType,
const std::string &Host, const std::string &Firmware) {
}
void DeviceCache::DumpCache() {
}
}

52
src/DeviceCache.h Normal file
View File

@@ -0,0 +1,52 @@
//
// Created by stephane bourque on 2021-07-13.
//
#ifndef UCENTRALFMS_DEVICECACHE_H
#define UCENTRALFMS_DEVICECACHE_H
#include <string>
#include "SubSystemServer.h"
#include "uCentralTypes.h"
namespace uCentral {
struct DeviceCacheEntry {
std::string compatible;
std::string host;
std::string firmware;
};
typedef std::map<std::string, DeviceCacheEntry> DeviceCacheMap;
class DeviceCache : public SubSystemServer {
public:
static DeviceCache *instance() {
if (instance_ == nullptr) {
instance_ = new DeviceCache;
}
return instance_;
}
int Start() override;
void Stop() override;
void AddToCache(const std::string &serialNumber, const std::string & DeviceType,
const std::string &Host, const std::string &Firmware);
std::string FindLatestFirmware(std::string &DeviceType);
void DumpCache();
private:
static DeviceCache *instance_;
std::atomic_bool Running_=false;
DeviceCacheMap DeviceCache_;
explicit DeviceCache() noexcept:
SubSystemServer("DeviceCache", "DEVICE-CACHE", "devicecache")
{
}
};
inline DeviceCache * DeviceCache() { return DeviceCache::instance(); }
}
#endif //UCENTRALFMS_DEVICECACHE_H

View File

@@ -23,19 +23,17 @@ namespace uCentral {
Running_ = true;
while(Running_) {
Poco::Thread::trySleep(10000);
Poco::Thread::trySleep(DBRefresh_*1000);
if(!Running_)
break;
std::cout << "About to read bucket..." << std::endl;
Logger_.information("Performing DB refresh");
S3BucketContent BucketList;
ReadBucket(BucketList);
if(!Running_)
break;
std::cout << "Bucket read: " << BucketList.size() << std::endl;
Logger_.information(Poco::format("Found %Lu entries in S# repository for firmware.",(uint64_t)BucketList.size()));
ComputeManifest(BucketList);
AddManifestToDB(BucketList);
// LatestFirmwareCache()->DumpCache();
// Print(BucketList);
}
}
@@ -87,9 +85,8 @@ namespace uCentral {
F.revision = BucketEntry.Revision;
F.deviceType = BucketEntry.Compatible;
if(Storage()->AddFirmware(F)) {
std::cout << "Adding " << Release << std::endl;
Logger_.information(Poco::format("Adding firmware '%'",Release));
} else {
std::cout << "Could not add firmware..." << Release << std::endl;
}
}
}
@@ -103,6 +100,8 @@ namespace uCentral {
S3Key_ = Daemon()->ConfigGetString("s3.key");
S3Retry_ = Daemon()->ConfigGetInt("s3.retry",60);
DBRefresh_ = Daemon()->ConfigGetInt("firmwaredb.refresh",30*60);
AwsConfig_.enableTcpKeepAlive = true;
AwsConfig_.enableEndpointDiscovery = true;
AwsConfig_.useDualStack = true;
@@ -167,13 +166,9 @@ namespace uCentral {
auto Outcome = S3Client.ListObjects(Request);
if(Outcome.IsSuccess()) {
// std::cout << "Success..." << std::endl;
// std::cout << "Objects: ." ;
Aws::Vector<Aws::S3::Model::Object> objects = Outcome.GetResult().GetContents();
for (const auto &Object : objects) {
Poco::Path FileName(Object.GetKey().c_str());
// std::cout << "Object: " << Object.GetKey() << std::endl;
// std::cout << "." << std::flush;
if(!Running_)
return false;
if (FileName.getExtension() == "json") {

View File

@@ -64,6 +64,7 @@ namespace uCentral {
uint64_t S3Retry_;
Aws::Client::ClientConfiguration AwsConfig_{"ARILIA"};
Aws::Auth::AWSCredentials AwsCreds_;
uint64_t DBRefresh_ = 30 * 60;
ManifestCreator() noexcept:
SubSystemServer("ManifestCreator", "MANIFEST-MGR", "manifestcreator") {

View File

@@ -33,7 +33,6 @@ namespace uCentral {
if(!Running_)
break;
std::cout << "New connection..." << std::endl;
Types::StringPair S;
{
SubMutexGuard G(Mutex_);
@@ -41,22 +40,18 @@ namespace uCentral {
NewConnections_.pop();
}
auto SerialNumber = S.first;
std::cout << "Connection data:" << S.second << std::endl;
Poco::JSON::Parser Parser;
auto Object = Parser.parse(S.second).extract<Poco::JSON::Object::Ptr>();
std::string compatible, serialNumber, firmware;
if(Object->has("payload")) {
std::cout << __LINE__ << std::endl;
auto PayloadObj = Object->getObject("payload");
std::cout << __LINE__ << std::endl;
if(PayloadObj->has("capabilities")) {
std::cout << __LINE__ << std::endl;
auto CapObj = PayloadObj->getObject("capabilities");
std::cout << __LINE__ << std::endl;
if(CapObj->has("compatible")) {
std::cout << __LINE__ << std::endl;
compatible = CapObj->get("compatible").toString();
serialNumber = PayloadObj->get("serial").toString();
firmware = PayloadObj->get("firmware").toString();
std::cout << "Compatible: " << CapObj->get("compatible").toString() << std::endl;
}
}
@@ -87,6 +82,5 @@ namespace uCentral {
void NewConnectionHandler::ConnectionReceived( const std::string & Key, const std::string & Message) {
SubMutexGuard G(Mutex_);
NewConnections_.push(std::make_pair(Key,Message));
std::cout << "New connection..." << std::endl;
}
}

View File

@@ -45,6 +45,7 @@ s3.key = **************************
s3.retry = 60
s3.bucket.uri = ucentral-ap-firmware.s3.amazonaws.com
firmwaredb.refresh = 1800
#############################
# Generic information for all micro services
#############################