ADD: added central kubernetes api class
This commit is contained in:
@@ -64,6 +64,10 @@ ENDIF()
|
|||||||
|
|
||||||
include/kubecontrol/PodInfo.hpp
|
include/kubecontrol/PodInfo.hpp
|
||||||
src/kubecontrol/PodInfo.cpp
|
src/kubecontrol/PodInfo.cpp
|
||||||
|
|
||||||
|
|
||||||
|
include/kubecontrol/KubernetesAPI.hpp
|
||||||
|
src/kubecontrol/KubernetesAPI.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "kubecontrol/KubernetesAPI.hpp"
|
||||||
#include "kubecontrol/PodInfo.hpp"
|
#include "kubecontrol/PodInfo.hpp"
|
||||||
#include "nlohmann/json_fwd.hpp"
|
#include "nlohmann/json_fwd.hpp"
|
||||||
#include "yaml-cpp/node/node.h"
|
#include "yaml-cpp/node/node.h"
|
||||||
@@ -45,16 +46,36 @@ namespace kubecontrol
|
|||||||
std::string getComponent();
|
std::string getComponent();
|
||||||
|
|
||||||
|
|
||||||
std::string createYAML();
|
|
||||||
std::string start(std::string apiAddress,std::string token);
|
// [[deprecated("replace with start(KubernetesAPI APIInterface)")]]
|
||||||
|
// std::string start(std::string apiAddress,std::string token,bool WaitTillRunning = true);
|
||||||
|
|
||||||
|
std::string start(KubernetesAPI APIInterface,bool WaitTillRunning = true);
|
||||||
|
|
||||||
|
[[deprecated("replace with stop(KubernetesAPI APIInterface)")]]
|
||||||
std::string stop(std::string apiAddress,std::string token);
|
std::string stop(std::string apiAddress,std::string token);
|
||||||
std::string getInfo(std::string apiAddress,std::string token);
|
|
||||||
|
std::string stop(KubernetesAPI APIInterface);
|
||||||
|
|
||||||
|
// [[deprecated("replace with getInfo(KubernetesAPI APIInterface)")]]
|
||||||
|
// std::string getInfo(std::string apiAddress,std::string token);
|
||||||
|
|
||||||
|
std::string getInfoForThisPod(KubernetesAPI APIInterface);
|
||||||
|
|
||||||
|
std::string getInfoForRelatedPods(KubernetesAPI APIInterface);
|
||||||
|
|
||||||
|
std::vector<std::string> getUUIDForRelatedPods(KubernetesAPI APIInterface);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PodInfo InfoPod;
|
PodInfo InfoPod;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string Owner_;
|
std::string Owner_;
|
||||||
std::string Uuid_;
|
std::string Uuid_;
|
||||||
std::string Component_;
|
std::string Component_;
|
||||||
@@ -63,6 +84,10 @@ namespace kubecontrol
|
|||||||
std::string PathToYaml_;
|
std::string PathToYaml_;
|
||||||
std::string Namespace_;
|
std::string Namespace_;
|
||||||
|
|
||||||
|
std::string Ip_;
|
||||||
|
std::string Status_;
|
||||||
|
std::string PartOf_;
|
||||||
|
std::vector<std::string> uuidsOfShildContainers;
|
||||||
|
|
||||||
std::string PodCommand_;
|
std::string PodCommand_;
|
||||||
|
|
||||||
@@ -71,9 +96,12 @@ namespace kubecontrol
|
|||||||
std::map<std::string, std::string> EnvirmonentVars_;
|
std::map<std::string, std::string> EnvirmonentVars_;
|
||||||
std::vector<std::string> Args_;
|
std::vector<std::string> Args_;
|
||||||
|
|
||||||
|
std::string createYAML();
|
||||||
|
|
||||||
|
// std::string read;
|
||||||
|
|
||||||
|
|
||||||
std::string StopChilds(std::string apiAddress,std::string token,std::string uuid);
|
std::string StopChilds(std::string apiAddress,std::string token,std::string uuid);
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
32
include/kubecontrol/KubernetesAPI.hpp
Normal file
32
include/kubecontrol/KubernetesAPI.hpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <yaml-cpp/node/node.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
namespace kubecontrol
|
||||||
|
{
|
||||||
|
|
||||||
|
class KubernetesAPI
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KubernetesAPI();
|
||||||
|
KubernetesAPI(YAML::Node config);
|
||||||
|
|
||||||
|
KubernetesAPI(std::string APIAddress, std::string Token);
|
||||||
|
|
||||||
|
std::string performRequest(std::string request,std::string Methode = "GET");
|
||||||
|
|
||||||
|
std::string performRequest(std::string request,std::string Methode,std::string PostFields);
|
||||||
|
|
||||||
|
void addAddress(std::string address);
|
||||||
|
void addToken(std::string Token);
|
||||||
|
void addYaml(YAML::Node config);
|
||||||
|
private:
|
||||||
|
std::string APIAddress_;
|
||||||
|
std::string Token_;
|
||||||
|
std::string Namespace_;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "kubecontrol/KubernetesAPI.hpp"
|
||||||
#include "kubecontrol/PodInfo.hpp"
|
#include "kubecontrol/PodInfo.hpp"
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <kubecontrol/KubePod.hpp>
|
#include <kubecontrol/KubePod.hpp>
|
||||||
@@ -16,13 +17,13 @@ namespace kubecontrol
|
|||||||
|
|
||||||
std::string getServerAddress();
|
std::string getServerAddress();
|
||||||
|
|
||||||
void startPod(KubePod Pod);
|
void startPod(KubePod Pod,bool WaitTillRunning = true );
|
||||||
void stopPod(std::string Label);
|
void stopPod(std::string uuid);
|
||||||
void stopAllPods();
|
void stopAllPods();
|
||||||
|
|
||||||
std::string getPodsInfo();
|
std::string getInfoForAllPods();
|
||||||
std::string getInfoForOwnPod();
|
// std::string getInfoForOwnPod();
|
||||||
std::string getInfoForPod(std::string Label);
|
std::string getInfoForPod(std::string uuid);
|
||||||
size_t getListOfChildPods();
|
size_t getListOfChildPods();
|
||||||
|
|
||||||
void checkPodsHierarchy();
|
void checkPodsHierarchy();
|
||||||
@@ -30,6 +31,7 @@ namespace kubecontrol
|
|||||||
std::string getPodsInfoForAll();
|
std::string getPodsInfoForAll();
|
||||||
std::shared_ptr<PodInfo> getPodsInfo(std::string uuid);
|
std::shared_ptr<PodInfo> getPodsInfo(std::string uuid);
|
||||||
private:
|
private:
|
||||||
|
KubernetesAPI APIInterface_;
|
||||||
std::vector<KubePod> PodList_;
|
std::vector<KubePod> PodList_;
|
||||||
|
|
||||||
std::string performRequest(std::string url);
|
std::string performRequest(std::string url);
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
#include "curlpp/Options.hpp"
|
#include "curlpp/Options.hpp"
|
||||||
|
#include "kubecontrol/PodInfo.hpp"
|
||||||
#include "kubecontrol/Utils.hpp"
|
#include "kubecontrol/Utils.hpp"
|
||||||
|
#include "nlohmann/json_fwd.hpp"
|
||||||
#include "yaml-cpp/binary.h"
|
#include "yaml-cpp/binary.h"
|
||||||
|
#include <exception>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <kubecontrol/KubePod.hpp>
|
#include <kubecontrol/KubePod.hpp>
|
||||||
@@ -170,7 +173,7 @@ namespace kubecontrol
|
|||||||
node["spec"]["containers"][0]["command"].push_back(PodCommand_);
|
node["spec"]["containers"][0]["command"].push_back(PodCommand_);
|
||||||
}
|
}
|
||||||
|
|
||||||
node["spec"]["terminationGracePeriodSeconds"] = 3;
|
node["spec"]["terminationGracePeriodSeconds"] = 10;
|
||||||
|
|
||||||
node["spec"]["restartPolicy"] = "Never";
|
node["spec"]["restartPolicy"] = "Never";
|
||||||
|
|
||||||
@@ -185,62 +188,43 @@ namespace kubecontrol
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string KubePod::start(std::string apiAddress,std::string token)
|
|
||||||
|
|
||||||
|
std::string KubePod::start(KubernetesAPI APIInterface,bool WaitTillRunning)
|
||||||
{
|
{
|
||||||
std::string curlURL = apiAddress;
|
std::string request = "/api/v1/namespaces/simulator/pods/";
|
||||||
std::string AuthString = "Authorization: Bearer " + token;
|
|
||||||
|
|
||||||
std::list<std::string> headers;
|
|
||||||
headers.push_back(AuthString);
|
|
||||||
headers.push_back("Content-Type: application/yaml");
|
|
||||||
|
|
||||||
|
|
||||||
curlpp::Cleanup cleaner;
|
|
||||||
curlpp::Easy request;
|
|
||||||
|
|
||||||
std::stringstream result;
|
|
||||||
request.setOpt(cURLpp::Options::WriteStream(&result));
|
|
||||||
|
|
||||||
request.setOpt(new curlpp::options::HttpHeader(headers));
|
|
||||||
|
|
||||||
request.setOpt(new curlpp::options::Url(curlURL));
|
|
||||||
|
|
||||||
request.setOpt(new curlpp::options::SslVerifyPeer(false));
|
|
||||||
|
|
||||||
// request.setOpt(new curlpp::options::Post(true));
|
|
||||||
request.setOpt(new curlpp::options::CustomRequest("POST"));
|
|
||||||
// request.setOpt(new curlpp::options::Verbose("POST"));
|
|
||||||
|
|
||||||
this->createYAML();
|
this->createYAML();
|
||||||
|
|
||||||
LOG_S(INFO)<< this->PathToYaml_;
|
// LOG_S(INFO)<< this->PathToYaml_;
|
||||||
|
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
stream << YAMLNode_;
|
stream << YAMLNode_;
|
||||||
// request.setOpt(new curlpp::options::PostFields(buffer));
|
std::string response = APIInterface.performRequest(request,"POST",stream.str());
|
||||||
request.setOpt(new curlpp::options::PostFields(stream.str()));
|
|
||||||
|
|
||||||
|
|
||||||
request.perform();
|
|
||||||
|
|
||||||
request.reset();
|
|
||||||
std::string response = result.str();
|
|
||||||
InfoPod.update(response);
|
InfoPod.update(response);
|
||||||
while (InfoPod.Status != "Running" && InfoPod.Status != "Succeeded") {
|
if (WaitTillRunning == true) {
|
||||||
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
while (InfoPod.Status != "Running" && InfoPod.Status != "Succeeded") {
|
||||||
response = this->getInfo(curlURL, token);
|
|
||||||
|
|
||||||
InfoPod.update(response);
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
response = this->getInfoForThisPod(APIInterface);
|
||||||
|
|
||||||
|
InfoPod.update(response);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string KubePod::stop(std::string apiAddress,std::string token)
|
std::string KubePod::stop(std::string apiAddress,std::string token)
|
||||||
{
|
{
|
||||||
std::string curlURL = apiAddress+ this->Uuid_;
|
std::string curlURL = apiAddress+ this->Uuid_;
|
||||||
|
LOG_S(INFO)<<curlURL;
|
||||||
|
|
||||||
std::string AuthString = "Authorization: Bearer " + token;
|
std::string AuthString = "Authorization: Bearer " + token;
|
||||||
|
|
||||||
std::list<std::string> headers;
|
std::list<std::string> headers;
|
||||||
@@ -267,12 +251,20 @@ namespace kubecontrol
|
|||||||
request.perform();
|
request.perform();
|
||||||
auto response = result.str();
|
auto response = result.str();
|
||||||
|
|
||||||
LOG_S(INFO)<<InfoPod.getRelatedPods().size();
|
|
||||||
|
// std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
||||||
|
|
||||||
|
|
||||||
|
// InfoPod.update(this->getInfo(apiAddress, token));
|
||||||
|
|
||||||
|
LOG_S(INFO)<<"Related pods: " <<InfoPod.getRelatedPods().size();
|
||||||
|
|
||||||
|
|
||||||
if (InfoPod.getRelatedPods().size() > 0)
|
if (InfoPod.getRelatedPods().size() > 0)
|
||||||
{
|
{
|
||||||
for(int i = 0; i<InfoPod.getRelatedPods().size(); i++)
|
for(int i = 0; i<InfoPod.getRelatedPods().size(); i++)
|
||||||
{
|
{
|
||||||
StopChilds(apiAddress, token, InfoPod.getRelatedPods()[i]);
|
StopChilds(apiAddress, token, InfoPod.getRelatedPods()[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,6 +273,19 @@ namespace kubecontrol
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string KubePod::stop(KubernetesAPI APIInterface)
|
||||||
|
{
|
||||||
|
std::string request = "/api/v1/namespaces/simulator/pods/"+Uuid_;
|
||||||
|
std::string result = APIInterface.performRequest(request,"DELETE");
|
||||||
|
|
||||||
|
|
||||||
|
this->getInfoForRelatedPods(APIInterface);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string KubePod::StopChilds(std::string apiAddress,std::string token,std::string uuid)
|
std::string KubePod::StopChilds(std::string apiAddress,std::string token,std::string uuid)
|
||||||
{
|
{
|
||||||
std::string curlURL = apiAddress+ uuid;
|
std::string curlURL = apiAddress+ uuid;
|
||||||
@@ -316,34 +321,88 @@ namespace kubecontrol
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string KubePod::getInfo(std::string apiAddress,std::string token)
|
// std::string KubePod::getInfo(std::string apiAddress,std::string token)
|
||||||
|
// {
|
||||||
|
// std::string curlURL = apiAddress+Uuid_+"/"+"status";
|
||||||
|
// std::string AuthString = "Authorization: Bearer " + token;
|
||||||
|
|
||||||
|
// std::list<std::string> headers;
|
||||||
|
// headers.push_back(AuthString);
|
||||||
|
|
||||||
|
|
||||||
|
// curlpp::Cleanup cleaner;
|
||||||
|
// curlpp::Easy request;
|
||||||
|
|
||||||
|
// std::stringstream result;
|
||||||
|
// request.setOpt(cURLpp::Options::WriteStream(&result));
|
||||||
|
|
||||||
|
|
||||||
|
// request.setOpt(new curlpp::options::HttpHeader(headers));
|
||||||
|
|
||||||
|
// request.setOpt(new curlpp::options::Url(curlURL));
|
||||||
|
|
||||||
|
// request.setOpt(new curlpp::options::SslVerifyPeer(false));
|
||||||
|
|
||||||
|
|
||||||
|
// request.perform();
|
||||||
|
// return result.str();
|
||||||
|
// }
|
||||||
|
|
||||||
|
std::string KubePod::getInfoForThisPod(KubernetesAPI APIInterface)
|
||||||
{
|
{
|
||||||
std::string curlURL = apiAddress+Uuid_+"/"+"status";
|
std::string request = "/api/v1/namespaces/simulator/pods/"+Uuid_+"/status";
|
||||||
std::string AuthString = "Authorization: Bearer " + token;
|
std::string result = APIInterface.performRequest(request,"GET");
|
||||||
|
|
||||||
std::list<std::string> headers;
|
return result;
|
||||||
headers.push_back(AuthString);
|
|
||||||
|
|
||||||
|
|
||||||
curlpp::Cleanup cleaner;
|
|
||||||
curlpp::Easy request;
|
|
||||||
|
|
||||||
std::stringstream result;
|
|
||||||
request.setOpt(cURLpp::Options::WriteStream(&result));
|
|
||||||
|
|
||||||
|
|
||||||
request.setOpt(new curlpp::options::HttpHeader(headers));
|
|
||||||
|
|
||||||
request.setOpt(new curlpp::options::Url(curlURL));
|
|
||||||
|
|
||||||
request.setOpt(new curlpp::options::SslVerifyPeer(false));
|
|
||||||
|
|
||||||
|
|
||||||
request.perform();
|
|
||||||
return result.str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string KubePod::getInfoForRelatedPods( KubernetesAPI APIInterface)
|
||||||
|
{
|
||||||
|
// std::string curlURL = apiAddress+"?labelSelector=app.kubernetes.io/part-of="+Uuid_;
|
||||||
|
std::string request = "/api/v1/namespaces/simulator/pods?labelSelector=app.kubernetes.io/part-of="+Uuid_;
|
||||||
|
std::string result = APIInterface.performRequest(request,"GET");
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<std::string> KubePod::getUUIDForRelatedPods(KubernetesAPI APIInterface)
|
||||||
|
{
|
||||||
|
std::vector<std::string> uuids;
|
||||||
|
|
||||||
|
auto rawResponse = getInfoForRelatedPods(APIInterface);
|
||||||
|
|
||||||
|
if (rawResponse == "")
|
||||||
|
{
|
||||||
|
return uuids;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
nlohmann::json j = nlohmann::json::parse(rawResponse);
|
||||||
|
if (j.contains("items") && j["items"].is_array())
|
||||||
|
{
|
||||||
|
for (auto i : j["items"])
|
||||||
|
{
|
||||||
|
uuids.push_back(i["metadata"]["name"].get<std::string>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (const std::exception e) {
|
||||||
|
LOG_S(ERROR)<< "Exeption in getUUIDForRelatedPods() :" << e.what();
|
||||||
|
}
|
||||||
|
|
||||||
|
// LOG_S(INFO)<<rawResponse;
|
||||||
|
|
||||||
|
return uuids;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
142
src/kubecontrol/KubernetesAPI.cpp
Normal file
142
src/kubecontrol/KubernetesAPI.cpp
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
#include <curlpp/Easy.hpp>
|
||||||
|
#include <curlpp/cURLpp.hpp>
|
||||||
|
#include <exception>
|
||||||
|
#include <kubecontrol/KubernetesAPI.hpp>
|
||||||
|
#include <list>
|
||||||
|
#include <curlpp/Options.hpp>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include <loguru.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace kubecontrol {
|
||||||
|
|
||||||
|
KubernetesAPI::KubernetesAPI()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
KubernetesAPI::KubernetesAPI(YAML::Node config)
|
||||||
|
{
|
||||||
|
addYaml(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
KubernetesAPI::KubernetesAPI(std::string APIAddress, std::string Token)
|
||||||
|
:APIAddress_(APIAddress), Token_(Token)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void KubernetesAPI::addAddress(std::string address)
|
||||||
|
{
|
||||||
|
APIAddress_ = address;
|
||||||
|
}
|
||||||
|
void KubernetesAPI::addToken(std::string token)
|
||||||
|
{
|
||||||
|
Token_ = token;
|
||||||
|
}
|
||||||
|
void KubernetesAPI::addYaml(YAML::Node config)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
|
||||||
|
Token_ = config["users"][0]["user"]["token"].as<std::string>();
|
||||||
|
Namespace_ = config["contexts"][0]["context"]["namespace"].as<std::string>();
|
||||||
|
|
||||||
|
char * KUBERNETES_SERVICE_HOST = std::getenv("KUBERNETES_SERVICE_HOST");
|
||||||
|
char * KUBERNETES_SERVICE_PORT = std::getenv("KUBERNETES_SERVICE_PORT");
|
||||||
|
|
||||||
|
if (KUBERNETES_SERVICE_HOST != nullptr && KUBERNETES_SERVICE_PORT!= nullptr)
|
||||||
|
{
|
||||||
|
APIAddress_ = "https://" +std::string(KUBERNETES_SERVICE_HOST)+":"+std::string(KUBERNETES_SERVICE_PORT);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
LOG_S(INFO)<<"Taking Serveraddress out of the provided YAML file";
|
||||||
|
|
||||||
|
APIAddress_ = config["clusters"][0]["cluster"]["server"].as<std::string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
LOG_S(ERROR)<< e.what();
|
||||||
|
throw e.what();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string KubernetesAPI::performRequest(std::string request,std::string Methode )
|
||||||
|
{
|
||||||
|
std::stringstream result;
|
||||||
|
|
||||||
|
std::string curlURL = APIAddress_+request;
|
||||||
|
std::string AuthString = "Authorization: Bearer " + Token_;
|
||||||
|
|
||||||
|
std::list<std::string> headers;
|
||||||
|
headers.push_back(AuthString);
|
||||||
|
|
||||||
|
|
||||||
|
curlpp::Cleanup cleaner;
|
||||||
|
curlpp::Easy curlRequest;
|
||||||
|
|
||||||
|
curlRequest.setOpt(cURLpp::Options::WriteStream(&result));
|
||||||
|
|
||||||
|
|
||||||
|
curlRequest.setOpt(new curlpp::options::HttpHeader(headers));
|
||||||
|
|
||||||
|
curlRequest.setOpt(new curlpp::options::Url(curlURL));
|
||||||
|
|
||||||
|
curlRequest.setOpt(new curlpp::options::SslVerifyPeer(false));
|
||||||
|
curlRequest.setOpt(new curlpp::options::CustomRequest(Methode));
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
curlRequest.perform();
|
||||||
|
|
||||||
|
} catch (const std::exception e) {
|
||||||
|
LOG_S(ERROR)<<e.what();
|
||||||
|
}
|
||||||
|
curlRequest.reset();
|
||||||
|
return result.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string KubernetesAPI::performRequest(std::string request,std::string Methode,std::string PostFields)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
std::string curlURL = APIAddress_+request;;
|
||||||
|
std::string AuthString = "Authorization: Bearer " + Token_;
|
||||||
|
|
||||||
|
std::list<std::string> headers;
|
||||||
|
headers.push_back(AuthString);
|
||||||
|
headers.push_back("Content-Type: application/yaml");
|
||||||
|
|
||||||
|
|
||||||
|
curlpp::Cleanup cleaner;
|
||||||
|
curlpp::Easy curlRequest;
|
||||||
|
|
||||||
|
std::stringstream result;
|
||||||
|
curlRequest.setOpt(cURLpp::Options::WriteStream(&result));
|
||||||
|
|
||||||
|
curlRequest.setOpt(new curlpp::options::HttpHeader(headers));
|
||||||
|
|
||||||
|
curlRequest.setOpt(new curlpp::options::Url(curlURL));
|
||||||
|
|
||||||
|
curlRequest.setOpt(new curlpp::options::SslVerifyPeer(false));
|
||||||
|
|
||||||
|
curlRequest.setOpt(new curlpp::options::CustomRequest("POST"));
|
||||||
|
|
||||||
|
curlRequest.setOpt(new curlpp::options::PostFields(PostFields));
|
||||||
|
|
||||||
|
|
||||||
|
curlRequest.perform();
|
||||||
|
|
||||||
|
curlRequest.reset();
|
||||||
|
|
||||||
|
|
||||||
|
return result.str();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
|
|
||||||
#include "curlpp/Options.hpp"
|
#include "curlpp/Options.hpp"
|
||||||
|
#include "kubecontrol/KubePod.hpp"
|
||||||
|
#include "kubecontrol/KubernetesAPI.hpp"
|
||||||
#include "kubecontrol/PodInfo.hpp"
|
#include "kubecontrol/PodInfo.hpp"
|
||||||
#include "nlohmann/json_fwd.hpp"
|
#include "nlohmann/json_fwd.hpp"
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
@@ -8,13 +10,15 @@
|
|||||||
#include <kubecontrol/PodController.hpp>
|
#include <kubecontrol/PodController.hpp>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
namespace kubecontrol
|
namespace kubecontrol
|
||||||
{
|
{
|
||||||
PodController::PodController(std::string pathToKubectlConfig)
|
PodController::PodController(std::string pathToKubectlConfig):
|
||||||
|
APIInterface_( YAML::LoadFile(pathToKubectlConfig))
|
||||||
{
|
{
|
||||||
LOG_S(INFO)<< "Path To Yaml: " <<pathToKubectlConfig;
|
LOG_S(INFO)<< "Path To Yaml: " <<pathToKubectlConfig;
|
||||||
|
|
||||||
@@ -37,10 +41,11 @@ namespace kubecontrol
|
|||||||
ServerAddress_ = config["clusters"][0]["cluster"]["server"].as<std::string>();
|
ServerAddress_ = config["clusters"][0]["cluster"]["server"].as<std::string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ApiCall_ = "/api/v1/namespaces/"+Namespace_+"/pods/";
|
ApiCall_ = "/api/v1/namespaces/"+Namespace_+"/pods/";
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
LOG_S(ERROR)<< e.what();
|
LOG_S(ERROR)<< e.what();
|
||||||
throw e.what();
|
throw e.what();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,22 +56,32 @@ namespace kubecontrol
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PodController::startPod(KubePod Pod)
|
void PodController::startPod(KubePod Pod,bool WaitTillRunning )
|
||||||
{
|
{
|
||||||
PodList_.emplace_back(Pod);
|
|
||||||
LOG_S(INFO)<< "starting pod: "<<Pod.getUUID();
|
|
||||||
auto response = Pod.start(ServerAddress_+ApiCall_, BearerToken_);
|
|
||||||
|
|
||||||
|
LOG_S(INFO)<< "starting pod: "<<Pod.getUUID();
|
||||||
|
// auto response = Pod.start(ServerAddress_+ApiCall_, BearerToken_,WaitTillRunning);
|
||||||
|
auto response = Pod.start(APIInterface_,WaitTillRunning);
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex>lock(mx_);
|
||||||
|
PodList_.emplace_back(Pod);
|
||||||
// LOG_S(INFO)<<response;
|
// LOG_S(INFO)<<response;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PodController::stopPod(std::string Label)
|
void PodController::stopPod(std::string Label)
|
||||||
{
|
{
|
||||||
for (auto item : PodList_)
|
std::lock_guard<std::mutex>lock(mx_);
|
||||||
|
// PodList_
|
||||||
|
for (std::vector<KubePod>::iterator it = PodList_.begin(); it != PodList_.end();)
|
||||||
{
|
{
|
||||||
if (Label == item.getUUID())
|
if (Label == it->getUUID())
|
||||||
{
|
{
|
||||||
item.stop(ServerAddress_+ApiCall_, BearerToken_);
|
it->stop(APIInterface_);
|
||||||
|
it = PodList_.erase(it);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
it++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,30 +89,34 @@ namespace kubecontrol
|
|||||||
|
|
||||||
void PodController::stopAllPods()
|
void PodController::stopAllPods()
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::mutex>lock(mx_);
|
||||||
|
|
||||||
checkPodsHierarchy();
|
checkPodsHierarchy();
|
||||||
|
|
||||||
for (auto item : PodList_)
|
for (auto item : PodList_)
|
||||||
{
|
{
|
||||||
LOG_S(INFO)<<item.InfoPod.Uuid;
|
LOG_S(INFO)<<item.InfoPod.Uuid;
|
||||||
item.InfoPod = *getPodInfo(item.getUUID()).get();
|
item.InfoPod = *getPodInfo(item.getUUID()).get();
|
||||||
item.stop(ServerAddress_+ApiCall_, BearerToken_);
|
|
||||||
|
item.stop(APIInterface_);
|
||||||
|
|
||||||
LOG_S(INFO)<< "stopping pod: "<<item.getUUID();
|
LOG_S(INFO)<< "stopping pod: "<<item.getUUID();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string PodController::getInfoForOwnPod()
|
// std::string PodController::getInfoForOwnPod()
|
||||||
{
|
// {
|
||||||
std::string response = "";
|
// std::string response = "";
|
||||||
for (auto item : PodList_)
|
// for (auto item : PodList_)
|
||||||
{
|
// {
|
||||||
|
|
||||||
response = item.getInfo(ServerAddress_+ApiCall_, BearerToken_);
|
// response = item.getInfoForThisPod(APIInterface_);
|
||||||
}
|
// }
|
||||||
|
|
||||||
return response;
|
// return response;
|
||||||
}
|
// }
|
||||||
|
|
||||||
std::string PodController::getPodsInfo()
|
std::string PodController::getInfoForAllPods()
|
||||||
{
|
{
|
||||||
|
|
||||||
std::string curlURL = ServerAddress_+ApiCall_;
|
std::string curlURL = ServerAddress_+ApiCall_;
|
||||||
@@ -155,11 +174,13 @@ namespace kubecontrol
|
|||||||
if (uid == item.getUUID())
|
if (uid == item.getUUID())
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
checkPodsHierarchy();
|
// checkPodsHierarchy();
|
||||||
item.InfoPod = *getPodInfo(item.getUUID()).get();
|
item.InfoPod = *getPodInfo(item.getUUID()).get();
|
||||||
// LOG_S(INFO)<<item.InfoPod.getRelatedPods().size();
|
// LOG_S(INFO)<<item.InfoPod.getRelatedPods().size();
|
||||||
|
item.getInfoForRelatedPods(APIInterface_);
|
||||||
|
|
||||||
return item.getInfo(ServerAddress_+ApiCall_, BearerToken_);
|
// return item.getInfo(ServerAddress_+ApiCall_, BearerToken_);
|
||||||
|
return item.getInfoForThisPod(APIInterface_);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -175,7 +196,7 @@ namespace kubecontrol
|
|||||||
|
|
||||||
void PodController::checkPodsHierarchy()
|
void PodController::checkPodsHierarchy()
|
||||||
{
|
{
|
||||||
auto response = this->getPodsInfo();
|
auto response = this->getInfoForAllPods();
|
||||||
|
|
||||||
nlohmann::json j;
|
nlohmann::json j;
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -84,6 +84,11 @@ namespace kubecontrol
|
|||||||
j["Ip"] = Ip;
|
j["Ip"] = Ip;
|
||||||
j["Status"] = Status;
|
j["Status"] = Status;
|
||||||
j["Part-Of"] = PartOf;
|
j["Part-Of"] = PartOf;
|
||||||
|
j["Related-Pods"] ;
|
||||||
|
for (auto i : this->relatedPods ) {
|
||||||
|
j["Related-Pods"].push_back(i);
|
||||||
|
}
|
||||||
|
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include "kubecontrol/KubernetesAPI.hpp"
|
||||||
#define CATCH_CONFIG_MAIN
|
#define CATCH_CONFIG_MAIN
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <catch2/catch.hpp>
|
#include <catch2/catch.hpp>
|
||||||
@@ -12,21 +13,41 @@ SCENARIO("Testing the SimCore Sensor")
|
|||||||
GIVEN("different Attributes for a Track in different forms")
|
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 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";
|
// 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();
|
auto guid = xg::newGuid();
|
||||||
std::string uuid = guid.str();
|
std::string uuid = guid.str();
|
||||||
// int random = rand() % 100 + 1;
|
// int random = rand() % 100 + 1;
|
||||||
|
|
||||||
// std::string uuid = "random" + std::to_string(random);
|
// std::string uuid = "random" + std::to_string(random);
|
||||||
|
|
||||||
kubecontrol::KubePod pod1("debug-debian",uuid,"debugdebianhenry:0.1.3");
|
kubecontrol::KubePod pod1("controller",uuid,"ship","ship:latest","simulator");
|
||||||
pod1.setEnvironmentVar("OWN_SHIP_SERVER", "127.0.0.1");
|
nlohmann::json vars;
|
||||||
LOG_S(INFO)<<pod1.createYAML();
|
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);
|
||||||
|
|
||||||
LOG_S(INFO)<<pod1.start(api,token);
|
vars["ENTITY_SENSORS"].push_back("radar:latest");
|
||||||
LOG_S(INFO)<< pod1.getInfo(api, token);
|
pod1.setEnvironmentVar("CONFIG", vars.dump());
|
||||||
pod1.stop(api,token);
|
|
||||||
|
// 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")
|
WHEN("constructing Track Object with data")
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,17 +3,20 @@
|
|||||||
|
|
||||||
#include "kubecontrol/KubePod.hpp"
|
#include "kubecontrol/KubePod.hpp"
|
||||||
#include "nlohmann/json_fwd.hpp"
|
#include "nlohmann/json_fwd.hpp"
|
||||||
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <vector>
|
||||||
|
#include <future>
|
||||||
|
|
||||||
#define CATCH_CONFIG_MAIN
|
#define CATCH_CONFIG_MAIN
|
||||||
#include <catch2/catch.hpp>
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
#include <kubecontrol/PodController.hpp>
|
#include <kubecontrol/PodController.hpp>
|
||||||
#include <crossguid/guid.hpp>
|
#include <crossguid/guid.hpp>
|
||||||
|
|
||||||
void startShip(kubecontrol::PodController* podc,std::string Name, std::string lat, std::string lon)
|
void startShip(kubecontrol::PodController* podc,std::string uuid,std::string Name, std::string lat, std::string lon)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::string uuid = xg::newGuid().str();
|
|
||||||
kubecontrol::KubePod ShipPod1("controller",uuid,"ship","ship:latest","simulator");
|
kubecontrol::KubePod ShipPod1("controller",uuid,"ship","ship:latest","simulator");
|
||||||
|
|
||||||
nlohmann::json vars;
|
nlohmann::json vars;
|
||||||
@@ -36,14 +39,14 @@ std::string uuid = xg::newGuid().str();
|
|||||||
podc->startPod(ShipPod1);
|
podc->startPod(ShipPod1);
|
||||||
|
|
||||||
}
|
}
|
||||||
void createScenario(kubecontrol::PodController* podc)
|
void createScenario(kubecontrol::PodController* podc,std::vector<std::string> *uuidList)
|
||||||
{
|
{
|
||||||
// GeographicLib::Geodesic geod(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f());
|
// GeographicLib::Geodesic geod(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f());
|
||||||
double lat = 54, lon = 1;
|
double lat = 54, lon = 1;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
double distance = 10000;
|
double distance = 10000;
|
||||||
|
|
||||||
int rasterSize = 2;
|
int rasterSize = 5;
|
||||||
|
|
||||||
for (int i = 0; i < rasterSize; i++ )
|
for (int i = 0; i < rasterSize; i++ )
|
||||||
{
|
{
|
||||||
@@ -58,8 +61,10 @@ void createScenario(kubecontrol::PodController* podc)
|
|||||||
lat2= lat+10;
|
lat2= lat+10;
|
||||||
// SimCore::Identifier id;
|
// SimCore::Identifier id;
|
||||||
// ids->push_back(id.getUUID());
|
// ids->push_back(id.getUUID());
|
||||||
|
std::string uuid = xg::newGuid().str();
|
||||||
startShip( podc,name, std::to_string(lat2), std::to_string(lon2));
|
uuidList->push_back(uuid);
|
||||||
|
// startShip( podc,uuid,name, std::to_string(lat2), std::to_string(lon2));
|
||||||
|
auto retrurn = std::async(std::launch::async, &startShip,podc,uuid,name, std::to_string(lat2), std::to_string(lon2));
|
||||||
|
|
||||||
// SimCore::Position pos;
|
// SimCore::Position pos;
|
||||||
// pos.setGeodesicPos(lat2, lon2, 0);
|
// pos.setGeodesicPos(lat2, lon2, 0);
|
||||||
@@ -86,13 +91,24 @@ SCENARIO("Testing the SimCore Sensor")
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
kubecontrol::PodController podc("docs/config");
|
// kubecontrol::PodController podc("docs/config");
|
||||||
|
auto podc = new kubecontrol::PodController("docs/config");
|
||||||
|
std::vector<std::string> uuidList;
|
||||||
|
|
||||||
createScenario(&podc);
|
createScenario(podc, &uuidList);
|
||||||
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
LOG_S(INFO)<<"Amount Parent Pods: " << uuidList.size();
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(20000));
|
||||||
|
// podc.stopPod(std::string Label)
|
||||||
|
|
||||||
podc.stopAllPods();
|
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));
|
||||||
|
|
||||||
|
podc->stopAllPods();
|
||||||
|
|
||||||
GIVEN("different Attributes for a Track in different forms")
|
GIVEN("different Attributes for a Track in different forms")
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "kubecontrol/PodController.hpp"
|
#include "kubecontrol/PodController.hpp"
|
||||||
#include "nlohmann/json_fwd.hpp"
|
#include "nlohmann/json_fwd.hpp"
|
||||||
|
#include <thread>
|
||||||
#define CATCH_CONFIG_MAIN
|
#define CATCH_CONFIG_MAIN
|
||||||
#include <catch2/catch.hpp>
|
#include <catch2/catch.hpp>
|
||||||
#include <kubecontrol/PodInfo.hpp>
|
#include <kubecontrol/PodInfo.hpp>
|
||||||
@@ -10,11 +11,52 @@
|
|||||||
|
|
||||||
SCENARIO("Testing the SimCore Sensor")
|
SCENARIO("Testing the SimCore Sensor")
|
||||||
{
|
{
|
||||||
kubecontrol::PodController podc("docs/config");
|
|
||||||
podc.checkPodsHierarchy();
|
|
||||||
auto tmp = podc.getInfoForPod("hamburg");
|
kubecontrol::PodController podc("docs/config");
|
||||||
LOG_S(INFO)<<tmp;
|
|
||||||
kubecontrol::PodInfo info(tmp);
|
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")
|
GIVEN("different Attributes for a Track in different forms")
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -42,22 +42,33 @@ std::string uuid = name;
|
|||||||
|
|
||||||
// kubecontrol::KubePod pod2("Pod2",xg::newGuid().str(),"debugdebianhenry:0.1.3");
|
// kubecontrol::KubePod pod2("Pod2",xg::newGuid().str(),"debugdebianhenry:0.1.3");
|
||||||
|
|
||||||
// pod1.setArgs("-c");
|
// pod2.setArgs("-c");
|
||||||
// pod1.setArgs("while true; do echo hello; sleep 5;done");
|
// pod2.setArgs("while true; do echo hello; sleep 5;done");
|
||||||
|
|
||||||
// pod1.setCommand("/bin/sh");
|
// pod2.setCommand("/bin/sh");
|
||||||
|
// podc.startPod(pod2);
|
||||||
|
|
||||||
|
LOG_S(INFO)<<"Starting";
|
||||||
|
|
||||||
podc.startPod(ShipPod1);
|
podc.startPod(ShipPod1);
|
||||||
// podc.startPod(pod2);
|
LOG_S(INFO)<<"started";
|
||||||
|
|
||||||
std::string info1 = "";
|
std::string info1 = "";
|
||||||
info1 = podc.getInfoForPod("hamburg");
|
// info1 = podc.getInfoForPod("hamburg");
|
||||||
nlohmann::json j1 = nlohmann::json::parse(info1);
|
// nlohmann::json j1 = nlohmann::json::parse(info1);
|
||||||
|
|
||||||
nlohmann::json jall = nlohmann::json::parse(podc.getPodsInfo());
|
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
|
||||||
|
|
||||||
podc.stopAllPods();
|
// podc.checkPodsHierarchy();
|
||||||
|
// LOG_S(INFO)<<podc.PodList_.size();;
|
||||||
|
// for(auto i: podc.PodList_)
|
||||||
|
// {
|
||||||
|
// LOG_S(INFO)<< i.InfoPod.Uuid;
|
||||||
|
// LOG_S(INFO)<< i.InfoPod.ToString();
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// nlohmann::json jall = nlohmann::json::parse(podc.getPodsInfo());
|
||||||
|
|
||||||
GIVEN("different Attributes for a Track in different forms")
|
GIVEN("different Attributes for a Track in different forms")
|
||||||
{
|
{
|
||||||
@@ -66,8 +77,11 @@ podc.stopAllPods();
|
|||||||
|
|
||||||
THEN("check if Track attributes are correct")
|
THEN("check if Track attributes are correct")
|
||||||
{
|
{
|
||||||
REQUIRE(true == true);
|
REQUIRE(podc.getListOfChildPods() == 1);
|
||||||
|
|
||||||
|
LOG_S(INFO)<<"Stopping";
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
||||||
|
podc.stopAllPods();
|
||||||
// REQUIRE(info1 != "");
|
// REQUIRE(info1 != "");
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user