desi 0.6.9 → 0.7.0

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: ca6a85c9fea92581a05bf10fa46540fbb77458fe
4
- data.tar.gz: 55517b9b24c7e2965e9ab78b03b43a4582f841f6
3
+ metadata.gz: 1a904d5f9b8c7b6a47443b5604430e886677404c
4
+ data.tar.gz: 925618b93f68d4f8a1a04d71804a2ceea4872a99
5
5
  SHA512:
6
- metadata.gz: 0a6c23cda7bc27a2cb405051c371d437acdb5a99f2d57a25ffeda9024175cd14ef7f4bd489d8beb0532f4d4190e7cad22d6f0df914dddb44ade39abcbefb952e
7
- data.tar.gz: c8fbbb9c547362f1a13512f366b254b850d573dde67b3ee70d03febbc755c7f3d4c8dda638565741299647f59c081e2541071b599c2be861f0ac0d612758c2f5
6
+ metadata.gz: cd305555d76f562c53990742890c322dd43a8269f2dbba816a1c796dd11160156a4b45dcbe9c13a033c454c4857871ccaf9b45d019a696886daec613e5d8dad5
7
+ data.tar.gz: 41bafd0856752105569549bb1e838342629f56afa7cb5470041c06af5de4585228fcd04b78662e343d3384ac157c9e85c3292d2d962beffaf3c30c26e606da57
data/README.md CHANGED
@@ -26,9 +26,12 @@ It can be used both as a command-line tool and as a library.
26
26
  $ desi stop # Stop cluster
27
27
  $ desi status [--host HOST] # Show running cluster info
28
28
  $ desi tail # Show tail output from Elastic Search's log file
29
+ $ desi current # Show current version
30
+ $ desi current [VERSION] # Change the symlink pointing to current version
29
31
 
30
32
  $ desi indices "^foo" # List all indices whose name match /^foo/
31
33
  $ desi indices "^foo" --delete # Delete all matching indices
34
+ $ desi indices "^foo" --close # Delete all matching indices
32
35
  $ desi indices "bar$" --empty # Remove all records from the matching indices
33
36
 
34
37
  ## Examples (command-line and Ruby)
@@ -38,6 +38,17 @@ module Desi
38
38
  end
39
39
  end
40
40
 
41
+ def post(uri)
42
+ response = @http.request(Net::HTTP::Post.new(uri))
43
+
44
+ case response
45
+ when Net::HTTPSuccess
46
+ response
47
+ else
48
+ raise response.error!
49
+ end
50
+ end
51
+
41
52
  def delete(uri)
42
53
  response = @http.request(Net::HTTP::Delete.new(uri))
43
54
 
@@ -132,6 +132,31 @@ module Desi
132
132
  end
133
133
  end
134
134
 
135
+ # Close all indices matching the specified pattern
136
+ #
137
+ # @param [#to_s] pattern Regexp pattern used to restrict the selection
138
+ # @return [void]
139
+ #
140
+ # @note No confirmation is needed, so beware!
141
+ #
142
+ # @note This method will also output its result on STDOUT if +@verbose+ is
143
+ # true
144
+ #
145
+ # @example Close all indices whose name begins with "test"
146
+ # Desi::IndexManager.new.close!('^test') #=> nil
147
+ #
148
+ # @api public
149
+ def close!(pattern)
150
+ warn "You must provide a pattern" and exit if pattern.nil?
151
+
152
+ @outputter.puts "The following indices from host #{@host} are now closed" if @verbose
153
+
154
+ indices(Regexp.new(pattern)).each do |index|
155
+ @client.post("/#{index}/_close")
156
+ @outputter.puts " * #{index.inspect}" if @verbose
157
+ end
158
+ end
159
+
135
160
  # Empty (remove all records) from indices matching the specified pattern
136
161
  #
137
162
  # @param [#to_s] pattern Regexp pattern used to restrict the selection
@@ -15,7 +15,7 @@ module Desi
15
15
  def install!
16
16
  extract! unless extracted?
17
17
  install_config_file
18
- update_symlink!
18
+ update_symlinks!
19
19
  remove_archive!
20
20
  end
21
21
 
@@ -32,8 +32,10 @@ module Desi
32
32
  end
33
33
 
34
34
 
35
- def update_symlink!
36
- @local_install.update_current_to(release_dir)
35
+ def update_symlinks!
36
+ @local_install.
37
+ update_current_to(release_dir).
38
+ add_data_symlink(release_dir)
37
39
  end
38
40
 
39
41
  def config_file
@@ -0,0 +1,78 @@
1
+ # encoding: utf-8
2
+
3
+ require "pathname"
4
+ require "semantic"
5
+
6
+ module Desi
7
+ class LocalInstall
8
+
9
+ class Release
10
+ def self.all_in(workdir)
11
+ Dir[workdir.join('*')].
12
+ select {|subdir| File.directory?(subdir) && File.basename(subdir) =~ /^elasticsearch\-\d+\.\d+\.\d+/ }.
13
+ map {|dirname| new(dirname, workdir) }
14
+ end
15
+
16
+ def initialize(dirname, workdir)
17
+ @dirname = Pathname.new(dirname)
18
+ @workdir = workdir
19
+ end
20
+
21
+ def name
22
+ @name ||= File.basename(@dirname)
23
+ end
24
+
25
+ def current?
26
+ current_symlink? && current_symlink.realpath == @dirname
27
+ end
28
+
29
+ def version
30
+ @version ||= Semantic::Version.new(version_number)
31
+ end
32
+
33
+ def with_version?(other_version)
34
+ version == Semantic::Version.new(other_version)
35
+ end
36
+
37
+ def to_s
38
+ current_mark = current? ? '*' : '-'
39
+
40
+ " #{current_mark} #{name} (#{@dirname})"
41
+ end
42
+
43
+ def ==(other)
44
+ other.version.to_s == version.to_s
45
+ end
46
+
47
+ def <=>(other)
48
+ name <=> other.name
49
+ end
50
+
51
+ def pre_one_zero?
52
+ @pre_one_zero ||= (version < Semantic::Version.new("1.0.0-alpha"))
53
+ end
54
+
55
+ def to_path
56
+ @dirname.to_path
57
+ end
58
+
59
+ private
60
+
61
+ def current_symlink
62
+ @current_symlink ||= Pathname(@workdir).join('current')
63
+ end
64
+
65
+ def current_symlink?
66
+ current_symlink.exist?
67
+ end
68
+
69
+ # Ugly hack to get around elasticsearch's flakey semver naming
70
+ # (e.g. `1.4.0.Beta1` instead of `1.4.0-beta1`)
71
+ def version_number
72
+ /^elasticsearch\-(?<version>.*)$/.match(name.to_s)[:version].
73
+ sub(/\.(alpha|beta)/i, '-\1')
74
+ end
75
+ end # Release
76
+
77
+ end
78
+ end
@@ -1,71 +1,10 @@
1
1
  # encoding: utf-8
2
2
 
3
- require "pathname"
4
- require "semantic"
3
+ require_relative "local_install/release"
5
4
 
6
5
  module Desi
7
6
  class LocalInstall
8
7
 
9
- class Release
10
- def self.all_in(workdir)
11
- Dir[workdir.join('*')].
12
- select {|subdir| File.directory?(subdir) && File.basename(subdir) =~ /^elasticsearch\-\d+\.\d+\.\d+/ }.
13
- map {|dirname| new(dirname, workdir) }
14
- end
15
-
16
- def initialize(dirname, workdir)
17
- @dirname = Pathname.new(dirname)
18
- @workdir = workdir
19
- end
20
-
21
- def name
22
- @name ||= File.basename(@dirname)
23
- end
24
-
25
- def current?
26
- current_symlink? && current_symlink.realpath == @dirname
27
- end
28
-
29
- def version
30
- @version ||= Semantic::Version.new(version_number)
31
- end
32
-
33
- def to_s
34
- current_mark = current? ? '*' : '-'
35
-
36
- " #{current_mark} #{name} (#{@dirname})"
37
- end
38
-
39
- def ==(other)
40
- other.version.to_s == version.to_s
41
- end
42
-
43
- def <=>(other)
44
- name <=> other.name
45
- end
46
-
47
- def pre_one_zero?
48
- @pre_one_zero ||= (version < Semantic::Version.new("1.0.0-alpha"))
49
- end
50
-
51
- private
52
-
53
- def current_symlink
54
- @current_symlink ||= Pathname(@workdir).join('current')
55
- end
56
-
57
- def current_symlink?
58
- current_symlink.exist?
59
- end
60
-
61
- # Ugly hack to get around elasticsearch's flakey semver naming
62
- # (e.g. `1.4.0.Beta1` instead of `1.4.0-beta1`)
63
- def version_number
64
- /^elasticsearch\-(?<version>.*)$/.match(name.to_s)[:version].
65
- sub(/\.(alpha|beta)/i, '-\1')
66
- end
67
- end # Release
68
-
69
8
  def self.current_release_is_pre_one_zero?
70
9
  current = new.current_release
71
10
  current && current.pre_one_zero?
@@ -82,7 +21,7 @@ module Desi
82
21
  end
83
22
 
84
23
  def current_dir
85
- @workdir.join('current')
24
+ @current_dir ||= @workdir.join('current')
86
25
  end
87
26
 
88
27
  def update_current_to(release_dir)
@@ -91,6 +30,15 @@ module Desi
91
30
  puts " * Updating #{current_dir} symlink" if @verbose
92
31
  FileUtils.remove(current_dir) if current_dir.exist?
93
32
  FileUtils.ln_sf(release_dir, current_dir)
33
+ self
34
+ end
35
+
36
+ def add_data_symlink(release_dir)
37
+ current_dir_must_be_nil_or_symlink!
38
+ symlink = current_dir.join('data')
39
+ puts " * Updating data dir symlink (#{symlink} -> #{data_dir})" if @verbose
40
+ FileUtils.ln_sf(data_dir, symlink)
41
+ self
94
42
  end
95
43
 
96
44
  def create!
@@ -109,6 +57,10 @@ module Desi
109
57
  @workdir.to_s
110
58
  end
111
59
 
60
+ def data_dir
61
+ @data_dir ||= @workdir.join('data')
62
+ end
63
+
112
64
  def to_s
113
65
  to_path
114
66
  end
data/lib/desi/runner.rb CHANGED
@@ -54,6 +54,11 @@ module Desi
54
54
  Desi::Upstream.new.latest_release
55
55
  end
56
56
 
57
+ unless release
58
+ warn "Could not find release '#{version_or_full_name}'"
59
+ exit 1
60
+ end
61
+
57
62
  if Desi::LocalInstall.new.releases.any? {|r| r == release }
58
63
  puts " * release #{release.version} seems to be already installed" if options[:verbose]
59
64
  return
@@ -65,6 +70,27 @@ module Desi
65
70
  puts " * #{release} installed" if Desi::Installer.new(package).install! && options[:verbose]
66
71
  end
67
72
 
73
+
74
+ desc "Show or set the current version"
75
+ verbosity_option
76
+ def current(version = nil, options = {})
77
+ set_verbosity!(options)
78
+ local_install = Desi::LocalInstall.new
79
+
80
+ if version
81
+ dir = local_install.releases.find {|d| d.with_version?(version) }
82
+
83
+ unless dir
84
+ warn "Cannot find locale install of version #{version}"
85
+ exit 1
86
+ end
87
+ local_install.update_current_to(dir)
88
+ puts "Set current version to #{dir.version} (#{dir.to_path})" if options[:verbose]
89
+ else
90
+ puts local_install.current_release
91
+ end
92
+ end
93
+
68
94
  desc "Start Elastic Search (do nothing if already active)"
69
95
  verbosity_option
70
96
  start_options
@@ -100,6 +126,7 @@ module Desi
100
126
  verbosity_option
101
127
  option "--host", type: :string, desc: "Elastic Search cluster URL", default: Desi.configuration.server
102
128
  option "--delete", type: :boolean, desc: "Delete the specified indices (You've been warned!)", default: false
129
+ option "--close", type: :boolean, desc: "Close specified indices", default: false
103
130
  option "--empty", type: :boolean, desc: "Delete all documents from the specified indices", default: false
104
131
  def indices(pattern = nil, options = {})
105
132
  set_verbosity!(options)
@@ -107,6 +134,8 @@ module Desi
107
134
 
108
135
  if options[:delete]
109
136
  index_manager.delete!(pattern)
137
+ elsif options[:close]
138
+ index_manager.close!(pattern)
110
139
  elsif options[:empty]
111
140
  index_manager.empty!(pattern)
112
141
  else
data/lib/desi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Desi
2
- VERSION = "0.6.9"
2
+ VERSION = "0.7.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: desi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.9
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominique Rose-Rosette
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-06 00:00:00.000000000 Z
11
+ date: 2015-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: boson
@@ -194,6 +194,7 @@ files:
194
194
  - lib/desi/index_manager.rb
195
195
  - lib/desi/installer.rb
196
196
  - lib/desi/local_install.rb
197
+ - lib/desi/local_install/release.rb
197
198
  - lib/desi/process_manager.rb
198
199
  - lib/desi/runner.rb
199
200
  - lib/desi/upstream.rb