summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Feuer <mfeuer@jaguarlandrover.com>2014-12-17 16:36:32 -0800
committerMagnus Feuer <mfeuer@jaguarlandrover.com>2014-12-17 16:36:32 -0800
commita3f0d4f82b4b70738d8a51cbef2e01a794a572af (patch)
tree91fcd79fe593cf1ee4d12be92b48e2c192a835cd
parentc05e34990a3e15c3a0c8a91939fc89f90aa600f6 (diff)
downloadrvi_core-a3f0d4f82b4b70738d8a51cbef2e01a794a572af.tar.gz
Test commit
-rw-r--r--components/rvi_common/src/rvi_common.erl25
-rw-r--r--components/service_edge/src/service_edge_rpc.erl99
2 files changed, 53 insertions, 71 deletions
diff --git a/components/rvi_common/src/rvi_common.erl b/components/rvi_common/src/rvi_common.erl
index 06132e2..8c772ef 100644
--- a/components/rvi_common/src/rvi_common.erl
+++ b/components/rvi_common/src/rvi_common.erl
@@ -27,7 +27,6 @@
-export([local_service_prefix/0]).
-export([get_static_node/1]).
-export([static_nodes/0]).
--export([is_local_service/1]).
-export([node_address_string/0]).
-export([node_address_tuple/0]).
-export([get_request_result/1]).
@@ -427,30 +426,6 @@ get_static_node(Service, [{ SvcPrefix, NetworkAddress} | T] ) ->
[ Service, SvcPrefix, NetworkAddress]),
get_static_node(Service, T )
end.
-
-%% Return true if the provided service is locally connected to this
-%% node. In such cases, service edge should just bounce the request
-%% off directly to the targeted service without invoking the rest of
-%% the RVI structure.
-%%
-is_local_service(Service) ->
- case application:get_env(rvi, ?NODE_SERVICE_PREFIX) of
- {ok, P} when is_list(P) ->
- case string:str(sanitize_service_string(Service), P) of
- 1 ->
- ?debug("is_local_service(~p): Is local", [ Service ]),
- true;
-
- Err ->
- ?debug("is_local_service(~p): Not local: ~p", [ Service, Err ]),
- false
- end;
-
- undefined ->
- ?warning("WARNING: Please set application rvi environment ~p",
- [?NODE_SERVICE_PREFIX]),
- false
- end.
node_address_string() ->
diff --git a/components/service_edge/src/service_edge_rpc.erl b/components/service_edge/src/service_edge_rpc.erl
index 8dbbd8f..c401707 100644
--- a/components/service_edge/src/service_edge_rpc.erl
+++ b/components/service_edge/src/service_edge_rpc.erl
@@ -143,14 +143,18 @@ handle_local_message(ServiceName, Timeout, Parameters, CallingService) ->
{ ok, ok, [Certificate, Signature] } ->
%%
- %% Check if this is a local service. If so, just forward it to its service_name.
+ %% Check if this is a local service by trying to resolve its service name.
+ %% If successful, just forward it to its service_name.
%%
- case rvi_common:is_local_service(ServiceName) of
- true -> %% ServiceName is local. Forward message
+ case rvi_common:send_component_request(service_discovery, resolve_local_service,
+ [
+ {service, ServiceName}
+ ], [ network_address ]) of
+ { ok, ok, [ NetworkAddress] } -> %% ServiceName is local. Forward message
?debug("service_edge_rpc:local_msg(): Service is local. Forwarding."),
- forward_message_to_local_service(ServiceName, Parameters);
+ forward_message_to_local_service(ServiceName, NetworkAddress, xParameters);
- false -> %% ServiceName is remote
+ _ -> %% ServiceName is remote
%% Ask Schedule the request to resolve the network address
?debug("service_edge_rpc:local_msg(): Service is remote. Scheduling."),
forward_message_to_scheduler(ServiceName, Timeout, Parameters, Certificate, Signature)
@@ -217,7 +221,7 @@ flatten_ws_args(Args) ->
flatten_ws_args(Args, []).
dispatch_to_local_service([ $w, $s, $: | WSPidStr], Command, Args) ->
- ?debug("service_edge:dispatch_to_local_service(): Websocket!: ~p, ~p", [ Command, Args]),
+ ?info("service_edge:dispatch_to_local_service(): Websocket!: ~p, ~p", [ Command, Args]),
wse:call(list_to_pid(WSPidStr), wse:window(),
Command, flatten_ws_args(Args)),
ok;
@@ -227,6 +231,48 @@ dispatch_to_local_service(NetworkAddress, Command, Args) ->
rvi_common:send_http_request(NetworkAddress, Command, Args).
+forward_message_to_local_service(ServiceName, NetworkAddress, Parameters) ->
+ ?debug("service_edge:forward_to_local(): URL: ~p", [NetworkAddress]),
+
+ %%
+ %% Strip our node prefix from service_name so that
+ %% the service receiving the JSON rpc call will have
+ %% a service_name that is identical to the service name
+ %% it registered with.
+ %%
+ SvcName = string:substr(ServiceName,
+ length(rvi_common:local_service_prefix())),
+
+ %% Deliver the message to the local service, which can
+ %% be either a wse websocket, or a regular HTTP JSON-RPC call
+ case rvi_common:get_request_result(
+ dispatch_to_local_service(NetworkAddress,
+ "message",
+ [ { service_name, SvcName },
+ { parameters, Parameters }])) of
+
+ %% Request delivered.
+ { ok, ok, _ } ->
+ { ok, [ { status, rvi_common:json_rpc_status(ok)} ] };
+
+ %% status returned was an error code.
+ { ok, undefined } ->
+ ?warning("service_edge:forward_to_local(): "
+ "Local Service ~p at ~p not available.",
+ [ServiceName, NetworkAddress]),
+ { ok, [ { status, rvi_common:json_rpc_status(not_available)}]};
+
+ { ok, Status } ->
+ ?warning(" service_edge:forward_to_local(): Status: ~p",
+ [Status]),
+ { error, [{ status, rvi_common:json_rpc_status(Status)}]};
+
+ %% HTTP or similar error.
+ Err ->
+ ?warning("service_edge:forward_to_local(): Local service failed: ~p", [Err]),
+ Err
+ end.
+
forward_message_to_local_service(ServiceName, Parameters) ->
%%
%% Resolve the local service name to an URL that we can send the
@@ -239,47 +285,8 @@ forward_message_to_local_service(ServiceName, Parameters) ->
[ {service, ServiceName} ],
[ network_address ]) of
{ ok, ok, [ NetworkAddress] } ->
- ?debug("service_edge:forward_to_local(): URL: ~p", [NetworkAddress]),
+ forward_message_to_local_service(ServiceName, NetworkAddress, Parameters);
- %%
- %% Strip our node prefix from service_name so that
- %% the service receiving the JSON rpc call will have
- %% a service_name that is identical to the service name
- %% it registered with.
- %%
- SvcName = string:substr(ServiceName,
- length(rvi_common:local_service_prefix())),
-
- %% Deliver the message to the local service, which can
- %% be either a wse websocket, or a regular HTTP JSON-RPC call
- case rvi_common:get_request_result(
- dispatch_to_local_service(NetworkAddress,
- "message",
- [ { service_name, SvcName },
- { parameters, Parameters }])) of
-
- %% Request delivered.
- { ok, ok, _ } ->
- { ok, [ { status, rvi_common:json_rpc_status(ok)} ] };
-
- %% status returned was an error code.
- { ok, undefined } ->
- ?warning("service_edge:forward_to_local(): "
- "Local Service ~p at ~p not available.",
- [ServiceName, NetworkAddress]),
- { ok, [ { status, rvi_common:json_rpc_status(not_available)}]};
-
- { ok, Status } ->
- ?warning(" service_edge:forward_to_local(): Status: ~p",
- [Status]),
- { error, [{ status, rvi_common:json_rpc_status(Status)}]};
-
- %% HTTP or similar error.
- Err ->
- ?warning("service_edge:forward_to_local(): Local service failed: ~p", [Err]),
- Err
- end;
-
%% Local service could not be resolved to an URL
{ok, not_found, _} ->
?info(" service_edge_rpc:local_msg() Local service ~p not found.",