apollo-tools 0.1.1 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff541244f5ec31aa2142100d2fb40f3382464357
4
- data.tar.gz: 27d50ac2d94f8281c40a88b982262b0e82eebeaf
3
+ metadata.gz: e8f6801ba0b199ea0e814e5497062adb39ed7d15
4
+ data.tar.gz: d36c554a302ff2e12ca22cad6f2020fbdd76abcf
5
5
  SHA512:
6
- metadata.gz: dc42df0bfeff8a36963a3a0028d0b64164c0b2fa8b8bc7decf33e9113f473e7ec82d2834ed57c9adca08cc67fe52024b6d80a1d2aa6417b85c8fdff0805c52ae
7
- data.tar.gz: 2257317bdf197064a8b8a4cf4db8587553bd7e7c1626060b632645dd854777fba690638e5e4442fa244c27b0b1a30edc66813fd3ef4af82b530d03abbca446fd
6
+ metadata.gz: d0ffc9ee318f897e9e7bbd8f0a06ae3b0a467978bef61d07f6efaf56fd8084c5ff1ad2414e08da8d431a93b1ec82bb8a04679ed7529735cf0e459684b7946151
7
+ data.tar.gz: a540e79a60717bedb4d7394ef0160ea5e5deb3d3286c3a5d31db35760e2ce5fc65adb026e90e7915c3ea93f793327121abd0ff7cd2516f520ba479df01ae2170
data/.gitignore CHANGED
@@ -11,3 +11,4 @@
11
11
  apollo.iml
12
12
  .bin
13
13
  .vendor
14
+ .vagrant
@@ -12,4 +12,8 @@ Vagrant.configure(2) do |config|
12
12
  config.ssh.insert_key = false
13
13
 
14
14
  config.vm.network "private_network", ip: "192.168.100.4"
15
+
16
+ config.vm.provision 'ansible' do |ansible|
17
+ ansible.playbook = 'test_vm.yml'
18
+ end
15
19
  end
@@ -22,5 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency 'minitest', '~> 5.5.1'
23
23
 
24
24
  spec.add_dependency 'rabbitmq_manager', '~> 0.3.0'
25
+ spec.add_dependency 'bunny', '~> 1.7.0'
26
+ spec.add_dependency 'json_pure', '~> 1.8.2'
25
27
  spec.add_dependency 'net-ssh', '~> 2.9.2'
26
28
  end
@@ -2,6 +2,7 @@ require "apollo/version"
2
2
  require "yaml"
3
3
  require 'net/ssh'
4
4
  require 'rabbitmq_manager'
5
+ require 'apollo/rabbitmq'
5
6
 
6
7
  module Apollo
7
8
  class Cluster
@@ -80,6 +81,18 @@ module Apollo
80
81
  manager.queue(vhost, queue)['messages']
81
82
  end
82
83
 
84
+ # create_rmq_listener creates an exclusive queue with a randomized name bound to the specified exchange with the
85
+ # specified routing key
86
+ # @param host [Symbol] the host that the queue is on
87
+ # @param exchange [String] the exchange to bind the queue to
88
+ # @param key [String] The routing key to use to bind the queue to the specified exchange
89
+ # @return [Apollo::Rabbitmq::Listener] A listener listening on the specified queue
90
+ def create_rmq_listener(host, exchange, key)
91
+ sym_hash = Hash.new
92
+ @hosts[host].each { |k, v| sym_hash[k.to_sym] = v}
93
+ Apollo::Rabbitmq::Listener.new(exchange, key, sym_hash)
94
+ end
95
+
83
96
  # Runs the specified command on the specified host
84
97
  #
85
98
  # @param on [Symbol] The host to run the command on
@@ -0,0 +1,40 @@
1
+ require 'bunny'
2
+ require 'json'
3
+
4
+ module Apollo
5
+ module Rabbitmq
6
+ class Listener
7
+ # Returns a new listener. It listens on a randomly named queue bound to the specified exchange with the specified
8
+ # routing key
9
+ # @param exchange [String] the exchange to bind the queue to
10
+ # @param key [String] the routing key to bind the queue to the exchange
11
+ # @param opts [Hash]
12
+ # @option opts [String] :rmq_username The username to connect to the rabbitmq server
13
+ # @option opts [String] :rmq_password The password to connect to the rabbitmq server
14
+ # @option opts [String] :address the hostname or ip to connect to the rabbitmq server
15
+ # @option opts [Integer] :port the port to connect to the rabbitmq server
16
+ def initialize(exchange, key, opts = {})
17
+ username = CGI.escape opts.fetch(:rmq_username, 'guest')
18
+ password = CGI.escape opts.fetch(:rmq_password, 'guest')
19
+ host = opts.fetch(:ip, opts.fetch(:hostname, '127.0.0.1'))
20
+ port = opts.fetch(:port, 5672)
21
+ @conn = Bunny.new("amqp://#{username}:#{password}@#{host}:#{port}")
22
+ @conn.start
23
+ raise 'connection is nil' if @conn.nil?
24
+ @ch = @conn.create_channel
25
+ x = @ch.direct exchange
26
+ @messages = []
27
+ @ch.temporary_queue.bind(x, :routing_key => key).subscribe do |delivery_info, metadata, payload|
28
+ @messages << JSON.parse(payload)
29
+ end
30
+ end
31
+
32
+ # get_all returns all of the messages that were collected from the queue
33
+ # @return [Array] An array of hashes from the json
34
+ def get_all()
35
+ @conn.close
36
+ @messages
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module Apollo
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,26 @@
1
+ ---
2
+ - name: Setup rabbimtq
3
+ hosts: all
4
+ user: vagrant
5
+ sudo: yes
6
+ tasks:
7
+ - name: Add the rabbitmq apt key
8
+ apt_key: url=http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
9
+ state=present
10
+
11
+ - name: Add the rabbitmq apt repository
12
+ apt_repository: repo="deb http://www.rabbitmq.com/debian/ testing main"
13
+
14
+ - name: Install rabbitmq
15
+ apt: name=rabbitmq-server
16
+ state=present
17
+
18
+ - name: setup the mesos user
19
+ rabbitmq_user: user=apollo
20
+ password=apollo
21
+ vhost=/
22
+ configure_priv=.*
23
+ read_priv=.*
24
+ write_priv=.*
25
+ state=present
26
+ tags=administrator
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apollo-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brendan Tobolaski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-03-25 00:00:00.000000000 Z
11
+ date: 2015-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.3.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: bunny
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.7.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.7.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: json_pure
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.8.2
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.8.2
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: net-ssh
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -97,7 +125,9 @@ files:
97
125
  - bin/console
98
126
  - bin/setup
99
127
  - lib/apollo.rb
128
+ - lib/apollo/rabbitmq.rb
100
129
  - lib/apollo/version.rb
130
+ - test_vm.yml
101
131
  homepage: https://github.com/signalvine/apollo
102
132
  licenses: []
103
133
  metadata: {}