diff options
-rw-r--r-- | components/rvi_common/src/rvi_common.erl | 96 | ||||
-rw-r--r-- | components/service_discovery/src/service_discovery_rpc.erl | 36 | ||||
-rw-r--r-- | components/service_edge/src/service_edge_rpc.erl | 81 | ||||
-rw-r--r-- | packaging/repo/README.md | 7 | ||||
-rw-r--r-- | rvi_backend.config | 135 |
5 files changed, 256 insertions, 99 deletions
diff --git a/components/rvi_common/src/rvi_common.erl b/components/rvi_common/src/rvi_common.erl index c14c7f8..8aa2cb6 100644 --- a/components/rvi_common/src/rvi_common.erl +++ b/components/rvi_common/src/rvi_common.erl @@ -114,6 +114,7 @@ json_rpc_status(_) -> get_request_result({ok, {http_response, {_V1, _V2}, 200, _Text, _Hdr}, JSONBody}) -> case get_json_element(["result", "status"], JSONBody) of {ok, Value} -> + ?debug("get_request_result(~s)", [JSONBody]), { json_rpc_status(Value), JSONBody }; { error, undefined} -> @@ -158,18 +159,21 @@ request(Component, %% We have a gen_server { ok, gen_server } -> ?debug("Sending ~p - ~p:~p(~p)", [Component, Module, Function, InArg]), - gen_server:call(Module, { rvi_call, Module, InArg}); + gen_server:call(Module, { rvi_call, Function, InArg}); %% We have a JSON-RPC server { ok, json_rpc } -> URL = get_module_json_rpc_url(Component, Module, CompSpec), + ?debug("Sending ~p:~p(~p) -> ~p.", [Module, Function, InArg, URL]), JSONArg = json_argument(InArg, InArgSpec), + ?debug("Sending ~p:~p(~p) -> ~p.", [Module, Function, InArg, JSONArg]), + case get_request_result( - send_http_request(URL, atom_to_list(Module), JSONArg) + send_http_request(URL, atom_to_list(Function), JSONArg) ) of { ok, JSONBody} -> - json_reply(JSONBody, OutArgSpec); + json_reply(OutArgSpec, JSONBody); Err -> Err end; @@ -184,7 +188,7 @@ send_http_request(Url,Method, Args) -> exo_json:encode({struct, [{"jsonrpc", "2.0"}, {"id", 1}, {"method", Method}, - {"params", {struct, Args}} + {"params", Args} ] }))), @@ -411,9 +415,13 @@ node_address_tuple() -> get_component_config_(Component, Default, CompList) -> case proplists:get_value(Component, CompList, undefined) of undefined -> + ?debug("get_component_config(~p): Default: ~p", + [Component, Default]), Default; ModList -> + ?debug("get_component_config(~p) -> ~p", + [Component, ModList]), ModList end. @@ -493,6 +501,8 @@ get_module_specification(Component, Module, CompSpec) -> {error, {not_found, Module}}; { Module, Type, ModConf } -> + ?debug("get_component_module_specification(): ~p:~p -> ~p ", + [Component, Module, { Module, Type, ModConf}]), {ok, Module, Type, ModConf }; IllegalFormat -> @@ -515,6 +525,8 @@ get_module_config(Component, Module, Key, CompSpec) -> Config -> + ?debug("get_component_config(): ~p:~p:~p -> ~p: ", + [Component, Module, Key, Config]), {ok, Config } end; Err -> Err @@ -534,59 +546,51 @@ get_module_config(Component, Module, Key, Default, CompSpec) -> get_module_type(Component, Module, CompSpec) -> case get_module_specification(Component, Module, CompSpec) of - {ok, {_Module, Type, _ModConf } } -> + {ok, _Module, Type, _ModConf } -> {ok, Type} ; Err -> Err end. get_module_json_rpc_address(Component, Module, CompSpec) -> - ?debug("get_module_json_rpc_address(~p, ~p, ~p)", [ Component, Module, CompSpec]), - %% Check that this is a JSON RPC module - case get_module_type(Component, Module, CompSpec) of - { ok, json_rpc} -> - ?debug("get_module_json_rpc_address(): Is json_rpc"), - %% Dig out the JSON RPC address - case get_module_config(Component, - Module, - json_rpc_address, - undefined, - CompSpec) of - undefined -> - ?debug("get_component_config(): Missing component spec: " - "rvi:component:~p:~p:json_rpc_addr, {...}", [Component, Module]), - {error, {not_found, Component, Module, json_rpc_addr}}; - - {ok, { IP, Port }} -> - {ok, IP, Port }; - - {ok, Port } -> - {ok, "127.0.0.1", Port} - - end; - - {ok, gen_server } -> - ?debug("get_module_json_rpc_address(): Is gen_server"), - { error, { is_gen_server, Module } }; - - {ok, Unknown } -> - ?debug("get_module_json_rpc_address(): Is unknown: ~p", [Unknown]), - { error, { unknown_type, Unknown } }; - - Err -> Err + %% Dig out the JSON RPC address + case get_module_config(Component, + Module, + json_rpc_address, + undefined, + CompSpec) of + undefined -> + ?debug("get_component_config(): Missing component spec: " + "rvi:component:~p:~p:json_rpc_addr, {...}", [Component, Module]), + {error, {not_found, Component, Module, json_rpc_addr}}; + + {ok, { IP, Port }} -> + ?debug("get_module_json_rpc_address(~p, ~p) -> ~p:~p", + [ Component, Module, IP, Port]), + {ok, IP, Port }; + + {ok, Port } -> + ?debug("get_module_json_rpc_address(~p, ~p) -> 127.0.0.1:~p", + [ Component, Module, Port]), + {ok, "127.0.0.1", Port} end. get_module_json_rpc_url(Component, Module, CompSpec) -> - ?debug("get_module_json_rpc_url(~p, ~p, ~p)", [ Component, Module, CompSpec]), case get_module_json_rpc_address(Component, Module, CompSpec) of { ok, IP, Port } when is_integer(Port)-> - "http://" ++ IP ++ ":" ++ integer_to_list(Port); + Res = "http://" ++ IP ++ ":" ++ integer_to_list(Port), + ?debug("get_module_json_rpc_url(~p, ~p) ->~p", [ Component, Module, Res ]), + Res; - { ok, IP, Port } when is_list(Port)-> - "http://" ++ IP ++ ":" ++ Port; - Err -> Err + { ok, IP, Port } when is_list(Port)-> + Res = "http://" ++ IP ++ ":" ++ Port, + ?debug("get_module_json_rpc_url(~p, ~p) ->~p", [ Component, Module, Res ]), + Res; + Err -> + ?debug("get_module_json_rpc_url(~p, ~p) Failed: ~p", [ Component, Module, Err ]), + Err end. @@ -620,6 +624,10 @@ start_json_rpc_server(Component, Module, Supervisor) -> exoport_exo_http:instance(Supervisor, Module, ExoHttpOpts); - Err -> Err + Err -> + ?info("rvi_common:start_json_rpc_server(~p:~p): " + "No JSON-RPC address setup. skip", + [ Component, Module ]), + Err end. diff --git a/components/service_discovery/src/service_discovery_rpc.erl b/components/service_discovery/src/service_discovery_rpc.erl index 265bffa..e9f1c9f 100644 --- a/components/service_discovery/src/service_discovery_rpc.erl +++ b/components/service_discovery/src/service_discovery_rpc.erl @@ -57,11 +57,11 @@ start_json_server() -> get_all_services(CompSpec) -> rvi_common:request(service_discovery, ?MODULE, - get_all_services, [], [status], CompSpec). + get_all_services, [], [], [status, services], CompSpec). get_local_network_addresses(CompSpec) -> rvi_common:request(service_discovery, ?MODULE, - get_local_network_addresses, [], [status], CompSpec). + get_local_network_addresses, [], [], [status], CompSpec). resolve_local_service(CompSpec, RawService) -> @@ -114,7 +114,7 @@ handle_rpc("register_local_service", Args) -> {ok, Address} = rvi_common:get_json_element(["network_address"], Args), [ok, FullSvcName] = gen_server:call(?SERVER, { rvi_call, register_local_service, [ Service, Address ]}), - [ {status, ok }, { full_service_name, FullSvcName }]; + {ok, [ {status, rvi_common:json_rpc_status(ok) }, { full_service_name, FullSvcName }]}; %% Register remote services @@ -124,20 +124,20 @@ handle_rpc("register_remote_services", Args) -> [ok ] = gen_server:call(?SERVER, { rvi_call, register_remote_services, [ Services, Address ]}), - [ {status, ok} ]; + {ok, [ {status, rvi_common:json_rpc_status(ok)} ]}; handle_rpc("unregister_remote_services_by_address", Args) -> {ok, Address} = rvi_common:get_json_element(["network_address"], Args), [ok] = gen_server:call(?SERVER, { rvi_call, unregister_remote_services_by_address, [ Address ]}), - [ {status, ok} ]; + {ok, [ {status, rvi_common:json_rpc_status(ok)} ]}; handle_rpc("unregister_remote_service_by_name", Args) -> {ok, Service} = rvi_common:get_json_element(["service"], Args), [ok ] = gen_server:call(?SERVER, { rvi_call, unregister_remote_service_by_Name, [ Service ]}), - [ {status, ok} ]; + {ok, [ {status, rvi_common:json_rpc_status(ok)} ]}; handle_rpc("unregister_local_service", Args) -> @@ -145,7 +145,7 @@ handle_rpc("unregister_local_service", Args) -> %% De-register service [ok ] = gen_server:call(?SERVER, { rvi_call, unregister_local_service, [ Service ]}), - [ {status, ok} ]; + {ok, [ {status, rvi_common:json_rpc_status(ok)} ]}; %% @@ -154,15 +154,17 @@ handle_rpc("unregister_local_service", Args) -> handle_rpc("get_remote_services", _Args) -> [ok, Services ] = gen_server:call(?SERVER, { rvi_call, get_remote_services, [ ]}), - [ {status, ok} , { services, { array, Services } }]; + {ok, [ {status, rvi_common:json_rpc_status(ok)} , { services, { array, Services } }]}; %% %% Get all services %% handle_rpc("get_all_services", _Args) -> + ?debug("service_discovery_rpc:get_all_services(json-rpc)"), [ok, Services ] = gen_server:call(?SERVER, { rvi_call, get_all_services, []}), - [ {status, ok} , { services, { array, Services } }]; + ?debug("service_discovery_rpc:Done"), + {ok, [ {status, rvi_common:json_rpc_status(ok)} , { services, { array, Services } }]}; %% @@ -171,7 +173,7 @@ handle_rpc("get_all_services", _Args) -> handle_rpc("get_remote_network_addresses", _Args) -> [ok, Addresses ] = gen_server:call(?SERVER, { rvi_call, get_remote_network_addresses, []}), - [ {status, ok}, { addresses, { array, Addresses }}]; + {ok, [ {status, rvi_common:json_rpc_status(ok)}, { addresses, { array, Addresses }}]}; %% %% Resolve remote service @@ -182,9 +184,9 @@ handle_rpc("resolve_remote_service", Args) -> case gen_server:call(?SERVER, { rvi_call, resolve_remote_service, [Service]}) of [ok, Addresses ] -> - [ {status, ok}, { addresses, { array, Addresses }}]; + {ok, [ {status, rvi_common:json_rpc_status(ok)}, { addresses, { array, Addresses }}]}; - [ Other ] -> [ {status, Other} ] + [ Other ] -> {ok, [ {status, rvi_common:json_rpc_status(Other)} ]} end; @@ -198,9 +200,9 @@ handle_rpc("resolve_local_service", Args) -> case gen_server:call(?SERVER, { rvi_call, resolve_local_service, [Service]}) of [ok, Addresses ] -> - [ {status, ok}, { addresses, { array, Addresses }}]; + {ok, [ {status, rvi_common:json_rpc_status(ok)}, { addresses, { array, Addresses }}]}; - [ Other ] -> [ {status, Other} ] + [ Other ] -> {ok, [ {status, rvi_common:json_rpc_status(Other)} ]} end; @@ -212,7 +214,7 @@ handle_rpc("resolve_local_service", Args) -> handle_rpc("get_local_services", _Args) -> [ok, LocalServices ] = gen_server:call(?SERVER, { rvi_call, get_local_services, []}), - [ {status, ok} , { services, { array, LocalServices }}]; + {ok, [ {status, rvi_common:json_rpc_status(ok)} , { services, { array, LocalServices }}]}; @@ -223,7 +225,7 @@ handle_rpc("get_local_network_addresses", _Args) -> [ok, LocalAddresses ] = gen_server:call(?SERVER, { rvi_call, get_local_network_addresses, []}), - [ {status, ok} , { network_addresses, { array, LocalAddresses }}]; + {ok, [ {status, rvi_common:json_rpc_status(ok)} , { network_addresses, { array, LocalAddresses }}]}; @@ -232,7 +234,7 @@ handle_rpc("get_local_network_addresses", _Args) -> %% handle_rpc( Other, _Args) -> ?info("service_discovery_rpc:handle_rpc(~p): unknown", [ Other ]), - [ { status, invalid_command } ]. + {ok, [ { status, invalid_command } ]}. %% Handle calls received through regular gen_server calls, routed by diff --git a/components/service_edge/src/service_edge_rpc.erl b/components/service_edge/src/service_edge_rpc.erl index 4a6d110..b4c7118 100644 --- a/components/service_edge/src/service_edge_rpc.erl +++ b/components/service_edge/src/service_edge_rpc.erl @@ -42,7 +42,8 @@ -record(st, { - comp_spec = #component_spec{} + %% Component specification + cs = #component_spec{} }). @@ -62,12 +63,25 @@ init([]) -> ?notice("---- Node Service Prefix: ~s", [ rvi_common:local_service_prefix()]), {ok, #st { - comp_spec = CompSpec + cs = CompSpec }}. start_json_server() -> - rvi_common:start_json_rpc_server(service_edge, ?MODULE, service_edge_sup). + ?debug("service_edge_rpc:start_json_server()"), + case rvi_common:start_json_rpc_server(service_edge, + ?MODULE, + service_edge_sup) of + ok -> + ok; + + Err -> + ?warning("service_edge_rpc:start_json_server(): Failed to start: ~p", + [Err]), + Err + end. + + @@ -94,7 +108,6 @@ start_websocket() -> wse_server:start(Port, proplists:delete(port, WSOpts)), ok end - end. register_remote_services(Service, LocalServiceAddresses) -> @@ -224,7 +237,7 @@ dispatch_to_local_service(NetworkAddress, Command, Args) -> %% Forward a message to a specific locally connected service. %% Called by forward_message_to_local_service/2. %% -forward_message_to_local_service(ServiceName, NetworkAddress, Parameters) -> +forward_message_to_local_service(ServiceName, NetworkAddress, Parameters, _CompSpec) -> ?debug("service_edge:forward_to_local(): URL: ~p", [NetworkAddress]), ?debug("service_edge:forward_to_local(): Parameters: ~p", [Parameters]), @@ -263,16 +276,16 @@ forward_message_to_local_service(ServiceName, NetworkAddress, Parameters) -> %% A message is to targeting a service that is connected to the local RVI %% node. We can just bounce the messsage straight over to the target service. -forward_message_to_local_service(ServiceName, Parameters) -> +forward_message_to_local_service(ServiceName, Parameters, CompSpec) -> %% %% Resolve the local service name to an URL that we can send the %% request to %% ?debug("service_edge:forward_to_local(): service_name: ~p", [ServiceName]), - case service_discovery:resolve_local_service(ServiceName) of + case service_discovery_rpc:resolve_local_service(CompSpec, ServiceName) of [ ok, NetworkAddress] -> - forward_message_to_local_service(ServiceName, NetworkAddress, Parameters); + forward_message_to_local_service(ServiceName, NetworkAddress, Parameters, CompSpec); %% Local service could not be resolved to an URL [ not_found ] -> @@ -303,9 +316,10 @@ handle_rpc("unregister_service", Args) -> [ {status, rvi_common:json_rpc_status(ok) }]; handle_rpc("get_available_services", _Args) -> - [ Services ] = gen_server:call(?SERVER, { rvi_call, get_available_services, []}), - [ { status, rvi_common:json_rpc_status(ok)}, - { services, {array, Services}} ]; + [ Status, Services ] = gen_server:call(?SERVER, { rvi_call, get_available_services, []}), + ?debug("get_available_services(): ~p ~p", [ Status, Services ]), + {ok, [ { status, rvi_common:json_rpc_status(ok)}, + { services, {array, Services}} ]}; @@ -405,9 +419,9 @@ handle_call({ rvi_call, register_local_service, [Service, ServiceAddress] }, _Fr ?debug("service_edge_rpc:register_local_service(): address: ~p ", [ServiceAddress]), [ok, FullSvcName ] = - service_discovery:register_local_service(St#st.comp_spec, - Service, - ServiceAddress), + service_discovery_rpc:register_local_service(St#st.cs, + Service, + ServiceAddress), SvcString = rvi_common:local_service_to_string(Service), @@ -416,7 +430,7 @@ handle_call({ rvi_call, register_local_service, [Service, ServiceAddress] }, _Fr %% Retrieve addresses of all locally registered services. [ ok, AnnounceAddresses ] = - service_discovery:get_local_network_addresses(), + service_discovery_rpc:get_local_network_addresses(St#st.cs), announce_service_availability(services_available, AnnounceAddresses, [FullSvcName], ServiceAddress), @@ -428,9 +442,9 @@ handle_call({ rvi_call, register_local_service, [Service, ServiceAddress] }, _Fr handle_call({ rvi_call, unregister_local_service, [Service] }, _From, St) -> ?debug("service_edge_rpc:unregister_local_service(): service: ~p ", [Service]), - service_discovery:unregister_local_service(Service), + service_discovery_rpc:unregister_local_service(St#st.cs, Service), data_link:announce_unavailable_local_service(Service), - [ ok, AnnounceAddresses ] = service_discovery:get_local_network_addresses(), + [ ok, AnnounceAddresses ] = service_discovery_rpc:get_local_network_addresses(St#st.cs), %% Send out an announcement to all locally connected services, but skip %% the one that made the registration call announce_service_availability(services_unavailable, AnnounceAddresses, Service), @@ -442,7 +456,7 @@ handle_call({ rvi_call, unregister_local_service, [Service] }, _From, St) -> handle_call({rvi_call, get_available_services, []}, _From, St) -> ?debug("service_edge_rpc:get_available_services()"), - {reply, service_discovery:get_all_services(), St}; + {reply, service_discovery_rpc:get_all_services(St#st.cs), St}; handle_call({ rvi_call, handle_local_message, ServiceName, Timeout, Parameters }, _From, St) -> @@ -462,10 +476,13 @@ handle_call({ rvi_call, handle_local_message, ServiceName, Timeout, Parameters } %% Check if this is a local service by trying to resolve its service name. %% If successful, just forward it to its service_name. %% - Res = case service_discovery:resolve_local_service(ServiceName) of + Res = case service_discovery_rpc:resolve_local_service(St#st.cs, ServiceName) of [ ok, NetworkAddress] -> %% ServiceName is local. Forward message ?debug("service_edge_rpc:local_msg(): Service is local. Forwarding."), - [ forward_message_to_local_service(ServiceName, NetworkAddress, Parameters) ]; + [ forward_message_to_local_service(ServiceName, + NetworkAddress, + Parameters, + St#st.cs) ]; _ -> %% ServiceName is remote %% Ask Schedule the request to resolve the network address @@ -497,7 +514,7 @@ handle_call({rvi_call, handle_remote_message, Parameters, Certificate, Signature - ] }, _From, State) -> + ] }, _From, St) -> ?debug("service_edge:remote_msg(): service_name: ~p", [ServiceName]), ?debug("service_edge:remote_msg(): timeout: ~p", [Timeout]), @@ -507,27 +524,27 @@ handle_call({rvi_call, handle_remote_message, case authorize:authorize_remote_message(ServiceName, Certificate, Signature) of [ ok ] -> - { reply, [ forward_message_to_local_service(ServiceName, Parameters) ], State }; + { reply, [ forward_message_to_local_service(ServiceName, Parameters, St#st.cs) ], St }; %% Authorization failed. [ Err ] -> ?warning(" service_edge:remote_msg(): Authorization failed: ~p", [Err]), - {reply, [ authorization_failed ], State} + {reply, [ authorization_failed ], St} end; -handle_call(Other, _From, State) -> +handle_call(Other, _From, St) -> ?warning("service_edge_rpc:handle_call(~p): unknown", [ Other ]), - { reply, [ invalid_command ], State}. + { reply, [ invalid_command ], St}. -handle_cast(_Msg, State) -> - {noreply, State}. +handle_cast(_Msg, St) -> + {noreply, St}. -handle_info(_Info, State) -> - {noreply, State}. +handle_info(_Info, St) -> + {noreply, St}. -terminate(_Reason, _State) -> +terminate(_Reason, _St) -> ok. -code_change(_OldVsn, State, _Extra) -> - {ok, State}. +code_change(_OldVsn, St, _Extra) -> + {ok, St}. diff --git a/packaging/repo/README.md b/packaging/repo/README.md index 9696a32..9485c24 100644 --- a/packaging/repo/README.md +++ b/packaging/repo/README.md @@ -1,10 +1,5 @@ # Local repo with erlang runtime. The R16B03-1 runtime system RPMs for Tizen in this directory was -created by Magnus Feuer (mfeuer@jaguarlandrover.copm). As of this -writing, we were not sure where to put the packages (and their -source), so we dumped them here. - -Email Magnus if you want the source code to build your own RPMs. - +created from github.com/PDXostc/erlang_otp using gbs build -A i586 diff --git a/rvi_backend.config b/rvi_backend.config new file mode 100644 index 0000000..e403b33 --- /dev/null +++ b/rvi_backend.config @@ -0,0 +1,135 @@ +%% -*- erlang -*- + +%% Copyright (C) 2014, Jaguar Land Rover +%% +%% This program is licensed under the terms and conditions of the +%% Mozilla Public License, version 2.0. The full text of the +%% Mozilla Public License is at https://www.mozilla.org/MPL/2.0/ +%% +%% Configuration file for the (in-vehicle) IVI used by the hvac_demo +%% See ../hvac_demo/README.md for detai;s +%% + +%% ----------------------------------------------- +%% See vehicle.config file for documentation and hints +%% ----------------------------------------------- + +[ + {apps, + [kernel, + stdlib, + sasl, + {setup, load}, + syntax_tools, + lager, + crypto, + public_key, + exo, + compiler, + ssl, + asn1, + wse, + + rvi, + rvi_common, + service_edge, + service_discovery, + authorize, + schedule, + data_link_bert_rpc, + protocol ]}, + + {env, + [ + {lager, + [ { handlers, + [{lager_console_backend, debug}] + } + ] + }, + + {rvi, + [ + { node_address, "172.16.0.37:8807" }, + { node_service_prefix, "jlr.com/backend/"}, + + { static_nodes, + [ + %% We are the backend server. No need. + ] + }, + + { components, + [ + { service_edge, + %% This is the URL that local services use to connect to + %% the RVI system. It is also used by + %% the other components below to send inter-compoonent + %% JSON-RPC calls to the service edge. + %% + %% For this component url and exo_http_opts should always be specified + %% so that local services have a HTTP port to connect to. + %% + %% gen_server can also be specified to enable faster, native erlang + %% inter compojnent communication. + %% + %% The host and address given in URL should route to the port given + %% in exo_http_opts below. + %% + %% The web socket integrates with the rvi.js javascript code + %% that connects Tizen IVI to the RVI system. + [ { service_edge_rpc, gen_server, + [ + { json_rpc_address, { "127.0.0.1", 8801 } }, + { websocket, [ { port, 8808}]} + ] + } + ] + }, + { service_discovery, + [ { service_discovery_rpc, gen_server, + [ + { json_rpc_address, { "127.0.0.1", 8802 }} + ] + } + ] + }, + { schedule, + [ { schedule_rpc, json_rpc, + [ + { json_rpc_address, { "127.0.0.1", 8803 }} + ] + } + ] + }, + { authorize, + [ { authorize_rpc, gen_server, + [ + { json_rpc_address, { "127.0.0.1", 8804 } } + ] + } + ] + }, + { protocol, + [ { protocol_rpc, gen_server, + [ + { json_rpc_address, { "127.0.0.1", 8805 } } + ] + } + ] + }, + { data_link, + [ { data_link_bert_rpc_rpc, gen_server, + [ + { json_rpc_address, { "127.0.0.1", 8806 } }, + { bert_rpc_server, [ { port, 8807 }]} + ] + } + ] + } + ] + } + ]} +]} + +]. |