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