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



136
137
138
# File 'lib/wukong-migrate/elasticsearch_migration.rb', line 136

def combined_operations
  operation_list + nested_operations
end

#nested_operationsObject



132
133
134
# File 'lib/wukong-migrate/elasticsearch_migration.rb', line 132

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

#perform(options = {}) ⇒ Object



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

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



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

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



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

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



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

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