From 05584bc0f5a1b0b0e78e52496f842d52c2c018c2 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Tue, 28 Aug 2018 16:12:42 +0200 Subject: [PATCH 1/8] Deprecate nornsctl_ping() and send_ping_request() --- include/norns/nornsctl.h | 2 +- lib/communication.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/norns/nornsctl.h b/include/norns/nornsctl.h index c6cceea..237d456 100644 --- a/include/norns/nornsctl.h +++ b/include/norns/nornsctl.h @@ -122,7 +122,7 @@ nornsctl_job_init(nornsctl_job_t* job, /* Check if the service daemon is running */ norns_error_t -nornsctl_ping(void) __THROW; +nornsctl_ping(void) __THROW __attribute__((deprecated)); /* Send a command to the service daemon */ norns_error_t diff --git a/lib/communication.h b/lib/communication.h index 7e40649..b47de8d 100644 --- a/lib/communication.h +++ b/lib/communication.h @@ -41,7 +41,7 @@ norns_error_t send_process_request(norns_rpc_type_t type, uint32_t jobid, norns_error_t send_namespace_request(norns_rpc_type_t type, const char* nsid, nornsctl_backend_t* backend); norns_error_t send_control_status_request(nornsctl_stat_t* stats); -norns_error_t send_ping_request(); +norns_error_t send_ping_request() __attribute__((deprecated)); #pragma GCC visibility pop -- GitLab From 37ff6de10e088e240b11b429dc2667dfcfc6c62b Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Tue, 28 Aug 2018 18:01:45 +0200 Subject: [PATCH 2/8] Rename ctl_status to global_status --- lib/communication.c | 6 +++--- lib/requests.c | 12 ++++++------ lib/requests.h | 2 +- rpc/messages.proto | 4 ++-- src/api/request.cpp | 6 +++--- src/api/request.hpp | 6 +++--- src/api/response.cpp | 10 +++++----- src/api/response.hpp | 6 +++--- src/urd.cpp | 4 ++-- 9 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/communication.c b/lib/communication.c index 5a5c794..b28a6df 100644 --- a/lib/communication.c +++ b/lib/communication.c @@ -113,12 +113,12 @@ send_control_status_request(nornsctl_stat_t* stats) { int res; norns_response_t resp; - if((res = send_request(NORNSCTL_STATUS, &resp)) + if((res = send_request(NORNSCTL_GLOBAL_STATUS, &resp)) != NORNS_SUCCESS) { return res; } - if(resp.r_type != NORNSCTL_STATUS) { + if(resp.r_type != NORNSCTL_GLOBAL_STATUS) { return NORNS_ESNAFU; } @@ -245,7 +245,7 @@ send_request(norns_rpc_type_t type, norns_response_t* resp, ...) { break; } - case NORNSCTL_STATUS: + case NORNSCTL_GLOBAL_STATUS: case NORNS_PING: { if((res = pack_to_buffer(type, &req_buf)) != NORNS_SUCCESS) { diff --git a/lib/requests.c b/lib/requests.c index d470e85..888cb7e 100644 --- a/lib/requests.c +++ b/lib/requests.c @@ -107,8 +107,8 @@ encode_request_type(norns_rpc_type_t type) { return NORNS__RPC__REQUEST__TYPE__NAMESPACE_UPDATE; case NORNS_NAMESPACE_UNREGISTER: return NORNS__RPC__REQUEST__TYPE__NAMESPACE_UNREGISTER; - case NORNSCTL_STATUS: - return NORNS__RPC__REQUEST__TYPE__CTL_STATUS; + case NORNSCTL_GLOBAL_STATUS: + return NORNS__RPC__REQUEST__TYPE__GLOBAL_STATUS; default: return -1; } @@ -139,8 +139,8 @@ decode_response_type(int norns_rpc_type) { return NORNS_NAMESPACE_UPDATE; case NORNS__RPC__RESPONSE__TYPE__NAMESPACE_UNREGISTER: return NORNS_NAMESPACE_UNREGISTER; - case NORNS__RPC__RESPONSE__TYPE__CTL_STATUS: - return NORNSCTL_STATUS; + case NORNS__RPC__RESPONSE__TYPE__GLOBAL_STATUS: + return NORNSCTL_GLOBAL_STATUS; case NORNS__RPC__RESPONSE__TYPE__BAD_REQUEST: // intentionally fall through default: @@ -177,7 +177,7 @@ build_request_msg(norns_rpc_type_t type, va_list ap) { break; } - case NORNSCTL_STATUS: + case NORNSCTL_GLOBAL_STATUS: case NORNS_PING: { break; @@ -780,7 +780,7 @@ unpack_from_buffer(msgbuffer_t* buf, norns_response_t* response) { response->r_errno = rpc_resp->stats->sys_errnum; break; - case NORNSCTL_STATUS: + case NORNSCTL_GLOBAL_STATUS: if(rpc_resp->gstats == NULL) { return NORNS_ERPCRECVFAILED; } diff --git a/lib/requests.h b/lib/requests.h index b96bc87..fd4f224 100644 --- a/lib/requests.h +++ b/lib/requests.h @@ -38,7 +38,7 @@ typedef enum { NORNS_IOTASK_SUBMIT, NORNS_IOTASK_STATUS, - NORNSCTL_STATUS, + NORNSCTL_GLOBAL_STATUS, NORNS_PING, diff --git a/rpc/messages.proto b/rpc/messages.proto index 6b95fc6..09c0f29 100644 --- a/rpc/messages.proto +++ b/rpc/messages.proto @@ -17,7 +17,7 @@ message Request { NAMESPACE_UPDATE = 10; NAMESPACE_UNREGISTER = 11; - CTL_STATUS = 12; + GLOBAL_STATUS = 12; } // I/O task descriptor @@ -105,7 +105,7 @@ message Response { NAMESPACE_UPDATE = 10; NAMESPACE_UNREGISTER = 11; - CTL_STATUS = 12; + GLOBAL_STATUS = 12; BAD_REQUEST = 13; } diff --git a/src/api/request.cpp b/src/api/request.cpp index c617eb1..3af1298 100644 --- a/src/api/request.cpp +++ b/src/api/request.cpp @@ -213,8 +213,8 @@ request_ptr request::create_from_buffer(const std::vector& buffer, int case norns::rpc::Request::PING: return std::make_unique(); - case norns::rpc::Request::CTL_STATUS: - return std::make_unique(); + case norns::rpc::Request::GLOBAL_STATUS: + return std::make_unique(); case norns::rpc::Request::JOB_REGISTER: case norns::rpc::Request::JOB_UPDATE: @@ -353,7 +353,7 @@ std::string iotask_status_request::to_string() const { } template<> -std::string ctl_status_request::to_string() const { +std::string global_status_request::to_string() const { return "GLOBAL_STATUS"; } diff --git a/src/api/request.hpp b/src/api/request.hpp index e90e9da..1f144b6 100644 --- a/src/api/request.hpp +++ b/src/api/request.hpp @@ -77,7 +77,7 @@ namespace api { enum class request_type { iotask_create, iotask_status, - ctl_status, + global_status, ping, job_register, job_update, @@ -255,8 +255,8 @@ using backend_unregister_request = detail::request_impl< std::string >; -using ctl_status_request = detail::request_impl< - request_type::ctl_status +using global_status_request = detail::request_impl< + request_type::global_status >; } // namespace api diff --git a/src/api/response.cpp b/src/api/response.cpp index 353cb6c..1070a03 100644 --- a/src/api/response.cpp +++ b/src/api/response.cpp @@ -59,8 +59,8 @@ norns::rpc::Response_Type encode(norns::api::response_type type) { return norns::rpc::Response::NAMESPACE_UPDATE; case response_type::backend_unregister: return norns::rpc::Response::NAMESPACE_UNREGISTER; - case response_type::ctl_status: - return norns::rpc::Response::CTL_STATUS; + case response_type::global_status: + return norns::rpc::Response::GLOBAL_STATUS; case response_type::bad_request: return norns::rpc::Response::BAD_REQUEST; default: @@ -157,10 +157,10 @@ std::string iotask_status_response::to_string() const { } ///////////////////////////////////////////////////////////////////////////////// -// specializations for ctl_status_response +// specializations for global_status_response ///////////////////////////////////////////////////////////////////////////////// template<> -void ctl_status_response::pack_extra_info(norns::rpc::Response& r) const { +void global_status_response::pack_extra_info(norns::rpc::Response& r) const { const auto& gstats = this->get<0>(); auto gstats_msg = new norns::rpc::Response_GlobalStats(); @@ -175,7 +175,7 @@ void ctl_status_response::pack_extra_info(norns::rpc::Response& r) const { } template<> -std::string ctl_status_response::to_string() const { +std::string global_status_response::to_string() const { const auto& gstats = this->get<0>(); return utils::to_string(gstats) + " " + utils::to_string(this->error_code()); } diff --git a/src/api/response.hpp b/src/api/response.hpp index 82ac789..fec814c 100644 --- a/src/api/response.hpp +++ b/src/api/response.hpp @@ -54,7 +54,7 @@ namespace api { enum class response_type { iotask_create, iotask_status, - ctl_status, + global_status, ping, job_register, job_update, @@ -185,8 +185,8 @@ using backend_unregister_response = detail::response_impl< response_type::backend_unregister >; -using ctl_status_response = detail::response_impl< - response_type::ctl_status, +using global_status_response = detail::response_impl< + response_type::global_status, io::global_stats >; diff --git a/src/urd.cpp b/src/urd.cpp index 6e1fada..a7aff02 100644 --- a/src/urd.cpp +++ b/src/urd.cpp @@ -562,7 +562,7 @@ response_ptr urd::namespace_remove_handler(const request_ptr base_request) { response_ptr urd::global_status_handler(const request_ptr /*base_request*/) { - auto resp = std::make_unique(); + auto resp = std::make_unique(); resp->set_error_code(urd_error::success); resp->set<0>(m_task_mgr->global_stats()); @@ -759,7 +759,7 @@ void urd::init_event_handlers() { std::bind(&urd::namespace_remove_handler, this, std::placeholders::_1)); m_api_listener->register_callback( - api::request_type::ctl_status, + api::request_type::global_status, std::bind(&urd::global_status_handler, this, std::placeholders::_1)); m_api_listener->register_callback( -- GitLab From aeffac30667499c5b3b47e1f695a2ba1f02ff523 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Tue, 28 Aug 2018 18:04:53 +0200 Subject: [PATCH 3/8] Rename msgbuffer_t to norns_msgbuffer_t --- lib/communication.c | 12 ++++++------ lib/requests.c | 4 ++-- lib/requests.h | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/communication.c b/lib/communication.c index b28a6df..1e2db77 100644 --- a/lib/communication.c +++ b/lib/communication.c @@ -47,8 +47,8 @@ #include "log.h" static int connect_to_daemon(const char* socket_path); -static int send_message(int conn, const msgbuffer_t* buffer); -static int recv_message(int conn, msgbuffer_t* buffer); +static int send_message(int conn, const norns_msgbuffer_t* buffer); +static int recv_message(int conn, norns_msgbuffer_t* buffer); static ssize_t recv_data(int conn, void* data, size_t size); static ssize_t send_data(int conn, const void* data, size_t size); static void print_hex(void* buffer, size_t bytes) __attribute__((unused)); @@ -208,8 +208,8 @@ send_request(norns_rpc_type_t type, norns_response_t* resp, ...) { int res; int conn = -1; - msgbuffer_t req_buf = MSGBUFFER_INIT(); - msgbuffer_t resp_buf = MSGBUFFER_INIT(); + norns_msgbuffer_t req_buf = MSGBUFFER_INIT(); + norns_msgbuffer_t resp_buf = MSGBUFFER_INIT(); libcontext_t* ctx = get_context(); @@ -384,7 +384,7 @@ connect_to_daemon(const char* socket_path) { } static int -send_message(int conn, const msgbuffer_t* buffer) { +send_message(int conn, const norns_msgbuffer_t* buffer) { if(buffer == NULL || buffer->b_data == NULL || buffer->b_size == 0) { return -1; @@ -412,7 +412,7 @@ send_message(int conn, const msgbuffer_t* buffer) { } static int -recv_message(int conn, msgbuffer_t* buffer) { +recv_message(int conn, norns_msgbuffer_t* buffer) { // first of all read the message prefix and decode it // so that we know how much data to receive diff --git a/lib/requests.c b/lib/requests.c index 888cb7e..3751fb9 100644 --- a/lib/requests.c +++ b/lib/requests.c @@ -705,7 +705,7 @@ free_task_msg(Norns__Rpc__Request__Task* msg) { } int -pack_to_buffer(norns_rpc_type_t type, msgbuffer_t* buf, ...) { +pack_to_buffer(norns_rpc_type_t type, norns_msgbuffer_t* buf, ...) { Norns__Rpc__Request* req_msg = NULL; void* req_buf = NULL; @@ -748,7 +748,7 @@ cleanup_on_error: } int -unpack_from_buffer(msgbuffer_t* buf, norns_response_t* response) { +unpack_from_buffer(norns_msgbuffer_t* buf, norns_response_t* response) { Norns__Rpc__Response* rpc_resp = NULL; void* resp_buf = buf->b_data; diff --git a/lib/requests.h b/lib/requests.h index fd4f224..36cf279 100644 --- a/lib/requests.h +++ b/lib/requests.h @@ -60,7 +60,7 @@ typedef enum { typedef struct { void* b_data; size_t b_size; -} msgbuffer_t; +} norns_msgbuffer_t; #define MSGBUFFER_INIT() \ { .b_data = 0, \ @@ -85,8 +85,8 @@ typedef struct { }; } norns_response_t; -int pack_to_buffer(norns_rpc_type_t type, msgbuffer_t* buf, ...); -int unpack_from_buffer(msgbuffer_t* buf, norns_response_t* response); +int pack_to_buffer(norns_rpc_type_t type, norns_msgbuffer_t* buf, ...); +int unpack_from_buffer(norns_msgbuffer_t* buf, norns_response_t* response); #pragma GCC visibility pop -- GitLab From 66f78848cdbced3950c211eb67f9db8dc041dafa Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Tue, 28 Aug 2018 18:06:54 +0200 Subject: [PATCH 4/8] Rename norns_rpc_type_t to norns_msgtype_t --- lib/communication.c | 10 +++++----- lib/communication.h | 6 +++--- lib/requests.c | 12 ++++++------ lib/requests.h | 6 +++--- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/communication.c b/lib/communication.c index 1e2db77..4ce9adf 100644 --- a/lib/communication.c +++ b/lib/communication.c @@ -52,7 +52,7 @@ static int recv_message(int conn, norns_msgbuffer_t* buffer); static ssize_t recv_data(int conn, void* data, size_t size); static ssize_t send_data(int conn, const void* data, size_t size); static void print_hex(void* buffer, size_t bytes) __attribute__((unused)); -static norns_error_t send_request(norns_rpc_type_t type, norns_response_t* resp, ...); +static norns_error_t send_request(norns_msgtype_t type, norns_response_t* resp, ...); norns_error_t send_submit_request(norns_iotask_t* task) { @@ -147,7 +147,7 @@ send_ping_request() { } norns_error_t -send_job_request(norns_rpc_type_t type, uint32_t jobid, nornsctl_job_t* job) { +send_job_request(norns_msgtype_t type, uint32_t jobid, nornsctl_job_t* job) { int res; norns_response_t resp; @@ -166,7 +166,7 @@ send_job_request(norns_rpc_type_t type, uint32_t jobid, nornsctl_job_t* job) { norns_error_t -send_process_request(norns_rpc_type_t type, uint32_t jobid, +send_process_request(norns_msgtype_t type, uint32_t jobid, uid_t uid, gid_t gid, pid_t pid) { int res; @@ -185,7 +185,7 @@ send_process_request(norns_rpc_type_t type, uint32_t jobid, } norns_error_t -send_namespace_request(norns_rpc_type_t type, const char* nsid, +send_namespace_request(norns_msgtype_t type, const char* nsid, nornsctl_backend_t* ns) { int res; @@ -204,7 +204,7 @@ send_namespace_request(norns_rpc_type_t type, const char* nsid, } static int -send_request(norns_rpc_type_t type, norns_response_t* resp, ...) { +send_request(norns_msgtype_t type, norns_response_t* resp, ...) { int res; int conn = -1; diff --git a/lib/communication.h b/lib/communication.h index b47de8d..17b466d 100644 --- a/lib/communication.h +++ b/lib/communication.h @@ -34,11 +34,11 @@ norns_error_t send_submit_request(norns_iotask_t* task); norns_error_t send_status_request(norns_iotask_t* task, norns_stat_t* stats); -norns_error_t send_job_request(norns_rpc_type_t type, uint32_t jobid, +norns_error_t send_job_request(norns_msgtype_t type, uint32_t jobid, nornsctl_job_t* job); -norns_error_t send_process_request(norns_rpc_type_t type, uint32_t jobid, +norns_error_t send_process_request(norns_msgtype_t type, uint32_t jobid, uid_t uid, gid_t gid, pid_t pid); -norns_error_t send_namespace_request(norns_rpc_type_t type, const char* nsid, +norns_error_t send_namespace_request(norns_msgtype_t type, const char* nsid, nornsctl_backend_t* backend); norns_error_t send_control_status_request(nornsctl_stat_t* stats); norns_error_t send_ping_request() __attribute__((deprecated)); diff --git a/lib/requests.c b/lib/requests.c index 3751fb9..ab5cf90 100644 --- a/lib/requests.c +++ b/lib/requests.c @@ -78,12 +78,12 @@ static void free_path_msg(Norns__Rpc__Request__Task__PosixPath* msg); static int -encode_request_type(norns_rpc_type_t type); -static norns_rpc_type_t +encode_request_type(norns_msgtype_t type); +static norns_msgtype_t decode_response_type(int type); static int -encode_request_type(norns_rpc_type_t type) { +encode_request_type(norns_msgtype_t type) { switch(type) { case NORNS_IOTASK_SUBMIT: return NORNS__RPC__REQUEST__TYPE__IOTASK_SUBMIT; @@ -114,7 +114,7 @@ encode_request_type(norns_rpc_type_t type) { } } -static norns_rpc_type_t +static norns_msgtype_t decode_response_type(int norns_rpc_type) { switch(norns_rpc_type) { case NORNS__RPC__RESPONSE__TYPE__IOTASK_SUBMIT: @@ -149,7 +149,7 @@ decode_response_type(int norns_rpc_type) { } Norns__Rpc__Request* -build_request_msg(norns_rpc_type_t type, va_list ap) { +build_request_msg(norns_msgtype_t type, va_list ap) { Norns__Rpc__Request* req_msg = NULL; @@ -705,7 +705,7 @@ free_task_msg(Norns__Rpc__Request__Task* msg) { } int -pack_to_buffer(norns_rpc_type_t type, norns_msgbuffer_t* buf, ...) { +pack_to_buffer(norns_msgtype_t type, norns_msgbuffer_t* buf, ...) { Norns__Rpc__Request* req_msg = NULL; void* req_buf = NULL; diff --git a/lib/requests.h b/lib/requests.h index 36cf279..66c1bc7 100644 --- a/lib/requests.h +++ b/lib/requests.h @@ -55,7 +55,7 @@ typedef enum { NORNS_NAMESPACE_UNREGISTER, /* other */ NORNS_BAD_RPC -} norns_rpc_type_t; +} norns_msgtype_t; typedef struct { void* b_data; @@ -68,7 +68,7 @@ typedef struct { } typedef struct { - norns_rpc_type_t r_type; + norns_msgtype_t r_type; int r_error_code; union { size_t r_taskid; @@ -85,7 +85,7 @@ typedef struct { }; } norns_response_t; -int pack_to_buffer(norns_rpc_type_t type, norns_msgbuffer_t* buf, ...); +int pack_to_buffer(norns_msgtype_t type, norns_msgbuffer_t* buf, ...); int unpack_from_buffer(norns_msgbuffer_t* buf, norns_response_t* response); #pragma GCC visibility pop -- GitLab From 622f34fe3b5eba9367d7ddd07158299f8294f40f Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Wed, 29 Aug 2018 15:17:43 +0200 Subject: [PATCH 5/8] First implementation of nornsctl_send_command() The nornsctl_send_command() function allows administrative applications such as SLURM to send control commands to the urd server to control its behavior or to query specific information from it. Accepted commands: - NORNSCTL_COMMAND_PAUSE_ACCEPT: Stop accepting incoming tasks. - NORNSCTL_COMMAND_RESUME_ACCEPT: Resume accepting incoming tasks after a successful NORNSCTL_COMMAND_PAUSE_ACCEPT has been received. - NORNSCTL_COMMAND_PING: Check whether the server is up and running. --- include/norns/norns_error.h | 1 + include/norns/nornsctl_types.h | 12 ++++- lib/communication.c | 31 ++++++++++++ lib/communication.h | 1 + lib/errors.c | 8 +-- lib/libnornsctl.c | 11 ++-- lib/requests.c | 45 +++++++++++++++++ lib/requests.h | 3 ++ rpc/messages.proto | 16 ++++-- src/api/request.cpp | 38 ++++++++++++++ src/api/request.hpp | 6 +++ src/api/response.cpp | 2 + src/api/response.hpp | 5 ++ src/common/types.cpp | 2 + src/common/types.hpp | 9 ++++ src/urd.cpp | 45 ++++++++++++++++- src/urd.hpp | 3 ++ tests/Makefile.am | 1 + tests/api-send-command.cpp | 92 ++++++++++++++++++++++++++++++++++ 19 files changed, 318 insertions(+), 13 deletions(-) create mode 100644 tests/api-send-command.cpp diff --git a/include/norns/norns_error.h b/include/norns/norns_error.h index 167889f..d9d5b83 100644 --- a/include/norns/norns_error.h +++ b/include/norns/norns_error.h @@ -50,6 +50,7 @@ extern "C" { #define NORNS_ECONNFAILED -5 #define NORNS_ERPCSENDFAILED -6 #define NORNS_ERPCRECVFAILED -7 +#define NORNS_EACCEPTPAUSED -8 /* errors about jobs */ #define NORNS_EJOBEXISTS -10 diff --git a/include/norns/nornsctl_types.h b/include/norns/nornsctl_types.h index aacfa0e..07b8fb9 100644 --- a/include/norns/nornsctl_types.h +++ b/include/norns/nornsctl_types.h @@ -34,9 +34,17 @@ extern "C" { #include "norns_types.h" -/* Types */ +/* Additional administrative types */ typedef uint32_t nornsctl_backend_flags_t; -typedef uint32_t nornsctl_command_t; +//typedef uint32_t nornsctl_command_t; + +/* Administrative command IDs valid for nornsctl_send_command() */ +typedef enum { + NORNSCTL_COMMAND_PING = 1000, + NORNSCTL_COMMAND_PAUSE_ACCEPT, + NORNSCTL_COMMAND_RESUME_ACCEPT, +} nornsctl_command_t; + #ifdef __cplusplus }; diff --git a/lib/communication.c b/lib/communication.c index 4ce9adf..422e85e 100644 --- a/lib/communication.c +++ b/lib/communication.c @@ -81,6 +81,25 @@ send_submit_request(norns_iotask_t* task) { return resp.r_error_code; } +norns_error_t +send_control_command_request(nornsctl_command_t cmd, void* args) { + + int res; + norns_response_t resp; + + if((res = send_request(NORNSCTL_COMMAND, &resp, cmd, args)) + != NORNS_SUCCESS) { + return res; + } + + if(resp.r_type != NORNSCTL_COMMAND) { + return NORNS_ESNAFU; + } + + return NORNS_SUCCESS; +} + + norns_error_t send_status_request(norns_iotask_t* task, norns_stat_t* stats) { @@ -245,6 +264,18 @@ send_request(norns_msgtype_t type, norns_response_t* resp, ...) { break; } + case NORNSCTL_COMMAND: + { + const nornsctl_command_t cmd = va_arg(ap, nornsctl_command_t); + const void* args = va_arg(ap, const void*); + + if((res = pack_to_buffer(type, &req_buf, cmd, args)) + != NORNS_SUCCESS) { + return res; + } + break; + } + case NORNSCTL_GLOBAL_STATUS: case NORNS_PING: { diff --git a/lib/communication.h b/lib/communication.h index 17b466d..e055ee3 100644 --- a/lib/communication.h +++ b/lib/communication.h @@ -33,6 +33,7 @@ #pragma GCC visibility push(hidden) norns_error_t send_submit_request(norns_iotask_t* task); +norns_error_t send_control_command_request(nornsctl_command_t cmd, void* args); norns_error_t send_status_request(norns_iotask_t* task, norns_stat_t* stats); norns_error_t send_job_request(norns_msgtype_t type, uint32_t jobid, nornsctl_job_t* job); diff --git a/lib/errors.c b/lib/errors.c index b28c206..91b407e 100644 --- a/lib/errors.c +++ b/lib/errors.c @@ -30,19 +30,17 @@ #define ERR_REMAP(n) ((n) < 0 ? -(n) : (n)) const char* const norns_errlist[NORNS_ERRMAX + 1] = { - /* misc errors */ [ERR_REMAP(NORNS_SUCCESS)] = "Success", [ERR_REMAP(NORNS_ESNAFU)] = "Internal error", [ERR_REMAP(NORNS_EBADREQUEST)] = "Bad request", [ERR_REMAP(NORNS_EBADARGS)] = "Bad arguments", [ERR_REMAP(NORNS_ENOMEM)] = "Cannot allocate memory", - [ERR_REMAP(NORNS_ENOTSUPPORTED)] = "Not supported", - [ERR_REMAP(NORNS_ESYSTEMERROR)] = "Operating system error", /* communication errors */ [ERR_REMAP(NORNS_ECONNFAILED)] = "Cannot connect to daemon", [ERR_REMAP(NORNS_ERPCSENDFAILED)] = "Cannot send requests to daemon", [ERR_REMAP(NORNS_ERPCRECVFAILED)] = "Cannot receive responses from daemon", + [ERR_REMAP(NORNS_EACCEPTPAUSED)] = "Daemon does not accept new tasks", /* job errors */ [ERR_REMAP(NORNS_EJOBEXISTS)] = "Job already exists", @@ -61,6 +59,10 @@ const char* const norns_errlist[NORNS_ERRMAX + 1] = { [ERR_REMAP(NORNS_ENOSUCHTASK)] = "Task does not exist", [ERR_REMAP(NORNS_ETOOMANYTASKS)] = "Too many pending tasks", + /* misc errors */ + [ERR_REMAP(NORNS_ENOTSUPPORTED)] = "Not supported", + [ERR_REMAP(NORNS_ESYSTEMERROR)] = "Operating system error", + /* fallback */ [ERR_REMAP(NORNS_ERRMAX)] = "Unknown error", diff --git a/lib/libnornsctl.c b/lib/libnornsctl.c index 192e634..66f437c 100644 --- a/lib/libnornsctl.c +++ b/lib/libnornsctl.c @@ -156,11 +156,14 @@ nornsctl_ping(void) { norns_error_t nornsctl_send_command(nornsctl_command_t command, void* args) { - // TODO - (void) command; - (void) args; - return NORNS_SUCCESS; + // we don't have any commands right now that support arguments + if(args != NULL) { + ERR("invalid arguments"); + return NORNS_EBADARGS; + } + + return send_control_command_request(command, args); } norns_error_t diff --git a/lib/requests.c b/lib/requests.c index ab5cf90..b0b0d55 100644 --- a/lib/requests.c +++ b/lib/requests.c @@ -77,6 +77,11 @@ build_path_msg(const norns_posix_path_t* path); static void free_path_msg(Norns__Rpc__Request__Task__PosixPath* msg); +static Norns__Rpc__Request__Command* +build_command_msg(const nornsctl_command_t cmd, const void* args); +static void +free_command_msg(Norns__Rpc__Request__Command* msg) __attribute__((unused)); + static int encode_request_type(norns_msgtype_t type); static norns_msgtype_t @@ -109,6 +114,8 @@ encode_request_type(norns_msgtype_t type) { return NORNS__RPC__REQUEST__TYPE__NAMESPACE_UNREGISTER; case NORNSCTL_GLOBAL_STATUS: return NORNS__RPC__REQUEST__TYPE__GLOBAL_STATUS; + case NORNSCTL_COMMAND: + return NORNS__RPC__REQUEST__TYPE__CTL_COMMAND; default: return -1; } @@ -141,6 +148,8 @@ decode_response_type(int norns_rpc_type) { return NORNS_NAMESPACE_UNREGISTER; case NORNS__RPC__RESPONSE__TYPE__GLOBAL_STATUS: return NORNSCTL_GLOBAL_STATUS; + case NORNS__RPC__REQUEST__TYPE__CTL_COMMAND: + return NORNSCTL_COMMAND; case NORNS__RPC__RESPONSE__TYPE__BAD_REQUEST: // intentionally fall through default: @@ -165,6 +174,19 @@ build_request_msg(norns_msgtype_t type, va_list ap) { } switch(type) { + + case NORNSCTL_COMMAND: + { + const nornsctl_command_t cmd = va_arg(ap, nornsctl_command_t); + const void* args = va_arg(ap, void*); + + if((req_msg->command = build_command_msg(cmd, args)) == NULL) { + goto cleanup_on_error; + } + + break; + } + case NORNS_IOTASK_SUBMIT: case NORNS_IOTASK_STATUS: { @@ -704,6 +726,29 @@ free_task_msg(Norns__Rpc__Request__Task* msg) { xfree(msg); } +Norns__Rpc__Request__Command* +build_command_msg(const nornsctl_command_t cmd, const void* args) { + + (void) args; + + Norns__Rpc__Request__Command* msg = xmalloc(sizeof(*msg)); + + if(msg == NULL) { + return NULL; + } + + norns__rpc__request__command__init(msg); + msg->id = cmd; + + return msg; +} + +void +free_command_msg(Norns__Rpc__Request__Command* msg) { + // TODO + (void) msg; +} + int pack_to_buffer(norns_msgtype_t type, norns_msgbuffer_t* buf, ...) { diff --git a/lib/requests.h b/lib/requests.h index 66c1bc7..b6d228e 100644 --- a/lib/requests.h +++ b/lib/requests.h @@ -40,6 +40,9 @@ typedef enum { NORNSCTL_GLOBAL_STATUS, + /* control commands */ + NORNSCTL_COMMAND, + NORNS_PING, /* jobs */ diff --git a/rpc/messages.proto b/rpc/messages.proto index 09c0f29..f0b93da 100644 --- a/rpc/messages.proto +++ b/rpc/messages.proto @@ -8,6 +8,7 @@ message Request { IOTASK_SUBMIT = 1; IOTASK_STATUS = 2; PING = 3; + JOB_REGISTER = 4; JOB_UPDATE = 5; JOB_UNREGISTER = 6; @@ -17,7 +18,8 @@ message Request { NAMESPACE_UPDATE = 10; NAMESPACE_UNREGISTER = 11; - GLOBAL_STATUS = 12; + GLOBAL_STATUS = 1000; + CTL_COMMAND = 1001; } // I/O task descriptor @@ -80,12 +82,18 @@ message Request { required int32 quota = 2; } + // command descriptor + message Command { + required uint32 id = 1; + } + required Type type = 1; optional Task task = 2; optional uint32 jobid = 3; optional Job job = 4; optional Process process = 5; optional Namespace nspace = 6; + optional Command command = 7; } message Response { @@ -105,8 +113,10 @@ message Response { NAMESPACE_UPDATE = 10; NAMESPACE_UNREGISTER = 11; - GLOBAL_STATUS = 12; - BAD_REQUEST = 13; + GLOBAL_STATUS = 1000; + CTL_COMMAND = 1001; + + BAD_REQUEST = 2000; } message TaskStats { diff --git a/src/api/request.cpp b/src/api/request.cpp index 3af1298..32062b7 100644 --- a/src/api/request.cpp +++ b/src/api/request.cpp @@ -72,6 +72,22 @@ norns::backend_type decode_backend_type(::google::protobuf::uint32 type) { } } +norns::command_type decode_command(::google::protobuf::uint32 type) { + + using norns::command_type; + + switch(type) { + case NORNSCTL_COMMAND_PING: + return command_type::ping; + case NORNSCTL_COMMAND_PAUSE_ACCEPT: + return command_type::pause_accept; + case NORNSCTL_COMMAND_RESUME_ACCEPT: + return command_type::resume_accept; + default: + return command_type::unknown; + } +} + bool is_valid(const norns::rpc::Request_Task_Resource& res) { if(!(res.type() & (NORNS_PROCESS_MEMORY | NORNS_POSIX_PATH))) { @@ -216,6 +232,14 @@ request_ptr request::create_from_buffer(const std::vector& buffer, int case norns::rpc::Request::GLOBAL_STATUS: return std::make_unique(); + case norns::rpc::Request::CTL_COMMAND: + + if(rpc_req.has_command()) { + command_type cmd = ::decode_command(rpc_req.command().id()); + return std::make_unique(cmd); + } + break; + case norns::rpc::Request::JOB_REGISTER: case norns::rpc::Request::JOB_UPDATE: @@ -357,6 +381,20 @@ std::string global_status_request::to_string() const { return "GLOBAL_STATUS"; } +template<> +std::string command_request::to_string() const { + switch(this->get<0>()) { + case command_type::ping: + return "PING"; + case command_type::pause_accept: + return "PAUSE_ACCEPT"; + case command_type::resume_accept: + return "RESUME_ACCEPT"; + default: + return "UNKNOWN"; + } +} + template<> std::string ping_request::to_string() const { return "PING"; diff --git a/src/api/request.hpp b/src/api/request.hpp index 1f144b6..0d24f1d 100644 --- a/src/api/request.hpp +++ b/src/api/request.hpp @@ -78,6 +78,7 @@ enum class request_type { iotask_create, iotask_status, global_status, + command, ping, job_register, job_update, @@ -259,6 +260,11 @@ using global_status_request = detail::request_impl< request_type::global_status >; +using command_request = detail::request_impl< + request_type::command, + command_type +>; + } // namespace api } // namespace norns diff --git a/src/api/response.cpp b/src/api/response.cpp index 1070a03..fbcfcbb 100644 --- a/src/api/response.cpp +++ b/src/api/response.cpp @@ -61,6 +61,8 @@ norns::rpc::Response_Type encode(norns::api::response_type type) { return norns::rpc::Response::NAMESPACE_UNREGISTER; case response_type::global_status: return norns::rpc::Response::GLOBAL_STATUS; + case response_type::command: + return norns::rpc::Response::CTL_COMMAND; case response_type::bad_request: return norns::rpc::Response::BAD_REQUEST; default: diff --git a/src/api/response.hpp b/src/api/response.hpp index fec814c..27ea49b 100644 --- a/src/api/response.hpp +++ b/src/api/response.hpp @@ -55,6 +55,7 @@ enum class response_type { iotask_create, iotask_status, global_status, + command, ping, job_register, job_update, @@ -190,6 +191,10 @@ using global_status_response = detail::response_impl< io::global_stats >; +using command_response = detail::response_impl< + response_type::command +>; + using bad_request_response = detail::response_impl< response_type::bad_request >; diff --git a/src/common/types.cpp b/src/common/types.cpp index 0b001f4..e2b73d9 100644 --- a/src/common/types.cpp +++ b/src/common/types.cpp @@ -99,6 +99,8 @@ std::string to_string(urd_error ecode) { return "NORNS_ENOSUCHTASK"; case urd_error::too_many_tasks: return "NORNS_ETOOMANYTASKS"; + case urd_error::accept_paused: + return "NORNS_EACCEPTPAUSED"; default: return "UNKNOWN_ERROR"; } diff --git a/src/common/types.hpp b/src/common/types.hpp index e20156d..90dce2a 100644 --- a/src/common/types.hpp +++ b/src/common/types.hpp @@ -33,6 +33,7 @@ #include #include "norns.h" +#include "nornsctl.h" #ifndef __URD_TYPES_HPP__ #define __URD_TYPES_HPP__ @@ -60,6 +61,13 @@ enum class backend_type { unknown }; +enum class command_type { + ping, + pause_accept, + resume_accept, + unknown +}; + /*! Error codes */ enum class urd_error : norns_error_t { success = NORNS_SUCCESS, @@ -76,6 +84,7 @@ enum class urd_error : norns_error_t { connection_failed = NORNS_ECONNFAILED, rpc_send_failed = NORNS_ERPCSENDFAILED, rpc_recv_failed = NORNS_ERPCRECVFAILED, + accept_paused = NORNS_EACCEPTPAUSED, /* errors about jobs */ job_exists = NORNS_EJOBEXISTS, diff --git a/src/urd.cpp b/src/urd.cpp index a7aff02..c3dee80 100644 --- a/src/urd.cpp +++ b/src/urd.cpp @@ -212,9 +212,15 @@ response_ptr urd::iotask_create_handler(const request_ptr base_request) { response_ptr resp; iotask_id tid = 0; + boost::optional auth; urd_error rv = urd_error::success; - const auto auth = request->credentials(); + if(m_is_paused) { + rv = urd_error::accept_paused; + goto log_and_return; + } + + auth = request->credentials(); if(!auth) { LOGGER_CRITICAL("Request without credentials"); @@ -571,6 +577,39 @@ response_ptr urd::global_status_handler(const request_ptr /*base_request*/) { return std::move(resp); } +response_ptr +urd::command_handler(const request_ptr base_request) { + + // downcast the generic request to the concrete implementation + auto request = + utils::static_unique_ptr_cast( + std::move(base_request)); + auto resp = std::make_unique(); + resp->set_error_code(urd_error::success); + + switch(request->get<0>()) { + case command_type::ping: + break; // nothing special to do here + case command_type::pause_accept: + if(!m_is_paused) { + m_is_paused = true; + } + break; + case command_type::resume_accept: + if(m_is_paused) { + m_is_paused = false; + } + break; + case command_type::unknown: + resp->set_error_code(urd_error::bad_args); + break; + } + + LOGGER_INFO("COMMAND({}) = {}", request->to_string(), resp->to_string()); + return std::move(resp); +} + + response_ptr urd::unknown_request_handler(const request_ptr /*base_request*/) { response_ptr resp = std::make_unique(); @@ -762,6 +801,10 @@ void urd::init_event_handlers() { api::request_type::global_status, std::bind(&urd::global_status_handler, this, std::placeholders::_1)); + m_api_listener->register_callback( + api::request_type::command, + std::bind(&urd::command_handler, this, std::placeholders::_1)); + m_api_listener->register_callback( api::request_type::bad_request, std::bind(&urd::unknown_request_handler, this, std::placeholders::_1)); diff --git a/src/urd.hpp b/src/urd.hpp index 953d8a3..9880514 100644 --- a/src/urd.hpp +++ b/src/urd.hpp @@ -113,6 +113,7 @@ private: response_ptr namespace_update_handler(const request_ptr req); response_ptr namespace_remove_handler(const request_ptr req); response_ptr global_status_handler(const request_ptr req); + response_ptr command_handler(const request_ptr req); response_ptr unknown_request_handler(const request_ptr req); // TODO: add helpers for remove and update @@ -121,6 +122,8 @@ private: const bfs::path& mount, uint32_t quota); private: + std::atomic m_is_paused; + std::shared_ptr m_settings; std::unique_ptr m_transferor_registry; diff --git a/tests/Makefile.am b/tests/Makefile.am index fbc3f0a..90cb0e8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -60,6 +60,7 @@ api_SOURCES = \ api-task-init.cpp \ api-task-submit.cpp \ api-task-status.cpp \ + api-send-command.cpp \ compare-files.cpp \ compare-files.hpp \ config-template.cpp \ diff --git a/tests/api-send-command.cpp b/tests/api-send-command.cpp new file mode 100644 index 0000000..2dc0133 --- /dev/null +++ b/tests/api-send-command.cpp @@ -0,0 +1,92 @@ +/************************************************************************* + * Copyright (C) 2017-2018 Barcelona Supercomputing Center * + * Centro Nacional de Supercomputacion * + * All rights reserved. * + * * + * This file is part of the NORNS Data Scheduler, a service that allows * + * other programs to start, track and manage asynchronous transfers of * + * data resources transfers requests between different storage backends. * + * * + * See AUTHORS file in the top level directory for information * + * regarding developers and contributors. * + * * + * The NORNS Data Scheduler is free software: you can redistribute it * + * and/or modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation, either * + * version 3 of the License, or (at your option) any later version. * + * * + * The NORNS Data Scheduler 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General * + * Public License along with the NORNS Data Scheduler. If not, see * + * . * + *************************************************************************/ + +#include "norns.h" +#include "nornsctl.h" +#include "test-env.hpp" +#include "catch.hpp" + +SCENARIO("send control commands to urd", "[api::nornsctl_send_command]") { + GIVEN("a running urd instance") { + + test_env env( + fake_daemon_cfg { + true /* dry_run? */ + } + ); + + const char* nsid0 = "tmp0"; + bfs::path src_mnt; + std::tie(std::ignore, src_mnt) = env.create_namespace(nsid0, "mnt/tmp0", 16384); + + WHEN("a NORNSCTL_COMMAND_PAUSE_ACCEPT command is sent") { + + norns_error_t rv = nornsctl_send_command(NORNSCTL_COMMAND_PAUSE_ACCEPT, NULL); + + THEN("nornsctl_send_command() returns NORNS_SUCCESS") { + REQUIRE(rv == NORNS_SUCCESS); + + AND_THEN("norns_submit() returns NORNS_EACCEPTPAUSED") { + norns_iotask_t task = + NORNS_IOTASK(NORNS_IOTASK_COPY, + NORNS_MEMORY_REGION((void*)0xdeadbeef, 42), + NORNS_LOCAL_PATH(nsid0, "foobar")); + + rv = norns_submit(&task); + REQUIRE(rv == NORNS_EACCEPTPAUSED); + + AND_THEN("nornsctl_send_command() returns NORNS_SUCCESS and norns_submit() succeeds") { + norns_error_t rv = nornsctl_send_command(NORNSCTL_COMMAND_RESUME_ACCEPT, NULL); + REQUIRE(rv == NORNS_SUCCESS); + + rv = norns_submit(&task); + REQUIRE(rv == NORNS_SUCCESS); + REQUIRE(task.t_id == 1); + } + } + } + } + + WHEN("a NORNSCTL_COMMAND_RESUME_ACCEPT command is sent") { + + norns_error_t rv = nornsctl_send_command(NORNSCTL_COMMAND_RESUME_ACCEPT, NULL); + + THEN("nornsctl_send_command() returns NORNS_SUCCESS") { + REQUIRE(rv == NORNS_SUCCESS); + } + } + + WHEN("a NORNSCTL_COMMAND_PING command is sent") { + + norns_error_t rv = nornsctl_send_command(NORNSCTL_COMMAND_PING, NULL); + + THEN("nornsctl_send_command() returns NORNS_SUCCESS") { + REQUIRE(rv == NORNS_SUCCESS); + } + } + } +} -- GitLab From 1f57d2cd95bddb5f100cf1d82c23df6c9abaae65 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Wed, 29 Aug 2018 15:25:28 +0200 Subject: [PATCH 6/8] Add new tests to .gitlab-ci.yml --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a99d2cc..4151aff 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -156,6 +156,7 @@ test:ubuntu:latest: - NORNS_DEBUG_CONFIG_FILE_OVERRIDE=1 ./api -as "[api::norns_submit]" - NORNS_DEBUG_CONFIG_FILE_OVERRIDE=1 ./api -as "[api::norns_status]" - NORNS_DEBUG_CONFIG_FILE_OVERRIDE=1 ./api -as "[api::nornsctl_status]" + - NORNS_DEBUG_CONFIG_FILE_OVERRIDE=1 ./api -as "[api::nornsctl_send_command]" after_script: - pwd - if [[ -e tests.log ]]; -- GitLab From 428c13c66252551a05df014e80f1ec976654a53d Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Wed, 29 Aug 2018 15:43:02 +0200 Subject: [PATCH 7/8] Remove deprecated nornsctl_ping() function It has been decided to remove the deprectated nornsctl_ping() function from libnornsctl.so, since an equivalent functionality is now supported using the new nornsctl_send_command() function and its NORNSCTL_COMMAND_PING argument. Therefore, any such invocation: norns_error_t rv = nornsctl_ping(); can now be replicated as: norns_error_t rv = nornsctl_send_command(NORNSCTL_COMMAND_PING, NULL); --- .gitlab-ci.yml | 1 - include/norns/nornsctl.h | 4 --- lib/communication.c | 17 ----------- lib/communication.h | 1 - lib/libnornsctl.c | 5 ---- tests/Makefile.am | 1 - tests/api-ping.cpp | 64 ---------------------------------------- tests/fake-daemon.cpp | 2 +- 8 files changed, 1 insertion(+), 94 deletions(-) delete mode 100644 tests/api-ping.cpp diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4151aff..1655851 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -143,7 +143,6 @@ test:ubuntu:latest: - NORNS_DEBUG_CONFIG_FILE_OVERRIDE=1 ./api -as "[api::nornsctl_register_job]" - NORNS_DEBUG_CONFIG_FILE_OVERRIDE=1 ./api -as "[api::nornsctl_update_job]" - NORNS_DEBUG_CONFIG_FILE_OVERRIDE=1 ./api -as "[api::nornsctl_unregister_job]" - - NORNS_DEBUG_CONFIG_FILE_OVERRIDE=1 ./api -as "[api::nornsctl_ping]" - NORNS_DEBUG_CONFIG_FILE_OVERRIDE=1 ./api -as "[api::nornsctl_add_process]" - NORNS_DEBUG_CONFIG_FILE_OVERRIDE=1 ./api -as "[api::nornsctl_remove_process]" - NORNS_DEBUG_CONFIG_FILE_OVERRIDE=1 ./api -as "[api::norns_resource_init]" diff --git a/include/norns/nornsctl.h b/include/norns/nornsctl.h index 237d456..2d4bb87 100644 --- a/include/norns/nornsctl.h +++ b/include/norns/nornsctl.h @@ -120,10 +120,6 @@ nornsctl_job_init(nornsctl_job_t* job, nornsctl_job_limit_t** limits, size_t nlimits) __THROW; -/* Check if the service daemon is running */ -norns_error_t -nornsctl_ping(void) __THROW __attribute__((deprecated)); - /* Send a command to the service daemon */ norns_error_t nornsctl_send_command(nornsctl_command_t command, diff --git a/lib/communication.c b/lib/communication.c index 422e85e..263a5d5 100644 --- a/lib/communication.c +++ b/lib/communication.c @@ -148,23 +148,6 @@ send_control_status_request(nornsctl_stat_t* stats) { return resp.r_error_code; } -norns_error_t -send_ping_request() { - - int res; - norns_response_t resp; - - if((res = send_request(NORNS_PING, &resp)) != NORNS_SUCCESS) { - return res; - } - - if(resp.r_type != NORNS_PING) { - return NORNS_ESNAFU; - } - - return resp.r_error_code; -} - norns_error_t send_job_request(norns_msgtype_t type, uint32_t jobid, nornsctl_job_t* job) { diff --git a/lib/communication.h b/lib/communication.h index e055ee3..02be182 100644 --- a/lib/communication.h +++ b/lib/communication.h @@ -42,7 +42,6 @@ norns_error_t send_process_request(norns_msgtype_t type, uint32_t jobid, norns_error_t send_namespace_request(norns_msgtype_t type, const char* nsid, nornsctl_backend_t* backend); norns_error_t send_control_status_request(nornsctl_stat_t* stats); -norns_error_t send_ping_request() __attribute__((deprecated)); #pragma GCC visibility pop diff --git a/lib/libnornsctl.c b/lib/libnornsctl.c index 66f437c..cccbbc9 100644 --- a/lib/libnornsctl.c +++ b/lib/libnornsctl.c @@ -148,11 +148,6 @@ libnornsctl_reload_config_file(void) { #endif /* Control API */ -norns_error_t -nornsctl_ping(void) { - return send_ping_request(); -} - norns_error_t nornsctl_send_command(nornsctl_command_t command, void* args) { diff --git a/tests/Makefile.am b/tests/Makefile.am index 90cb0e8..cadfce6 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -53,7 +53,6 @@ api_SOURCES = \ api-job-register.cpp \ api-job-update.cpp \ api-job-unregister.cpp \ - api-ping.cpp \ api-process-add.cpp \ api-process-remove.cpp \ api-resource-init.cpp \ diff --git a/tests/api-ping.cpp b/tests/api-ping.cpp deleted file mode 100644 index a01e593..0000000 --- a/tests/api-ping.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/************************************************************************* - * Copyright (C) 2017-2018 Barcelona Supercomputing Center * - * Centro Nacional de Supercomputacion * - * All rights reserved. * - * * - * This file is part of the NORNS Data Scheduler, a service that allows * - * other programs to start, track and manage asynchronous transfers of * - * data resources transfers requests between different storage backends. * - * * - * See AUTHORS file in the top level directory for information * - * regarding developers and contributors. * - * * - * The NORNS Data Scheduler is free software: you can redistribute it * - * and/or modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation, either * - * version 3 of the License, or (at your option) any later version. * - * * - * The NORNS Data Scheduler 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 * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General * - * Public License along with the NORNS Data Scheduler. If not, see * - * . * - *************************************************************************/ - - -#include "norns.h" -#include "nornsctl.h" -#include "catch.hpp" -#include "fake-daemon.hpp" -#include "test-env.hpp" - -SCENARIO("ping request", "[api::nornsctl_ping]") { - GIVEN("a running urd instance") { - - test_env env; - - WHEN("pinging urd") { - - int rv = nornsctl_ping(); - - THEN("NORNS_SUCCESS is returned") { - REQUIRE(rv == NORNS_SUCCESS); - } - } - - env.notify_success(); - } - -#ifndef USE_REAL_DAEMON - GIVEN("a non-running urd instance") { - WHEN("pinging urd") { - - int rv = nornsctl_ping(); - - THEN("NORNS_ECONNFAILED is returned") { - REQUIRE(rv == NORNS_ECONNFAILED); - } - } - } -#endif -} diff --git a/tests/fake-daemon.cpp b/tests/fake-daemon.cpp index 0b094d6..87802f0 100644 --- a/tests/fake-daemon.cpp +++ b/tests/fake-daemon.cpp @@ -108,7 +108,7 @@ void fake_daemon::run() { do { std::this_thread::sleep_for(std::chrono::milliseconds(1)); - rv = nornsctl_ping(); + rv = nornsctl_send_command(NORNSCTL_COMMAND_PING, NULL); } while(rv != NORNS_SUCCESS && --retries != 0); if(retries == 0) { -- GitLab From 2d0e8200ae2798e99a3dc964fc363d9b38f237e1 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Wed, 29 Aug 2018 15:47:21 +0200 Subject: [PATCH 8/8] Fix wrong initialization of m_is_paused The member field m_is_paused in class urd was not being explicitly initialized by default, which caused norns_submit() to fail even if no NORNSCTL_COMMAND_PAUSE_ACCEPT had been sent to the urd daemon. --- src/urd.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/urd.cpp b/src/urd.cpp index c3dee80..c8b5129 100644 --- a/src/urd.cpp +++ b/src/urd.cpp @@ -59,6 +59,7 @@ namespace norns { urd::urd() : + m_is_paused(false), m_settings(std::make_shared()) {} urd::~urd() {} -- GitLab