summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-09 21:09:19 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-09 21:09:19 +0000
commit254ec28f5448f6f353cd98f637985de3d1405854 (patch)
tree1c84ed7b7dd32db96454af034cd6c7e90699e76d /lib
parent141902c04943d5fb43c014b8cf42af60a3bc0cdf (diff)
downloadgitlab-ce-254ec28f5448f6f353cd98f637985de3d1405854.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/tasks/gitlab/praefect.rake54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/tasks/gitlab/praefect.rake b/lib/tasks/gitlab/praefect.rake
new file mode 100644
index 00000000000..a9b126ae379
--- /dev/null
+++ b/lib/tasks/gitlab/praefect.rake
@@ -0,0 +1,54 @@
+namespace :gitlab do
+ namespace :praefect do
+ def int?(string)
+ true if Integer(string) rescue false
+ end
+
+ def print_checksums(header, row)
+ header.each_with_index do |val, i|
+ width = [val.length, row[i].length].max
+ header[i] = header[i].ljust(width)
+ row[i] = row[i].ljust(width)
+ end
+
+ header_str = header.join(' | ')
+ puts header_str
+ puts '-' * header_str.length
+ puts row.join(' | ')
+ end
+
+ desc 'GitLab | Praefect | Check replicas'
+ task :replicas, [:project_id] => :gitlab_environment do |t, args|
+ warn_user_is_not_gitlab
+
+ unless int?(args.project_id)
+ puts 'argument must be a valid project_id'
+ next
+ end
+
+ project = Project.find_by_id(args.project_id)
+ if project.nil?
+ puts 'No project was found with that id'
+ next
+ end
+
+ begin
+ replicas_resp = project.repository.replicas
+
+ sorted_replicas = replicas_resp.replicas.sort_by { |r| r.repository.storage_name }
+
+ header = ['Project name'] << "#{replicas_resp.primary.repository.storage_name} (primary)"
+ header.concat(sorted_replicas.map { |r| r.repository.storage_name })
+
+ row = [project.name] << replicas_resp.primary.checksum
+ row.concat(sorted_replicas.map {|r| r.checksum})
+ rescue
+ puts 'Something went wrong when getting replicas.'
+ next
+ end
+
+ puts "\n"
+ print_checksums(header, row)
+ end
+ end
+end