-Remove slurm_check_interval configuration parameter since is unnecessary.
-Load multiple SLURM files from a configured location (must be a directory).
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
#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"
#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
#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
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 *);
struct stat attr;
json_t *slurm;
char const *slurm_location;
- int slurm_check_interval;
int error;
slurm = json_object_get(root, OPTNAME_SLURM);
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)
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;
}
{
return config.slurm_location;
}
-
-int
-config_get_slurm_check_interval(void)
-{
- return config.slurm_check_interval;
-}
int config_get_expire_interval(void);
char const *config_get_slurm_location(void);
-int config_get_slurm_check_interval(void);
#endif /* _SRC_CONFIGURATION_H_ */
#include <unistd.h>
#include "rtr/rtr.h"
-#include "slurm_parser.h"
+#include "slurm_loader.h"
#include "clients.h"
#include "configuration.h"
#include "csv.h"
--- /dev/null
+#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 */
+}
--- /dev/null
+#ifndef SRC_SLURM_LOADER_H_
+#define SRC_SLURM_LOADER_H_
+
+int slurm_load(void);
+void slurm_cleanup(void);
+
+#endif /* SRC_SLURM_LOADER_H_ */
#include <openssl/evp.h>
#include "address.h"
-#include "configuration.h"
#include "crypto/base64.h"
#include "json_parser.h"
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);
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
#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_ */