Commit 926a1aba authored by James Fargher's avatar James Fargher

Add API to schedule project repository storage moves

A higher visibility endpoint than the update project endpoint.
parent 59e5a8ef
---
title: Add API to schedule project repository storage moves
merge_request: 34119
author:
type: added
...@@ -16,7 +16,7 @@ are [paginated](README.md#pagination). ...@@ -16,7 +16,7 @@ are [paginated](README.md#pagination).
Example request: Example request:
```shell ```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: Example response:
...@@ -54,12 +54,12 @@ Parameters: ...@@ -54,12 +54,12 @@ Parameters:
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `project_id` | integer | yes | The ID of the project | | `project_id` | integer | yes | ID of the project |
Example request: Example request:
```shell ```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: Example response:
...@@ -94,12 +94,12 @@ Parameters: ...@@ -94,12 +94,12 @@ Parameters:
| Attribute | Type | Required | Description | | 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: Example request:
```shell ```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: Example response:
...@@ -125,20 +125,60 @@ Example response: ...@@ -125,20 +125,60 @@ Example response:
## Get a single repository storage move for a project ## Get a single repository storage move for a project
```plaintext ```plaintext
GET /project/:project_id/repository_storage_moves/:repository_storage_id GET /projects/:project_id/repository_storage_moves/:repository_storage_id
``` ```
Parameters: Parameters:
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `project_id` | integer | yes | The ID of the project | | `project_id` | integer | yes | ID of the project |
| `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: Example request:
```shell ```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: Example response:
......
...@@ -63,6 +63,25 @@ module API ...@@ -63,6 +63,25 @@ module API
present storage_move, with: Entities::ProjectRepositoryStorageMove, current_user: current_user present storage_move, with: Entities::ProjectRepositoryStorageMove, current_user: current_user
end 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 end
end end
...@@ -111,4 +111,45 @@ describe API::ProjectRepositoryStorageMoves do ...@@ -111,4 +111,45 @@ describe API::ProjectRepositoryStorageMoves do
let(:url) { "/projects/#{project.id}/repository_storage_moves/#{project_repository_storage_move_id}" } let(:url) { "/projects/#{project.id}/repository_storage_moves/#{project_repository_storage_move_id}" }
end end
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 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