Class: EsMigration

Inherits:
EsMigrationDsl show all
Defined in:
lib/wukong-migrate/elasticsearch_migration.rb

Instance Method Summary collapse

Methods inherited from EsMigrationDsl

#operation_list, template

Methods included from EsHttpOperation::Helpers

#alias_index_op, #create_index_op, #delete_index_op, #update_mapping_op, #update_settings_op

Methods inherited from Wukong::Migration::Dsl

define, perform

Methods included from Gorillib::Builder

#getset, #getset_collection_item

Instance Method Details

#combined_operationsObject



138
139
140
# File 'lib/wukong-migrate/elasticsearch_migration.rb', line 138

def combined_operations
  operation_list + nested_operations
end

#nested_operationsObject



134
135
136
# File 'lib/wukong-migrate/elasticsearch_migration.rb', line 134

def nested_operations
  (creations.to_a + updates.to_a).map{ |idx| idx.operation_list }.flatten
end

#perform(options = {}) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/wukong-migrate/elasticsearch_migration.rb', line 142

def perform(options = {})
  combined_operations.each do |op|
    op.configure_with options
    log.info  op.info
    log.debug op.raw_curl_string
    response = op.execute
    log.debug [response.code, response.parsed_response].join(' ')
    if response.code == 200
      log.info 'Operation complete'
    else
      log.error response.parsed_response
      break unless options[:force]
    end
  end
end

#receive_create_index(attrs, &block) ⇒ Object



116
117
118
119
120
# File 'lib/wukong-migrate/elasticsearch_migration.rb', line 116

def receive_create_index(attrs, &block)
  idx = IndexDsl.receive(attrs, &block)
  operation_list << create_index_op(idx.name, idx.index_settings)
  idx
end

#receive_delete_index(attrs, &block) ⇒ Object



128
129
130
131
132
# File 'lib/wukong-migrate/elasticsearch_migration.rb', line 128

def receive_delete_index(attrs, &block)
  idx = IndexDsl.receive(attrs, &block)
  operation_list.unshift delete_index_op(idx.name)
  idx
end

#receive_update_index(attrs, &block) ⇒ Object



122
123
124
125
126
# File 'lib/wukong-migrate/elasticsearch_migration.rb', line 122

def receive_update_index(attrs, &block)
  idx = IndexDsl.receive(attrs, &block)
  operation_list << update_settings_op(idx.name, idx.index_settings)
  idx
end