Commit fa3d3673 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Persist Clone URL prefix in geo_nodes table to be used by the secondary

parent 6a25c2cd
......@@ -95,6 +95,18 @@ class GeoNode < ActiveRecord::Base
self.primary? ? false : !oauth_application.present?
end
def update_clone_url!
update_clone_url
# Update with update_column to prevent calling callbacks as this method will
# be called in an initializer and we don't want other callbacks
# to mess with uninitialized dependencies.
if clone_url_prefix_changed?
Rails.logger.info "Geo: modified clone_url_prefix to #{clone_url_prefix}"
update_column(:clone_url_prefix, clone_url_prefix)
end
end
private
def geo_api_url(suffix)
......@@ -134,6 +146,7 @@ class GeoNode < ActiveRecord::Base
if self.primary?
self.oauth_application = nil
update_clone_url
else
update_oauth_application!
update_system_hook!
......@@ -149,6 +162,10 @@ class GeoNode < ActiveRecord::Base
end
end
def update_clone_url
self.clone_url_prefix = Gitlab.config.gitlab_shell.ssh_path_prefix
end
def update_oauth_application!
self.build_oauth_application if oauth_application.nil?
self.oauth_application.name = "Geo node: #{self.url}"
......
......@@ -3,3 +3,11 @@ if File.exist?(Rails.root.join('config/database_geo.yml'))
config.geo_database = config_for(:database_geo)
end
end
begin
if Gitlab::Geo.primary?
Gitlab::Geo.current_node.update_clone_url!
end
rescue
warn 'WARNING: Unable to check/update clone_url_prefix for Geo'
end
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddCloneUrlPrefixToGeoNode < ActiveRecord::Migration
DOWNTIME = false
def change
add_column :geo_nodes, :clone_url_prefix, :string
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170523091700) do
ActiveRecord::Schema.define(version: 20170602003304) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -511,6 +511,7 @@ ActiveRecord::Schema.define(version: 20170523091700) do
t.string "access_key"
t.string "encrypted_secret_access_key"
t.string "encrypted_secret_access_key_iv"
t.string "clone_url_prefix"
end
add_index "geo_nodes", ["access_key"], name: "index_geo_nodes_on_access_key", using: :btree
......
......@@ -54,7 +54,7 @@ describe GeoNode, type: :model do
end
end
context 'dependent models for GeoNode' do
context 'dependent models and attributes for GeoNode' do
let(:geo_node_key_attributes) { FactoryGirl.build(:geo_node_key).attributes }
context 'on initialize' do
......@@ -77,10 +77,6 @@ describe GeoNode, type: :model do
expect(node.oauth_application).to be_persisted
end
it 'has no oauth_application if it is a primary node' do
expect(primary_node.oauth_application).not_to be_present
end
it 'has a system_hook if it is a secondary node' do
expect(node.system_hook).to be_present
end
......@@ -93,6 +89,16 @@ describe GeoNode, type: :model do
expect(node.system_hook.tag_push_events).to be_falsey
expect(node.system_hook.repository_update_events).to be_truthy
end
context 'when is a primary node' do
it 'has no oauth_application' do
expect(primary_node.oauth_application).not_to be_present
end
it 'persists current clone_url_prefix' do
expect(primary_node.clone_url_prefix).to be_present
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