gi_cat_driver 0.1.0 → 0.1.1

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/README.md CHANGED
@@ -44,6 +44,9 @@ Rubydoc API documentation is available at http://rubydoc.info/gems/gi_cat_driver
44
44
 
45
45
  ## Version History
46
46
 
47
+ * 0.1.1
48
+ * Added parameter to ESIP OpenSearch query builder
49
+ * Added log output for GI-Cat harvest procedures
47
50
  * 0.1.0
48
51
  * Release stable version of gem features that invoke GI-Cat
49
52
  * 0.0.8
@@ -68,15 +71,13 @@ This gem follows the principles of [Semantic Versioning 2.0.0](http://semver.org
68
71
  ## Releasing
69
72
 
70
73
  1. Make sure to increment the version number (See the section about versioning above) and append a description of your changes to the Version History section above.
71
- 2. Commit changes into the master branch of the repo on sourcecontrol.nsidc.org
72
- 3. The commit will trigger a Jenkins job to run the tests
73
- 4. When the changes are ready to be released, you can either push the gem manually or run a job in Jenkins
74
- 4a. To push manually: You must have permissions on the GitHub repository through the NSIDC organization and you must be an owner of the 'gi_cat_driver'a gem on RubyGems.
75
- Once you have the credentials, run the command 'rake release' to tag the version number in the Git revision history and publish on RubyGems.
76
- To push to GitHub make sure you have the remotes configured (run 'git remote -v' to list available remotes. To add the GitHub repository to your remotes, run 'git remote add github https://github.com/nsidc/gi_cat_driver.git')
77
- 4b: Using Jenkins: Run the job named 'GI-Cat_(gem)_Deploy_gi_cat_driver'
78
-
79
- NOTE: RubyGems will not allow you to release the same version of a gem more than once.
74
+ 2. Commit changes into the master branch of the repo on 'sourcecontrol.nsidc.org'. This will trigger a Jenkins job to run the tests.
75
+ 4. Assuming the change is merged with the master branch and you are ready to release them to GitHub run 'git push https://github.com/nsidc/gi_cat_driver.git master'
76
+ * There is a Jenkins job that can push master to GitHub if you are confident you wont have merge conflicts.
77
+ * Note: You must have permissions on the GitHub repository through the NSIDC organization.
78
+ 5. Make sure to release the new gem version to RubyGems by running 'rake release'
79
+ * Note: You must be configured as an owner of the 'gi_cat_driver'a gem on RubyGems.
80
+ * Also Note: RubyGems will not allow you to release the same version of a gem more than once.
80
81
 
81
82
  ## Contributing
82
83
 
@@ -9,17 +9,18 @@ module EsipOpensearchQueryBuilder
9
9
  end
10
10
 
11
11
  def self.get_query_string( query_params={} )
12
- all_params = {
13
- :si => '',
14
- :ct => '',
15
- :st => '',
16
- :bbox => '',
17
- :rel => '',
18
- :loc => '',
19
- :ts => '',
20
- :te => '',
21
- :lac => '',
22
- :luc => '',
12
+ all_params = {
13
+ :si => '',
14
+ :ct => '',
15
+ :st => '',
16
+ :bbox => '',
17
+ :rel => '',
18
+ :loc => '',
19
+ :ts => '',
20
+ :te => '',
21
+ :lac => '',
22
+ :luc => '',
23
+ :gdc => '',
23
24
  :outputFormat => ''
24
25
  }.merge(query_params)
25
26
 
@@ -1,3 +1,3 @@
1
1
  module GiCatDriver
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/gi_cat_driver.rb CHANGED
@@ -12,13 +12,14 @@ module GiCatDriver
12
12
 
13
13
  ATOM_NAMESPACE = { "atom" => "http://www.w3.org/2005/Atom" }
14
14
  RELEVANCE_NAMESPACE = { "relevance" => "http://a9.com/-/opensearch/extensions/relevance/1.0/" }
15
- attr_accessor :base_url, :harvestersid_array
16
-
15
+ attr_accessor :base_url, :harvestersid_array, :harvestersinfo_array
16
+
17
17
  def initialize( url, username, password )
18
18
  @base_url = url.sub(/\/+$/, '')
19
19
  @admin_username = username
20
20
  @admin_password = password
21
21
  @harvestersid_array = []
22
+ @harvestersinfo_array = {}
22
23
  end
23
24
 
24
25
  def basic_auth_string
@@ -51,12 +52,6 @@ module GiCatDriver
51
52
  return (profile.empty? ? nil : profile.attr('id').value)
52
53
  end
53
54
 
54
- def parse_profile_element( profile_name, xml_doc )
55
- configs = Nokogiri.XML(xml_doc)
56
-
57
- return configs.css("brokerConfiguration[name=#{profile_name}]")
58
- end
59
-
60
55
  # Enable a profile with the specified name
61
56
  def enable_profile( profile_name )
62
57
  profile_id = find_profile_id(profile_name)
@@ -66,6 +61,17 @@ module GiCatDriver
66
61
  RestClient.get(activate_profile_request, standard_headers)
67
62
  end
68
63
 
64
+ # Given a profile id, put all the associated resource id and title into harvest info array
65
+ def get_harvest_resources(profile_id)
66
+ id = get_active_profile_distributor_id(profile_id)
67
+ harvest_resource_request = "#{@base_url}/services/conf/brokerConfigurations/#{profile_id}/distributors/#{id}"
68
+ response = RestClient.get(harvest_resource_request, standard_headers)
69
+ doc = Nokogiri::XML(response)
70
+ doc.css("component").each do |component|
71
+ @harvestersinfo_array[component.css("id").text.to_sym] = component.css("title").text
72
+ end
73
+ end
74
+
69
75
  # Retrieve the ID for the active profile
70
76
  # Returns an integer ID reference to the active profile
71
77
  def get_active_profile_id
@@ -78,23 +84,12 @@ module GiCatDriver
78
84
  def enable_lucene
79
85
  set_lucene_enabled true
80
86
  end
81
-
87
+
82
88
  # Disable Lucene indexes for GI-Cat search results
83
89
  def disable_lucene
84
90
  set_lucene_enabled false
85
91
  end
86
92
 
87
- def set_lucene_enabled( enabled )
88
- enable_lucene_request = "#{@base_url}/services/conf/brokerConfigurations/#{get_active_profile_id}/luceneEnabled"
89
- RestClient.put(enable_lucene_request,
90
- enabled.to_s,
91
- standard_headers)
92
-
93
- activate_profile_request = "#{@base_url}/services/conf/brokerConfigurations/#{get_active_profile_id}?opts=active"
94
- RestClient.get(activate_profile_request,
95
- standard_headers)
96
- end
97
-
98
93
  # Find out whether Lucene indexing is turned on for the current profile
99
94
  # It is desirable to use REST to query GI-Cat for the value of this setting but GI-Cat does not yet support this.
100
95
  # Instead, run a query and check that a 'relevance:score' element is present.
@@ -108,59 +103,119 @@ module GiCatDriver
108
103
 
109
104
  return result_scores.count > 0
110
105
  end
111
-
112
- # Build the harvester resource id array
106
+
107
+ # Build the harvester resource id
113
108
  def add_harvester_resource_id(resource_id)
114
109
  @harvestersid_array.push(resource_id)
110
+ @harvestersinfo_array[resource_id.to_sym] = "default"
111
+ end
112
+
113
+ # Remove the harvester resourceinfo array
114
+ def clear_resource
115
+ @harvestersinfo_array.clear
116
+ end
117
+
118
+ # Harvest all resource in the active profile
119
+ def harvest_all_resources_for_active_configuration
120
+ get_harvest_resources(get_active_profile_id)
121
+ @harvestersinfo_array.each do |harvester_id, harvester_title|
122
+ harvest_resource_for_active_configuration(harvester_id.to_s, harvester_title)
123
+ end
124
+ end
125
+
126
+ # Run till harvest all the resources are completed or time out
127
+ # The default timeout is 300 seconds (5 minutes)
128
+ def confirm_harvest_done(waitmax=300)
129
+ begin
130
+ puts "Info: Max wait time (timeout) for current profile is set to #{waitmax} seconds"
131
+ Timeout::timeout(waitmax) do
132
+ @harvestersinfo_array.each do |harvester_id, harvester_title|
133
+ havest_request_is_done(harvester_id.to_s, harvester_title)
134
+ end
135
+ end
136
+ rescue Timeout::Error
137
+ puts "Warning: re-harvest is time out(#{waitmax} seconds, we are going to reuse the previous harvest results"
138
+ end
139
+ end
140
+
141
+ private
142
+
143
+ # Retrieve the profile element using the name
144
+ def parse_profile_element( profile_name, xml_doc )
145
+ configs = Nokogiri.XML(xml_doc)
146
+
147
+ return configs.css("brokerConfiguration[name=#{profile_name}]")
148
+ end
149
+
150
+ # Retrive the distributor id given a profile id
151
+ def get_active_profile_distributor_id(id)
152
+ active_profile_request = "#{@base_url}/services/conf/brokerConfigurations/#{id}"
153
+ response = RestClient.get(active_profile_request, standard_headers)
154
+ id = Nokogiri::XML(response).css("component id").text
155
+ return id
156
+ end
157
+
158
+ # Toggle lucene indexes on when enabled is true, off when false
159
+ def set_lucene_enabled( enabled )
160
+ enable_lucene_request = "#{@base_url}/services/conf/brokerConfigurations/#{get_active_profile_id}/luceneEnabled"
161
+ RestClient.put(enable_lucene_request,
162
+ enabled.to_s,
163
+ standard_headers)
164
+
165
+ activate_profile_request = "#{@base_url}/services/conf/brokerConfigurations/#{get_active_profile_id}?opts=active"
166
+ RestClient.get(activate_profile_request,
167
+ standard_headers)
115
168
  end
116
169
 
117
170
  # Harvest from specified resource
118
- def harvest_resource_for_active_configuration(harvesterid)
171
+ def harvest_resource_for_active_configuration(harvesterid, harvestername = "n/a")
119
172
  RestClient.get(
120
173
  "#{@base_url}/services/conf/brokerConfigurations/#{self.get_active_profile_id}/harvesters/#{harvesterid}/start",
121
174
  standard_headers){ |response, request, result, &block|
122
175
  case response.code
123
176
  when 200
124
- p "Harvest initiated. Please wait a couple minutes for the process to complete."
177
+ puts "#{Time.now}: Initiate harvesting GI-Cat resource #{harvestername}. Please wait a couple minutes for the process to complete."
125
178
  else
126
- raise "Failed to start GI-Cat resource harvest."
179
+ raise "Failed to initiate harvesting GI-Cat resource #{harvestername}."
127
180
  response.return!(request, result, &block)
128
181
  end
129
182
  }
130
183
  end
131
184
 
132
- # Harvest all resource in the active profile
133
- def harvest_all_resources_for_active_configuration
134
- harvestersid_array.each do |harvesterid|
135
- harvest_resource_for_active_configuration(harvesterid)
136
- end
137
- end
138
-
185
+ # Parsing and handle the harvest status
186
+ def handle_harvest_status(harvest_status, harvestername="default")
187
+ timestamp = Time.now
188
+ puts "#{Time.now}: Harvest #{harvestername} status: #{harvest_status}"
189
+ case harvest_status
190
+ when /completed/
191
+ return :completed
192
+ when /error/
193
+ return :error
194
+ else
195
+ return :pending
196
+ end
197
+ end
198
+
139
199
  # Run till the harvest of a resource is completed
140
- def havest_request_is_done(harvesterid)
200
+ def havest_request_is_done(harvesterid, harvestername="n/a")
141
201
  while(1) do
142
202
  rnum=rand
143
203
  request = @base_url + "/services/conf/giconf/status?id=#{harvesterid}&rand=#{rnum}"
144
204
  response = RestClient.get request
145
- teststring = String.new(response.body)
146
- if teststring.include?("Harvesting completed")
147
- break
148
- end
149
- end
150
- end
151
205
 
152
- # Run till harvest all the resource is completed or time out
153
- def confirm_harvest_done
154
- begin
155
- Timeout::timeout(10) do
156
- harvestersid_array.each do |harvesterid|
157
- havest_request_is_done(harvesterid)
206
+ responsexml = Nokogiri::XML::Reader(response)
207
+ responsexml.each do |node|
208
+ if node.name == "status" && !node.inner_xml.empty?
209
+ case handle_harvest_status(node.inner_xml, harvestername)
210
+ when :error
211
+ fail "Error harvesting the resource #{harvestername}: #{harvest_status}"
212
+ when :completed
213
+ puts "Harvest succeed"
214
+ return
215
+ end
158
216
  end
159
217
  end
160
- rescue Timeout::Error
161
- puts "Warning: reharvest is time out, we are going to reuse the previous harvest results"
162
218
  end
163
219
  end
164
-
165
220
  end
166
221
  end
@@ -6,17 +6,17 @@ describe EsipOpensearchQueryBuilder do
6
6
  describe "get_query_string returns ESIP OpenSearch URLs" do
7
7
  it "Returns a URL with empty parameters when called without arguments" do
8
8
  query = EsipOpensearchQueryBuilder::get_query_string()
9
- query.should eq "?si=&ct=&st=&bbox=&rel=&loc=&ts=&te=&lac=&luc=&outputFormat="
9
+ query.should eq "?si=&ct=&st=&bbox=&rel=&loc=&ts=&te=&lac=&luc=&gdc=&outputFormat="
10
10
  end
11
11
 
12
12
  it "Returns a URL with a bounding box when called with a bbox argument" do
13
13
  query = EsipOpensearchQueryBuilder::get_query_string( :bbox => 'abcd')
14
- query.should eq "?si=&ct=&st=&bbox=abcd&rel=&loc=&ts=&te=&lac=&luc=&outputFormat="
14
+ query.should eq "?si=&ct=&st=&bbox=abcd&rel=&loc=&ts=&te=&lac=&luc=&gdc=&outputFormat="
15
15
  end
16
16
 
17
17
  it "Returns a URL with a search term when called with a st argument" do
18
18
  query = EsipOpensearchQueryBuilder::get_query_string( :st => 'snow')
19
- query.should eq "?si=&ct=&st=snow&bbox=&rel=&loc=&ts=&te=&lac=&luc=&outputFormat="
19
+ query.should eq "?si=&ct=&st=snow&bbox=&rel=&loc=&ts=&te=&lac=&luc=&gdc=&outputFormat="
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gi_cat_driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-20 00:00:00.000000000 Z
13
+ date: 2013-04-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
17
- requirement: !ruby/object:Gem::Requirement
17
+ requirement: &70253266626500 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,15 +22,10 @@ dependencies:
22
22
  version: 1.6.7
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
- requirements:
28
- - - ~>
29
- - !ruby/object:Gem::Version
30
- version: 1.6.7
25
+ version_requirements: *70253266626500
31
26
  - !ruby/object:Gem::Dependency
32
27
  name: nokogiri
33
- requirement: !ruby/object:Gem::Requirement
28
+ requirement: &70253266625340 !ruby/object:Gem::Requirement
34
29
  none: false
35
30
  requirements:
36
31
  - - ~>
@@ -38,15 +33,10 @@ dependencies:
38
33
  version: 1.5.6
39
34
  type: :runtime
40
35
  prerelease: false
41
- version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
44
- - - ~>
45
- - !ruby/object:Gem::Version
46
- version: 1.5.6
36
+ version_requirements: *70253266625340
47
37
  - !ruby/object:Gem::Dependency
48
38
  name: bundler
49
- requirement: !ruby/object:Gem::Requirement
39
+ requirement: &70253266624460 !ruby/object:Gem::Requirement
50
40
  none: false
51
41
  requirements:
52
42
  - - ~>
@@ -54,15 +44,10 @@ dependencies:
54
44
  version: '1.3'
55
45
  type: :development
56
46
  prerelease: false
57
- version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
60
- - - ~>
61
- - !ruby/object:Gem::Version
62
- version: '1.3'
47
+ version_requirements: *70253266624460
63
48
  - !ruby/object:Gem::Dependency
64
49
  name: rake
65
- requirement: !ruby/object:Gem::Requirement
50
+ requirement: &70253266623780 !ruby/object:Gem::Requirement
66
51
  none: false
67
52
  requirements:
68
53
  - - ~>
@@ -70,15 +55,10 @@ dependencies:
70
55
  version: 10.0.3
71
56
  type: :development
72
57
  prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ~>
77
- - !ruby/object:Gem::Version
78
- version: 10.0.3
58
+ version_requirements: *70253266623780
79
59
  - !ruby/object:Gem::Dependency
80
60
  name: rspec
81
- requirement: !ruby/object:Gem::Requirement
61
+ requirement: &70253266623000 !ruby/object:Gem::Requirement
82
62
  none: false
83
63
  requirements:
84
64
  - - ~>
@@ -86,12 +66,7 @@ dependencies:
86
66
  version: 2.13.0
87
67
  type: :development
88
68
  prerelease: false
89
- version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
- requirements:
92
- - - ~>
93
- - !ruby/object:Gem::Version
94
- version: 2.13.0
69
+ version_requirements: *70253266623000
95
70
  description: Configure and control deployed instances of GI-Cat.
96
71
  email:
97
72
  - stuart.reed@nsidc.org
@@ -135,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
110
  version: '0'
136
111
  requirements: []
137
112
  rubyforge_project:
138
- rubygems_version: 1.8.23
113
+ rubygems_version: 1.8.15
139
114
  signing_key:
140
115
  specification_version: 3
141
116
  summary: Configure and control deployed instances of GI-Cat.