lib/zold/commands/remote.rb in zold-0.11.16 vs lib/zold/commands/remote.rb in zold-0.11.17

- old
+ new

@@ -56,18 +56,23 @@ Restore it back to the default list of nodes #{Rainbow('remote add').green} host [port] Add a new remote node #{Rainbow('remote remove').green} host [port] Remove the remote node + #{Rainbow('remote elect').green} + Pick a random remote node as a target for a bonus awarding #{Rainbow('remote trim').green} Remote the least reliable nodes #{Rainbow('remote update').green} Check each registered remote node for availability Available options:" o.bool '--ignore-score-weakness', 'Don\'t complain when their score is too weak', default: false + o.bool '--ignore-score-value', + 'Don\'t complain when their score is too small', + default: false o.bool '--force', 'Add/remove if if this operation is not possible', default: false o.bool '--reboot', 'Exit if any node reports version higher than we have', @@ -86,10 +91,12 @@ reset when 'add' add(mine[1], mine[2] ? mine[2].to_i : Remotes::PORT, opts) when 'remove' remove(mine[1], mine[2] ? mine[2].to_i : Remotes::PORT, opts) + when 'elect' + elect(opts) when 'trim' trim(opts) when 'update' update(opts) update(opts, false) @@ -135,9 +142,29 @@ else raise "#{host}:#{port} is not in the list" unless opts['force'] @log.info("#{host}:#{port} is not in the list") end @log.info("There are #{@remotes.all.count} remote nodes in the list") + end + + # Returns an array of Zold::Score + def elect(opts) + scores = [] + @remotes.all.sample(1).each do |winner| + @remotes.iterate(@log, farm: @farm) do |r| + next if r.host != winner[:host] || r.port != winner[:port] + res = r.http('/').get + r.assert_code(200, res) + score = Score.parse_json(JSON.parse(res.body)['score']) + r.assert_valid_score(score) + r.assert_score_ownership(score) + r.assert_score_strength(score) unless opts['ignore-score-weakness'] + r.assert_score_value(score, Tax::EXACT_SCORE) unless opts['ignore-score-value'] + @log.info("Elected: #{score}") + scores << score + end + end + scores end def trim(opts) @remotes.all.each do |r| remove(r[:host], r[:port], opts) if r[:errors] > Remotes::TOLERANCE