fcrepo_wrapper 0.0.1 → 0.1.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/README.md +2 -15
- data/exe/fcrepo_wrapper +1 -2
- data/lib/fcrepo_wrapper/instance.rb +40 -125
- data/lib/fcrepo_wrapper/version.rb +1 -1
- data/lib/fcrepo_wrapper.rb +1 -1
- data/lib/service_instance.rb +134 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0f8e9988b5ee44ce1a0e23953a2f123905ca46c
|
4
|
+
data.tar.gz: e58c9f5a366d73a997892a8fcecd1748b68ea136
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cae3f84d9feb62d4addf0469e5aed08a7251a595e0d45f1124ee1cb5ebc2779d7d659935d09aa7973f77550cf9567eb8a1bb78854bd5a452eb748e7ff0bb3fd
|
7
|
+
data.tar.gz: c1d6ce5f75551a6d5ffa00f78e6dc26f4b9cefb53766c2e5a8e1db9ca475ee86ed817580a18180b7d6cb768747af6674bd6c6a4155bb2960e7595e8c91137233
|
data/README.md
CHANGED
@@ -1,28 +1,15 @@
|
|
1
1
|
# FcrepoWrapper
|
2
2
|
|
3
|
-
Wrap any task with a
|
3
|
+
Wrap any task with a Fcrepo instance:
|
4
4
|
|
5
5
|
```ruby
|
6
6
|
FcrepoWrapper.wrap do |solr|
|
7
|
-
# Something that requires
|
7
|
+
# Something that requires Fcrepo
|
8
8
|
end
|
9
9
|
```
|
10
10
|
|
11
|
-
Or with Solr and a solr collection:
|
12
|
-
|
13
|
-
```ruby
|
14
|
-
subject.wrap do |solr|
|
15
|
-
solr.with_collection(dir: File.join(FIXTURES_DIR, "basic_configs")) do |collection_name|
|
16
|
-
end
|
17
|
-
end
|
18
|
-
```
|
19
|
-
|
20
11
|
## Basic Options
|
21
12
|
|
22
13
|
```ruby
|
23
14
|
FcrepoWrapper.wrap port: 8983, verbose: true, managed: true
|
24
15
|
```
|
25
|
-
|
26
|
-
```ruby
|
27
|
-
solr.with_collection(name: 'collection_name', dir: 'path_to_solr_confiigs')
|
28
|
-
```
|
data/exe/fcrepo_wrapper
CHANGED
@@ -12,7 +12,7 @@ OptionParser.new do |opts|
|
|
12
12
|
options[:verbose] = v
|
13
13
|
end
|
14
14
|
|
15
|
-
opts.on("--version VERSION", "Specify a fcrepo version to download (default: #{FcrepoWrapper.
|
15
|
+
opts.on("--version VERSION", "Specify a fcrepo version to download (default: #{FcrepoWrapper.default_fcrepo_version})") do |v|
|
16
16
|
options[:version] = v
|
17
17
|
end
|
18
18
|
|
@@ -25,7 +25,6 @@ end.parse!
|
|
25
25
|
options[:verbose] = true if options[:verbose].nil?
|
26
26
|
|
27
27
|
FcrepoWrapper.wrap(options) do |conn|
|
28
|
-
with_collection(collection_options)
|
29
28
|
while conn.status
|
30
29
|
sleep 1
|
31
30
|
end
|
@@ -6,9 +6,11 @@ require 'securerandom'
|
|
6
6
|
require 'stringio'
|
7
7
|
require 'tmpdir'
|
8
8
|
require 'byebug'
|
9
|
+
require 'service_instance'
|
9
10
|
|
10
11
|
module FcrepoWrapper
|
11
12
|
class Instance
|
13
|
+
include ServiceInstance
|
12
14
|
attr_reader :options, :pid
|
13
15
|
|
14
16
|
##
|
@@ -24,6 +26,7 @@ module FcrepoWrapper
|
|
24
26
|
# @option options [Boolean] :verbose
|
25
27
|
# @option options [Boolean] :managed
|
26
28
|
# @option options [Boolean] :ignore_md5sum
|
29
|
+
# @option options [Array<String>] :java_options a list of options to pass to the JVM
|
27
30
|
# @option options [Hash] :fcrepo_options
|
28
31
|
# @option options [Hash] :env
|
29
32
|
def initialize(options = {})
|
@@ -37,14 +40,33 @@ module FcrepoWrapper
|
|
37
40
|
stop
|
38
41
|
end
|
39
42
|
|
43
|
+
# @return a list of arguments to pass to the JVM
|
44
|
+
def java_options
|
45
|
+
options.fetch(:java_options, default_java_options) + ['-jar', binary_path]
|
46
|
+
end
|
47
|
+
|
48
|
+
def default_java_options
|
49
|
+
['-Dfcrepo.log.http.api=WARN',
|
50
|
+
# To avoid "WARN: The namespace of predicate:
|
51
|
+
# info:fedora/fedora-system:def/relations-external#isPartOf
|
52
|
+
# was possibly misinterpreted as:
|
53
|
+
# info:fedora/fedora-system:def/relations-external#."
|
54
|
+
'-Dfcrepo.log.kernel=ERROR']
|
55
|
+
end
|
56
|
+
|
57
|
+
def process_arguments
|
58
|
+
["java"] + java_options +
|
59
|
+
fcrepo_options.merge(port: port)
|
60
|
+
.map { |k, v| ["--#{k}", "#{v}"].reject(&:empty?) }.flatten
|
61
|
+
end
|
62
|
+
|
40
63
|
##
|
41
64
|
# Start Solr and wait for it to become available
|
42
65
|
def start
|
43
66
|
extract
|
44
67
|
if managed?
|
45
|
-
args = ["java", "-jar", fcrepo_binary] + fcrepo_options.merge(port: port).map { |k, v| ["--#{k}", "#{v}"].reject(&:empty?) }.flatten
|
46
68
|
|
47
|
-
@pid = spawn(env, *
|
69
|
+
@pid = spawn(env, *process_arguments)
|
48
70
|
|
49
71
|
# Wait for fcrepo to start
|
50
72
|
until status
|
@@ -86,76 +108,20 @@ module FcrepoWrapper
|
|
86
108
|
end
|
87
109
|
end
|
88
110
|
|
89
|
-
##
|
90
|
-
# Is Solr running?
|
91
|
-
def started?
|
92
|
-
!!status
|
93
|
-
end
|
94
|
-
|
95
111
|
##
|
96
112
|
# Get the port this fcrepo instance is running at
|
97
113
|
def port
|
98
114
|
options.fetch(:port, "8080").to_s
|
99
115
|
end
|
100
116
|
|
101
|
-
##
|
102
|
-
# Clean up any files fcrepo_wrapper may have downloaded
|
103
|
-
def clean!
|
104
|
-
stop
|
105
|
-
FileUtils.remove_entry(download_path) if File.exists? download_path
|
106
|
-
FileUtils.remove_entry(tmp_save_dir, true) if File.exists? tmp_save_dir
|
107
|
-
FileUtils.remove_entry(instance_dir, true) if File.exists? instance_dir
|
108
|
-
FileUtils.remove_entry(md5sum_path) if File.exists? md5sum_path
|
109
|
-
FileUtils.remove_entry(version_file) if File.exists? version_file
|
110
|
-
end
|
111
|
-
|
112
117
|
##
|
113
118
|
# Get a (likely) URL to the fcrepo instance
|
114
119
|
def url
|
115
|
-
"http://127.0.0.1:#{port}/
|
116
|
-
end
|
117
|
-
|
118
|
-
protected
|
119
|
-
|
120
|
-
def extract
|
121
|
-
return fcrepo_dir if File.exists?(fcrepo_binary) && extracted_version == version
|
122
|
-
|
123
|
-
jar_path = download
|
124
|
-
|
125
|
-
FileUtils.mkdir_p fcrepo_path
|
126
|
-
FileUtils.cp jar_path, fcrepo_binary
|
127
|
-
self.extracted_version = version
|
128
|
-
|
129
|
-
configure
|
130
|
-
|
131
|
-
fcrepo_dir
|
132
|
-
end
|
133
|
-
|
134
|
-
def download
|
135
|
-
unless File.exists?(download_path) && validate?(download_path)
|
136
|
-
fetch_with_progressbar download_url, download_path
|
137
|
-
validate! download_path
|
138
|
-
end
|
139
|
-
|
140
|
-
download_path
|
141
|
-
end
|
142
|
-
|
143
|
-
def validate?(file)
|
144
|
-
Digest::MD5.file(file).hexdigest == expected_md5sum
|
145
|
-
end
|
146
|
-
|
147
|
-
def validate!(file)
|
148
|
-
unless validate? file
|
149
|
-
raise "MD5 mismatch" unless options[:ignore_md5sum]
|
150
|
-
end
|
120
|
+
"http://127.0.0.1:#{port}/rest/"
|
151
121
|
end
|
152
122
|
|
153
123
|
private
|
154
124
|
|
155
|
-
def download_url
|
156
|
-
@download_url ||= options.fetch(:url, default_download_url)
|
157
|
-
end
|
158
|
-
|
159
125
|
def default_download_url
|
160
126
|
@default_url ||= "https://github.com/fcrepo4/fcrepo4/releases/download/fcrepo-#{version}/fcrepo-webapp-#{version}-jetty-console.jar"
|
161
127
|
end
|
@@ -172,87 +138,36 @@ module FcrepoWrapper
|
|
172
138
|
options.fetch(:fcrepo_options, headless: nil)
|
173
139
|
end
|
174
140
|
|
175
|
-
def env
|
176
|
-
options.fetch(:env, {})
|
177
|
-
end
|
178
|
-
|
179
141
|
def default_fcrepo_version
|
180
142
|
FcrepoWrapper.default_fcrepo_version
|
181
143
|
end
|
182
144
|
|
183
|
-
def
|
184
|
-
|
185
|
-
end
|
186
|
-
|
187
|
-
def default_download_path
|
188
|
-
File.join(Dir.tmpdir, File.basename(download_url))
|
189
|
-
end
|
190
|
-
|
191
|
-
def fcrepo_dir
|
192
|
-
@fcrepo_dir ||= options.fetch(:instance_dir, File.join(Dir.tmpdir, File.basename(download_url, ".jar")))
|
193
|
-
end
|
194
|
-
|
195
|
-
def verbose?
|
196
|
-
!!options.fetch(:verbose, false)
|
145
|
+
def default_instance_dir
|
146
|
+
File.join(Dir.tmpdir, File.basename(download_url, ".jar"))
|
197
147
|
end
|
198
148
|
|
199
149
|
def managed?
|
200
150
|
!!options.fetch(:managed, true)
|
201
151
|
end
|
202
152
|
|
203
|
-
def
|
204
|
-
|
205
|
-
end
|
206
|
-
|
207
|
-
def expected_md5sum
|
208
|
-
@md5sum ||= options.fetch(:md5sum, open(md5file).read.split(" ").first)
|
209
|
-
end
|
210
|
-
|
211
|
-
def fcrepo_binary
|
212
|
-
File.join(fcrepo_dir, "fcrepo-webapp-#{version}-jetty-console.jar")
|
213
|
-
end
|
214
|
-
|
215
|
-
def md5sum_path
|
216
|
-
File.join(Dir.tmpdir, File.basename(md5url))
|
217
|
-
end
|
218
|
-
|
219
|
-
def tmp_save_dir
|
220
|
-
@tmp_save_dir ||= Dir.mktmpdir
|
221
|
-
end
|
222
|
-
|
223
|
-
def fetch_with_progressbar(url, output)
|
224
|
-
pbar = ProgressBar.create(title: File.basename(url), total: nil, format: "%t: |%B| %p%% (%e )")
|
225
|
-
open(url, content_length_proc: lambda do|t|
|
226
|
-
if t && 0 < t
|
227
|
-
pbar.total = t
|
228
|
-
end
|
229
|
-
end,
|
230
|
-
progress_proc: lambda do|s|
|
231
|
-
pbar.progress = s
|
232
|
-
end) do |io|
|
233
|
-
IO.copy_stream(io, output)
|
234
|
-
end
|
153
|
+
def binary_path
|
154
|
+
File.join(instance_dir, "fcrepo-webapp-#{version}-jetty-console.jar")
|
235
155
|
end
|
236
156
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
md5sum_path
|
243
|
-
end
|
157
|
+
# extract a copy of fcrepo to instance_dir
|
158
|
+
# Does noting if fcrepo already exists at instance_dir
|
159
|
+
# @return [String] instance_dir Directory where solr has been installed
|
160
|
+
def extract
|
161
|
+
return instance_dir if extracted?
|
244
162
|
|
245
|
-
|
246
|
-
File.read(version_file).strip if File.exists? version_file
|
247
|
-
end
|
163
|
+
jar_file = download
|
248
164
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
end
|
165
|
+
byebug
|
166
|
+
FileUtils.mkdir_p instance_dir
|
167
|
+
FileUtils.cp jar_file, binary_path
|
168
|
+
self.extracted_version = version
|
254
169
|
|
255
|
-
|
170
|
+
instance_dir
|
256
171
|
end
|
257
172
|
end
|
258
173
|
end
|
data/lib/fcrepo_wrapper.rb
CHANGED
@@ -0,0 +1,134 @@
|
|
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
|
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.0
|
4
|
+
version: 0.1.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:
|
11
|
+
date: 2016-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-progressbar
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/fcrepo_wrapper.rb
|
118
118
|
- lib/fcrepo_wrapper/instance.rb
|
119
119
|
- lib/fcrepo_wrapper/version.rb
|
120
|
+
- lib/service_instance.rb
|
120
121
|
- spec/lib/fcrepo_wrapper_spec.rb
|
121
122
|
- spec/spec_helper.rb
|
122
123
|
homepage: https://github.com/cbeer/fcrepo_wrapper
|
@@ -139,10 +140,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
140
|
version: '0'
|
140
141
|
requirements: []
|
141
142
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.4.
|
143
|
+
rubygems_version: 2.4.5.1
|
143
144
|
signing_key:
|
144
145
|
specification_version: 4
|
145
146
|
summary: Solr 5 service wrapper
|
146
147
|
test_files:
|
147
148
|
- spec/lib/fcrepo_wrapper_spec.rb
|
148
149
|
- spec/spec_helper.rb
|
150
|
+
has_rdoc:
|