vayacondios-server 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +61 -0
  2. data/.travis.yml +11 -0
  3. data/.yardopts +10 -0
  4. data/CHANGELOG.md +0 -0
  5. data/Gemfile +4 -0
  6. data/Guardfile +41 -0
  7. data/LICENSE.md +99 -0
  8. data/Procfile +2 -0
  9. data/README.md +183 -0
  10. data/Rakefile +6 -0
  11. data/app/http_shim.rb +67 -0
  12. data/bin/vcd.sh +27 -0
  13. data/config/http_shim.rb +43 -0
  14. data/config/vayacondios.example.yaml +4 -0
  15. data/config/vayacondios.yaml +4 -0
  16. data/lib/tasks/publish.rake +23 -0
  17. data/lib/tasks/spec.rake +9 -0
  18. data/lib/tasks/yard.rake +2 -0
  19. data/lib/vayacondios/client/configliere.rb +38 -0
  20. data/lib/vayacondios/client/http_client.rb +49 -0
  21. data/lib/vayacondios/client/notifier.rb +84 -0
  22. data/lib/vayacondios/server/handlers/config_handler.rb +35 -0
  23. data/lib/vayacondios/server/handlers/event_handler.rb +30 -0
  24. data/lib/vayacondios/server/model/config_document.rb +94 -0
  25. data/lib/vayacondios/server/model/document.rb +25 -0
  26. data/lib/vayacondios/server/model/event_document.rb +94 -0
  27. data/lib/vayacondios/version.rb +3 -0
  28. data/lib/vayacondios-client.rb +20 -0
  29. data/lib/vayacondios-server.rb +18 -0
  30. data/scripts/hadoop_monitor/configurable.rb +74 -0
  31. data/scripts/hadoop_monitor/hadoop_client.rb +249 -0
  32. data/scripts/hadoop_monitor/hadoop_monitor.rb +91 -0
  33. data/scripts/hadoop_monitor/hadoopable.rb +65 -0
  34. data/scripts/hadoop_monitor/machine_monitor.rb +115 -0
  35. data/scripts/s3_cataloger/buckets +33 -0
  36. data/scripts/s3_cataloger/foreach_bucket +88 -0
  37. data/scripts/s3_cataloger/parse_ls.py +391 -0
  38. data/spec/client/notifier_spec.rb +120 -0
  39. data/spec/server/config_spec.rb +55 -0
  40. data/spec/server/event_spec.rb +44 -0
  41. data/spec/server/server_spec.rb +20 -0
  42. data/spec/spec_helper.rb +10 -0
  43. data/spec/support/mongo_cleaner.rb +26 -0
  44. data/vayacondios-client.gemspec +26 -0
  45. data/vayacondios-server.gemspec +30 -0
  46. metadata +216 -0
data/.gitignore ADDED
@@ -0,0 +1,61 @@
1
+ ## OS
2
+ .DS_Store
3
+ Icon
4
+ nohup.out
5
+ .bak
6
+
7
+ *.pem
8
+
9
+ ## EDITORS
10
+ \#*
11
+ .\#*
12
+ \#*\#
13
+ *~
14
+ *.swp
15
+ REVISION
16
+ TAGS*
17
+ tmtags
18
+ *_flymake.*
19
+ *_flymake
20
+ *.tmproj
21
+ .project
22
+ .settings
23
+
24
+ ## COMPILED
25
+ a.out
26
+ *.o
27
+ *.pyc
28
+ *.so
29
+
30
+ ## OTHER SCM
31
+ .bzr
32
+ .hg
33
+ .svn
34
+
35
+ ## PROJECT::GENERAL
36
+
37
+ log/*
38
+ tmp/*
39
+ pkg/*
40
+
41
+ coverage
42
+ rdoc
43
+ doc
44
+ pkg
45
+ .rake_test_cache
46
+ .bundle
47
+ .yardoc
48
+
49
+ .vendor
50
+
51
+ ## PROJECT::SPECIFIC
52
+
53
+ Gemfile.lock
54
+ .rvmrc
55
+ .rbenv-version
56
+
57
+ public/stylesheets/compiled/*
58
+ public/system/*
59
+ .sass-cache
60
+
61
+ .rbx
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
5
+ - jruby-19mode # JRuby in 1.9 mode
6
+ - rbx-19mode
7
+
8
+ bundler_args: --without docs support
9
+
10
+ notifications:
11
+ email: false
data/.yardopts ADDED
@@ -0,0 +1,10 @@
1
+ --readme README.md
2
+ --markup markdown
3
+ --verbose
4
+ -
5
+ VERSION
6
+ CHANGELOG.md
7
+ LICENSE.md
8
+ README.md
9
+ notes/*.md
10
+ features/**/*.feature
data/CHANGELOG.md ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec name: 'vayacondios-server'
4
+ gemspec name: 'vayacondios-client'
data/Guardfile ADDED
@@ -0,0 +1,41 @@
1
+ # -*- ruby -*-
2
+
3
+ # More info at https://github.com/guard/guard#readme
4
+
5
+ # guard 'yard' do
6
+ # watch(%r{lib/.+\.rb})
7
+ # watch(%r{notes/.+\.(md|txt)}) { "notes" }
8
+ # end
9
+
10
+ rspec_opts = '--format progress'
11
+ # rspec_opts = '--format doc'
12
+
13
+ guard 'rspec', :version => 2, :cli => rspec_opts do
14
+ watch(%r{^spec/.+_spec\.rb$})
15
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
16
+ watch('spec/spec_helper.rb') { "spec" }
17
+ watch(/spec\/support\/(.+)\.rb/) { "spec" }
18
+ watch(%r{^examples/(\w+)\.rb$}) { |m| "spec/examples/#{m[1]}_spec.rb" }
19
+ watch(%r{^examples/(\w+)/(.+)\.rb$}) { |m| "spec/examples/#{m[1]}_spec.rb" }
20
+ end
21
+
22
+ # # This is an example with all options that you can specify for guard-process
23
+ # Dir['examples/**/*.rb'].each do |file|
24
+ # next unless File.file?(file) && File.executable?(file)
25
+ # guard 'process', :name => file, :command => file do
26
+ # watch('Gemfile.lock')
27
+ # watch(file)
28
+ # watch('examples/examples_helper.rb')
29
+ # end
30
+ # end
31
+
32
+ graph_output_dir = File.expand_path("/tmp/wukong-#{ENV['USER']}/graphs")
33
+ FileUtils.mkdir_p(graph_output_dir)
34
+
35
+ Dir['examples/**/*.gv'].each do |file|
36
+ graph_output_file = File.join(graph_output_dir, File.basename(file, '.gv')+".png")
37
+ cmd = "dot -Tpng -o #{graph_output_file} #{file}"
38
+ guard 'process', :name => "dot on #{file}", :command => cmd do
39
+ watch(file)
40
+ end
41
+ end
data/LICENSE.md ADDED
@@ -0,0 +1,99 @@
1
+ # License for Ironfan Toolset
2
+
3
+ The ironfan code is __Copyright (c) 2011, 2012 Infochimps, Inc__
4
+
5
+ This code is licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an **AS IS** BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
10
+
11
+ __________________________________________________________________________
12
+
13
+ Some code has been incorporated from outside projects. Terms for these appear in an explicit license statement within that portion of the code tree.
14
+
15
+ __________________________________________________________________________
16
+
17
+ # Apache License
18
+
19
+
20
+ Apache License
21
+ Version 2.0, January 2004
22
+ http://www.apache.org/licenses/
23
+
24
+ _TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION_
25
+
26
+ ## 1. Definitions.
27
+
28
+ * **License** shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
29
+
30
+ * **Licensor** shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
31
+
32
+ * **Legal Entity** shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
33
+
34
+ * **You** (or **Your**) shall mean an individual or Legal Entity exercising permissions granted by this License.
35
+
36
+ * **Source** form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
37
+
38
+ * **Object** form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
39
+
40
+ * **Work** shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
41
+
42
+ * **Derivative Works** shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
43
+
44
+ * **Contribution** shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
45
+
46
+ * **Contributor** shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
47
+
48
+ ## 2. Grant of Copyright License.
49
+
50
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
51
+
52
+ ## 3. Grant of Patent License.
53
+
54
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
55
+
56
+ ## 4. Redistribution.
57
+
58
+ You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
59
+
60
+ - (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
61
+ - (b) You must cause any modified files to carry prominent notices stating that You changed the files; and
62
+ - (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
63
+ - (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
64
+
65
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
66
+
67
+ ## 5. Submission of Contributions.
68
+
69
+ Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
70
+
71
+ ## 6. Trademarks.
72
+
73
+ This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
74
+
75
+ ## 7. Disclaimer of Warranty.
76
+
77
+ Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
78
+
79
+ ## 8. Limitation of Liability.
80
+
81
+ In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
82
+
83
+ ## 9. Accepting Warranty or Additional Liability.
84
+
85
+ While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
86
+
87
+ _END OF TERMS AND CONDITIONS_
88
+
89
+ ## APPENDIX: How to apply the Apache License to your work.
90
+
91
+ To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets `[]` replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
92
+
93
+ > Copyright [yyyy] [name of copyright owner]
94
+ >
95
+ > Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
96
+ >
97
+ > http://www.apache.org/licenses/LICENSE-2.0
98
+ >
99
+ > Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
data/Procfile ADDED
@@ -0,0 +1,2 @@
1
+ listener: ./app/http_shim.rb -sv -p 8000 -c $PWD/config/http_shim.rb
2
+ mongod: mongod
data/README.md ADDED
@@ -0,0 +1,183 @@
1
+ # Vaya con Dios
2
+
3
+ > "Data goes in. The right thing happens."
4
+
5
+ Simple enough to use in a shell script, performant enough to use everywhere.
6
+
7
+ You can chuck the following into Vaya con Dios from Ruby, the shell, over HTTP, or in a repeated polling loop:
8
+
9
+ * *value* -- 'there are 3 cups of coffee remaining':
10
+ * *timing* -- 'this response took 100ms'
11
+ * *count* -- 'I just served a 404 response code'
12
+ * *fact* -- 'here's everything to know about the coffee machine: `{"cups_remaining":3,"uptime":127,room:"hyrule"}`' -- an arbitrary JSON hash
13
+
14
+ ### Design goals
15
+
16
+ * *Decentralized* -- Any (authorized) system can dispatch facts or metrics using an arbitrary namespace and schema. Nothing needs to be created in advance.
17
+ * *Bulletproof* -- UDP clients will never fail because of network loss or timeout.
18
+ * *Fast* -- UDP clients are non-blocking and happily dispatch thousands of requests per second.
19
+ * *Minimal Dependency* -- Ruby clients uses nothing outside of the standard libraries.
20
+ * *Ubiquitous* -- Can send facts from the shell (with nothing besides `curl`)
21
+ * *writes are simple, reads are clever* -- A writer gets to chuck things in according to its conception of the world.
22
+
23
+ See also [Coda Hale's metrics](https://github.com/codahale/metrics/).
24
+
25
+ ## Namespacing
26
+
27
+ The first path segment defines a collection, and the remainder defines a [materialized path](http://www.mongodb.org/display/DOCS/Trees+in+MongoDB#TreesinMongoDB-MaterializedPaths%28FullPathinEachNode%29).
28
+ All hashes within a given path should always have the same structure. Writes to an overlapping key will overwrite.
29
+
30
+ A full Vaya con Dios path is broken down into specific segments.
31
+
32
+ `/:organization/(event|config)/:topic.format`
33
+
34
+ * `:organization` is the top level collection that all info is contained in.
35
+ * `(event|config)` changes the context of the message. Events are timestamped and scope destructive. Config is merged with the current configuration.
36
+ * `topic` is the materialized path we referred to that specifies its unique location.
37
+ * `format` will change the serialization format for the data. Only JSON is currently supported.
38
+
39
+ ### Events
40
+
41
+ Events are the primary piece of information stored. An event is anything that happened that you'd want to write down.
42
+
43
+
44
+ For example a `POST` to `http://vayacondios.whatever.com/v1/code/commit` with the
45
+ ```
46
+ {
47
+ "_id": "f93f2f08a0e39648fe64", # commit SHA as unique id
48
+ "_path": "code.commit", # materialized path
49
+ "_ts": "20110614104817", # utc flat time
50
+ "repo": "infochimps/wukong"
51
+ "message": "...",
52
+ "lines": 69,
53
+ "author": "mrflip"
54
+ }
55
+ ```
56
+
57
+ Will write the hash as shown into the `code` collection. Vaya con Dios fills in the _path always, and the _id and _ts if missing. This can be queried with path of "^commit/infochimps" or "^commit/.*".
58
+
59
+ The hash will contain:
60
+
61
+ * `_id` -- unique _id
62
+ * `_ts` -- timestamp, set if blank
63
+ * `_path` -- `name.spaced.path.fact_name`, omits the collection part
64
+
65
+
66
+ ### Writes
67
+
68
+ * value
69
+ * count
70
+ * timing
71
+ * fact
72
+
73
+ `echo 'bob.dobolina.mr.bob.dobolina:320|ms:320' | netcat -c -u 127.0.0.1 8125`
74
+
75
+ `http://vayacondios:9000/bob/dobolina/mr/bob/dobolina?_count=1`
76
+
77
+ `http://vayacondios:9000/bob/dobolina/mr/bob/dobolina?_count=1&_sampling=0.1`
78
+
79
+ `http://vayacondios:9000/bob/dobolina/mr/bob/dobolina?_timing=320`
80
+
81
+ ### also
82
+
83
+ * Path components must be ASCII strings matching `[a-z][a-z0-9_]+` -- that is, start with [a-z] and contain only lowercase alphanumeric or underscore. Components starting with a '_' have reserved meanings. The only valid underscored fields that a request can fill in are _id, _ts and _path.
84
+
85
+ * Vaya con Dios reserves the right to read and write paths in `/vayacondios`, and the details of those paths will be documented; it will never read or write other paths unless explicitly asked to.
86
+
87
+ * tree_merge rules:
88
+
89
+ - hash1 + hash = hash1.merge(hash)
90
+ - arr1 + arr2 = arr1 + arr2
91
+ - val1 + val2 = val2
92
+
93
+ - hsh1 + nil = hsh1
94
+ - arr1 + nil = arr1
95
+ - val1 + nil = val1
96
+
97
+ - nil + hs## = hsh2
98
+ - nil + arr2 = arr2
99
+ - nil + val2 = val2
100
+
101
+ - otherwise, exception
102
+
103
+ types: Hash, Array, String, Time, Integer, Float, Nil
104
+
105
+ mongo: string, int, double, boolean, date, bytearray, object, array, others
106
+ couch: string,number,boolean,array,object
107
+
108
+ #### add (set? send?)
109
+
110
+ GET http://vayacondios:9099/f/{clxn}/{arbitrary/name/space}.{ext}?auth=token&query=predicate
111
+
112
+ db.collection(collection).save
113
+
114
+
115
+ get
116
+
117
+
118
+ #### get
119
+
120
+ POST http://vayacondios:9099/f/arbitrary/name/space with JSON body
121
+
122
+ #### Increment
123
+
124
+ #### Add to set
125
+
126
+ what do we need to provide the 'I got next' feature (to distribute resources uniquely from a set)?
127
+
128
+ #### Auth
129
+
130
+ `/vayacondios/_auth/` holds one hash giving public key.
131
+ * walk down the hash until you see _tok
132
+ * can only auth at first or second level?
133
+ * or by wildcard?
134
+ * access is read or read_write; by default allows read_write
135
+
136
+ ## Others
137
+
138
+ GET latest
139
+ GET all
140
+ GET next
141
+
142
+ ## Configuration
143
+
144
+ All organizations have a special topic called, "config" that allows for storage and retrieval of configuration data via standard [CRUD requests](http://en.wikipedia.org/wiki/Create,_read,_update_and_delete).
145
+
146
+ ### Writing config data
147
+
148
+ A `POST` request can be made to a full URL such as: `http://vayacondios:9000/organization/topic/some/deep/key`
149
+
150
+ Vaya con Dios stores configuration data in special collections (`"#{organization}.config"`). The topic acts as the primary key while `/some/deep/key` acts as a materialized path for selection.
151
+
152
+ ## Notes
153
+
154
+ ### When to use HTTP vs UDP
155
+
156
+ #### HTTP is connectionful
157
+
158
+ * you get acknowledgement that a metric was recorded (this is good).
159
+ * if the network is down, your code will break (this is bad). (Well, usually. For some accounting and auditing metrics one might rather serve nothing at all than something unrecorded. Vayacondios doesn't address this use case.)
160
+
161
+ #### UDP has Packet Size limitations
162
+
163
+ If you're using UDP for facts, you need to be *very* careful about payload size.
164
+
165
+ From the [EventMachine docs](http://eventmachine.rubyforge.org/EventMachine/Connection.html#M000298)
166
+
167
+ > You may not send an arbitrarily-large data packet because your operating system will enforce a platform-specific limit on the size of the outbound packet. (Your kernel will respond in a platform-specific way if you send an overlarge packet: some will send a truncated packet, some will complain, and some will silently drop your request). On LANs, it’s usually OK to send datagrams up to about 4000 bytes in length, but to be really safe, send messages smaller than the Ethernet-packet size (typically about 1400 bytes). Some very restrictive WANs will either drop or truncate packets larger than about 500 bytes.
168
+
169
+ ## Colophon
170
+
171
+ ### Contributing to vayacondios
172
+
173
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
174
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
175
+ * Fork the project
176
+ * Start a feature/bugfix branch
177
+ * Commit and push until you are happy with your contribution
178
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
179
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
180
+
181
+ ### Copyright
182
+
183
+ Copyright (c) 2011, 2012 Infochimps. See [LICENSE.md](LICENSE.md) for further details.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler' ; Bundler.setup
2
+
3
+ # App-specific tasks
4
+ Dir[File.dirname(__FILE__)+'/lib/tasks/**/*.rake'].sort.each{|f| load f }
5
+
6
+ task :default => :spec
data/app/http_shim.rb ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'vayacondios-server'
4
+ require 'time'
5
+
6
+ class HttpShim < Goliath::API
7
+ use Goliath::Rack::Heartbeat # respond to /status with 200, OK (monitoring, etc)
8
+ use Goliath::Rack::Tracer, 'X-Tracer' # log trace statistics
9
+ use Goliath::Rack::Params # parse & merge query and body parameters
10
+
11
+ use Goliath::Rack::DefaultMimeType # cleanup accepted media types
12
+ use Goliath::Rack::Render, 'json' # auto-negotiate response format
13
+
14
+ def response(env)
15
+ path_params = parse_path(env[Goliath::Request::REQUEST_PATH])
16
+
17
+ if path_params.present?
18
+ klass = ('vayacondios/' + path_params[:type] + '_handler').camelize.constantize
19
+
20
+ if method_name == :get && !path_params[:topic].present?
21
+ return [400, {}, {error: "Bad Request"}]
22
+ end
23
+ begin
24
+ if method_name == :update
25
+ record = klass.new(mongo).update(env.params, path_params)
26
+ elsif method_name == :get
27
+ record = klass.find(mongo, path_params)
28
+ end
29
+
30
+ rescue Exception => ex
31
+ puts ex
32
+ ex.backtrace.each{|l| puts l}
33
+ end
34
+
35
+ if record.present?
36
+ [200, {}, record]
37
+ else
38
+ [404, {}, {error: "Not Found"}]
39
+ end
40
+ else
41
+ [400, {}, {error: "Bad Request"}]
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ # Determine the organization, type of action (config or event), the topic,
48
+ # id, and format for the request.
49
+ def parse_path path
50
+ path_regex = /^\/v1\/(?<organization>[a-z]\w+)\/(?<type>config|event)(\/(?<topic>\w+)(\/(?<id>(\w+\/?)+))?)?(\/|\.(?<format>json))?$/i
51
+ if (match = path_regex.match(path))
52
+ {}.tap do |segments|
53
+ match.names.each do |segment|
54
+ segments[segment.to_sym] = match[segment]
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ def method_name
61
+ if %{PUT POST}.include?(env['REQUEST_METHOD'].upcase)
62
+ :update
63
+ elsif env['REQUEST_METHOD'].downcase == 'get'
64
+ :get
65
+ end
66
+ end
67
+ end