Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing graphql server status to return the MongooseIM version #3995

Merged
merged 2 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion big_tests/tests/graphql_server_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ set_and_get_loglevel_test(Config) ->
get_status_test(Config) ->
Result = get_ok_value([data, server, status], get_status(Config)),
?assertEqual(<<"RUNNING">>, maps:get(<<"statusCode">>, Result)),
?assert(is_binary(maps:get(<<"message">>, Result))).
?assert(is_binary(maps:get(<<"message">>, Result))),
?assert(is_binary(maps:get(<<"version">>, Result))).


join_successful(Config) ->
#{node := Node2} = RPCSpec2 = mim2(),
Expand Down
2 changes: 2 additions & 0 deletions priv/graphql/schemas/admin/server.gql
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type Status {
statusCode: StatusCode
"Message about the status"
message: String
"MongooseIM version"
version: String
}

"Specifies status of the server"
Expand Down
10 changes: 9 additions & 1 deletion src/ejabberd_admin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

-export([start/0, stop/0,
%% Server
status/0,
%% Accounts
register/3, register/2, unregister/2,
registered_users/1,
Expand Down Expand Up @@ -65,7 +66,7 @@ commands() ->
%% They are defined here so that other interfaces can use them too
#ejabberd_commands{name = status, tags = [server],
desc = "Get status of the ejabberd server",
module = mongoose_server_api, function = status,
module = ?MODULE, function = status,
args = [], result = {res, restuple}},
#ejabberd_commands{name = restart, tags = [server],
desc = "Restart ejabberd gracefully",
Expand Down Expand Up @@ -169,6 +170,13 @@ commands() ->
result = {res, restuple}}
].

%%%
%%% Commands
%%%
-spec status() -> {ok, {boolean(), iolist()}} | {mongooseim_not_running, iolist()}.
status() ->
{ok, {Status, Message, _}} = mongoose_server_api:status(),
{ok, {Status, Message}}.
jacekwegr marked this conversation as resolved.
Show resolved Hide resolved

%%%
%%% Server management
Expand Down
5 changes: 3 additions & 2 deletions src/graphql/admin/mongoose_graphql_server_admin_query.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
-include("../mongoose_graphql_types.hrl").

execute(_Ctx, server, <<"status">>, _) ->
{ok, {Status, String}} = mongoose_server_api:status(),
{ok, #{<<"statusCode">> => status_code(Status), <<"message">> => String}};
{ok, {Status, Message, Version}} = mongoose_server_api:status(),
{ok, #{<<"statusCode">> => status_code(Status), <<"message">> => Message,
<<"version">> => Version}};
execute(_Ctx, server, <<"getLoglevel">>, _) ->
mongoose_server_api:get_loglevel();
execute(_Ctx, server, <<"getCookie">>, _) ->
Expand Down
3 changes: 2 additions & 1 deletion src/mongoose_server_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ status() ->
{false, String1 ++ " MongooseIM is not running in that node."};
{value, {_, _, Version}} ->
{true,
String1 ++ io_lib:format(" MongooseIM ~s is running in that node.", [Version])}
String1 ++ io_lib:format(" MongooseIM ~s is running in that node.", [Version]),
lists:nth(1, string:split(Version, "-"))}
end,
{ok, Result}.

Expand Down