vayacondios-client 0.2.11 → 0.3.0

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.
Files changed (62) hide show
  1. data/.gitignore +64 -0
  2. data/.travis.yml +13 -0
  3. data/CHANGELOG.md +0 -0
  4. data/Gemfile +21 -0
  5. data/LICENSE.md +95 -0
  6. data/Procfile +2 -0
  7. data/README.md +734 -0
  8. data/Rakefile +93 -0
  9. data/bin/vcd +10 -0
  10. data/config/database.yml +6 -0
  11. data/config/spec.example.yml +18 -0
  12. data/config/vayacondios.example.yml +15 -0
  13. data/examples/configuration.rb +56 -0
  14. data/examples/event_stream.rb +19 -0
  15. data/examples/simple.rb +61 -0
  16. data/features/event.feature +319 -0
  17. data/features/events.feature +208 -0
  18. data/features/stash.feature +840 -0
  19. data/features/stashes.feature +492 -0
  20. data/features/step_definitions/stash_steps.rb +113 -0
  21. data/features/stream.feature +30 -0
  22. data/features/support/em.rb +14 -0
  23. data/features/support/env.rb +13 -0
  24. data/lib/vayacondios/client/cli.rb +456 -0
  25. data/lib/vayacondios/client/configuration.rb +13 -0
  26. data/lib/vayacondios/client/connection.rb +39 -0
  27. data/lib/vayacondios/client/http_client.rb +6 -42
  28. data/lib/vayacondios/client/http_methods.rb +85 -0
  29. data/lib/vayacondios/client.rb +21 -0
  30. data/lib/vayacondios/configuration.rb +63 -0
  31. data/lib/vayacondios-client.rb +16 -17
  32. data/lib/vayacondios.rb +22 -0
  33. data/pom.xml +168 -0
  34. data/spec/client/cli_spec.rb +283 -0
  35. data/spec/client/configuration_spec.rb +11 -0
  36. data/spec/client/http_client_spec.rb +150 -0
  37. data/spec/configuration_spec.rb +41 -0
  38. data/spec/spec_helper.rb +27 -0
  39. data/spec/support/database_helper.rb +42 -0
  40. data/spec/support/log_helper.rb +19 -0
  41. data/spec/support/shared_context_for_events.rb +22 -0
  42. data/spec/support/shared_context_for_stashes.rb +24 -0
  43. data/spec/support/shared_examples_for_handlers.rb +32 -0
  44. data/src/main/java/com/infochimps/vayacondios/BaseClient.java +342 -0
  45. data/src/main/java/com/infochimps/vayacondios/HTTPClient.java +426 -0
  46. data/src/main/java/com/infochimps/vayacondios/VayacondiosClient.java +500 -0
  47. data/src/main/java/com/infochimps/vayacondios/test/IntegrationTest.java +3 -0
  48. data/src/test/java/com/infochimps/vayacondios/BaseClientTest.java +50 -0
  49. data/src/test/java/com/infochimps/vayacondios/HTTPClientIT.java +267 -0
  50. data/vayacondios-client.gemspec +25 -0
  51. metadata +96 -60
  52. checksums.yaml +0 -15
  53. data/lib/vayacondios/client/config.rb +0 -7
  54. data/lib/vayacondios/client/configliere.rb +0 -38
  55. data/lib/vayacondios/client/cube_client.rb +0 -39
  56. data/lib/vayacondios/client/itemset.rb +0 -130
  57. data/lib/vayacondios/client/legacy_switch.rb +0 -43
  58. data/lib/vayacondios/client/notifier.rb +0 -123
  59. data/lib/vayacondios/client/zabbix_client.rb +0 -148
  60. data/spec/client/itemset_legacy_spec.rb +0 -55
  61. data/spec/client/itemset_spec.rb +0 -60
  62. data/spec/client/notifier_spec.rb +0 -120
@@ -0,0 +1,150 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vayacondios::Client::HttpClient do
4
+
5
+ let(:http_connection){ double :http }
6
+ let(:hash_event) { { foo: 'bar' } }
7
+ subject(:http_client){ described_class.new(organization: 'organization') }
8
+
9
+ def expect_query(verb, &assertions)
10
+ subject.http_connection.should_receive(verb) do |path, &blk|
11
+ request = double :request
12
+ assertions.call(path, request)
13
+ blk.call(request) unless blk.nil?
14
+ end
15
+ end
16
+
17
+ context '#initialize' do
18
+ it 'allows to customize the connection' do
19
+ http_client = described_class.new(host: 'foo.com')
20
+ http_client.http_connection.url_prefix.host.should eq('foo.com')
21
+ end
22
+ end
23
+
24
+ context '#announce', 'without an ID' do
25
+ it 'constructs a POST request to /v3/organization/event/topic with the Event as the body' do
26
+ expect_query(:post) do |path, req|
27
+ path.should eq('organization/event/topic')
28
+ req.should_receive(:body=).with(hash_event)
29
+ end
30
+ http_client.announce('topic', hash_event)
31
+ end
32
+ end
33
+
34
+ context '#announce', 'with an ID' do
35
+ it 'constructs a POST request to /v3/organization/event/topic/id with the Event as the body' do
36
+ expect_query(:post) do |path, req|
37
+ path.should eq('organization/event/topic/id')
38
+ req.should_receive(:body=).with(hash_event)
39
+ end
40
+ http_client.announce('topic', hash_event, 'id')
41
+ end
42
+ end
43
+
44
+ context '#events', 'without a query' do
45
+ it 'constructs a GET request to /v3/organization/events/topic' do
46
+ expect_query(:get) do |path, req|
47
+ path.should eq('organization/events/topic')
48
+ req.should_receive(:body=).with({})
49
+ end
50
+ http_client.events 'topic'
51
+ end
52
+ end
53
+
54
+ context '#events', 'with a query' do
55
+ let(:query){ { foo: 'bar' } }
56
+
57
+ it 'constructs a GET request to /v3/organization/events/topic with the query as the body' do
58
+ expect_query(:get) do |path, req|
59
+ path.should eq('organization/events/topic')
60
+ req.should_receive(:body=).with(query)
61
+ end
62
+ subject.events('topic', query)
63
+ end
64
+ end
65
+
66
+ context '#get', 'without an ID' do
67
+ it 'constructs a GET request to /v3/organization/stash/topic' do
68
+ expect_query(:get) do |path, req|
69
+ path.should eq('organization/stash/topic')
70
+ end
71
+ subject.get 'topic'
72
+ end
73
+ end
74
+
75
+ context '#get', 'with an ID' do
76
+ it 'constructs a GET request to /v3/organization/stash/topic/id' do
77
+ expect_query(:get) do |path, req|
78
+ path.should eq('organization/stash/topic/id')
79
+ end
80
+ subject.get('topic', 'id')
81
+ end
82
+ end
83
+
84
+ context '#get_many', 'without a query' do
85
+ it 'sends a GET request to /v3/organization/stashes' do
86
+ expect_query(:get) do |path, req|
87
+ path.should eq('organization/stashes')
88
+ req.should_receive(:body=).with({})
89
+ end
90
+ subject.get_many
91
+ end
92
+ end
93
+
94
+ context '#get_many', 'with a query' do
95
+ let(:query){ { foo: 'bar' } }
96
+
97
+ it 'constructs a GET request to /v3/organization/stashes with the query as the body' do
98
+ expect_query(:get) do |path, req|
99
+ path.should eq('organization/stashes')
100
+ req.should_receive(:body=).with(query)
101
+ end
102
+ subject.get_many query
103
+ end
104
+ end
105
+
106
+ context '#set', 'without an ID' do
107
+ let(:stash){ { foo: 'bar' } }
108
+
109
+ it 'constructs a PUT request to /v3/organization/stash/topic with the Stash as the body' do
110
+ expect_query(:post) do |path, req|
111
+ path.should eq('organization/stash/topic')
112
+ req.should_receive(:body=).with(stash)
113
+ end
114
+ subject.set('topic', nil, stash)
115
+ end
116
+ end
117
+
118
+ context '#set', 'with an ID' do
119
+ let(:stash){ { foo: 'bar' } }
120
+
121
+ it 'constructs a PUT request to /v3/organization/stash/topic/id with the Stash as the body' do
122
+ expect_query(:post) do |path, req|
123
+ path.should eq('organization/stash/topic/id')
124
+ req.should_receive(:body=).with(stash)
125
+ end
126
+ subject.set('topic', 'id', stash)
127
+ end
128
+ end
129
+
130
+ context '#unset', 'without an ID' do
131
+ it 'constructs a DELETE request to /v3/organization/stash/topic' do
132
+ expect_query(:delete) do |path, req|
133
+ path.should eq('organization/stash/topic')
134
+ end
135
+ subject.unset 'topic'
136
+ end
137
+ end
138
+
139
+ context '#unset_many' do
140
+ let(:query){ { foo: 'bar' } }
141
+
142
+ it 'constructs a DELETE request to /v3/organization/stashes with the query' do
143
+ expect_query(:delete) do |path, req|
144
+ path.should eq('organization/stashes')
145
+ req.should_receive(:body=).with(query)
146
+ end
147
+ subject.unset_many query
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vayacondios::Configuration do
4
+
5
+ def change_defaults new_defaults
6
+ subject.define_singleton_method(:defaults) do
7
+ new_defaults
8
+ end
9
+ end
10
+
11
+ context '#defaults' do
12
+ it 'defines defaults' do
13
+ subject.defaults.should eq(Hash.new)
14
+ end
15
+ end
16
+
17
+ context '#resolved_settings' do
18
+ it 'resolves settings automatically when accessed' do
19
+ subject.should_not be_resolved
20
+ subject.resolved_settings.should eq(Hash.new)
21
+ subject.should be_resolved
22
+ end
23
+ end
24
+
25
+ context '#overlay' do
26
+ before{ change_defaults(foo: 'bar', baz: 'qix') }
27
+
28
+ it 'allows a top-level override of settings' do
29
+ subject.overlay(foo: 'override')
30
+ subject.resolved_settings.should eq(foo: 'override', baz: 'qix')
31
+ end
32
+ end
33
+
34
+ context '#[]' do
35
+ before{ change_defaults(foo: 'bar') }
36
+
37
+ it 'allows access to the resolved_settings' do
38
+ subject[:foo].should eq('bar')
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,27 @@
1
+ require 'bundler/setup' ; Bundler.require(:test)
2
+
3
+ require 'goliath/test_helper'
4
+ require 'mongo'
5
+
6
+ if ENV['VAYACONDIOS_COV']
7
+ require 'simplecov'
8
+ SimpleCov.start do
9
+ add_group 'Library', 'lib/'
10
+ add_group 'Test', '(spec|features)/'
11
+ end
12
+ end
13
+
14
+ WITH_MONGO = ENV['WITH_MONGO']
15
+
16
+ require 'vayacondios-server'
17
+ require 'vayacondios-client'
18
+
19
+ Dir[File.expand_path('../support/**/*.rb', __FILE__)].each{ |f| require f }
20
+
21
+ Goliath.env = :test
22
+
23
+ require 'vayacondios/server/api'
24
+
25
+ RSpec.configure do |c|
26
+ c.include Goliath::TestHelper
27
+ end
@@ -0,0 +1,42 @@
1
+ module DatabaseHelper
2
+
3
+ def insert_record(index, document)
4
+ # mongo only
5
+ db_query(index){ |db| db.connection.insert(document) }
6
+ end
7
+
8
+ def database_count index
9
+ # mongo only
10
+ db_query(index){ |db| db.connection.count }
11
+ end
12
+
13
+ def retrieve_record(index, filter = {})
14
+ # mongo only
15
+ db_query(index){ |db| db.connection.find_one(filter) }
16
+ end
17
+
18
+ def db_connection
19
+ return @db_connection if @db_connection
20
+ settings = Vayacondios::Server::DbConfig.env :test
21
+ driver = Vayacondios::Server::Driver.retrieve settings[:driver]
22
+ @db_connection = driver.connect settings.merge(log: log)
23
+ end
24
+
25
+ def db_locations
26
+ @locations ||= [ "organization.topic.events", "organization.stash" ]
27
+ end
28
+
29
+ def db_query(location, &blk)
30
+ db_connection.set_location location
31
+ db_locations << location
32
+ result = blk.call db_connection
33
+ db_connection.unset_location
34
+ result
35
+ end
36
+
37
+ def db_reset!
38
+ db_locations.uniq.each do |location|
39
+ db_query(location){ |db| EM::Synchrony.sync db.reset! }
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,19 @@
1
+ require 'logger'
2
+
3
+ module LogHelper
4
+
5
+ def log
6
+ @logdev = StringIO.new
7
+ Logger.new @logdev
8
+ end
9
+
10
+ def log_device
11
+ @logdev
12
+ end
13
+
14
+ def log_content
15
+ log_device.rewind
16
+ log_device.read
17
+ end
18
+
19
+ end
@@ -0,0 +1,22 @@
1
+ shared_context 'events', events: true do
2
+ let(:nil_event) { nil }
3
+ let(:json_nil_event) { 'null' }
4
+ let(:hash_event) { { 'foo' => 'bar'} }
5
+ let(:json_hash_event) { '{"foo":"bar"}' }
6
+ let(:array_event) { [1, 2, 3] }
7
+ let(:json_array_event) { '[1,2,3]' }
8
+ let(:string_event) { 'HELLO' }
9
+ let(:json_string_event) { '"HELLO"' }
10
+ let(:numeric_event) { 1 }
11
+ let(:json_numeric_event) { '1' }
12
+ let(:nested_event) { { 'A' => 1, 'B' => { 'c' => 2, 'd' => 3 } } }
13
+ let(:json_nested_event) { MultiJson.dump(nested_event) }
14
+ let(:event_query) { { 'foo' => 'bar' } }
15
+ let(:json_event_query) { MultiJson.dump(event_query) }
16
+ let(:event_query_with_sort) { { 'foo' => 'bar', 'sort' => %w[ bing descending ] } }
17
+ let(:event_query_with_limit) { { 'foo' => 'bar', 'limit' => 10 } }
18
+ let(:event_query_with_fields) { { 'foo' => 'bar', 'fields' => %w[ bing bam ] } }
19
+ let(:event_query_with_string_time) { { 'foo' => 'bar', 'from' => '2013-06-08 01:19:15 -0500' } }
20
+ let(:event_query_with_int_time) { { 'foo' => 'bar', 'from' => 1370672418 } }
21
+ let(:event_query_with_id) { { 'foo' => 'bar', 'id' => 'baz' } }
22
+ end
@@ -0,0 +1,24 @@
1
+ shared_context 'stashes', stashes: true do
2
+ let(:nil_stash) { nil }
3
+ let(:json_nil_stash) { 'null' }
4
+ let(:hash_stash) { { 'foo' => 'bar' } }
5
+ let(:json_hash_stash) { '{"foo":"bar"}' }
6
+ let(:array_stash) { [1, 2, 3] }
7
+ let(:json_array_stash) { '[1,2,3]' }
8
+ let(:string_stash) { 'HELLO' }
9
+ let(:json_string_stash) { '"HELLO"' }
10
+ let(:numeric_stash) { 1 }
11
+ let(:json_numeric_stash) { '1' }
12
+ let(:nested_stash) { { 'root' => { 'b' => 2, 'c' => { 'x' => 3 }, 'a' => 1 } } }
13
+ let(:stash_query) { { 'foo' => 'bar' } }
14
+ let(:json_stash_query) { MultiJson.dump(stash_query) }
15
+ let(:nested_stash_query) { { 'root.b' => 2 } }
16
+ let(:json_nested_stash_query) { MultiJson.dump(nested_stash_query) }
17
+ let(:stash_query_with_limit) { { 'foo' => 'bar', 'limit' => 10 } }
18
+ let(:stash_query_with_sort) { { 'foo' => 'bar', 'sort' => %w[ bar ascending ] } }
19
+ let(:stash_query_with_topic) { { 'foo' => 'bar', 'topic' => 'baz' } }
20
+ let(:stash_replacement) { { 'foo' => 'baz' } }
21
+ let(:json_stash_replacement) { '{"foo":"baz"}' }
22
+ let(:stash_update) { { 'counter' => 1 } }
23
+ let(:json_stash_update) { '{"counter":1}' }
24
+ end
@@ -0,0 +1,32 @@
1
+ shared_examples 'handlers', behaves_like: 'handler' do
2
+ include LogHelper
3
+
4
+ let!(:driver) do
5
+ db = Class.new{ include Vayacondios::Server::Driver }.new
6
+ db.set_log log
7
+ db
8
+ end
9
+
10
+ def validation_error
11
+ Goliath::Validation::Error
12
+ end
13
+
14
+ def success_response
15
+ handler.action_successful
16
+ end
17
+
18
+ subject(:handler){ described_class.new(log, driver) }
19
+
20
+ it{ should respond_to(:log) }
21
+ it{ should respond_to(:database) }
22
+
23
+ its(:action_successful){ should eq(ok: true) }
24
+
25
+ context '#call' do
26
+ it 'calls base methods for logging before delegating' do
27
+ handler.log.should_receive(:debug).at_least(1).times
28
+ handler.should_receive(:create).with({}, {})
29
+ handler.call(:create, {}, {})
30
+ end
31
+ end
32
+ end