elastics-admin 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
 - data/bin/elastics-admin +2 -1
 - data/lib/elastics/admin.rb +1 -1
 - data/lib/elastics/admin_live_reindex.rb +7 -14
 - metadata +4 -4
 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            1.1. 
     | 
| 
      
 1 
     | 
    
         
            +
            1.1.1
         
     | 
    
        data/bin/elastics-admin
    CHANGED
    
    | 
         @@ -5,7 +5,8 @@ require 'elastics-admin' 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            options  = Elastics::Admin::Tasks.new.default_options
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
      
 8 
     | 
    
         
            +
            version_path = %w[../../VERSION ../../../VERSION].detect{|v| File.exist?(File.expand_path(v, __FILE__))}
         
     | 
| 
      
 9 
     | 
    
         
            +
            version  = File.read(File.expand_path(version_path, __FILE__)).strip
         
     | 
| 
       9 
10 
     | 
    
         
             
            copy     = "elastics-admin #{version} (c) 2012-2013 by Domizio Demichelis"
         
     | 
| 
       10 
11 
     | 
    
         
             
            optparse = OptionParser.new do |opts|
         
     | 
| 
       11 
12 
     | 
    
         | 
    
        data/lib/elastics/admin.rb
    CHANGED
    
    | 
         @@ -29,7 +29,7 @@ module Elastics 
     | 
|
| 
       29 
29 
     | 
    
         
             
                  end
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
31 
     | 
    
         
             
                  def dump_to_file(cli=false)
         
     | 
| 
       32 
     | 
    
         
            -
                    vars = { :index => cli ? options[:index] : (options[:index] ||  
     | 
| 
      
 32 
     | 
    
         
            +
                    vars = { :index => cli ? options[:index] : (options[:index] || Conf.indices.keys),
         
     | 
| 
       33 
33 
     | 
    
         
             
                             :type  => options[:type] }
         
     | 
| 
       34 
34 
     | 
    
         
             
                    Prompter.say_title "Dumping indices: #{vars[:index].inspect}" if options[:verbose]
         
     | 
| 
       35 
35 
     | 
    
         
             
                    if options[:verbose]
         
     | 
| 
         @@ -70,7 +70,7 @@ module Elastics 
     | 
|
| 
       70 
70 
     | 
    
         
             
                  yield self if block_given?
         
     | 
| 
       71 
71 
     | 
    
         | 
| 
       72 
72 
     | 
    
         
             
                  opts[:verbose] = true unless opts.has_key?(:verbose)
         
     | 
| 
       73 
     | 
    
         
            -
                  opts[:index] ||= opts.delete(:indices) ||  
     | 
| 
      
 73 
     | 
    
         
            +
                  opts[:index] ||= opts.delete(:indices) || Conf.indices.keys
         
     | 
| 
       74 
74 
     | 
    
         | 
| 
       75 
75 
     | 
    
         
             
                  # we override the on_reindex eventually set
         
     | 
| 
       76 
76 
     | 
    
         
             
                  on_reindex do
         
     | 
| 
         @@ -105,12 +105,9 @@ module Elastics 
     | 
|
| 
       105 
105 
     | 
    
         
             
                  # raise if base is not included in @ensure_indices
         
     | 
| 
       106 
106 
     | 
    
         
             
                  raise ExtraIndexError, "The index #{base} is missing from the :ensure_indices option. Reindexing aborted." \
         
     | 
| 
       107 
107 
     | 
    
         
             
                        if @ensure_indices && !@ensure_indices.include?(base)
         
     | 
| 
       108 
     | 
    
         
            -
                  prefixed = @ 
     | 
| 
      
 108 
     | 
    
         
            +
                  prefixed = @prefix + base
         
     | 
| 
       109 
109 
     | 
    
         
             
                  unless @indices.include?(base)
         
     | 
| 
       110 
     | 
    
         
            -
                    unless Elastics.exist?(:index => prefixed)
         
     | 
| 
       111 
     | 
    
         
            -
                      config_hash[base] = {} unless config_hash.has_key?(base)
         
     | 
| 
       112 
     | 
    
         
            -
                      Elastics.POST "/#{prefixed}", config_hash[base]
         
     | 
| 
       113 
     | 
    
         
            -
                    end
         
     | 
| 
      
 110 
     | 
    
         
            +
                    Conf.indices.create_index(base, prefixed) unless Elastics.exist?(:index => prefixed)
         
     | 
| 
       114 
111 
     | 
    
         
             
                    @indices |= [base]
         
     | 
| 
       115 
112 
     | 
    
         
             
                  end
         
     | 
| 
       116 
113 
     | 
    
         
             
                  prefixed
         
     | 
| 
         @@ -123,10 +120,6 @@ module Elastics 
     | 
|
| 
       123 
120 
     | 
    
         | 
| 
       124 
121 
     | 
    
         
             
                private
         
     | 
| 
       125 
122 
     | 
    
         | 
| 
       126 
     | 
    
         
            -
                def config_hash
         
     | 
| 
       127 
     | 
    
         
            -
                  @config_hash ||= ModelTasks.new.config_hash
         
     | 
| 
       128 
     | 
    
         
            -
                end
         
     | 
| 
       129 
     | 
    
         
            -
             
     | 
| 
       130 
123 
     | 
    
         
             
                def perform(opts={})
         
     | 
| 
       131 
124 
     | 
    
         
             
                  Prompter.say_title 'Live-Reindex' if opts[:verbose]
         
     | 
| 
       132 
125 
     | 
    
         
             
                  if opts[:safe_reindex] == false
         
     | 
| 
         @@ -135,7 +128,7 @@ module Elastics 
     | 
|
| 
       135 
128 
     | 
    
         
             
                  end
         
     | 
| 
       136 
129 
     | 
    
         
             
                  Redis.init
         
     | 
| 
       137 
130 
     | 
    
         
             
                  @indices        = []
         
     | 
| 
       138 
     | 
    
         
            -
                  @ 
     | 
| 
      
 131 
     | 
    
         
            +
                  @prefix         = Time.now.strftime('%Y%m%d%H%M%S_')
         
     | 
| 
       139 
132 
     | 
    
         
             
                  @ensure_indices = nil
         
     | 
| 
       140 
133 
     | 
    
         | 
| 
       141 
134 
     | 
    
         
             
                  unless opts[:on_stop_indexing] == false || Conf.on_stop_indexing == false
         
     | 
| 
         @@ -179,7 +172,7 @@ module Elastics 
     | 
|
| 
       179 
172 
     | 
    
         
             
                    Elastics.delete_index :index => index,
         
     | 
| 
       180 
173 
     | 
    
         
             
                                          :raise => false # may not exist
         
     | 
| 
       181 
174 
     | 
    
         
             
                    Elastics.post_index_aliases :actions => [{ :add => { :alias => index,
         
     | 
| 
       182 
     | 
    
         
            -
                                                                         :index => @ 
     | 
| 
      
 175 
     | 
    
         
            +
                                                                         :index => @prefix + index } }]
         
     | 
| 
       183 
176 
     | 
    
         
             
                  end
         
     | 
| 
       184 
177 
     | 
    
         
             
                  # after the execution of this method the user should deploy the new code and then resume the regular app processing
         
     | 
| 
       185 
178 
     | 
    
         | 
| 
         @@ -187,7 +180,7 @@ module Elastics 
     | 
|
| 
       187 
180 
     | 
    
         
             
                  unless opts[:safe_reindex] == false
         
     | 
| 
       188 
181 
     | 
    
         
             
                    class_eval <<-ruby, __FILE__, __LINE__
         
     | 
| 
       189 
182 
     | 
    
         
             
                      def perform(*)
         
     | 
| 
       190 
     | 
    
         
            -
                        raise MultipleReindexError, "Multiple live-reindex attempted! You cannot use any reindexing method multiple times in the same session or you may corrupt your index/indices! The previous reindexing in this session successfully reindexed and swapped the new index/indices: #{@indices.map{|i| @ 
     | 
| 
      
 183 
     | 
    
         
            +
                        raise MultipleReindexError, "Multiple live-reindex attempted! You cannot use any reindexing method multiple times in the same session or you may corrupt your index/indices! The previous reindexing in this session successfully reindexed and swapped the new index/indices: #{@indices.map{|i| @prefix + i}.join(', ')}. You must deploy now, and run the other reindexing in single successive deploys ASAP. Notice that if the code-changes that you are about to deploy rely on the successive reindexings that have been aborted, your app may fail. If you are working in development mode you must restart the session now. The next time you can silence this error by passing :safe_reindex => false"
         
     | 
| 
       191 
184 
     | 
    
         
             
                      end
         
     | 
| 
       192 
185 
     | 
    
         
             
                    ruby
         
     | 
| 
       193 
186 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -196,7 +189,7 @@ module Elastics 
     | 
|
| 
       196 
189 
     | 
    
         
             
                  # delete all the created indices
         
     | 
| 
       197 
190 
     | 
    
         
             
                  @indices ||=[]
         
     | 
| 
       198 
191 
     | 
    
         
             
                  @indices.each do |index|
         
     | 
| 
       199 
     | 
    
         
            -
                    Elastics.delete_index :index => @ 
     | 
| 
      
 192 
     | 
    
         
            +
                    Elastics.delete_index :index => @prefix + index
         
     | 
| 
       200 
193 
     | 
    
         
             
                  end
         
     | 
| 
       201 
194 
     | 
    
         
             
                  raise
         
     | 
| 
       202 
195 
     | 
    
         | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: elastics-admin
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.1.1
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2013-09- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2013-09-15 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: elastics-client
         
     | 
| 
         @@ -18,7 +18,7 @@ dependencies: 
     | 
|
| 
       18 
18 
     | 
    
         
             
                requirements:
         
     | 
| 
       19 
19 
     | 
    
         
             
                - - '='
         
     | 
| 
       20 
20 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       21 
     | 
    
         
            -
                    version: 1.1. 
     | 
| 
      
 21 
     | 
    
         
            +
                    version: 1.1.1
         
     | 
| 
       22 
22 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       23 
23 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       24 
24 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -26,7 +26,7 @@ dependencies: 
     | 
|
| 
       26 
26 
     | 
    
         
             
                requirements:
         
     | 
| 
       27 
27 
     | 
    
         
             
                - - '='
         
     | 
| 
       28 
28 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       29 
     | 
    
         
            -
                    version: 1.1. 
     | 
| 
      
 29 
     | 
    
         
            +
                    version: 1.1.1
         
     | 
| 
       30 
30 
     | 
    
         
             
            description: Provides binary and rake tasks to dump, load and optionally rename indices.
         
     | 
| 
       31 
31 
     | 
    
         
             
              Implements live-reindex with hot-swap of old code/index with new code/index.
         
     | 
| 
       32 
32 
     | 
    
         
             
            email: dd.nexus@gmail.com
         
     |