Commit cf52488c authored by Gabriel Mazetto's avatar Gabriel Mazetto

Move MigrationService to HashedStorage module

This is part of the refactor to include a RollbackService into
HashedStorage module
parent c2c34eba
...@@ -62,7 +62,7 @@ module Projects ...@@ -62,7 +62,7 @@ module Projects
def rename_or_migrate_repository! def rename_or_migrate_repository!
success = success =
if migrate_to_hashed_storage? if migrate_to_hashed_storage?
::Projects::HashedStorageMigrationService ::Projects::HashedStorage::MigrationService
.new(project, full_path_before) .new(project, full_path_before)
.execute .execute
else else
......
# frozen_string_literal: true
module Projects
module HashedStorage
class MigrationService < BaseService
attr_reader :logger, :old_disk_path
def initialize(project, old_disk_path, logger: nil)
@project = project
@old_disk_path = old_disk_path
@logger = logger || Rails.logger
end
def execute
# Migrate repository from Legacy to Hashed Storage
unless project.hashed_storage?(:repository)
return unless HashedStorage::MigrateRepositoryService.new(project, old_disk_path, logger: logger).execute
end
# Migrate attachments from Legacy to Hashed Storage
unless project.hashed_storage?(:attachments)
HashedStorage::MigrateAttachmentsService.new(project, old_disk_path, logger: logger).execute
end
true
end
end
end
end
# frozen_string_literal: true
module Projects
class HashedStorageMigrationService < BaseService
attr_reader :logger, :old_disk_path
def initialize(project, old_disk_path, logger: nil)
@project = project
@old_disk_path = old_disk_path
@logger = logger || Rails.logger
end
def execute
# Migrate repository from Legacy to Hashed Storage
unless project.hashed_storage?(:repository)
return unless HashedStorage::MigrateRepositoryService.new(project, old_disk_path, logger: logger).execute
end
# Migrate attachments from Legacy to Hashed Storage
unless project.hashed_storage?(:attachments)
HashedStorage::MigrateAttachmentsService.new(project, old_disk_path, logger: logger).execute
end
true
end
end
end
...@@ -12,7 +12,7 @@ class ProjectMigrateHashedStorageWorker ...@@ -12,7 +12,7 @@ class ProjectMigrateHashedStorageWorker
uuid = lease_for(project_id).try_obtain uuid = lease_for(project_id).try_obtain
if uuid if uuid
::Projects::HashedStorageMigrationService.new(project, old_disk_path || project.full_path, logger: logger).execute ::Projects::HashedStorage::MigrationService.new(project, old_disk_path || project.full_path, logger: logger).execute
else else
false false
end end
......
...@@ -101,10 +101,10 @@ describe Projects::AfterRenameService do ...@@ -101,10 +101,10 @@ describe Projects::AfterRenameService do
end end
context 'with hashed storage upgrade when renaming enabled' do context 'with hashed storage upgrade when renaming enabled' do
it 'calls HashedStorageMigrationService with correct options' do it 'calls HashedStorage::MigrationService with correct options' do
stub_application_setting(hashed_storage_enabled: true) stub_application_setting(hashed_storage_enabled: true)
expect_next_instance_of(::Projects::HashedStorageMigrationService) do |service| expect_next_instance_of(::Projects::HashedStorage::MigrationService) do |service|
expect(service).to receive(:execute).and_return(true) expect(service).to receive(:execute).and_return(true)
end end
......
require 'spec_helper' require 'spec_helper'
describe Projects::HashedStorageMigrationService do describe Projects::HashedStorage::MigrationService do
let(:project) { create(:project, :empty_repo, :wiki_repo, :legacy_storage) } let(:project) { create(:project, :empty_repo, :wiki_repo, :legacy_storage) }
let(:logger) { double } let(:logger) { double }
......
...@@ -9,7 +9,7 @@ describe ProjectMigrateHashedStorageWorker, :clean_gitlab_redis_shared_state do ...@@ -9,7 +9,7 @@ describe ProjectMigrateHashedStorageWorker, :clean_gitlab_redis_shared_state do
let(:lease_timeout) { ProjectMigrateHashedStorageWorker::LEASE_TIMEOUT } let(:lease_timeout) { ProjectMigrateHashedStorageWorker::LEASE_TIMEOUT }
it 'skips when project no longer exists' do it 'skips when project no longer exists' do
expect(::Projects::HashedStorageMigrationService).not_to receive(:new) expect(::Projects::HashedStorage::MigrationService).not_to receive(:new)
subject.perform(-1) subject.perform(-1)
end end
...@@ -17,7 +17,7 @@ describe ProjectMigrateHashedStorageWorker, :clean_gitlab_redis_shared_state do ...@@ -17,7 +17,7 @@ describe ProjectMigrateHashedStorageWorker, :clean_gitlab_redis_shared_state do
it 'skips when project is pending delete' do it 'skips when project is pending delete' do
pending_delete_project = create(:project, :empty_repo, pending_delete: true) pending_delete_project = create(:project, :empty_repo, pending_delete: true)
expect(::Projects::HashedStorageMigrationService).not_to receive(:new) expect(::Projects::HashedStorage::MigrationService).not_to receive(:new)
subject.perform(pending_delete_project.id) subject.perform(pending_delete_project.id)
end end
...@@ -27,7 +27,7 @@ describe ProjectMigrateHashedStorageWorker, :clean_gitlab_redis_shared_state do ...@@ -27,7 +27,7 @@ describe ProjectMigrateHashedStorageWorker, :clean_gitlab_redis_shared_state do
migration_service = spy migration_service = spy
allow(::Projects::HashedStorageMigrationService) allow(::Projects::HashedStorage::MigrationService)
.to receive(:new).with(project, project.full_path, logger: subject.logger) .to receive(:new).with(project, project.full_path, logger: subject.logger)
.and_return(migration_service) .and_return(migration_service)
...@@ -39,7 +39,7 @@ describe ProjectMigrateHashedStorageWorker, :clean_gitlab_redis_shared_state do ...@@ -39,7 +39,7 @@ describe ProjectMigrateHashedStorageWorker, :clean_gitlab_redis_shared_state do
it 'skips when dont have lease when dont have exclusive lease' do it 'skips when dont have lease when dont have exclusive lease' do
stub_exclusive_lease_taken(lease_key, timeout: lease_timeout) stub_exclusive_lease_taken(lease_key, timeout: lease_timeout)
expect(::Projects::HashedStorageMigrationService).not_to receive(:new) expect(::Projects::HashedStorage::MigrationService).not_to receive(:new)
subject.perform(project.id) subject.perform(project.id)
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