Commit 48894683 authored by Carla Goncalves Ourofino's avatar Carla Goncalves Ourofino
Browse files

Valida as configurações de todo o arquivo múltiplo e mostra warnings.

Foi corrigida também a função check pois não contemplava todos os parâmetros.

[SOMA-3827][SOMA-4161]
parent e3bdbefa
......@@ -18,6 +18,7 @@ local function get(config_data, filename, config_default)
local ok, err = pcall(chunk)
config.os = nil
config.tonumber = nil
if not ok then
return nil, "Failed processing config file "..filename..": "..err
end
......@@ -41,15 +42,13 @@ local function get_from_multiple(filename, sga_name, config)
local sga_config, err_msg = {}
sga_config, err_msg = get(data, filename, config)
if sga_config then
configuration.check(sga_config, true)
if sga_config.sga_name then
if sgas[sga_config.sga_name] then
table.insert(warning,
string.format("[WARNING] Config file %s has duplicate configuration for sga '%s'", filename, sga_config.sga_name))
end
sgas[sga_config.sga_name] = sga_config
else
table.insert(warning,
string.format("[WARNING] Config file %s has configuration without sga_name:\n %s", filename, data))
end
else
table.insert(warning,
......@@ -98,16 +97,18 @@ function configuration.read(filename, sga_name)
return config, message
end
function configuration.check(config)
function configuration.check(config, just_warn)
local config_schema = schema.Record {
csbase_server = schema.Pattern("https?://.*"),
platform = schema.String,
sgad_bind_addr = schema.Optional(schema.String),
sgad_host = schema.String,
sgad_port = schema.NumberFrom(1,65535),
sga_name = schema.Pattern("[A-Za-z0-9_]+"),
sga_type = schema.Optional(schema.String),
status_interval_s = schema.PositiveNumber,
exec_polling_interval_s = schema.PositiveNumber,
register_retry_s = schema.PositiveNumber,
driver = schema.Test(function(v)
local ok, err = pcall(require, v)
if not ok then
......@@ -118,6 +119,12 @@ function configuration.check(config)
driver_config = schema.Optional(schema.Map(schema.String, schema.Any)),
resources = schema.Optional(schema.Collection(schema.String)),
extra_config = schema.Optional(schema.Map(schema.String, schema.Any)),
-- TODO validate path in *_dir parameters:
runtime_data_dir = schema.String,
project_root_dir = schema.String,
algorithm_root_dir = schema.String,
runtime_data_dir = schema.String,
sandbox_root_dir = schema.String,
}
local err = schema.CheckSchema(config, config_schema)
if err then
......@@ -125,8 +132,12 @@ function configuration.check(config)
if config.sga_name then
prefix = "["..config.sga_name.."] "
end
io.stderr:write(prefix.."Configuration error: "..tostring(err).."\n")
os.exit(1)
if just_warn then
io.stderr:write("[WARNING] "..prefix.."Configuration error: \n"..tostring(err).."\n")
else
io.stderr:write(prefix.."Configuration error: \n"..tostring(err).."\n")
os.exit(1)
end
end
end
......
......@@ -28,6 +28,7 @@ if not config then
os.exit(1)
end
io.stderr:write("\27[1;32m".."sgad starting '"..config.sga_name.."'...".."\27[0m\n")
configuration.check(config)
local app, err = application.new(config)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment