chore(worker): remove dead config-file code (xcecd_conf)
xcecd_conf.c/h provided worker.yaml parsing (config_load, config_result_t). Removed along with -c/-p/-m CLI flags. Worker now uses CLI defaults or --peers. Deleted: include/xcecd_conf.h, src/xcecd_conf.c. meson.build updated.
This commit is contained in:
parent
5e4baa2745
commit
f0f46f87ad
4 changed files with 0 additions and 288 deletions
|
|
@ -11,7 +11,6 @@
|
|||
#include "system_monitor.h"
|
||||
#include "thread_pool.h"
|
||||
#include "uv_ipc.h"
|
||||
#include "xcecd_conf.h"
|
||||
#include "xcecd_db.h"
|
||||
#include "xcecd_dbus_manager.h"
|
||||
#include "xcecd_worker_utils.h"
|
||||
|
|
|
|||
|
|
@ -1,47 +0,0 @@
|
|||
#ifndef XCECD_CONF_H
|
||||
#define XCECD_CONF_H
|
||||
|
||||
#include <cyaml/cyaml.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define DEFAULT_CONFIG_PATH "/opt/xce/conf/worker.yaml"
|
||||
#define MAX_HOSTNAME_LEN 256
|
||||
#define MAX_PATH_LEN 512
|
||||
#define MAX_LOG_LEVEL_LEN 16
|
||||
|
||||
typedef enum {
|
||||
CONFIG_SUCCESS = 0,
|
||||
CONFIG_ERROR_FILE_NOT_FOUND,
|
||||
CONFIG_ERROR_PARSE_FAILED,
|
||||
CONFIG_ERROR_INVALID_DATA,
|
||||
CONFIG_ERROR_MEMORY,
|
||||
CONFIG_ERROR_UNKNOWN
|
||||
} config_error_t;
|
||||
|
||||
typedef struct {
|
||||
char* hostname;
|
||||
} management_host_t;
|
||||
|
||||
typedef struct {
|
||||
management_host_t* management_list;
|
||||
uint32_t management_list_count;
|
||||
uint16_t controller_port;
|
||||
char* log_level;
|
||||
char* log_dir;
|
||||
} worker_config_t;
|
||||
|
||||
typedef struct {
|
||||
config_error_t error_code;
|
||||
char error_message[512];
|
||||
worker_config_t* config;
|
||||
} config_result_t;
|
||||
|
||||
config_result_t* config_load(const char* config_path);
|
||||
config_result_t* config_load_default(void);
|
||||
void config_free(config_result_t* result);
|
||||
const char* config_error_string(config_error_t error);
|
||||
void config_print(const worker_config_t* config);
|
||||
int level_to_int(const char* level);
|
||||
|
||||
#endif // XCECD_CONF_H
|
||||
|
|
@ -67,7 +67,6 @@ xrun = executable('xrun',
|
|||
|
||||
xcecd_srcs = [
|
||||
'src/static_array.c',
|
||||
'src/xcecd_conf.c',
|
||||
'src/inter_job_utils.c',
|
||||
'src/xcecd_sig.c',
|
||||
'src/uv_ipc.c',
|
||||
|
|
|
|||
|
|
@ -1,239 +0,0 @@
|
|||
#include "xcecd_conf.h"
|
||||
#include "xcelog.h"
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static const cyaml_schema_value_t management_host_schema = {
|
||||
.type = CYAML_STRING,
|
||||
.flags = CYAML_FLAG_POINTER,
|
||||
.data_size = sizeof(char*),
|
||||
.string = {
|
||||
.min = 0,
|
||||
.max = MAX_HOSTNAME_LEN,
|
||||
},
|
||||
};
|
||||
|
||||
static const cyaml_schema_field_t worker_config_fields_schema[] = {
|
||||
{
|
||||
.key = "management_list",
|
||||
.data_offset = offsetof(worker_config_t, management_list),
|
||||
.value = {
|
||||
.type = CYAML_SEQUENCE,
|
||||
.flags = CYAML_FLAG_POINTER,
|
||||
.data_size = sizeof(char*),
|
||||
.sequence = {
|
||||
.entry = &management_host_schema,
|
||||
.min = 0,
|
||||
.max = CYAML_UNLIMITED,
|
||||
},
|
||||
},
|
||||
.count_offset = offsetof(worker_config_t, management_list_count),
|
||||
.count_size = sizeof(uint32_t),
|
||||
},
|
||||
{
|
||||
.key = "controller_port",
|
||||
.data_offset = offsetof(worker_config_t, controller_port),
|
||||
.value = {
|
||||
.type = CYAML_UINT,
|
||||
.flags = CYAML_FLAG_DEFAULT,
|
||||
.data_size = sizeof(uint16_t),
|
||||
},
|
||||
},
|
||||
{
|
||||
.key = "log_level",
|
||||
.data_offset = offsetof(worker_config_t, log_level),
|
||||
.value = {
|
||||
.type = CYAML_STRING,
|
||||
.flags = CYAML_FLAG_POINTER,
|
||||
.data_size = sizeof(char*),
|
||||
.string = {
|
||||
.min = 0,
|
||||
.max = MAX_LOG_LEVEL_LEN,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
.key = "log_dir",
|
||||
.data_offset = offsetof(worker_config_t, log_dir),
|
||||
.value = {
|
||||
.type = CYAML_STRING,
|
||||
.flags = CYAML_FLAG_POINTER,
|
||||
.data_size = sizeof(char*),
|
||||
.string = {
|
||||
.min = 0,
|
||||
.max = MAX_PATH_LEN,
|
||||
},
|
||||
},
|
||||
},
|
||||
{ .key = NULL }
|
||||
};
|
||||
|
||||
static const cyaml_schema_field_t root_fields_schema[] = {
|
||||
{
|
||||
.key = "workerconf",
|
||||
.value = {
|
||||
.type = CYAML_MAPPING,
|
||||
.flags = CYAML_FLAG_DEFAULT,
|
||||
.data_size = sizeof(worker_config_t),
|
||||
.mapping = {worker_config_fields_schema},
|
||||
},
|
||||
},
|
||||
CYAML_FIELD_END
|
||||
};
|
||||
|
||||
static const cyaml_schema_value_t root_schema = {
|
||||
.type = CYAML_MAPPING,
|
||||
.flags = CYAML_FLAG_POINTER,
|
||||
.data_size = sizeof(worker_config_t),
|
||||
.mapping = { root_fields_schema },
|
||||
};
|
||||
|
||||
static const cyaml_config_t cyaml_config = {
|
||||
.log_fn = cyaml_log,
|
||||
.mem_fn = cyaml_mem,
|
||||
.log_level = CYAML_LOG_WARNING,
|
||||
};
|
||||
|
||||
config_result_t* config_load(const char* config_path)
|
||||
{
|
||||
config_result_t* result = calloc(1, sizeof(config_result_t));
|
||||
if (!result) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result->error_code = CONFIG_SUCCESS;
|
||||
result->config = NULL;
|
||||
|
||||
FILE* file = fopen(config_path, "r");
|
||||
if (!file) {
|
||||
result->error_code = CONFIG_ERROR_FILE_NOT_FOUND;
|
||||
snprintf(result->error_message, sizeof(result->error_message),
|
||||
"Cannot open config file '%s': %s", config_path,
|
||||
strerror(errno));
|
||||
return result;
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
cyaml_err_t err = cyaml_load_file(config_path, &cyaml_config, &root_schema,
|
||||
(void**)&result->config, NULL);
|
||||
|
||||
if (err != CYAML_OK) {
|
||||
result->error_code = CONFIG_ERROR_PARSE_FAILED;
|
||||
snprintf(result->error_message, sizeof(result->error_message),
|
||||
"YAML parse error: %s", cyaml_strerror(err));
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!result->config) {
|
||||
result->error_code = CONFIG_ERROR_INVALID_DATA;
|
||||
snprintf(result->error_message, sizeof(result->error_message),
|
||||
"Configuration data is null");
|
||||
return result;
|
||||
}
|
||||
|
||||
if (result->config->controller_port == 0) {
|
||||
result->error_code = CONFIG_ERROR_INVALID_DATA;
|
||||
snprintf(result->error_message, sizeof(result->error_message),
|
||||
"controller_port must be greater than 0");
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!result->config->log_level || strlen(result->config->log_level) == 0) {
|
||||
result->error_code = CONFIG_ERROR_INVALID_DATA;
|
||||
snprintf(result->error_message, sizeof(result->error_message),
|
||||
"log_level cannot be empty");
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!result->config->log_dir || strlen(result->config->log_dir) == 0) {
|
||||
result->error_code = CONFIG_ERROR_INVALID_DATA;
|
||||
snprintf(result->error_message, sizeof(result->error_message),
|
||||
"log_dir cannot be empty");
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
config_result_t* config_load_default(void)
|
||||
{
|
||||
return config_load(DEFAULT_CONFIG_PATH);
|
||||
}
|
||||
|
||||
void config_free(config_result_t* result)
|
||||
{
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
if (result->config) {
|
||||
cyaml_free(&cyaml_config, &root_schema, result->config, 0);
|
||||
}
|
||||
free(result);
|
||||
}
|
||||
|
||||
const char* config_error_string(config_error_t error)
|
||||
{
|
||||
switch (error) {
|
||||
case CONFIG_SUCCESS:
|
||||
return "Success";
|
||||
case CONFIG_ERROR_FILE_NOT_FOUND:
|
||||
return "Configuration file not found";
|
||||
case CONFIG_ERROR_PARSE_FAILED:
|
||||
return "YAML parsing failed";
|
||||
case CONFIG_ERROR_INVALID_DATA:
|
||||
return "Invalid configuration data";
|
||||
case CONFIG_ERROR_MEMORY:
|
||||
return "Memory allocation error";
|
||||
case CONFIG_ERROR_UNKNOWN:
|
||||
default:
|
||||
return "Unknown error";
|
||||
}
|
||||
}
|
||||
|
||||
int level_to_int(const char* level)
|
||||
{
|
||||
if (!level)
|
||||
return XCE_LOG_INFO; // Default to INFO if NULL
|
||||
|
||||
if (strcmp(level, "debug3") == 0) {
|
||||
return XCE_LOG_DEBUG3;
|
||||
} else if (strcmp(level, "debug2") == 0) {
|
||||
return XCE_LOG_DEBUG2;
|
||||
} else if (strcmp(level, "debug") == 0) {
|
||||
return XCE_LOG_DEBUG;
|
||||
} else if (strcmp(level, "notice") == 0) {
|
||||
return XCE_LOG_NOTICE;
|
||||
} else if (strcmp(level, "info") == 0) {
|
||||
return XCE_LOG_INFO;
|
||||
} else if (strcmp(level, "warn") == 0) {
|
||||
return XCE_LOG_WARN;
|
||||
} else if (strcmp(level, "error") == 0) {
|
||||
return XCE_LOG_ERROR;
|
||||
} else if (strcmp(level, "fatal") == 0) {
|
||||
return XCE_LOG_FATAL;
|
||||
} else if (strcmp(level, "off") == 0) {
|
||||
return XCE_LOG_OFF;
|
||||
} else {
|
||||
return XCE_LOG_INFO; // Default to INFO for unknown levels
|
||||
}
|
||||
}
|
||||
|
||||
void config_print(const worker_config_t* config)
|
||||
{
|
||||
if (!config) {
|
||||
printf("Configuration is NULL\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Worker Configuration:\n");
|
||||
printf(" Controller Port: %u\n", config->controller_port);
|
||||
printf(" Log Level: %s\n", config->log_level);
|
||||
printf(" Log Directory: %s\n", config->log_dir);
|
||||
printf(" Management List (%u hosts):\n", config->management_list_count);
|
||||
|
||||
for (uint32_t i = 0; i < config->management_list_count; i++) {
|
||||
printf(" - %s\n", config->management_list[i].hostname);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue