Permalink
Browse files

Merge pull request #59 from basho/csm-add-planning-api

Series of dialyzer and formatting changes.
  • Loading branch information...
2 parents 3f72461 + e9ed6c7 commit 28cde807475b3bb88dc2b644698c27f65491c6b2 @cmeiklejohn cmeiklejohn committed Feb 28, 2013
Showing with 281 additions and 274 deletions.
  1. +1 −0 .gitignore
  2. +15 −9 include/riak_control.hrl
  3. +34 −31 src/admin_partitions.erl
  4. +223 −226 src/riak_control_session.erl
  5. +8 −8 src/riak_control_sup.erl
View
@@ -7,3 +7,4 @@ erl_crash.dump
EUnit-SASL.log
priv/admin/js/templates.js
priv/admin/js/vendor.js
+tags
View
@@ -19,37 +19,43 @@
%% -------------------------------------------------------------------
-type version() :: integer().
--type index() :: binary().
+-type index() :: integer().
-type status() :: valid | invalid | down | leaving | incompatible.
-type home() :: primary | fallback | undefined.
--type service() :: atom().
--type services() :: [{service(),home()}].
+-type service() :: {atom(), home()}.
+-type services() :: [service()].
-type owner() :: atom().
--type vnode() :: {{atom(),atom()},atom()}. % {{Idx,Node},Status}
--type handoff() :: {{atom(),atom()},atom()}. % {{Mod,Idx},TargetNode}
+-type vnode() :: {{atom(),atom()},atom()}.
+-type handoff() :: {atom(),integer(),atom()}.
-type online() :: boolean().
+-type ring() :: riak_core_ring:riak_core_ring().
+-type handoffs() :: [handoff()].
+-type vnodes() :: [vnode()].
-record(partition_info,
{ index :: index(),
partition :: integer(),
owner :: owner(),
vnodes :: services(),
- handoffs :: [handoff()]
+ handoffs :: handoffs()
}).
-record(member_info,
{ node :: atom(),
status :: status(),
reachable :: boolean(),
- vnodes :: [vnode()],
- handoffs :: [handoff()],
+ vnodes :: vnodes(),
+ handoffs :: handoffs(),
ring_pct :: float(),
pending_pct :: float(),
mem_total :: integer(),
mem_used :: integer(),
mem_erlang :: integer()
}).
+-type partitions() :: [#partition_info{}].
+-type members() :: [#member_info{}].
+
%% These two should always match, in terms of webmachine dispatcher
%% logic, and ADMIN_BASE_PATH should always end with a /
-define(ADMIN_BASE_PATH, "/admin/").
@@ -59,4 +65,4 @@
-define(ADMIN_AUTH_HEAD, "Basic realm=riak").
%% Names of HTTP header fields
--define(HEAD_CTYPE, "Content-Type").
+-define(HEAD_CTYPE, "Content-Type").
View
@@ -19,52 +19,55 @@
%% -------------------------------------------------------------------
-module(admin_partitions).
+
+-author('Christopher Meiklejohn <cmeiklejohn@basho.com>').
+
-export([routes/0,
init/1,
content_types_provided/2,
to_json/2,
is_authorized/2,
service_available/2,
- forbidden/2
- ]).
+ forbidden/2]).
-%% riak_control and webmachine dependencies
-include_lib("riak_control/include/riak_control.hrl").
-include_lib("webmachine/include/webmachine.hrl").
-%% mappings to the various content types supported for this resource
--define(CONTENT_TYPES,[{"application/json",to_json}]).
+-define(CONTENT_TYPES, [{"application/json",to_json}]).
+
+-define(VNODE_TYPES, [riak_kv,riak_pipe,riak_search]).
-%% the different vnode types we care about
--define(VNODE_TYPES,[riak_kv,riak_pipe,riak_search]).
+-record(context, {partitions}).
-%% defines the webmachine routes this module handles
-routes () ->
- [{admin_routes:partitions_route(),?MODULE,[]}].
+%% @doc Route handling.
+routes() ->
+ [{admin_routes:partitions_route(), ?MODULE, []}].
-%% entry-point for the resource from webmachine
-init ([]) ->
- {ok,_V,Partitions}=riak_control_session:get_partitions(),
- {ok,Partitions}.
+%% @doc Get partition list at the start of the request.
+init([]) ->
+ {ok, _, Partitions} = riak_control_session:get_partitions(),
+ {ok, #context{partitions=Partitions}}.
-%% validate origin
-forbidden(RD, C) ->
- {riak_control_security:is_null_origin(RD), RD, C}.
+%% @doc Validate origin.
+forbidden(ReqData, Context) ->
+ {riak_control_security:is_null_origin(ReqData), ReqData, Context}.
-%% redirect to SSL port if using HTTP
-service_available (RD,C) ->
- riak_control_security:scheme_is_available(RD,C).
+%% @doc Determine if it's available.
+service_available(ReqData, Context) ->
+ riak_control_security:scheme_is_available(ReqData, Context).
-%% validate username and password
-is_authorized (RD,C) ->
- riak_control_security:enforce_auth(RD,C).
+%% @doc Handle authorization.
+is_authorized(ReqData, Context) ->
+ riak_control_security:enforce_auth(ReqData, Context).
-%% return the list of available content types for webmachine
-content_types_provided (Req,C) ->
- {?CONTENT_TYPES,Req,C}.
+%% @doc Return available content types.
+content_types_provided(ReqData, Context) ->
+ {?CONTENT_TYPES, ReqData, Context}.
-%% valid | invalid | joining | leaving | exiting
-to_json (Req,C=Partitions) ->
- {ok,_V,Nodes}=riak_control_session:get_nodes(),
- Details=[{struct,riak_control_formatting:node_ring_details(P,Nodes)} || P <- Partitions],
- {mochijson2:encode({struct,[{partitions,Details}]}), Req,C}.
+%% @doc Return a list of partitions.
+to_json(ReqData, Context) ->
+ {ok, _, Nodes} = riak_control_session:get_nodes(),
+ Details = [{struct,
+ riak_control_formatting:node_ring_details(P, Nodes)} ||
+ P <- Context#context.partitions],
+ {mochijson2:encode({struct,[{partitions,Details}]}), ReqData, Context}.
Oops, something went wrong.

0 comments on commit 28cde80

Please sign in to comment.