Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Series of dialyzer and formatting changes. #59

Merged
merged 2 commits into from Feb 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,3 +7,4 @@ erl_crash.dump
EUnit-SASL.log
priv/admin/js/templates.js
priv/admin/js/vendor.js
tags
24 changes: 15 additions & 9 deletions include/riak_control.hrl
Expand Up @@ -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/").
Expand All @@ -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").
65 changes: 34 additions & 31 deletions src/admin_partitions.erl
Expand Up @@ -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}.