]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Update SLURM loading:
authorpcarana <pc.moreno2099@gmail.com>
Thu, 11 Apr 2019 20:26:48 +0000 (15:26 -0500)
committerpcarana <pc.moreno2099@gmail.com>
Thu, 11 Apr 2019 20:26:48 +0000 (15:26 -0500)
-Remove slurm_check_interval configuration parameter since is unnecessary.
-Load multiple SLURM files from a configured location (must be a directory).

src/Makefile.am
src/configuration.c
src/configuration.h
src/main.c
src/slurm_loader.c [new file with mode: 0644]
src/slurm_loader.h [new file with mode: 0644]
src/slurm_parser.c
src/slurm_parser.h

index 3375adda9e0a4147a3bea992b1ee24eafe08c340..7041508cf94c242bc1e1ce96db917eee08f93cf4 100644 (file)
@@ -13,6 +13,7 @@ rtr_server_SOURCES += csv.c csv.h
 rtr_server_SOURCES += json_parser.c json_parser.h
 rtr_server_SOURCES += line_file.c line_file.h
 rtr_server_SOURCES += notify.c notify.h
+rtr_server_SOURCES += slurm_loader.c slurm_loader.h
 rtr_server_SOURCES += slurm_parser.c slurm_parser.h
 rtr_server_SOURCES += updates_daemon.c updates_daemon.h
 rtr_server_SOURCES += vrps.c vrps.h
index 422d433cfd191984ac047f78b5e1f6bc88c4596a..bc19c0cfefe8cc9bf8920cc51c7fd1dc568c0351 100644 (file)
@@ -24,7 +24,6 @@
 #define OPTNAME_RTR_INTERVAL_EXPIRE    "expire"
 #define OPTNAME_SLURM                  "slurm"
 #define OPTNAME_SLURM_LOCATION         "location"
-#define OPTNAME_SLURM_CHECK_INTERVAL   "checkInterval"
 
 #define DEFAULT_ADDR                   NULL
 #define DEFAULT_PORT                   "323"
@@ -35,7 +34,6 @@
 #define DEFAULT_RETRY_INTERVAL         600
 #define DEFAULT_EXPIRE_INTERVAL                7200
 #define DEFAULT_SLURM_LOCATION         NULL
-#define DEFAULT_SLURM_CHECK_INTERVAL   60
 
 /* Protocol timing parameters ranges in secs */
 #define MIN_VRPS_CHECK_INTERVAL                60
@@ -46,8 +44,6 @@
 #define MAX_RETRY_INTERVAL             7200
 #define MIN_EXPIRE_INTERVAL            600
 #define MAX_EXPIRE_INTERVAL            172800
-#define MIN_SLURM_CHECK_INTERVAL       60
-#define MAX_SLURM_CHECK_INTERVAL       7200
 
 /* Range values for other params */
 #define MIN_LISTEN_QUEUE               1
@@ -70,8 +66,6 @@ struct rtr_config {
        int expire_interval;
        /** SLURM location */
        char *slurm_location;
-       /** Interval used to look for updates at SLURM location */
-       int slurm_check_interval;
 } config;
 
 static int handle_json(json_t *);
@@ -253,7 +247,6 @@ load_slurm(json_t *root)
        struct stat attr;
        json_t *slurm;
        char const *slurm_location;
-       int slurm_check_interval;
        int error;
 
        slurm = json_object_get(root, OPTNAME_SLURM);
@@ -275,17 +268,8 @@ load_slurm(json_t *root)
                            OPTNAME_SLURM_LOCATION);
                        return -errno;
                }
-
-               error = load_range(slurm, OPTNAME_SLURM_CHECK_INTERVAL,
-                   DEFAULT_SLURM_CHECK_INTERVAL, &slurm_check_interval,
-                   MIN_SLURM_CHECK_INTERVAL, MAX_SLURM_CHECK_INTERVAL);
-               if (error)
-                       return error;
-               config.slurm_check_interval = slurm_check_interval;
-       } else {
+       } else
                config.slurm_location = DEFAULT_SLURM_LOCATION;
-               config.slurm_check_interval = DEFAULT_SLURM_CHECK_INTERVAL;
-       }
 
        /* Validate data (only if a value was set */
        if (config.slurm_location == NULL)
@@ -297,8 +281,8 @@ load_slurm(json_t *root)
                    config.slurm_location);
                return -errno;
        }
-       if (S_ISDIR(attr.st_mode) != 0) {
-               warnx("SLURM location '%s' isn't a file",
+       if (S_ISDIR(attr.st_mode) == 0) {
+               warnx("SLURM location '%s' isn't a directory",
                    config.slurm_location);
                return -EINVAL;
        }
@@ -489,9 +473,3 @@ config_get_slurm_location(void)
 {
        return config.slurm_location;
 }
-
-int
-config_get_slurm_check_interval(void)
-{
-       return config.slurm_check_interval;
-}
index 196a032daf8acca0cae76a57c72bebcac484ac4a..1fe7f1d0f11abaa0d947601448ca0ce1dfcca3c8 100644 (file)
@@ -16,6 +16,5 @@ int config_get_retry_interval(void);
 int config_get_expire_interval(void);
 
 char const *config_get_slurm_location(void);
-int config_get_slurm_check_interval(void);
 
 #endif /* _SRC_CONFIGURATION_H_ */
index 1f13a8858a3c433731836430fd1efbde873f0972..8d02dfff6a689f6da2d8323932bdd1f5f4271f02 100644 (file)
@@ -4,7 +4,7 @@
 #include <unistd.h>
 
 #include "rtr/rtr.h"
-#include "slurm_parser.h"
+#include "slurm_loader.h"
 #include "clients.h"
 #include "configuration.h"
 #include "csv.h"
diff --git a/src/slurm_loader.c b/src/slurm_loader.c
new file mode 100644 (file)
index 0000000..6a56fac
--- /dev/null
@@ -0,0 +1,93 @@
+#include "slurm_loader.h"
+
+#include <err.h>
+#include <errno.h>
+#include <dirent.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "configuration.h"
+#include "slurm_parser.h"
+
+#define SLURM_FILE_EXTENSION   ".slurm"
+
+static int
+single_slurm_load(const char *dir_name, const char *file_name)
+{
+       char *ext, *fullpath, *tmp;
+       int error;
+
+       ext = strrchr(file_name, '.');
+       /* Ignore file if extension isn't the expected */
+       if (ext == NULL || strcmp(ext, SLURM_FILE_EXTENSION) != 0)
+               return 0;
+
+       /* Get the full file path */
+       tmp = strdup(dir_name);
+       if (tmp == NULL) {
+               warn("Couldn't create temporal char for SLURM");
+               return -errno;
+       }
+       tmp = realloc(tmp, strlen(tmp) + 1 + strlen(file_name) + 1);
+       if (tmp == NULL) {
+               warn("Couldn't reallocate temporal char for SLURM");
+               return -errno;
+       }
+
+       strcat(tmp, "/");
+       strcat(tmp, file_name);
+       fullpath = realpath(tmp, NULL);
+       if (fullpath == NULL) {
+               warn("Error getting real path for file '%s' at dir '%s'",
+                   dir_name, file_name);
+               free(tmp);
+               return -errno;
+       }
+
+       error = slurm_parse(fullpath);
+       free(tmp);
+       free(fullpath);
+       return error;
+}
+
+int
+slurm_load(void)
+{
+       DIR *dir_loc;
+       struct dirent *dir_ent;
+       char const *slurm_dir;
+       int error;
+
+       /* Optional configuration */
+       slurm_dir = config_get_slurm_location();
+       if (slurm_dir == NULL)
+               return 0;
+
+       dir_loc = opendir(slurm_dir);
+       if (dir_loc == NULL) {
+               warn("Couldn't open dir %s", slurm_dir);
+               return -errno;
+       }
+
+       error = 0;
+       errno = 0;
+       while ((dir_ent = readdir(dir_loc)) != NULL) {
+               error = single_slurm_load(slurm_dir, dir_ent->d_name);
+               if (error)
+                       goto end;
+               errno = 0;
+       }
+       if (errno) {
+               warn("Error reading dir %s", slurm_dir);
+               error = -errno;
+       }
+end:
+       closedir(dir_loc);
+       return error;
+}
+
+void
+slurm_cleanup(void)
+{
+       /* TODO Nothing for now */
+}
diff --git a/src/slurm_loader.h b/src/slurm_loader.h
new file mode 100644 (file)
index 0000000..fdef9ca
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef SRC_SLURM_LOADER_H_
+#define SRC_SLURM_LOADER_H_
+
+int slurm_load(void);
+void slurm_cleanup(void);
+
+#endif /* SRC_SLURM_LOADER_H_ */
index 190f52f9a7987cd6d14f9b1a3dc1d834bf90a068..85665f9581ca1851a5863a92f410ac0266a46bd7 100644 (file)
@@ -8,7 +8,6 @@
 #include <openssl/evp.h>
 
 #include "address.h"
-#include "configuration.h"
 #include "crypto/base64.h"
 #include "json_parser.h"
 
@@ -61,18 +60,14 @@ struct slurm_bgpsec {
 static int handle_json(json_t *);
 
 int
-slurm_load(void)
+slurm_parse(char const *location)
 {
        json_t *json_root;
        json_error_t json_error;
        int error;
 
-       /* Optional configuration */
-       if (config_get_slurm_location() == NULL)
-               return 0;
-
-       json_root = json_load_file(config_get_slurm_location(),
-           JSON_REJECT_DUPLICATES, &json_error);
+       json_root = json_load_file(location, JSON_REJECT_DUPLICATES,
+           &json_error);
        if (json_root == NULL) {
                warnx("SLURM JSON error on line %d, column %d: %s",
                    json_error.line, json_error.column, json_error.text);
@@ -85,12 +80,6 @@ slurm_load(void)
        return error;
 }
 
-void
-slurm_cleanup(void)
-{
-       /* TODO Nothing for now */
-}
-
 /*
  * TODO Maybe some of the parsing functions can be on a common place, since
  * csv.c also does a similar parsing
index 208ef4c6f6e4b717c835a05780111087af045d62..290d5543a6ab9329d8ed22167d7c6365303bfc6c 100644 (file)
@@ -13,7 +13,7 @@
 #define SLURM_BGPS_FLAG_ROUTER_KEY     0x08
 
 
-int slurm_load(void);
-void slurm_cleanup(void);
+int slurm_parse(char const *);
+
 
 #endif /* SRC_SLURM_PARSER_H_ */