Update to the new config format
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
34335045ca
commit
3f4588f44a
@ -0,0 +1,6 @@
|
||||
planificador
|
||||
===========
|
||||
|
||||
A sandbox execution environment for untrusted code. It acts as a front-end in front of Docker+Bubblewrap.
|
||||
|
||||
Tasks are submitted using a ZeroMQ message queue, allowing quick scaling of the system.
|
@ -1,12 +0,0 @@
|
||||
[serveurs]
|
||||
[serveurs.serveur1]
|
||||
ip = '100.000.000.000'
|
||||
nbContainerMax = 10
|
||||
|
||||
[serveurs.serveur2]
|
||||
ip = '200.000.000.000'
|
||||
nbContainerMax = 20
|
||||
|
||||
[serveurs.serveur3]
|
||||
ip = '300.000.000.000'
|
||||
nbContainerMax = 30
|
@ -0,0 +1,7 @@
|
||||
[queue]
|
||||
pull = "tcp://localhost:5557"
|
||||
push = "tcp://localhost:5558"
|
||||
threads = 1
|
||||
|
||||
[runner]
|
||||
timeout = 2
|
@ -1,29 +1,33 @@
|
||||
#include "config.hpp"
|
||||
|
||||
std::vector<sk::host> sk::config::loadHostsFromToml(const fs::path &confFile) {
|
||||
std::vector<sk::host> hosts;
|
||||
#include <iostream>
|
||||
#include <toml++/toml.h>
|
||||
|
||||
auto config = toml::parse_file(confFile.string());
|
||||
toml::table *serverSection = config.get_as<toml::table>("serveurs");
|
||||
if (serverSection == nullptr) {
|
||||
return hosts;
|
||||
}
|
||||
|
||||
// Parcourir les serveurs
|
||||
for (const auto &[serverNameKey, serverInfoValue] : *serverSection) {
|
||||
std::string serverName{serverNameKey};
|
||||
toml::table *serverInfoPtr = serverInfoValue.as_table();
|
||||
if (serverInfoPtr == nullptr) {
|
||||
}
|
||||
toml::table &serverInfo = *serverInfoPtr;
|
||||
|
||||
if (serverInfo.get_as<std::string>("ip") && serverInfo.get_as<int64_t>("nbContainerMax")) {
|
||||
std::string serverIp = serverInfo.get_as<std::string>("ip")->get();
|
||||
int serverMaxContainers = serverInfo.get_as<int64_t>("nbContainerMax")->get();
|
||||
static sk::config read(const toml::table &config) {
|
||||
return sk::config{
|
||||
sk::queue_config{
|
||||
config["queue"]["pull"].value_or("tcp://localhost:5557"),
|
||||
config["queue"]["push"].value_or("tcp://localhost:5558"),
|
||||
config["queue"]["threads"].value_or(1u),
|
||||
},
|
||||
sk::runner_config{
|
||||
config["runner"]["timeout"].value_or(2u),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
hosts.push_back(sk::host(serverIp, serverMaxContainers));
|
||||
sk::config sk::config::read_or_default(const std::filesystem::path &path, bool expect_present) {
|
||||
std::ifstream t(path);
|
||||
if (!t) {
|
||||
if (errno == ENOENT && !expect_present) {
|
||||
std::cout << "Using default config\n";
|
||||
} else {
|
||||
std::cerr << "Failed to open config file " << path << ": " << strerror(errno) << "\n";
|
||||
}
|
||||
return read(toml::table{});
|
||||
}
|
||||
|
||||
return hosts;
|
||||
std::stringstream buffer;
|
||||
buffer << t.rdbuf();
|
||||
auto config = toml::parse(buffer.str(), path);
|
||||
return read(config);
|
||||
}
|
||||
|
@ -1,15 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <toml++/toml.h>
|
||||
#include <vector>
|
||||
|
||||
#include "host.hpp"
|
||||
namespace fs = std::filesystem;
|
||||
#include <string>
|
||||
|
||||
namespace sk {
|
||||
class config {
|
||||
public:
|
||||
static std::vector<sk::host> loadHostsFromToml(const fs::path &confFile);
|
||||
struct queue_config {
|
||||
std::string pull_addr;
|
||||
std::string push_addr;
|
||||
unsigned int nb_threads;
|
||||
};
|
||||
|
||||
struct runner_config {
|
||||
unsigned int timeout;
|
||||
};
|
||||
|
||||
struct config {
|
||||
queue_config queue;
|
||||
runner_config runner;
|
||||
|
||||
static config read_or_default(const std::filesystem::path &path, bool expect_present = false);
|
||||
};
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
#include "host.hpp"
|
||||
|
||||
namespace sk {
|
||||
host::host(const std::string &ip, unsigned int connectionsMax) : ip{ip}, connections{0}, connectionsMax{connectionsMax}, runners{} {}
|
||||
|
||||
void host::addConnection(sk::runner &runner) {
|
||||
runners.push(&runner);
|
||||
connections += 1;
|
||||
}
|
||||
|
||||
const std::string &host::getIp() const { return ip; }
|
||||
|
||||
unsigned int host::getNbConnections() const { return connections; }
|
||||
|
||||
unsigned int host::getNbConnectionsMax() const { return connectionsMax; }
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "runner.hpp"
|
||||
#include <queue>
|
||||
#include <string>
|
||||
|
||||
namespace sk {
|
||||
class host {
|
||||
std::string ip;
|
||||
|
||||
unsigned int connections;
|
||||
unsigned int connectionsMax;
|
||||
|
||||
std::queue<sk::runner *> runners;
|
||||
|
||||
public:
|
||||
host(const std::string &ip, unsigned int connectionsMax);
|
||||
void addConnection(sk::runner &runner);
|
||||
|
||||
const std::string &getIp() const;
|
||||
|
||||
unsigned int getNbConnections() const;
|
||||
unsigned int getNbConnectionsMax() const;
|
||||
|
||||
bool operator<(const host &other) const { return (connectionsMax - connections) < other.getNbConnectionsMax() - other.getNbConnections(); }
|
||||
};
|
||||
}
|
Loading…
Reference in new issue