Commit 58829631 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '299853-fj-move-snippet-repository-storage-classes-to-namespace' into 'master'

Move snippet repository storage classes to namespace

See merge request gitlab-org/gitlab!54798
parents af9d1d7f 860b7e8f
......@@ -45,7 +45,7 @@ class Snippet < ApplicationRecord
has_many :notes, as: :noteable, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_many :user_mentions, class_name: "SnippetUserMention", dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
has_one :snippet_repository, inverse_of: :snippet
has_many :repository_storage_moves, class_name: 'SnippetRepositoryStorageMove', inverse_of: :container
has_many :repository_storage_moves, class_name: 'Snippets::RepositoryStorageMove', inverse_of: :container
# We need to add the `dependent` in order to call the after_destroy callback
has_one :statistics, class_name: 'SnippetStatistics', dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
......
# frozen_string_literal: true
# SnippetRepositoryStorageMove are details of repository storage moves for a
# snippet. For example, moving a snippet to another gitaly node to help
# balance storage capacity.
class SnippetRepositoryStorageMove < ApplicationRecord
extend ::Gitlab::Utils::Override
include RepositoryStorageMovable
belongs_to :container, class_name: 'Snippet', inverse_of: :repository_storage_moves, foreign_key: :snippet_id
alias_attribute :snippet, :container
override :schedule_repository_storage_update_worker
def schedule_repository_storage_update_worker
SnippetUpdateRepositoryStorageWorker.perform_async(
snippet_id,
destination_storage_name,
id
)
end
private
override :error_key
def error_key
:snippet
end
# This is a compatibility class to avoid calling a non-existent
# class from sidekiq during deployment.
#
# This class was moved to a namespace in https://gitlab.com/gitlab-org/gitlab/-/issues/299853.
# we cannot remove this class entirely because there can be jobs
# referencing it.
#
# We can get rid of this class in 14.0
# https://gitlab.com/gitlab-org/gitlab/-/issues/322393
class SnippetRepositoryStorageMove < Snippets::RepositoryStorageMove
end
# frozen_string_literal: true
# Snippets::RepositoryStorageMove are details of repository storage moves for a
# snippet. For example, moving a snippet to another gitaly node to help
# balance storage capacity.
module Snippets
class RepositoryStorageMove < ApplicationRecord
extend ::Gitlab::Utils::Override
include RepositoryStorageMovable
self.table_name = 'snippet_repository_storage_moves'
belongs_to :container, class_name: 'Snippet', inverse_of: :repository_storage_moves, foreign_key: :snippet_id
alias_attribute :snippet, :container
override :schedule_repository_storage_update_worker
def schedule_repository_storage_update_worker
Snippets::UpdateRepositoryStorageWorker.perform_async(
snippet_id,
destination_storage_name,
id
)
end
private
override :error_key
def error_key
:snippet
end
end
end
......@@ -25,7 +25,7 @@ module Snippets
override :schedule_bulk_worker_klass
def self.schedule_bulk_worker_klass
::SnippetScheduleBulkRepositoryShardMovesWorker
::Snippets::ScheduleBulkRepositoryShardMovesWorker
end
end
end
......@@ -2204,6 +2204,22 @@
:weight: 1
:idempotent: true
:tags: []
- :name: snippets_schedule_bulk_repository_shard_moves
:feature_category: :gitaly
:has_external_dependencies:
:urgency: :throttled
:resource_boundary: :unknown
:weight: 1
:idempotent: true
:tags: []
- :name: snippets_update_repository_storage
:feature_category: :gitaly
:has_external_dependencies:
:urgency: :throttled
:resource_boundary: :unknown
:weight: 1
:idempotent: true
:tags: []
- :name: system_hook_push
:feature_category: :source_code_management
:has_external_dependencies:
......
# frozen_string_literal: true
class SnippetScheduleBulkRepositoryShardMovesWorker
include ApplicationWorker
# This is a compatibility class to avoid calling a non-existent
# class from sidekiq during deployment.
#
# This class was moved to a namespace in https://gitlab.com/gitlab-org/gitlab/-/issues/299853.
# we cannot remove this class entirely because there can be jobs
# referencing it.
#
# We can get rid of this class in 14.0
# https://gitlab.com/gitlab-org/gitlab/-/issues/322393
class SnippetScheduleBulkRepositoryShardMovesWorker < Snippets::ScheduleBulkRepositoryShardMovesWorker
idempotent!
feature_category :gitaly
urgency :throttled
def perform(source_storage_name, destination_storage_name = nil)
Snippets::ScheduleBulkRepositoryShardMovesService.new.execute(source_storage_name, destination_storage_name)
end
end
# frozen_string_literal: true
class SnippetUpdateRepositoryStorageWorker # rubocop:disable Scalability/IdempotentWorker
extend ::Gitlab::Utils::Override
include UpdateRepositoryStorageWorker
private
override :find_repository_storage_move
def find_repository_storage_move(repository_storage_move_id)
SnippetRepositoryStorageMove.find(repository_storage_move_id)
end
override :find_container
def find_container(container_id)
Snippet.find(container_id)
end
override :update_repository_storage
def update_repository_storage(repository_storage_move)
::Snippets::UpdateRepositoryStorageService.new(repository_storage_move).execute
end
# This is a compatibility class to avoid calling a non-existent
# class from sidekiq during deployment.
#
# This class was moved to a namespace in https://gitlab.com/gitlab-org/gitlab/-/issues/299853.
# we cannot remove this class entirely because there can be jobs
# referencing it.
#
# We can get rid of this class in 14.0
# https://gitlab.com/gitlab-org/gitlab/-/issues/322393
class SnippetUpdateRepositoryStorageWorker < Snippets::UpdateRepositoryStorageWorker # rubocop:disable Scalability/IdempotentWorker
idempotent!
urgency :throttled
end
# frozen_string_literal: true
module Snippets
class ScheduleBulkRepositoryShardMovesWorker
include ApplicationWorker
idempotent!
feature_category :gitaly
urgency :throttled
def perform(source_storage_name, destination_storage_name = nil)
Snippets::ScheduleBulkRepositoryShardMovesService.new.execute(source_storage_name, destination_storage_name)
end
end
end
# frozen_string_literal: true
module Snippets
class UpdateRepositoryStorageWorker # rubocop:disable Scalability/IdempotentWorker
extend ::Gitlab::Utils::Override
include ::UpdateRepositoryStorageWorker
private
override :find_repository_storage_move
def find_repository_storage_move(repository_storage_move_id)
Snippets::RepositoryStorageMove.find(repository_storage_move_id)
end
override :find_container
def find_container(container_id)
Snippet.find(container_id)
end
override :update_repository_storage
def update_repository_storage(repository_storage_move)
::Snippets::UpdateRepositoryStorageService.new(repository_storage_move).execute
end
end
end
......@@ -346,6 +346,10 @@
- 1
- - snippet_update_repository_storage
- 1
- - snippets_schedule_bulk_repository_shard_moves
- 1
- - snippets_update_repository_storage
- 1
- - status_page_publish
- 1
- - sync_seat_link_request
......
# frozen_string_literal: true
module API
module Entities
module Snippets
class RepositoryStorageMove < BasicRepositoryStorageMove
expose :snippet, using: Entities::BasicSnippet
end
end
end
end
......@@ -11,28 +11,28 @@ module API
resource :snippet_repository_storage_moves do
desc 'Get a list of all snippet repository storage moves' do
detail 'This feature was introduced in GitLab 13.8.'
success Entities::SnippetRepositoryStorageMove
success Entities::Snippets::RepositoryStorageMove
end
params do
use :pagination
end
get do
storage_moves = SnippetRepositoryStorageMove.order_created_at_desc
storage_moves = ::Snippets::RepositoryStorageMove.order_created_at_desc
present paginate(storage_moves), with: Entities::SnippetRepositoryStorageMove, current_user: current_user
present paginate(storage_moves), with: Entities::Snippets::RepositoryStorageMove, current_user: current_user
end
desc 'Get a snippet repository storage move' do
detail 'This feature was introduced in GitLab 13.8.'
success Entities::SnippetRepositoryStorageMove
success Entities::Snippets::RepositoryStorageMove
end
params do
requires :repository_storage_move_id, type: Integer, desc: 'The ID of a snippet repository storage move'
end
get ':repository_storage_move_id' do
storage_move = SnippetRepositoryStorageMove.find(params[:repository_storage_move_id])
storage_move = ::Snippets::RepositoryStorageMove.find(params[:repository_storage_move_id])
present storage_move, with: Entities::SnippetRepositoryStorageMove, current_user: current_user
present storage_move, with: Entities::Snippets::RepositoryStorageMove, current_user: current_user
end
desc 'Schedule bulk snippet repository storage moves' do
......@@ -68,7 +68,7 @@ module API
desc 'Get a list of all snippets repository storage moves' do
detail 'This feature was introduced in GitLab 13.8.'
success Entities::SnippetRepositoryStorageMove
success Entities::Snippets::RepositoryStorageMove
end
params do
use :pagination
......@@ -76,12 +76,12 @@ module API
get ':id/repository_storage_moves' do
storage_moves = user_snippet.repository_storage_moves.order_created_at_desc
present paginate(storage_moves), with: Entities::SnippetRepositoryStorageMove, current_user: current_user
present paginate(storage_moves), with: Entities::Snippets::RepositoryStorageMove, current_user: current_user
end
desc 'Get a snippet repository storage move' do
detail 'This feature was introduced in GitLab 13.8.'
success Entities::SnippetRepositoryStorageMove
success Entities::Snippets::RepositoryStorageMove
end
params do
requires :repository_storage_move_id, type: Integer, desc: 'The ID of a snippet repository storage move'
......@@ -89,12 +89,12 @@ module API
get ':id/repository_storage_moves/:repository_storage_move_id' do
storage_move = user_snippet.repository_storage_moves.find(params[:repository_storage_move_id])
present storage_move, with: Entities::SnippetRepositoryStorageMove, current_user: current_user
present storage_move, with: Entities::Snippets::RepositoryStorageMove, current_user: current_user
end
desc 'Schedule a snippet repository storage move' do
detail 'This feature was introduced in GitLab 13.8.'
success Entities::SnippetRepositoryStorageMove
success Entities::Snippets::RepositoryStorageMove
end
params do
optional :destination_storage_name, type: String, desc: 'The destination storage shard'
......@@ -105,7 +105,7 @@ module API
)
if storage_move.schedule
present storage_move, with: Entities::SnippetRepositoryStorageMove, current_user: current_user
present storage_move, with: Entities::Snippets::RepositoryStorageMove, current_user: current_user
else
render_validation_error!(storage_move)
end
......
# frozen_string_literal: true
FactoryBot.define do
factory :snippet_repository_storage_move, class: 'SnippetRepositoryStorageMove' do
factory :snippet_repository_storage_move, class: 'Snippets::RepositoryStorageMove' do
container { association(:snippet) }
source_storage_name { 'default' }
trait :scheduled do
state { SnippetRepositoryStorageMove.state_machines[:state].states[:scheduled].value }
state { Snippets::RepositoryStorageMove.state_machines[:state].states[:scheduled].value }
end
trait :started do
state { SnippetRepositoryStorageMove.state_machines[:state].states[:started].value }
state { Snippets::RepositoryStorageMove.state_machines[:state].states[:started].value }
end
trait :replicated do
state { SnippetRepositoryStorageMove.state_machines[:state].states[:replicated].value }
state { Snippets::RepositoryStorageMove.state_machines[:state].states[:replicated].value }
end
trait :finished do
state { SnippetRepositoryStorageMove.state_machines[:state].states[:finished].value }
state { Snippets::RepositoryStorageMove.state_machines[:state].states[:finished].value }
end
trait :failed do
state { SnippetRepositoryStorageMove.state_machines[:state].states[:failed].value }
state { Snippets::RepositoryStorageMove.state_machines[:state].states[:failed].value }
end
end
end
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe API::Entities::SnippetRepositoryStorageMove do
RSpec.describe API::Entities::Snippets::RepositoryStorageMove do
describe '#as_json' do
subject { entity.as_json }
......
......@@ -8,6 +8,6 @@ RSpec.describe SnippetRepositoryStorageMove, type: :model do
let(:repository_storage_factory_key) { :snippet_repository_storage_move }
let(:error_key) { :snippet }
let(:repository_storage_worker) { SnippetUpdateRepositoryStorageWorker }
let(:repository_storage_worker) { Snippets::UpdateRepositoryStorageWorker }
end
end
......@@ -21,7 +21,7 @@ RSpec.describe Snippet do
it { is_expected.to have_many(:user_mentions).class_name("SnippetUserMention") }
it { is_expected.to have_one(:snippet_repository) }
it { is_expected.to have_one(:statistics).class_name('SnippetStatistics').dependent(:destroy) }
it { is_expected.to have_many(:repository_storage_moves).class_name('SnippetRepositoryStorageMove').inverse_of(:container) }
it { is_expected.to have_many(:repository_storage_moves).class_name('Snippets::RepositoryStorageMove').inverse_of(:container) }
end
describe 'validation' do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Snippets::RepositoryStorageMove, type: :model do
it_behaves_like 'handles repository moves' do
let_it_be_with_refind(:container) { create(:snippet) }
let(:repository_storage_factory_key) { :snippet_repository_storage_move }
let(:error_key) { :snippet }
let(:repository_storage_worker) { Snippets::UpdateRepositoryStorageWorker }
end
end
......@@ -7,6 +7,6 @@ RSpec.describe API::SnippetRepositoryStorageMoves do
let_it_be(:container) { create(:snippet, :repository).tap { |snippet| snippet.create_repository } }
let_it_be(:storage_move) { create(:snippet_repository_storage_move, :scheduled, container: container) }
let(:repository_storage_move_factory) { :snippet_repository_storage_move }
let(:bulk_worker_klass) { SnippetScheduleBulkRepositoryShardMovesWorker }
let(:bulk_worker_klass) { Snippets::ScheduleBulkRepositoryShardMovesWorker }
end
end
......@@ -6,7 +6,7 @@ RSpec.describe Snippets::ScheduleBulkRepositoryShardMovesService do
it_behaves_like 'moves repository shard in bulk' do
let_it_be_with_reload(:container) { create(:snippet, :repository) }
let(:move_service_klass) { SnippetRepositoryStorageMove }
let(:bulk_worker_klass) { ::SnippetScheduleBulkRepositoryShardMovesWorker }
let(:move_service_klass) { Snippets::RepositoryStorageMove }
let(:bulk_worker_klass) { ::Snippets::ScheduleBulkRepositoryShardMovesWorker }
end
end
......@@ -6,7 +6,7 @@ RSpec.describe SnippetScheduleBulkRepositoryShardMovesWorker do
it_behaves_like 'schedules bulk repository shard moves' do
let_it_be_with_reload(:container) { create(:snippet, :repository).tap { |snippet| snippet.create_repository } }
let(:move_service_klass) { SnippetRepositoryStorageMove }
let(:worker_klass) { SnippetUpdateRepositoryStorageWorker }
let(:move_service_klass) { Snippets::RepositoryStorageMove }
let(:worker_klass) { Snippets::UpdateRepositoryStorageWorker }
end
end
......@@ -10,6 +10,6 @@ RSpec.describe SnippetUpdateRepositoryStorageWorker do
let_it_be(:repository_storage_move) { create(:snippet_repository_storage_move) }
let(:service_klass) { Snippets::UpdateRepositoryStorageService }
let(:repository_storage_move_klass) { SnippetRepositoryStorageMove }
let(:repository_storage_move_klass) { Snippets::RepositoryStorageMove }
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Snippets::ScheduleBulkRepositoryShardMovesWorker do
it_behaves_like 'schedules bulk repository shard moves' do
let_it_be_with_reload(:container) { create(:snippet, :repository).tap { |snippet| snippet.create_repository } }
let(:move_service_klass) { Snippets::RepositoryStorageMove }
let(:worker_klass) { Snippets::UpdateRepositoryStorageWorker }
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Snippets::UpdateRepositoryStorageWorker do
subject { described_class.new }
it_behaves_like 'an update storage move worker' do
let_it_be_with_refind(:container) { create(:snippet, :repository) }
let_it_be(:repository_storage_move) { create(:snippet_repository_storage_move) }
let(:service_klass) { Snippets::UpdateRepositoryStorageService }
let(:repository_storage_move_klass) { Snippets::RepositoryStorageMove }
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