nifi_sdk_ruby 0.0.2 → 0.0.3

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: 5bb97fd650f0de430ee1b893f5abff6bf28c59f1
4
- data.tar.gz: 049c9dc2772ee4c9acd83b1ae8f69e686f522a0a
3
+ metadata.gz: be48d97b56f690c502c1b8723c4867461ec0798c
4
+ data.tar.gz: 6a77e0569fb024980fb3fca6c00eb53f04060266
5
5
  SHA512:
6
- metadata.gz: 284592edc6779800145e9150086f513210c7e67bb96ab5c985afe075321d9b40e650f57120cc1ae15a0a646b51f10291deed51fc0588f62b3774b15993922609
7
- data.tar.gz: 28e7e0e03ded209b4458a65e69ab0df00cb686f384e0e2f8387a1f1b347281b8f3bbb1e1722416a7536cbd1eb64114e2a9f7b45b475740aa5de4df97fd4975c6
6
+ metadata.gz: a9edf3dbce0917300ed3fbb1e44e7274656d1623ecca087d7f55a917c49676c5f7757f1e24ee05b10a37a0ab3b76c41f989ee71d6299219e1d76114107bd8793
7
+ data.tar.gz: 1fd9b45e1e7dea96ece0f062cacd638bf46cab9a319ec46c14e214cd3a9eec92c67881491f4533966e02c65ffd1d891acf20e7a357b3477eba65879c1a2e7f2e
data/README.md CHANGED
@@ -30,44 +30,83 @@ Or install it yourself as:
30
30
  require 'nifi_sdk_ruby'
31
31
 
32
32
  nifi_client = Nifi.new()
33
- nifi_client.set_debug(true)
33
+ nifi_client.set_debug true
34
34
 
35
35
  ```
36
36
 
37
- ### Get root id
37
+ ### Get Root's Process Group id
38
38
 
39
39
  ```ruby
40
40
  # Get Root Process Group
41
- pg_root = nifi_client.get_process_group()
41
+ pg_root = nifi_client.get_process_group
42
42
  puts "PG Root's ID"
43
43
  puts pg_root['id']
44
44
  ```
45
45
 
46
- ### Create new PG
46
+ ### Create new Process Group
47
47
 
48
48
  ```ruby
49
49
  new_pg = nifi_client.create_process_group(:name => 'test')
50
50
  puts new_pg
51
51
  ```
52
52
 
53
- ### Get all attrs of the Process Group with ID 9c3ebb60-015b-1000-1027-b27d47832152 (PG Root's child)
53
+ ### Check if Process Group exists
54
+
55
+ ```ruby
56
+ puts nifi_client.process_group_by_name? test
57
+ ```
58
+
59
+ ### Get all attrs a the Process Group by ID (PG Root's child)
54
60
 
55
61
  ```ruby
56
62
  puts nifi_client.get_process_group(:id => new_pg['id'])
57
63
  ```
58
64
 
59
- ### Delete some PG
65
+ ### Get all attrs a the Process Group by Name (Root's childs)
66
+
67
+ ```ruby
68
+ puts nifi_client.get_process_group_by_name 'test'
69
+ ```
70
+
71
+ ### Delete some Process Group
60
72
 
61
73
  ```ruby
62
74
  puts nifi_client.delete_process_group(new_pg['id'])
63
75
  ```
64
76
 
65
- # Upload a template to Root PG
77
+ ### Upload a template to Root Process Group
78
+
79
+ From file ...
66
80
 
67
81
  ```ruby
68
82
  puts nifi_client.upload_template(:path => 'IN.hmStaff.taskStatus.xml')
69
83
  ```
70
84
 
85
+ From url ...
86
+
87
+ ```ruby
88
+ puts nifi_client.upload_template(:path => 'https://your.domain.net/IN.hmStaff.taskStatus.xml')
89
+ ```
90
+
91
+ ### Check if Process Group exists
92
+
93
+ ```ruby
94
+ puts nifi_client.template_by_name? test
95
+ ```
96
+
97
+
98
+ ### Get all attrs of a template by Name (Root's childs)
99
+
100
+ ```ruby
101
+ t = nifi_client.get_template_group_by_name 'test'
102
+ puts t
103
+ ```
104
+
105
+ ### Delete template
106
+ ```ruby
107
+ puts nifi_client.delete_template t['id']
108
+ ```
109
+
71
110
  ## Contributing
72
111
 
73
112
  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
@@ -3,10 +3,10 @@ require 'pp'
3
3
  require '../lib/nifi_sdk_ruby'
4
4
 
5
5
  nifi_client = Nifi.new()
6
- nifi_client.set_debug(true)
6
+ nifi_client.set_debug true
7
7
 
8
8
  # Get the ID of Root Process Group
9
- pg_root = nifi_client.get_process_group()
9
+ pg_root = nifi_client.get_process_group
10
10
  puts "\n"
11
11
  puts "PG Root's ID"
12
12
  puts "\n"
@@ -37,10 +37,9 @@ puts "\n"
37
37
  # Delete some Process Group
38
38
  puts 'Delete PG with id ' + new_pg['id']
39
39
  puts "\n"
40
- puts nifi_client.delete_process_group(new_pg['id'])
40
+ puts nifi_client.delete_process_group new_pg['id']
41
41
  puts "\n"
42
42
 
43
43
  # Upload a template to Root Process Group
44
- puts 'Upload templete to Root PG'
44
+ puts 'Upload template to Root PG'
45
45
  puts nifi_client.upload_template(:path => 'IN.hmStaff.taskStatus.xml')
46
-
data/lib/nifi_sdk_ruby.rb CHANGED
@@ -7,6 +7,8 @@ require 'curb'
7
7
  require 'json'
8
8
  require 'securerandom'
9
9
  require 'active_support/all'
10
+ require 'open-uri'
11
+ require 'nokogiri'
10
12
 
11
13
  class Nifi
12
14
 
@@ -107,6 +109,10 @@ class Nifi
107
109
  abort 'name params is mandatory.'
108
110
  end
109
111
 
112
+ if self.process_group_by_name? args[:name]
113
+ abort 'The process group ' + args[:name] + ' already exists'
114
+ end
115
+
110
116
  params = '{"revision":{"clientId":"' + @@client_id + '","version":0},"component":{"name":"' + args[:name] + '","position":{"x":274.54776144527517,"y":-28.886681059739686}}}'
111
117
 
112
118
  process_group = args[:id] ? args[:id] : 'root'
@@ -124,18 +130,68 @@ class Nifi
124
130
  self.class.http_client(base_url, 'DELETE')
125
131
  end
126
132
 
133
+ def get_process_group_by_name(name = nil)
134
+
135
+ if name.nil?
136
+ abort 'name is mandatory.'
137
+ end
138
+
139
+ res = self.class.exists
140
+
141
+ pg = res.select do |r|
142
+ r['name'] == name and r['identifier'] =~ /process-groups/
143
+ end
144
+
145
+ if pg.count == 1
146
+ self.class.get pg[0]['identifier']
147
+ else
148
+ abort 'Unable to locate group with name ' + name
149
+ end
150
+ end
151
+
152
+ def process_group_by_name?(name = nil)
153
+
154
+ if name.nil?
155
+ abort 'name is mandatory.'
156
+ end
157
+
158
+ res = self.class.exists
159
+
160
+ pg = res.select do |r|
161
+ r['name'] == name and r['identifier'] =~ /process-groups/
162
+ end
163
+
164
+ pg.count == 1 ? true : false
165
+ end
166
+
127
167
  def upload_template(*args)
128
168
 
129
169
  args = args.reduce Hash.new, :merge
130
-
170
+
131
171
  if args[:path].nil?
132
172
  abort 'path params is mandatory.'
133
173
  end
134
174
  path = args[:path]
135
175
 
176
+ if path =~ URI::regexp
177
+
178
+ download_s = open(path)
179
+ download_t = "/tmp/#{download_s.base_uri.to_s.split('/')[-1]}"
180
+ IO.copy_stream(download_s, download_t)
181
+ path = download_t
182
+ end
183
+
136
184
  if not File.file? path or not File.readable? path
137
185
  abort "Access to #{path} failed"
138
186
  end
187
+
188
+ t = File.open(path) { |f| Nokogiri::XML(f) }
189
+ name = t.xpath('//template/name').text
190
+
191
+ if self.template_by_name? name
192
+ abort 'The template ' + name + ' already exists'
193
+ end
194
+
139
195
  params = Array.new
140
196
  params << Curl::PostField.file('template', path)
141
197
 
@@ -147,8 +203,66 @@ class Nifi
147
203
  return res['templateEntity']['template']
148
204
  end
149
205
 
206
+ def delete_template(id = nil)
207
+
208
+ if id.nil?
209
+ abort 'id is mandatory.'
210
+ end
211
+
212
+ base_url = @@base_url + '/templates/' + id
213
+ self.class.http_client(base_url, 'DELETE')
214
+ end
215
+
216
+ def get_template_by_name(name = nil)
217
+
218
+ if name.nil?
219
+ abort 'name is mandatory.'
220
+ end
221
+
222
+ res = self.class.exists
223
+
224
+ t = res.select do |r|
225
+ r['name'] == name and r['identifier'] =~ /templates/
226
+ end
227
+
228
+
229
+ if t.count == 1
230
+ t[0]['identifier'].scan(/\/templates\/(.*)/)
231
+ else
232
+ abort 'Unable to locate template with name ' + name
233
+ end
234
+
235
+ end
236
+
237
+ def template_by_name?(name = nil)
238
+
239
+ if name.nil?
240
+ abort 'name is mandatory.'
241
+ end
242
+
243
+ res = self.class.exists
244
+
245
+ pg = res.select do |r|
246
+ r['name'] == name and r['identifier'] =~ /templates/
247
+ end
248
+
249
+ pg.count == 1 ? true : false
250
+ end
251
+
150
252
  private
151
253
 
254
+ def self.exists
255
+ base_url = @@base_url + "/resources"
256
+ res = self.http_client(base_url)
257
+
258
+ return res['resources']
259
+ end
260
+
261
+ def self.get(resource)
262
+ base_url = @@base_url + resource
263
+ self.http_client(base_url)
264
+ end
265
+
152
266
  def self.http_client(url, method = 'GET', params = nil, filename = nil)
153
267
  c = Curl::Easy.new
154
268
  #c.http_auth_types = :basic
@@ -1,3 +1,3 @@
1
1
  module NifiSdkRuby
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -24,6 +24,7 @@ Gem::Specification.new do |gem|
24
24
  gem.add_dependency 'curb', '>= 0.9.3'
25
25
  gem.add_dependency 'json', '>= 1.8.3'
26
26
  gem.add_dependency 'activesupport', '>= 5.0.2'
27
+ gem.add_dependency 'nokogiri', '>= 1.6.7.2'
27
28
 
28
29
  gem.add_development_dependency "bundler", "~> 1.14"
29
30
  gem.add_development_dependency "rake", "~> 10.0"
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.2
4
+ version: 0.0.3
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-04-25 00:00:00.000000000 Z
11
+ date: 2017-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 5.0.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.6.7.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.6.7.2
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement