nifi_sdk_ruby 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01032e0711255ad4a4a189e1298ff17694276da4
4
- data.tar.gz: f579d3be582ce5a2d4d24b33b9930b0ad7cc0042
3
+ metadata.gz: 7d01124b4fdb133022e3b6a135054b882354a056
4
+ data.tar.gz: f3f2f366976dec99ee29adc7000ffa1c65457efc
5
5
  SHA512:
6
- metadata.gz: c640f80758ad0f6fca9beb8b8387b1bd93edfed2fa517f5651548af9e5e34086b54351a873377ea1ff248f5675ba898adcc0a79cc9af9fc36d110c0d2694dc94
7
- data.tar.gz: 5e157bddbda327b4bfd59402bfba7cdd8485e627a53a115f94d55bc0282c2269910efd93ee12b0508d2b295a935b20a47f093d49e0a2dcf3051e12c4319e03a8
6
+ metadata.gz: 03517b738ecadf80fcbfb881631ab62db5483850fb8fba857ec0a75dab17dc7ff9913b257d2ebadaf0985484ef4bd3ba33d5905b7e03678d7d4043a448ed2144
7
+ data.tar.gz: 1146908cdbfb9a7c7f44f6fc4fa2defabaffdb95c7b977b9d8cd9357b82bc9eefbde78c0c54ec2f3b628b7cf371cb1ae13107e7073e947633d2b6fd76866c6c3
data/README.md CHANGED
@@ -59,7 +59,7 @@ puts nifi_client.process_group_by_name? test
59
59
  ### Get all attrs a the Process Group by ID (PG Root's child)
60
60
 
61
61
  ```ruby
62
- puts nifi_client.get_process_group(:id => new_pg['id'])
62
+ puts nifi_client.get_process_group(new_pg['id'])
63
63
  ```
64
64
 
65
65
  ### Get all attrs a the Process Group by Name (Root's childs)
@@ -107,6 +107,17 @@ puts t
107
107
  puts nifi_client.delete_template t['id']
108
108
  ```
109
109
 
110
+ ### Create template instance
111
+ By id
112
+ ```ruby
113
+ puts nifi_client.create_template_instance(:id => '43fwe1s-asd2-sdf3-sfq3ev')
114
+ ```
115
+ Or by name
116
+ ```ruby
117
+ puts nifi_client.create_template_instance(:name => 'TemplateName')
118
+ ```
119
+
120
+
110
121
  ## Contributing
111
122
 
112
123
  Bug reports and pull requests are welcome on GitHub at https://github.com/icalvete/nifi_sdk_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
data/examples/basic.rb CHANGED
@@ -24,13 +24,13 @@ puts "\n"
24
24
  # Get all attrs of the Process Group by ID (PG Root's child)
25
25
  puts 'PG ' + new_pg['id'] + ' attrs.'
26
26
  puts "\n"
27
- puts nifi_client.get_process_group(:id => new_pg['id'])
27
+ puts nifi_client.get_process_group(new_pg['id'])
28
28
  puts "\n"
29
29
 
30
30
  # Get a Process Group ID
31
31
  puts "PG ID"
32
32
  puts "\n"
33
- pg = nifi_client.get_process_group(:id => new_pg['id'])
33
+ pg = nifi_client.get_process_group(new_pg['id'])
34
34
  puts pg['id']
35
35
  puts "\n"
36
36
 
data/lib/nifi_sdk_ruby.rb CHANGED
@@ -46,59 +46,57 @@ class Nifi
46
46
 
47
47
  def set_debug(debug = nil)
48
48
  if debug.nil?
49
- abort 'missing debug'
49
+ raise ArgumentError.new('missing debug')
50
50
  end
51
51
 
52
52
  if !(!!debug == debug)
53
- abort 'debug must be a boolean'
53
+ raise TypeError.new('debug must be a boolean')
54
54
  end
55
55
 
56
56
  @@debug = debug
57
57
  end
58
58
 
59
- def get_debug()
59
+ def get_debug
60
60
  @@debug
61
61
  end
62
62
 
63
63
  def set_async(async = nil)
64
64
  if async.nil?
65
- abort 'missing async'
65
+ raise ArgumentError.new('missing async')
66
66
  end
67
67
 
68
68
  if !(!!async == async)
69
- abort 'async must be a boolean'
69
+ raise TypeError.new('async must be a boolean')
70
70
  end
71
71
 
72
72
  @@async = async
73
73
  end
74
74
 
75
- def get_async()
75
+ def get_async
76
76
  @@async
77
77
  end
78
78
 
79
- def get_api_key()
79
+ def get_api_key
80
80
  @@api_key
81
81
  end
82
82
 
83
- def get_schema()
83
+ def get_schema
84
84
  @@schema
85
85
  end
86
86
 
87
- def get_host()
88
- @@host
87
+ def get_host
88
+ @@host
89
89
  end
90
90
 
91
- def get_base_url()
92
- @@base_url
91
+ def get_base_url
92
+ @@base_url
93
93
  end
94
94
 
95
- def get_process_group(*args)
95
+ def get_process_group(id = nil)
96
96
 
97
- args = args.reduce Hash.new, :merge
98
-
99
- process_group = args[:id] ? args[:id] : 'root'
97
+ process_group = id ? id : 'root'
100
98
 
101
- base_url = @@base_url + "/process-groups/#{process_group}"
99
+ base_url = @@base_url + '/process-groups/' << process_group
102
100
  self.class.http_client(base_url)
103
101
  end
104
102
 
@@ -106,34 +104,35 @@ class Nifi
106
104
  args = args.reduce Hash.new, :merge
107
105
 
108
106
  if args[:name].nil?
109
- abort 'name params is mandatory.'
107
+ raise ArgumentError.new('name params is mandatory.')
110
108
  end
111
-
112
- if self.process_group_by_name? args[:name]
113
- abort 'The process group ' + args[:name] + ' already exists'
109
+ name = args[:name].to_s
110
+ if self.process_group_by_name? name
111
+ raise ArgumentError.new('The process group ' << name << ' already exists')
114
112
  end
115
113
 
116
- params = '{"revision":{"clientId":"' + @@client_id + '","version":0},"component":{"name":"' + args[:name] + '","position":{"x":274.54776144527517,"y":-28.886681059739686}}}'
114
+ params = '{"revision":{"clientId":"' << @@client_id + '","version":0},"component":{"name":"' << name <<
115
+ '","position":{"x":274.54776144527517,"y":-28.886681059739686}}}'
117
116
 
118
117
  process_group = args[:id] ? args[:id] : 'root'
119
- base_url = @@base_url + "/process-groups/#{process_group}/process-groups"
118
+ base_url = @@base_url + '/process-groups/' << process_group << '/process-groups'
120
119
  self.class.http_client(base_url, 'POSTRAW', params)
121
120
  end
122
121
 
123
122
  def delete_process_group(id = nil)
124
123
 
125
124
  if id.nil?
126
- abort 'id is mandatory.'
125
+ raise ArgumentError.new('id is mandatory.')
127
126
  end
128
127
 
129
- base_url = @@base_url + '/process-groups/' + id + '?clientId=' + @@client_id + '&version=1'
128
+ base_url = @@base_url + '/process-groups/' << id << '?clientId=' << @@client_id + '&version=1'
130
129
  self.class.http_client(base_url, 'DELETE')
131
130
  end
132
131
 
133
132
  def get_process_group_by_name(name = nil)
134
133
 
135
134
  if name.nil?
136
- abort 'name is mandatory.'
135
+ raise ArgumentError.new('name is mandatory.')
137
136
  end
138
137
 
139
138
  res = self.class.exists
@@ -145,53 +144,103 @@ class Nifi
145
144
  if pg.count == 1
146
145
  self.class.get pg[0]['identifier']
147
146
  else
148
- abort 'Unable to locate group with name ' + name
147
+ raise ArgumentError.new('Unable to locate group with name ' << name)
149
148
  end
150
149
  end
151
150
 
152
151
  def get_process(id = nil)
153
152
  if id.nil?
154
- abort 'id is mandatory.'
153
+ raise ArgumentError.new('id is mandatory.')
155
154
  end
156
155
 
157
- url = @@base_url + '/processors/' + id
156
+ url = @@base_url + '/processors/' << id
158
157
  self.class.http_client(url)
159
158
  end
160
159
 
161
160
  def start_process(*args)
162
161
  args = args.reduce Hash.new, :merge
163
162
  if args[:id].nil? or args[:version].nil?
164
- abort 'id and version params are mandatory'
163
+ raise ArgumentError.new('id and version params are mandatory')
165
164
  end
166
165
 
167
- id = args[:id]
168
- version = args[:version]
169
-
170
- params = '{"revision":{"version":'+ version +'},"id":"'+ id +'","component":{"id":"'+ id +
171
- '","state":"RUNNING"},"status":{"runStatus":"Running"}}'
172
- base_url = @@base_url + '/processors/' + id
173
- self.class.http_client(base_url, 'PUT', params)
166
+ id = args[:id].to_s
167
+ version = args[:version].to_s
168
+
169
+ params = {
170
+ revision:{
171
+ version: version
172
+ },
173
+ id: id,
174
+ component:{
175
+ id: id,
176
+ state: 'RUNNING'
177
+ },
178
+ status:{
179
+ runStatus: 'Running'
180
+ }
181
+ }
182
+ update_process(id: id, update_json: params)
174
183
  end
175
184
 
176
185
  def stop_process(*args)
177
186
  args = args.reduce Hash.new, :merge
178
187
  if args[:id].nil? or args[:version].nil?
179
- abort 'id and version params are mandatory'
188
+ raise ArgumentError.new('id and version params are mandatory')
180
189
  end
181
190
 
182
- id = args[:id]
183
- version = args[:version]
191
+ id = args[:id].to_s
192
+ version = args[:version].to_s
193
+
194
+ params = {
195
+ revision:{
196
+ version: version
197
+ },
198
+ id: id,
199
+ component:{
200
+ id: id,
201
+ state: 'STOPPED'
202
+ },
203
+ status:{
204
+ runStatus: 'Stopped'
205
+ }
206
+ }
207
+ update_process(id: id, update_json: params)
208
+ end
184
209
 
185
- params = '{"revision":{"version":'+ version +'},"id":"'+ id +'","component":{"id":"'+ id +
186
- '","state":"STOPPED"},"status":{"runStatus": "Stopped"}}'
187
- base_url = @@base_url + '/processors/' + id
210
+ ##
211
+ # NiFi has a classic Optimistic Locking pattern implementation which means that your call will only be
212
+ # accepted and processed as valid if you specify the right version of the component in the revision -> version field
213
+ #
214
+ # ArgumentError is raised if you haven't specified required arguments or they are invalid
215
+ #
216
+ # Updates the process by id using given JSON string or Hash
217
+ # Params:
218
+ # :id => the id of the process
219
+ # :update_json => json with updated values, could be either a JSON string or Ruby Hash
220
+ def update_process(*args)
221
+ args = args.reduce Hash.new, :merge
222
+ if args[:id].nil? or args[:update_json].nil?
223
+ raise ArgumentError.new('id and update_json params are mandatory')
224
+ end
225
+
226
+ id = args[:id].to_s
227
+ case args[:update_json]
228
+ when Hash
229
+ params = args[:update_json].to_json
230
+ when String
231
+ params = args[:update_json]
232
+ else
233
+ raise ArgumentError.new('update_json param must be either a Hash or a String')
234
+ end
235
+
236
+ base_url = @@base_url + '/processors/' << id
188
237
  self.class.http_client(base_url, 'PUT', params)
189
238
  end
190
239
 
191
240
  def process_group_by_name?(name = nil)
192
241
 
193
242
  if name.nil?
194
- abort 'name is mandatory.'
243
+ raise ArgumentError.new('name is mandatory.')
195
244
  end
196
245
 
197
246
  res = self.class.exists
@@ -207,22 +256,22 @@ class Nifi
207
256
  args = args.reduce Hash.new, :merge
208
257
 
209
258
  if args[:id].nil? and args[:name].nil?
210
- abort 'either specify id of the template or it\'s name '
259
+ raise ArgumentError.new('either specify id of the template or it\'s name ')
211
260
  end
212
261
 
213
262
  if args[:name]
214
- abort "Could not find template called #{args[:name]}" unless template_by_name?(args[:name])
263
+ raise StandardError.new('Could not find template called ' << args[:name]) unless template_by_name?(args[:name])
215
264
  id = get_template_by_name(args[:name])[0][0]
216
265
  else
217
- abort "Could not find template with id #{args[:id]}" unless template_by_id?(args[:id])
266
+ raise StandardError.new('Could not find template with id ' << args[:id]) unless template_by_id?(args[:id])
218
267
  id = args[:id]
219
268
  end
220
269
 
221
- originX = args[:originX] ? args[:originX] : '0.0'
222
- originY = args[:originY] ? args[:originY] : '0.0'
270
+ originX = args[:originX] ? args[:originX].to_s : '0.0'
271
+ originY = args[:originY] ? args[:originY].to_s : '0.0'
223
272
  process_group = args[:process_group_id] ? args[:process_group_id] : 'root'
224
- params = '{"templateId": "'+ id +'", "originX": '+ originX +', "originY": '+ originY +'}'
225
- base_url = @@base_url + "/process-groups/#{process_group}/template-instance"
273
+ params = '{"templateId": "' << id << '", "originX": ' << originX << ', "originY": ' << originY << '}'
274
+ base_url = @@base_url + '/process-groups/' << process_group << '/template-instance'
226
275
  self.class.http_client(base_url, 'POSTRAW', params)
227
276
  end
228
277
 
@@ -231,27 +280,27 @@ class Nifi
231
280
  args = args.reduce Hash.new, :merge
232
281
 
233
282
  if args[:path].nil?
234
- abort 'path params is mandatory.'
283
+ raise ArgumentError.new('path params is mandatory.')
235
284
  end
236
285
  path = args[:path]
237
286
 
238
287
  if path =~ URI::regexp
239
288
 
240
289
  download_s = open(path)
241
- download_t = "/tmp/#{download_s.base_uri.to_s.split('/')[-1]}"
290
+ download_t = '/tmp/' << download_s.base_uri.to_s.split('/')[-1]
242
291
  IO.copy_stream(download_s, download_t)
243
292
  path = download_t
244
293
  end
245
294
 
246
295
  if not File.file? path or not File.readable? path
247
- abort "Access to #{path} failed"
296
+ raise IOError.new('Access to ' <<path << ' failed')
248
297
  end
249
298
 
250
299
  t = File.open(path) { |f| Nokogiri::XML(f) }
251
300
  name = t.xpath('//template/name').text
252
301
 
253
302
  if self.template_by_name? name
254
- abort 'The template ' + name + ' already exists'
303
+ raise StandardError.new('The template ' << name << ' already exists')
255
304
  end
256
305
 
257
306
  params = Array.new
@@ -259,7 +308,7 @@ class Nifi
259
308
 
260
309
  process_group = args[:id] ? args[:id] : 'root'
261
310
 
262
- base_url = @@base_url + "/process-groups/#{process_group}/templates/upload"
311
+ base_url = @@base_url + '/process-groups/' << process_group << '/templates/upload'
263
312
  res = self.class.http_client(base_url, 'POST', params)
264
313
 
265
314
  return res['templateEntity']['template']
@@ -268,17 +317,17 @@ class Nifi
268
317
  def delete_template(id = nil)
269
318
 
270
319
  if id.nil?
271
- abort 'id is mandatory.'
320
+ raise ArgumentError.new('id is mandatory.')
272
321
  end
273
322
 
274
- base_url = @@base_url + '/templates/' + id
323
+ base_url = @@base_url + '/templates/' << id
275
324
  self.class.http_client(base_url, 'DELETE')
276
325
  end
277
326
 
278
327
  def get_template_by_name(name = nil)
279
328
 
280
329
  if name.nil?
281
- abort 'name is mandatory.'
330
+ raise ArgumentError.new('name is mandatory.')
282
331
  end
283
332
 
284
333
  res = self.class.exists
@@ -291,7 +340,7 @@ class Nifi
291
340
  if t.count == 1
292
341
  t[0]['identifier'].scan(/\/templates\/(.*)/)
293
342
  else
294
- abort 'Unable to locate template with name ' + name
343
+ raise StandardError.new('Unable to locate template with name ' << name)
295
344
  end
296
345
 
297
346
  end
@@ -299,7 +348,7 @@ class Nifi
299
348
  def template_by_name?(name = nil)
300
349
 
301
350
  if name.nil?
302
- abort 'name is mandatory.'
351
+ raise ArgumentError.new('name is mandatory.')
303
352
  end
304
353
 
305
354
  res = self.class.exists
@@ -314,13 +363,13 @@ class Nifi
314
363
  def template_by_id?(id = nil)
315
364
 
316
365
  if id.nil?
317
- abort 'id is mandatory.'
366
+ raise ArgumentError.new('id is mandatory.')
318
367
  end
319
368
 
320
369
  res = self.class.exists
321
370
 
322
371
  pg = res.select do |r|
323
- r['identifier'] == "/templates/#{id}"
372
+ r['identifier'] == '/templates/' << id
324
373
  end
325
374
 
326
375
  pg.count == 1 ? true : false
@@ -329,9 +378,8 @@ class Nifi
329
378
  private
330
379
 
331
380
  def self.exists
332
- base_url = @@base_url + "/resources"
381
+ base_url = @@base_url + '/resources'
333
382
  res = self.http_client(base_url)
334
-
335
383
  return res['resources']
336
384
  end
337
385
 
@@ -346,7 +394,7 @@ class Nifi
346
394
  #c.username = @@api_key
347
395
  #c.password = ''
348
396
  c.url = url
349
- c.useragent = @@sdk_name + '_' + @@sdk_version
397
+ c.useragent = @@sdk_name + '_' << @@sdk_version
350
398
  c.headers['NIFI-SDK-Name'] = @@sdk_name
351
399
  c.headers['NIFI-SDK-Version'] = @@sdk_version
352
400
  c.ssl_verify_peer = false
@@ -367,7 +415,7 @@ class Nifi
367
415
  when 'DELETE'
368
416
  c.delete
369
417
  else
370
- abort 'HTTP method not supported.'
418
+ raise ArgumentError.new('HTTP method ' << method << ' not supported.')
371
419
  end
372
420
 
373
421
  if c.response_code.to_s.match(/20./) and not c.body_str.empty?
@@ -379,8 +427,8 @@ class Nifi
379
427
  end
380
428
  end
381
429
  else
430
+ puts c.response_code.to_s
382
431
  puts c.body_str
383
432
  end
384
433
  end
385
- end
386
-
434
+ end
@@ -1,3 +1,3 @@
1
1
  module NifiSdkRuby
2
- VERSION = "0.0.4"
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nifi_sdk_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Israel Calvete
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-04 00:00:00.000000000 Z
11
+ date: 2017-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -142,6 +142,7 @@ files:
142
142
  - lib/nifi_sdk_ruby.rb
143
143
  - lib/nifi_sdk_ruby/version.rb
144
144
  - nifi_sdk_ruby.gemspec
145
+ - pkg/.gitkeep
145
146
  - release.md
146
147
  homepage: http://rubygems.org/gems/nifi-sdk-ruby
147
148
  licenses:
@@ -163,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
164
  version: '0'
164
165
  requirements: []
165
166
  rubyforge_project:
166
- rubygems_version: 2.5.1
167
+ rubygems_version: 2.6.11
167
168
  signing_key:
168
169
  specification_version: 4
169
170
  summary: A RUBY SDK to use APACHE NIFI API