Commit 84b82bd4 authored by Sushil Khanchi's avatar Sushil Khanchi 🐨
Browse files

native-migration: pre-check if Gitaly and HGitaly are running

Also, added color to puts statements.

--HG--
branch : heptapod-stable
parent 92bbc064cdc4
Pipeline #26614 passed with stages
in 14 minutes and 31 seconds
......@@ -35,6 +35,15 @@ def migrate!
end
end
def log_error(err, msg)
Gitlab::AppLogger.error(
message: msg,
backtrace: Gitlab::BacktraceCleaner.clean_backtrace(err.backtrace),
project_id: @project.id,
project_full_path: @project.full_path
)
end
def do_migrate
Gitlab::AppLogger.info(
message: "Starting native hg migration",
......@@ -56,22 +65,9 @@ def do_migrate
@project.vcs_type = 'hg'
@project.save!
rescue GRPC::Unavailable => err
Gitlab::AppLogger.error(
message: "Error: Could not connect to Gitaly, make sure it is running.",
backtrace: Gitlab::BacktraceCleaner.clean_backtrace(err.backtrace),
project_id: @project.id,
project_full_path: @project.full_path
)
raise
rescue StandardError => err
Gitlab::AppLogger.error(
message: "Native mercurial migration failed: #{err}",
backtrace: Gitlab::BacktraceCleaner.clean_backtrace(err.backtrace),
project_id: @project.id,
project_full_path: @project.full_path
)
msg = "Native mercurial migration failed: #{err}"
log_error(err, msg)
raise
end
......
......@@ -8,18 +8,41 @@ namespace :heptapod do
project = Project.find(args[:project_id])
unless project.mercurial?
puts "abort: project is not a mercurial project"
puts "abort: project is not a mercurial project".color(:red)
exit(1)
end
if project.vcs_type == 'hg' && !args[:force]
puts "abort: project is already migrated, use 'force' to migrate anyway"
puts "abort: project is already migrated, use 'force' to migrate anyway".color(:red)
exit(1)
end
check_gitaly_connection
check_hgitaly_connection
migrator = Heptapod::NativeMercurial::Migrator.new(project)
migrator.migrate!
puts 'Done!'
puts 'done!'.color(:green)
end
end
end
def check_gitaly_connection
Gitlab.config.repositories.storages.each do |name, _details|
Gitlab::GitalyClient::ServerService.new(name).info
end
rescue GRPC::Unavailable => ex
puts "Failed to connect to Gitaly...".color(:red)
puts "Error: #{ex}"
exit 1
end
def check_hgitaly_connection
Gitlab.config.repositories.storages.each do |name, _details|
storage = Gitlab::GitalyClient.vcs_qualified_storage(name, 'hg')
Gitlab::GitalyClient::ServerService.new(storage).info
end
rescue GRPC::Unavailable => ex
puts "Failed to connect to HGitaly...".color(:red)
puts "Error: #{ex}"
exit 1
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment