legion-transport 0.1.0 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +53 -80
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +3 -9
  5. data/CHANGELOG.md +9 -0
  6. data/Gemfile +0 -1
  7. data/README.md +3 -0
  8. data/bitbucket-pipelines.yml +1 -1
  9. data/legion-transport.gemspec +19 -14
  10. data/lib/legion/transport.rb +12 -10
  11. data/lib/legion/transport/common.rb +23 -18
  12. data/lib/legion/transport/connection.rb +56 -12
  13. data/lib/legion/transport/consumer.rb +8 -1
  14. data/lib/legion/transport/exchange.rb +44 -6
  15. data/lib/legion/transport/exchanges/crypt.rb +11 -0
  16. data/lib/legion/transport/exchanges/node.rb +11 -0
  17. data/lib/legion/transport/message.rb +100 -2
  18. data/lib/legion/transport/messages/check_subtask.rb +25 -0
  19. data/lib/legion/transport/messages/dynamic.rb +25 -0
  20. data/lib/legion/transport/messages/lex_register.rb +11 -19
  21. data/lib/legion/transport/messages/node_health.rb +21 -0
  22. data/lib/legion/transport/messages/request_cluster_secret.rb +33 -0
  23. data/lib/legion/transport/messages/subtask.rb +38 -0
  24. data/lib/legion/transport/messages/task_log.rb +36 -0
  25. data/lib/legion/transport/messages/task_update.rb +3 -24
  26. data/lib/legion/transport/queue.rb +65 -6
  27. data/lib/legion/transport/queues/node.rb +15 -0
  28. data/lib/legion/transport/queues/node_crypt.rb +21 -0
  29. data/lib/legion/transport/queues/node_status.rb +1 -1
  30. data/lib/legion/transport/queues/task_log.rb +1 -1
  31. data/lib/legion/transport/queues/task_update.rb +1 -1
  32. data/lib/legion/transport/settings.rb +72 -0
  33. data/lib/legion/transport/version.rb +1 -1
  34. data/settings/transport.json +5 -1
  35. data/sonar-project.properties +12 -0
  36. metadata +93 -49
  37. data/lib/legion/transport/connections/bunny.rb +0 -53
  38. data/lib/legion/transport/connections/common.rb +0 -36
  39. data/lib/legion/transport/connections/marchhare.rb +0 -20
  40. data/lib/legion/transport/consumers/bunny.rb +0 -11
  41. data/lib/legion/transport/consumers/common.rb +0 -8
  42. data/lib/legion/transport/consumers/marchhare.rb +0 -11
  43. data/lib/legion/transport/exchanges/bunny.rb +0 -28
  44. data/lib/legion/transport/exchanges/common.rb +0 -32
  45. data/lib/legion/transport/exchanges/marchhare.rb +0 -17
  46. data/lib/legion/transport/messages/base.rb +0 -22
  47. data/lib/legion/transport/messages/node_status.rb +0 -49
  48. data/lib/legion/transport/messages/task_check_subtask.rb +0 -35
  49. data/lib/legion/transport/messages/task_subtask.rb +0 -45
  50. data/lib/legion/transport/queues/bunny.rb +0 -26
  51. data/lib/legion/transport/queues/common.rb +0 -45
  52. data/lib/legion/transport/queues/marchhare.rb +0 -26
@@ -1,13 +1,72 @@
1
1
  module Legion
2
2
  module Transport
3
- if RUBY_ENGINE == 'jruby'
4
- require 'legion/transport/queues/marchhare'
5
- class Queue < Legion::Transport::Queues::Marchhare
3
+ class Queue < Legion::Transport::CONNECTOR::Queue
4
+ include Legion::Transport::Common
5
+
6
+ def initialize(queue = queue_name, options = {})
7
+ retries ||= 0
8
+ @options = options
9
+ super(channel, queue, options_builder(default_options, queue_options, options))
10
+ rescue ::Bunny::PreconditionFailed
11
+ retries.zero? ? retries = 1 : raise
12
+ recreate_queue(channel, queue)
13
+ retry
6
14
  end
7
- else
8
- require 'legion/transport/queues/bunny'
9
- class Queue < Legion::Transport::Queues::Bunny
15
+
16
+ def recreate_queue(channel, queue)
17
+ Legion::Logging.warn "Queue:#{queue} exists with wrong parameters, deleting and creating"
18
+ queue = ::Bunny::Queue.new(channel, queue, no_declare: true, passive: true)
19
+ queue.delete(if_empty: true)
20
+ end
21
+
22
+ def default_options
23
+ hash = {}
24
+ hash[:manual_ack] = true
25
+ hash[:durable] = true
26
+ hash[:exclusive] = false
27
+ hash[:block] = false
28
+ hash[:auto_delete] = false
29
+ hash[:arguments] = {
30
+ 'x-max-priority': 255,
31
+ 'x-overflow': 'reject-publish',
32
+ 'x-dead-letter-exchange': "#{self.class.ancestors.first.to_s.split('::')[2].downcase}.dlx"
33
+ }
34
+ hash
35
+ end
36
+
37
+ def queue_options
38
+ {}
39
+ end
40
+
41
+ def queue_name
42
+ ancestor = self.class.ancestors.first.to_s.split('::')
43
+ name = if ancestor[5].scan(/[A-Z]/).length > 1
44
+ ancestor[5].gsub!(/(.)([A-Z])/, '\1_\2').downcase!
45
+ else
46
+ ancestor[5].downcase!
47
+ end
48
+ "#{ancestor[2].downcase}.#{name}"
49
+ end
50
+
51
+ def delete(options = { if_unused: true, if_empty: true })
52
+ super(options)
53
+ true
54
+ rescue ::Bunny::PreconditionFailed
55
+ false
56
+ end
57
+
58
+ def acknowledge(delivery_tag)
59
+ channel.acknowledge(delivery_tag)
60
+ end
61
+
62
+ def reject(delivery_tag, requeue: false)
63
+ channel.reject(delivery_tag, requeue)
10
64
  end
11
65
  end
12
66
  end
13
67
  end
68
+
69
+ require_relative 'queues/node'
70
+ require_relative 'queues/node_status'
71
+ require_relative 'queues/task_log'
72
+ require_relative 'queues/task_update'
@@ -0,0 +1,15 @@
1
+ module Legion
2
+ module Transport
3
+ module Queues
4
+ class Node < Legion::Transport::Queue
5
+ def queue_name
6
+ "node.#{Legion::Settings['client']['name']}"
7
+ end
8
+
9
+ def queue_options
10
+ { durable: false, auto_delete: true, arguments: { 'x-dead-letter-exchange': 'node.dlx' } }
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ module Legion
2
+ module Transport
3
+ module Queues
4
+ class NodeCrypt < Legion::Transport::Queue
5
+ def queue_name
6
+ 'node.status'
7
+ end
8
+
9
+ def queue_options
10
+ hash = {}
11
+ hash[:manual_ack] = true
12
+ hash[:durable] = true
13
+ hash[:exclusive] = false
14
+ hash[:block] = false
15
+ hash[:arguments] = { 'x-dead-letter-exchange': 'node.dlx' }
16
+ hash
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -12,7 +12,7 @@ module Legion
12
12
  hash[:durable] = true
13
13
  hash[:exclusive] = false
14
14
  hash[:block] = false
15
- hash[:arguments] = {}
15
+ hash[:arguments] = { 'x-dead-letter-exchange': 'node.dlx' }
16
16
  hash
17
17
  end
18
18
  end
@@ -12,7 +12,7 @@ module Legion
12
12
  hash[:durable] = true
13
13
  hash[:exclusive] = false
14
14
  hash[:block] = false
15
- hash[:arguments] = { 'x-max-priority': 255 }
15
+ hash[:arguments] = { 'x-max-priority': 255, 'x-dead-letter-exchange': 'task.dlx' }
16
16
  hash
17
17
  end
18
18
  end
@@ -12,7 +12,7 @@ module Legion
12
12
  hash[:durable] = true
13
13
  hash[:exclusive] = false
14
14
  hash[:block] = false
15
- hash[:arguments] = { 'x-max-priority': 252, 'x-dead-letter-exchange': 'task.dlx' }
15
+ hash[:arguments] = { 'x-dead-letter-exchange': 'task.dlx' }
16
16
  hash
17
17
  end
18
18
  end
@@ -0,0 +1,72 @@
1
+ require 'legion/settings'
2
+
3
+ module Legion
4
+ module Transport
5
+ module Settings
6
+ # Legion::Settings.merge_settings('transport', default) if Legion::Settings.method_defined? :merge_settings
7
+ def self.connection
8
+ {
9
+ read_timeout: 1,
10
+ heartbeat: 1,
11
+ automatically_recover: true,
12
+ continuation_timeout: 4000,
13
+ network_recovery_interval: 1,
14
+ connection_timeout: 1,
15
+ user: 'guest',
16
+ password: 'guest',
17
+ host: '127.0.0.1',
18
+ port: '5672',
19
+ vhost: '/',
20
+ recovery_attempts: 0,
21
+ logger_level: 'info'
22
+ }.merge(grab_vault_creds)
23
+ end
24
+
25
+ def self.grab_vault_creds
26
+ return {} unless Legion::Settings[:crypt][:vault][:connected]
27
+
28
+ lease = Legion::Crypt.read('rabbitmq/creds/legion', type: nil)
29
+ Legion::Logging.debug 'successfully grabbed amqp username from Vault'
30
+ { user: lease[:username], password: lease[:password] }
31
+ rescue StandardError
32
+ {}
33
+ end
34
+
35
+ def self.default
36
+ {
37
+ type: 'rabbitmq',
38
+ connected: false,
39
+ logger_level: 'info',
40
+ messages: {
41
+ encrypt: false,
42
+ ttl: nil,
43
+ priority: 0
44
+ },
45
+ exchanges: {
46
+ type: 'topic',
47
+ arguments: {},
48
+ auto_delete: false,
49
+ durable: true,
50
+ internal: false
51
+ },
52
+ queues: {
53
+ manual_ack: true,
54
+ durable: true,
55
+ exclusive: false,
56
+ block: false,
57
+ auto_delete: false,
58
+ arguments: { 'x-max-priority': 255, 'x-overflow': 'reject-publish' }
59
+ },
60
+ prefetch: 2,
61
+ connection: connection
62
+ }
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ begin
69
+ Legion::Settings.merge_settings('transport', Legion::Transport::Settings.default) if Legion.const_defined?('Settings')
70
+ rescue StandardError => e
71
+ Legion::Logging.fatal(e.message) if Legion::Logging.method_defined?(:fatal)
72
+ end
@@ -1,5 +1,5 @@
1
1
  module Legion
2
2
  module Transport
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '1.1.3'.freeze
4
4
  end
5
5
  end
@@ -1 +1,5 @@
1
- {}
1
+ {
2
+ "transport": {
3
+ "vhost": "/"
4
+ }
5
+ }
@@ -0,0 +1,12 @@
1
+ sonar.projectKey=legion-io_legion-transport
2
+ sonar.organization=legion-io
3
+ sonar.projectName=Legion::Transport
4
+ sonar.sources=.
5
+ sonar.exclusions=vendor/**
6
+ sonar.coverage.exclusions=spec/**
7
+ sonar.ruby.coverage.reportPath=coverage/.resultset.json
8
+ sonar.ruby.file.suffixes=rb,ruby
9
+ sonar.ruby.coverage.framework=RSpec
10
+ sonar.ruby.rubocopConfig=.rubocop.yml
11
+ sonar.ruby.rubocop.reportPath=rubocop-result.json
12
+ sonar.ruby.rubocop.filePath=.
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legion-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esity
8
- autorequire:
9
- bindir: exe
8
+ autorequire:
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-08 00:00:00.000000000 Z
11
+ date: 2020-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: codecov
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,34 +38,62 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: legion-logging
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: legion-settings
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rake
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
- - - "~>"
73
+ - - ">="
46
74
  - !ruby/object:Gem::Version
47
- version: '10.0'
75
+ version: '0'
48
76
  type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
- - - "~>"
80
+ - - ">="
53
81
  - !ruby/object:Gem::Version
54
- version: '10.0'
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rspec
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
- - - "~>"
87
+ - - ">="
60
88
  - !ruby/object:Gem::Version
61
- version: '3.0'
89
+ version: '0'
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
- - - "~>"
94
+ - - ">="
67
95
  - !ruby/object:Gem::Version
68
- version: '3.0'
96
+ version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: rspec_junit_formatter
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -95,19 +123,19 @@ dependencies:
95
123
  - !ruby/object:Gem::Version
96
124
  version: '0'
97
125
  - !ruby/object:Gem::Dependency
98
- name: legion-settings
126
+ name: simplecov
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
- - - "~>"
129
+ - - ">="
102
130
  - !ruby/object:Gem::Version
103
- version: '0.1'
131
+ version: '0'
104
132
  type: :development
105
133
  prerelease: false
106
134
  version_requirements: !ruby/object:Gem::Requirement
107
135
  requirements:
108
- - - "~>"
136
+ - - ">="
109
137
  - !ruby/object:Gem::Version
110
- version: '0.1'
138
+ version: '0'
111
139
  - !ruby/object:Gem::Dependency
112
140
  name: bunny
113
141
  requirement: !ruby/object:Gem::Requirement
@@ -123,19 +151,33 @@ dependencies:
123
151
  - !ruby/object:Gem::Version
124
152
  version: '0'
125
153
  - !ruby/object:Gem::Dependency
126
- name: legion-logging
154
+ name: concurrent-ruby
127
155
  requirement: !ruby/object:Gem::Requirement
128
156
  requirements:
129
- - - "~>"
157
+ - - ">="
130
158
  - !ruby/object:Gem::Version
131
- version: '0.1'
132
- type: :development
159
+ version: '0'
160
+ type: :runtime
133
161
  prerelease: false
134
162
  version_requirements: !ruby/object:Gem::Requirement
135
163
  requirements:
136
- - - "~>"
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: legion-json
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
137
179
  - !ruby/object:Gem::Version
138
- version: '0.1'
180
+ version: '0'
139
181
  description: The Legion transport gem
140
182
  email:
141
183
  - matthewdiverson@gmail.com
@@ -145,8 +187,11 @@ extra_rdoc_files: []
145
187
  files:
146
188
  - ".circleci/config.yml"
147
189
  - ".gitignore"
190
+ - ".rspec"
148
191
  - ".rubocop.yml"
192
+ - CHANGELOG.md
149
193
  - Gemfile
194
+ - README.md
150
195
  - Rakefile
151
196
  - bin/console
152
197
  - bin/setup
@@ -155,39 +200,39 @@ files:
155
200
  - lib/legion/transport.rb
156
201
  - lib/legion/transport/common.rb
157
202
  - lib/legion/transport/connection.rb
158
- - lib/legion/transport/connections/bunny.rb
159
- - lib/legion/transport/connections/common.rb
160
- - lib/legion/transport/connections/marchhare.rb
161
203
  - lib/legion/transport/consumer.rb
162
- - lib/legion/transport/consumers/bunny.rb
163
- - lib/legion/transport/consumers/common.rb
164
- - lib/legion/transport/consumers/marchhare.rb
165
204
  - lib/legion/transport/exchange.rb
166
- - lib/legion/transport/exchanges/bunny.rb
167
- - lib/legion/transport/exchanges/common.rb
205
+ - lib/legion/transport/exchanges/crypt.rb
168
206
  - lib/legion/transport/exchanges/lex.rb
169
- - lib/legion/transport/exchanges/marchhare.rb
207
+ - lib/legion/transport/exchanges/node.rb
170
208
  - lib/legion/transport/exchanges/task.rb
171
209
  - lib/legion/transport/message.rb
172
- - lib/legion/transport/messages/base.rb
210
+ - lib/legion/transport/messages/check_subtask.rb
211
+ - lib/legion/transport/messages/dynamic.rb
173
212
  - lib/legion/transport/messages/lex_register.rb
174
- - lib/legion/transport/messages/node_status.rb
175
- - lib/legion/transport/messages/task_check_subtask.rb
176
- - lib/legion/transport/messages/task_subtask.rb
213
+ - lib/legion/transport/messages/node_health.rb
214
+ - lib/legion/transport/messages/request_cluster_secret.rb
215
+ - lib/legion/transport/messages/subtask.rb
216
+ - lib/legion/transport/messages/task_log.rb
177
217
  - lib/legion/transport/messages/task_update.rb
178
218
  - lib/legion/transport/queue.rb
179
- - lib/legion/transport/queues/bunny.rb
180
- - lib/legion/transport/queues/common.rb
181
- - lib/legion/transport/queues/marchhare.rb
219
+ - lib/legion/transport/queues/node.rb
220
+ - lib/legion/transport/queues/node_crypt.rb
182
221
  - lib/legion/transport/queues/node_status.rb
183
222
  - lib/legion/transport/queues/task_log.rb
184
223
  - lib/legion/transport/queues/task_update.rb
224
+ - lib/legion/transport/settings.rb
185
225
  - lib/legion/transport/version.rb
186
226
  - settings/transport.json
227
+ - sonar-project.properties
187
228
  homepage: https://bitbucket.org/legion-io/legion-transport
188
229
  licenses: []
189
- metadata: {}
190
- post_install_message:
230
+ metadata:
231
+ bug_tracker_uri: https://legionio.atlassian.net/projects/TRANSPORT/issues
232
+ changelog_uri: https://bitbucket.org/legion-io/legion-transport/src/master/CHANGELOG.md
233
+ homepage_uri: https://bitbucket.org/legion-io/legion-transport
234
+ wiki_uri: https://bitbucket.org/legion-io/legion-transport/wiki/Home
235
+ post_install_message:
191
236
  rdoc_options: []
192
237
  require_paths:
193
238
  - lib
@@ -195,16 +240,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
195
240
  requirements:
196
241
  - - ">="
197
242
  - !ruby/object:Gem::Version
198
- version: '0'
243
+ version: 2.5.0
199
244
  required_rubygems_version: !ruby/object:Gem::Requirement
200
245
  requirements:
201
246
  - - ">="
202
247
  - !ruby/object:Gem::Version
203
248
  version: '0'
204
249
  requirements: []
205
- rubyforge_project:
206
- rubygems_version: 2.7.8
207
- signing_key:
250
+ rubygems_version: 3.1.2
251
+ signing_key:
208
252
  specification_version: 4
209
253
  summary: Used by Legion to connect with RabbitMQ
210
254
  test_files: []