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

170 lines
3.4 KiB
C++
Raw Normal View History

/** The super node object holding the state of the application.
*
* @file
2015-06-02 21:53:04 +02:00
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
2019-01-13 00:42:39 +01:00
* @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC
2017-04-27 12:56:43 +02:00
* @license GNU General Public License (version 3)
*
* VILLASnode
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
2017-04-27 12:56:43 +02:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
2017-04-27 12:56:43 +02:00
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2015-06-02 21:53:04 +02:00
*********************************************************************************/
2017-02-16 09:04:12 -03:00
#pragma once
#include <villas/list.h>
2018-10-20 14:20:06 +02:00
#include <villas/api.hpp>
#include <villas/web.hpp>
#include <villas/log.hpp>
2018-07-03 21:51:48 +02:00
#include <villas/node.h>
2018-10-20 14:20:06 +02:00
#include <villas/task.h>
#include <villas/common.h>
2017-02-18 10:31:42 -05:00
2018-07-03 21:51:48 +02:00
namespace villas {
namespace node {
2017-02-18 10:31:42 -05:00
/** Global configuration */
2018-07-03 21:51:48 +02:00
class SuperNode {
protected:
enum state state;
2019-02-12 15:07:50 +01:00
int idleStop;
2018-06-29 08:37:14 +02:00
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. */
2017-02-18 10:31:42 -05:00
2019-01-17 20:28:20 +01:00
Logger logger;
2018-10-20 14:20:06 +02:00
2019-01-07 10:28:55 +01:00
struct vlist nodes;
struct vlist paths;
struct vlist 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
2018-10-20 14:20:06 +02:00
struct task task; /**< Task for periodic stats output */
2017-08-05 21:02:09 +02:00
2018-10-20 14:20:06 +02:00
std::string name; /**< A name of this super node. Usually the hostname. */
std::string uri; /**< URI of configuration */
2017-02-18 10:31:42 -05:00
2018-07-03 21:51:48 +02:00
json_t *json; /**< JSON representation of the configuration. */
2018-07-03 21:51:48 +02:00
public:
/** Inititalize configuration object before parsing the configuration. */
SuperNode();
2016-02-04 16:27:14 +01:00
2018-07-03 21:51:48 +02:00
int init();
/** Wrapper for parse() */
void parseUri(const std::string &name);
2017-02-18 10:31:42 -05:00
2018-07-03 21:51:48 +02:00
/** Parse super-node configuration.
*
* @param cfg A libjansson object which contains the configuration.
*/
void parseJson(json_t *cfg);
2018-07-03 21:51:48 +02:00
/** Check validity of super node configuration. */
void check();
2017-03-06 08:59:28 -04:00
2018-07-03 21:51:48 +02: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 startPaths();
void startNodes();
void startNodeTypes();
void startInterfaces();
void stopPaths();
void stopNodes();
void stopNodeTypes();
void stopInterfaces();
2018-07-03 21:51:48 +02:00
/** Run periodic hooks of this super node. */
int periodic();
void setState(enum state st)
{
state = st;
}
2018-10-20 14:20:06 +02:00
struct node * getNode(const std::string &name)
{
2019-01-07 10:28:55 +01:00
return (struct node *) vlist_lookup(&nodes, name.c_str());
2018-10-20 14:20:06 +02:00
}
2019-01-07 10:28:55 +01:00
struct vlist * getNodes()
2018-10-20 14:20:06 +02:00
{
return &nodes;
}
2019-01-07 10:28:55 +01:00
struct vlist * getPaths() {
2018-10-20 14:20:06 +02:00
return &paths;
}
struct vlist * getInterfaces() {
return &interfaces;
}
enum state getState() {
return state;
}
2018-10-20 14:20:06 +02:00
#ifdef WITH_API
Api * getApi() {
return &api;
}
#endif
#ifdef WITH_WEB
Web * getWeb() {
return &web;
}
#endif
json_t * getConfig()
{
return json;
}
std::string getConfigUri()
{
return uri;
}
std::string getName()
{
return name;
}
/** Destroy configuration object. */
2018-07-03 21:51:48 +02:00
~SuperNode();
};
2018-07-03 21:51:48 +02:00
} // node
} // villas