mirror of
https://github.com/Telecominfraproject/wlan-cloud-owls.git
synced 2026-01-27 10:22:52 +00:00
Fixing stats reset at sim startup.
This commit is contained in:
@@ -348,41 +348,6 @@ components:
|
||||
items:
|
||||
$ref: '#/components/schemas/SimulationDetails'
|
||||
|
||||
SimulationResults:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
format: uuid
|
||||
simulationId:
|
||||
type: string
|
||||
format: uuid
|
||||
startTime:
|
||||
type: integer
|
||||
format: int64
|
||||
endTime:
|
||||
type: integer
|
||||
format: int64
|
||||
numClientsSuccesses:
|
||||
type: integer
|
||||
numClientsErrors:
|
||||
type: integer
|
||||
timeToFullDevices:
|
||||
type: integer
|
||||
format: int64
|
||||
tx:
|
||||
type: integer
|
||||
rx:
|
||||
type: integer
|
||||
|
||||
SimulationResultsList:
|
||||
type: object
|
||||
properties:
|
||||
list:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/SimulationResults'
|
||||
|
||||
SimulationStatus:
|
||||
type: object
|
||||
properties:
|
||||
@@ -423,6 +388,14 @@ components:
|
||||
- canceled
|
||||
- completed
|
||||
|
||||
SimulationStatusList:
|
||||
type: object
|
||||
properties:
|
||||
list:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/SimulationStatus'
|
||||
|
||||
paths:
|
||||
/simulation:
|
||||
get:
|
||||
@@ -498,7 +471,7 @@ paths:
|
||||
operationId: getSimulationResults
|
||||
responses:
|
||||
200:
|
||||
$ref: '#/components/schemas/SimulationResultsList'
|
||||
$ref: '#/components/schemas/SimulationStatusList'
|
||||
400:
|
||||
$ref: '#/components/responses/BadRequest'
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
namespace OpenWifi {
|
||||
|
||||
void RESTAPI_results_handler::DoGet() {
|
||||
std::vector<OWLSObjects::SimulationResults> Results;
|
||||
std::vector<OWLSObjects::SimulationStatus> Results;
|
||||
StorageService()->SimulationResultsDB().GetRecords(1,10000,Results);
|
||||
return ReturnObject("list",Results);
|
||||
}
|
||||
|
||||
@@ -82,50 +82,6 @@ namespace OpenWifi::OWLSObjects {
|
||||
return false;
|
||||
}
|
||||
|
||||
void SimulationResults::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj,"id", id);
|
||||
field_to_json(Obj,"simulationId", simulationId);
|
||||
field_to_json(Obj,"startTime", startTime);
|
||||
field_to_json(Obj,"endTime", endTime);
|
||||
field_to_json(Obj,"numClientsSuccesses", numClientsSuccesses);
|
||||
field_to_json(Obj,"numClientsErrors", numClientsErrors);
|
||||
field_to_json(Obj,"timeToFullDevices", timeToFullDevices);
|
||||
field_to_json(Obj,"tx", tx);
|
||||
field_to_json(Obj,"rx", rx);
|
||||
}
|
||||
|
||||
bool SimulationResults::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"id", id);
|
||||
field_from_json(Obj,"simulationId", simulationId);
|
||||
field_from_json(Obj,"startTime", startTime);
|
||||
field_from_json(Obj,"endTime", endTime);
|
||||
field_from_json(Obj,"numClientsSuccesses", numClientsSuccesses);
|
||||
field_from_json(Obj,"numClientsErrors", numClientsErrors);
|
||||
field_from_json(Obj,"timeToFullDevices", timeToFullDevices);
|
||||
field_from_json(Obj,"tx", tx);
|
||||
field_from_json(Obj,"rx", rx);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SimulationResultsList::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj,"list", list);
|
||||
}
|
||||
|
||||
bool SimulationResultsList::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json(Obj,"list", list);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SimulationStatus::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj,"id", id);
|
||||
field_to_json(Obj,"simulationId", simulationId);
|
||||
|
||||
@@ -43,29 +43,6 @@ namespace OpenWifi::OWLSObjects {
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
|
||||
struct SimulationResults {
|
||||
std::string id;
|
||||
std::string simulationId;
|
||||
uint64_t startTime;
|
||||
uint64_t endTime;
|
||||
uint64_t numClientsSuccesses;
|
||||
uint64_t numClientsErrors;
|
||||
uint64_t timeToFullDevices;
|
||||
uint64_t tx;
|
||||
uint64_t rx;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
struct SimulationResultsList {
|
||||
std::vector<SimulationResults> list;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
struct SimulationStatus {
|
||||
std::string id;
|
||||
std::string simulationId;
|
||||
|
||||
@@ -85,17 +85,23 @@ namespace OpenWifi {
|
||||
Status_.state = S;
|
||||
}
|
||||
|
||||
[[nodiscard]] const std::string & GetState() {
|
||||
[[nodiscard]] inline const std::string & GetState() {
|
||||
std::lock_guard G(Mutex_);
|
||||
return Status_.state;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline const std::string & Id() const {
|
||||
return Status_.id;
|
||||
}
|
||||
|
||||
inline void Reset() {
|
||||
Status_.liveDevices = Status_.tx = Status_.msgsRx = Status_.msgsTx = Status_.rx =
|
||||
Status_.endTime = Status_.errorDevices = Status_.startTime = Status_.timeToFullDevices = 0;
|
||||
Status_.simulationId = Status_.id = Status_.state = "";
|
||||
}
|
||||
|
||||
[[nodiscard]] uint64_t GetStartTime() const { return Status_.startTime; }
|
||||
|
||||
private:
|
||||
static SimStats * instance_;
|
||||
OWLSObjects::SimulationStatus Status_;
|
||||
|
||||
@@ -41,6 +41,17 @@ namespace OpenWifi {
|
||||
Poco::Thread::trySleep(2000);
|
||||
if(!Running_)
|
||||
break;
|
||||
|
||||
if(SimStats()->GetState()!="running") {
|
||||
continue;
|
||||
}
|
||||
|
||||
uint64_t Now = std::time(nullptr);
|
||||
|
||||
if( (Now - SimStats()->GetStartTime()) > CurrentSim_.simulationLength ) {
|
||||
std::string Error;
|
||||
StopSim( SimStats()->Id(), Error );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,6 +153,12 @@ namespace OpenWifi {
|
||||
|
||||
SimRunning_ = false;
|
||||
SimStats()->SetState("stopped");
|
||||
SimStats()->EndSim();
|
||||
|
||||
OWLSObjects::SimulationStatus S;
|
||||
SimStats()->GetCurrent(S);
|
||||
StorageService()->SimulationResultsDB().CreateRecord(S);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,13 +9,16 @@ namespace OpenWifi {
|
||||
static ORM::FieldVec SimulationResultsDB_Fields{
|
||||
ORM::Field{"id",64, true},
|
||||
ORM::Field{"simulationId",ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"state",ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"tx",ORM::FieldType::FT_BIGINT},
|
||||
ORM::Field{"rx",ORM::FieldType::FT_BIGINT},
|
||||
ORM::Field{"msgsTx",ORM::FieldType::FT_BIGINT},
|
||||
ORM::Field{"msgsRx",ORM::FieldType::FT_BIGINT},
|
||||
ORM::Field{"liveDevices",ORM::FieldType::FT_BIGINT},
|
||||
ORM::Field{"timeToFullDevices",ORM::FieldType::FT_BIGINT},
|
||||
ORM::Field{"startTime",ORM::FieldType::FT_BIGINT},
|
||||
ORM::Field{"endTime",ORM::FieldType::FT_BIGINT},
|
||||
ORM::Field{"numClientsSuccesses",ORM::FieldType::FT_BIGINT},
|
||||
ORM::Field{"numClientsErrors",ORM::FieldType::FT_BIGINT},
|
||||
ORM::Field{"timeToFullDevices",ORM::FieldType::FT_BIGINT},
|
||||
ORM::Field{"tx",ORM::FieldType::FT_BIGINT},
|
||||
ORM::Field{"rx",ORM::FieldType::FT_BIGINT}
|
||||
ORM::Field{"errorDevices",ORM::FieldType::FT_BIGINT}
|
||||
};
|
||||
|
||||
static ORM::IndexVec SimulationResultsDB_Indexes{
|
||||
@@ -26,26 +29,32 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
|
||||
template<> void ORM::DB<OpenWifi::SimulationResultsDBRecordType, OpenWifi::OWLSObjects::SimulationResults>::Convert(OpenWifi::SimulationResultsDBRecordType &In, OpenWifi::OWLSObjects::SimulationResults &Out) {
|
||||
template<> void ORM::DB<OpenWifi::SimulationResultsDBRecordType, OpenWifi::OWLSObjects::SimulationStatus>::Convert(OpenWifi::SimulationResultsDBRecordType &In, OpenWifi::OWLSObjects::SimulationStatus &Out) {
|
||||
Out.id = In.get<0>();
|
||||
Out.simulationId = In.get<1>();
|
||||
Out.startTime = In.get<2>();
|
||||
Out.endTime = In.get<3>();
|
||||
Out.numClientsSuccesses = In.get<4>();
|
||||
Out.numClientsErrors = In.get<5>();
|
||||
Out.timeToFullDevices = In.get<6>();
|
||||
Out.tx = In.get<7>();
|
||||
Out.rx = In.get<8>();
|
||||
Out.state = In.get<2>();
|
||||
Out.tx = In.get<3>();
|
||||
Out.rx = In.get<4>();
|
||||
Out.msgsTx = In.get<5>();
|
||||
Out.msgsRx = In.get<6>();
|
||||
Out.liveDevices = In.get<7>();
|
||||
Out.timeToFullDevices = In.get<8>();
|
||||
Out.startTime = In.get<9>();
|
||||
Out.endTime = In.get<10>();
|
||||
Out.errorDevices = In.get<11>();
|
||||
}
|
||||
|
||||
template<> void ORM::DB<OpenWifi::SimulationResultsDBRecordType, OpenWifi::OWLSObjects::SimulationResults>::Convert(OpenWifi::OWLSObjects::SimulationResults &In, OpenWifi::SimulationResultsDBRecordType &Out) {
|
||||
template<> void ORM::DB<OpenWifi::SimulationResultsDBRecordType, OpenWifi::OWLSObjects::SimulationStatus>::Convert(OpenWifi::OWLSObjects::SimulationStatus &In, OpenWifi::SimulationResultsDBRecordType &Out) {
|
||||
Out.set<0>(In.id);
|
||||
Out.set<1>(In.simulationId);
|
||||
Out.set<2>(In.startTime);
|
||||
Out.set<3>(In.endTime);
|
||||
Out.set<4>(In.numClientsSuccesses);
|
||||
Out.set<5>(In.numClientsErrors);
|
||||
Out.set<6>(In.timeToFullDevices);
|
||||
Out.set<7>(In.tx);
|
||||
Out.set<8>(In.rx);
|
||||
Out.set<2>(In.state);
|
||||
Out.set<3>(In.tx);
|
||||
Out.set<4>(In.rx);
|
||||
Out.set<5>(In.msgsTx);
|
||||
Out.set<6>(In.msgsRx);
|
||||
Out.set<7>(In.liveDevices);
|
||||
Out.set<8>(In.timeToFullDevices);
|
||||
Out.set<9>(In.startTime);
|
||||
Out.set<10>(In.endTime);
|
||||
Out.set<11>(In.errorDevices);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ namespace OpenWifi {
|
||||
typedef Poco::Tuple<
|
||||
std::string,
|
||||
std::string,
|
||||
std::string,
|
||||
uint64_t,
|
||||
uint64_t,
|
||||
uint64_t,
|
||||
uint64_t,
|
||||
uint64_t,
|
||||
@@ -21,7 +24,7 @@ namespace OpenWifi {
|
||||
uint64_t
|
||||
> SimulationResultsDBRecordType;
|
||||
|
||||
class SimulationResultsDB : public ORM::DB<SimulationResultsDBRecordType,OWLSObjects::SimulationResults> {
|
||||
class SimulationResultsDB : public ORM::DB<SimulationResultsDBRecordType,OWLSObjects::SimulationStatus> {
|
||||
public:
|
||||
SimulationResultsDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L);
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user