Skip to content

Commit

Permalink
NodeName is converted to an atom automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
jacekwegr committed Dec 14, 2022
1 parent 429d930 commit 1fcfb88
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions big_tests/tests/graphql_mnesia_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ admin_mnesia_tests() ->
get_all_info_test,
install_fallback_error_test,
set_master_test,
set_master_self_test,
set_master_bad_name_test,
set_master_empty_name_test].

Expand Down Expand Up @@ -267,6 +268,10 @@ set_master_test(Config) ->
ParsedRes = get_ok_value([data, mnesia, setMaster], set_master(mim(), Config)),
?assertEqual(<<"Master node set">>, ParsedRes).

set_master_self_test(Config) ->
ParsedRes = get_ok_value([data, mnesia, setMaster], set_master(#{node => self}, Config)),
?assertEqual(<<"Master node set">>, ParsedRes).

set_master_bad_name_test(Config) ->
Res = set_master(#{node => incorrect_name}, Config),
get_coercion_err_msg(Res).
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/admin/mongoose_graphql_mnesia_admin_mutation.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
-include("../mongoose_graphql_types.hrl").

execute(_Ctx, mnesia, <<"setMaster">>, #{<<"node">> := Node}) ->
case mnesia_api:set_master(binary_to_list(Node)) of
case mnesia_api:set_master(Node) of
{ok, _} -> {ok, "Master node set"};
Error -> make_error(Error, #{node => Node})
end;
Expand All @@ -21,7 +21,7 @@ execute(_Ctx, mnesia, <<"backup">>, #{<<"path">> := Path}) ->
end;
execute(_Ctx, mnesia, <<"changeNodename">>, #{<<"fromString">> := FromString,
<<"toString">> := ToString, <<"source">> := Source, <<"target">> := Target}) ->
case mnesia_api:mnesia_change_nodename(binary_to_list(FromString), binary_to_list(ToString),
case mnesia_api:mnesia_change_nodename(FromString, ToString,
binary_to_list(Source), binary_to_list(Target)) of
{ok, _} -> {ok, "Name of the node in the backup was successfully changed"};
Error -> make_error(Error, #{fromString => FromString, toString => ToString,
Expand Down
4 changes: 3 additions & 1 deletion src/graphql/mongoose_graphql_scalar.erl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ node_from_binary(<<>>) ->
node_from_binary(NodeName) ->
case string:lexemes(binary_to_list(NodeName), "@") of
[_Name, _Host] ->
{ok, NodeName};
{ok, binary_to_atom(NodeName)};
["self"] ->
{ok, node()};
_ ->
{error, incorrect_node_name}
end.
Expand Down
8 changes: 4 additions & 4 deletions src/mnesia_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ load_mnesia(Path) ->
{cannot_load, String}
end.

-spec mnesia_change_nodename(string(), string(), _, _) ->
-spec mnesia_change_nodename(atom() | string(), atom() | string(), _, _) ->
{ok, _} | {change_error(), io_lib:chars()}.
mnesia_change_nodename(FromString, ToString, Source, Target) ->
From = list_to_atom(FromString),
To = list_to_atom(ToString),
mnesia_change_nodename(From, To, Source, Target) when is_list(From), is_list(To) ->
mnesia_change_nodename(list_to_atom(From), list_to_atom(To), Source, Target);
mnesia_change_nodename(From, To, Source, Target) when is_atom(From), is_atom(To) ->
Switch =
fun
(Node) when Node == From ->
Expand Down

0 comments on commit 1fcfb88

Please sign in to comment.