ADD: added a general kubenetes API and integrated that in the classes and remodeled the info management

This commit is contained in:
hwinkel
2023-12-22 13:14:40 +01:00
parent 351cf9ec69
commit 4045f21786
13 changed files with 363 additions and 833 deletions

View File

@@ -1,62 +1,71 @@
#include "kubecontrol/KubernetesAPI.hpp"
#define CATCH_CONFIG_MAIN
#include <string>
#include <catch2/catch.hpp>
#include <loguru.hpp>
#include <kubecontrol/KubePod.hpp>
#include <crossguid/guid.hpp>
#include "kubecontrol/PodController.hpp"
#include "nlohmann/json_fwd.hpp"
#include <thread>
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include "loguru.hpp"
SCENARIO("Testing the SimCore Sensor")
{
// kubecontrol::PodController podc("docs/config");
kubecontrol::KubernetesAPI api(YAML::LoadFile("docs/config"));
std::string name = "hamburg";
std::string uuid = name;
kubecontrol::KubePod ShipPod1("controller",uuid,"ship","ship:latest","simulator");
nlohmann::json vars;
vars["ENTITY_ID"] = uuid;
vars["ENTITY_NAME"] = "FGS Hamburg";
vars["ENTITY_SIDE"] = "Neutral";
vars["POSITION"]["LAT"] = "55";
vars["POSITION"]["LON"] = "8";
vars["POSITION"]["Height"] = "0";
vars["COURSE"] = "0";
vars["SPEED"] = "0";
vars["GROUNDTRUTH_PORT"] = std::to_string(10000);
vars["GROUNDTRUTH_ADDR"] = "239.0.0.1";
vars["COMMAND_PORT"] = "5555";
vars["ENTITY_RCS"] = std::to_string(850);
vars["ENTITY_SENSORS"].push_back("radar:latest");
ShipPod1.setEnvironmentVar("CONFIG", vars.dump());
LOG_S(INFO)<<"Starting";
ShipPod1.start(api);
LOG_S(INFO)<<"started";
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
GIVEN("different Attributes for a Track in different forms")
{
// std::string api = "https://192.168.3.11:6443/api/v1/namespaces/simulator/pods/";
// std::string token = "eyJhbGciOiJSUzI1NiIsImtpZCI6Il9tUkVrVkp5VjFKeDhtV2xDTmM4R2Y1ZkhRSlBOOWxaVnhKTkZuWVlJamMifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJzaW11bGF0b3IiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlY3JldC5uYW1lIjoic2ltLXNlY3JldCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJzaW11bGF0b3IiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiJlOGU5YzQ2ZS1lMzcxLTQxMTItOTgzYS1lNzM5NGJmNWE0YzEiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6c2ltdWxhdG9yOnNpbXVsYXRvciJ9.JJjzj0RCU6PJruXuyrK_mNdW4piDADXKPtEW9YP2x1R57uhTDPFfG6LPMFbZTNyeI-A7A7bmjjAt0ICJDuLeL69J8ig3TS-i54R_PB--wFr-7jZMhnNz2wueyPuXxGiIuX-36H9rZ1cA-Dgt2qtDMNhK0TvOlgwUFU_cRjb2W0NhSvH8uB0qtIqOCyVzapCVwXWinyJPGiPL3ph8VxSo6P0ZDa4UjMJ_D6IlMpUpuHriKPLjGnDwTh2oJBjMFOmC_E0Mnr6Sd0rxzsIjIeG_ST6KqoPwyCTX27CPmO74CJUguLgFXSBOjuzvxon8KRYG6VJhRawEDnTU0zx6XrPXIQ";
kubecontrol::KubernetesAPI KubeAPI(YAML::LoadFile("docs/config"));
auto guid = xg::newGuid();
std::string uuid = guid.str();
// int random = rand() % 100 + 1;
// std::string uuid = "random" + std::to_string(random);
kubecontrol::KubePod pod1("controller",uuid,"ship","ship:latest","simulator");
nlohmann::json vars;
vars["ENTITY_ID"] = uuid;
vars["ENTITY_NAME"] = "FGS Hamburg";
vars["ENTITY_SIDE"] = "Neutral";
vars["POSITION"]["LAT"] = "55";
vars["POSITION"]["LON"] = "8";
vars["POSITION"]["Height"] = "0";
vars["COURSE"] = "0";
vars["SPEED"] = "0";
vars["GROUNDTRUTH_PORT"] = std::to_string(10000);
vars["GROUNDTRUTH_ADDR"] = "239.0.0.1";
vars["COMMAND_PORT"] = "5555";
vars["ENTITY_RCS"] = std::to_string(850);
vars["ENTITY_SENSORS"].push_back("radar:latest");
pod1.setEnvironmentVar("CONFIG", vars.dump());
// LOG_S(INFO)<<pod1.createYAML();
pod1.start(KubeAPI);
// LOG_S(INFO)<< pod1.getInfoForThisPod(KubeAPI);
// LOG_S(INFO)<< pod1.getInfoForRelatedPods(KubeAPI);
pod1.getUUIDForRelatedPods(KubeAPI);
pod1.stop(KubeAPI);
WHEN("constructing Track Object with data")
{
THEN("check if Track attributes are correct")
{
REQUIRE(true == true);
REQUIRE(ShipPod1.getUUID() == "hamburg");
REQUIRE(ShipPod1.getComponent() == "ship");
REQUIRE(ShipPod1.getOwner() == "controller");
REQUIRE(ShipPod1.getStatus() == "Running");
REQUIRE(ShipPod1.getIp() != "");
REQUIRE(ShipPod1.getUUIDsForChildPods(api).size() == 2);
// REQUIRE(info1 != "");
ShipPod1.stop(api);

View File

@@ -14,6 +14,8 @@
#include <kubecontrol/PodController.hpp>
#include <crossguid/guid.hpp>
const int podGrid = 2;
void startShip(kubecontrol::PodController* podc,std::string uuid,std::string Name, std::string lat, std::string lon)
{
@@ -46,7 +48,7 @@ void createScenario(kubecontrol::PodController* podc,std::vector<std::string> *u
int counter = 0;
double distance = 10000;
int rasterSize = 5;
int rasterSize = podGrid;
for (int i = 0; i < rasterSize; i++ )
{
@@ -98,17 +100,22 @@ std::vector<std::string> uuidList;
createScenario(podc, &uuidList);
LOG_S(INFO)<<"Amount Parent Pods: " << uuidList.size();
std::this_thread::sleep_for(std::chrono::milliseconds(20000));
std::this_thread::sleep_for(std::chrono::milliseconds(4000));
// podc.stopPod(std::string Label)
for (auto i: uuidList)
{
auto retrurn = std::async(std::launch::async, &kubecontrol::PodController::stopPod,podc,i);
}
// for (auto i: uuidList)
// {
// auto retrurn = std::async(std::launch::async, &kubecontrol::PodController::stopPod,podc,i);
// }
// std::this_thread::sleep_for(std::chrono::milliseconds(20000));
// Create a random number generator
std::default_random_engine generator;
std::uniform_int_distribution<int> distribution(0, uuidList.size()-1);
// Generate a random index
int random_index = distribution(generator);
podc->stopAllPods();
GIVEN("different Attributes for a Track in different forms")
{
@@ -117,9 +124,15 @@ podc->stopAllPods();
THEN("check if Track attributes are correct")
{
REQUIRE(true == true);
auto info = podc->getInfoForPod(uuidList[random_index]);
REQUIRE(info.Component == "ship");
REQUIRE(info.UUID == uuidList[random_index]);
REQUIRE(info.IP != "");
REQUIRE(info.Owner == "controller");
REQUIRE(podc->getInfoForAllPods().size() == podGrid*podGrid);
// REQUIRE(info1 != "");
podc->stopAllPods();

View File

@@ -1,79 +0,0 @@
#include "kubecontrol/PodController.hpp"
#include "nlohmann/json_fwd.hpp"
#include <thread>
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <kubecontrol/PodInfo.hpp>
SCENARIO("Testing the SimCore Sensor")
{
kubecontrol::PodController podc("docs/config");
std::string name = "hamburg";
std::string uuid = name;
kubecontrol::KubePod ShipPod1("controller",uuid,"ship","ship:latest","simulator");
nlohmann::json vars;
vars["ENTITY_ID"] = uuid;
vars["ENTITY_NAME"] = "FGS Hamburg";
vars["ENTITY_SIDE"] = "Neutral";
vars["POSITION"]["LAT"] = "55";
vars["POSITION"]["LON"] = "8";
vars["POSITION"]["Height"] = "0";
vars["COURSE"] = "0";
vars["SPEED"] = "0";
vars["GROUNDTRUTH_PORT"] = std::to_string(10000);
vars["GROUNDTRUTH_ADDR"] = "239.0.0.1";
vars["COMMAND_PORT"] = "5555";
vars["ENTITY_RCS"] = std::to_string(850);
vars["ENTITY_SENSORS"].push_back("radar:latest");
ShipPod1.setEnvironmentVar("CONFIG", vars.dump());
LOG_S(INFO)<<"Starting";
podc.startPod(ShipPod1);
LOG_S(INFO)<<"started";
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
podc.checkPodsHierarchy();
auto tmp = podc.getInfoForPod(name);
// LOG_S(INFO)<<tmp;
kubecontrol::PodInfo info(tmp);
LOG_S(INFO)<<info.ToString();
LOG_S(INFO)<<info.ToJson();
podc.stopAllPods();
GIVEN("different Attributes for a Track in different forms")
{
WHEN("constructing Track Object with data")
{
THEN("check if Track attributes are correct")
{
REQUIRE(info.Uuid == "hamburg");
// REQUIRE(info1 != "");
} //THEN
} // WHEN
} // GIVEN
} //SCENARIO

View File

@@ -58,7 +58,7 @@ std::string info1 = "";
// nlohmann::json j1 = nlohmann::json::parse(info1);
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
ShipPod1.updateInfoForThisPod(podc.getKubernetesAPI());
// podc.checkPodsHierarchy();
// LOG_S(INFO)<<podc.PodList_.size();;
// for(auto i: podc.PodList_)
@@ -77,11 +77,15 @@ std::this_thread::sleep_for(std::chrono::milliseconds(2000));
THEN("check if Track attributes are correct")
{
REQUIRE(podc.getListOfChildPods() == 1);
auto info = podc.getInfoForPod(ShipPod1.getUUID());
REQUIRE(info.UUID == ShipPod1.getUUID());
REQUIRE(info.IP == ShipPod1.getIp());
REQUIRE(info.Owner == ShipPod1.getOwner());
REQUIRE(info.Component == ShipPod1.getComponent());
LOG_S(INFO)<<"Stopping";
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
podc.stopAllPods();
LOG_S(INFO)<<"Stopping";
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
podc.stopAllPods();
// REQUIRE(info1 != "");