Commit baa48794 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Fixed minor mistakes and improved code based on review

parent 38bc8053
......@@ -2,14 +2,10 @@ class Admin::GeoNodesController < Admin::ApplicationController
def index
@nodes = GeoNode.all
@node = GeoNode.new
@node.build_geo_node_key
end
def create
@node = GeoNode.new
@node.build_geo_node_key
@node.attributes = geo_node_params
@node.geo_node_key.title = "Geo node: #{@node.url}"
@node = GeoNode.new(geo_node_params)
if @node.save
redirect_to admin_geo_nodes_path, notice: 'Node was successfully created.'
......@@ -23,7 +19,7 @@ class Admin::GeoNodesController < Admin::ApplicationController
@node = GeoNode.find(params[:id])
@node.destroy
redirect_to admin_geo_nodes_path
redirect_to admin_geo_nodes_path, notice: 'Node was successfully removed.'
end
def geo_node_params
......
......@@ -26,9 +26,11 @@ class GeoNode < ActiveRecord::Base
validates :schema, inclusion: %w(http https)
validates :relative_url_root, length: { minimum: 0, allow_nil: false }
after_initialize :check_geo_node_key
after_save :refresh_bulk_notify_worker_status
after_destroy :refresh_bulk_notify_worker_status
after_destroy :destroy_orphaned_geo_node_key
before_validation :change_geo_node_key_title
def uri
if relative_url_root
......@@ -51,7 +53,7 @@ class GeoNode < ActiveRecord::Base
end
def notify_url
URI::join(uri, "#{uri.path}/", 'api/v3/geo/refresh_projects').to_s
URI.join(uri, "#{uri.path}/", "api/#{API::API.version}/geo/refresh_projects").to_s
end
private
......@@ -63,6 +65,18 @@ class GeoNode < ActiveRecord::Base
end
def refresh_bulk_notify_worker_status
Gitlab::Geo.primary? ? Gitlab::Geo.bulk_notify_job.try(:enable!) : Gitlab::Geo.bulk_notify_job.try(:disable!)
if Gitlab::Geo.primary?
Gitlab::Geo.bulk_notify_job.enable!
else
Gitlab::Geo.bulk_notify_job.disable!
end
end
def check_geo_node_key
self.build_geo_node_key if geo_node_key.nil?
end
def geo_node_key_title
self.geo_node_key.title = "Geo node: #{self.url}"
end
end
......@@ -14,7 +14,7 @@
#
class GeoNodeKey < Key
has_many :geo_nodes
has_one :geo_nodes
def orphaned?
self.geo_nodes.length == 0
......
......@@ -183,10 +183,12 @@ class Repository
end
def set_remote_as_mirror(name)
remote_config = raw_repository.rugged.config
# This is used by Gitlab Geo to define repository as equivalent as "git clone --mirror"
raw_repository.rugged.config["remote.#{name}.fetch"]='refs/*:refs/*'
raw_repository.rugged.config["remote.#{name}.mirror"]=true
raw_repository.rugged.config["remote.#{name}.prune"]=true
remote_config["remote.#{name}.fetch"] = 'refs/*:refs/*'
remote_config["remote.#{name}.mirror"] = true
remote_config["remote.#{name}.prune"] = true
end
def fetch_remote(remote)
......
......@@ -12,7 +12,7 @@ module Geo
::Gitlab::Geo.secondary_nodes.each do |node|
success, message = notify_updated_projects(node, projects)
unless success
Rails.logger.error("Gitlab Failed to notify #{node.url} : #{message}")
Rails.logger.error("GitLab failed to notify #{node.url} : #{message}")
@queue.store_batched_data(projects)
end
end
......@@ -28,7 +28,7 @@ module Geo
'PRIVATE-TOKEN' => private_token
})
return [(response.code >= 200 && response.code < 300), ActionView::Base.full_sanitizer.sanitize(response.to_s)]
[(response.code >= 200 && response.code < 300), ActionView::Base.full_sanitizer.sanitize(response.to_s)]
rescue HTTParty::Error, Errno::ECONNREFUSED => e
return [false, ActionView::Base.full_sanitizer.sanitize(e.message)]
end
......
......@@ -2,7 +2,7 @@ module Gitlab
module Geo
class UpdateQueue
BATCH_SIZE = 250
NAMESPACE = :geo
NAMESPACE = 'geo:gitlab'
QUEUE = 'updated_projects'
def initialize
......@@ -10,7 +10,8 @@ module Gitlab
end
def store(data)
@redis.rpush(QUEUE, data.to_json) and expire_queue_size!
@redis.rpush(QUEUE, data.to_json)
expire_queue_size!
end
def first
......@@ -28,7 +29,7 @@ module Gitlab
bsize = batch_size
@redis.multi do
projects = @redis.lrange(QUEUE, 0, bsize-1)
projects = @redis.lrange(QUEUE, 0, bsize - 1)
@redis.ltrim(QUEUE, bsize, -1)
end
......
......@@ -337,7 +337,7 @@ module Gitlab
end
if Gitlab::Geo.enabled? && Gitlab::Geo.readonly?
return build_status_object(false, "You can't use git-anex with Gitlab Geo readonly node.")
return build_status_object(false, "You can't use git-annex with Gitlab Geo secondary node.")
end
if user.can?(:push_code, project)
......
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