Commit 622f34fe authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

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.
parent 66f78848
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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
+10 −2
Original line number Diff line number Diff line
@@ -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
};
+31 −0
Original line number Diff line number Diff line
@@ -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:
        {
+1 −0
Original line number Diff line number Diff line
@@ -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);
+5 −3
Original line number Diff line number Diff line
@@ -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",

Loading