Commit 3b0aedda authored by Nick Thomas's avatar Nick Thomas

Send a Geo repository renamed event when migrating to hashed storage

parent e96e3eb8
...@@ -10,14 +10,18 @@ module Geo ...@@ -10,14 +10,18 @@ module Geo
repository_storage_name: project.repository.storage, repository_storage_name: project.repository.storage,
repository_storage_path: project.repository_storage_path, repository_storage_path: project.repository_storage_path,
old_path_with_namespace: old_path_with_namespace, old_path_with_namespace: old_path_with_namespace,
new_path_with_namespace: project.full_path, new_path_with_namespace: project.disk_path,
old_wiki_path_with_namespace: old_wiki_path_with_namespace, old_wiki_path_with_namespace: old_wiki_path_with_namespace,
new_wiki_path_with_namespace: new_wiki_path_with_namespace, new_wiki_path_with_namespace: new_wiki_path_with_namespace,
old_path: params.fetch(:old_path), old_path: old_path,
new_path: project.path new_path: project.path
) )
end end
def old_path
params.fetch(:old_path)
end
def old_path_with_namespace def old_path_with_namespace
params.fetch(:old_path_with_namespace) params.fetch(:old_path_with_namespace)
end end
...@@ -27,7 +31,7 @@ module Geo ...@@ -27,7 +31,7 @@ module Geo
end end
def new_wiki_path_with_namespace def new_wiki_path_with_namespace
project.wiki.full_path "#{project.disk_path}.wiki"
end end
end end
end end
...@@ -2,6 +2,8 @@ module Projects ...@@ -2,6 +2,8 @@ module Projects
class HashedStorageMigrationService < BaseService class HashedStorageMigrationService < BaseService
include Gitlab::ShellAdapter include Gitlab::ShellAdapter
prepend ::EE::Projects::HashedStorageMigrationService
attr_reader :old_disk_path, :new_disk_path attr_reader :old_disk_path, :new_disk_path
def initialize(project, logger = nil) def initialize(project, logger = nil)
......
module EE
module Projects
module HashedStorageMigrationService
def execute
raise NotImplementedError.new unless defined?(super)
super do
::Geo::RepositoryRenamedEventStore.new(
project,
old_path: File.basename(old_disk_path),
old_path_with_namespace: old_disk_path
).create
end
end
end
end
end
require 'spec_helper'
describe Projects::HashedStorageMigrationService do
let(:project) { create(:project, :empty_repo, :wiki_repo) }
let(:service) { described_class.new(project) }
let(:legacy_storage) { Storage::LegacyProject.new(project) }
let(:hashed_storage) { Storage::HashedProject.new(project) }
describe '#execute' do
it 'creates a Geo::RepositoryRenamedEvent on success' do
allow(Gitlab::Geo).to receive(:primary?).and_return(true)
expect { service.execute }.to change { Geo::EventLog.count }.by(1)
event = Geo::EventLog.first.event
expect(event).to be_a(Geo::RepositoryRenamedEvent)
expect(event).to have_attributes(
old_path: project.path,
new_path: project.path,
old_path_with_namespace: legacy_storage.disk_path,
new_path_with_namespace: hashed_storage.disk_path,
old_wiki_path_with_namespace: legacy_storage.disk_path + '.wiki',
new_wiki_path_with_namespace: hashed_storage.disk_path + '.wiki'
)
end
it 'does not create a Geo event on failure' do
from_name = project.disk_path
to_name = hashed_storage.disk_path
allow(service).to receive(:move_repository).and_call_original
allow(service).to receive(:move_repository).with(from_name, to_name).once { false } # will disable first move only
allow(Gitlab::Geo).to receive(:primary?).and_return(true)
expect { service.execute }.not_to change { Geo::EventLog.count }
end
end
end
...@@ -31,9 +31,9 @@ describe Geo::RepositoryRenamedEventStore do ...@@ -31,9 +31,9 @@ describe Geo::RepositoryRenamedEventStore do
expect(event.repository_storage_name).to eq(project.repository_storage) expect(event.repository_storage_name).to eq(project.repository_storage)
expect(event.repository_storage_path).to eq(project.repository_storage_path) expect(event.repository_storage_path).to eq(project.repository_storage_path)
expect(event.old_path_with_namespace).to eq(old_path_with_namespace) expect(event.old_path_with_namespace).to eq(old_path_with_namespace)
expect(event.new_path_with_namespace).to eq(project.full_path) expect(event.new_path_with_namespace).to eq(project.disk_path)
expect(event.old_wiki_path_with_namespace).to eq("#{old_path_with_namespace}.wiki") expect(event.old_wiki_path_with_namespace).to eq("#{old_path_with_namespace}.wiki")
expect(event.new_wiki_path_with_namespace).to eq("#{project.full_path}.wiki") expect(event.new_wiki_path_with_namespace).to eq("#{project.disk_path}.wiki")
expect(event.old_path).to eq(old_path) expect(event.old_path).to eq(old_path)
expect(event.new_path).to eq(project.path) expect(event.new_path).to eq(project.path)
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