Permalink
Browse files

merge

  • Loading branch information...
justin
justin committed Sep 25, 2009
2 parents db225b3 + c73678f commit 8e36109badf05313061bed5d47f551414b8afc59
Showing with 21 additions and 19 deletions.
  1. +21 −19 riak_demo.escript
View
@@ -1,11 +1,11 @@
#!/usr/bin/env escript
%% -*- erlang -*-
-%%! -name riak_demo@127.0.0.1 -pa ebin
+%%! -name riak_demo@127.0.0.1 -pa ebin -setcookie xyzzy
main([ConfigFile]) ->
case file:consult(ConfigFile) of
{ok, Config} ->
- run_demo(proplists:get_value(riak_hostname, Config),
- proplists:get_value(doorbell_port, Config),
+ run_demo(proplists:get_value(riak_nodename, Config),
+ proplists:get_value(riak_hostname, Config),
proplists:get_value(riak_cookie, Config));
Error ->
io:format("Error: could not open config file: ~p~n", [Error]),
@@ -18,43 +18,45 @@ usage() ->
io:format("usage: riak_demo.escript CONFIG_FILENAME~n"),
halt(1).
-run_demo(Hostname, Port, Cookie) when is_list(Hostname),
- is_integer(Port),
- is_atom(Cookie) ->
- io:format("Attempting to connect to ~s:~p with cookie ~p...~n",
- [Hostname, Port, Cookie]),
- case riak:client_connect(Hostname, Port, Cookie) of
+run_demo(NodeName, Hostname, Cookie) when is_atom(NodeName),
+ is_list(Hostname),
+ is_atom(Cookie) ->
+ Node = list_to_atom(atom_to_list(NodeName)++"@"++Hostname),
+ io:format("Attempting to connect to ~p with cookie ~p...~n",
+ [Node, Cookie]),
+ erlang:set_cookie(Node, Cookie),
+ case riak:client_connect(Node) of
{ok, Client} ->
io:format("Connected successfully~n"),
continue_demo(Client);
Error ->
io:format("Error: failed to connect to Riak cluster: ~p", [Error])
end;
-run_demo(Hostname, Port, Cookie) ->
+run_demo(NodeName, Hostname, Cookie) ->
io:format("Error: invalid configuration file:~n"),
+ if is_list(NodeName) -> ok;
+ true -> io:format(" riak_nodename must be an atom (ex. 'riak')~n")
+ end,
if is_list(Hostname) -> ok;
true -> io:format(" riak_hostname must be a list (ex. \"127.0.0.1\")~n")
end,
- if is_integer(Port) -> ok;
- true -> io:format(" doorbell_port must be an integer (ex. 9000)~n")
- end,
if is_atom(Cookie) -> ok;
true -> io:format(" riak_cookie must be an atom (ex. 'riak_cookie')~n")
end,
usage().
continue_demo(Client) ->
- io:format("Looking for pre-existing object at {riak_demo, \"demo\"}...~n"),
+ io:format("Looking for pre-existing object at {<<\"riak_demo\">>, <<\"demo\">>}...~n"),
WrittenValue =
- case Client:get(riak_demo, <<"demo">>, 1) of
+ case Client:get(<<"riak_demo">>, <<"demo">>, 1) of
{error, notfound} ->
io:format(" No pre-existing object found, creating new~n"),
- demo_write(Client, riak_object:new(riak_demo, <<"demo">>, undefined));
+ demo_write(Client, riak_object:new(<<"riak_demo">>, <<"demo">>, undefined));
{ok, Object} ->
io:format(" Pre-existing object found, modifying~n"),
demo_write(Client, Object);
Error ->
- io:format("Error: request for {riak_demo, \"demo\"} failed: ~p~n",
+ io:format("Error: request for {<<\"riak_demo\">>, <<\"demo\">>} failed: ~p~n",
[Error]),
halt(1)
end,
@@ -75,8 +77,8 @@ demo_write(Client, Object0) ->
end.
demo_read(Client, WrittenValue) ->
- io:format("Fetching object at {riak_demo, \"demo\"}...~n"),
- case Client:get(riak_demo, <<"demo">>, 1) of
+ io:format("Fetching object at {<<\"riak_demo\">>, <<\"demo\">>}...~n"),
+ case Client:get(<<"riak_demo">>, <<"demo">>, 1) of
{ok, Object} ->
io:format(" Fetched successfully~n"),
case lists:member(WrittenValue, riak_object:get_values(Object)) of

0 comments on commit 8e36109

Please sign in to comment.