nifi_sdk_ruby 0.0.1 → 0.0.2

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/examples/basic.rb CHANGED
@@ -6,16 +6,41 @@ nifi_client = Nifi.new()
6
6
  nifi_client.set_debug(true)
7
7
 
8
8
  # Get the ID of Root Process Group
9
- pg_root_id = nifi_client.get_process_group(:attr => 'id')
9
+ pg_root = nifi_client.get_process_group()
10
10
  puts "\n"
11
11
  puts "PG Root's ID"
12
12
  puts "\n"
13
- puts pg_root_id
13
+ puts pg_root['id']
14
14
  puts "\n"
15
15
 
16
- # Get all attrs of the Process Group with ID 9c3ebb60-015b-1000-1027-b27d47832152 (PG Root's child)
17
- some_pg = nifi_client.get_process_group(:pg_id => '9c3ebb60-015b-1000-1027-b27d47832152')
18
- puts "PG 9c3ebb60-015b-1000-1027-b27d47832152`s attrs"
16
+ # Create new Process Group
17
+ puts "Create new PG"
19
18
  puts "\n"
20
- puts some_pg
19
+ new_pg = nifi_client.create_process_group(:name => 'test')
21
20
  puts "\n"
21
+ puts new_pg
22
+ puts "\n"
23
+
24
+ # Get all attrs of the Process Group by ID (PG Root's child)
25
+ puts 'PG ' + new_pg['id'] + ' attrs.'
26
+ puts "\n"
27
+ puts nifi_client.get_process_group(:id => new_pg['id'])
28
+ puts "\n"
29
+
30
+ # Get a Process Group ID
31
+ puts "PG ID"
32
+ puts "\n"
33
+ pg = nifi_client.get_process_group(:id => new_pg['id'])
34
+ puts pg['id']
35
+ puts "\n"
36
+
37
+ # Delete some Process Group
38
+ puts 'Delete PG with id ' + new_pg['id']
39
+ puts "\n"
40
+ puts nifi_client.delete_process_group(new_pg['id'])
41
+ puts "\n"
42
+
43
+ # Upload a template to Root Process Group
44
+ puts 'Upload templete to Root PG'
45
+ puts nifi_client.upload_template(:path => 'IN.hmStaff.taskStatus.xml')
46
+
@@ -1,3 +1,3 @@
1
1
  module NifiSdkRuby
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/nifi_sdk_ruby.rb CHANGED
@@ -5,6 +5,8 @@ require 'pp' if ENV['DEBUG']
5
5
  require 'httparty'
6
6
  require 'curb'
7
7
  require 'json'
8
+ require 'securerandom'
9
+ require 'active_support/all'
8
10
 
9
11
  class Nifi
10
12
 
@@ -23,6 +25,7 @@ class Nifi
23
25
  @@async
24
26
  @@sdk_name
25
27
  @@sdk_version
28
+ @@client_id
26
29
 
27
30
  def initialize(*args)
28
31
 
@@ -36,6 +39,7 @@ class Nifi
36
39
  @@async = DEFAULT_ACYNC
37
40
  @@sdk_name = 'ruby'
38
41
  @@sdk_version = NifiSdkRuby::VERSION
42
+ @@client_id = SecureRandom.uuid
39
43
  end
40
44
 
41
45
  def set_debug(debug = nil)
@@ -90,16 +94,57 @@ class Nifi
90
94
 
91
95
  args = args.reduce Hash.new, :merge
92
96
 
93
- process_group = args[:pg_id] ? args[:pg_id] : 'root'
97
+ process_group = args[:id] ? args[:id] : 'root'
94
98
 
95
99
  base_url = @@base_url + "/process-groups/#{process_group}"
96
- res = self.class.http_client(base_url)
100
+ self.class.http_client(base_url)
101
+ end
102
+
103
+ def create_process_group(*args)
104
+ args = args.reduce Hash.new, :merge
105
+
106
+ if args[:name].nil?
107
+ abort 'name params is mandatory.'
108
+ end
97
109
 
98
- if args[:attr]
99
- return res[args[:attr]]
110
+ params = '{"revision":{"clientId":"' + @@client_id + '","version":0},"component":{"name":"' + args[:name] + '","position":{"x":274.54776144527517,"y":-28.886681059739686}}}'
111
+
112
+ process_group = args[:id] ? args[:id] : 'root'
113
+ base_url = @@base_url + "/process-groups/#{process_group}/process-groups"
114
+ self.class.http_client(base_url, 'POSTRAW', params)
115
+ end
116
+
117
+ def delete_process_group(id = nil)
118
+
119
+ if id.nil?
120
+ abort 'id is mandatory.'
100
121
  end
101
122
 
102
- return res
123
+ base_url = @@base_url + '/process-groups/' + id + '?clientId=' + @@client_id + '&version=1'
124
+ self.class.http_client(base_url, 'DELETE')
125
+ end
126
+
127
+ def upload_template(*args)
128
+
129
+ args = args.reduce Hash.new, :merge
130
+
131
+ if args[:path].nil?
132
+ abort 'path params is mandatory.'
133
+ end
134
+ path = args[:path]
135
+
136
+ if not File.file? path or not File.readable? path
137
+ abort "Access to #{path} failed"
138
+ end
139
+ params = Array.new
140
+ params << Curl::PostField.file('template', path)
141
+
142
+ process_group = args[:id] ? args[:id] : 'root'
143
+
144
+ base_url = @@base_url + "/process-groups/#{process_group}/templates/upload"
145
+ res = self.class.http_client(base_url, 'POST', params)
146
+
147
+ return res['templateEntity']['template']
103
148
  end
104
149
 
105
150
  private
@@ -120,6 +165,7 @@ class Nifi
120
165
  when 'GET'
121
166
  c.get
122
167
  when 'POSTRAW'
168
+ c.headers['Content-Type'] = 'application/json'
123
169
  c.post(params)
124
170
  when 'POST'
125
171
  c.multipart_form_post = true
@@ -133,7 +179,13 @@ class Nifi
133
179
  end
134
180
 
135
181
  if c.response_code.to_s.match(/20./) and not c.body_str.empty?
136
- JSON.parse(c.body_str)
182
+ begin
183
+ JSON.parse(c.body_str)
184
+ rescue
185
+ if c.content_type == 'application/xml'
186
+ JSON.parse(Hash.from_xml(c.body_str).to_json)
187
+ end
188
+ end
137
189
  else
138
190
  puts c.body_str
139
191
  end
@@ -23,6 +23,7 @@ Gem::Specification.new do |gem|
23
23
  gem.add_dependency 'httparty', '>= 0.14.0'
24
24
  gem.add_dependency 'curb', '>= 0.9.3'
25
25
  gem.add_dependency 'json', '>= 1.8.3'
26
+ gem.add_dependency 'activesupport', '>= 5.0.2'
26
27
 
27
28
  gem.add_development_dependency "bundler", "~> 1.14"
28
29
  gem.add_development_dependency "rake", "~> 10.0"
data/pkg/.gitkeep ADDED
File without changes
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.1
4
+ version: 0.0.2
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-24 00:00:00.000000000 Z
11
+ date: 2017-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.8.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 5.0.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 5.0.2
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -101,6 +115,7 @@ executables: []
101
115
  extensions: []
102
116
  extra_rdoc_files: []
103
117
  files:
118
+ - ".gitignore"
104
119
  - CODE_OF_CONDUCT.md
105
120
  - Gemfile
106
121
  - LICENSE.txt
@@ -108,10 +123,12 @@ files:
108
123
  - Rakefile
109
124
  - bin/console
110
125
  - bin/setup
126
+ - examples/IN.hmStaff.taskStatus.xml
111
127
  - examples/basic.rb
112
128
  - lib/nifi_sdk_ruby.rb
113
129
  - lib/nifi_sdk_ruby/version.rb
114
130
  - nifi_sdk_ruby.gemspec
131
+ - pkg/.gitkeep
115
132
  - release.md
116
133
  homepage: http://rubygems.org/gems/nifi-sdk-ruby
117
134
  licenses: