Skip to content

Commit

Permalink
Address review comments 1
Browse files Browse the repository at this point in the history
Signed-off-by: Shree Vatsa N <[email protected]>
  • Loading branch information
vatsa287 committed Jan 17, 2023
1 parent 26e40b8 commit f1ac911
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 82 deletions.
47 changes: 47 additions & 0 deletions mgr/src/cmds/rebalance_start_stop.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require "./helpers"

command "rebalance.start", "Start Rebalancing Kadalu Storage volume" do |parser, _|
parser.banner = "Usage: kadalu rebalance start POOL/VOLNAME [arguments]"
end

handler "rebalance.start" do |args|
begin
command_error "Pool/Volname is required" if args.pos_args.size == 0
args.pool_name, volume_name = pool_and_volume_name(args.pos_args.size > 0 ? args.pos_args[0] : "")
api_call(args, "Failed to start rebalancing of volume") do |client|
volume = client.pool(args.pool_name).volume(volume_name).rebalance_start

handle_json_output(volume, args)

puts "Rebalance of Volume #{volume.name} started"
end
rescue ex : InvalidVolumeRequest
STDERR.puts "Starting of volume rebalance failed"
STDERR.puts ex
exit 1
end
end

command "rebalance.stop", "Stop Rebalancing Kadalu Storage volume" do |parser, _|
parser.banner = "Usage: kadalu rebalance stop POOL/VOLNAME [arguments]"
end

handler "rebalance.stop" do |args|
begin
command_error "Pool/Volname is required" if args.pos_args.size == 0
args.pool_name, volume_name = pool_and_volume_name(args.pos_args.size > 0 ? args.pos_args[0] : "")
next unless (args.script_mode || yes("Are you sure you want to stop rebalancing of volume? [y/N]"))

api_call(args, "Failed to stop rebalancing of volume.") do |client|
volume = client.pool(args.pool_name).volume(volume_name).rebalance_stop

handle_json_output(volume, args)

puts "Rebalancing of Volume #{volume.name} stopped"
end
rescue ex : InvalidVolumeRequest
STDERR.puts "Stopping of volume rebalance failed"
STDERR.puts ex
exit 1
end
end
46 changes: 0 additions & 46 deletions mgr/src/cmds/volumes.cr
Original file line number Diff line number Diff line change
Expand Up @@ -347,49 +347,3 @@ handler "volume.expand" do |args|
exit 1
end
end

command "volume.rebalance-start", "Start Rebalancing Kadalu Storage volume" do |parser, _|
parser.banner = "Usage: kadalu volume rebalance-start POOL/VOLNAME [arguments]"
end

handler "volume.rebalance-start" do |args|
begin
command_error "Pool/Volname is required" if args.pos_args.size == 0
args.pool_name, volume_name = pool_and_volume_name(args.pos_args.size > 0 ? args.pos_args[0] : "")
api_call(args, "Failed to start rebalancing of volume") do |client|
volume = client.pool(args.pool_name).volume(volume_name).rebalance_start

handle_json_output(volume, args)

puts "Rebalance of Volume #{volume.name} started"
end
rescue ex : InvalidVolumeRequest
STDERR.puts "Starting of volume rebalance failed"
STDERR.puts ex
exit 1
end
end

command "volume.rebalance-stop", "Stop Rebalancing Kadalu Storage volume" do |parser, _|
parser.banner = "Usage: kadalu volume rebalance-stop POOL/VOLNAME [arguments]"
end

handler "volume.rebalance-stop" do |args|
begin
command_error "Pool/Volname is required" if args.pos_args.size == 0
args.pool_name, volume_name = pool_and_volume_name(args.pos_args.size > 0 ? args.pos_args[0] : "")
next unless (args.script_mode || yes("Are you sure you want to stop rebalancing of volume? [y/N]"))

api_call(args, "Failed to stop rebalancing of volume.") do |client|
volume = client.pool(args.pool_name).volume(volume_name).rebalance_stop

handle_json_output(volume, args)

puts "Rebalancing of Volume #{volume.name} stopped"
end
rescue ex : InvalidVolumeRequest
STDERR.puts "Stopping of volume rebalance failed"
STDERR.puts ex
exit 1
end
end
31 changes: 1 addition & 30 deletions mgr/src/server/plugins/volume_utils.cr
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def restart_shd_service_and_manage_rebalance_services(services, action = "start"
if svc.name == "shdservice"
svc.restart
elsif svc.name == "fixlayoutservice" || svc.name == "migratedataservice"
status_file_path = "/var/lib/kadalu/#{svc.id.gsub("/", "%2F")}.json"
status_file_path = "/var/lib/kadalu/#{svc.id}.json"
FileUtils.rm(status_file_path) if File.exists?(status_file_path)
if action == "start"
svc.start
Expand Down Expand Up @@ -549,32 +549,3 @@ def add_migrate_data_service(services, pool_name, volume_name, node, storage_uni

services
end

def handle_volume_rebalance_start_stop(data, action)
services, volfiles, _ = VolumeRequestToNode.from_json(data)

if action == "start" && !volfiles[GlobalConfig.local_node.id]?.nil?
Dir.mkdir_p(Path.new(GlobalConfig.workdir, "volfiles"))
volfiles[GlobalConfig.local_node.id].each do |volfile|
File.write(Path.new(GlobalConfig.workdir, "volfiles", "#{volfile.name}.vol"), volfile.content)
end
end

unless services[GlobalConfig.local_node.id]?.nil?
# TODO: Hard coded path change?
Dir.mkdir_p("/var/log/kadalu")
Dir.mkdir_p("/run/kadalu")
services[GlobalConfig.local_node.id].each do |service|
svc = Service.from_json(service.to_json)
if svc.name == "migratedataservice"
if action == "start"
svc.start
else
svc.stop
end
end
end
end

NodeResponse.new(true, "")
end
2 changes: 1 addition & 1 deletion mgr/src/server/services/fix_layout.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class FixLayoutService < Service
@create_pid_file = true

@path = PROGRAM_NAME == "kadalu" ? PROGRAM_NAME : Path[PROGRAM_NAME].expand.to_s
@id = "rebalance-fix-layout-#{storage_unit.path}"
@id = "rebalance-fix-layout-#{storage_unit.path.gsub("/", "%2F")}"
@pid_file = "/run/kadalu/#{@id}.pid"
@args = [
"_rebalance", "--fix-layout",
Expand Down
2 changes: 1 addition & 1 deletion mgr/src/server/services/migrate_data.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MigrateDataService < Service
@create_pid_file = true

@path = PROGRAM_NAME == "kadalu" ? PROGRAM_NAME : Path[PROGRAM_NAME].expand.to_s
@id = "rebalance-migrate-data-#{storage_unit.path}"
@id = "rebalance-migrate-data-#{storage_unit.path.gsub("/", "%2F")}"
@pid_file = "/run/kadalu/#{@id}.pid"
@args = [
"_rebalance", "--migrate-data",
Expand Down
8 changes: 4 additions & 4 deletions tests/all/volumes.t
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ USE_NODE nodes[2]
EQUAL "3", (TEST "ls /exports/vol15/s3_e/* -d | wc -l").strip, "Check for fix-layout in server3 s3 unit"

USE_NODE nodes[0]
TEST "kadalu volume rebalance-start DEV/vol15"
TEST "kadalu rebalance start DEV/vol15"
TEST "sleep 3"

EQUAL "3", (TEST "ls /exports/vol15/s1/d1/f3 /exports/vol15/s1/d2/f3 /exports/vol15/s1/d3/f3 | wc -l").strip, "Check for migrate-data in server1 s1 unit vol15"
Expand Down Expand Up @@ -296,7 +296,7 @@ USE_NODE nodes[2]
EQUAL "3", (TEST "ls /exports/vol16/s3_e/* -d | wc -l").strip, "Check for fix-layout in server3 s3 unit vol16"

USE_NODE nodes[0]
TEST "kadalu volume rebalance-start DEV/vol16"
TEST "kadalu rebalance start DEV/vol16"
TEST "sleep 3"

EQUAL "5", (TEST "ls /exports/vol16/s1/d1/ | wc -l").strip, "Check for migrate-data in server1 s1/d1 unit vol16"
Expand Down Expand Up @@ -354,7 +354,7 @@ EQUAL "3", (TEST "ls /exports/vol17/s3_e/* -d | wc -l").strip, "Check for fix-la
EQUAL "3", (TEST "ls /exports/vol17/s6_e/* -d | wc -l").strip, "Check for fix-layout in server3 s6 unit vol17"

USE_NODE nodes[0]
TEST "kadalu volume rebalance-start DEV/vol17"
TEST "kadalu rebalance start DEV/vol17"
TEST "sleep 3"

EQUAL "2", (TEST "ls /exports/vol17/s1/d1/ | wc -l").strip, "Check for migrate-data in server1 s1/d1 unit vol17"
Expand Down Expand Up @@ -433,7 +433,7 @@ USE_NODE nodes[2]
EQUAL "3", (TEST "ls /exports/vol18/s3_e/* -d | wc -l").strip, "Check for fix-layout in server3 s3 unit vol18"

USE_NODE nodes[0]
TEST "kadalu volume rebalance-start DEV/vol18"
TEST "kadalu rebalance start DEV/vol18"
TEST "sleep 3"

EQUAL "5", (TEST "ls /exports/vol18/s1/d1/ | wc -l").strip, "Check for migrate-data in server1 s1/d1 unit vol18"
Expand Down

0 comments on commit f1ac911

Please sign in to comment.