From 13e8799aa24c8537a661af80cae11e885b17e9ee Mon Sep 17 00:00:00 2001 From: Janusz Jakubiec Date: Fri, 31 Mar 2023 12:24:18 +0200 Subject: [PATCH 1/2] Changing graphql server status to return the MongooseIM version --- big_tests/tests/graphql_server_SUITE.erl | 4 +++- priv/graphql/schemas/admin/server.gql | 2 ++ src/ejabberd_admin.erl | 10 +++++++++- .../admin/mongoose_graphql_server_admin_query.erl | 5 +++-- src/mongoose_server_api.erl | 3 ++- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/big_tests/tests/graphql_server_SUITE.erl b/big_tests/tests/graphql_server_SUITE.erl index 5c58f11ddb4..73bfd9bccbf 100644 --- a/big_tests/tests/graphql_server_SUITE.erl +++ b/big_tests/tests/graphql_server_SUITE.erl @@ -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(), diff --git a/priv/graphql/schemas/admin/server.gql b/priv/graphql/schemas/admin/server.gql index 245a0f32a5f..741ea84e353 100644 --- a/priv/graphql/schemas/admin/server.gql +++ b/priv/graphql/schemas/admin/server.gql @@ -46,6 +46,8 @@ type Status { statusCode: StatusCode "Message about the status" message: String + "MongooseIM version" + version: String } "Specifies status of the server" diff --git a/src/ejabberd_admin.erl b/src/ejabberd_admin.erl index b839cf4a168..3e6edd8e39c 100644 --- a/src/ejabberd_admin.erl +++ b/src/ejabberd_admin.erl @@ -28,6 +28,7 @@ -export([start/0, stop/0, %% Server + status/0, %% Accounts register/3, register/2, unregister/2, registered_users/1, @@ -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", @@ -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}}. %%% %%% Server management diff --git a/src/graphql/admin/mongoose_graphql_server_admin_query.erl b/src/graphql/admin/mongoose_graphql_server_admin_query.erl index 50923131aaf..eb6e84b6d99 100644 --- a/src/graphql/admin/mongoose_graphql_server_admin_query.erl +++ b/src/graphql/admin/mongoose_graphql_server_admin_query.erl @@ -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">>, _) -> diff --git a/src/mongoose_server_api.erl b/src/mongoose_server_api.erl index 1d0910376b7..f55ba6b49f5 100644 --- a/src/mongoose_server_api.erl +++ b/src/mongoose_server_api.erl @@ -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}. From 7352bf4b331c4305651aaff5b17a121f5dab0630 Mon Sep 17 00:00:00 2001 From: Janusz Jakubiec Date: Mon, 3 Apr 2023 08:52:24 +0200 Subject: [PATCH 2/2] Fixing tests and dialyzer --- big_tests/tests/graphql_server_SUITE.erl | 2 +- src/ejabberd_admin.erl | 2 +- src/mongoose_server_api.erl | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/big_tests/tests/graphql_server_SUITE.erl b/big_tests/tests/graphql_server_SUITE.erl index 73bfd9bccbf..0aca24eb405 100644 --- a/big_tests/tests/graphql_server_SUITE.erl +++ b/big_tests/tests/graphql_server_SUITE.erl @@ -276,7 +276,7 @@ ensure_node_started(Node) -> Timeout = timer:seconds(60), F = fun() -> case rpc(Node#{timeout => Timeout}, mongoose_server_api, status, []) of - {ok, {true, _}} -> true; + {ok, {true, _, _}} -> true; _Other -> false end end, diff --git a/src/ejabberd_admin.erl b/src/ejabberd_admin.erl index 3e6edd8e39c..8e4f010d3e0 100644 --- a/src/ejabberd_admin.erl +++ b/src/ejabberd_admin.erl @@ -173,7 +173,7 @@ commands() -> %%% %%% Commands %%% --spec status() -> {ok, {boolean(), iolist()}} | {mongooseim_not_running, iolist()}. +-spec status() -> {ok, {boolean(), iolist()}}. status() -> {ok, {Status, Message, _}} = mongoose_server_api:status(), {ok, {Status, Message}}. diff --git a/src/mongoose_server_api.erl b/src/mongoose_server_api.erl index f55ba6b49f5..1d9e1e79183 100644 --- a/src/mongoose_server_api.erl +++ b/src/mongoose_server_api.erl @@ -28,7 +28,7 @@ set_loglevel(Level) -> {invalid_level, io_lib:format("Log level ~p does not exist.", [Level])} end. --spec status() -> {ok, {boolean(), iolist()}} | {mongooseim_not_running, iolist()}. +-spec status() -> {ok, {boolean(), iolist(), iolist()}}. status() -> {InternalStatus, ProvidedStatus} = init:get_status(), String1 = io_lib:format("The node ~p is ~p. Status: ~p.", @@ -36,7 +36,8 @@ status() -> Result = case lists:keysearch(mongooseim, 1, application:which_applications()) of false -> - {false, String1 ++ " MongooseIM is not running in that node."}; + {false, String1 ++ " MongooseIM is not running in that node.", + "MongooseIM is not running in that node"}; {value, {_, _, Version}} -> {true, String1 ++ io_lib:format(" MongooseIM ~s is running in that node.", [Version]),