From 57f570d9b0c3778e09f786a6b750a0158e187b9a Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Tue, 25 Aug 2020 20:22:19 +0200 Subject: [PATCH] list: use new lookup methods --- common | 2 +- doc/openapi.yaml | 368 ++++++++++++------ include/villas/api/node_request.hpp | 32 ++ include/villas/api/request.hpp | 2 +- include/villas/path.h | 1 - include/villas/super_node.hpp | 2 +- lib/api/CMakeLists.txt | 14 +- lib/api/requests/node_action.cpp | 30 +- lib/api/requests/{file.cpp => node_file.cpp} | 0 .../requests/{stats.cpp => node_stats.cpp} | 19 +- .../{stats_reset.cpp => node_stats_reset.cpp} | 9 +- lib/api/requests/path_action.cpp | 22 +- lib/api/requests/restart.cpp | 2 +- lib/api/requests/shutdown.cpp | 2 +- lib/api/session.cpp | 4 +- lib/formats/json_reserve.cpp | 2 +- lib/hooks/average.cpp | 2 +- lib/hooks/cast.cpp | 2 +- lib/hooks/dp.cpp | 2 +- lib/hooks/gate.cpp | 2 +- lib/hooks/limit_value.cpp | 2 +- lib/hooks/scale.cpp | 2 +- lib/mapping.cpp | 6 +- lib/node.cpp | 4 +- lib/nodes/file.cpp | 1 + lib/nodes/ngsi.cpp | 2 +- lib/nodes/stats.cpp | 2 +- lib/nodes/websocket.cpp | 2 +- lib/path.cpp | 2 +- packaging/deps.sh | 2 +- tests/unit/mapping.cpp | 12 +- 31 files changed, 355 insertions(+), 201 deletions(-) create mode 100644 include/villas/api/node_request.hpp rename lib/api/requests/{file.cpp => node_file.cpp} (100%) rename lib/api/requests/{stats.cpp => node_stats.cpp} (84%) rename lib/api/requests/{stats_reset.cpp => node_stats_reset.cpp} (91%) diff --git a/common b/common index 88ebc1d67..7f356d91d 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 88ebc1d67c16809fec8975e0cadf002f91c61389 +Subproject commit 7f356d91d5fe81e91ec552583fb5b307ccaa723d diff --git a/doc/openapi.yaml b/doc/openapi.yaml index 62214c7b5..36fd41450 100644 --- a/doc/openapi.yaml +++ b/doc/openapi.yaml @@ -16,6 +16,8 @@ externalDocs: servers: - url: "https://villas-new.k8s.eonerc.rwth-aachen.de/api/v2" description: "The production API server in our EONERC OpenStack Kubernetes" + - url: "http://ernie.acs-lab.eonerc.rwth-aachen.de:8080/api/v2" + description: "VILLASnode lab instance in ACS laboratory" tags: - name: super-node description: Global super-node related operations. @@ -71,7 +73,47 @@ paths: examples: example1: value: - { test: 1 } + build: v0.10.0-4b9e8a6-debug + hooks: + - average + - cast + - decimate + - drop + - dump + - ebm + - fix + - gate + - jitter_calc + - limit_rate + - restart + - scale + - shift_seq + - shift_ts + - skip_first + - stats + - ts + - pps_ts + - print + node-types: [] + apis: + - capabilities + - config + - shutdown + - restart + - nodes + - node/start + - node/stop + - node/pause + - node/resume + - node/restart + - stats + - stats/reset + - file + - paths + - path/start + - path/stop + formats: [] + "/config": get: @@ -86,7 +128,42 @@ paths: examples: example1: value: - { test: 1 } + nodes: + udp_node1: + type: socket + layer: udp + in: + address: '*:12000' + signals: + count: 8 + type: float + out: + address: '127.0.0.1:12001' + web_node1: + type: websocket + vectorize: 2 + series: + - label: Random walk + unit: V + - label: Sine + unit: A + - label: Rect + unit: Var + - label: Ramp + unit: °C + paths: + - in: + - udp_node1 + out: + - web_node1 + hooks: + - type: decimate + ratio: 2 + - in: + - web_node1 + out: + - udp_node1 + "/restart": post: @@ -106,13 +183,14 @@ paths: description: An optional path to a new configuration file which should be loaded after restarting the node. responses: '200': - description: Success + description: Success. The instance has been restarted. content: application/json: examples: example1: value: - { test: 1 } + restarts: 5 + config: http://example.com/path/to/config.json "/shutdown": post: @@ -121,13 +199,7 @@ paths: - super-node responses: '200': - description: Success - content: - application/json: - examples: - example1: - value: - { test: 1 } + description: Success. The instance has been shut down. "/nodes": get: @@ -142,7 +214,95 @@ paths: examples: example1: value: - { test: 1 } + - name: udp_node1 + uuid: b3df1d73-f483-f16c-5936-4ea48295615c + state: running + affinity: -1 + in: + address: '*:12000' + signals: + count: 8 + type: float + out: + address: '127.0.0.1:12001' + type: socket + layer: udp + - name: web_node1 + uuid: 19c84350-c83a-8a3b-224b-43fa591c8998 + state: running + affinity: -1 + in: + vectorize: 2 + signals: + - type: float + enabled: true + name: signal0 + - type: float + enabled: true + name: signal1 + - type: float + enabled: true + name: signal2 + - type: float + enabled: true + name: signal3 + - type: float + enabled: true + name: signal4 + - type: float + enabled: true + name: signal5 + - type: float + enabled: true + name: signal6 + - type: float + enabled: true + name: signal7 + - type: float + enabled: true + name: signal8 + - type: float + enabled: true + name: signal9 + - type: float + enabled: true + name: signal10 + - type: float + enabled: true + name: signal11 + - type: float + enabled: true + name: signal12 + - type: float + enabled: true + name: signal13 + - type: float + enabled: true + name: signal14 + out: + vectorize: 2 + signals: + - type: float + enabled: true + name: signal0 + - type: float + enabled: true + name: signal1 + - type: float + enabled: true + name: signal2 + type: websocket + vectorize: 2 + series: + - label: Random walk + unit: V + - label: Sine + unit: A + - label: Rect + unit: Var + - label: Ramp + unit: °C + "/node/{uuid}/stats": get: @@ -160,6 +320,8 @@ paths: example1: value: { test: 1 } + '404': + description: Error. There is no node with the given UUID or the node does not collect statistics. "/node/{uuid}/stats/reset": post: @@ -170,13 +332,9 @@ paths: - $ref: "#/components/parameters/node-uuid" responses: '200': - description: Success - content: - application/json: - examples: - example1: - value: - { test: 1 } + description: Success. The statistics of the node have been reset. + '404': + description: Error. There is no node with the given UUID. "/node/{uuid}/start": post: @@ -187,14 +345,10 @@ paths: - $ref: "#/components/parameters/node-uuid" responses: '200': - description: Success - content: - application/json: - examples: - example1: - value: - { test: 1 } - + description: Success. The node has been started. + '404': + description: Error. There is no node with the given UUID. + "/node/{uuid}/stop": post: summary: Stop a node. @@ -204,14 +358,10 @@ paths: - $ref: "#/components/parameters/node-uuid" responses: '200': - description: Success - content: - application/json: - examples: - example1: - value: - { test: 1 } - + description: Success. The node has been stopped. + '404': + description: Error. There is no node with the given UUID. + "/node/{uuid}/pause": post: summary: Pause a node. @@ -221,13 +371,9 @@ paths: - $ref: "#/components/parameters/node-uuid" responses: '200': - description: Success - content: - application/json: - examples: - example1: - value: - { test: 1 } + description: Success. The node has been paused. + '404': + description: Error. There is no node with the given UUID. "/node/{uuid}/resume": post: @@ -238,14 +384,10 @@ paths: - $ref: "#/components/parameters/node-uuid" responses: '200': - description: Success - content: - application/json: - examples: - example1: - value: - { test: 1 } - + description: Success. The node has been resumed. + '404': + description: Error. There is no node with the given UUID. + "/node/{uuid}/restart": post: summary: Retart a node. @@ -255,14 +397,10 @@ paths: - $ref: "#/components/parameters/node-uuid" responses: '200': - description: Success - content: - application/json: - examples: - example1: - value: - { test: 1 } - + description: Success. The node has been restarted. + '404': + description: Error. There is no node with the given UUID. + "/node/{uuid}/file/rewind": post: summary: Rewind the playback file to the beginning. @@ -272,13 +410,9 @@ paths: - $ref: "#/components/parameters/node-uuid" responses: '200': - description: Success - content: - application/json: - examples: - example1: - value: - { test: 1 } + description: Success. The file has been rewound. + '404': + description: Error. There is no node with the given UUID. "/node/{uuid}/file/seek": post: @@ -302,17 +436,13 @@ paths: example: 123 responses: '200': - description: Success - content: - application/json: - examples: - example1: - value: - { test: 1 } - + description: Success. The read-pointer of the file has been changed. + '404': + description: Error. There is no node with the given UUID. + "/paths": get: - summary: Get a list of all configure paths. + summary: Get a list of all paths. tags: - paths responses: @@ -323,7 +453,38 @@ paths: examples: example1: value: - { test: 1 } + - uuid: 251c99af-4b05-9de4-367e-2bb550412e56 + state: running + mode: any + enabled: true + builtin: true + reverse: false + original_sequence_no: true + last_sequence: false + poll: false + queuelen: 1024 + signals: [] + hooks: [] + in: + - udp_node1 + out: + - web_node1 + - uuid: 61b5674b-95fa-b35f-bff8-c877acf21e3b + state: running + mode: any + enabled: true + builtin: true + reverse: false + original_sequence_no: true + last_sequence: false + poll: false + queuelen: 1024 + signals: [] + hooks: [] + in: + - web_node1 + out: + - udp_node1 "/path/{uuid}/start": post: @@ -334,14 +495,10 @@ paths: - $ref: "#/components/parameters/path-uuid" responses: '200': - description: Success - content: - application/json: - examples: - example1: - value: - { test: 1 } - + description: Success. The path has been started. + '404': + description: Error. There is no path with the given UUID. + "/path/{uuid}/stop": post: summary: Start a path. @@ -351,45 +508,6 @@ paths: - $ref: "#/components/parameters/path-uuid" responses: '200': - description: Success - content: - application/json: - examples: - example1: - value: - { test: 1 } - - "/path/{uuid}/stats": - get: - summary: Get the statistics of a path. - tags: - - paths - parameters: - - $ref: "#/components/parameters/path-uuid" - responses: - '200': - description: Success - content: - application/json: - examples: - example1: - value: - { test: 1 } - - "/path/{uuid}/stats/reset": - post: - summary: Reset the statistics counters for a specific path. - tags: - - paths - parameters: - - $ref: "#/components/parameters/path-uuid" - responses: - '200': - description: Success - content: - application/json: - examples: - example1: - value: - { test: 1 } - \ No newline at end of file + description: Success. The path has been stopped. + '404': + description: Error. There is no path with the given UUID. diff --git a/include/villas/api/node_request.hpp b/include/villas/api/node_request.hpp new file mode 100644 index 000000000..ded6cb4b2 --- /dev/null +++ b/include/villas/api/node_request.hpp @@ -0,0 +1,32 @@ +/** API Request. + * + * @file + * @author Steffen Vogel + * @copyright 2014-2020, Institute for Automation of Complex Power Systems, EONERC + * @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. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *********************************************************************************/ + +#pragma once + +#include + +class NodeRequest : public Request { + +public: + +}; diff --git a/include/villas/api/request.hpp b/include/villas/api/request.hpp index a31a7b7cd..cebedd0a3 100644 --- a/include/villas/api/request.hpp +++ b/include/villas/api/request.hpp @@ -58,7 +58,7 @@ public: RequestFactory *factory; enum Method { - UNKNOWN_METHOD, + UNKNOWN, GET, POST, DELETE, diff --git a/include/villas/path.h b/include/villas/path.h index 5cd3a2b1c..7e9bf9f4d 100644 --- a/include/villas/path.h +++ b/include/villas/path.h @@ -45,7 +45,6 @@ #include /* Forward declarations */ -struct stats; struct node; /** The register mode determines under which condition the path is triggered. */ diff --git a/include/villas/super_node.hpp b/include/villas/super_node.hpp index 9633d3f33..8e83f1e76 100644 --- a/include/villas/super_node.hpp +++ b/include/villas/super_node.hpp @@ -132,7 +132,7 @@ public: struct node * getNode(const std::string &name) { - return (struct node *) vlist_lookup(&nodes, name.c_str()); + return vlist_lookup_name(&nodes, name); } struct vlist * getNodes() diff --git a/lib/api/CMakeLists.txt b/lib/api/CMakeLists.txt index 8d51675f1..29d83b2f1 100644 --- a/lib/api/CMakeLists.txt +++ b/lib/api/CMakeLists.txt @@ -26,16 +26,18 @@ set(API_SRC request.cpp response.cpp - requests/capabiltities.cpp - requests/shutdown.cpp requests/status.cpp + requests/capabiltities.cpp requests/config.cpp - requests/nodes.cpp - requests/paths.cpp + requests/shutdown.cpp requests/restart.cpp + requests/nodes.cpp requests/node_action.cpp - requests/file.cpp - requests/stats_reset.cpp + requests/node_stats.cpp + requests/node_stats_reset.cpp + requests/node_file.cpp + requests/paths.cpp + requests/path_action.cpp ) add_library(api STATIC ${API_SRC}) diff --git a/lib/api/requests/node_action.cpp b/lib/api/requests/node_action.cpp index 77c18fbb5..25f78068f 100644 --- a/lib/api/requests/node_action.cpp +++ b/lib/api/requests/node_action.cpp @@ -65,29 +65,29 @@ public: }; /* Register API requests */ -char n1[] = "node/start"; -char r1[] = "/node/([^/]+)/start"; -char d1[] = "start a node"; +static char n1[] = "node/start"; +static char r1[] = "/node/([^/]+)/start"; +static char d1[] = "start a node"; static RequestPlugin, n1, r1, d1> p1; -char n2[] = "node/stop"; -char r2[] = "/node/([^/]+)/stop"; -char d2[] = "stop a node"; +static char n2[] = "node/stop"; +static char r2[] = "/node/([^/]+)/stop"; +static char d2[] = "stop a node"; static RequestPlugin, n2, r2, d2> p2; -char n3[] = "node/pause"; -char r3[] = "/node/([^/]+)/pause"; -char d3[] = "pause a node"; +static char n3[] = "node/pause"; +static char r3[] = "/node/([^/]+)/pause"; +static char d3[] = "pause a node"; static RequestPlugin, n3, r3, d3> p3; -char n4[] = "node/resume"; -char r4[] = "/node/([^/]+)/resume"; -char d4[] = "resume a node"; +static char n4[] = "node/resume"; +static char r4[] = "/node/([^/]+)/resume"; +static char d4[] = "resume a node"; static RequestPlugin, n4, r4, d4> p4; -char n5[] = "node/restart"; -char r5[] = "/node/([^/]+)/restart"; -char d5[] = "restart a node"; +static char n5[] = "node/restart"; +static char r5[] = "/node/([^/]+)/restart"; +static char d5[] = "restart a node"; static RequestPlugin, n5, r5, d5> p5; diff --git a/lib/api/requests/file.cpp b/lib/api/requests/node_file.cpp similarity index 100% rename from lib/api/requests/file.cpp rename to lib/api/requests/node_file.cpp diff --git a/lib/api/requests/stats.cpp b/lib/api/requests/node_stats.cpp similarity index 84% rename from lib/api/requests/stats.cpp rename to lib/api/requests/node_stats.cpp index d2c8e08d5..3b3ab3ed1 100644 --- a/lib/api/requests/stats.cpp +++ b/lib/api/requests/node_stats.cpp @@ -43,29 +43,24 @@ public: virtual Response * execute() { - int ret; - json_error_t err; - if (method != Method::GET) throw InvalidMethod(this); if (body != nullptr) throw BadRequest("Stats endpoint does not accept any body data"); - json_t *json_stats = json_array(); + const auto &nodeName = matches[1].str(); struct vlist *nodes = session->getSuperNode()->getNodes(); - for (size_t i = 0; i < vlist_length(nodes); i++) { - struct node *n = (struct node *) vlist_at(nodes, i); + struct node *node = (struct node *) vlist_lookup(nodes, nodeName.c_str()); - if (node && strcmp(node, node_name(n))) - continue; + if (!node) + throw BadRequest("Unknown node"); - if (n->stats) - json_array_append(json_stats, n->stats->toJson()); - } + if (!node->stats) + throw BadRequest("The statistics collection for this node is not enabled"); - return new Response(session, json_stats); + return new Response(session, node->stats->toJson()); } }; diff --git a/lib/api/requests/stats_reset.cpp b/lib/api/requests/node_stats_reset.cpp similarity index 91% rename from lib/api/requests/stats_reset.cpp rename to lib/api/requests/node_stats_reset.cpp index b73b4fbfd..c89831b2e 100644 --- a/lib/api/requests/stats_reset.cpp +++ b/lib/api/requests/node_stats_reset.cpp @@ -46,6 +46,13 @@ public: int ret; json_error_t err; + if (method != Method::POST) + throw InvalidMethod(this); + + if (body != nullptr) + throw BadRequest("Stats endpoint does not accept any body data"); + + char *node = nullptr; ret = json_unpack_ex(body, &err, 0, "{ s?: s }", @@ -74,7 +81,7 @@ public: /* Register API requests */ static char n[] = "stats/reset"; -static char r[] = "/stats/reset"; +static char r[] = "/node/([^/]+)/stats/reset"; static char d[] = "reset internal statistics counters"; static RequestPlugin p; diff --git a/lib/api/requests/path_action.cpp b/lib/api/requests/path_action.cpp index 41aa06b01..5329cdeef 100644 --- a/lib/api/requests/path_action.cpp +++ b/lib/api/requests/path_action.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include #include @@ -35,7 +35,7 @@ namespace villas { namespace node { namespace api { -template +template class PathActionRequest : public Request { public: @@ -53,16 +53,16 @@ public: const auto &pathIndexStr = matches[1].str(); try { - pathIndex = std::atoul(pathIndexStr); + pathIndex = std::stoul(pathIndexStr); } catch (const std::invalid_argument &e) { throw BadRequest("Invalid argument"); } struct vlist *paths = session->getSuperNode()->getPaths(); - struct vpath *p = (struct path *) vlist_at_safe(pathIndex); + struct vpath *p = (struct vpath *) vlist_at_safe(paths, pathIndex); if (!p) - throw Error(HTTP_STATUS_NOT_FOUND, "Node not found"); + throw Error(HTTP_STATUS_NOT_FOUND, "Path not found"); A(p); @@ -72,14 +72,14 @@ public: }; /* Register API requests */ -char n1[] = "path/start"; -char r1[] = "/path/([^/]+)/start"; -char d1[] = "start a path"; +static char n1[] = "path/start"; +static char r1[] = "/path/([^/]+)/start"; +static char d1[] = "start a path"; static RequestPlugin, n1, r1, d1> p1; -char n2[] = "path/stop"; -char r2[] = "/path/([^/]+)/stop"; -char d2[] = "stop a path"; +static char n2[] = "path/stop"; +static char r2[] = "/path/([^/]+)/stop"; +static char d2[] = "stop a path"; static RequestPlugin, n2, r2, d2> p2; diff --git a/lib/api/requests/restart.cpp b/lib/api/requests/restart.cpp index 3cd55afa0..e67b13135 100644 --- a/lib/api/requests/restart.cpp +++ b/lib/api/requests/restart.cpp @@ -79,7 +79,7 @@ public: ? cfg : session->getSuperNode()->getConfigUri(); - logger->info("Restarting to %s", configUri.c_str()); + logger->info("Restarting to {}", configUri.c_str()); /* Increment API restart counter */ char *scnt = getenv("VILLAS_API_RESTART_COUNT"); diff --git a/lib/api/requests/shutdown.cpp b/lib/api/requests/shutdown.cpp index 560756b42..c58c50ba1 100644 --- a/lib/api/requests/shutdown.cpp +++ b/lib/api/requests/shutdown.cpp @@ -37,7 +37,7 @@ public: virtual Response * execute() { - if (method != Method::GET) + if (method != Method::POST) throw InvalidMethod(this); if (body != nullptr) diff --git a/lib/api/session.cpp b/lib/api/session.cpp index 7afb4e021..a21af3378 100644 --- a/lib/api/session.cpp +++ b/lib/api/session.cpp @@ -131,7 +131,7 @@ void Session::open(void *in, size_t len) try { meth = getRequestMethod(wsi); - if (meth == Request::Method::UNKNOWN_METHOD) + if (meth == Request::Method::UNKNOWN) throw RuntimeError("Invalid request method"); request = RequestFactory::make(this, uri, meth); @@ -332,7 +332,7 @@ int Session::getRequestMethod(struct lws *wsi) return Request::Method::OPTIONS; #endif else - return Request::Method::UNKNOWN_METHOD; + return Request::Method::UNKNOWN; } std::string Session::methodToString(int method) diff --git a/lib/formats/json_reserve.cpp b/lib/formats/json_reserve.cpp index 88767f42a..9c17e9522 100644 --- a/lib/formats/json_reserve.cpp +++ b/lib/formats/json_reserve.cpp @@ -185,7 +185,7 @@ static int json_reserve_unpack_sample(struct io *io, json_t *json_smp, struct sa struct signal *sig; - sig = (struct signal *) vlist_lookup(io->signals, name); + sig = vlist_lookup_name(io->signals, name); if (sig) { if (!sig->enabled) continue; diff --git a/lib/hooks/average.cpp b/lib/hooks/average.cpp index d858bde81..8ccf9aa0d 100644 --- a/lib/hooks/average.cpp +++ b/lib/hooks/average.cpp @@ -73,7 +73,7 @@ public: for (size_t i = 0; i < vlist_length(&signal_names); i++) { char *signal_name = (char *) vlist_at_safe(&signal_names, i); - int index = vlist_lookup_index(&signals, signal_name); + int index = vlist_lookup_index(&signals, signal_name); if (index < 0) throw RuntimeError("Failed to find signal {}", signal_name); diff --git a/lib/hooks/cast.cpp b/lib/hooks/cast.cpp index 8a3a3fb5b..5c3449a4c 100644 --- a/lib/hooks/cast.cpp +++ b/lib/hooks/cast.cpp @@ -72,7 +72,7 @@ public: assert(state == State::CHECKED); if (signal_name) { - signal_index = vlist_lookup_index(&signals, signal_name); + signal_index = vlist_lookup_index(&signals, signal_name); if (signal_index < 0) throw RuntimeError("Failed to find signal: {}", signal_name); } diff --git a/lib/hooks/dp.cpp b/lib/hooks/dp.cpp index 416ccb157..286c8096b 100644 --- a/lib/hooks/dp.cpp +++ b/lib/hooks/dp.cpp @@ -221,7 +221,7 @@ public: assert(state != State::STARTED); if (signal_name) { - signal_index = vlist_lookup_index(&signals, signal_name); + signal_index = vlist_lookup_index(&signals, signal_name); if (signal_index < 0) throw RuntimeError("Failed to find signal: {}", signal_name); } diff --git a/lib/hooks/gate.cpp b/lib/hooks/gate.cpp index 00dda1129..915ef5a62 100644 --- a/lib/hooks/gate.cpp +++ b/lib/hooks/gate.cpp @@ -122,7 +122,7 @@ public: assert(state == State::CHECKED); if (!signalName.empty()) { - signalIndex = vlist_lookup_index(&signals, signalName.c_str()); + signalIndex = vlist_lookup_index(&signals, signalName); if (signalIndex < 0) throw RuntimeError("Failed to find signal: {}", signalName); } diff --git a/lib/hooks/limit_value.cpp b/lib/hooks/limit_value.cpp index 364eaf903..bd15189a0 100644 --- a/lib/hooks/limit_value.cpp +++ b/lib/hooks/limit_value.cpp @@ -75,7 +75,7 @@ public: for (size_t i = 0; i < vlist_length(&signal_names); i++) { char *signal_name = (char *) vlist_at_safe(&signal_names, i); - int index = vlist_lookup_index(&signals, signal_name); + int index = vlist_lookup_index(&signals, signal_name); if (index < 0) throw RuntimeError("Failed to find signal {}", signal_name); diff --git a/lib/hooks/scale.cpp b/lib/hooks/scale.cpp index ee5a43fd8..9f3697d86 100644 --- a/lib/hooks/scale.cpp +++ b/lib/hooks/scale.cpp @@ -53,7 +53,7 @@ public: assert(state != State::STARTED); if (signal_name) { - signal_index = vlist_lookup_index(&signals, signal_name); + signal_index = vlist_lookup_index(&signals, signal_name); if (signal_index < 0) throw RuntimeError("Failed to find signal: {}", signal_name); } diff --git a/lib/mapping.cpp b/lib/mapping.cpp index 994154766..2498d0c60 100644 --- a/lib/mapping.cpp +++ b/lib/mapping.cpp @@ -48,7 +48,7 @@ int mapping_parse_str(struct mapping_entry *me, const char *str, struct vlist *n goto invalid_format; } - me->node = (struct node *) vlist_lookup(nodes, node); + me->node = vlist_lookup_name(nodes, node); if (!me->node) { warning("Unknown node %s", node); goto invalid_format; @@ -128,7 +128,7 @@ int mapping_parse_str(struct mapping_entry *me, const char *str, struct vlist *n first_str = strtok_r(nullptr, "-]", &lasts); if (first_str) { if (me->node) - first = vlist_lookup_index(&me->node->in.signals, first_str); + first = vlist_lookup_index(&me->node->in.signals, first_str); if (first < 0) { char *endptr; @@ -149,7 +149,7 @@ int mapping_parse_str(struct mapping_entry *me, const char *str, struct vlist *n last_str = strtok_r(nullptr, "]", &lasts); if (last_str) { if (me->node) - last = vlist_lookup_index(&me->node->in.signals, last_str); + last = vlist_lookup_index(&me->node->in.signals, last_str); if (last < 0) { char *endptr; diff --git a/lib/node.cpp b/lib/node.cpp index b4f4928b4..8fcabe223 100644 --- a/lib/node.cpp +++ b/lib/node.cpp @@ -600,7 +600,7 @@ int node_list_parse(struct vlist *list, json_t *cfg, struct vlist *all) switch (json_typeof(cfg)) { case JSON_STRING: str = json_string_value(cfg); - node = (struct node *) vlist_lookup(all, str); + node = vlist_lookup_name(all, str); if (!node) goto invalid2; @@ -612,7 +612,7 @@ int node_list_parse(struct vlist *list, json_t *cfg, struct vlist *all) if (!json_is_string(elm)) goto invalid; - node = (struct node *) vlist_lookup(all, json_string_value(elm)); + node = vlist_lookup_name(all, json_string_value(elm)); if (!node) goto invalid; diff --git a/lib/nodes/file.cpp b/lib/nodes/file.cpp index 2bccbade1..c9b801a99 100644 --- a/lib/nodes/file.cpp +++ b/lib/nodes/file.cpp @@ -328,6 +328,7 @@ int file_start(struct node *n) struct sample *smp = sample_alloc_mem(vlist_length(&n->in.signals)); for (unsigned i = 0; i < f->skip_lines; i++) io_scan(&f->io, &smp, 1); + sample_free(smp); return 0; diff --git a/lib/nodes/ngsi.cpp b/lib/nodes/ngsi.cpp index e9144b224..2a67f9da8 100644 --- a/lib/nodes/ngsi.cpp +++ b/lib/nodes/ngsi.cpp @@ -315,7 +315,7 @@ static int ngsi_parse_entity(struct node *n, json_t *json_entity, struct sample return -3; /* Check attribute name and type */ - attr = (NgsiAttribute *) vlist_lookup(&i->in.signals, name); + attr = vlist_lookup_name(&i->in.signals, name); if (!attr || attr->type != type) continue; /* skip unknown attributes */ diff --git a/lib/nodes/stats.cpp b/lib/nodes/stats.cpp index 90a76895b..060a3280d 100644 --- a/lib/nodes/stats.cpp +++ b/lib/nodes/stats.cpp @@ -100,7 +100,7 @@ int stats_node_start(struct node *n) for (size_t i = 0; i < vlist_length(&s->signals); i++) { struct stats_node_signal *stats_sig = (struct stats_node_signal *) vlist_at(&s->signals, i); - stats_sig->node = (struct node *) vlist_lookup(nodes, stats_sig->node_str); + stats_sig->node = vlist_lookup_name(nodes, stats_sig->node_str); if (!stats_sig->node) error("Invalid reference node %s for setting 'node' of node %s", stats_sig->node_str, node_name(n)); } diff --git a/lib/nodes/websocket.cpp b/lib/nodes/websocket.cpp index 7b4aca6ac..7f86b1498 100644 --- a/lib/nodes/websocket.cpp +++ b/lib/nodes/websocket.cpp @@ -218,7 +218,7 @@ int websocket_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, voi format = (char *) "villas.web"; /* Search for node whose name matches the URI. */ - c->node = (struct node *) vlist_lookup(&p.node.instances, node); + c->node = vlist_lookup_name(&p.node.instances, node); if (!c->node) { websocket_connection_close(c, wsi, LWS_CLOSE_STATUS_POLICY_VIOLATION, "Unknown node"); warning("Failed to find node: node=%s", node); diff --git a/lib/path.cpp b/lib/path.cpp index fcef417f7..4d4f2c637 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -464,7 +464,7 @@ int path_parse(struct vpath *p, json_t *cfg, struct vlist *nodes) return -1; } - node = (struct node *) vlist_lookup(nodes, name); + node = vlist_lookup_name(nodes, name); if (!node) { p->logger->error("The 'mask' entry '{}' is not a valid node name", name); return -1; diff --git a/packaging/deps.sh b/packaging/deps.sh index cd34b7825..a4c9165a9 100644 --- a/packaging/deps.sh +++ b/packaging/deps.sh @@ -102,7 +102,7 @@ if ! pkg-config "libwebsockets >= 2.3.0"; then mkdir -p libwebsockets/build pushd libwebsockets/build git checkout v4.0-stable - cmake -DLWS_WITHOUT_TESTAPPS=ON -DLWS_WITHOUT_EXTENSIONS=OFF ${CMAKE_OPTS} .. + cmake -DLWS_WITHOUT_TESTAPPS=ON -DLWS_WITHOUT_EXTENSIONS=OFF -DLWS_WITH_SERVER_STATUS=ON ${CMAKE_OPTS} .. make -j$(nproc) ${TARGET} popd fi diff --git a/tests/unit/mapping.cpp b/tests/unit/mapping.cpp index c5997576e..99d44ccab 100644 --- a/tests/unit/mapping.cpp +++ b/tests/unit/mapping.cpp @@ -67,41 +67,41 @@ Test(mapping, parse_nodes) ret = mapping_parse_str(&m, "apple.ts.origin", &nodes); cr_assert_eq(ret, 0); - cr_assert_eq(m.node, vlist_lookup(&nodes, "apple")); + cr_assert_eq(m.node, vlist_lookup_name(&nodes, "apple")); cr_assert_eq(m.type, MappingType::TIMESTAMP); cr_assert_eq(m.timestamp.type, MappingTimestampType::ORIGIN); ret = mapping_parse_str(&m, "cherry.stats.owd.mean", &nodes); cr_assert_eq(ret, 0); - cr_assert_eq(m.node, vlist_lookup(&nodes, "cherry")); + cr_assert_eq(m.node, vlist_lookup_name(&nodes, "cherry")); cr_assert_eq(m.type, MappingType::STATS); cr_assert_eq(m.stats.metric, Stats::Metric::OWD); cr_assert_eq(m.stats.type, Stats::Type::MEAN); ret = mapping_parse_str(&m, "carrot.data[1-2]", &nodes); cr_assert_eq(ret, 0); - cr_assert_eq(m.node, vlist_lookup(&nodes, "carrot")); + cr_assert_eq(m.node, vlist_lookup_name(&nodes, "carrot")); cr_assert_eq(m.type, MappingType::DATA); cr_assert_eq(m.data.offset, 1); cr_assert_eq(m.length, 2); ret = mapping_parse_str(&m, "carrot", &nodes); cr_assert_eq(ret, 0); - cr_assert_eq(m.node, vlist_lookup(&nodes, "carrot")); + cr_assert_eq(m.node, vlist_lookup_name(&nodes, "carrot")); cr_assert_eq(m.type, MappingType::DATA); cr_assert_eq(m.data.offset, 0); cr_assert_eq(m.length, -1); ret = mapping_parse_str(&m, "carrot.data[sole]", &nodes); cr_assert_eq(ret, 0); - cr_assert_eq(m.node, vlist_lookup(&nodes, "carrot")); + cr_assert_eq(m.node, vlist_lookup_name(&nodes, "carrot")); cr_assert_eq(m.type, MappingType::DATA); cr_assert_eq(m.data.offset, 1); cr_assert_eq(m.length, 1); ret = mapping_parse_str(&m, "carrot.data[sole-mio]", &nodes); cr_assert_eq(ret, 0); - cr_assert_eq(m.node, vlist_lookup(&nodes, "carrot")); + cr_assert_eq(m.node, vlist_lookup_name(&nodes, "carrot")); cr_assert_eq(m.type, MappingType::DATA); cr_assert_eq(m.data.offset, 1); cr_assert_eq(m.length, 2);