2017-08-03 00:19:27 +02:00
|
|
|
/* The super node object holding the state of the application.
|
2017-03-12 17:01:24 -03:00
|
|
|
*
|
2022-03-15 09:18:01 -04:00
|
|
|
* Author: Steffen Vogel <post@steffenvogel.de>
|
2022-03-15 09:28:57 -04:00
|
|
|
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
2022-07-04 18:20:03 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2017-03-12 17:01:24 -03:00
|
|
|
*/
|
|
|
|
|
2021-06-21 16:12:47 -04:00
|
|
|
#include <algorithm>
|
2019-06-23 16:57:00 +02:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
2017-03-12 17:01:24 -03:00
|
|
|
|
2019-03-26 07:01:10 +01:00
|
|
|
#include <villas/config_helper.hpp>
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <villas/hook_list.hpp>
|
|
|
|
#include <villas/kernel/if.hpp>
|
|
|
|
#include <villas/kernel/rt.hpp>
|
2018-10-20 14:20:06 +02:00
|
|
|
#include <villas/log.hpp>
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <villas/node.hpp>
|
2019-03-26 07:11:27 +01:00
|
|
|
#include <villas/node/exceptions.hpp>
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <villas/node/memory.hpp>
|
|
|
|
#include <villas/path.hpp>
|
|
|
|
#include <villas/super_node.hpp>
|
|
|
|
#include <villas/timing.hpp>
|
|
|
|
#include <villas/uuid.hpp>
|
2017-03-12 17:01:24 -03:00
|
|
|
|
2019-01-21 22:14:51 +01:00
|
|
|
#ifdef WITH_NETEM
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <villas/kernel/nl.hpp>
|
2019-01-21 22:14:51 +01:00
|
|
|
#endif
|
|
|
|
|
2018-10-20 14:20:06 +02:00
|
|
|
using namespace villas;
|
2018-07-03 21:51:48 +02:00
|
|
|
using namespace villas::node;
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
SuperNode::SuperNode()
|
|
|
|
: state(State::INITIALIZED), idleStop(-1),
|
2019-01-30 12:00:53 +01:00
|
|
|
#ifdef WITH_API
|
2023-09-07 11:46:39 +02:00
|
|
|
api(this),
|
2019-04-05 02:22:53 +02:00
|
|
|
#endif
|
2019-01-30 12:00:53 +01:00
|
|
|
#ifdef WITH_WEB
|
2023-09-07 11:46:39 +02:00
|
|
|
#ifdef WITH_API
|
|
|
|
web(&api),
|
|
|
|
#else
|
|
|
|
web(),
|
|
|
|
#endif
|
2019-01-30 12:00:53 +01:00
|
|
|
#endif
|
2023-09-07 11:46:39 +02:00
|
|
|
priority(0), affinity(0), hugepages(DEFAULT_NR_HUGEPAGES), statsRate(1.0),
|
|
|
|
task(CLOCK_REALTIME), started(time_now()) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
char hname[128];
|
|
|
|
ret = gethostname(hname, sizeof(hname));
|
|
|
|
if (ret)
|
|
|
|
throw SystemError("Failed to determine hostname");
|
|
|
|
|
|
|
|
// Default UUID is derived from hostname
|
|
|
|
uuid::generateFromString(uuid, hname);
|
2020-10-15 14:47:43 +02:00
|
|
|
|
2019-01-21 15:50:18 +01:00
|
|
|
#ifdef WITH_NETEM
|
2023-09-07 11:46:39 +02:00
|
|
|
kernel::nl::init(); // Fill link cache
|
|
|
|
#endif // WITH_NETEM
|
2019-01-21 15:50:18 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
logger = logging.get("super_node");
|
2017-03-12 17:01:24 -03:00
|
|
|
}
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void SuperNode::parse(const std::string &u) {
|
|
|
|
config.root = config.load(u);
|
2017-03-29 04:26:57 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
parse(config.root);
|
2017-03-12 17:01:24 -03:00
|
|
|
}
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void SuperNode::parse(json_t *root) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
assert(state == State::PARSED || state == State::INITIALIZED ||
|
|
|
|
state == State::CHECKED);
|
|
|
|
|
|
|
|
const char *uuid_str = nullptr;
|
|
|
|
|
|
|
|
json_t *json_nodes = nullptr;
|
|
|
|
json_t *json_paths = nullptr;
|
|
|
|
json_t *json_logging = nullptr;
|
|
|
|
json_t *json_http = nullptr;
|
|
|
|
|
|
|
|
json_error_t err;
|
|
|
|
|
|
|
|
idleStop = 1;
|
|
|
|
|
|
|
|
ret =
|
|
|
|
json_unpack_ex(root, &err, 0,
|
|
|
|
"{ s?: F, s?: o, s?: o, s?: o, s?: o, s?: i, s?: i, s?: "
|
|
|
|
"i, s?: b, s?: s }",
|
|
|
|
"stats", &statsRate, "http", &json_http, "logging",
|
|
|
|
&json_logging, "nodes", &json_nodes, "paths", &json_paths,
|
|
|
|
"hugepages", &hugepages, "affinity", &affinity, "priority",
|
|
|
|
&priority, "idle_stop", &idleStop, "uuid", &uuid_str);
|
|
|
|
if (ret)
|
|
|
|
throw ConfigError(root, err, "node-config",
|
|
|
|
"Unpacking top-level config failed");
|
|
|
|
|
|
|
|
if (uuid_str) {
|
|
|
|
ret = uuid_parse(uuid_str, uuid);
|
|
|
|
if (ret)
|
|
|
|
throw ConfigError(root, "node-config-uuid", "Failed to parse UUID: {}",
|
|
|
|
uuid_str);
|
|
|
|
}
|
2020-10-15 14:47:43 +02:00
|
|
|
|
2017-07-25 11:57:01 +02:00
|
|
|
#ifdef WITH_WEB
|
2023-09-07 11:46:39 +02:00
|
|
|
if (json_http)
|
|
|
|
web.parse(json_http);
|
2017-07-25 11:57:01 +02:00
|
|
|
#endif // WITH_WEB
|
2017-03-12 17:01:24 -03:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
if (json_logging)
|
|
|
|
logging.parse(json_logging);
|
|
|
|
|
|
|
|
// Parse nodes
|
|
|
|
if (json_nodes) {
|
|
|
|
if (!json_is_object(json_nodes))
|
|
|
|
throw ConfigError(
|
|
|
|
json_nodes, "node-config-nodes",
|
|
|
|
"Setting 'nodes' must be a group with node name => group mappings.");
|
|
|
|
|
|
|
|
const char *node_name;
|
|
|
|
json_t *json_node;
|
|
|
|
json_object_foreach(json_nodes, node_name, json_node) {
|
|
|
|
uuid_t node_uuid;
|
|
|
|
const char *node_type;
|
|
|
|
const char *node_uuid_str = nullptr;
|
|
|
|
|
|
|
|
ret = Node::isValidName(node_name);
|
|
|
|
if (!ret)
|
|
|
|
throw RuntimeError("Invalid name for node: {}", node_name);
|
|
|
|
|
|
|
|
ret = json_unpack_ex(json_node, &err, 0, "{ s: s, s?: s }", "type",
|
|
|
|
&node_type, "uuid", &node_uuid_str);
|
|
|
|
if (ret)
|
|
|
|
throw ConfigError(root, err, "node-config-node-type",
|
|
|
|
"Failed to parse type of node '{}'", node_name);
|
|
|
|
|
|
|
|
if (node_uuid_str) {
|
|
|
|
ret = uuid_parse(uuid_str, uuid);
|
|
|
|
if (ret)
|
|
|
|
throw ConfigError(json_node, "node-config-node-uuid",
|
|
|
|
"Failed to parse UUID: {}", uuid_str);
|
|
|
|
} else
|
|
|
|
// Generate UUID from node name and super-node UUID
|
|
|
|
uuid::generateFromString(node_uuid, node_name, uuid::toString(uuid));
|
|
|
|
|
|
|
|
auto *n = NodeFactory::make(node_type, node_uuid, node_name);
|
|
|
|
if (!n)
|
|
|
|
throw MemoryAllocationError();
|
|
|
|
|
|
|
|
ret = n->parse(json_node);
|
|
|
|
if (ret) {
|
|
|
|
auto config_id = fmt::format("node-config-node-{}", node_type);
|
|
|
|
throw ConfigError(json_node, config_id,
|
|
|
|
"Failed to parse configuration of node '{}'",
|
|
|
|
node_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
nodes.push_back(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse paths
|
|
|
|
if (json_paths) {
|
|
|
|
if (!json_is_array(json_paths))
|
|
|
|
logger->warn("Setting 'paths' must be a list of objects");
|
|
|
|
|
|
|
|
size_t i;
|
|
|
|
json_t *json_path;
|
|
|
|
json_array_foreach(json_paths, i, json_path) {
|
|
|
|
parse:
|
|
|
|
auto *p = new Path();
|
|
|
|
if (!p)
|
|
|
|
throw MemoryAllocationError();
|
|
|
|
|
|
|
|
p->parse(json_path, nodes, uuid);
|
|
|
|
|
|
|
|
paths.push_back(p);
|
|
|
|
|
|
|
|
if (p->isReversed()) {
|
|
|
|
// Only simple paths can be reversed
|
|
|
|
ret = p->isSimple();
|
|
|
|
if (!ret)
|
|
|
|
throw RuntimeError("Complex paths can not be reversed!");
|
|
|
|
|
|
|
|
// Parse a second time with in/out reversed
|
|
|
|
json_path = json_copy(json_path);
|
|
|
|
|
|
|
|
json_t *json_in = json_object_get(json_path, "in");
|
|
|
|
json_t *json_out = json_object_get(json_path, "out");
|
|
|
|
|
|
|
|
if (json_equal(json_in, json_out))
|
|
|
|
throw RuntimeError(
|
|
|
|
"Can not reverse path with identical in/out nodes!");
|
|
|
|
|
|
|
|
json_object_set(json_path, "reverse", json_false());
|
|
|
|
json_object_set(json_path, "in", json_out);
|
|
|
|
json_object_set(json_path, "out", json_in);
|
|
|
|
|
|
|
|
goto parse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
state = State::PARSED;
|
2017-03-12 17:01:24 -03:00
|
|
|
}
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void SuperNode::check() {
|
|
|
|
int ret;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
assert(state == State::INITIALIZED || state == State::PARSED ||
|
|
|
|
state == State::CHECKED);
|
2017-03-12 17:01:24 -03:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
for (auto *n : nodes) {
|
|
|
|
ret = n->check();
|
|
|
|
if (ret)
|
|
|
|
throw RuntimeError("Invalid configuration for node {}", n->getName());
|
|
|
|
}
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
for (auto *p : paths)
|
|
|
|
p->check();
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
state = State::CHECKED;
|
2017-03-12 17:01:24 -03:00
|
|
|
}
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void SuperNode::prepareNodeTypes() {
|
|
|
|
int ret;
|
2017-09-19 04:18:05 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
for (auto *n : nodes) {
|
|
|
|
auto *nf = n->getFactory();
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
if (nf->getState() == State::STARTED)
|
|
|
|
continue;
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
ret = nf->start(this);
|
|
|
|
if (ret)
|
|
|
|
throw RuntimeError("Failed to start node-type: {}",
|
|
|
|
n->getFactory()->getName());
|
|
|
|
}
|
2019-01-21 22:11:30 +01:00
|
|
|
}
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void SuperNode::startInterfaces() {
|
2019-01-21 15:44:39 +01:00
|
|
|
#ifdef WITH_NETEM
|
2023-09-07 11:46:39 +02:00
|
|
|
int ret;
|
2019-01-21 22:11:30 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
for (auto *i : interfaces) {
|
|
|
|
ret = i->start();
|
|
|
|
if (ret)
|
|
|
|
throw RuntimeError("Failed to start network interface: {}", i->getName());
|
|
|
|
}
|
2019-01-21 15:44:39 +01:00
|
|
|
#endif // WITH_NETEM
|
2019-01-21 22:11:30 +01:00
|
|
|
}
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void SuperNode::startNodes() {
|
|
|
|
int ret;
|
2019-01-21 15:44:39 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
for (auto *n : nodes) {
|
|
|
|
if (!n->isEnabled())
|
|
|
|
continue;
|
2018-08-20 18:31:27 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
ret = n->start();
|
|
|
|
if (ret)
|
|
|
|
throw RuntimeError("Failed to start node: {}", n->getName());
|
|
|
|
}
|
2019-01-21 22:11:30 +01:00
|
|
|
}
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void SuperNode::startPaths() {
|
|
|
|
for (auto *p : paths) {
|
|
|
|
if (!p->isEnabled())
|
|
|
|
continue;
|
2023-04-03 13:04:59 +00:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
p->start();
|
|
|
|
}
|
2019-02-24 11:13:28 +01:00
|
|
|
}
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void SuperNode::prepareNodes() {
|
|
|
|
int ret;
|
2019-02-24 11:13:28 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
for (auto *n : nodes) {
|
|
|
|
if (!n->isEnabled())
|
|
|
|
continue;
|
2019-02-24 11:13:28 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
ret = n->prepare();
|
|
|
|
if (ret)
|
|
|
|
throw RuntimeError("Failed to prepare node: {}", n->getName());
|
|
|
|
}
|
2019-02-24 11:13:28 +01:00
|
|
|
}
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void SuperNode::preparePaths() {
|
|
|
|
for (auto *p : paths) {
|
|
|
|
if (!p->isEnabled())
|
|
|
|
continue;
|
2023-04-03 13:04:59 +00:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
p->prepare(nodes);
|
|
|
|
}
|
2019-01-21 22:11:30 +01:00
|
|
|
}
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void SuperNode::prepare() {
|
|
|
|
int ret;
|
2019-02-11 16:32:39 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
assert(state == State::CHECKED);
|
2019-01-21 22:11:30 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
ret = memory::init(hugepages);
|
|
|
|
if (ret)
|
|
|
|
throw RuntimeError("Failed to initialize memory system");
|
2019-02-12 17:06:09 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
kernel::rt::init(priority, affinity);
|
2019-01-21 22:11:30 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
prepareNodeTypes();
|
|
|
|
prepareNodes();
|
|
|
|
preparePaths();
|
2019-03-09 00:32:22 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
for (auto *n : nodes) {
|
|
|
|
if (n->sources.size() == 0 && n->destinations.size() == 0) {
|
|
|
|
logger->info("Node {} is not used by any path. Disabling...",
|
|
|
|
n->getName());
|
|
|
|
n->setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
2020-09-10 17:35:35 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
state = State::PREPARED;
|
2019-03-09 00:32:22 +01:00
|
|
|
}
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void SuperNode::start() {
|
|
|
|
assert(state == State::PREPARED);
|
2019-03-09 00:32:22 +01:00
|
|
|
|
2019-01-21 22:11:30 +01:00
|
|
|
#ifdef WITH_API
|
2023-09-07 11:46:39 +02:00
|
|
|
api.start();
|
2019-01-21 22:11:30 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WITH_WEB
|
2023-09-07 11:46:39 +02:00
|
|
|
web.start();
|
2019-01-21 22:11:30 +01:00
|
|
|
#endif
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
startInterfaces();
|
|
|
|
startNodes();
|
|
|
|
startPaths();
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
if (statsRate > 0) // A rate <0 will disable the periodic stats
|
|
|
|
task.setRate(statsRate);
|
2018-10-20 14:20:06 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
Stats::printHeader(Stats::Format::HUMAN);
|
2018-10-20 14:20:06 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
state = State::STARTED;
|
2017-03-12 17:01:24 -03:00
|
|
|
}
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void SuperNode::stopPaths() {
|
|
|
|
for (auto *p : paths) {
|
|
|
|
if (p->getState() == State::STARTED || p->getState() == State::PAUSED)
|
|
|
|
p->stop();
|
|
|
|
}
|
2019-01-21 22:11:30 +01:00
|
|
|
}
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void SuperNode::stopNodes() {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
for (auto *n : nodes) {
|
|
|
|
if (n->getState() == State::STARTED || n->getState() == State::PAUSED ||
|
|
|
|
n->getState() == State::STOPPING) {
|
|
|
|
ret = n->stop();
|
|
|
|
if (ret)
|
|
|
|
throw RuntimeError("Failed to stop node: {}", n->getName());
|
|
|
|
}
|
|
|
|
}
|
2019-01-21 22:11:30 +01:00
|
|
|
}
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void SuperNode::stopNodeTypes() {
|
|
|
|
int ret;
|
2017-03-12 17:01:24 -03:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
for (auto *n : nodes) {
|
|
|
|
auto *nf = n->getFactory();
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
if (nf->getState() != State::STARTED)
|
|
|
|
continue;
|
2021-08-10 10:12:48 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
ret = nf->stop();
|
|
|
|
if (ret)
|
|
|
|
throw RuntimeError("Failed to stop node-type: {}",
|
|
|
|
n->getFactory()->getName());
|
|
|
|
}
|
2019-01-21 22:11:30 +01:00
|
|
|
}
|
2017-03-12 17:01:24 -03:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void SuperNode::stopInterfaces() {
|
2019-01-21 15:44:39 +01:00
|
|
|
#ifdef WITH_NETEM
|
2023-09-07 11:46:39 +02:00
|
|
|
int ret;
|
2019-01-21 22:11:30 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
for (auto *i : interfaces) {
|
|
|
|
ret = i->stop();
|
|
|
|
if (ret)
|
|
|
|
throw RuntimeError("Failed to stop interface: {}", i->getName());
|
|
|
|
}
|
2019-01-21 15:44:39 +01:00
|
|
|
#endif // WITH_NETEM
|
2019-01-21 22:11:30 +01:00
|
|
|
}
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void SuperNode::stop() {
|
|
|
|
stopNodes();
|
|
|
|
stopPaths();
|
|
|
|
stopNodeTypes();
|
|
|
|
stopInterfaces();
|
2019-01-21 15:44:39 +01:00
|
|
|
|
2017-07-25 11:57:01 +02:00
|
|
|
#ifdef WITH_API
|
2023-09-07 11:46:39 +02:00
|
|
|
api.stop();
|
2017-08-10 13:35:08 +02:00
|
|
|
#endif
|
2019-04-05 20:57:34 +02:00
|
|
|
|
2017-08-10 13:35:08 +02:00
|
|
|
#ifdef WITH_WEB
|
2023-09-07 11:46:39 +02:00
|
|
|
web.stop();
|
2017-07-25 11:57:01 +02:00
|
|
|
#endif
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
state = State::STOPPED;
|
2017-03-12 17:01:24 -03:00
|
|
|
}
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void SuperNode::run() {
|
|
|
|
int ret;
|
2019-02-11 16:33:14 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
while (state == State::STARTED) {
|
|
|
|
task.wait();
|
2019-02-11 16:33:14 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
ret = periodic();
|
|
|
|
if (ret)
|
|
|
|
state = State::STOPPING;
|
|
|
|
}
|
2018-07-03 21:51:48 +02:00
|
|
|
}
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
SuperNode::~SuperNode() {
|
|
|
|
assert(state == State::INITIALIZED || state == State::PARSED ||
|
|
|
|
state == State::CHECKED || state == State::STOPPED ||
|
|
|
|
state == State::PREPARED);
|
2020-09-10 11:11:42 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
for (auto *p : paths)
|
|
|
|
delete p;
|
2018-07-03 21:51:48 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
for (auto *n : nodes)
|
|
|
|
delete n;
|
2017-04-06 12:12:56 +02:00
|
|
|
}
|
2018-08-20 19:06:24 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
int SuperNode::periodic() {
|
|
|
|
int started = 0;
|
2019-02-11 16:39:30 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
for (auto *p : paths) {
|
|
|
|
if (p->getState() == State::STARTED) {
|
|
|
|
started++;
|
2018-08-20 19:06:24 +02:00
|
|
|
|
2019-02-11 16:39:30 +01:00
|
|
|
#ifdef WITH_HOOKS
|
2023-09-07 11:46:39 +02:00
|
|
|
p->hooks.periodic();
|
2019-02-11 16:39:30 +01:00
|
|
|
#endif // WITH_HOOKS
|
2023-09-07 11:46:39 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-20 19:06:24 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
for (auto *n : nodes) {
|
|
|
|
if (n->getState() == State::STARTED) {
|
2019-02-11 16:39:30 +01:00
|
|
|
#ifdef WITH_HOOKS
|
2023-09-07 11:46:39 +02:00
|
|
|
n->in.hooks.periodic();
|
|
|
|
n->out.hooks.periodic();
|
2019-02-11 16:39:30 +01:00
|
|
|
#endif // WITH_HOOKS
|
2023-09-07 11:46:39 +02:00
|
|
|
}
|
|
|
|
}
|
2019-02-11 16:39:30 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
if (idleStop > 0 && state == State::STARTED && started == 0) {
|
|
|
|
logger->info("No more active paths. Stopping super-node");
|
2019-02-11 16:39:30 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2019-02-11 16:39:30 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
return 0;
|
2018-08-20 19:06:24 +02:00
|
|
|
}
|
2019-06-30 14:46:55 +02:00
|
|
|
|
|
|
|
#ifdef WITH_GRAPHVIZ
|
2023-09-07 11:46:39 +02:00
|
|
|
static void set_attr(void *ptr, const std::string &key,
|
|
|
|
const std::string &value, bool html = false) {
|
|
|
|
Agraph_t *g = agraphof(ptr);
|
2020-10-20 22:11:08 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
char *d = (char *)"";
|
|
|
|
char *k = (char *)key.c_str();
|
|
|
|
char *v = (char *)value.c_str();
|
|
|
|
char *vd = html ? agstrdup_html(g, v) : agstrdup(g, v);
|
2020-10-20 22:11:08 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
agsafeset(ptr, k, vd, d);
|
2020-10-20 22:11:08 +02:00
|
|
|
}
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
graph_t *SuperNode::getGraph() {
|
|
|
|
Agraph_t *g;
|
|
|
|
Agnode_t *m;
|
2020-10-16 17:31:32 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
g = agopen((char *)"g", Agdirected, 0);
|
2020-10-16 17:31:32 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
std::map<Node *, Agnode_t *> nodeMap;
|
2020-10-20 22:11:08 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
for (auto *n : nodes) {
|
|
|
|
nodeMap[n] = agnode(g, (char *)n->getNameShort().c_str(), 1);
|
2020-10-16 17:31:32 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
set_attr(nodeMap[n], "shape", "ellipse");
|
|
|
|
set_attr(nodeMap[n], "tooltip",
|
|
|
|
fmt::format("type={}, uuid={}", n->getFactory()->getName(),
|
|
|
|
uuid::toString(n->getUuid()).c_str()));
|
|
|
|
// set_attr(nodeMap[n], "fixedsize", "true");
|
|
|
|
// set_attr(nodeMap[n], "width", "0.15");
|
|
|
|
// set_attr(nodeMap[n], "height", "0.15");
|
|
|
|
}
|
2020-10-16 17:31:32 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
unsigned i = 0;
|
|
|
|
for (auto *p : paths) {
|
|
|
|
auto name = fmt::format("path_{}", i++);
|
2020-10-16 17:31:32 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
m = agnode(g, (char *)name.c_str(), 1);
|
2020-10-20 22:11:08 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
set_attr(m, "shape", "box");
|
|
|
|
set_attr(m, "tooltip",
|
|
|
|
fmt::format("uuid={}", uuid::toString(p->getUuid()).c_str()));
|
2020-10-16 17:31:32 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
for (auto ps : p->sources)
|
|
|
|
agedge(g, nodeMap[ps->getNode()], m, nullptr, 1);
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
for (auto pd : p->destinations)
|
|
|
|
agedge(g, m, nodeMap[pd->getNode()], nullptr, 1);
|
|
|
|
}
|
2020-10-16 17:31:32 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
return g;
|
2019-06-30 14:46:55 +02:00
|
|
|
}
|
|
|
|
#endif // WITH_GRAPHVIZ
|