Add an option to enable/disable a secondary geo node

[ci skip]
parent 3aa3cef4
.geo-node-icon-enabled {
color: $gl-success;
}
.geo-node-icon-disabled {
color: $gl-danger;
}
class Admin::GeoNodesController < Admin::ApplicationController
before_action :check_license, except: [:index, :destroy]
before_action :load_node, only: [:destroy, :repair]
before_action :load_node, only: [:destroy, :repair, :toggle]
def index
@nodes = GeoNode.all
......@@ -40,6 +40,19 @@ class Admin::GeoNodesController < Admin::ApplicationController
redirect_to admin_geo_nodes_path
end
def toggle
if @node.primary?
flash[:alert] = "Primary node can't be disabled."
else
@node.toggle!
new_status = @node.enabled? ? 'enabled' : 'disabled'
flash[:notice] = "Node #{@node.url} was successfully #{new_status}."
end
redirect_to admin_geo_nodes_path
end
private
def geo_node_params
......
module EE
module GeoHelper
def node_status_icon(node)
if node.primary?
icon 'star fw'
else
status = node.enabled? ? 'enabled' : 'disabled'
icon 'globe fw',
class: "geo-node-icon-#{status} has-tooltip",
title: status.capitalize
end
end
def toggle_node_button(node)
btn_class, title, data =
if node.enabled?
['warning', 'Disable node', { confirm: 'Disabling a node stops the repositories backfilling process. Are you sure?' }]
else
['success', 'Enable node']
end
link_to icon('power-off fw', text: title),
toggle_admin_geo_node_path(node),
method: :post,
class: "btn btn-sm btn-#{btn_class} prepend-left-10 has-tooltip",
title: title,
data: data
end
end
end
......@@ -31,6 +31,14 @@ class GeoNode < ActiveRecord::Base
mode: :per_attribute_iv,
encode: true
def secondary?
!primary
end
def toggle!
update_attribute(:enabled, !enabled)
end
def uri
if relative_url_root
relative_url = relative_url_root.starts_with?('/') ? relative_url_root : "/#{relative_url_root}"
......
......@@ -21,7 +21,6 @@
%p.help-block
Paste a machine public key here for the GitLab user this node runs on. Read more about how to generate it
= link_to "here", help_page_path("ssh/README")
.form-actions
= f.submit 'Add Node', class: 'btn btn-create'
%hr
......@@ -8,7 +8,7 @@
%hr
= render :partial => 'form', locals: {geo_node: @node} if Gitlab::Geo.license_allows?
= render partial: 'form', locals: {geo_node: @node} if Gitlab::Geo.license_allows?
- if @nodes.any?
.panel.panel-default
......@@ -19,7 +19,7 @@
%li
.list-item-name
%span
= node.primary ? icon('star fw') : icon('globe fw')
= node_status_icon(node)
%strong= node.url
%p
%span.help-block= node.primary ? 'Primary node' : 'Secondary node'
......@@ -30,6 +30,8 @@
= link_to repair_admin_geo_node_path(node), method: :post, title: 'OAuth application is missing', class: 'btn btn-default btn-sm prepend-left-10' do
= icon('exclamation-triangle fw')
Repair authentication
- if node.secondary?
= toggle_node_button(node)
= link_to admin_geo_node_path(node), data: { confirm: 'Are you sure?' }, method: :delete, class: 'btn btn-remove btn-sm prepend-left-10' do
= icon 'trash'
Remove
......@@ -113,6 +113,7 @@ namespace :admin do
resources :geo_nodes, only: [:index, :create, :destroy] do
member do
post :repair
post :toggle
end
end
## EE-specific
......
......@@ -115,4 +115,58 @@ describe Admin::GeoNodesController do
it_behaves_like 'unlicensed geo action'
end
describe '#toggle' do
subject { post :toggle, id: geo_node }
context 'without add-on license' do
let(:geo_node) { create(:geo_node) }
before do
allow(Gitlab::Geo).to receive(:license_allows?).and_return(false)
subject
end
it_behaves_like 'unlicensed geo action'
end
context 'with add-on license' do
before do
allow(Gitlab::Geo).to receive(:license_allows?).and_return(true)
subject
end
context 'with a primary node' do
let(:geo_node) { create(:geo_node, :primary, enabled: true) }
it 'does not disable the node' do
expect(geo_node.reload).to be_enabled
end
it 'displays a flash message' do
expect(controller).to set_flash.now[:alert].to("Primary node can't be disabled.")
end
it 'redirects to the geo nodes page' do
expect(response).to redirect_to(admin_geo_nodes_path)
end
end
context 'with a secondary node' do
let(:geo_node) { create(:geo_node, host: 'example.com', port: 80, enabled: true) }
it 'disables the node' do
expect(geo_node.reload).not_to be_enabled
end
it 'displays a flash message' do
expect(controller).to set_flash.now[:notice].to('Node http://example.com/ was successfully disabled.')
end
it 'redirects to the geo nodes page' do
expect(response).to redirect_to(admin_geo_nodes_path)
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