Add minimum reverification interval to Geo nodes

This commit add a minimum_reverification_interval column to
the geo_nodes table. This columns says after how many days
(at least) a repository should reverified.
parent 9bb27f79
...@@ -1238,6 +1238,7 @@ ActiveRecord::Schema.define(version: 20181204135932) do ...@@ -1238,6 +1238,7 @@ ActiveRecord::Schema.define(version: 20181204135932) do
t.string "selective_sync_type" t.string "selective_sync_type"
t.text "selective_sync_shards" t.text "selective_sync_shards"
t.integer "verification_max_capacity", default: 100, null: false t.integer "verification_max_capacity", default: 100, null: false
t.integer "minimum_reverification_interval", default: 7, null: false
t.index ["access_key"], name: "index_geo_nodes_on_access_key", using: :btree t.index ["access_key"], name: "index_geo_nodes_on_access_key", using: :btree
t.index ["primary"], name: "index_geo_nodes_on_primary", using: :btree t.index ["primary"], name: "index_geo_nodes_on_primary", using: :btree
t.index ["url"], name: "index_geo_nodes_on_url", unique: true, using: :btree t.index ["url"], name: "index_geo_nodes_on_url", unique: true, using: :btree
......
...@@ -3,11 +3,12 @@ import { s__ } from '~/locale'; ...@@ -3,11 +3,12 @@ import { s__ } from '~/locale';
import '~/flash'; import '~/flash';
import Api from '~/api'; import Api from '~/api';
const onPrimaryCheckboxChange = function onPrimaryCheckboxChange(e, $namespaces) { const onPrimaryCheckboxChange = function onPrimaryCheckboxChange(e, $namespaces, $reverification) {
const $namespacesSelect = $('.select2', $namespaces); const $namespacesSelect = $('.select2', $namespaces);
$namespacesSelect.select2('data', null); $namespacesSelect.select2('data', null);
$namespaces.toggleClass('hidden', e.currentTarget.checked); $namespaces.toggleClass('hidden', e.currentTarget.checked);
$reverification.toggleClass('hidden', !e.currentTarget.checked);
}; };
const onSelectiveSyncTypeChange = function onSelectiveSyncTypeChange(e, $byNamespaces, $byShards) { const onSelectiveSyncTypeChange = function onSelectiveSyncTypeChange(e, $byNamespaces, $byShards) {
...@@ -18,13 +19,14 @@ const onSelectiveSyncTypeChange = function onSelectiveSyncTypeChange(e, $byNames ...@@ -18,13 +19,14 @@ const onSelectiveSyncTypeChange = function onSelectiveSyncTypeChange(e, $byNames
export default function geoNodeForm() { export default function geoNodeForm() {
const $container = $('.js-geo-node-form'); const $container = $('.js-geo-node-form');
const $namespaces = $('.js-hide-if-geo-primary', $container); const $namespaces = $('.js-hide-if-geo-primary', $container);
const $reverification = $('.js-hide-if-geo-secondary', $container);
const $primaryCheckbox = $('input[type="checkbox"]', $container); const $primaryCheckbox = $('input[type="checkbox"]', $container);
const $selectiveSyncTypeSelect = $('.js-geo-node-selective-sync-type', $container); const $selectiveSyncTypeSelect = $('.js-geo-node-selective-sync-type', $container);
const $select2Dropdown = $('.js-geo-node-namespaces', $container); const $select2Dropdown = $('.js-geo-node-namespaces', $container);
const $syncByNamespaces = $('.js-sync-by-namespace', $container); const $syncByNamespaces = $('.js-sync-by-namespace', $container);
const $syncByShards = $('.js-sync-by-shard', $container); const $syncByShards = $('.js-sync-by-shard', $container);
$primaryCheckbox.on('change', e => onPrimaryCheckboxChange(e, $namespaces)); $primaryCheckbox.on('change', e => onPrimaryCheckboxChange(e, $namespaces, $reverification));
$selectiveSyncTypeSelect.on('change', e => $selectiveSyncTypeSelect.on('change', e =>
onSelectiveSyncTypeChange(e, $syncByNamespaces, $syncByShards), onSelectiveSyncTypeChange(e, $syncByNamespaces, $syncByShards),
......
...@@ -18,7 +18,7 @@ class Admin::Geo::NodesController < Admin::ApplicationController ...@@ -18,7 +18,7 @@ class Admin::Geo::NodesController < Admin::ApplicationController
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def create def create
@node = Geo::NodeCreateService.new(geo_node_params).execute @node = ::Geo::NodeCreateService.new(geo_node_params).execute
if @node.persisted? if @node.persisted?
redirect_to admin_geo_nodes_path, notice: 'Node was successfully created.' redirect_to admin_geo_nodes_path, notice: 'Node was successfully created.'
...@@ -34,7 +34,7 @@ class Admin::Geo::NodesController < Admin::ApplicationController ...@@ -34,7 +34,7 @@ class Admin::Geo::NodesController < Admin::ApplicationController
end end
def update def update
if Geo::NodeUpdateService.new(@node, geo_node_params).execute if ::Geo::NodeUpdateService.new(@node, geo_node_params).execute
redirect_to admin_geo_nodes_path, notice: 'Node was successfully updated.' redirect_to admin_geo_nodes_path, notice: 'Node was successfully updated.'
else else
render :edit render :edit
...@@ -52,7 +52,8 @@ class Admin::Geo::NodesController < Admin::ApplicationController ...@@ -52,7 +52,8 @@ class Admin::Geo::NodesController < Admin::ApplicationController
:namespace_ids, :namespace_ids,
:repos_max_capacity, :repos_max_capacity,
:files_max_capacity, :files_max_capacity,
:verification_max_capacity :verification_max_capacity,
:minimum_reverification_interval
) )
end end
......
...@@ -34,13 +34,14 @@ class GeoNode < ActiveRecord::Base ...@@ -34,13 +34,14 @@ class GeoNode < ActiveRecord::Base
validates :repos_max_capacity, numericality: { greater_than_or_equal_to: 0 } validates :repos_max_capacity, numericality: { greater_than_or_equal_to: 0 }
validates :files_max_capacity, numericality: { greater_than_or_equal_to: 0 } validates :files_max_capacity, numericality: { greater_than_or_equal_to: 0 }
validates :verification_max_capacity, numericality: { greater_than_or_equal_to: 0 } validates :verification_max_capacity, numericality: { greater_than_or_equal_to: 0 }
validates :minimum_reverification_interval, numericality: { greater_than_or_equal_to: 1 }
validate :check_not_adding_primary_as_secondary, if: :secondary? validate :check_not_adding_primary_as_secondary, if: :secondary?
after_save :expire_cache! after_save :expire_cache!
after_destroy :expire_cache! after_destroy :expire_cache!
before_validation :update_dependents_attributes
before_validation :update_dependents_attributes
before_validation :ensure_access_keys! before_validation :ensure_access_keys!
alias_method :repair, :save # the `update_dependents_attributes` hook will take care of it alias_method :repair, :save # the `update_dependents_attributes` hook will take care of it
......
...@@ -60,3 +60,11 @@ ...@@ -60,3 +60,11 @@
= form.number_field :verification_max_capacity, class: 'form-control', min: 0 = form.number_field :verification_max_capacity, class: 'form-control', min: 0
.form-text.text-muted .form-text.text-muted
#{ s_('Control the maximum concurrency of verification operations for this Geo node') } #{ s_('Control the maximum concurrency of verification operations for this Geo node') }
.form-group.row.js-hide-if-geo-secondary{ class: ('hidden' unless geo_node.primary?) }
.col-sm-2
= form.label :minimum_reverification_interval, s_('Geo|Re-verification interval'), class: 'col-form-label'
.col-sm-10
= form.number_field :minimum_reverification_interval, class: 'form-control', min: 1
.form-text.text-muted
#{ s_('Control the minimum interval in days that a repository should be reverified for this primary node') }
# frozen_string_literal: true
class AddMinimumReverificationIntervalToGeoNodes < ActiveRecord::Migration[4.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_column_with_default :geo_nodes, :minimum_reverification_interval, :integer, default: 7, allow_null: false
end
def down
remove_column :geo_nodes, :minimum_reverification_interval
end
end
...@@ -38,6 +38,18 @@ describe 'admin Geo Nodes', :js do ...@@ -38,6 +38,18 @@ describe 'admin Geo Nodes', :js do
end end
end end
it 'changes re-verification interval field visibility based on primary node checkbox' do
expect(page).not_to have_field('Re-verification interval')
check 'This is a primary node'
expect(page).to have_field('Re-verification interval')
uncheck 'This is a primary node'
expect(page).not_to have_field('Re-verification interval')
end
it 'returns an error message when a duplicate primary is added' do it 'returns an error message when a duplicate primary is added' do
create(:geo_node, :primary) create(:geo_node, :primary)
......
...@@ -26,6 +26,7 @@ describe GeoNode, type: :model do ...@@ -26,6 +26,7 @@ describe GeoNode, type: :model do
it { is_expected.to validate_numericality_of(:repos_max_capacity).is_greater_than_or_equal_to(0) } it { is_expected.to validate_numericality_of(:repos_max_capacity).is_greater_than_or_equal_to(0) }
it { is_expected.to validate_numericality_of(:files_max_capacity).is_greater_than_or_equal_to(0) } it { is_expected.to validate_numericality_of(:files_max_capacity).is_greater_than_or_equal_to(0) }
it { is_expected.to validate_numericality_of(:verification_max_capacity).is_greater_than_or_equal_to(0) } it { is_expected.to validate_numericality_of(:verification_max_capacity).is_greater_than_or_equal_to(0) }
it { is_expected.to validate_numericality_of(:minimum_reverification_interval).is_greater_than_or_equal_to(1) }
end end
context 'default values' do context 'default values' do
......
...@@ -2417,6 +2417,9 @@ msgstr "" ...@@ -2417,6 +2417,9 @@ msgstr ""
msgid "Control the maximum concurrency of verification operations for this Geo node" msgid "Control the maximum concurrency of verification operations for this Geo node"
msgstr "" msgstr ""
msgid "Control the minimum interval in days that a repository should be reverified for this primary node"
msgstr ""
msgid "ConvDev Index" msgid "ConvDev Index"
msgstr "" msgstr ""
...@@ -3994,6 +3997,9 @@ msgstr "" ...@@ -3994,6 +3997,9 @@ msgstr ""
msgid "Geo|Projects in certain storage shards" msgid "Geo|Projects in certain storage shards"
msgstr "" msgstr ""
msgid "Geo|Re-verification interval"
msgstr ""
msgid "Geo|Recheck" msgid "Geo|Recheck"
msgstr "" msgstr ""
......
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