Add group repository storage move endpoints

In this commit we add the necessary endpoints
to perform group repository storage moves.

We also add endpoints to move them in bulk.
parent 7f3c898c
---
title: Add group repository storage move endpoints
merge_request: 53016
author:
type: added
# frozen_string_literal: true
module API
module Entities
module Groups
class RepositoryStorageMove < ::API::Entities::BasicRepositoryStorageMove
expose :group, using: ::API::Entities::BasicGroupDetails
end
end
end
end
# frozen_string_literal: true
module API
class GroupRepositoryStorageMoves < ::API::Base
include PaginationParams
before { authenticated_as_admin! }
feature_category :gitaly
resource :group_repository_storage_moves do
desc 'Get a list of all group repository storage moves' do
detail 'This feature was introduced in GitLab 13.9.'
success Entities::Groups::RepositoryStorageMove
end
params do
use :pagination
end
get do
storage_moves = ::Groups::RepositoryStorageMove.with_groups.order_created_at_desc
present paginate(storage_moves), with: Entities::Groups::RepositoryStorageMove, current_user: current_user
end
desc 'Get a group repository storage move' do
detail 'This feature was introduced in GitLab 13.9.'
success Entities::Groups::RepositoryStorageMove
end
params do
requires :repository_storage_move_id, type: Integer, desc: 'The ID of a group repository storage move'
end
get ':repository_storage_move_id' do
storage_move = ::Groups::RepositoryStorageMove.find(params[:repository_storage_move_id])
present storage_move, with: Entities::Groups::RepositoryStorageMove, current_user: current_user
end
desc 'Schedule bulk group repository storage moves' do
detail 'This feature was introduced in GitLab 13.9.'
end
params do
requires :source_storage_name, type: String, desc: 'The source storage shard', values: -> { Gitlab.config.repositories.storages.keys }
optional :destination_storage_name, type: String, desc: 'The destination storage shard', values: -> { Gitlab.config.repositories.storages.keys }
end
post do
::Groups::ScheduleBulkRepositoryShardMovesService.enqueue(
declared_params[:source_storage_name],
declared_params[:destination_storage_name]
)
accepted!
end
end
params do
requires :id, type: String, desc: 'The ID of a group'
end
resource :groups, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Get a list of all group repository storage moves' do
detail 'This feature was introduced in GitLab 13.9.'
success Entities::Groups::RepositoryStorageMove
end
params do
use :pagination
end
get ':id/repository_storage_moves' do
storage_moves = user_group.repository_storage_moves.with_groups.order_created_at_desc
present paginate(storage_moves), with: Entities::Groups::RepositoryStorageMove, current_user: current_user
end
desc 'Get a group repository storage move' do
detail 'This feature was introduced in GitLab 13.9.'
success Entities::Groups::RepositoryStorageMove
end
params do
requires :repository_storage_move_id, type: Integer, desc: 'The ID of a group repository storage move'
end
get ':id/repository_storage_moves/:repository_storage_move_id' do
storage_move = user_group.repository_storage_moves.find(params[:repository_storage_move_id])
present storage_move, with: Entities::Groups::RepositoryStorageMove, current_user: current_user
end
desc 'Schedule a group repository storage move' do
detail 'This feature was introduced in GitLab 13.9.'
success Entities::Groups::RepositoryStorageMove
end
params do
optional :destination_storage_name, type: String, desc: 'The destination storage shard'
end
post ':id/repository_storage_moves' do
storage_move = user_group.repository_storage_moves.build(
declared_params.merge(source_storage_name: user_group.wiki.repository_storage)
)
if storage_move.schedule
present storage_move, with: Entities::Groups::RepositoryStorageMove, current_user: current_user
else
render_validation_error!(storage_move)
end
end
end
end
end
......@@ -48,6 +48,7 @@ module EE
mount ::API::ResourceWeightEvents
mount ::API::ResourceIterationEvents
mount ::API::Iterations
mount ::API::GroupRepositoryStorageMoves
end
end
end
......
{
"type": "object",
"required": [
"id",
"created_at",
"state",
"source_storage_name",
"destination_storage_name",
"group"
],
"properties" : {
"id": { "type": "integer" },
"created_at": { "type": "date" },
"state": { "type": "string" },
"source_storage_name": { "type": "string" },
"destination_storage_name": { "type": "string" },
"group": { "type": "object" }
},
"additionalProperties": false
}
{
"type": "array",
"items": {
"$ref": "./group_repository_storage_move.json"
}
}
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe API::Entities::Groups::RepositoryStorageMove do
describe '#as_json' do
subject { entity.as_json }
let(:default_storage) { 'default' }
let(:second_storage) { 'test_second_storage' }
let(:storage_move) { create(:group_repository_storage_move, :scheduled, destination_storage_name: second_storage) }
let(:entity) { described_class.new(storage_move) }
it 'includes basic fields' do
allow(Gitlab.config.repositories.storages).to receive(:keys).and_return(%W[#{default_storage} #{second_storage}])
is_expected.to include(
state: 'scheduled',
source_storage_name: default_storage,
destination_storage_name: second_storage,
group: a_kind_of(Hash)
)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe API::GroupRepositoryStorageMoves do
it_behaves_like 'repository_storage_moves API', 'groups' do
let_it_be(:container) { create(:group, :wiki_repo) }
let_it_be(:storage_move) { create(:group_repository_storage_move, :scheduled, container: container) }
let(:repository_storage_move_factory) { :group_repository_storage_move }
let(:bulk_worker_klass) { Groups::ScheduleBulkRepositoryShardMovesWorker }
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