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

OTP 17 compatibility #1245

Merged
merged 7 commits into from
Sep 10, 2015
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/riak_cs.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -518,3 +518,11 @@
-define(BLOCK_BUCKET_PREFIX, <<"0b:">>). % Version # = 0

-define(MAX_S3_KEY_LENGTH, 1024).

-ifdef(namespaced_types).
-type mochiweb_headers() :: gb_trees:tree().
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not must, but don't you mind updating mochiweb_headers.erl to export such types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next time :)

-type robj_md() :: dict:dict().
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you use riakc_obj:metadata() here?

-else.
-type mochiweb_headers() :: gb_tree().
-type robj_md() :: dict().
-endif.
13 changes: 8 additions & 5 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{sub_dirs, ["rel"]}.

{require_otp_vsn, "R16"}.
{require_otp_vsn, "R16|17"}.

{cover_enabled, false}.

Expand All @@ -9,7 +9,10 @@

{lib_dirs, ["deps", "apps"]}.

{erl_opts, [debug_info, warnings_as_errors, {parse_transform, lager_transform}]}.
{erl_opts, [debug_info,
warnings_as_errors,
{parse_transform, lager_transform},
{platform_define, "^[0-9]+", namespaced_types}]}.

{xref_checks, []}.
{xref_queries,
Expand All @@ -34,19 +37,19 @@
]}.

{deps, [
{lager, ".*", {git, "git://github.com/basho/lager", {tag, "2.2.0"}}},
{lager_syslog, ".*", {git, "git://github.com/basho/lager_syslog", {tag, "2.1.1"}}},
{cuttlefish, ".*", {git, "git://github.com/basho/cuttlefish.git", {tag, "2.0.4"}}},
{node_package, ".*", {git, "git://github.com/basho/node_package", {tag, "2.0.3"}}},
{getopt, ".*", {git, "git://github.com/jcomellas/getopt.git", {tag, "v0.8.2"}}},
{webmachine, ".*", {git, "git://github.com/basho/webmachine", {tag, "1.10.8"}}},
{riakc, ".*", {git, "git://github.com/basho/riak-erlang-client", {tag, "2.1.1"}}},
{lager, ".*", {git, "git://github.com/basho/lager", {tag, "2.1.1"}}},
{lager_syslog, ".*", {git, "git://github.com/basho/lager_syslog", {tag, "2.1.1"}}},
{eper, ".*", {git, "git://github.com/basho/eper.git", "0.92-basho1"}},
{druuid, ".*", {git, "git://github.com/kellymclaughlin/druuid.git", {tag, "0.2"}}},
{poolboy, "0.8.*", {git, "git://github.com/basho/poolboy", "0.8.1p3"}},
{exometer_core, ".*", {git, "git://github.com/Feuerlabs/exometer_core", {tag, "1.2"}}},
{cluster_info, ".*", {git, "git://github.com/basho/cluster_info", {tag, "2.0.3"}}},
{xmerl, ".*", {git, "git://github.com/shino/xmerl", "b35bcb05abaf27f183cfc3d85d8bffdde0f59325"}},
{xmerl, ".*", {git, "git://github.com/shino/xmerl", "1b016a05473e086abadbb3c12f63d167fe96c00f"}},
{erlcloud, ".*", {git, "git://github.com/basho/erlcloud.git", {tag, "0.4.5"}}},
{rebar_lock_deps_plugin, ".*", {git, "git://github.com/seth/rebar_lock_deps_plugin.git", {tag, "3.1.0"}}}
]}.
Expand Down
1 change: 0 additions & 1 deletion riak_test/src/rtcs.erl
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ set_advanced_conf(DevPath, NameValuePairs) ->
[rtcs_dev:update_app_config_file(RiakConf, NameValuePairs) || RiakConf <- AdvancedConfs],
ok.


assert_error_log_empty(N) ->
assert_error_log_empty(current, N).

Expand Down
113 changes: 47 additions & 66 deletions riak_test/src/rtcs_admin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
create_user/4,
create_admin_user/1,
update_user/5,
get_user/4,
list_users/4,
make_authorization/5,
make_authorization/6,
Expand All @@ -49,7 +50,7 @@ storage_stats_json_request(AdminConfig, UserConfig, Begin, End) ->
{struct, Slice} = latest(Samples, undefined),
by_bucket_list(Slice, []).

-spec(create_admin_user(atom()) -> #aws_config{}).
-spec create_admin_user(atom()) -> #aws_config{}.
create_admin_user(Node) ->
User = "admin",
Email = "admin@me.com",
Expand All @@ -60,7 +61,7 @@ create_admin_user(Node) ->
lager:info("Id = ~p",[Id]),
UserConfig.

-spec(create_user(atom(), non_neg_integer()) -> #aws_config{}).
-spec create_user(atom(), non_neg_integer()) -> #aws_config{}.
create_user(Node, UserIndex) ->
{A, B, C} = erlang:now(),
User = "Test User" ++ integer_to_list(UserIndex),
Expand All @@ -71,78 +72,58 @@ create_user(Node, UserIndex) ->
UserConfig#aws_config.secret_access_key]),
UserConfig.

-spec(create_user(non_neg_integer(), string(), string()) -> {#aws_config{}, string()}).
-spec create_user(non_neg_integer(), string(), string()) -> {#aws_config{}, string()}.
create_user(Port, EmailAddr, Name) ->
create_user(Port, undefined, EmailAddr, Name).
%% create_user(Port, undefined, EmailAddr, Name).
create_user(Port, aws_config("admin-key", "admin-secret", Port), EmailAddr, Name).

-spec(create_user(non_neg_integer(), string(), string(), string()) -> {#aws_config{}, string()}).
-spec create_user(non_neg_integer(), string(), string(), string()) -> {#aws_config{}, string()}.
create_user(Port, UserConfig, EmailAddr, Name) ->
lager:debug("Trying to create user ~p", [EmailAddr]),
Resource = "/riak-cs/user",
Date = httpd_util:rfc1123_date(),
Cmd="curl -s -H 'Content-Type: application/json' " ++
"-H 'Date: " ++ Date ++ "' " ++
case UserConfig of
undefined -> "";
_ ->
"-H 'Authorization: " ++
make_authorization("POST", Resource, "application/json",
UserConfig, Date) ++
"' "
end ++
"http://localhost:" ++
integer_to_list(Port) ++
Resource ++
" --data '{\"email\":\"" ++ EmailAddr ++ "\", \"name\":\"" ++ Name ++"\"}'",
lager:debug("Cmd: ~p", [Cmd]),
ReqBody = "{\"email\":\"" ++ EmailAddr ++ "\", \"name\":\"" ++ Name ++"\"}",
Delay = rt_config:get(rt_retry_delay),
Retries = rt_config:get(rt_max_wait_time) div Delay,
OutputFun = fun() -> rt:cmd(Cmd) end,
Condition = fun({Status, Res}) ->
lager:debug("Return (~p), Res: ~p", [Status, Res]),
Status =:= 0 andalso Res /= []
OutputFun = fun() -> catch erlcloud_s3:s3_request(
UserConfig, post, "", Resource, [], "",
{ReqBody, "application/json"}, [])
end,
{_Status, Output} = rtcs:wait_until(OutputFun, Condition, Retries, Delay),
lager:debug("Create user output=~p~n",[Output]),
{struct, JsonData} = mochijson2:decode(Output),
KeyId = binary_to_list(proplists:get_value(<<"key_id">>, JsonData)),
KeySecret = binary_to_list(proplists:get_value(<<"key_secret">>, JsonData)),
Id = binary_to_list(proplists:get_value(<<"id">>, JsonData)),
Condition = fun({'EXIT', Res}) ->
lager:debug("create_user failing, Res: ~p", [Res]),
false;
({_ResHeader, _ResBody}) ->
true
end,
{_ResHeader, ResBody} = rtcs:wait_until(OutputFun, Condition, Retries, Delay),
lager:debug("ResBody: ~s", [ResBody]),
JsonData = mochijson2:decode(ResBody),
[KeyId, KeySecret, Id] = [binary_to_list(rtcs:json_get([K], JsonData)) ||
K <- [<<"key_id">>, <<"key_secret">>, <<"id">>]],
{aws_config(KeyId, KeySecret, Port), Id}.

-spec(update_user(#aws_config{}, non_neg_integer(), string(), string(), string()) -> string()).
update_user(UserConfig, Port, Resource, ContentType, UpdateDoc) ->
Date = httpd_util:rfc1123_date(),
Cmd="curl -s -X PUT -H 'Date: " ++ Date ++
"' -H 'Content-Type: " ++ ContentType ++
"' -H 'Authorization: " ++
make_authorization("PUT", Resource, ContentType, UserConfig, Date) ++
"' http://localhost:" ++ integer_to_list(Port) ++
Resource ++ " --data-binary " ++ UpdateDoc,
Delay = rt_config:get(rt_retry_delay),
Retries = rt_config:get(rt_max_wait_time) div Delay,
OutputFun = fun() -> os:cmd(Cmd) end,
Condition = fun(Res) -> Res /= [] end,
Output = rtcs:wait_until(OutputFun, Condition, Retries, Delay),
lager:debug("Update user output=~p~n",[Output]),
Output.

-spec(list_users(#aws_config{}, non_neg_integer(), string(), string()) -> string()).
list_users(UserConfig, Port, Resource, AcceptContentType) ->
Date = httpd_util:rfc1123_date(),
Cmd="curl -s -H 'Date: " ++ Date ++
"' -H 'Accept: " ++ AcceptContentType ++
"' -H 'Authorization: " ++
make_authorization("GET", Resource, "", UserConfig, Date) ++
"' http://localhost:" ++ integer_to_list(Port) ++
Resource,
Delay = rt_config:get(rt_retry_delay),
Retries = rt_config:get(rt_max_wait_time) div Delay,
OutputFun = fun() -> os:cmd(Cmd) end,
Condition = fun(Res) -> Res /= [] end,
Output = rtcs:wait_until(OutputFun, Condition, Retries, Delay),
lager:debug("List users output=~p~n",[Output]),
Output.
-spec update_user(#aws_config{}, non_neg_integer(), string(), string(), string()) -> string().
update_user(UserConfig, _Port, Resource, ContentType, UpdateDoc) ->
{_ResHeader, ResBody} = erlcloud_s3:s3_request(
UserConfig, put, "", Resource, [], "",
{UpdateDoc, ContentType}, []),
lager:debug("ResBody: ~s", [ResBody]),
ResBody.

-spec get_user(#aws_config{}, non_neg_integer(), string(), string()) -> string().
get_user(UserConfig, _Port, Resource, AcceptContentType) ->
lager:debug("Retreiving user record"),
Headers = [{"Accept", AcceptContentType}],
{_ResHeader, ResBody} = erlcloud_s3:s3_request(
UserConfig, get, "", Resource, [], "", "", Headers),
lager:debug("ResBody: ~s", [ResBody]),
ResBody.

-spec list_users(#aws_config{}, non_neg_integer(), string(), string()) -> string().
list_users(UserConfig, _Port, Resource, AcceptContentType) ->
Headers = [{"Accept", AcceptContentType}],
{_ResHeader, ResBody} = erlcloud_s3:s3_request(
UserConfig, get, "", Resource, [], "", "", Headers),
ResBody.

-spec(make_authorization(string(), string(), string(), #aws_config{}, string()) -> string()).
make_authorization(Method, Resource, ContentType, Config, Date) ->
Expand All @@ -166,7 +147,7 @@ make_authorization(Type, Method, Resource, ContentType, Config, Date, AmzHeaders
base64:encode_to_string(rtcs:sha_mac(Config#aws_config.secret_access_key, StringToSign)),
lists:flatten([Prefix, " ", Config#aws_config.access_key_id, $:, Signature]).

-spec(aws_config(string(), string(), non_neg_integer()) -> #aws_config{}).
-spec aws_config(string(), string(), non_neg_integer()) -> #aws_config{}.
aws_config(Key, Secret, Port) ->
erlcloud_s3:new(Key,
Secret,
Expand All @@ -177,7 +158,7 @@ aws_config(Key, Secret, Port) ->
Port,
[]).

-spec(aws_config(#aws_config{}, [{atom(), term()}]) -> #aws_config{}).
-spec aws_config(#aws_config{}, [{atom(), term()}]) -> #aws_config{}.
aws_config(UserConfig, []) ->
UserConfig;
aws_config(UserConfig, [{port, Port}|Props]) ->
Expand Down
Loading