1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-16 00:00:02 +01:00
VILLASnode/include/villas/super_node.hpp

198 lines
3.2 KiB
C++
Raw Normal View History

/* The super node object holding the state of the application.
*
* Author: Steffen Vogel <post@steffenvogel.de>
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
* SPDX-License-Identifier: Apache-2.0
*/
2017-02-16 09:04:12 -03:00
#pragma once
#include <villas/node/config.hpp>
#ifdef WITH_GRAPHVIZ
2020-03-04 13:59:46 +01:00
extern "C" {
2021-02-19 06:38:38 +01:00
#include <graphviz/gvc.h>
2020-03-04 13:59:46 +01:00
}
#endif
#include <fstream>
2018-10-20 14:20:06 +02:00
#include <villas/api.hpp>
#include <villas/web.hpp>
#include <villas/log.hpp>
#include <villas/config_class.hpp>
#include <villas/node.hpp>
#include <villas/node_list.hpp>
#include <villas/path_list.hpp>
2020-03-04 13:07:20 +01:00
#include <villas/task.hpp>
#include <villas/common.hpp>
#include <villas/kernel/if.hpp>
2017-02-18 10:31:42 -05:00
2018-07-03 21:51:48 +02:00
namespace villas {
namespace node {
// Forward declarations
class Node;
// Global configuration
2018-07-03 21:51:48 +02:00
class SuperNode {
protected:
2019-06-23 16:13:23 +02:00
enum State state;
2019-02-12 15:07:50 +01:00
int idleStop;
2019-01-17 20:28:20 +01:00
Logger logger;
2018-10-20 14:20:06 +02:00
NodeList nodes;
PathList paths;
std::list<kernel::Interface *> interfaces;
2017-02-18 10:31:42 -05:00
2018-10-20 14:20:06 +02:00
#ifdef WITH_API
Api api;
#endif
#ifdef WITH_WEB
Web web;
#endif
int priority; // Process priority (lower is better)
int affinity; // Process affinity of the server and all created threads
int hugepages; // Number of hugepages to reserve.
double statsRate; // Rate at which we display the periodic stats.
struct Task task; // Task for periodic stats output
2017-08-05 21:02:09 +02:00
uuid_t uuid; // A globally unique identifier of the instance
2020-10-15 14:47:43 +02:00
struct timespec started; // The time at which the instance has been started.
2020-10-15 14:47:43 +02:00
std::string uri; // URI of configuration
2017-02-18 10:31:42 -05:00
Config config; // The configuration file.
2018-07-03 21:51:48 +02:00
public:
// Inititalize configuration object before parsing the configuration.
2018-07-03 21:51:48 +02:00
SuperNode();
2016-02-04 16:27:14 +01:00
2018-07-03 21:51:48 +02:00
int init();
// Wrapper for parse() which loads the config first.
void parse(const std::string &name);
2017-02-18 10:31:42 -05:00
/* Parse super-node configuration.
2018-07-03 21:51:48 +02:00
*
2021-02-16 14:15:14 +01:00
* @param json A libjansson object which contains the configuration.
2018-07-03 21:51:48 +02:00
*/
2021-02-16 14:15:14 +01:00
void parse(json_t *json);
// Check validity of super node configuration.
void check();
2017-03-06 08:59:28 -04:00
// Initialize after parsing the configuration file.
2019-02-24 11:13:28 +01:00
void prepare();
void start();
void stop();
2018-07-03 21:51:48 +02:00
void run();
2019-02-24 11:13:28 +01:00
void preparePaths();
void prepareNodes();
void prepareNodeTypes();
2019-02-24 11:13:28 +01:00
void startPaths();
void startNodes();
void startInterfaces();
void stopPaths();
void stopNodes();
void stopNodeTypes();
void stopInterfaces();
#ifdef WITH_GRAPHVIZ
graph_t * getGraph();
#endif
// Run periodic hooks of this super node.
2018-07-03 21:51:48 +02:00
int periodic();
2019-06-23 16:13:23 +02:00
void setState(enum State st)
{
state = st;
}
Node * getNode(const std::string &name)
2018-10-20 14:20:06 +02:00
{
return nodes.lookup(name);
2018-10-20 14:20:06 +02:00
}
NodeList & getNodes()
2018-10-20 14:20:06 +02:00
{
return nodes;
2018-10-20 14:20:06 +02:00
}
PathList & getPaths()
{
return paths;
2018-10-20 14:20:06 +02:00
}
std::list<kernel::Interface *> & getInterfaces()
{
return interfaces;
}
enum State getState() const
{
return state;
}
const uuid_t & getUuid() const
2020-10-15 14:47:43 +02:00
{
return uuid;
2020-10-15 14:47:43 +02:00
}
struct timespec getStartTime() const
{
return started;
}
2018-10-20 14:20:06 +02:00
#ifdef WITH_API
Api * getApi()
{
2018-10-20 14:20:06 +02:00
return &api;
}
#endif
#ifdef WITH_WEB
Web * getWeb()
{
2018-10-20 14:20:06 +02:00
return &web;
}
#endif
json_t * getConfig()
{
return config.root;
2018-10-20 14:20:06 +02:00
}
std::string getConfigUri() const
2018-10-20 14:20:06 +02:00
{
return uri;
}
int getAffinity() const
{
return affinity;
}
2021-02-16 14:15:14 +01:00
Logger getLogger()
{
return logger;
}
// Destroy configuration object.
2018-07-03 21:51:48 +02:00
~SuperNode();
};
} // namespace node
} // namespace villas