mirror of
https://github.com/Telecominfraproject/wlan-cloud-owls.git
synced 2026-01-27 02:22:44 +00:00
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
This commit is contained in:
@@ -3,11 +3,8 @@
|
||||
//
|
||||
#include "OWLSclient.h"
|
||||
#include "SimulationRunner.h"
|
||||
#include "SimulationCoordinator.h"
|
||||
#include <fmt/format.h>
|
||||
#include "SimStats.h"
|
||||
#include <Poco/NObserver.h>
|
||||
|
||||
#include "OWLSclientEvents.h"
|
||||
|
||||
namespace OpenWifi::OWLSclientEvents {
|
||||
|
||||
@@ -26,6 +26,10 @@ namespace OpenWifi {
|
||||
|
||||
std::string Error;
|
||||
if (Op == "start") {
|
||||
if(SimulationCoordinator()->IsSimulationRunning(Id)) {
|
||||
RESTAPI::Errors::msg E{.err_num=4001, .err_txt="Simulation is already running."};
|
||||
return BadRequest(E);
|
||||
}
|
||||
SimulationCoordinator()->StartSim(SimId, Id, Error, UserInfo_.userinfo.email);
|
||||
} else if (Op == "stop") {
|
||||
SimulationCoordinator()->StopSim(SimId, Error);
|
||||
|
||||
@@ -56,12 +56,17 @@ namespace OpenWifi {
|
||||
|
||||
uint64_t Now = Utils::Now();
|
||||
std::lock_guard G(Mutex_);
|
||||
for(auto &[_,simulation]:Simulations_) {
|
||||
|
||||
for(auto &[id,simulation]:Simulations_) {
|
||||
if (simulation->Details.simulationLength != 0 &&
|
||||
(Now - SimStats()->GetStartTime(simulation->Runner.Id())) > simulation->Details.simulationLength) {
|
||||
std::string Error;
|
||||
simulation->Runner.Stop();
|
||||
SimStats()->EndSim(simulation->Runner.Id());
|
||||
SimStats()->EndSim(id);
|
||||
OWLSObjects::SimulationStatus S;
|
||||
SimStats()->GetCurrent(id, S);
|
||||
StorageService()->SimulationResultsDB().CreateRecord(S);
|
||||
Simulations_.erase(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,6 +105,16 @@ namespace OpenWifi {
|
||||
return Res;
|
||||
}
|
||||
|
||||
bool SimulationCoordinator::IsSimulationRunning(const std::string &id) {
|
||||
std::lock_guard G(Mutex_);
|
||||
|
||||
for(const auto &[instance_id,simulation]:Simulations_) {
|
||||
if(simulation->Details.id==id)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SimulationCoordinator::StartSim(std::string &SimId, const std::string &Id,
|
||||
std::string &Error, const std::string &Owner) {
|
||||
std::lock_guard G(Mutex_);
|
||||
@@ -130,10 +145,10 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
sim_hint->second->Runner.Stop();
|
||||
|
||||
OWLSObjects::SimulationStatus S;
|
||||
SimStats()->GetCurrent(sim_hint->second->Runner.Id(), S);
|
||||
StorageService()->SimulationResultsDB().CreateRecord(S);
|
||||
Simulations_.erase(sim_hint);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -150,6 +165,7 @@ namespace OpenWifi {
|
||||
|
||||
sim_hint->second->Runner.Stop();
|
||||
SimStats()->SetState(sim_hint->second->Runner.Id(),"none");
|
||||
Simulations_.erase(sim_hint);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ namespace OpenWifi {
|
||||
|
||||
[[nodiscard]] Poco::JSON::Object::Ptr GetSimConfigurationPtr(uint64_t uuid);
|
||||
[[nodiscard]] Poco::JSON::Object::Ptr GetSimCapabilitiesPtr();
|
||||
bool IsSimulationRunning(const std::string &id);
|
||||
|
||||
private:
|
||||
Poco::Thread Worker_;
|
||||
|
||||
Reference in New Issue
Block a user