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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8e533b2973535c4763ab30eddf935de8f180e1114dc94c04ca8b1f875ff29ac
4
- data.tar.gz: 595f0dbb65675f616c9485f28433220475ded71a4727e8f3db8f4fc8206449c3
3
+ metadata.gz: aca9d21a2d161f0838dc16ce328d81c3ba42360a777c63e6aa805f6c52502e13
4
+ data.tar.gz: 46af9353894537c81d73a68e01522498181d6d2fb54ae3fcdec465ebb75f8675
5
5
  SHA512:
6
- metadata.gz: 6b1eac97b2775e5d67ff1f27efecf93fa96ab7dc276a5698a1323be276ee0176040eccec771752eee49068a928cce8fa044cb9ddb0d59c603f37c511c913937e
7
- data.tar.gz: 4efa70d6438d27bfb9a9ceda17be7bb63f3f34aca5ff0dfad33186f3d16d70d99fc4aeeeecc227769a098a0118554abca4781ec5c8b37de8f359f928b52e9b25
6
+ metadata.gz: add6818532d2159f4fa2be2a40148694f24511f7ca5095ad4477c9e0b72d70c546b2c7ba7ce6b60b44fa9b538c64e08d032dede1f341bbcb6e1831f541828d0e
7
+ data.tar.gz: 754b708ce889ff36ab763f4f72887895195721a9f5e43bea168e802ad6cde0e3fc813ef9ed7ac2e11d677388777d264fc635b57912376f96dff1b03d71108ce3
@@ -1,116 +1,89 @@
1
- version: 2 # use CircleCI 2.0
1
+ version: 2.1
2
+ orbs:
3
+ ruby: circleci/ruby@0.2.1
4
+ sonarcloud: sonarsource/sonarcloud@1.0.1
5
+
2
6
  jobs:
3
7
  "rubocop":
4
8
  docker:
5
- - image: circleci/ruby:2.4-node
9
+ - image: circleci/ruby:2.7-node
6
10
  steps:
7
11
  - checkout
8
- - run: gem install rubocop
12
+ - ruby/load-cache
13
+ - ruby/install-deps
9
14
  - run:
10
15
  name: Run Rubocop
11
- command: rubocop
12
- - store_test_results:
13
- path: test_results
14
- "ruby-2.3":
16
+ command: bundle exec rubocop
17
+ - ruby/save-cache
18
+ "ruby-two-five":
15
19
  docker:
16
- - image: circleci/ruby:2.3
20
+ - image: circleci/ruby:2.5
17
21
  - image: rabbitmq:3.7
18
22
  steps:
19
23
  - checkout
24
+ - ruby/load-cache
20
25
  - run:
21
- name: Bundle Install
22
- command: bundle install
23
- - run:
24
- name: Run RSpec
25
- command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
26
- when: always
27
- - store_test_results:
28
- path: test-results
29
-
30
- "ruby-2.4":
26
+ name: update bundler
27
+ command: gem update bundler
28
+ - ruby/install-deps
29
+ - ruby/run-tests
30
+ - ruby/save-cache
31
+ "ruby-two-six":
31
32
  docker:
32
- - image: circleci/ruby:2.4-node
33
+ - image: circleci/ruby:2.6
33
34
  - image: rabbitmq:3.7
34
35
  steps:
35
36
  - checkout
37
+ - ruby/load-cache
36
38
  - run:
37
- name: Bundle Install
38
- command: bundle install
39
- - run:
40
- name: Run RSpec
41
- command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
42
- when: always
43
- - store_test_results:
44
- path: test-results
45
- "ruby-2.5":
39
+ name: update bundler
40
+ command: gem update bundler
41
+ - ruby/install-deps
42
+ - ruby/run-tests
43
+ - ruby/save-cache
44
+ "ruby-two-seven":
46
45
  docker:
47
- - image: circleci/ruby:2.5-node
46
+ - image: circleci/ruby:2.7
48
47
  - image: rabbitmq:3.7
49
48
  steps:
50
49
  - checkout
50
+ - ruby/load-cache
51
51
  - run:
52
- name: Bundle Install
53
- command: bundle install
54
- - run:
55
- name: Run RSpec
56
- command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
57
- when: always
58
- - store_test_results:
59
- path: test-results
60
- "ruby-2.6":
52
+ name: update bundler
53
+ command: gem update bundler
54
+ - ruby/install-deps
55
+ - ruby/run-tests
56
+ - ruby/save-cache
57
+ "sonarcloud":
61
58
  docker:
62
- - image: circleci/ruby:2.6-node
59
+ - image: circleci/ruby:2.7
63
60
  - image: rabbitmq:3.7
64
61
  steps:
65
62
  - checkout
63
+ - ruby/load-cache
64
+ - ruby/install-deps
65
+ - ruby/run-tests
66
66
  - run:
67
- name: Bundle Install
68
- command: bundle install
69
- - run:
70
- name: Run RSpec
71
- command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
72
- when: always
73
- - store_test_results:
74
- path: test-results
75
- "jruby-9.2":
76
- docker:
77
- - image: circleci/jruby:9.2
78
- - image: rabbitmq:3.7
79
- steps:
80
- - checkout
81
- - run:
82
- name: Bundle Install
83
- command: bundle install
84
- - run:
85
- name: Run RSpec
86
- command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
87
- when: always
88
- - store_test_results:
89
- path: test-results
67
+ name: Run Rubocop
68
+ command: bundle exec rubocop --format=json --out=rubocop-result.json
69
+ - sonarcloud/scan
70
+ - ruby/save-cache
90
71
 
91
72
  workflows:
92
73
  version: 2
93
- cop_rake_deploy:
74
+ rubocop-rspec:
94
75
  jobs:
95
76
  - rubocop
96
- - ruby-2.3:
97
- requires:
98
- - ruby-2.4
99
- filters:
100
- branches:
101
- only: /\bdevelop\b|\bmaster\b/
102
- - ruby-2.4:
77
+ - ruby-two-five:
103
78
  requires:
104
79
  - rubocop
105
- - ruby-2.5:
80
+ - ruby-two-six:
81
+ requires:
82
+ - ruby-two-five
83
+ - ruby-two-seven:
106
84
  requires:
107
- - ruby-2.4
108
- filters:
109
- branches:
110
- only: /\bdevelop\b|\bmaster\b/
111
- - ruby-2.6:
85
+ - ruby-two-five
86
+ - sonarcloud:
112
87
  requires:
113
- - ruby-2.4
114
- filters:
115
- branches:
116
- only: /\bdevelop\b|\bmaster\b/
88
+ - ruby-two-seven
89
+ - ruby-two-six
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -1,4 +1,4 @@
1
- Metrics/LineLength:
1
+ Layout/LineLength:
2
2
  Max: 120
3
3
  Metrics/MethodLength:
4
4
  Max: 30
@@ -6,21 +6,15 @@ Metrics/ClassLength:
6
6
  Max: 1500
7
7
  Metrics/BlockLength:
8
8
  Max: 50
9
- Exclude:
10
- - 'spec/legion/connections/*'
11
9
  Layout/SpaceAroundEqualsInParameterDefault:
12
10
  EnforcedStyle: space
13
11
  Style/SymbolArray:
14
12
  Enabled: true
15
- Layout/AlignHash:
16
- EnforcedHashRocketStyle: table
17
- EnforcedColonStyle: table
18
- Style/HashSyntax:
19
- EnforcedStyle: ruby19_no_mixed_keys
20
13
  Style/Documentation:
21
14
  Enabled: false
22
15
  AllCops:
23
- TargetRubyVersion: 2.4
16
+ TargetRubyVersion: 2.5
17
+ NewCops: enable
24
18
  Style/FrozenStringLiteralComment:
25
19
  Enabled: false
26
20
  Naming/FileName:
@@ -0,0 +1,9 @@
1
+ # Legion::Transport ChangeLog
2
+
3
+ ## v1.1.3
4
+ * Adding JRuby support via a different gem
5
+ * Adding more logic on choosing which gem to pick for the CONNECTOR
6
+ * Cleaning up some rubocop things
7
+
8
+ ## v1.1.2
9
+ Updating queue auto_delete to be false
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in legion-transport.gemspec
4
3
  gemspec
@@ -0,0 +1,3 @@
1
+ # Legion::Transport
2
+
3
+ Used to connect Legion to RabbitMQ and is a core component of Legion.
@@ -1,4 +1,4 @@
1
- image: ruby:2.4.0
1
+ image: ruby:2.5.0
2
2
 
3
3
  pipelines:
4
4
  branches:
@@ -11,28 +11,33 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = 'Used by Legion to connect with RabbitMQ'
12
12
  spec.description = 'The Legion transport gem'
13
13
  spec.homepage = 'https://bitbucket.org/legion-io/legion-transport'
14
+ spec.required_ruby_version = '>= 2.5.0'
14
15
 
15
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ spec.metadata = {
17
+ 'bug_tracker_uri' => 'https://legionio.atlassian.net/projects/TRANSPORT/issues',
18
+ 'changelog_uri' => 'https://bitbucket.org/legion-io/legion-transport/src/master/CHANGELOG.md',
19
+ 'homepage_uri' => 'https://bitbucket.org/legion-io/legion-transport',
20
+ 'wiki_uri' => 'https://bitbucket.org/legion-io/legion-transport/wiki/Home'
21
+ }
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
24
  f.match(%r{^(test|spec|features)/})
17
25
  end
18
- spec.bindir = 'exe'
19
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
27
  spec.require_paths = ['lib']
21
28
 
22
- spec.add_development_dependency 'bundler', '~> 1'
29
+ spec.add_development_dependency 'bundler'
23
30
  spec.add_development_dependency 'codecov'
24
- spec.add_development_dependency 'rake', '~> 10.0'
25
- spec.add_development_dependency 'rspec', '~> 3.0'
31
+ spec.add_development_dependency 'legion-logging'
32
+ spec.add_development_dependency 'legion-settings'
33
+ spec.add_development_dependency 'march_hare' if RUBY_ENGINE == 'jruby'
34
+ spec.add_development_dependency 'rake'
35
+ spec.add_development_dependency 'rspec'
26
36
  spec.add_development_dependency 'rspec_junit_formatter'
27
37
  spec.add_development_dependency 'rubocop'
38
+ spec.add_development_dependency 'simplecov'
28
39
 
29
- if RUBY_ENGINE == 'jruby'
30
- spec.add_development_dependency 'legion-settings-java', '~> 0.1'
31
- spec.add_dependency 'march_hare'
32
- else
33
- spec.add_development_dependency 'legion-settings', '~> 0.1'
34
- spec.add_dependency 'bunny'
35
- end
36
-
37
- spec.add_development_dependency 'legion-logging', '~> 0.1'
40
+ spec.add_dependency 'bunny'
41
+ spec.add_dependency 'concurrent-ruby'
42
+ spec.add_dependency 'legion-json'
38
43
  end
@@ -1,20 +1,22 @@
1
- require 'legion/transport/version'
1
+ require_relative 'transport/version'
2
+ require_relative 'transport/settings'
2
3
 
3
4
  module Legion
4
- # Base Legion::Transport
5
5
  module Transport
6
- if RUBY_ENGINE == 'jruby'
6
+ if RUBY_ENGINE == 'jruby' && defined?(::Marchhare)
7
7
  require 'marchhare'
8
- CONNECTOR = 'marchhare'.freeze
8
+ TYPE = 'marchhare'.freeze
9
+ CONNECTOR = ::Marchhare
9
10
  else
10
11
  require 'bunny'
11
- CONNECTOR = 'bunny'.freeze
12
+ TYPE = 'bunny'.freeze
13
+ CONNECTOR = ::Bunny
12
14
  end
13
15
  end
14
16
 
15
- require 'legion/transport/common'
16
- require 'legion/transport/queue'
17
- require 'legion/transport/exchange'
18
- require 'legion/transport/consumer'
19
- require 'legion/transport/message'
17
+ require_relative 'transport/common'
18
+ require_relative 'transport/queue'
19
+ require_relative 'transport/exchange'
20
+ require_relative 'transport/consumer'
21
+ require_relative 'transport/message'
20
22
  end
@@ -3,16 +3,12 @@ require 'legion/transport/connection'
3
3
  module Legion
4
4
  module Transport
5
5
  module Common
6
- def open_channel(options = {})
7
- @channel = Legion::Transport::Connection.new(options).channel
6
+ def open_channel(_options = {})
7
+ @channel = Legion::Transport::Connection.channel
8
8
  end
9
9
 
10
- def channel_valid?(channel = @channel)
11
- return false if channel.nil?
12
- return false unless channel.instance_of?(::Bunny::Channel)
13
- return false if channel.closed?
14
-
15
- true
10
+ def channel_open?
11
+ channel.open?
16
12
  end
17
13
 
18
14
  def options_builder(first, *args)
@@ -51,20 +47,29 @@ module Legion
51
47
  end
52
48
  # rubocop:enable all
53
49
 
54
- def closed?
55
- @channel.closed?
50
+ def channel
51
+ @channel ||= Legion::Transport::Connection.channel
52
+ end
53
+
54
+ def close!
55
+ Legion::Logging.error 'close! called'
56
+ false unless Legion::Transport::Connection.channel_open?
57
+ Legion::Transport::Connection.channel.close
56
58
  end
57
59
 
58
- def channel(options = @options || {})
59
- @channel if channel_valid?
60
- @channel = options[:channel] if channel_valid?(options[:channel])
61
- @channel = open_channel(options) unless channel_valid?(@channel)
62
- @channel
60
+ def close
61
+ Legion::Logging.error 'close called'
62
+ Legion::Logging.warn 'close called, but method is called close!'
63
+ close!
63
64
  end
64
65
 
65
- def close(_options = @options || {})
66
- false if @channel.closed?
67
- @channel.close
66
+ def generate_consumer_tag(lex_name: nil, runner_name: nil, thread: Thread.current.object_id)
67
+ tag = "#{Legion::Settings[:client][:name]}_"
68
+ tag.concat("#{lex_name}_") unless lex_name.nil?
69
+ tag.concat("#{runner_name}_") unless runner_name.nil?
70
+ tag.concat("#{thread}_")
71
+ tag.concat(SecureRandom.hex)
72
+ tag
68
73
  end
69
74
  end
70
75
  end
@@ -1,17 +1,61 @@
1
+ require 'concurrent-ruby'
2
+
1
3
  module Legion
2
4
  module Transport
3
- class Connection
4
- @@session = nil # rubocop:disable Style/ClassVars
5
- attr_accessor :session, :channel
6
-
7
- if RUBY_ENGINE == 'jruby'
8
- require 'march-hare'
9
- require 'legion/transport/connections/marchhare'
10
- include Legion::Transport::Connections::Marchhare
11
- else
12
- require 'bunny'
13
- require 'legion/transport/connections/bunny'
14
- include Legion::Transport::Connections::Bunny
5
+ module Connection
6
+ class << self
7
+ def connector
8
+ Legion::Transport::CONNECTOR
9
+ end
10
+
11
+ def setup # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
12
+ if @session.respond_to?(:value) && session.respond_to?(:closed?) && session.closed?
13
+ @channel_thread = Concurrent::ThreadLocalVar.new
14
+ elsif @session.respond_to?(:value) && session.respond_to?(:closed?) && session.open?
15
+ return nil
16
+ else
17
+ @session ||= Concurrent::Atom.new(
18
+ connector.new(
19
+ Legion::Settings[:transport][:connection],
20
+ logger: Legion::Logging::Logger.new(level: 'warn'),
21
+ log_level: :info
22
+ )
23
+ )
24
+ @channel_thread = Concurrent::ThreadLocalVar.new
25
+ end
26
+
27
+ session.start
28
+ session.create_channel.basic_qos(1, true)
29
+ end
30
+
31
+ def channel
32
+ return @channel_thread.value if !@channel_thread.value.nil? && @channel_thread.value.open?
33
+
34
+ @channel_thread.value = session.create_channel
35
+ @channel_thread.value.prefetch(Legion::Settings[:transport][:prefetch])
36
+ @channel_thread.value
37
+ end
38
+
39
+ def session
40
+ nil if @session.nil?
41
+ @session.value
42
+ end
43
+
44
+ def channel_thread
45
+ channel
46
+ end
47
+
48
+ def channel_open?
49
+ channel.open?
50
+ end
51
+
52
+ def session_open?
53
+ session.open?
54
+ end
55
+
56
+ def shutdown
57
+ session.close
58
+ end
15
59
  end
16
60
  end
17
61
  end