From 64daaf148cd59bf19942014bc754992b6bc6d86d Mon Sep 17 00:00:00 2001 From: Magnus Ahltorp Date: Thu, 2 Mar 2017 12:52:16 +0100 Subject: Rename to statusserver --- Emakefile | 4 +- Makefile | 2 +- src/statusreport.erl | 2 +- statsserver/ebin/statsserver.app | 13 ------- statsserver/src/statsserver.erl | 71 ----------------------------------- statsserver/src/statsserver_app.erl | 13 ------- statsserver/src/statsserver_sup.erl | 42 --------------------- statusserver/ebin/statusserver.app | 13 +++++++ statusserver/src/statusserver.erl | 71 +++++++++++++++++++++++++++++++++++ statusserver/src/statusserver_app.erl | 13 +++++++ statusserver/src/statusserver_sup.erl | 42 +++++++++++++++++++++ 11 files changed, 143 insertions(+), 143 deletions(-) delete mode 100644 statsserver/ebin/statsserver.app delete mode 100644 statsserver/src/statsserver.erl delete mode 100644 statsserver/src/statsserver_app.erl delete mode 100644 statsserver/src/statsserver_sup.erl create mode 100644 statusserver/ebin/statusserver.app create mode 100644 statusserver/src/statusserver.erl create mode 100644 statusserver/src/statusserver_app.erl create mode 100644 statusserver/src/statusserver_sup.erl diff --git a/Emakefile b/Emakefile index 0a41ae3..f223dab 100644 --- a/Emakefile +++ b/Emakefile @@ -10,9 +10,9 @@ {i, "src/"}, % For plop.hrl. {outdir, "merge/ebin/"}, {parse_transform, lager_transform}]}. -{["statsserver/src/*"], +{["statusserver/src/*"], [debug_info, {i, "../"}, % For hackney. {i, "src/"}, % For plop.hrl. - {outdir, "statsserver/ebin/"}, + {outdir, "statusserver/ebin/"}, {parse_transform, lager_transform}]}. diff --git a/Makefile b/Makefile index 4e5d5b2..65f2355 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ clean: -rm priv/fsynchelper -rm ebin/*.beam -rm merge/ebin/*.beam - -rm statsserver/ebin/*.beam + -rm statusserver/ebin/*.beam dialyze: build dialyzer ebin merge/ebin tags: diff --git a/src/statusreport.erl b/src/statusreport.erl index cd5bb5a..63414cd 100644 --- a/src/statusreport.erl +++ b/src/statusreport.erl @@ -112,7 +112,7 @@ encode_status({multi, Statuses}) -> send(Service, Statusreports, Nodename) -> lager:debug("reporting status to ~p: ~p", [Service, Statusreports]), - [NodeAddress] = plopconfig:get_env(statsservers, []), + [NodeAddress] = plopconfig:get_env(statusservers, []), DebugTag = "statusreport", URL = NodeAddress ++ Service, Headers = [{"Content-Type", "text/json"}], diff --git a/statsserver/ebin/statsserver.app b/statsserver/ebin/statsserver.app deleted file mode 100644 index 9c642ed..0000000 --- a/statsserver/ebin/statsserver.app +++ /dev/null @@ -1,13 +0,0 @@ -%%% Copyright (c) 2017, NORDUnet A/S. -%%% See LICENSE for licensing information. - -%%% Application resource file for statsserver, see app(5). - -{application, statsserver, - [{description, "Plop statsserver"}, - {vsn, "0.10.1"}, - {modules, [statsserver_app, statsserver_sup, statsserver]}, - {applications, [kernel, stdlib, lager, plop]}, - {registered, [statsserver_sup, statsserver]}, - {mod, {statsserver_app, []}} - ]}. diff --git a/statsserver/src/statsserver.erl b/statsserver/src/statsserver.erl deleted file mode 100644 index 1d42b27..0000000 --- a/statsserver/src/statsserver.erl +++ /dev/null @@ -1,71 +0,0 @@ -%%% Copyright (c) 2014-2016, NORDUnet A/S. -%%% See LICENSE for licensing information. - -%%% @doc Frontend node API - --module(statsserver). --export([init_module/0]). -%% API (URL) --export([request/4]). - --define(APPURL_PLOP_STATUS, "plop/v1/status"). - -request(post, ?APPURL_PLOP_STATUS, Service, Input) -> - case (catch mochijson2:decode(Input)) of - {error, E} -> - html("bad input:", E); - Entries when is_list(Entries) -> - lists:foreach(fun ({struct, PropList}) -> - Target = proplists:get_value(<<"target">>, PropList), - Variable = proplists:get_value(<<"key">>, PropList), - Status = proplists:get_value(<<"value">>, PropList), - set_status(Service, Target, Variable, Status) - end, Entries) - end, - success({[{result, <<"ok">>}]}); -request(get, "", "status", Input) -> - Now = erlang:monotonic_time(millisecond), - Variables = [{struct, [ - {service, list_to_binary(Service)}, - {target, Target}, - {variable, Variable}, - {status, Status}, - {age, (Now - Timestamp) / 1000} - ]} || {{Service, Target, Variable}, Status, Timestamp} <- get_status()], - success({[{result, Variables}]}). - - -success(Data) -> - {200, [{"Content-Type", "text/json"}, {"Access-Control-Allow-Origin", "*"}], mochijson2:encode(Data)}. - -html(Text, Input) -> - {400, [{"Content-Type", "text/html"}], - io_lib:format( - "

~n" ++ - "~s~n" ++ - "~p~n" ++ - "~n", [Text, Input])}. - --define(STATUSDB_TABLE, statsserver_statusdb). - -init_module() -> - create_statusdb(). - -create_statusdb() -> - case ets:info(?STATUSDB_TABLE) of - undefined -> - ok; - _ -> - ets:delete(?STATUSDB_TABLE) - end, - ets:new(?STATUSDB_TABLE, [set, public, named_table]). - -get_status() -> - [E || [E] <- ets:match(?STATUSDB_TABLE, '$1')]. - -set_status(Service, Target, Variable, Status) -> - lager:info("status: ~p ~p ~p ~p", [Service, Target, Variable, Status]), - Timestamp = erlang:monotonic_time(millisecond), - true = ets:insert(?STATUSDB_TABLE, - {{Service, Target, Variable}, Status, Timestamp}), - ok. diff --git a/statsserver/src/statsserver_app.erl b/statsserver/src/statsserver_app.erl deleted file mode 100644 index 6caf2b7..0000000 --- a/statsserver/src/statsserver_app.erl +++ /dev/null @@ -1,13 +0,0 @@ -%%% Copyright (c) 2017, NORDUnet A/S. -%%% See LICENSE for licensing information. - --module(statsserver_app). --behaviour(application). --export([start/2, stop/1]). - -start(normal, Args) -> - statsserver:init_module(), - statsserver_sup:start_link(Args). - -stop(_State) -> - ok. diff --git a/statsserver/src/statsserver_sup.erl b/statsserver/src/statsserver_sup.erl deleted file mode 100644 index 6b92e35..0000000 --- a/statsserver/src/statsserver_sup.erl +++ /dev/null @@ -1,42 +0,0 @@ -%%% Copyright (c) 2017, NORDUnet A/S. -%%% See LICENSE for licensing information. - --module(statsserver_sup). --behaviour(supervisor). - --export([start_link/1, init/1]). - -start_link(_Args) -> - supervisor:start_link({local, ?MODULE}, ?MODULE, []). - -gen_http_config(Config, SSLOptions, SSLFlag) -> - {ChildName, IpAddress, Port, Module} = Config, - {ok, IPv4Address} = inet:parse_ipv4strict_address(IpAddress), - WebConfig = [{ip, IPv4Address}, - {port, Port}, - {ssl, SSLFlag}, - {acceptor_pool_size, - application:get_env(catlfish, http_server_pool_size, 16)}, - {ssl_opts, SSLOptions} - ], - {ChildName, - {catlfish_web, start, [WebConfig, Module, ChildName]}, - permanent, 5000, worker, dynamic}. - - -init([]) -> - SSLOptions = - [{certfile, application:get_env(plop, https_certfile, none)}, - {keyfile, application:get_env(plop, https_keyfile, none)}, - {cacertfile, application:get_env(plop, https_cacertfile, none)}], - Servers = - lists:map(fun (Config) -> - gen_http_config(Config, SSLOptions, true) - end, application:get_env(plop, https_servers, [])) ++ - lists:map(fun (Config) -> - gen_http_config(Config, SSLOptions, false) - end, application:get_env(plop, http_servers, [])), - lager:debug("Starting servers ~p", [Servers]), - {ok, - {{one_for_one, 3, 10}, - Servers}}. diff --git a/statusserver/ebin/statusserver.app b/statusserver/ebin/statusserver.app new file mode 100644 index 0000000..1a032f1 --- /dev/null +++ b/statusserver/ebin/statusserver.app @@ -0,0 +1,13 @@ +%%% Copyright (c) 2017, NORDUnet A/S. +%%% See LICENSE for licensing information. + +%%% Application resource file for statusserver, see app(5). + +{application, statusserver, + [{description, "Plop statusserver"}, + {vsn, "0.10.1"}, + {modules, [statusserver_app, statusserver_sup, statusserver]}, + {applications, [kernel, stdlib, lager, plop]}, + {registered, [statusserver_sup, statusserver]}, + {mod, {statusserver_app, []}} + ]}. diff --git a/statusserver/src/statusserver.erl b/statusserver/src/statusserver.erl new file mode 100644 index 0000000..323b28d --- /dev/null +++ b/statusserver/src/statusserver.erl @@ -0,0 +1,71 @@ +%%% Copyright (c) 2014-2016, NORDUnet A/S. +%%% See LICENSE for licensing information. + +%%% @doc Frontend node API + +-module(statusserver). +-export([init_module/0]). +%% API (URL) +-export([request/4]). + +-define(APPURL_PLOP_STATUS, "plop/v1/status"). + +request(post, ?APPURL_PLOP_STATUS, Service, Input) -> + case (catch mochijson2:decode(Input)) of + {error, E} -> + html("bad input:", E); + Entries when is_list(Entries) -> + lists:foreach(fun ({struct, PropList}) -> + Target = proplists:get_value(<<"target">>, PropList), + Variable = proplists:get_value(<<"key">>, PropList), + Status = proplists:get_value(<<"value">>, PropList), + set_status(Service, Target, Variable, Status) + end, Entries) + end, + success({[{result, <<"ok">>}]}); +request(get, "", "status", Input) -> + Now = erlang:monotonic_time(millisecond), + Variables = [{struct, [ + {service, list_to_binary(Service)}, + {target, Target}, + {variable, Variable}, + {status, Status}, + {age, (Now - Timestamp) / 1000} + ]} || {{Service, Target, Variable}, Status, Timestamp} <- get_status()], + success({[{result, Variables}]}). + + +success(Data) -> + {200, [{"Content-Type", "text/json"}, {"Access-Control-Allow-Origin", "*"}], mochijson2:encode(Data)}. + +html(Text, Input) -> + {400, [{"Content-Type", "text/html"}], + io_lib:format( + "

~n" ++ + "~s~n" ++ + "~p~n" ++ + "~n", [Text, Input])}. + +-define(STATUSDB_TABLE, statusserver_statusdb). + +init_module() -> + create_statusdb(). + +create_statusdb() -> + case ets:info(?STATUSDB_TABLE) of + undefined -> + ok; + _ -> + ets:delete(?STATUSDB_TABLE) + end, + ets:new(?STATUSDB_TABLE, [set, public, named_table]). + +get_status() -> + [E || [E] <- ets:match(?STATUSDB_TABLE, '$1')]. + +set_status(Service, Target, Variable, Status) -> + lager:info("status: ~p ~p ~p ~p", [Service, Target, Variable, Status]), + Timestamp = erlang:monotonic_time(millisecond), + true = ets:insert(?STATUSDB_TABLE, + {{Service, Target, Variable}, Status, Timestamp}), + ok. diff --git a/statusserver/src/statusserver_app.erl b/statusserver/src/statusserver_app.erl new file mode 100644 index 0000000..2fd8b8d --- /dev/null +++ b/statusserver/src/statusserver_app.erl @@ -0,0 +1,13 @@ +%%% Copyright (c) 2017, NORDUnet A/S. +%%% See LICENSE for licensing information. + +-module(statusserver_app). +-behaviour(application). +-export([start/2, stop/1]). + +start(normal, Args) -> + statusserver:init_module(), + statusserver_sup:start_link(Args). + +stop(_State) -> + ok. diff --git a/statusserver/src/statusserver_sup.erl b/statusserver/src/statusserver_sup.erl new file mode 100644 index 0000000..5b0811a --- /dev/null +++ b/statusserver/src/statusserver_sup.erl @@ -0,0 +1,42 @@ +%%% Copyright (c) 2017, NORDUnet A/S. +%%% See LICENSE for licensing information. + +-module(statusserver_sup). +-behaviour(supervisor). + +-export([start_link/1, init/1]). + +start_link(_Args) -> + supervisor:start_link({local, ?MODULE}, ?MODULE, []). + +gen_http_config(Config, SSLOptions, SSLFlag) -> + {ChildName, IpAddress, Port, Module} = Config, + {ok, IPv4Address} = inet:parse_ipv4strict_address(IpAddress), + WebConfig = [{ip, IPv4Address}, + {port, Port}, + {ssl, SSLFlag}, + {acceptor_pool_size, + application:get_env(catlfish, http_server_pool_size, 16)}, + {ssl_opts, SSLOptions} + ], + {ChildName, + {catlfish_web, start, [WebConfig, Module, ChildName]}, + permanent, 5000, worker, dynamic}. + + +init([]) -> + SSLOptions = + [{certfile, application:get_env(plop, https_certfile, none)}, + {keyfile, application:get_env(plop, https_keyfile, none)}, + {cacertfile, application:get_env(plop, https_cacertfile, none)}], + Servers = + lists:map(fun (Config) -> + gen_http_config(Config, SSLOptions, true) + end, application:get_env(plop, https_servers, [])) ++ + lists:map(fun (Config) -> + gen_http_config(Config, SSLOptions, false) + end, application:get_env(plop, http_servers, [])), + lager:debug("Starting servers ~p", [Servers]), + {ok, + {{one_for_one, 3, 10}, + Servers}}. -- cgit v1.1