fcrepo_wrapper 0.1.1 → 0.2.0
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.
- checksums.yaml +4 -4
- data/data/spring-noop.xml +11 -0
- data/exe/fcrepo_wrapper +29 -6
- data/lib/fcrepo_wrapper/instance.rb +218 -39
- data/lib/fcrepo_wrapper/rake_task.rb +5 -0
- data/lib/fcrepo_wrapper/tasks/fcrepo_wrapper.rake +45 -0
- data/lib/fcrepo_wrapper/version.rb +1 -1
- data/lib/fcrepo_wrapper.rb +13 -2
- metadata +5 -3
- data/lib/service_instance.rb +0 -134
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a144f4c282130ef794aacb6218cf8134b563c8ef
|
|
4
|
+
data.tar.gz: 49d5805fc67970698545245d9707a832e5f5c57b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1514aa19a011b30e50864ca5d00cd3d493b5a4297fd066ce1eccec5c6843061ac62fe76046f6e7c4ce365f909d3818671efb2dccd0df9610eef1c828384de2af
|
|
7
|
+
data.tar.gz: e13cda2c8ca4211ab18bb3e1c4515c66fd533140c03a2d6cf9494e3f09ffaec4640abe07add3ef69e54377b90db7e57922e0ebecd4632bc14b919e471c87cb06
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
3
|
+
xmlns:context="http://www.springframework.org/schema/context"
|
|
4
|
+
xmlns:p="http://www.springframework.org/schema/p"
|
|
5
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
6
|
+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
|
7
|
+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
|
8
|
+
|
|
9
|
+
<context:annotation-config/>
|
|
10
|
+
|
|
11
|
+
</beans>
|
data/exe/fcrepo_wrapper
CHANGED
|
@@ -4,7 +4,7 @@ require 'fcrepo_wrapper'
|
|
|
4
4
|
require 'optparse'
|
|
5
5
|
|
|
6
6
|
options = {}
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
OptionParser.new do |opts|
|
|
9
9
|
opts.banner = "Usage: fcrepo_wrapper [options]"
|
|
10
10
|
|
|
@@ -12,20 +12,43 @@ OptionParser.new do |opts|
|
|
|
12
12
|
options[:verbose] = v
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
opts.on("--[no-]jms", "Run without JMS") do |v|
|
|
16
|
+
options[:enable_jms] = v
|
|
17
|
+
end
|
|
18
|
+
|
|
15
19
|
opts.on("--version VERSION", "Specify a fcrepo version to download (default: #{FcrepoWrapper.default_fcrepo_version})") do |v|
|
|
16
20
|
options[:version] = v
|
|
17
21
|
end
|
|
18
22
|
|
|
19
|
-
opts.on("-pPORT", "--port PORT", "Specify the port fcrepo should run at (default:
|
|
20
|
-
|
|
23
|
+
opts.on("-pPORT", "--port PORT", "Specify the port fcrepo should run at (default: 8983)") do |p|
|
|
24
|
+
if p == 'random'
|
|
25
|
+
options[:port] = nil
|
|
26
|
+
else
|
|
27
|
+
options[:port] = p
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
opts.on("-iDIR", "--instance_directory DIR", "Install/use fcrepo jar at the given directory") do |d|
|
|
32
|
+
options[:instance_dir] = d
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
opts.on("-dDIR", "--fcrepo_home DIR", "Store fcrepo at the given directory") do |d|
|
|
36
|
+
options[:fcrepo_home_dir] = d
|
|
21
37
|
end
|
|
22
38
|
end.parse!
|
|
23
39
|
|
|
24
40
|
# default to verbose
|
|
25
41
|
options[:verbose] = true if options[:verbose].nil?
|
|
26
42
|
|
|
27
|
-
FcrepoWrapper.
|
|
28
|
-
|
|
29
|
-
|
|
43
|
+
instance = FcrepoWrapper.default_instance(options)
|
|
44
|
+
$stderr.print "Starting Fedora #{instance.version} on port #{instance.port} ... "
|
|
45
|
+
instance.wrap do |conn|
|
|
46
|
+
$stderr.puts "http://#{instance.host}:#{instance.port}/"
|
|
47
|
+
begin
|
|
48
|
+
while conn.status
|
|
49
|
+
sleep 1
|
|
50
|
+
end
|
|
51
|
+
rescue Interrupt
|
|
52
|
+
$stderr.puts "Fedora is shutting down."
|
|
30
53
|
end
|
|
31
54
|
end
|
|
@@ -1,31 +1,30 @@
|
|
|
1
1
|
require 'digest'
|
|
2
2
|
require 'fileutils'
|
|
3
|
+
require 'json'
|
|
3
4
|
require 'open-uri'
|
|
4
5
|
require 'ruby-progressbar'
|
|
5
6
|
require 'securerandom'
|
|
7
|
+
require 'socket'
|
|
6
8
|
require 'stringio'
|
|
7
9
|
require 'tmpdir'
|
|
8
|
-
require 'service_instance'
|
|
9
10
|
|
|
10
11
|
module FcrepoWrapper
|
|
11
12
|
class Instance
|
|
12
|
-
include ServiceInstance
|
|
13
13
|
attr_reader :options, :pid
|
|
14
14
|
|
|
15
15
|
##
|
|
16
16
|
# @param [Hash] options
|
|
17
17
|
# @option options [String] :url
|
|
18
|
-
# @option options [String] :
|
|
19
|
-
# @option options [String] :
|
|
20
|
-
# @option options [String] :
|
|
21
|
-
# @option options [String] :
|
|
22
|
-
# @option options [String] :download_path
|
|
23
|
-
# @option options [String] :
|
|
24
|
-
# @option options [
|
|
25
|
-
# @option options [
|
|
26
|
-
# @option options [Boolean] :
|
|
18
|
+
# @option options [String] :instance_dir Directory to store the fcrepo index files
|
|
19
|
+
# @option options [String] :version Fcrepo version to download and install
|
|
20
|
+
# @option options [String] :port port to run fcrepo on
|
|
21
|
+
# @option options [String] :version_file Local path to store the currently installed version
|
|
22
|
+
# @option options [String] :download_dir Local directory to store the downloaded fcrepo jar and its md5 file in (overridden by :download_path)
|
|
23
|
+
# @option options [String] :download_path Local path for storing the downloaded fcrepo jar file
|
|
24
|
+
# @option options [Boolean] :validate Should fcrepo_wrapper download a new md5 and (re-)validate the zip file? (default: trueF)
|
|
25
|
+
# @option options [String] :md5sum Path/URL to MD5 checksum
|
|
26
|
+
# @option options [Boolean] :verbose return verbose info when running fcrepo commands
|
|
27
27
|
# @option options [Boolean] :ignore_md5sum
|
|
28
|
-
# @option options [Array<String>] :java_options a list of options to pass to the JVM
|
|
29
28
|
# @option options [Hash] :fcrepo_options
|
|
30
29
|
# @option options [Hash] :env
|
|
31
30
|
def initialize(options = {})
|
|
@@ -33,6 +32,7 @@ module FcrepoWrapper
|
|
|
33
32
|
end
|
|
34
33
|
|
|
35
34
|
def wrap(&_block)
|
|
35
|
+
extract_and_configure
|
|
36
36
|
start
|
|
37
37
|
yield self
|
|
38
38
|
ensure
|
|
@@ -50,7 +50,14 @@ module FcrepoWrapper
|
|
|
50
50
|
# info:fedora/fedora-system:def/relations-external#isPartOf
|
|
51
51
|
# was possibly misinterpreted as:
|
|
52
52
|
# info:fedora/fedora-system:def/relations-external#."
|
|
53
|
-
'-Dfcrepo.log.kernel=ERROR'
|
|
53
|
+
'-Dfcrepo.log.kernel=ERROR',
|
|
54
|
+
("-Dfcrepo.home=#{fcrepo_home_dir}" if fcrepo_home_dir),
|
|
55
|
+
("-Dfcrepo.spring.jms.configuration=#{spring_noop_file}" unless jms_enabled?),
|
|
56
|
+
'-Xmx512m'].compact
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def fcrepo_home_dir
|
|
60
|
+
options[:fcrepo_home_dir]
|
|
54
61
|
end
|
|
55
62
|
|
|
56
63
|
def process_arguments
|
|
@@ -60,15 +67,14 @@ module FcrepoWrapper
|
|
|
60
67
|
end
|
|
61
68
|
|
|
62
69
|
##
|
|
63
|
-
# Start
|
|
70
|
+
# Start fcrepo and wait for it to become available
|
|
64
71
|
def start
|
|
65
|
-
|
|
72
|
+
extract_and_configure
|
|
66
73
|
if managed?
|
|
67
|
-
|
|
68
74
|
@pid = spawn(env, *process_arguments)
|
|
69
75
|
|
|
70
76
|
# Wait for fcrepo to start
|
|
71
|
-
|
|
77
|
+
while !status
|
|
72
78
|
sleep 1
|
|
73
79
|
end
|
|
74
80
|
end
|
|
@@ -91,6 +97,15 @@ module FcrepoWrapper
|
|
|
91
97
|
@pid = nil
|
|
92
98
|
end
|
|
93
99
|
|
|
100
|
+
##
|
|
101
|
+
# Stop fcrepo and wait for it to finish exiting
|
|
102
|
+
def restart
|
|
103
|
+
if managed? && started?
|
|
104
|
+
stop
|
|
105
|
+
start
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
94
109
|
##
|
|
95
110
|
# Check the status of a managed fcrepo service
|
|
96
111
|
def status
|
|
@@ -100,27 +115,126 @@ module FcrepoWrapper
|
|
|
100
115
|
begin
|
|
101
116
|
Process.getpgid(pid)
|
|
102
117
|
|
|
103
|
-
TCPSocket.new(
|
|
118
|
+
TCPSocket.new(host, port).close
|
|
119
|
+
|
|
120
|
+
Net::HTTP.start(host, port) do |http|
|
|
121
|
+
http.request(Net::HTTP::Get.new('/'))
|
|
122
|
+
end
|
|
123
|
+
|
|
104
124
|
true
|
|
105
125
|
rescue Errno::ESRCH, Errno::ECONNREFUSED
|
|
106
126
|
false
|
|
107
127
|
end
|
|
108
128
|
end
|
|
109
129
|
|
|
130
|
+
##
|
|
131
|
+
# Is fcrepo running?
|
|
132
|
+
def started?
|
|
133
|
+
!!status
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
##
|
|
137
|
+
# Get the host this fcrepo instance is bound to
|
|
138
|
+
def host
|
|
139
|
+
'127.0.0.1'
|
|
140
|
+
end
|
|
141
|
+
|
|
110
142
|
##
|
|
111
143
|
# Get the port this fcrepo instance is running at
|
|
112
144
|
def port
|
|
113
|
-
options
|
|
145
|
+
@port ||= options[:port]
|
|
146
|
+
@port ||= random_open_port.to_s
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
##
|
|
150
|
+
# Clean up any files fcrepo_wrapper may have downloaded
|
|
151
|
+
def clean!
|
|
152
|
+
stop
|
|
153
|
+
remove_instance_dir!
|
|
154
|
+
FileUtils.remove_entry(download_path) if File.exists?(download_path)
|
|
155
|
+
FileUtils.remove_entry(tmp_save_dir, true) if File.exists? tmp_save_dir
|
|
156
|
+
FileUtils.remove_entry(md5sum_path) if File.exists? md5sum_path
|
|
157
|
+
FileUtils.remove_entry(version_file) if File.exists? version_file
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
##
|
|
161
|
+
# Clean up any files in the fcrepo instance dir
|
|
162
|
+
def remove_instance_dir!
|
|
163
|
+
FileUtils.remove_entry(instance_dir, true) if File.exists? instance_dir
|
|
114
164
|
end
|
|
115
165
|
|
|
116
166
|
##
|
|
117
167
|
# Get a (likely) URL to the fcrepo instance
|
|
118
168
|
def url
|
|
119
|
-
"http
|
|
169
|
+
"http://#{host}:#{port}/"
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def configure
|
|
173
|
+
raise_error_unless_extracted
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def instance_dir
|
|
177
|
+
@instance_dir ||= options.fetch(:instance_dir, File.join(Dir.tmpdir, File.basename(download_url, ".jar")))
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def extract_and_configure
|
|
181
|
+
instance_dir = extract
|
|
182
|
+
configure
|
|
183
|
+
instance_dir
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# extract a copy of fcrepo to instance_dir
|
|
187
|
+
# Does noting if fcrepo already exists at instance_dir
|
|
188
|
+
# @return [String] instance_dir Directory where fcrepo has been installed
|
|
189
|
+
def extract
|
|
190
|
+
return instance_dir if extracted?
|
|
191
|
+
|
|
192
|
+
jar_file = download
|
|
193
|
+
|
|
194
|
+
FileUtils.mkdir_p instance_dir
|
|
195
|
+
FileUtils.cp jar_file, binary_path
|
|
196
|
+
self.extracted_version = version
|
|
197
|
+
|
|
198
|
+
instance_dir
|
|
199
|
+
end
|
|
200
|
+
# rubocop:enable Lint/RescueException
|
|
201
|
+
|
|
202
|
+
def version
|
|
203
|
+
@version ||= options.fetch(:version, FcrepoWrapper.default_fcrepo_version)
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
protected
|
|
207
|
+
|
|
208
|
+
def extracted?
|
|
209
|
+
File.exists?(binary_path) && extracted_version == version
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def download
|
|
213
|
+
unless File.exists?(download_path) && validate?(download_path)
|
|
214
|
+
fetch_with_progressbar download_url, download_path
|
|
215
|
+
validate! download_path
|
|
216
|
+
end
|
|
217
|
+
download_path
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def validate?(file)
|
|
221
|
+
return true if options[:validate] == false
|
|
222
|
+
|
|
223
|
+
Digest::MD5.file(file).hexdigest == expected_md5sum
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def validate!(file)
|
|
227
|
+
unless validate? file
|
|
228
|
+
raise "MD5 mismatch" unless options[:ignore_md5sum]
|
|
229
|
+
end
|
|
120
230
|
end
|
|
121
231
|
|
|
122
232
|
private
|
|
123
233
|
|
|
234
|
+
def download_url
|
|
235
|
+
@download_url ||= options.fetch(:url, default_download_url)
|
|
236
|
+
end
|
|
237
|
+
|
|
124
238
|
def default_download_url
|
|
125
239
|
@default_url ||= "https://github.com/fcrepo4/fcrepo4/releases/download/fcrepo-#{version}/fcrepo-webapp-#{version}-jetty-console.jar"
|
|
126
240
|
end
|
|
@@ -129,43 +243,108 @@ module FcrepoWrapper
|
|
|
129
243
|
"https://github.com/fcrepo4/fcrepo4/releases/download/fcrepo-#{version}/fcrepo-webapp-#{version}-jetty-console.jar.md5"
|
|
130
244
|
end
|
|
131
245
|
|
|
132
|
-
def version
|
|
133
|
-
@version ||= options.fetch(:version, default_fcrepo_version)
|
|
134
|
-
end
|
|
135
|
-
|
|
136
246
|
def fcrepo_options
|
|
137
247
|
options.fetch(:fcrepo_options, headless: nil)
|
|
138
248
|
end
|
|
139
249
|
|
|
140
|
-
def
|
|
141
|
-
|
|
250
|
+
def env
|
|
251
|
+
options.fetch(:env, {})
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def download_path
|
|
255
|
+
@download_path ||= options.fetch(:download_path, default_download_path)
|
|
142
256
|
end
|
|
143
257
|
|
|
144
|
-
def
|
|
145
|
-
File.join(
|
|
258
|
+
def default_download_path
|
|
259
|
+
File.join(download_dir, File.basename(download_url))
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
def download_dir
|
|
263
|
+
@download_dir ||= options.fetch(:download_dir, Dir.tmpdir)
|
|
264
|
+
FileUtils.mkdir_p @download_dir
|
|
265
|
+
@download_dir
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
def verbose?
|
|
269
|
+
!!options.fetch(:verbose, false)
|
|
146
270
|
end
|
|
147
271
|
|
|
148
272
|
def managed?
|
|
149
|
-
|
|
273
|
+
File.exists?(instance_dir)
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
def version_file
|
|
277
|
+
options.fetch(:version_file, File.join(instance_dir, "VERSION"))
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
def expected_md5sum
|
|
281
|
+
@md5sum ||= options.fetch(:md5sum, open(md5file).read.split(" ").first)
|
|
150
282
|
end
|
|
151
283
|
|
|
152
284
|
def binary_path
|
|
153
285
|
File.join(instance_dir, "fcrepo-webapp-#{version}-jetty-console.jar")
|
|
154
286
|
end
|
|
155
287
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
def extract
|
|
160
|
-
return instance_dir if extracted?
|
|
288
|
+
def md5sum_path
|
|
289
|
+
File.join(download_dir, File.basename(md5url))
|
|
290
|
+
end
|
|
161
291
|
|
|
162
|
-
|
|
292
|
+
def tmp_save_dir
|
|
293
|
+
@tmp_save_dir ||= Dir.mktmpdir
|
|
294
|
+
end
|
|
163
295
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
296
|
+
def fetch_with_progressbar(url, output)
|
|
297
|
+
pbar = ProgressBar.create(title: File.basename(url), total: nil, format: "%t: |%B| %p%% (%e )")
|
|
298
|
+
open(url, content_length_proc: lambda do|t|
|
|
299
|
+
if t && 0 < t
|
|
300
|
+
pbar.total = t
|
|
301
|
+
end
|
|
302
|
+
end,
|
|
303
|
+
progress_proc: lambda do|s|
|
|
304
|
+
pbar.progress = s
|
|
305
|
+
end) do |io|
|
|
306
|
+
IO.copy_stream(io, output)
|
|
307
|
+
end
|
|
308
|
+
end
|
|
167
309
|
|
|
168
|
-
|
|
310
|
+
def md5file
|
|
311
|
+
unless File.exists? md5sum_path
|
|
312
|
+
fetch_with_progressbar md5url, md5sum_path
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
md5sum_path
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
def extracted_version
|
|
319
|
+
File.read(version_file).strip if File.exists? version_file
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
def extracted_version=(version)
|
|
323
|
+
File.open(version_file, "w") do |f|
|
|
324
|
+
f.puts version
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
def random_open_port
|
|
329
|
+
socket = Socket.new(:INET, :STREAM, 0)
|
|
330
|
+
begin
|
|
331
|
+
socket.bind(Addrinfo.tcp('127.0.0.1', 0))
|
|
332
|
+
socket.local_address.ip_port
|
|
333
|
+
ensure
|
|
334
|
+
socket.close
|
|
335
|
+
end
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
def raise_error_unless_extracted
|
|
339
|
+
raise RuntimeError, "there is no fcrepo instance at #{instance_dir}. Run FcrepoWrapper.extract first." unless extracted?
|
|
340
|
+
end
|
|
341
|
+
|
|
342
|
+
def spring_noop_file
|
|
343
|
+
'file://' + File.expand_path('../../../data/spring-noop.xml', __FILE__)
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
def jms_enabled?
|
|
347
|
+
options.fetch(:enable_jms, true)
|
|
169
348
|
end
|
|
170
349
|
end
|
|
171
350
|
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'fcrepo_wrapper'
|
|
2
|
+
|
|
3
|
+
## These tasks get loaded into the host context when fcrepo_wrapper is required
|
|
4
|
+
namespace :fcrepo do
|
|
5
|
+
desc "Load the fcrepo options and fcrepo instance"
|
|
6
|
+
task :environment do
|
|
7
|
+
FcrepoWrapper.default_instance_options[:download_dir] ||= Rails.root.to_s + '/tmp' if defined? Rails
|
|
8
|
+
@fcrepo_instance = FcrepoWrapper.default_instance
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
desc 'Install a clean version of fcrepo. Replaces the existing copy if there is one.'
|
|
12
|
+
task clean: :environment do
|
|
13
|
+
puts "Installing clean version of fcrepo at #{File.expand_path(@fcrepo_instance.instance_dir)}"
|
|
14
|
+
@fcrepo_instance.remove_instance_dir!
|
|
15
|
+
@fcrepo_instance.extract_and_configure
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
desc 'start fcrepo'
|
|
19
|
+
task start: :environment do
|
|
20
|
+
begin
|
|
21
|
+
puts "Starting fcrepo at #{File.expand_path(@fcrepo_instance.instance_dir)} with options #{@fcrepo_instance.options}"
|
|
22
|
+
@fcrepo_instance.start
|
|
23
|
+
rescue => e
|
|
24
|
+
if e.message.include?("Port #{@fcrepo_instance.port} is already being used by another process")
|
|
25
|
+
puts "FAILED. Port #{@fcrepo_instance.port} is already being used."
|
|
26
|
+
puts " Did you already have fcrepo running?"
|
|
27
|
+
puts " a) YES: Continue as you were. fcrepo is running."
|
|
28
|
+
puts " b) NO: Either set FCREPO_OPTIONS[:port] to a different value or stop the process that's using port #{@fcrepo_instance.port}."
|
|
29
|
+
else
|
|
30
|
+
raise "Failed to start fcrepo. #{e.class}: #{e.message}"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
desc 'restart fcrepo'
|
|
36
|
+
task restart: :environment do
|
|
37
|
+
puts "Restarting fcrepo"
|
|
38
|
+
@fcrepo_instance.restart
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
desc 'stop fcrepo'
|
|
42
|
+
task stop: :environment do
|
|
43
|
+
@fcrepo_instance.stop
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/fcrepo_wrapper.rb
CHANGED
|
@@ -6,12 +6,23 @@ module FcrepoWrapper
|
|
|
6
6
|
'4.5.0'
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
+
def self.default_instance_options
|
|
10
|
+
@default_instance_options ||= {
|
|
11
|
+
port: '8080',
|
|
12
|
+
version: FcrepoWrapper.default_fcrepo_version
|
|
13
|
+
}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.default_instance_options=(options)
|
|
17
|
+
@default_instance_options = options
|
|
18
|
+
end
|
|
19
|
+
|
|
9
20
|
def self.default_instance(options = {})
|
|
10
|
-
@default_instance ||= FcrepoWrapper::Instance.new options
|
|
21
|
+
@default_instance ||= FcrepoWrapper::Instance.new default_instance_options.merge(options)
|
|
11
22
|
end
|
|
12
23
|
|
|
13
24
|
##
|
|
14
|
-
# Ensures a
|
|
25
|
+
# Ensures a fcrepo service is running before executing the block
|
|
15
26
|
def self.wrap(options = {}, &block)
|
|
16
27
|
default_instance(options).wrap &block
|
|
17
28
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fcrepo_wrapper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chris Beer
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-02-
|
|
11
|
+
date: 2016-02-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: ruby-progressbar
|
|
@@ -112,12 +112,14 @@ files:
|
|
|
112
112
|
- README.md
|
|
113
113
|
- Rakefile
|
|
114
114
|
- coveralls.yml
|
|
115
|
+
- data/spring-noop.xml
|
|
115
116
|
- exe/fcrepo_wrapper
|
|
116
117
|
- fcrepo_wrapper.gemspec
|
|
117
118
|
- lib/fcrepo_wrapper.rb
|
|
118
119
|
- lib/fcrepo_wrapper/instance.rb
|
|
120
|
+
- lib/fcrepo_wrapper/rake_task.rb
|
|
121
|
+
- lib/fcrepo_wrapper/tasks/fcrepo_wrapper.rake
|
|
119
122
|
- lib/fcrepo_wrapper/version.rb
|
|
120
|
-
- lib/service_instance.rb
|
|
121
123
|
- spec/lib/fcrepo_wrapper_spec.rb
|
|
122
124
|
- spec/spec_helper.rb
|
|
123
125
|
homepage: https://github.com/cbeer/fcrepo_wrapper
|
data/lib/service_instance.rb
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
# This module is intended to be mixed into SolrWrapper::Instance and FcrepoWrapper::Instance
|
|
2
|
-
module ServiceInstance
|
|
3
|
-
def env
|
|
4
|
-
options.fetch(:env, {})
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def binary_path
|
|
8
|
-
raise NotImplementedError, "Implement binary_path in a subclass"
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def default_download_url
|
|
12
|
-
raise NotImplementedError, "Implement default_download_url in a subclass"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def default_instance_dir
|
|
16
|
-
raise NotImplementedError, "Implement default_instance_dir in a subclass"
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def md5url
|
|
20
|
-
raise NotImplementedError, "Implement md5url in a subclass"
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def download_path
|
|
24
|
-
@download_path ||= options.fetch(:download_path, default_download_path)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def default_download_path
|
|
28
|
-
File.join(Dir.tmpdir, File.basename(download_url))
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def download_url
|
|
32
|
-
@download_url ||= options.fetch(:url, default_download_url)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def verbose?
|
|
37
|
-
!!options.fetch(:verbose, false)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def instance_dir
|
|
41
|
-
@instance_dir ||= options.fetch(:instance_dir, default_instance_dir)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def extracted?
|
|
45
|
-
File.exists?(binary_path) && extracted_version == version
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def extracted_version
|
|
49
|
-
File.read(version_file).strip if File.exists? version_file
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def extracted_version=(version)
|
|
53
|
-
File.open(version_file, "w") do |f|
|
|
54
|
-
f.puts version
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def version_file
|
|
59
|
-
options.fetch(:version_file, File.join(instance_dir, "VERSION"))
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def expected_md5sum
|
|
63
|
-
@md5sum ||= options.fetch(:md5sum, open(md5file).read.split(" ").first)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
##
|
|
67
|
-
# Is the service running?
|
|
68
|
-
def started?
|
|
69
|
-
!!status
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def download
|
|
73
|
-
unless File.exists?(download_path) && validate?(download_path)
|
|
74
|
-
fetch_with_progressbar download_url, download_path
|
|
75
|
-
validate! download_path
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
download_path
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def validate?(file)
|
|
82
|
-
return true if options[:validate] == false
|
|
83
|
-
Digest::MD5.file(file).hexdigest == expected_md5sum
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def validate!(file)
|
|
87
|
-
unless validate? file
|
|
88
|
-
raise "MD5 mismatch" unless options[:ignore_md5sum]
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
##
|
|
93
|
-
# Clean up any files fcrepo_wrapper may have downloaded
|
|
94
|
-
# TODO: if this is used for solr_wrapper, we also need to remove tmp_save_dir
|
|
95
|
-
def clean!
|
|
96
|
-
stop
|
|
97
|
-
remove_instance_dir!
|
|
98
|
-
FileUtils.remove_entry(download_path) if File.exists? download_path
|
|
99
|
-
FileUtils.remove_entry(md5sum_path) if File.exists? md5sum_path
|
|
100
|
-
FileUtils.remove_entry(version_file) if File.exists? version_file
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
##
|
|
104
|
-
# Clean up any files in the Solr instance dir
|
|
105
|
-
def remove_instance_dir!
|
|
106
|
-
FileUtils.remove_entry(instance_dir, true) if File.exists? instance_dir
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def fetch_with_progressbar(url, output)
|
|
110
|
-
pbar = ProgressBar.create(title: File.basename(url), total: nil, format: "%t: |%B| %p%% (%e )")
|
|
111
|
-
open(url, content_length_proc: lambda do|t|
|
|
112
|
-
if t && 0 < t
|
|
113
|
-
pbar.total = t
|
|
114
|
-
end
|
|
115
|
-
end,
|
|
116
|
-
progress_proc: lambda do|s|
|
|
117
|
-
pbar.progress = s
|
|
118
|
-
end) do |io|
|
|
119
|
-
IO.copy_stream(io, output)
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
def md5file
|
|
124
|
-
unless File.exists? md5sum_path
|
|
125
|
-
fetch_with_progressbar md5url, md5sum_path
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
md5sum_path
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
def md5sum_path
|
|
132
|
-
File.join(Dir.tmpdir, File.basename(md5url))
|
|
133
|
-
end
|
|
134
|
-
end
|