Commit 387877d4 authored by Gabriel Mazetto's avatar Gabriel Mazetto

More fixes and changes after review for Geo

parent f0bf830f
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
class GeoNode < ActiveRecord::Base class GeoNode < ActiveRecord::Base
belongs_to :geo_node_key belongs_to :geo_node_key, dependent: :destroy
default_values schema: 'http', default_values schema: 'http',
host: lambda { Gitlab.config.gitlab.host }, host: lambda { Gitlab.config.gitlab.host },
...@@ -29,7 +29,6 @@ class GeoNode < ActiveRecord::Base ...@@ -29,7 +29,6 @@ class GeoNode < ActiveRecord::Base
after_initialize :check_geo_node_key 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
before_validation :change_geo_node_key_title before_validation :change_geo_node_key_title
def uri def uri
...@@ -58,12 +57,6 @@ class GeoNode < ActiveRecord::Base ...@@ -58,12 +57,6 @@ class GeoNode < ActiveRecord::Base
private private
def destroy_orphaned_geo_node_key
return unless self.geo_node_key && self.geo_node_key.destroyed_when_orphaned? && self.geo_node_key.orphaned?
self.geo_node_key.destroy
end
def refresh_bulk_notify_worker_status def refresh_bulk_notify_worker_status
if Gitlab::Geo.primary? if Gitlab::Geo.primary?
Gitlab::Geo.bulk_notify_job.enable! Gitlab::Geo.bulk_notify_job.enable!
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
# #
class GeoNodeKey < Key class GeoNodeKey < Key
has_one :geo_nodes has_one :geo_node
def orphaned? def orphaned?
self.geo_nodes.length == 0 self.geo_nodes.length == 0
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
%li %li
.list-item-name .list-item-name
%strong= node.url %strong= node.url
%p #{node.primary ? 'Primary node' : 'Readonly node'} %p #{node.primary ? 'Primary node' : 'Secondary node'}
.pull-right .pull-right
= link_to 'Remove', admin_geo_node_path(node), data: { confirm: 'Are you sure?' }, method: :delete, class: 'btn btn-remove btn-sm' = link_to 'Remove', admin_geo_node_path(node), data: { confirm: 'Are you sure?' }, method: :delete, class: 'btn btn-remove btn-sm'
...@@ -25,7 +25,7 @@ module Gitlab ...@@ -25,7 +25,7 @@ module Gitlab
end end
def self.secondary? def self.secondary?
RequestStore.store[:geo_node_readonly?] ||= self.enabled? && self.current_node && !self.current_node.primary? RequestStore.store[:geo_node_secondary] ||= self.enabled? && self.current_node && !self.current_node.primary?
end end
def self.geo_node?(host:, port:) def self.geo_node?(host:, port:)
......
...@@ -95,7 +95,7 @@ module Gitlab ...@@ -95,7 +95,7 @@ module Gitlab
def push_access_check(changes) def push_access_check(changes)
if Gitlab::Geo.enabled? && Gitlab::Geo.secondary? if Gitlab::Geo.enabled? && Gitlab::Geo.secondary?
return build_status_object(false, "You can't push code on a secondary Gitlab Geo node.") return build_status_object(false, "You can't push code on a secondary GitLab Geo node.")
end end
return build_status_object(true) if git_annex_branch_sync?(changes) return build_status_object(true) if git_annex_branch_sync?(changes)
......
...@@ -20,6 +20,6 @@ describe GeoNodeKey, models: true do ...@@ -20,6 +20,6 @@ describe GeoNodeKey, models: true do
let(:geo_node_key) { create(:geo_node_key, geo_nodes: [geo_node]) } let(:geo_node_key) { create(:geo_node_key, geo_nodes: [geo_node]) }
describe 'Associations' do describe 'Associations' do
it { is_expected.to have_many(:geo_nodes) } it { is_expected.to have_one(:geo_node) }
end end
end end
...@@ -3,6 +3,10 @@ require 'spec_helper' ...@@ -3,6 +3,10 @@ require 'spec_helper'
describe GeoNode, type: :model do describe GeoNode, type: :model do
let(:dummy_url) { 'https://localhost:3000/gitlab' } let(:dummy_url) { 'https://localhost:3000/gitlab' }
context 'associations' do
it { is_expected.to belong_to(:geo_node_key).dependent(:destroy) }
end
context 'default values' do context 'default values' do
let(:gitlab_host) { 'gitlabhost' } let(:gitlab_host) { 'gitlabhost' }
before(:each) { allow(Gitlab.config.gitlab).to receive(:host) { gitlab_host } } before(:each) { allow(Gitlab.config.gitlab).to receive(:host) { gitlab_host } }
...@@ -105,5 +109,4 @@ describe GeoNode, type: :model do ...@@ -105,5 +109,4 @@ describe GeoNode, type: :model do
expect(subject.notify_url).to eq(refresh_url) expect(subject.notify_url).to eq(refresh_url)
end end
end end
end 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