-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Aravinda Vishwanathapura <[email protected]>
- Loading branch information
1 parent
e87f6d6
commit 1c76601
Showing
10 changed files
with
137 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
require "./helpers" | ||
|
||
struct NodeArgs | ||
property status = false | ||
end | ||
|
||
class Args | ||
property node_args = NodeArgs.new | ||
end | ||
|
||
command "node.join", "Join a node to Kadalu Storage Cluster" do |parser, args| | ||
parser.banner = "Usage: kadalu node join NAME ENDPOINT [arguments]" | ||
parser.on("-c NAME", "--cluster=NAME", "Cluster name") do |name| | ||
args.cluster_name = name | ||
end | ||
end | ||
|
||
handler "node.join" do |args| | ||
if args.pos_args.size < 2 | ||
STDERR.puts "Node name and Node endpoint are required." | ||
exit 1 | ||
end | ||
|
||
# TODO: Add default Cluster logic once it is available | ||
if args.cluster_name == "" | ||
STDERR.puts "--cluster=NAME is required." | ||
exit 1 | ||
end | ||
|
||
name = args.pos_args[0] | ||
endpoint = args.pos_args[1] | ||
api_call(args, "Failed to join the Node") do |client| | ||
node = client.cluster(args.cluster_name).join_node(name, endpoint) | ||
puts "Node #{name}(#{endpoint}) joined to #{args.cluster_name} successfully" | ||
puts "ID: #{node.id}" | ||
end | ||
end | ||
|
||
command "node.list", "Nodes list of a Kadalu Storage Cluster" do |parser, args| | ||
parser.banner = "Usage: kadalu node list [arguments]" | ||
parser.on("-c NAME", "--cluster=NAME", "Cluster name") do |name| | ||
args.cluster_name = name | ||
end | ||
parser.on("--status", "Show nodes states") do | ||
args.node_args.status = true | ||
end | ||
end | ||
|
||
handler "node.list" do |args| | ||
if args.cluster_name == "" | ||
STDERR.puts "--cluster=NAME is required." | ||
exit 1 | ||
end | ||
|
||
api_call(args, "Failed to get list of nodes") do |client| | ||
nodes = client.cluster(args.cluster_name).list_nodes(state: args.node_args.status) | ||
puts "No nodes added to the Cluster. Run `kadalu node join -c #{args.cluster_name} <node-name> <node-endpoint>` to add a node." if nodes.size == 0 | ||
|
||
if args.node_args.status | ||
printf("%36s %6s %20s %s\n", "ID", "State", "Name", "Endpoint") | ||
else | ||
printf("%36s %20s %s\n", "ID", "Name", "Endpoint") | ||
end | ||
|
||
nodes.each do |node| | ||
if args.node_args.status | ||
printf("%36s %6s %20s %s\n", node.id, node.state, node.name, node.endpoint) | ||
else | ||
printf("%36s %20s %s\n", node.id, node.name, node.endpoint) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require "./helpers" | ||
require "../conf" | ||
require "../datastore/*" | ||
|
||
get "/api/v1/clusters/:cluster_name/nodes" do |env| | ||
cluster_name = env.params.url["cluster_name"] | ||
state = env.params.query["state"] | ||
|
||
nodes = Datastore.list_nodes(cluster_name) | ||
|
||
next nodes.to_json unless state | ||
|
||
resp = dispatch_action( | ||
ACTION_PING, | ||
cluster_name, | ||
nodes | ||
) | ||
|
||
nodes.each do |node| | ||
node.state = resp.node_responses[node.name].ok ? "Up" : "Down" | ||
end | ||
|
||
nodes.to_json | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters