mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralfms.git
synced 2026-01-27 02:23:02 +00:00
Initial
This commit is contained in:
@@ -1 +1,2 @@
|
||||
95551b278368a27de446365d12b5b51da791947cf39b15d9bd1111de6aa053d9:ALL:CI-John:CI Key for John's CI
|
||||
59507518c956ac654dbb9a0c5fdbebe32d10c3f0aa68ae0e9000af89e03d4ad9:CALLBACK:tester1:Test home system
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
0T1jZ0zO9fkvWI8pk722ZAeSKmqey1jiDXNafRlpdiy4lletCCaVAgWdSH5LD5f8:John'CI
|
||||
t2dEOc88OIxVDb94mw7SLcLocgnCzZzzFoQ4JJv3OCU9UO6Ou5ds5Dh4CfBnHgrk
|
||||
t2dEOc88OIxVDb94mw7SLcLocgnCzZzzFoQ4JJv3OCU9UO6Ou5ds5Dh4CfBnHgrk:Tester1
|
||||
QC9xI7UjhM9WCZfG5CDbI07xiWRMnrHRphH6UNliz1d3i6XTeTMM5yLmVtpwwXuY
|
||||
g1wszktv1hMV6HRQqb62TAmfvY0WU0hm8INntr3pUf60xagj3OekIWQfeqJnvIwW
|
||||
67rae5YeRJsbuOIJIKHl6zHtksuQBv4GDvnCjHO8QedQpBRWLeD2igJpYB9Pr3CN
|
||||
|
||||
@@ -93,6 +93,8 @@ components:
|
||||
type: string
|
||||
s3uri:
|
||||
type: string
|
||||
latest:
|
||||
type: boolean
|
||||
|
||||
FirmwareDetailsList:
|
||||
type: object
|
||||
|
||||
@@ -30,7 +30,8 @@ namespace uCentral::Objects {
|
||||
Obj.set("size", Size);
|
||||
Obj.set("digest", Digest);
|
||||
Obj.set("s3uri", S3URI);
|
||||
Obj.set("deviceType", DeviceType);
|
||||
Obj.set("Compatible", Compatible);
|
||||
Obj.set("latest", (bool) (Latest ? true : false) );
|
||||
EmbedDocument("firmwareLatestDoc",Obj,FirmwareLatestDoc);
|
||||
}
|
||||
|
||||
@@ -64,7 +65,7 @@ namespace uCentral::Objects {
|
||||
}
|
||||
|
||||
void LatestFirmware::to_json(Poco::JSON::Object &Obj) const {
|
||||
Obj.set("deviceType", DeviceType);
|
||||
Obj.set("Compatible", Compatible);
|
||||
Obj.set("uuid", UUID);
|
||||
Obj.set("lastUpdated", RESTAPIHandler::to_RFC3339(LastUpdated));
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace uCentral::Objects {
|
||||
std::string Description;
|
||||
std::string Owner;
|
||||
std::string Location;
|
||||
std::string DeviceType;
|
||||
std::string Compatible;
|
||||
std::string Uploader;
|
||||
std::string Digest;
|
||||
std::string FirmwareFileName;
|
||||
@@ -48,6 +48,7 @@ namespace uCentral::Objects {
|
||||
uint64_t Uploaded;
|
||||
uint64_t DownloadCount;
|
||||
uint64_t Size;
|
||||
uint64_t Latest;
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
};
|
||||
|
||||
@@ -66,7 +67,7 @@ namespace uCentral::Objects {
|
||||
};
|
||||
|
||||
struct LatestFirmware {
|
||||
std::string DeviceType;
|
||||
std::string Compatible;
|
||||
std::string UUID;
|
||||
uint64_t LastUpdated;
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace uCentral::Storage {
|
||||
std::string FirmwareLatestDoc;
|
||||
std::string Owner;
|
||||
std::string Location;
|
||||
std::string DeviceType;
|
||||
std::string Compatible;
|
||||
std::string Uploader;
|
||||
std::string Digest;
|
||||
std::string S3URI;
|
||||
@@ -53,6 +53,7 @@ namespace uCentral::Storage {
|
||||
uint64_t Size;
|
||||
uint64_t Uploaded;
|
||||
uint64_t FirmwareDate;
|
||||
uint64_t Latest;
|
||||
*/
|
||||
|
||||
typedef Poco::Tuple<
|
||||
@@ -71,6 +72,7 @@ namespace uCentral::Storage {
|
||||
uint64_t,
|
||||
uint64_t,
|
||||
uint64_t,
|
||||
uint64_t,
|
||||
uint64_t
|
||||
> FirmwareRecordTuple;
|
||||
typedef std::vector<FirmwareRecordTuple> FirmwareRecordList;
|
||||
@@ -89,7 +91,7 @@ namespace uCentral::Storage {
|
||||
"Description VARCHAR(128), "
|
||||
"Owner VARCHAR(128), "
|
||||
"Location TEXT, ",
|
||||
"DeviceType VARCHAR(128), "
|
||||
"Compatible VARCHAR(128), "
|
||||
"Uploader VARCHAR(128), "
|
||||
"Digest TEXT, "
|
||||
"FirmwareFileName TEXT, "
|
||||
@@ -100,20 +102,32 @@ namespace uCentral::Storage {
|
||||
"FirmwareDate BIGINT, "
|
||||
"Uploaded BIGINT, "
|
||||
"DownloadCount BIGINT, "
|
||||
"Size BIGINT, "
|
||||
"Size BIGINT,
|
||||
"Latest BIGINT"
|
||||
*/
|
||||
|
||||
// find the older software and change to latest = 0
|
||||
if(F.Latest)
|
||||
{
|
||||
Poco::Data::Statement Update(Sess);
|
||||
std::string st{"UPDATE Firmwares SET Latest=0 WHERE Compatible=? AND Latest=1"};
|
||||
Update << ConvertParams(st),
|
||||
Poco::Data::Keywords::use(F.Compatible);
|
||||
Update.execute();
|
||||
}
|
||||
|
||||
std::string st{"INSERT INTO Firmwares ("
|
||||
"UUID, Description, Owner, Location, DeviceType, Uploader, Digest, "
|
||||
"UUID, Description, Owner, Location, Compatible, Uploader, Digest, "
|
||||
"FirmwareFileName, FirmwareVersion, FirmwareHash, FirmwareLatestDoc, "
|
||||
"S3URI, FirmwareDate, Uploaded, DownloadCount, Size "
|
||||
") VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"};
|
||||
"S3URI, FirmwareDate, Uploaded, DownloadCount, Size, Latest "
|
||||
") VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"};
|
||||
|
||||
Insert << ConvertParams(st),
|
||||
Poco::Data::Keywords::use(F.UUID),
|
||||
Poco::Data::Keywords::use(F.Description),
|
||||
Poco::Data::Keywords::use(F.Owner),
|
||||
Poco::Data::Keywords::use(F.Location),
|
||||
Poco::Data::Keywords::use(F.DeviceType),
|
||||
Poco::Data::Keywords::use(F.Compatible),
|
||||
Poco::Data::Keywords::use(F.Uploader),
|
||||
Poco::Data::Keywords::use(F.Digest),
|
||||
Poco::Data::Keywords::use(F.FirmwareFileName),
|
||||
@@ -124,7 +138,8 @@ namespace uCentral::Storage {
|
||||
Poco::Data::Keywords::use(F.FirmwareDate),
|
||||
Poco::Data::Keywords::use(F.Uploaded),
|
||||
Poco::Data::Keywords::use(F.DownloadCount),
|
||||
Poco::Data::Keywords::use(F.Size);
|
||||
Poco::Data::Keywords::use(F.Size),
|
||||
Poco::Data::Keywords::use(F.Latest);
|
||||
Insert.execute();
|
||||
FirmwareVersion_++;
|
||||
return true;
|
||||
@@ -141,16 +156,16 @@ namespace uCentral::Storage {
|
||||
Poco::Data::Statement Update(Sess);
|
||||
|
||||
std::string st{"UPDATE Firmwares "
|
||||
"Description, Owner, Location, DeviceType, Uploader, Digest, "
|
||||
"FirmwareFileName, FirmwareVersion, FirmwareHash, FirmwareLatestDoc, "
|
||||
"S3URI, FirmwareDate, Uploaded, DownloadCount, Size "
|
||||
" Description, Owner, Location, Compatible, Uploader, Digest, "
|
||||
" FirmwareFileName, FirmwareVersion, FirmwareHash, FirmwareLatestDoc, "
|
||||
" S3URI, FirmwareDate, Uploaded, DownloadCount, Size"
|
||||
" WHERE UUID=?"};
|
||||
|
||||
Update << ConvertParams(st),
|
||||
Poco::Data::Keywords::use(F.Description),
|
||||
Poco::Data::Keywords::use(F.Owner),
|
||||
Poco::Data::Keywords::use(F.Location),
|
||||
Poco::Data::Keywords::use(F.DeviceType),
|
||||
Poco::Data::Keywords::use(F.Compatible),
|
||||
Poco::Data::Keywords::use(F.Uploader),
|
||||
Poco::Data::Keywords::use(F.Digest),
|
||||
Poco::Data::Keywords::use(F.FirmwareFileName),
|
||||
@@ -161,7 +176,7 @@ namespace uCentral::Storage {
|
||||
Poco::Data::Keywords::use(F.FirmwareDate),
|
||||
Poco::Data::Keywords::use(F.Uploaded),
|
||||
Poco::Data::Keywords::use(F.DownloadCount),
|
||||
Poco::Data::Keywords::use(F.Size);
|
||||
Poco::Data::Keywords::use(F.Size),
|
||||
Poco::Data::Keywords::use(F.UUID);
|
||||
Update.execute();
|
||||
FirmwareVersion_++;
|
||||
@@ -198,29 +213,30 @@ namespace uCentral::Storage {
|
||||
Poco::Data::Statement Select(Sess);
|
||||
|
||||
std::string st{"SELECT "
|
||||
"UUID, Description, Owner, Location, DeviceType, Uploader, Digest, "
|
||||
"UUID, Description, Owner, Location, Compatible, Uploader, Digest, "
|
||||
"FirmwareFileName, FirmwareVersion, FirmwareHash, FirmwareLatestDoc, "
|
||||
"S3URI, FirmwareDate, Uploaded, DownloadCount, Size "
|
||||
"S3URI, FirmwareDate, Uploaded, DownloadCount, Size, Latest "
|
||||
" FROM Firmwares WHERE UUID=?"};
|
||||
|
||||
Select << ConvertParams(st),
|
||||
Poco::Data::Keywords::into(F.UUID),
|
||||
Poco::Data::Keywords::into(F.Description),
|
||||
Poco::Data::Keywords::into(F.Owner),
|
||||
Poco::Data::Keywords::into(F.Location),
|
||||
Poco::Data::Keywords::into(F.DeviceType),
|
||||
Poco::Data::Keywords::into(F.Uploader),
|
||||
Poco::Data::Keywords::into(F.Digest),
|
||||
Poco::Data::Keywords::into(F.FirmwareFileName),
|
||||
Poco::Data::Keywords::into(F.FirmwareVersion),
|
||||
Poco::Data::Keywords::into(F.FirmwareHash),
|
||||
Poco::Data::Keywords::into(F.FirmwareLatestDoc),
|
||||
Poco::Data::Keywords::into(F.S3URI),
|
||||
Poco::Data::Keywords::into(F.FirmwareDate),
|
||||
Poco::Data::Keywords::into(F.Uploaded),
|
||||
Poco::Data::Keywords::into(F.DownloadCount),
|
||||
Poco::Data::Keywords::into(F.Size);
|
||||
Poco::Data::Keywords::use(UUID);
|
||||
Poco::Data::Keywords::into(F.UUID),
|
||||
Poco::Data::Keywords::into(F.Description),
|
||||
Poco::Data::Keywords::into(F.Owner),
|
||||
Poco::Data::Keywords::into(F.Location),
|
||||
Poco::Data::Keywords::into(F.Compatible),
|
||||
Poco::Data::Keywords::into(F.Uploader),
|
||||
Poco::Data::Keywords::into(F.Digest),
|
||||
Poco::Data::Keywords::into(F.FirmwareFileName),
|
||||
Poco::Data::Keywords::into(F.FirmwareVersion),
|
||||
Poco::Data::Keywords::into(F.FirmwareHash),
|
||||
Poco::Data::Keywords::into(F.FirmwareLatestDoc),
|
||||
Poco::Data::Keywords::into(F.S3URI),
|
||||
Poco::Data::Keywords::into(F.FirmwareDate),
|
||||
Poco::Data::Keywords::into(F.Uploaded),
|
||||
Poco::Data::Keywords::into(F.DownloadCount),
|
||||
Poco::Data::Keywords::into(F.Size),
|
||||
Poco::Data::Keywords::into(F.Latest),
|
||||
Poco::Data::Keywords::use(UUID);
|
||||
Select.execute();
|
||||
|
||||
return !F.UUID.empty();
|
||||
@@ -238,9 +254,9 @@ namespace uCentral::Storage {
|
||||
Poco::Data::Statement Select(Sess);
|
||||
|
||||
std::string st{"SELECT "
|
||||
"UUID, Description, Owner, Location, DeviceType, Uploader, Digest, "
|
||||
"UUID, Description, Owner, Location, Compatible, Uploader, Digest, "
|
||||
"FirmwareFileName, FirmwareVersion, FirmwareHash, FirmwareLatestDoc, "
|
||||
"S3URI, FirmwareDate, Uploaded, DownloadCount, Size "
|
||||
"S3URI, FirmwareDate, Uploaded, DownloadCount, Size, Latest "
|
||||
" FROM Firmwares"};
|
||||
|
||||
Select << ConvertParams(st),
|
||||
@@ -254,7 +270,7 @@ namespace uCentral::Storage {
|
||||
.Description= i.get<1>(),
|
||||
.Owner= i.get<2>(),
|
||||
.Location= i.get<3>(),
|
||||
.DeviceType= i.get<4>(),
|
||||
.Compatible= i.get<4>(),
|
||||
.Uploader= i.get<5>(),
|
||||
.Digest= i.get<6>(),
|
||||
.FirmwareFileName= i.get<7>(),
|
||||
@@ -265,7 +281,8 @@ namespace uCentral::Storage {
|
||||
.FirmwareDate= i.get<12>(),
|
||||
.Uploaded= i.get<13>(),
|
||||
.DownloadCount= i.get<14>(),
|
||||
.Size= i.get<15>()
|
||||
.Size= i.get<15>(),
|
||||
.Latest = (bool) (i.get<16>()!=0)
|
||||
};
|
||||
Firmwares.push_back(F);
|
||||
}
|
||||
@@ -280,7 +297,7 @@ namespace uCentral::Storage {
|
||||
|
||||
|
||||
/*
|
||||
"DeviceType VARCHAR(128), "
|
||||
"Compatible VARCHAR(128), "
|
||||
"Uploader VARCHAR(128), "
|
||||
"FirmwareVersion VARCHAR(128), "
|
||||
"S3URI TEXT )",
|
||||
@@ -296,6 +313,7 @@ namespace uCentral::Storage {
|
||||
std::string,
|
||||
uint64_t,
|
||||
uint64_t,
|
||||
uint64_t,
|
||||
uint64_t
|
||||
> FirmwareManifestTuple;
|
||||
typedef std::vector<FirmwareManifestTuple> FirmwareManifestList;
|
||||
@@ -308,7 +326,7 @@ namespace uCentral::Storage {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
Poco::Data::Statement Select(Sess);
|
||||
|
||||
std::string st{"SELECT DeviceType,Uploader,FirmwareVersion,S3URI,Uploaded,Size,FirmwareDate FROM Firmwares"};
|
||||
std::string st{"SELECT Compatible,Uploader,FirmwareVersion,S3URI,Uploaded,Size,FirmwareDate,Latest FROM Firmwares"};
|
||||
|
||||
Select << ConvertParams(st),
|
||||
Poco::Data::Keywords::into(Records);
|
||||
@@ -318,13 +336,14 @@ namespace uCentral::Storage {
|
||||
for(const auto &i:Records) {
|
||||
Poco::JSON::Object Obj;
|
||||
|
||||
Obj.set("deviceType", i.get<0>());
|
||||
Obj.set("compatible", i.get<0>());
|
||||
Obj.set("uploader",i.get<1>());
|
||||
Obj.set("version",i.get<2>());
|
||||
Obj.set("uri",i.get<3>());
|
||||
Obj.set("uploaded",RESTAPIHandler::to_RFC3339(i.get<4>()));
|
||||
Obj.set("size",i.get<5>());
|
||||
Obj.set("date", RESTAPIHandler::to_RFC3339(i.get<6>()));
|
||||
Obj.set("latest", (bool) (i.get<7>() != 0));
|
||||
|
||||
Elements.add(Obj);
|
||||
}
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
|
||||
namespace uCentral::Storage {
|
||||
|
||||
bool AddLatestFirmware(std::string & DeviceType, std::string &UUID) {
|
||||
return Service::instance()->AddLatestFirmware(DeviceType, UUID);
|
||||
bool AddLatestFirmware(std::string & Compatible, std::string &UUID) {
|
||||
return Service::instance()->AddLatestFirmware(Compatible, UUID);
|
||||
}
|
||||
|
||||
bool GetLatestFirmware(std::string & DeviceType, uCentral::Objects::LatestFirmware &L) {
|
||||
return Service::instance()->GetLatestFirmware(DeviceType, L);
|
||||
bool GetLatestFirmware(std::string & Compatible, uCentral::Objects::LatestFirmware &L) {
|
||||
return Service::instance()->GetLatestFirmware(Compatible, L);
|
||||
}
|
||||
|
||||
bool DeleteLatestFirmware(std::string & DeviceType) {
|
||||
return Service::instance()->DeleteLatestFirmware(DeviceType);
|
||||
bool DeleteLatestFirmware(std::string & Compatible) {
|
||||
return Service::instance()->DeleteLatestFirmware(Compatible);
|
||||
}
|
||||
|
||||
bool GetLatestFirmwareList(uint64_t From, uint64_t HowMany, std::vector<uCentral::Objects::LatestFirmware> & LatestFirmwareList) {
|
||||
@@ -28,36 +28,36 @@ namespace uCentral::Storage {
|
||||
uint64_t> LatestFirmwareRecordTuple;
|
||||
typedef std::vector<LatestFirmwareRecordTuple> LatestFirmwareRecordList;
|
||||
|
||||
bool Service::AddLatestFirmware(std::string & DeviceType, std::string &UUID) {
|
||||
bool Service::AddLatestFirmware(std::string & Compatible, std::string &UUID) {
|
||||
try {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
Poco::Data::Statement Select(Sess);
|
||||
|
||||
std::string TmpUUID;
|
||||
std::string st{"SELECT UUID From LatestFirmwares WHERE DeviceType=?"};
|
||||
std::string st{"SELECT UUID From LatestFirmwares WHERE Compatible=?"};
|
||||
|
||||
Select << ConvertParams(st) ,
|
||||
Poco::Data::Keywords::into(TmpUUID),
|
||||
Poco::Data::Keywords::use(DeviceType);
|
||||
Poco::Data::Keywords::use(Compatible);
|
||||
Select.execute();
|
||||
|
||||
uint64_t LastUpdated = time(nullptr);
|
||||
|
||||
if(TmpUUID.empty()) {
|
||||
Poco::Data::Statement Insert(Sess);
|
||||
std::string st1{"INSERT INTO LatestFirmwares (DeviceType, UUID, LastUpdated) VALUES(?,?,?)"};
|
||||
std::string st1{"INSERT INTO LatestFirmwares (Compatible, UUID, LastUpdated) VALUES(?,?,?)"};
|
||||
Insert << ConvertParams(st1),
|
||||
Poco::Data::Keywords::use(DeviceType),
|
||||
Poco::Data::Keywords::use(Compatible),
|
||||
Poco::Data::Keywords::use(UUID),
|
||||
Poco::Data::Keywords::use(LastUpdated);
|
||||
Insert.execute();
|
||||
} else {
|
||||
Poco::Data::Statement Update(Sess);
|
||||
std::string st1{"UPDATE LatestFirmwares SET UUID=?, LastUpdated=? WHERE DeviceType=?"};
|
||||
std::string st1{"UPDATE LatestFirmwares SET UUID=?, LastUpdated=? WHERE Compatible=?"};
|
||||
Update << ConvertParams(st1),
|
||||
Poco::Data::Keywords::use(UUID),
|
||||
Poco::Data::Keywords::use(LastUpdated),
|
||||
Poco::Data::Keywords::use(DeviceType);
|
||||
Poco::Data::Keywords::use(Compatible);
|
||||
Update.execute();
|
||||
}
|
||||
return true;
|
||||
@@ -67,19 +67,19 @@ namespace uCentral::Storage {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Service::GetLatestFirmware(std::string & DeviceType, uCentral::Objects::LatestFirmware &L) {
|
||||
bool Service::GetLatestFirmware(std::string & Compatible, uCentral::Objects::LatestFirmware &L) {
|
||||
try {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
Poco::Data::Statement Select(Sess);
|
||||
|
||||
std::string TmpUUID;
|
||||
std::string st{"SELECT DeviceType, UUID, LastUpdated From LatestFirmwares WHERE DeviceType=?"};
|
||||
std::string st{"SELECT Compatible, UUID, LastUpdated From LatestFirmwares WHERE Compatible=?"};
|
||||
|
||||
Select << ConvertParams(st) ,
|
||||
Poco::Data::Keywords::into(L.DeviceType),
|
||||
Poco::Data::Keywords::into(L.Compatible),
|
||||
Poco::Data::Keywords::into(L.UUID),
|
||||
Poco::Data::Keywords::into(L.LastUpdated),
|
||||
Poco::Data::Keywords::use(DeviceType);
|
||||
Poco::Data::Keywords::use(Compatible);
|
||||
Select.execute();
|
||||
|
||||
return !L.UUID.empty();
|
||||
@@ -90,16 +90,16 @@ namespace uCentral::Storage {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Service::DeleteLatestFirmware(std::string & DeviceType) {
|
||||
bool Service::DeleteLatestFirmware(std::string & Compatible) {
|
||||
try {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
Poco::Data::Statement Delete(Sess);
|
||||
|
||||
std::string TmpUUID;
|
||||
std::string st{"DELETE From LatestFirmwares WHERE DeviceType=?"};
|
||||
std::string st{"DELETE From LatestFirmwares WHERE Compatible=?"};
|
||||
|
||||
Delete << ConvertParams(st),
|
||||
Poco::Data::Keywords::use(DeviceType);
|
||||
Poco::Data::Keywords::use(Compatible);
|
||||
Delete.execute();
|
||||
return true;
|
||||
} catch (const Poco::Exception &E) {
|
||||
@@ -114,7 +114,7 @@ namespace uCentral::Storage {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
Poco::Data::Statement Select(Sess);
|
||||
|
||||
std::string st{"SELECT DeviceType, UUID FROM LatestFirmwares"};
|
||||
std::string st{"SELECT Compatible, UUID FROM LatestFirmwares"};
|
||||
|
||||
Select << ConvertParams(st),
|
||||
Poco::Data::Keywords::into(Records),
|
||||
@@ -123,7 +123,7 @@ namespace uCentral::Storage {
|
||||
|
||||
for(const auto &i:Records) {
|
||||
uCentral::Objects::LatestFirmware L{
|
||||
.DeviceType = i.get<0>(),
|
||||
.Compatible = i.get<0>(),
|
||||
.UUID = i.get<1>()
|
||||
};
|
||||
LatestFirmwareList.push_back(L);
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace uCentral::Storage {
|
||||
location:
|
||||
type: string
|
||||
format: uri
|
||||
deviceType:
|
||||
Compatible:
|
||||
type: string
|
||||
downloadCount:
|
||||
type: integer
|
||||
@@ -69,7 +69,7 @@ namespace uCentral::Storage {
|
||||
"Description VARCHAR(128), "
|
||||
"Owner VARCHAR(128), "
|
||||
"Location TEXT, "
|
||||
"DeviceType VARCHAR(128), "
|
||||
"Compatible VARCHAR(128), "
|
||||
"Uploader VARCHAR(128), "
|
||||
"Uploaded BIGINT, "
|
||||
"DownloadCount BIGINT, "
|
||||
@@ -80,7 +80,9 @@ namespace uCentral::Storage {
|
||||
"FirmwareVersion VARCHAR(128), "
|
||||
"FirmwareHash VARCHAR(32), "
|
||||
"FirmwareLatestDoc TEXT, "
|
||||
"S3URI TEXT )",
|
||||
"S3URI TEXT, "
|
||||
"Latest BIGINT"
|
||||
")",
|
||||
Poco::Data::Keywords::now;
|
||||
return 0;
|
||||
} catch(const Poco::Exception &E) {
|
||||
@@ -143,7 +145,7 @@ namespace uCentral::Storage {
|
||||
LatestFirmware:
|
||||
type: object
|
||||
properties:
|
||||
deviceType:
|
||||
Compatible:
|
||||
type: string
|
||||
uuid:
|
||||
type: string
|
||||
@@ -157,7 +159,7 @@ namespace uCentral::Storage {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
|
||||
Sess << "CREATE TABLE IF NOT EXISTS LatestFirmwares ("
|
||||
"DeviceType VARCHAR(128) PRIMARY KEY, "
|
||||
"Compatible VARCHAR(128) PRIMARY KEY, "
|
||||
"UUID TEXT, "
|
||||
"LastUpdated BIGINT"
|
||||
")",
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace uCentral::FWManager {
|
||||
}
|
||||
|
||||
try {
|
||||
Poco::File JSONFileName(Path + "/" + JobEntry.UUID + "/latest.json");
|
||||
Poco::File JSONFileName(Path + "/" + JobEntry.UUID + "/latest-upgrade.json");
|
||||
|
||||
if (JSONFileName.exists() && JSONFileName.isFile()) {
|
||||
std::ifstream in(JSONFileName.path(),std::ios_base::in);
|
||||
@@ -130,11 +130,12 @@ namespace uCentral::FWManager {
|
||||
F.Size = ImageFileName.getSize();
|
||||
F.DownloadCount = 0;
|
||||
F.Uploaded = time(nullptr);
|
||||
F.DeviceType = ds["compatible"].toString();
|
||||
F.Compatible = ds["compatible"].toString();
|
||||
F.FirmwareVersion = ds["revision"].toString();
|
||||
F.FirmwareFileName = ds["image"].toString();
|
||||
F.Uploader = JobEntry.Entry.Description;
|
||||
F.S3URI = "https://s3-" + S3Region_ + ".amazonaws.com/" + S3BucketName_ + "/" + ImageName;
|
||||
F.Latest = 1;
|
||||
|
||||
if(uCentral::Storage::AddFirmware(F)) {
|
||||
Logger_.information(
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
//
|
||||
// Created by stephane bourque on 2021-05-11.
|
||||
//
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "uNotificationMgr.h"
|
||||
#include "uStorageService.h"
|
||||
@@ -66,17 +68,12 @@ namespace uCentral::NotificationMgr {
|
||||
Updated_ = false;
|
||||
|
||||
if(uCentral::Storage::FirmwareVersion()!=ManifestVersion_) {
|
||||
|
||||
Poco::JSON::Object Manifest;
|
||||
uCentral::Storage::BuildFirmwareManifest(Manifest, ManifestVersion_);
|
||||
|
||||
uCentral::Storage::BuildFirmwareManifest(Manifest, ManifestVersion_);
|
||||
std::stringstream OS;
|
||||
Poco::JSON::Stringifier stringifier;
|
||||
|
||||
stringifier.condense(Manifest, OS);
|
||||
|
||||
std::cout << "Manifest" << std::endl;
|
||||
std::cout << OS.str() << std::endl;
|
||||
CurrentManifest_ = OS.str();
|
||||
}
|
||||
|
||||
@@ -96,6 +93,10 @@ namespace uCentral::NotificationMgr {
|
||||
|
||||
std::vector<uCentral::Objects::Callback> Callbacks;
|
||||
|
||||
std::ofstream File( "latest_manifest.json" , std::ofstream::out | std::ofstream::trunc);
|
||||
File << CurrentManifest_;
|
||||
File.close();
|
||||
|
||||
// build the list of callbacks or update the existing callers.
|
||||
if(uCentral::Storage::GetCallbacks(0,200,Callbacks)) {
|
||||
for(const auto & i:Callbacks) {
|
||||
@@ -112,18 +113,12 @@ namespace uCentral::NotificationMgr {
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << __LINE__ << std::endl;
|
||||
|
||||
if(EndPoints_.empty())
|
||||
return;
|
||||
|
||||
std::cout << __LINE__ << std::endl;
|
||||
for(auto & host:EndPoints_) {
|
||||
std::cout << __LINE__ << std::endl;
|
||||
if(host.second.LastVersion!=ManifestVersion_) {
|
||||
std::cout << __LINE__ << std::endl;
|
||||
if(SendManifest(host.second.Caller)) {
|
||||
std::cout << __LINE__ << std::endl;
|
||||
host.second.LastVersion = ManifestVersion_;
|
||||
host.second.LasContact = time(nullptr);
|
||||
}
|
||||
@@ -133,19 +128,12 @@ namespace uCentral::NotificationMgr {
|
||||
|
||||
bool DoRequest(Poco::Net::HTTPSClientSession& Session, Poco::Net::HTTPRequest& Request, Poco::Net::HTTPResponse& Response, const std::string & Doc)
|
||||
{
|
||||
std::cout << __LINE__ << std::endl;
|
||||
std::stringstream Body(Doc);
|
||||
Request.setContentType("application/json");
|
||||
std::cout << __LINE__ << std::endl;
|
||||
Request.setContentLength(Doc.length());
|
||||
std::cout << __LINE__ << std::endl;
|
||||
std::ostream& OS = Session.sendRequest(Request);
|
||||
std::cout << __LINE__ << std::endl;
|
||||
// Poco::StreamCopier::copyStream(Body, OS);
|
||||
std::cout << __LINE__ << " Wrote bytes:" << Poco::StreamCopier::copyStream(Body, OS) << std::endl;
|
||||
|
||||
Poco::StreamCopier::copyStream(Body, OS);
|
||||
Session.receiveResponse(Response);
|
||||
std::cout << __LINE__ << std::endl;
|
||||
return (Response.getStatus() == Poco::Net::HTTPResponse::HTTP_OK);
|
||||
}
|
||||
|
||||
@@ -160,8 +148,6 @@ namespace uCentral::NotificationMgr {
|
||||
Uri.getPathAndQuery(),
|
||||
Poco::Net::HTTPMessage::HTTP_1_1);
|
||||
Request.add("X-API-KEY", Host.Token);
|
||||
std::cout << __LINE__ << Uri.toString() << std::endl;
|
||||
|
||||
Poco::Net::HTTPResponse Response;
|
||||
return DoRequest(Session, Request, Response, CurrentManifest_);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace uCentral::NotificationMgr {
|
||||
std::map<std::string,NotifyEndPoint> EndPoints_;
|
||||
|
||||
std::string CurrentManifest_;
|
||||
uint64_t ManifestVersion_;
|
||||
uint64_t ManifestVersion_=0;
|
||||
|
||||
int Start() override;
|
||||
void Stop() override;
|
||||
|
||||
@@ -37,9 +37,9 @@ namespace uCentral::Storage {
|
||||
bool BuildFirmwareManifest(Poco::JSON::Object & Manifest, uint64_t &Version);
|
||||
uint64_t FirmwareVersion();
|
||||
|
||||
bool AddLatestFirmware(std::string & DeviceType, std::string &UUID);
|
||||
bool GetLatestFirmware(std::string & DeviceType, uCentral::Objects::LatestFirmware &L);
|
||||
bool DeleteLatestFirmware(std::string & DeviceType);
|
||||
bool AddLatestFirmware(std::string & Compatible, std::string &UUID);
|
||||
bool GetLatestFirmware(std::string & Compatible, uCentral::Objects::LatestFirmware &L);
|
||||
bool DeleteLatestFirmware(std::string & Compatible);
|
||||
bool GetLatestFirmwareList(uint64_t From, uint64_t HowMany, std::vector<uCentral::Objects::LatestFirmware> & LatestFirmwareList);
|
||||
|
||||
|
||||
@@ -67,9 +67,9 @@ namespace uCentral::Storage {
|
||||
friend bool GetFirmware(std::string & UUID, uCentral::Objects::Firmware & C);
|
||||
friend bool GetFirmwares(uint64_t From, uint64_t HowMany, std::vector<uCentral::Objects::Firmware> & Firmwares);
|
||||
|
||||
friend bool AddLatestFirmware(std::string & DeviceType, std::string &UUID);
|
||||
friend bool GetLatestFirmware(std::string & DeviceType, uCentral::Objects::LatestFirmware &L);
|
||||
friend bool DeleteLatestFirmware(std::string & DeviceType);
|
||||
friend bool AddLatestFirmware(std::string & Compatible, std::string &UUID);
|
||||
friend bool GetLatestFirmware(std::string & Compatible, uCentral::Objects::LatestFirmware &L);
|
||||
friend bool DeleteLatestFirmware(std::string & Compatible);
|
||||
friend bool GetLatestFirmwareList(uint64_t From, uint64_t HowMany, std::vector<uCentral::Objects::LatestFirmware> & LatestFirmwareList);
|
||||
|
||||
|
||||
@@ -106,9 +106,9 @@ namespace uCentral::Storage {
|
||||
bool BuildFirmwareManifest(Poco::JSON::Object & Manifest, uint64_t & Version);
|
||||
uint64_t FirmwareVersion();
|
||||
|
||||
bool AddLatestFirmware(std::string & DeviceType, std::string &UUID);
|
||||
bool GetLatestFirmware(std::string & DeviceType, uCentral::Objects::LatestFirmware &L);
|
||||
bool DeleteLatestFirmware(std::string & DeviceType);
|
||||
bool AddLatestFirmware(std::string & Compatible, std::string &UUID);
|
||||
bool GetLatestFirmware(std::string & Compatible, uCentral::Objects::LatestFirmware &L);
|
||||
bool DeleteLatestFirmware(std::string & Compatible);
|
||||
bool GetLatestFirmwareList(uint64_t From, uint64_t HowMany, std::vector<uCentral::Objects::LatestFirmware> & LatestFirmwareList);
|
||||
|
||||
int Start() override;
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
key="0T1jZ0zO9fkvWI8pk722ZAeSKmqey1jiDXNafRlpdiy4lletCCaVAgWdSH5LD5f8"
|
||||
|
||||
curl -v -H "X-API-KEY: $key" \
|
||||
-F upload=@latest.json \
|
||||
-F upload=@latest-upgrade.json \
|
||||
-F upload=@20210508-linksys_ea8300-uCentral-trunk-43e1a2d-upgrade.bin \
|
||||
https://local.dpaas.arilia.com:15065
|
||||
|
||||
Reference in New Issue
Block a user