dizzyd avatar dizzyd committed 118fe54

Adding console module for commands from riak-admin; adding riak:join/1 for convenince in shell

Comments (0)

Files changed (4)

apps/riak/ebin/riak.app

              riak_claim,
              riak_client,
              riak_connect,
+             riak_console,
              riak_delete,
              riak_dets_backend,
              riak_ets_backend,

apps/riak/src/riak.erl

 -export([stop/0, stop/1]).
 -export([get_app_env/1,get_app_env/2]).
 -export([client_connect/1,client_connect/2,
-         local_client/0,local_client/1]).
+         local_client/0,local_client/1,
+         join/1]).
 -export([code_hash/0]).
 
 -include_lib("eunit/include/eunit.hrl").
 client_connect(Node, Other) ->
     client_connect(Node, <<(erlang:phash2(Other)):32>>).
 
+join(NodeStr) when is_list(NodeStr) ->
+    join(riak_util:str_to_node(NodeStr));
+join(Node) when is_atom(Node) ->
+    case net_adm:ping(Node) of
+        pong ->
+            riak_connect:send_ring(Node, node());
+        pang ->
+            {error, not_reachable}
+    end.
+
 
 %% 719528 days from Jan 1, 0 to Jan 1, 1970
 %%  *86400 seconds/day

apps/riak/src/riak_console.erl

+%% This file is provided to you under the Apache License,
+%% Version 2.0 (the "License"); you may not use this file
+%% except in compliance with the License.  You may obtain
+%% a copy of the License at
+
+%%   http://www.apache.org/licenses/LICENSE-2.0
+
+%% Unless required by applicable law or agreed to in writing,
+%% software distributed under the License is distributed on an
+%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+%% KIND, either express or implied.  See the License for the
+%% specific language governing permissions and limitations
+%% under the License.    
+
+%% @doc Riak: A lightweight, decentralized key-value store.
+%% @author Andy Gross <andy@basho.com>
+%% @author Justin Sheehy <justin@basho.com>
+%% @author Bryan Fink <bryan@basho.com>
+%% @copyright 2007-2009 Basho Technologies, Inc.  All Rights Reserved.
+-module(riak_console).
+
+-export([join/1]).
+
+join([NodeStr]) ->
+    case riak:join(NodeStr) of
+        ok ->
+            io:format("Sent join request to ~s\n", [NodeStr]),
+            ok;
+        {error, not_reachable} ->
+            io:format("Node ~s is not reachable!\n", [NodeStr]),
+            error
+    end.
+
+
+

apps/riak/src/riak_util.erl

 
 -export([moment/0,make_tmp_dir/0,compare_dates/2,reload_all/1,
          is_x_deleted/1,obj_not_deleted/1,integer_to_list/2,
-         unique_id_62/0]).
+         unique_id_62/0,
+         str_to_node/1]).
 -export([chash_key/1,chash_std_keyfun/1,chash_bucketonly_keyfun/1]).
 -export([try_cast/4, fallback/4, mkclientid/1]).
 
 clientid_uniqueness_test() ->
     ClientIds = [mkclientid('somenode@somehost') || _I <- lists:seq(0, 10000)],
     length(ClientIds) =:= length(sets:to_list(sets:from_list(ClientIds))).
+
+str_to_node(NodeStr) ->
+    case string:tokens(NodeStr, "@") of
+        [NodeName] ->
+            %% Node name only; no host name. If the local node has a hostname,
+            %% append it
+            case node_hostname() of
+                [] ->
+                    list_to_atom(NodeName);
+                Hostname ->
+                    list_to_atom(NodeName ++ "@" ++ Hostname)
+            end;
+        _ ->
+            list_to_atom(NodeStr)
+    end.
+
+node_hostname() ->
+    NodeStr = atom_to_list(node()),
+    case string:tokens(NodeStr, "@") of
+        [_NodeName, Hostname] ->
+            Hostname;
+        _ ->
+            []
+    end.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.