Sha256: 3de6cd46c1bb46f63b17e94df8ad5fb20b4239102e818c6f18724127a3f55d36

Contents?: true

Size: 1.75 KB

Versions: 15

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

require 'elastic_manager/logger'

# Index opening operations
module Open
  include Logging

  def open_populate_indices(indices, date_from, date_to, daysago)
    result = []

    if indices.length == 1 && indices.first == '_all'
      result = @elastic.all_indices(date_from, date_to, daysago, 'close', nil, @config)
      result += @elastic.all_indices_in_snapshots(date_from, date_to, daysago, @config)
      return result
    end

    if date_from.nil?
      result = @elastic.all_indices(date_from, date_to, daysago, 'close', nil, @config)
      result += @elastic.all_indices_in_snapshots(date_from, date_to, daysago, @config)
      return result.select { |r| r.start_with?(*indices) }
    else
      date_from.upto(date_to) do |date|
        indices.each do |index|
          date_formatted = date.to_s.tr('-', '.')
          result << "#{index}-#{date_formatted}"
        end
      end
    end

    return result unless result.empty?

    log.fatal 'no indices for work'
    exit 1
  end

  def do_open(indices)
    indices.each do |index|
      next if skip_index?(index, 'open')

      response = @elastic.request(:get, "/_cat/indices/#{index}")

      if index_exist?(response)
        next if already?(response, 'open')

        elastic_action_with_log('open_index', index)
      else
        log.warn "#{index} index not found"
        log.info "#{index} trying snapshot restore"

        elastic_action_with_log('restore_snapshot', index, @config['settings']['box_types']['store'])
      end
    end
  end

  def open
    indices, date_from, date_to, daysago = prepare_vars
    prechecks(date_from, date_to)
    indices = open_populate_indices(indices, date_from, date_to, daysago)
    log.debug indices.inspect
    do_open(indices)
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
elastic_manager-0.3.2 lib/elastic_manager/open.rb
elastic_manager-0.3.1 lib/elastic_manager/open.rb
elastic_manager-0.3.1.pre.debug lib/elastic_manager/open.rb
elastic_manager-0.3.0 lib/elastic_manager/open.rb
elastic_manager-0.2.9 lib/elastic_manager/open.rb
elastic_manager-0.2.8 lib/elastic_manager/open.rb
elastic_manager-0.2.7 lib/elastic_manager/open.rb
elastic_manager-0.2.6 lib/elastic_manager/open.rb
elastic_manager-0.2.5 lib/elastic_manager/open.rb
elastic_manager-0.2.4 lib/elastic_manager/open.rb
elastic_manager-0.2.3 lib/elastic_manager/open.rb
elastic_manager-0.2.2 lib/elastic_manager/open.rb
elastic_manager-0.2.1 lib/elastic_manager/open.rb
elastic_manager-0.2.0 lib/elastic_manager/open.rb
elastic_manager-0.1.9 lib/elastic_manager/open.rb