vayacondios-client 0.2.11 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
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,63 @@
1
+ module Vayacondios
2
+ class Configuration
3
+
4
+ attr_accessor :base_filename, :load_order
5
+
6
+ def initialize(base_fname = nil)
7
+ @base_filename = base_fname || 'vayacondios.yml'
8
+ @load_order = %w[ global project ]
9
+ @settings = Configliere::Param.new
10
+ end
11
+
12
+ def defaults
13
+ Hash.new
14
+ end
15
+
16
+ def global
17
+ File.join('/etc/vayacondios', base_filename)
18
+ end
19
+
20
+ def project
21
+ File.join(ENV['PWD'], 'config', base_filename)
22
+ end
23
+
24
+ def overlay(conf = nil)
25
+ @overlay = conf unless conf.nil?
26
+ @overlay
27
+ end
28
+
29
+ def resolved?
30
+ !!@resolved
31
+ end
32
+
33
+ def resolved_settings
34
+ resolve!
35
+ @resolved_settings.dup
36
+ end
37
+
38
+ def [] handle
39
+ resolved_settings[handle.to_sym]
40
+ end
41
+
42
+ def apply_all
43
+ scopes = load_order.dup.unshift(:defaults).push(:overlay)
44
+ scopes.each do |scope|
45
+ conf = send scope
46
+ if conf.is_a? String
47
+ @settings.read_yaml File.read(conf) if File.readable?(conf)
48
+ elsif conf.is_a? Hash
49
+ @settings.deep_merge! conf
50
+ end
51
+ end
52
+ end
53
+
54
+ def resolve!
55
+ unless resolved?
56
+ apply_all
57
+ @resolved_settings = @settings.to_hash.symbolize_keys
58
+ @resolved = true
59
+ end
60
+ end
61
+
62
+ end
63
+ end
@@ -1,22 +1,21 @@
1
1
  require 'configliere'
2
- require 'multi_json'
3
- require 'net/http'
4
-
5
- require 'gorillib/builder'
6
- require 'gorillib/configurable'
7
- require 'gorillib/enumerable/sum'
8
- require 'gorillib/exception/raisers'
9
- require 'gorillib/hash/deep_compact'
10
- require 'gorillib/hash/deep_merge'
11
- require 'gorillib/hash/keys'
12
- require 'gorillib/logger/log'
2
+ require 'faraday'
3
+ require 'faraday_middleware'
4
+ require 'gorillib'
13
5
  require 'gorillib/metaprogramming/class_attribute'
14
- require 'gorillib/object/blank'
15
- require 'gorillib/string/constantize'
16
6
  require 'gorillib/string/inflections'
7
+ require 'logger'
8
+ require 'multi_json'
17
9
 
10
+ require 'vayacondios'
11
+ require 'vayacondios/configuration'
12
+ require 'vayacondios/client/configuration'
13
+ require 'vayacondios/client/connection'
14
+ require 'vayacondios/client/http_methods'
18
15
  require 'vayacondios/client/http_client'
19
- require 'vayacondios/client/cube_client'
20
- require 'vayacondios/client/zabbix_client'
21
- require 'vayacondios/client/notifier'
22
- require 'vayacondios/client/configliere'
16
+
17
+ module Vayacondios
18
+ module Client
19
+
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ module Vayacondios
2
+ # Version of the api
3
+ API_VERSION = 'v3'
4
+
5
+ # Gem version for both client and server
6
+ GEM_VERSION = '0.3.0'
7
+
8
+ # Default port to find/connect to for the server
9
+ DEFAULT_SERVER_PORT = 3467
10
+
11
+ # Default address to bind/connect to for the server
12
+ DEFAULT_SERVER_ADDRESS = 'localhost'
13
+
14
+ module_function
15
+
16
+ def library_dir
17
+ File.expand_path('../..', __FILE__)
18
+ end
19
+ end
20
+
21
+ # Alias for Vayacondios
22
+ Vcd = Vayacondios
data/pom.xml ADDED
@@ -0,0 +1,168 @@
1
+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
+ <modelVersion>4.0.0</modelVersion>
4
+ <groupId>com.infochimps</groupId>
5
+ <artifactId>vayacondios</artifactId>
6
+ <packaging>jar</packaging>
7
+ <version>2.0.0-LESLIE</version>
8
+ <name>Vayacondios</name>
9
+ <url>http://maven.apache.org</url>
10
+
11
+ <parent>
12
+ <groupId>com.infochimps</groupId>
13
+ <artifactId>parent-pom</artifactId>
14
+ <version>1.0.0-SNAPSHOT</version>
15
+ </parent>
16
+
17
+ <reporting>
18
+ <plugins>
19
+ <plugin>
20
+ <groupId>org.apache.maven.plugins</groupId>
21
+ <artifactId>maven-javadoc-plugin</artifactId>
22
+ <version>2.9</version>
23
+ <configuration>
24
+ <show>public</show>
25
+ </configuration>
26
+ </plugin>
27
+ </plugins>
28
+ </reporting>
29
+
30
+ <build>
31
+ <plugins>
32
+ <plugin>
33
+ <artifactId>maven-failsafe-plugin</artifactId>
34
+ <version>2.6</version>
35
+ <executions>
36
+ <execution>
37
+ <goals>
38
+ <goal>integration-test</goal>
39
+ <goal>verify</goal>
40
+ </goals>
41
+ </execution>
42
+ </executions>
43
+ </plugin>
44
+ <plugin>
45
+ <groupId>org.apache.maven.plugins</groupId>
46
+ <artifactId>maven-surefire-plugin</artifactId>
47
+ <version>2.11</version>
48
+ <dependencies>
49
+ <dependency>
50
+ <groupId>org.apache.maven.surefire</groupId>
51
+ <artifactId>surefire-junit47</artifactId>
52
+ <version>2.12</version>
53
+ </dependency>
54
+ </dependencies>
55
+ <configuration>
56
+ <includes>
57
+ <include>**/*.class</include>
58
+ </includes>
59
+ <excludedGroups>com.infochimps.vayacondios.test.IntegrationTest</excludedGroups>
60
+ </configuration>
61
+ </plugin>
62
+
63
+ <!-- <plugin> -->
64
+ <!-- <groupId>org.apache.maven.plugins</groupId> -->
65
+ <!-- <artifactId>maven-shade-plugin</artifactId> -->
66
+ <!-- <version>2.0</version> -->
67
+ <!-- <executions> -->
68
+ <!-- <execution> -->
69
+ <!-- <phase>package</phase> -->
70
+ <!-- <goals> -->
71
+ <!-- <goal>shade</goal> -->
72
+ <!-- </goals> -->
73
+ <!-- <configuration> -->
74
+ <!-- <transformers> -->
75
+ <!-- <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> -->
76
+ <!-- <mainClass>com.infochimps.vayacondios.VCDIntegrationTest</mainClass> -->
77
+ <!-- </transformer> -->
78
+ <!-- </transformers> -->
79
+ <!-- </configuration> -->
80
+ <!-- </execution> -->
81
+ <!-- </executions> -->
82
+ <!-- </plugin> -->
83
+ <plugin>
84
+ <groupId>org.codehaus.mojo</groupId>
85
+ <artifactId>exec-maven-plugin</artifactId>
86
+ <version>1.2.1</version>
87
+ <configuration>
88
+ <executable>java</executable>
89
+ <arguments>
90
+ <argument>-cp</argument>
91
+ <classpath/>
92
+ <argument>-jar</argument>
93
+ <argument>target/${project.artifactId}-${project.version}.jar</argument>
94
+ </arguments>
95
+ </configuration>
96
+ </plugin>
97
+ </plugins>
98
+ </build>
99
+
100
+ <repositories>
101
+ <!-- Infochimps Repositories -->
102
+ <repository>
103
+ <id>infochimps.releases</id>
104
+ <name>Infochimps Internal Repository</name>
105
+ <url>https://s3.amazonaws.com/artifacts.chimpy.us/maven-s3p/releases</url>
106
+ </repository>
107
+ <repository>
108
+ <id>infochimps.snapshots</id>
109
+ <name>Infochimps Internal Repository</name>
110
+ <url>https://s3.amazonaws.com/artifacts.chimpy.us/maven-s3p/snapshots</url>
111
+ <snapshots>
112
+ <enabled>true</enabled>
113
+ <updatePolicy>always</updatePolicy>
114
+ </snapshots>
115
+ </repository>
116
+ </repositories>
117
+
118
+ <dependencies>
119
+ <dependency>
120
+ <groupId>com.google.code.gson</groupId>
121
+ <artifactId>gson</artifactId>
122
+ <version>2.2.2</version>
123
+ </dependency>
124
+ <dependency>
125
+ <groupId>commons-codec</groupId>
126
+ <artifactId>commons-codec</artifactId>
127
+ <version>1.2</version>
128
+ </dependency>
129
+ <dependency>
130
+ <groupId>org.slf4j</groupId>
131
+ <artifactId>slf4j-api</artifactId>
132
+ <version>1.7.2</version>
133
+ </dependency>
134
+ <dependency>
135
+ <groupId>org.slf4j</groupId>
136
+ <artifactId>slf4j-simple</artifactId>
137
+ <version>1.7.2</version>
138
+ </dependency>
139
+ <dependency>
140
+ <groupId>junit</groupId>
141
+ <artifactId>junit</artifactId>
142
+ <version>4.8.1</version>
143
+ <scope>test</scope>
144
+ </dependency>
145
+ <dependency>
146
+ <groupId>com.ning</groupId>
147
+ <artifactId>async-http-client</artifactId>
148
+ <version>1.7.16</version>
149
+ </dependency>
150
+ <dependency>
151
+ <groupId>org.apache.commons</groupId>
152
+ <artifactId>commons-lang3</artifactId>
153
+ <version>3.1</version>
154
+ </dependency>
155
+ <dependency>
156
+ <groupId>org.apache.httpcomponents</groupId>
157
+ <artifactId>httpclient</artifactId>
158
+ <version>4.2.5</version>
159
+ </dependency>
160
+ <dependency>
161
+ <groupId>org.mongodb</groupId>
162
+ <artifactId>mongo-java-driver</artifactId>
163
+ <version>2.11.1</version>
164
+ <scope>verify</scope>
165
+ </dependency>
166
+
167
+ </dependencies>
168
+ </project>
@@ -0,0 +1,283 @@
1
+ require 'spec_helper'
2
+ require 'vayacondios/client/cli'
3
+
4
+ describe Vayacondios::Client::CLI, events: true, stashes: true do
5
+
6
+ let(:client) { double('Vayacondios::Client::HttpClient', host: 'localhost', port: 9000) }
7
+ let(:cli) { described_class.new }
8
+ let(:cli_error) { Vayacondios::Client::CLI::Error }
9
+ let(:example_response){ double :response, :success? => true, body: {} }
10
+
11
+ before(:each) do
12
+ cli.stub(:client).and_return(client)
13
+ cli.stub(:display)
14
+ end
15
+
16
+ describe '#boot' do
17
+
18
+ after{ cli.boot }
19
+
20
+ it 'resolves the commandline' do
21
+ cli.cmdline.should_receive(:resolve!)
22
+ end
23
+ end
24
+
25
+ describe 'running with no arguments' do
26
+ before{ ARGV.replace [] }
27
+
28
+ it 'prints a help message' do
29
+ cli.cmdline.should_receive(:dump_help)
30
+ cli.boot
31
+ cli.run
32
+ end
33
+ end
34
+
35
+ describe 'running with a non-existing command argument' do
36
+ before{ ARGV.replace ['foobar'] }
37
+
38
+ it 'raises an error' do
39
+ cli.boot
40
+ expect{ cli.run }.to raise_error(cli_error)
41
+ end
42
+ end
43
+
44
+ describe 'announce' do
45
+ before{ ARGV.replace ['announce'] }
46
+
47
+ it 'raises an error without a topic' do
48
+ cli.boot
49
+ expect{ cli.run }.to raise_error(cli_error, /topic/)
50
+ end
51
+
52
+ context 'with a topic' do
53
+ before{ ARGV << 'topic' }
54
+
55
+ it 'raises an error without an event, --file, or STDIN' do
56
+ cli.boot
57
+ expect{ cli.run }.to raise_error(cli_error, /event/)
58
+ end
59
+
60
+ context 'and an inline event' do
61
+ before{ ARGV << json_hash_event }
62
+
63
+ it 'announces the event' do
64
+ client.should_receive(:announce).with('topic', hash_event, nil).and_return(example_response)
65
+ cli.boot
66
+ cli.run
67
+ end
68
+
69
+ context 'and an ID' do
70
+ before{ ARGV << 'id' }
71
+
72
+ it 'announces the event' do
73
+ client.should_receive(:announce).with('topic', hash_event, 'id').and_return(example_response)
74
+ cli.boot
75
+ cli.run
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ describe 'events' do
83
+ before{ ARGV.replace ['events'] }
84
+
85
+ it 'raises an error without a topic' do
86
+ cli.boot
87
+ expect{ cli.run }.to raise_error(cli_error, /topic/)
88
+ end
89
+
90
+ context 'with topic' do
91
+ before{ ARGV << 'topic' }
92
+
93
+ it 'searches for events' do
94
+ client.should_receive(:events).with('topic', {}).and_return(example_response)
95
+ cli.boot
96
+ cli.run
97
+ end
98
+
99
+ context 'and an inline query' do
100
+ before{ ARGV << json_event_query }
101
+
102
+ it 'uses the query' do
103
+ client.should_receive(:events).with('topic', event_query).and_return(example_response)
104
+ cli.boot
105
+ cli.run
106
+ end
107
+ end
108
+ end
109
+ end
110
+
111
+ describe 'get' do
112
+ before{ ARGV.replace ['get'] }
113
+
114
+ it 'raises an error without a topic' do
115
+ cli.boot
116
+ expect{ cli.run }.to raise_error(cli_error, /topic/)
117
+ end
118
+
119
+ context 'with a topic' do
120
+ before{ ARGV << 'topic' }
121
+
122
+ it 'gets the document' do
123
+ client.should_receive(:get).with('topic', nil).and_return(example_response)
124
+ cli.boot
125
+ cli.run
126
+ end
127
+
128
+ context 'and an ID' do
129
+ before{ ARGV << 'id' }
130
+
131
+ it 'gets the document' do
132
+ client.should_receive(:get).with('topic', 'id').and_return(example_response)
133
+ cli.boot
134
+ cli.run
135
+ end
136
+ end
137
+ end
138
+ end
139
+
140
+ describe 'get_many' do
141
+ before{ ARGV.replace ['get_many'] }
142
+
143
+ it 'searches for stashes' do
144
+ client.should_receive(:get_many).with({}).and_return(example_response)
145
+ cli.boot
146
+ cli.run
147
+ end
148
+
149
+ context 'and an inline query' do
150
+ before{ ARGV << json_stash_query }
151
+
152
+ it 'uses the query' do
153
+ client.should_receive(:get_many).with(stash_query).and_return(example_response)
154
+ cli.boot
155
+ cli.run
156
+ end
157
+ end
158
+ end
159
+
160
+ describe 'set' do
161
+ before{ ARGV.replace ['set'] }
162
+
163
+ it 'raises an error without a topic' do
164
+ cli.boot
165
+ expect{ cli.run }.to raise_error(cli_error, /topic/)
166
+ end
167
+
168
+ context 'with a topic' do
169
+ before{ ARGV << 'topic' }
170
+
171
+ it 'raises an error without a document, --file, or STDIN' do
172
+ cli.boot
173
+ expect{ cli.run }.to raise_error(cli_error, /document/)
174
+ end
175
+
176
+ context 'and an inline document' do
177
+ before{ ARGV << json_hash_stash }
178
+
179
+ it 'stashes the document' do
180
+ client.should_receive(:set).with('topic', nil, hash_stash).and_return(example_response)
181
+ cli.boot
182
+ cli.run
183
+ end
184
+
185
+ context 'and an ID' do
186
+ before{ ARGV << 'id' }
187
+
188
+ it 'stashes the document using the id' do
189
+ client.should_receive(:set).with('topic', 'id', hash_stash).and_return(example_response)
190
+ cli.boot
191
+ cli.run
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
197
+
198
+ describe 'set!' do
199
+ before{ ARGV.replace ['set!'] }
200
+
201
+ it 'raises an error without a topic' do
202
+ cli.boot
203
+ expect{ cli.run }.to raise_error(cli_error, /topic/)
204
+ end
205
+
206
+ context 'with a topic' do
207
+ before{ ARGV << 'topic' }
208
+
209
+ it 'raises an error without a document, --file, or STDIN' do
210
+ cli.boot
211
+ expect{ cli.run }.to raise_error(cli_error, /document/)
212
+ end
213
+
214
+ context 'and an inline document' do
215
+ before{ ARGV << json_hash_stash }
216
+
217
+ it 'stashes the document ' do
218
+ client.should_receive(:set!).with('topic', nil, hash_stash).and_return(example_response)
219
+ cli.boot
220
+ cli.run
221
+ end
222
+
223
+ context 'and an ID' do
224
+ before{ ARGV << 'id' }
225
+
226
+ it 'stashes the document under the id' do
227
+ client.should_receive(:set!).with('topic', 'id', hash_stash).and_return(example_response)
228
+ cli.boot
229
+ cli.run
230
+ end
231
+ end
232
+ end
233
+ end
234
+ end
235
+
236
+ describe 'unset' do
237
+ before{ ARGV.replace(['unset']) }
238
+
239
+ it 'raises an error without a topic' do
240
+ cli.boot
241
+ expect{ cli.run }.to raise_error(cli_error, /topic/)
242
+ end
243
+
244
+ context 'with a topic' do
245
+ before{ ARGV << 'topic' }
246
+
247
+ it 'deletes the document' do
248
+ client.should_receive(:unset).with('topic', nil).and_return(example_response)
249
+ cli.boot
250
+ cli.run
251
+ end
252
+
253
+ context 'and an ID' do
254
+ before{ ARGV << 'id' }
255
+
256
+ it 'deletes the document' do
257
+ client.should_receive(:unset).with('topic', 'id').and_return(example_response)
258
+ cli.boot
259
+ cli.run
260
+ end
261
+ end
262
+ end
263
+ end
264
+
265
+ describe 'unset_many' do
266
+ before{ ARGV.replace ['unset_many'] }
267
+
268
+ it 'raises an error without a document, --file or STDIN' do
269
+ cli.boot
270
+ expect{ cli.run }.to raise_error(cli_error)
271
+ end
272
+
273
+ context 'with input' do
274
+ before{ ARGV << json_stash_query }
275
+
276
+ it 'calls the unset_many method on the client' do
277
+ client.should_receive(:unset_many).with(stash_query).and_return(example_response)
278
+ cli.boot
279
+ cli.run
280
+ end
281
+ end
282
+ end
283
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vayacondios::Client::Configuration do
4
+ its(:defaults) do
5
+ should eq(host: 'localhost', port: 3467, adapter: :net_http)
6
+ end
7
+
8
+ it 'defines a connection options constant' do
9
+ Vayacondios::Client::ConnectionOpts.should be_a(described_class)
10
+ end
11
+ end