fix
This commit is contained in:
parent
2184149976
commit
33227d5613
@ -31,7 +31,11 @@ deploy_request(TaskId, Config) when is_integer(TaskId), is_map(Config), TaskId >
|
|||||||
catch
|
catch
|
||||||
throw:{error, Reason} ->
|
throw:{error, Reason} ->
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
end.
|
end;
|
||||||
|
deploy_request(TaskId, _Config) when is_integer(TaskId), TaskId < 0 ->
|
||||||
|
{error, <<"task_id must be non-negative">>};
|
||||||
|
deploy_request(_TaskId, _Config) ->
|
||||||
|
{error, <<"invalid deploy request">>}.
|
||||||
|
|
||||||
-spec start_request(binary()) -> map().
|
-spec start_request(binary()) -> map().
|
||||||
start_request(ContainerName) when is_binary(ContainerName) ->
|
start_request(ContainerName) when is_binary(ContainerName) ->
|
||||||
@ -103,15 +107,15 @@ validate_deploy_config(Config) when is_map(Config) ->
|
|||||||
{<<"devices">>, {list, binary}},
|
{<<"devices">>, {list, binary}},
|
||||||
{<<"mem_limit">>, binary},
|
{<<"mem_limit">>, binary},
|
||||||
{<<"mem_reservation">>, binary},
|
{<<"mem_reservation">>, binary},
|
||||||
{<<"cpu_shares">>, integer},
|
{<<"cpu_shares">>, non_neg_integer},
|
||||||
{<<"cpus">>, number},
|
{<<"cpus">>, non_neg_number},
|
||||||
{<<"ulimits">>, {map, {binary, binary}}},
|
{<<"ulimits">>, {map, {binary, binary}}},
|
||||||
{<<"sysctls">>, {map, {binary, binary}}},
|
{<<"sysctls">>, {map, {binary, binary}}},
|
||||||
{<<"tmpfs">>, {list, binary}},
|
{<<"tmpfs">>, {list, binary}},
|
||||||
{<<"extra_hosts">>, {list, binary}},
|
{<<"extra_hosts">>, {list, binary}},
|
||||||
{<<"healthcheck">>, {map, {binary, any}}}
|
{<<"healthcheck">>, map}
|
||||||
],
|
],
|
||||||
Errors = check_required(Config, Required) ++ check_optional(Config, Optional),
|
Errors = check_required(Config, Required) ++ check_optional(Config, Optional) ++ check_healthcheck(Config),
|
||||||
case Errors of
|
case Errors of
|
||||||
[] ->
|
[] ->
|
||||||
ok;
|
ok;
|
||||||
@ -160,8 +164,14 @@ type_name(binary) ->
|
|||||||
<<"string">>;
|
<<"string">>;
|
||||||
type_name(integer) ->
|
type_name(integer) ->
|
||||||
<<"integer">>;
|
<<"integer">>;
|
||||||
|
type_name(non_neg_integer) ->
|
||||||
|
<<"non-negative integer">>;
|
||||||
type_name(number) ->
|
type_name(number) ->
|
||||||
<<"number">>;
|
<<"number">>;
|
||||||
|
type_name(non_neg_number) ->
|
||||||
|
<<"non-negative number">>;
|
||||||
|
type_name(duration) ->
|
||||||
|
<<"duration string or non-negative integer">>;
|
||||||
type_name(list) ->
|
type_name(list) ->
|
||||||
<<"list">>;
|
<<"list">>;
|
||||||
type_name({list, binary}) ->
|
type_name({list, binary}) ->
|
||||||
@ -184,8 +194,14 @@ check_type(Value, binary) ->
|
|||||||
is_binary(Value);
|
is_binary(Value);
|
||||||
check_type(Value, integer) ->
|
check_type(Value, integer) ->
|
||||||
is_integer(Value);
|
is_integer(Value);
|
||||||
|
check_type(Value, non_neg_integer) ->
|
||||||
|
is_integer(Value) andalso Value >= 0;
|
||||||
check_type(Value, number) ->
|
check_type(Value, number) ->
|
||||||
is_number(Value);
|
is_number(Value);
|
||||||
|
check_type(Value, non_neg_number) ->
|
||||||
|
is_number(Value) andalso Value >= 0;
|
||||||
|
check_type(Value, duration) ->
|
||||||
|
is_binary(Value) orelse (is_integer(Value) andalso Value >= 0);
|
||||||
check_type(Value, list) when is_list(Value) ->
|
check_type(Value, list) when is_list(Value) ->
|
||||||
true;
|
true;
|
||||||
check_type(Value, {list, binary}) when is_list(Value) ->
|
check_type(Value, {list, binary}) when is_list(Value) ->
|
||||||
@ -205,6 +221,25 @@ check_type(Value, boolean) ->
|
|||||||
check_type(_, _) ->
|
check_type(_, _) ->
|
||||||
false.
|
false.
|
||||||
|
|
||||||
|
-spec check_healthcheck(map()) -> [binary()].
|
||||||
|
check_healthcheck(Config) ->
|
||||||
|
case maps:get(<<"healthcheck">>, Config, undefined) of
|
||||||
|
undefined ->
|
||||||
|
[];
|
||||||
|
Healthcheck when is_map(Healthcheck) ->
|
||||||
|
Fields = [
|
||||||
|
{<<"test">>, {list, binary}},
|
||||||
|
{<<"interval">>, duration},
|
||||||
|
{<<"timeout">>, duration},
|
||||||
|
{<<"retries">>, non_neg_integer}
|
||||||
|
],
|
||||||
|
KeyErrors = [<<"optional parameter: <<\"healthcheck\">>, type must be: map of string:any">> ||
|
||||||
|
{Key, _Value} <- maps:to_list(Healthcheck), not is_binary(Key)],
|
||||||
|
KeyErrors ++ check_optional(Healthcheck, Fields);
|
||||||
|
_ ->
|
||||||
|
[]
|
||||||
|
end.
|
||||||
|
|
||||||
-spec build_container_deploy_params(map()) -> map().
|
-spec build_container_deploy_params(map()) -> map().
|
||||||
build_container_deploy_params(Config) when is_map(Config) ->
|
build_container_deploy_params(Config) when is_map(Config) ->
|
||||||
#{
|
#{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user