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

Implement cluster CLI commands #659

Merged
merged 10 commits into from
Dec 10, 2014

Conversation

jadeallenx
Copy link
Contributor

Implement the following commands using riak_cli:

  • cluster status (improved member-status)
  • partition-count
  • partitions
  • partition id=
  • partition index=
  • members

TODO: After merge, some code clean up and boundary checking.

Depends on basho/riak_ee#295

T2 = riak_cli_status:text(
"Key: (C) = Claimant; availability marked with '!' is unexpected"),
Out = riak_cli_status:alert([T0,T1,Table,T2]),
riak_cli:print([Out]).
Copy link
Contributor

Choose a reason for hiding this comment

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

I've been thinking about this a bit. I didn't really intend for implementers to constantly call riak_cli:print/1. I intended for it to be called automatically and use the proper writer module given global --csv flags etc..., but of course I didn't implement it that way. I spent a lot of time focusing on config the last few weeks and if you look in riak_cli.erl you'll see that the config ops (show, describe, set) wrap the output in a print statement, and the callbacks themselves return errors tuples or status types. Returning errors works fine for config because it's all internal and riak_cli_error knows how to parse the riak_cli specific errors and generate alerts from them. However, since that requires modifying riak_cli itself, outside users of riak_cli should only ever return status types in callbacks.

This was a mistake in implementation that I will fix on Monday. We can then modify each PR to do the right thing and only return a status(). In your case it will just be removing the riak_cli:print/1 calls. Hopefully the same elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, gotcha. Now that basho/clique#14 has been merged, I will fix it up.

After basho/clique#14 was merged, callbacks are expected
to implement riak_cli_status types as their return values.
@jadeallenx
Copy link
Contributor Author

@andrewjstone I've pushed a new commit responding to your code review.

{pending, future_claim_percentage(Changes, Ring, Node)}
].

is_claimant(Node, Node) ->
Copy link
Contributor

Choose a reason for hiding this comment

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

This is totally a bikeshed comment and won't hold up a +1 of this PR. I was just thinking that we should align this better. Either put the (c) after the Node name, since it's left aligned, or put 3 spaces before the non-claimant nodes so it is right - aligned.

@jadeallenx
Copy link
Contributor Author

Ping @andrewjstone

node_availability(Node, Down, MarkedDown) ->
case {lists:member(Node, Down), lists:member(Node, MarkedDown)} of
{false, false} -> " up "; % put common case at the top
{true, true} -> " down ";
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you line this clause up please?

@jadeallenx
Copy link
Contributor Author

@andrewjstone think 3e28706 is a winner :)

@andrewjstone
Copy link
Contributor

I'm seeing the following behavior, but I believe it should be fixed in riak_cli. In this case ["riak-admin", "cluster", "partition"] has both a command and usage point. If riak_cli knew that the command required more than 1 argument it could automatically show usage if no arguments were given. This would require each user to change their specs to inform riak_cli of the number of required arguments. Alternatively, we could always show the usage if a client returns {error, usage} or {error, usage, Status}. That's probably a more robust solution for cases like these.

Andrews-MacBook-Pro:riak_ee ajs$ dev/dev1/bin/riak-admin cluster partition
RPC to 'dev1@127.0.0.1' failed: {'EXIT',
                                 {function_clause,
                                  [{riak_core_cluster_cli,partition,
                                    [[],[]],
                                    [{file,"src/riak_core_cluster_cli.erl"},
                                     {line,218}]},
                                   {riak_cli,run,1,
                                    [{file,"src/riak_cli.erl"},{line,70}]},
                                   {rpc,'-handle_call_call/6-fun-0-',5,
                                    [{file,"rpc.erl"},{line,205}]}]}}
Andrews-MacBook-Pro:riak_ee ajs$ dev/dev1/bin/riak-admin cluster partition -h
Usage: riak-admin cluster partition id=0
riak-admin cluster partition index=22835963083295358096932575511191922182123945984

Returns the id or index for the specified index or id.

@andrewjstone
Copy link
Contributor

👍 3e28706

Great work @mrallen1

borshop added a commit that referenced this pull request Dec 10, 2014
Implement cluster CLI commands

Reviewed-by: andrewjstone
@andrewjstone
Copy link
Contributor

@borshop merge

@borshop borshop merged commit 3e28706 into integration/riak-admin-handoff-team Dec 10, 2014
@jadeallenx jadeallenx deleted the feature/mra/cluster-cli branch December 10, 2014 15:28
jadeallenx pushed a commit to basho/riak that referenced this pull request Dec 10, 2014
jadeallenx pushed a commit to basho/riak that referenced this pull request Dec 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants