Commit a67891b4 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'schedule_storage_move_api' into 'master'

Add API to schedule project repository storage moves

See merge request gitlab-org/gitlab!34119
parents df71d756 926a1aba
---
title: Add API to schedule project repository storage moves
merge_request: 34119
author:
type: added
......@@ -23,7 +23,7 @@ are [paginated](README.md#pagination).
Example request:
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" 'https://primary.example.com/api/v4/project_repository_storage_moves'
curl --header "PRIVATE-TOKEN: <your_access_token>" 'https://gitlab.example.com/api/v4/project_repository_storage_moves'
```
Example response:
......@@ -61,12 +61,12 @@ Parameters:
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `project_id` | integer | yes | The ID of the project |
| `project_id` | integer | yes | ID of the project |
Example request:
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" 'https://primary.example.com/api/v4/project/1/repository_storage_moves'
curl --header "PRIVATE-TOKEN: <your_access_token>" 'https://gitlab.example.com/api/v4/projects/1/repository_storage_moves'
```
Example response:
......@@ -101,12 +101,12 @@ Parameters:
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `repository_storage_id` | integer | yes | The ID of the project repository storage move |
| `repository_storage_id` | integer | yes | ID of the project repository storage move |
Example request:
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" 'https://primary.example.com/api/v4/project_repository_storage_moves/1'
curl --header "PRIVATE-TOKEN: <your_access_token>" 'https://gitlab.example.com/api/v4/project_repository_storage_moves/1'
```
Example response:
......@@ -132,20 +132,60 @@ Example response:
## Get a single repository storage move for a project
```plaintext
GET /project/:project_id/repository_storage_moves/:repository_storage_id
GET /projects/:project_id/repository_storage_moves/:repository_storage_id
```
Parameters:
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `project_id` | integer | yes | The ID of the project |
| `repository_storage_id` | integer | yes | The ID of the project repository storage move |
| `project_id` | integer | yes | ID of the project |
| `repository_storage_id` | integer | yes | ID of the project repository storage move |
Example request:
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" 'https://primary.example.com/api/v4/project/1/repository_storage_moves/1'
curl --header "PRIVATE-TOKEN: <your_access_token>" 'https://gitlab.example.com/api/v4/projects/1/repository_storage_moves/1'
```
Example response:
```json
{
"id": 1,
"created_at": "2020-05-07T04:27:17.234Z",
"state": "scheduled",
"source_storage_name": "default",
"destination_storage_name": "storage2",
"project": {
"id": 1,
"description": null,
"name": "project1",
"name_with_namespace": "John Doe2 / project1",
"path": "project1",
"path_with_namespace": "namespace1/project1",
"created_at": "2020-05-07T04:27:17.016Z"
}
```
## Schedule a repository storage move for a project
```plaintext
POST /projects/:project_id/repository_storage_moves
```
Parameters:
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `project_id` | integer | yes | ID of the project |
| `destination_storage_name` | string | yes | Name of the destination storage shard |
Example request:
```shell
curl --request POST --header "PRIVATE_TOKEN: <your_access_token>" --header "Content-Type: application/json" \
--data '{"destination_storage_name":"storage2"}' 'https://gitlab.example.com/api/v4/projects/1/repository_storage_moves'
```
Example response:
......
......@@ -63,6 +63,25 @@ module API
present storage_move, with: Entities::ProjectRepositoryStorageMove, current_user: current_user
end
desc 'Schedule a project repository storage move' do
detail 'This feature was introduced in GitLab 13.1.'
success Entities::ProjectRepositoryStorageMove
end
params do
requires :destination_storage_name, type: String, desc: 'The destination storage shard'
end
post ':id/repository_storage_moves' do
storage_move = user_project.repository_storage_moves.build(
declared_params.merge(source_storage_name: user_project.repository_storage)
)
if storage_move.schedule
present storage_move, with: Entities::ProjectRepositoryStorageMove, current_user: current_user
else
render_validation_error!(storage_move)
end
end
end
end
end
......@@ -111,4 +111,45 @@ describe API::ProjectRepositoryStorageMoves do
let(:url) { "/projects/#{project.id}/repository_storage_moves/#{project_repository_storage_move_id}" }
end
end
describe 'POST /projects/:id/repository_storage_moves' do
let(:url) { "/projects/#{project.id}/repository_storage_moves" }
let(:destination_storage_name) { 'test_second_storage' }
def create_project_repository_storage_move
post api(url, user), params: { destination_storage_name: destination_storage_name }
end
before do
stub_storage_settings('test_second_storage' => { 'path' => 'tmp/tests/extra_storage' })
end
it 'schedules a project repository storage move' do
create_project_repository_storage_move
storage_move = project.repository_storage_moves.last
expect(response).to have_gitlab_http_status(:created)
expect(response).to match_response_schema('public_api/v4/project_repository_storage_move')
expect(json_response['id']).to eq(storage_move.id)
expect(json_response['state']).to eq('scheduled')
expect(json_response['source_storage_name']).to eq('default')
expect(json_response['destination_storage_name']).to eq(destination_storage_name)
end
describe 'permissions' do
it { expect { create_project_repository_storage_move }.to be_allowed_for(:admin) }
it { expect { create_project_repository_storage_move }.to be_denied_for(:user) }
end
context 'destination_storage_name is missing' do
let(:destination_storage_name) { nil }
it 'returns a validation error' do
create_project_repository_storage_move
expect(response).to have_gitlab_http_status(:bad_request)
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