Commit 1653a4a4 authored by Kushal Pandya's avatar Kushal Pandya

Toon: Changes for 404 node status, support for refresh param

parent b63a22c6
......@@ -66,6 +66,8 @@ module API
strong_memoize(:geo_node_status) do
if geo_node.current?
GeoNodeStatus.current_node_status
elsif to_boolean(declared_params(include_missing: false)[:refresh])
::Geo::NodeStatusFetchService.new.call(geo_node)
else
geo_node.status
end
......@@ -93,6 +95,9 @@ module API
desc 'Get metrics for a single Geo node' do
success EE::API::Entities::GeoNodeStatus
end
params do
optional :refresh, type: Boolean, desc: 'Attempt to fetch the latest status from the Geo node directly, ignoring the cache'
end
get 'status' do
not_found!('GeoNode') unless geo_node
......@@ -145,6 +150,20 @@ module API
render_validation_error!(geo_node)
end
end
# Delete an existing Geo node
#
# Example request:
# DELETE /geo_nodes/:id
desc 'Delete an existing Geo secondary node' do
success EE::API::Entities::GeoNode
end
delete do
not_found!('GeoNode') unless geo_node
geo_node.destroy!
status 204
end
end
end
end
......
......@@ -34,9 +34,11 @@ describe API::GeoNodes, :geo, api: true do
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('public_api/v4/geo_node', dir: 'ee')
expect(json_response['web_edit_url']).to end_with("/admin/geo_nodes/#{primary.id}/edit")
links = json_response['_links']
expect(links['self']).to end_with("/api/v4/geo_nodes/#{primary.id}")
expect(links['status']).to end_with("/api/v4/geo_nodes/#{primary.id}/status")
expect(links['repair']).to end_with("/api/v4/geo_nodes/#{primary.id}/repair")
end
......@@ -99,6 +101,32 @@ describe API::GeoNodes, :geo, api: true do
expect(response).to match_response_schema('public_api/v4/geo_node_status', dir: 'ee')
end
it 'fetches the real-time status with `refresh=true`' do
stub_current_geo_node(primary)
new_status = build(:geo_node_status, :healthy, geo_node: secondary, attachments_count: 923, lfs_objects_count: 652)
expect(GeoNode).to receive(:find).and_return(secondary)
expect_any_instance_of(Geo::NodeStatusFetchService).to receive(:call).and_return(new_status)
get api("/geo_nodes/#{secondary.id}/status", admin), refresh: true
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('public_api/v4/geo_node_status', dir: 'ee')
expect(json_response['attachments_count']).to eq(923)
expect(json_response['lfs_objects_count']).to eq(652)
end
it 'returns 404 when no Geo Node status is not found' do
stub_current_geo_node(primary)
secondary_status.destroy!
expect(GeoNode).to receive(:find).and_return(secondary)
get api("/geo_nodes/#{secondary.id}/status", admin)
expect(response).to have_gitlab_http_status(404)
end
it_behaves_like '404 response' do
let(:request) { get api("/geo_nodes/#{unexisting_node_id}/status", admin) }
end
......@@ -149,7 +177,7 @@ describe API::GeoNodes, :geo, api: true do
describe 'PUT /geo_nodes/:id' do
it_behaves_like '404 response' do
let(:request) { get api("/geo_nodes/#{unexisting_node_id}/status", admin) }
let(:request) { put api("/geo_nodes/#{unexisting_node_id}", admin), {} }
end
it 'denies access if not admin' do
......@@ -174,6 +202,32 @@ describe API::GeoNodes, :geo, api: true do
end
end
describe 'DELETE /geo_nodes/:id' do
it_behaves_like '404 response' do
let(:request) { delete api("/geo_nodes/#{unexisting_node_id}", admin) }
end
it 'denies access if not admin' do
delete api("/geo_nodes/#{secondary.id}", user)
expect(response).to have_gitlab_http_status(403)
end
it 'deletes the node' do
delete api("/geo_nodes/#{secondary.id}", admin)
expect(response).to have_gitlab_http_status(204)
end
it 'returns 400 if Geo Node could not be deleted' do
allow_any_instance_of(GeoNode).to receive(:destroy!).and_raise(StandardError, 'Something wrong')
delete api("/geo_nodes/#{secondary.id}", admin)
expect(response).to have_gitlab_http_status(500)
end
end
describe 'GET /geo_nodes/current/failures/:type' do
it 'fetches the current node failures' do
create(:geo_project_registry, :sync_failed)
......
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