mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
api: fix exception for node and path requests
This commit is contained in:
parent
4ae1b1cbfd
commit
8fe1df94ff
7 changed files with 112 additions and 43 deletions
|
@ -40,29 +40,7 @@ public:
|
|||
struct vnode *node;
|
||||
|
||||
virtual void
|
||||
prepare()
|
||||
{
|
||||
int ret;
|
||||
|
||||
auto *nodes = session->getSuperNode()->getNodes();
|
||||
|
||||
uuid_t uuid;
|
||||
ret = uuid_parse(matches[1].c_str(), uuid);
|
||||
if (ret) {
|
||||
node = vlist_lookup_name<struct vnode>(nodes, matches[1]);
|
||||
if (!node)
|
||||
throw BadRequest("Unknown node", "{ s: s }",
|
||||
"node", matches[1].c_str()
|
||||
);
|
||||
}
|
||||
else {
|
||||
node = vlist_lookup_uuid<struct vnode>(nodes, uuid);
|
||||
if (!node)
|
||||
throw BadRequest("No node found with with matching UUID", "{ s: s }",
|
||||
"uuid", matches[1].c_str()
|
||||
);
|
||||
}
|
||||
}
|
||||
prepare();
|
||||
};
|
||||
|
||||
} /* namespace api */
|
||||
|
|
|
@ -40,24 +40,7 @@ public:
|
|||
struct vpath *path;
|
||||
|
||||
virtual void
|
||||
prepare()
|
||||
{
|
||||
int ret;
|
||||
uuid_t uuid;
|
||||
|
||||
ret = uuid_parse(matches[1].c_str(), uuid);
|
||||
if (ret)
|
||||
throw BadRequest("Invalid UUID", "{ s: s }",
|
||||
"uuid", matches[1].c_str()
|
||||
);
|
||||
|
||||
auto *paths = session->getSuperNode()->getPaths();
|
||||
path = vlist_lookup_uuid<struct vpath>(paths, uuid);
|
||||
if (!path)
|
||||
throw BadRequest("No path found with with matching UUID", "{ s: s }",
|
||||
"uuid", matches[1].c_str()
|
||||
);
|
||||
}
|
||||
prepare();
|
||||
};
|
||||
|
||||
} /* namespace api */
|
||||
|
|
|
@ -79,9 +79,15 @@ public:
|
|||
json_decref(body);
|
||||
}
|
||||
|
||||
virtual Response * execute() = 0;
|
||||
virtual void
|
||||
prepare()
|
||||
{ }
|
||||
|
||||
virtual void decode();
|
||||
virtual Response *
|
||||
execute() = 0;
|
||||
|
||||
virtual void
|
||||
decode();
|
||||
|
||||
const std::string &
|
||||
getMatch(int idx) const
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
set(API_SRC
|
||||
session.cpp
|
||||
request.cpp
|
||||
node_request.cpp
|
||||
path_request.cpp
|
||||
response.cpp
|
||||
|
||||
requests/status.cpp
|
||||
|
|
51
lib/api/node_request.cpp
Normal file
51
lib/api/node_request.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
/** Node API Request.
|
||||
*
|
||||
* @file
|
||||
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
||||
* @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 <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************************/
|
||||
|
||||
#include <villas/api/node_request.hpp>
|
||||
|
||||
using namespace villas::node::api;
|
||||
|
||||
void
|
||||
NodeRequest::prepare()
|
||||
{
|
||||
int ret;
|
||||
|
||||
auto *nodes = session->getSuperNode()->getNodes();
|
||||
|
||||
uuid_t uuid;
|
||||
ret = uuid_parse(matches[1].c_str(), uuid);
|
||||
if (ret) {
|
||||
node = vlist_lookup_name<struct vnode>(nodes, matches[1]);
|
||||
if (!node)
|
||||
throw BadRequest("Unknown node", "{ s: s }",
|
||||
"node", matches[1].c_str()
|
||||
);
|
||||
}
|
||||
else {
|
||||
node = vlist_lookup_uuid<struct vnode>(nodes, uuid);
|
||||
if (!node)
|
||||
throw BadRequest("No node found with with matching UUID", "{ s: s }",
|
||||
"uuid", matches[1].c_str()
|
||||
);
|
||||
}
|
||||
}
|
47
lib/api/path_request.cpp
Normal file
47
lib/api/path_request.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
/** Path API Request.
|
||||
*
|
||||
* @file
|
||||
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
||||
* @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 <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************************/
|
||||
|
||||
#include <villas/api/path_request.hpp>
|
||||
#include <villas/path.h>
|
||||
|
||||
using namespace villas::node::api;
|
||||
|
||||
void
|
||||
PathRequest::prepare()
|
||||
{
|
||||
int ret;
|
||||
uuid_t uuid;
|
||||
|
||||
ret = uuid_parse(matches[1].c_str(), uuid);
|
||||
if (ret)
|
||||
throw BadRequest("Invalid UUID", "{ s: s }",
|
||||
"uuid", matches[1].c_str()
|
||||
);
|
||||
|
||||
auto *paths = session->getSuperNode()->getPaths();
|
||||
path = vlist_lookup_uuid<struct vpath>(paths, uuid);
|
||||
if (!path)
|
||||
throw BadRequest("No path found with with matching UUID", "{ s: s }",
|
||||
"uuid", matches[1].c_str()
|
||||
);
|
||||
}
|
|
@ -59,6 +59,8 @@ Request * RequestFactory::create(Session *s, const std::string &uri, Session::Me
|
|||
p->method = meth;
|
||||
p->contentLength = ct;
|
||||
|
||||
p->prepare();
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue