Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Commit

Permalink
add 'full' parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
uwiger committed Mar 23, 2016
1 parent 7f592ce commit 49e859c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 8 deletions.
33 changes: 25 additions & 8 deletions components/service_edge/src/service_edge_rpc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,9 @@ handle_ws_json_rpc(WSock, <<"unregister_service">>, Params, _Arg ) ->
gen_server:call(?SERVER, { rvi, unregister_local_service, [ SvcName ]}),
{ ok, [ { status, rvi_common:json_rpc_status(ok)} ]};

handle_ws_json_rpc(WSock, <<"get_node_service_prefix">>, [], _Arg) ->
handle_ws_json_rpc(WSock, <<"get_node_service_prefix">>, Params, _Arg) ->
?debug("websocket_get_node_service_prefix(~p)", [WSock]),
{ ok, [ { status, rvi_common:json_rpc_status(ok) },
{ node_service_prefix, rvi_common:local_service_prefix() },
{ method, <<"get_node_service_prefix">> } ]};
get_node_service_prefix_(Params);

handle_ws_json_rpc(_Ws , <<"get_available_services">>, _Params, _Arg ) ->
?debug("service_edge_rpc:websocket_get_available()"),
Expand Down Expand Up @@ -349,10 +347,9 @@ handle_rpc(<<"unregister_service">>, Args) ->
{ method, <<"unregister_service">>}
]};

handle_rpc(<<"get_node_service_prefix">>, []) ->
{ ok, [ { status, rvi_common:json_rpc_status(ok) },
{ node_service_prefix, rvi_common:local_service_prefix() },
{ method, <<"get_node_service_prefix">> } ]};
handle_rpc(<<"get_node_service_prefix">>, Params) ->
?debug("get_node_service_prefix", []),
get_node_service_prefix_(Params);

handle_rpc(<<"get_available_services">>, _Args) ->
[ Status, Services ] = gen_server:call(?SERVER, { rvi, get_available_services, []}),
Expand Down Expand Up @@ -380,6 +377,26 @@ handle_rpc(Other, _Args) ->
{ok,[ { status, rvi_common:json_rpc_status(invalid_command)} ]}.


get_node_service_prefix_(Params) ->
Prefix = rvi_common:local_service_prefix(),
[UUID | _ ] = re:split(Prefix, <<"/">>, [{return, binary}]),
GoodRes = fun(R) ->
{ ok, [ { status, rvi_common:json_rpc_status(ok) },
{ node_service_prefix, R },
{ method, <<"get_node_service_prefix">> } ]}
end,
case rvi_common:get_json_element(["full"], Params) of
{ok, Full} when Full == true; Full == 1 ->
GoodRes(Prefix);
{error, _} ->
GoodRes(Prefix);
{ok, Full} when Full == false; Full == 0 ->
GoodRes(UUID);
_ ->
{ ok, [ { status, rvi_common:json_rpc_status(invalid_command) },
{ method, <<"get_node_service_prefix">> } ] }
end.

handle_notification(<<"service_available">>, Args) ->
{ok, SvcName} = rvi_common:get_json_element([<<"service">>], Args),
{ok, DataLinkModule} = rvi_common:get_json_element([<<"data_link_module">>], Args),
Expand Down
42 changes: 42 additions & 0 deletions test/rvi_core_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
t_call_sota_service/1,
t_multicall_sota_service/1,
t_remote_call_lock_service/1,
t_get_node_service_prefix/1,
t_check_rvi_log/1,
t_no_errors/1
]).
Expand Down Expand Up @@ -94,6 +95,7 @@ groups() ->
t_call_sota_service,
t_multicall_sota_service,
t_remote_call_lock_service,
t_get_node_service_prefix,
t_no_errors
]},
{test_run_tls, [],
Expand All @@ -106,6 +108,7 @@ groups() ->
t_remote_call_lock_service,
t_call_sota_service,
t_multicall_sota_service,
t_get_node_service_prefix,
t_check_rvi_log,
t_no_errors
]},
Expand All @@ -131,6 +134,7 @@ groups() ->
t_remote_call_lock_service,
t_call_sota_service,
t_multicall_sota_service,
t_get_node_service_prefix,
t_check_rvi_log,
t_no_errors
]},
Expand All @@ -144,6 +148,7 @@ groups() ->
t_call_sota_service,
t_multicall_sota_service,
t_remote_call_lock_service,
t_get_node_service_prefix,
t_no_errors
]}
].
Expand Down Expand Up @@ -362,6 +367,43 @@ flush_reqs([{Pid, Ref}|T]) ->
flush_reqs([]) ->
ok.

t_get_node_service_prefix(Config) ->
get_node_service_prefix_("backend", Config),
get_short_node_service_prefix_("backend", Config),
get_node_service_prefix_("sample", Config),
get_short_node_service_prefix_("sample", Config).

get_node_service_prefix_(Node, _Config) ->
Reply = json_rpc_request(
service_edge(Node),
<<"get_node_service_prefix">>,
[]),
ct:log("get_node_service_prefix (~s) -> ~p", [Node, Reply]),
Result = node_prefix_result(Reply),
ct:log("Result = ~p", [Result]),
case Node of
"sample" -> <<"jlr.com/vin/abc/">> = Result;
"backend" -> <<"genivi.org/backend/">> = Result
end,
ok.

get_short_node_service_prefix_(Node, _Config) ->
Reply = json_rpc_request(
service_edge(Node),
<<"get_node_service_prefix">>,
[{<<"full">>, false}]),
ct:log("get_short_node_service_prefix (~s) -> ~p", [Node, Reply]),
Result = node_prefix_result(Reply),
ct:log("Result = ~p", [Result]),
case Node of
"sample" -> <<"jlr.com">> = Result;
"backend" -> <<"genivi.org">> = Result
end,
ok.

node_prefix_result(Res) ->
proplists:get_value(<<"node_service_prefix">>,
proplists:get_value(<<"result">>, Res), []).

call_sota_service_(RegName, Data) ->
{Mega, Secs, _} = os:timestamp(),
Expand Down

0 comments on commit 49e859c

Please sign in to comment.