elasticshelf 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 600e76e898a7092c714c0eb4eb8065af93c6690d
4
- data.tar.gz: 1aae40b15a8349ea1a4e7616f40e444e58e48229
3
+ metadata.gz: 17341df9c00b09d1a9627fedc1b198469cdd7873
4
+ data.tar.gz: 32c212f38fe54af22d16159dfadfe5948bafc226
5
5
  SHA512:
6
- metadata.gz: 600f1e3260425d1b89b5087c6cf8b7729dd0dfb377a1486bdde25550ed34b4e2b7222211980eaf11908aeebe264a75f150b5ca744b6c9b1287fbdcc1f76771cc
7
- data.tar.gz: 04c382b1ca40101f3c7ba9a8049512919b32d78f9fb382f90a024b7283988167f6859268529f29fe044ef925431e73e3234d646cf5530530d4ba2df19cf40b0d
6
+ metadata.gz: 309f27d6d4b3bdc13222b2ab84f9d578ab1f0882abb2a8e86d7a657854e8084e8921ad1d46c700e86a039c96b033b9541c67d99c4958e381a80b136b38a6fdd1
7
+ data.tar.gz: 646a30138b4cdea5c0d1f99dd9a2c8b2b255a0ae29d820eca3f6d632ccec048797664a9216f2f61756fe94386824281004951a32204fd45f737cddfb67939a2c
data/README.md CHANGED
@@ -172,6 +172,17 @@ es.snapshot = 'name_of_this_snapshot'
172
172
  es.snapshot_delete
173
173
  ```
174
174
 
175
+ ### Snapshot restore
176
+
177
+ ```
178
+ es.repo = 'name_of_the_snapshot_repository'
179
+ es.snapshot = "name_of_this_snapshot"
180
+ es.indices = "index1"
181
+ es.snapshot_restore
182
+ puts "errors=#{es.errors.inspect}"
183
+ puts "results=#{es.results.inspect}"
184
+ ```
185
+
175
186
  ### Other usage
176
187
 
177
188
  ```
@@ -1,17 +1,53 @@
1
- #!/usr/bin/env ruby
2
- require 'elasticshelf'
1
+ # Example: for use as a Resque job
2
+ # test in console to simulate resque job:
3
+ # turn off sql printing in rails console so we can see "puts" clearly:
4
+ # ActiveRecord::Base.logger = ::Logger.new(nil)
5
+ # bundle exec rails c
6
+ # ew = EsWither.new
7
+ # ew.wither_old_indices
3
8
 
4
- if ARGV.empty?
5
- puts "please enter the cutoff days number"
6
- exit(1)
7
- end
8
- days = ARGV[0].to_i
9
+ class EsWither
10
+ require 'elasticshelf'
9
11
 
10
- es = Elasticshelf::Client.new(:host => '127.0.0.1:9200')
12
+ # this allows us to pass in different methods to perform from the Resque config/schedule.yml:
13
+ class << self
14
+ def perform(method)
15
+ self.new.send(method)
16
+ end
17
+ end
11
18
 
12
- # optional, as 'logstash-' and '.' are the defaults:
13
- # es.indices_prefix = '???-'
14
- # es.date_separator = '.'
19
+ def initialize
20
+ puts "#{Time.now.utc} EsWither::initialize:"
21
+ @es = Elasticshelf::Client.new(:host => "#{APP_CONFIG[:elasticsearch_host]}:#{APP_CONFIG[:elasticsearch_port]}")
22
+ @es.repo = "#{APP_CONFIG[:elasticsearch_host]}}_logs"
23
+ @es.indices_prefix = "#{APP_CONFIG[:elasticsearch_host]}_logs-"
24
+ puts "\trepo=#{@es.repo}"
25
+ puts "\tindices_prefix=#{@es.indices_prefix}"
26
+ end
15
27
 
16
- es.cutoff_days = days
17
- es.wither_indices
28
+ def wither_old_indices
29
+ puts "#{Time.now.utc} EsWither::wither_old_indices: starting . . ."
30
+ start_time = Time.now.utc
31
+ @es.cutoff_days = 3
32
+ puts "\tcutoff date=#{@es.cutoff_days_as_date_to_s}"
33
+ # ************************
34
+ @es.wither_expired_indices
35
+ # ************************
36
+ puts "\tindices_withered: #{@es.indices_withered.inspect}"
37
+ puts "expired_indices:"
38
+ @es.expired_indices.each { |k,v| puts "\t#{k}=#{v}" }
39
+ puts "indices_rejected:"
40
+ @es.indices_rejected.each
41
+ puts "indices_affected:"
42
+ @es.indices_affected.each { |k,v| puts "\t#{k}=#{v}" }
43
+ puts "indices: #{@es.indices.inspect}"
44
+ # verify bloom filter was disabled:
45
+ @es.indices_withered.each do |k,v|
46
+ @es.get_settings_index(k)
47
+ puts "\tverifying index '#{k}' is withered"
48
+ puts "\terrors=#{@es.errors.inspect}"
49
+ puts "\tresults=#{@es.results.inspect}"
50
+ end
51
+ puts "#{Time.now.utc} EsWither::wither_old_indices: finished in #{Time.now.utc - start_time} secs"
52
+ end
53
+ end
data/lib/elasticshelf.rb CHANGED
@@ -75,8 +75,11 @@ module Elasticshelf
75
75
  end
76
76
 
77
77
  def index_closed?(index_name)
78
- index_metadata = @client.cluster.state(:index => index_name, :metric => 'metadata')
79
- index_metadata['metadata']['indices'][index_name]['state'] == 'close'
78
+ # catch exceptions when index doesn't exist
79
+ try do
80
+ index_metadata = @client.cluster.state(:index => index_name, :metric => 'metadata')
81
+ index_metadata['metadata']['indices'][index_name]['state'] == 'close'
82
+ end
80
83
  end
81
84
 
82
85
  def open_index(index_name)
@@ -120,7 +123,9 @@ module Elasticshelf
120
123
 
121
124
  def get_settings_index(index_name)
122
125
  reset_errors_results
123
- @results[index_name] = @client.indices.get_settings(:index => index_name)
126
+ try do
127
+ @results[index_name] = @client.indices.get_settings(:index => index_name)
128
+ end
124
129
  end
125
130
 
126
131
  def wither_index(index_name)
@@ -145,13 +150,17 @@ module Elasticshelf
145
150
  end
146
151
 
147
152
  def get_index_state(index_name, metric='metadata')
148
- index_metadata = @client.cluster.state(:index => index_name, :metric => metric)
149
- index_metadata['metadata']['indices'][index_name]['state']
153
+ try do
154
+ index_metadata = @client.cluster.state(:index => index_name, :metric => metric)
155
+ index_metadata['metadata']['indices'][index_name]['state']
156
+ end
150
157
  end
151
158
 
152
159
  def get_cluster_state(index_name, metric='metadata')
153
- index_metadata = @client.cluster.state(:index => index_name, :metric => metric)
154
- index_metadata
160
+ try do
161
+ index_metadata = @client.cluster.state(:index => index_name, :metric => metric)
162
+ index_metadata
163
+ end
155
164
  end
156
165
 
157
166
  def snapshot_create_repository
@@ -1,4 +1,4 @@
1
1
  module Elasticshelf
2
2
  # Elasticshelf::VERSION
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticshelf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - cLee Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-03 00:00:00.000000000 Z
11
+ date: 2014-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: elasticsearch