dynport_tools 0.2.20 → 0.2.21
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/dynport_tools.gemspec +2 -1
- data/lib/dynport_tools/services.rb +25 -0
- data/spec/dynport_tools/services_spec.rb +85 -6
- data/spec/fixtures/solr_admin.html +29 -0
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.21
|
data/dynport_tools.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "dynport_tools"
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.21"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tobias Schwab"]
|
@@ -67,6 +67,7 @@ Gem::Specification.new do |s|
|
|
67
67
|
"spec/dynport_tools_spec.rb",
|
68
68
|
"spec/fixtures/file_a.xml",
|
69
69
|
"spec/fixtures/jenkins_job.xml",
|
70
|
+
"spec/fixtures/solr_admin.html",
|
70
71
|
"spec/spec_helper.rb",
|
71
72
|
"spec/xml_diff_spec.rb"
|
72
73
|
]
|
@@ -23,10 +23,20 @@ class DynportTools::Services
|
|
23
23
|
"#{solr_data_root}/solr.xml"
|
24
24
|
end
|
25
25
|
|
26
|
+
def solr_core_names
|
27
|
+
get(solr_url).to_s.scan(/a href=\"(.*?)\/admin/).flatten
|
28
|
+
end
|
29
|
+
|
26
30
|
def solr_bootstrapped?
|
27
31
|
File.exists?(solr_xml_path)
|
28
32
|
end
|
29
33
|
|
34
|
+
def start_solr
|
35
|
+
raise "solr already running" if solr_running?
|
36
|
+
raise "solr must be bootstrapped first" if !solr_bootstrapped?
|
37
|
+
exec "solr #{solr_data_root} > #{solr_data_root}/solr.log 2>&1 &"
|
38
|
+
end
|
39
|
+
|
30
40
|
def bootstrap_solr
|
31
41
|
raise "#{solr_xml_path} already exists" if solr_bootstrapped?
|
32
42
|
write_solr_xml_when_possible
|
@@ -49,6 +59,10 @@ class DynportTools::Services
|
|
49
59
|
end
|
50
60
|
end
|
51
61
|
|
62
|
+
def get(url)
|
63
|
+
system_call(%(curl -s "#{url}"))
|
64
|
+
end
|
65
|
+
|
52
66
|
def post(url)
|
53
67
|
system_call(%(curl -s -I -XPOST "#{url}"))
|
54
68
|
end
|
@@ -75,6 +89,17 @@ class DynportTools::Services
|
|
75
89
|
post("#{solr_url}admin/cores?action=UNLOAD&core=#{core_name}")
|
76
90
|
end
|
77
91
|
|
92
|
+
def reload_all_solr_cores
|
93
|
+
solr_core_names.each do |core_name|
|
94
|
+
reload_solr_core(core_name)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def reload_solr_core(core_name)
|
99
|
+
post("#{solr_url}admin/cores?action=RELOAD&core=#{core_name}")
|
100
|
+
end
|
101
|
+
|
102
|
+
|
78
103
|
# redis
|
79
104
|
attr_writer :redis_path_prefix, :redis_config_path, :redis_config_hash
|
80
105
|
|
@@ -1,11 +1,13 @@
|
|
1
1
|
$:<<File.expand_path("../../../", __FILE__)
|
2
2
|
require "dynport_tools"
|
3
3
|
require "dynport_tools/services"
|
4
|
+
require "spec_helper"
|
4
5
|
|
5
6
|
describe "Services" do
|
6
7
|
let(:services) { DynportTools::Services.new }
|
7
8
|
before(:each) do
|
8
9
|
services.stub(:system_call).and_raise("stub me")
|
10
|
+
services.stub!(:exec).and_raise("stub me")
|
9
11
|
end
|
10
12
|
|
11
13
|
it "can be initialized" do
|
@@ -31,11 +33,60 @@ describe "Services" do
|
|
31
33
|
FileUtils.rm_rf(tmp_path)
|
32
34
|
end
|
33
35
|
|
34
|
-
|
36
|
+
before(:each) do
|
37
|
+
services.solr_data_root = tmp_path
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#start_solr" do
|
41
|
+
before(:each) do
|
42
|
+
FileUtils.mkdir_p(tmp_path)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "raises an error when running" do
|
46
|
+
services.stub!(:solr_running?).and_return true
|
47
|
+
lambda {
|
48
|
+
services.start_solr
|
49
|
+
}.should raise_error("solr already running")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "raises an error when not bootstrapped" do
|
53
|
+
services.stub!(:solr_running?).and_return false
|
54
|
+
services.stub!(:solr_bootstrapped?).and_return false
|
55
|
+
lambda {
|
56
|
+
services.start_solr
|
57
|
+
}.should raise_error("solr must be bootstrapped first")
|
58
|
+
end
|
59
|
+
|
60
|
+
it "executes the correct system call" do
|
61
|
+
services.stub!(:solr_running?).and_return false
|
62
|
+
services.stub!(:solr_bootstrapped?).and_return true
|
63
|
+
services.unstub(:exec)
|
64
|
+
services.should_receive(:exec).with("solr #{tmp_path} > #{tmp_path}/solr.log 2>&1 &")
|
65
|
+
services.start_solr
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#solr_core_names" do
|
35
70
|
before(:each) do
|
36
|
-
services.
|
71
|
+
services.stub!(:get).and_return("")
|
37
72
|
end
|
38
73
|
|
74
|
+
it "returns an array" do
|
75
|
+
services.solr_core_names.should be_kind_of(Array)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "calls the correct url" do
|
79
|
+
services.should_receive(:get).with("http://localhost:8983/solr/").and_return ""
|
80
|
+
services.solr_core_names
|
81
|
+
end
|
82
|
+
|
83
|
+
it "returns the cirrect core_names" do
|
84
|
+
services.stub!(:get).and_return(File.read(root.join("spec/fixtures/solr_admin.html")))
|
85
|
+
services.solr_core_names.should == %w(test supernova_test some_other)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#solr_bootstrapped?" do
|
39
90
|
it "returns false by default" do
|
40
91
|
services.should_not be_solr_bootstrapped
|
41
92
|
end
|
@@ -48,10 +99,6 @@ describe "Services" do
|
|
48
99
|
end
|
49
100
|
|
50
101
|
describe "bootstrap_solr" do
|
51
|
-
before(:each) do
|
52
|
-
services.solr_data_root = tmp_path
|
53
|
-
end
|
54
|
-
|
55
102
|
it "raises an error when dir not exists" do
|
56
103
|
lambda {
|
57
104
|
services.bootstrap_solr
|
@@ -148,6 +195,26 @@ describe "Services" do
|
|
148
195
|
services.unload_solr_core("core_to_unload")
|
149
196
|
end
|
150
197
|
end
|
198
|
+
|
199
|
+
describe "#reload_solr_core" do
|
200
|
+
it "calls the correct post method (haha, post)" do
|
201
|
+
services.solr_url = "http://some.host:8080/solr/"
|
202
|
+
url = "http://some.host:8080/solr/admin/cores?action=RELOAD&core=core_to_unload"
|
203
|
+
services.should_receive(:post).with(url)
|
204
|
+
services.reload_solr_core("core_to_unload")
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "#reload_all_solr_cores" do
|
209
|
+
it "calls reload_solr_core with all core_names" do
|
210
|
+
services.stub!(:solr_core_names).and_return(%w(b d f))
|
211
|
+
services.should_receive(:reload_solr_core).with("b")
|
212
|
+
services.should_receive(:reload_solr_core).with("d")
|
213
|
+
services.should_receive(:reload_solr_core).with("f")
|
214
|
+
services.reload_all_solr_cores
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
151
218
|
end
|
152
219
|
|
153
220
|
describe "redis" do
|
@@ -273,6 +340,7 @@ describe "Services" do
|
|
273
340
|
|
274
341
|
describe "http methods" do
|
275
342
|
let(:url) { "http://www.some.host:1234/path" }
|
343
|
+
|
276
344
|
describe "#head" do
|
277
345
|
before(:each) do
|
278
346
|
services.unstub(:system_call)
|
@@ -289,6 +357,17 @@ describe "Services" do
|
|
289
357
|
end
|
290
358
|
end
|
291
359
|
|
360
|
+
describe "#get" do
|
361
|
+
before(:each) do
|
362
|
+
services.unstub(:system_call)
|
363
|
+
end
|
364
|
+
|
365
|
+
it "executes the correct system call" do
|
366
|
+
services.should_receive(:system_call).with(%(curl -s "#{url}")).and_return("response body")
|
367
|
+
services.get(url).should == "response body"
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
292
371
|
describe "#post" do
|
293
372
|
before(:each) do
|
294
373
|
services.unstub(:system_call)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<link rel="stylesheet" type="text/css" href="solr-admin.css">
|
9
|
+
<link rel="icon" href="favicon.ico" type="image/ico"></link>
|
10
|
+
<link rel="shortcut icon" href="favicon.ico" type="image/ico"></link>
|
11
|
+
<title>Welcome to Solr</title>
|
12
|
+
</head>
|
13
|
+
|
14
|
+
<body>
|
15
|
+
<h1>Welcome to Solr!</h1>
|
16
|
+
<a href="."><img border="0" align="right" height="78" width="142" src="admin/solr_small.png" alt="Solr"/></a>
|
17
|
+
|
18
|
+
<a href="test/admin/">Admin test</a>
|
19
|
+
<br/>
|
20
|
+
|
21
|
+
<a href="supernova_test/admin/">Admin supernova_test</a>
|
22
|
+
<br/>
|
23
|
+
|
24
|
+
<a href="some_other/admin/">Admin some_other</a>
|
25
|
+
<br/>
|
26
|
+
|
27
|
+
|
28
|
+
</body>
|
29
|
+
</html>
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynport_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 61
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 21
|
10
|
+
version: 0.2.21
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tobias Schwab
|
@@ -337,6 +337,7 @@ files:
|
|
337
337
|
- spec/dynport_tools_spec.rb
|
338
338
|
- spec/fixtures/file_a.xml
|
339
339
|
- spec/fixtures/jenkins_job.xml
|
340
|
+
- spec/fixtures/solr_admin.html
|
340
341
|
- spec/spec_helper.rb
|
341
342
|
- spec/xml_diff_spec.rb
|
342
343
|
homepage: http://github.com/tobstarr/dynport_tools
|