diff options
-rw-r--r-- | lib/storage.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/storage.rb b/lib/storage.rb index 8828bf6..7ec0861 100644 --- a/lib/storage.rb +++ b/lib/storage.rb @@ -5,6 +5,21 @@ require 'pp' module Ag::Storage module_function + def index_states(indexname) + status = $es.indices.status(index: indexname) + states = status['indices'][indexname]['shards'].map do |key,array| + array.map do |v| + v['routing']['state'] + end.flatten + end.flatten + end + def index_ready?(indexname) + states = index_states(indexname) + not_ready = states.include? 'INITIALIZING' or states.include? 'RELOCATING' + return !not_ready + pp $es.cluster.health(level: indices) + end + # Throws Elasticsearch::Transport::Transport::Errors::NotFound # if the list does not exist def delete_index(list) @@ -88,6 +103,7 @@ module Ag::Storage } }) + pp $es.cluster.health(level: indices) # Give elasticsearch some time to process the new index status = $es.indices.status(index: indexname) while $es.cluster.health['status'] != 'green' do |