/
solrizer
executable file
·108 lines (86 loc) · 2.95 KB
/
solrizer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env ruby
require 'rubygems'
require 'optparse'
require 'stomp'
options = {}
optparse = OptionParser.new do|opts|
opts.banner = "Usage: solrizer [options]"
options[:hydra_home] = nil
opts.on( '--hydra_home PATH', 'Load the Hydra instance at this path' ) do |path|
if File.exist?(File.join(path,"config","environment.rb"))
options[:hydra_home] = path
else
puts "#{path} does not appear to be a valid rails home"
exit
end
end
options[:port] = 61613
opts.on('-p','--port NUM', 'Stomp port') do |port|
options[:port] = port
end
options[:host] = 'localhost'
opts.on('-o','--host HOSTNAME', 'Host to connect to') do |host|
options[:host] = host
end
options[:user] = 'fedoraStomper'
opts.on('-u', '--user USERNAME', 'User name for stomp listener') do |user|
options[:user] = user
end
options[:password] = 'fedoraStomper'
opts.on('-w', '--password PASSWORD', 'Password for stomp listener') do |password|
options[:password] = password
end
options[:destination] = '/topic/fedora.apim.update'
opts.on('-d','--destination TOPIC', 'Topic to listen to') do |destination|
options[:destination] = destination
end
opts.on('-h', '--help', 'Display this screen') do
puts opts
exit
end
end
optparse.parse!
begin; require 'rubygems'; rescue; end
if options[:hydra_home]
puts "Loading app..."
Dir.chdir(options[:hydra_home])
require File.join(options[:hydra_home],"config","environment.rb")
puts "app loaded"
else
$stderr.puts "The --hydra_home PATH option is mandatory. Please provide the path to the root of a valid Hydra instance."
exit 1
end
puts "loading listener"
begin
@port = options[:port]
@host = options[:host]
@user = options[:user]
@password = options[:password]
@reliable = true
@clientid = "fedora_stomper"
@destination = options[:destination]
$stderr.print "Connecting to stomp://#{@host}:#{@port} as #{@user}\n"
@conn = Stomp::Connection.open(@user, @password, @host, @port, @reliable, 5, {"client-id" => @clientid} )
$stderr.print "Getting output from #{@destination}\n"
@conn.subscribe(@destination, {"activemq.subscriptionName" => @clientid, :ack =>"client" })
while true
@msg = @conn.receive
pid = @msg.headers["pid"]
method = @msg.headers["methodName"]
puts @msg.headers.inspect
puts "\nPID: #{@msg.headers["pid"]}\n"
if ["addDatastream", "addRelationship","ingest","modifyDatastreamByValue","modifyDatastreamByReference","modifyObject","purgeDatastream","purgeRelationship"].include? method
solrizer = Solrizer::Fedora::Solrizer.new
solrizer.solrize @msg.headers["pid"]
elsif method == "purgeObject"
ActiveFedora::SolrService.instance.conn.delete_by_id(pid)
else
$stderr.puts "Unknown Method: #{method}"
end
puts "updated solr index for #{@msg.headers["pid"]}\n"
@conn.ack @msg.headers["message-id"]
end
@conn.join
rescue Exception => e
p e
end