ocean-dynamo 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +42 -33
- data/lib/ocean-dynamo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce113a0cc1dc99b428010d59a1a4f5cb508dcefb
|
4
|
+
data.tar.gz: c2ce6a2d070908c370e1e3fc29a60eab0e15a269
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e945ae2cf6e19c81bddd963ad1416064b997eaefaf73ae3c4edaaff223c50851ba9fd2227064fbcd56fe9496c6e0fde697d27c43058e036769361f21f4be52be
|
7
|
+
data.tar.gz: 4a749b813876644ceb054c28f76b3124315f90b115b4c0aac967a6ab912b66641be50763af0fa7397fbc2f00161b9cfbf66a900ec701047ef3a689f8645ddf9d
|
data/README.rdoc
CHANGED
@@ -35,9 +35,9 @@ The following example shows the basic syntax for declaring a DynamoDB-based sche
|
|
35
35
|
|
36
36
|
class AsyncJob < OceanDynamo::Table
|
37
37
|
|
38
|
-
dynamo_schema(:
|
38
|
+
dynamo_schema(:guid) do
|
39
39
|
attribute :credentials, :string
|
40
|
-
attribute :token, :string, default: Proc { SecureRandom.
|
40
|
+
attribute :token, :string, default: Proc { SecureRandom.guid }
|
41
41
|
attribute :steps, :serialized, default: []
|
42
42
|
attribute :max_seconds_in_queue, :integer, default: 1.day
|
43
43
|
attribute :default_poison_limit, :integer, default: 5
|
@@ -59,7 +59,7 @@ The following example shows the basic syntax for declaring a DynamoDB-based sche
|
|
59
59
|
|
60
60
|
Each attribute has a name, a type (+:string+, +:integer+, +:float+, +:datetime+, +:boolean+,
|
61
61
|
or +:serialized+) where +:string+ is the default. Each attribute also optionally has a default
|
62
|
-
value, which can be a Proc. The hash key attribute is by default +:id+ (overridden as +:
|
62
|
+
value, which can be a Proc. The hash key attribute is by default +:id+ (overridden as +:guid+ in
|
63
63
|
the example above) and is a +:string+.
|
64
64
|
|
65
65
|
The +:string+, +:integer+, +:float+ and +:datetime+ types can also store sets of their type.
|
@@ -106,7 +106,7 @@ The following example shows how to set up +has_many+ / +belongs_to+ relations:
|
|
106
106
|
|
107
107
|
|
108
108
|
class Topic < OceanDynamo::Table
|
109
|
-
dynamo_schema(:
|
109
|
+
dynamo_schema(:guid) do
|
110
110
|
attribute :title
|
111
111
|
end
|
112
112
|
belongs_to :forum
|
@@ -115,7 +115,7 @@ The following example shows how to set up +has_many+ / +belongs_to+ relations:
|
|
115
115
|
|
116
116
|
|
117
117
|
class Post < OceanDynamo::Table
|
118
|
-
dynamo_schema(:
|
118
|
+
dynamo_schema(:guid) do
|
119
119
|
attribute :body
|
120
120
|
end
|
121
121
|
belongs_to :topic, composite_key: true
|
@@ -142,10 +142,10 @@ relation in a very efficient and massively scalable way.
|
|
142
142
|
|
143
143
|
==== Implementation
|
144
144
|
|
145
|
-
+belongs_to+ claims the range key and uses it to store its own
|
145
|
+
+belongs_to+ claims the range key and uses it to store its own id, which normally
|
146
146
|
would be stored in the hash key attribute. Instead, the hash key attribute holds the
|
147
|
-
|
148
|
-
all children
|
147
|
+
guid of the parent. We have thus reversed the roles of these two fields. As a result,
|
148
|
+
all children store their parent id in the hash key, and their own id in the
|
149
149
|
range key.
|
150
150
|
|
151
151
|
This type of relation is even more efficient than its ActiveRecord counterpart as
|
@@ -162,6 +162,9 @@ which means that secondary indices won't be necessary for the vast majority of
|
|
162
162
|
DynamoDB tables. This ultimately means reduced operational costs, as well as
|
163
163
|
reduced complexity.
|
164
164
|
|
165
|
+
Nevertheless, as we now have switched to v2 of the DynamoDB API, we will be adding
|
166
|
+
the possibility to define both local and secondary indices for Tables.
|
167
|
+
|
165
168
|
|
166
169
|
=== Current State
|
167
170
|
|
@@ -170,7 +173,8 @@ controllers. OceanDynamo implements much of the infrastructure of ActiveRecord;
|
|
170
173
|
for instance, +read_attribute+, +write_attribute+, and much of the control logic and
|
171
174
|
internal organisation.
|
172
175
|
|
173
|
-
*
|
176
|
+
* Version 2 of the AWS Ruby SDK is now used. This required an internal reorganisation,
|
177
|
+
but it also gives us access to local and global secondary indices.
|
174
178
|
* Work begun on collection proxies, etc.
|
175
179
|
|
176
180
|
=== Future milestones
|
@@ -220,13 +224,13 @@ will be a generator to copy these files for you, but for now you need to do it m
|
|
220
224
|
* Ocean-dynamo gem on Rubygems: https://rubygems.org/gems/ocean-dynamo
|
221
225
|
* Ocean-dynamo gem API: http://rubydoc.info/gems/ocean-dynamo/frames
|
222
226
|
* Ocean-dynamo source and wiki: https://github.org/OceanDev/ocean-dynamo
|
227
|
+
* AWS DynamoDB Ruby SDK v2: http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB.html
|
223
228
|
|
224
|
-
|
225
|
-
|
229
|
+
You might also want to take a look at Ocean, a Rails framework and development pipeline
|
230
|
+
for creating highly scalable HATEOAS microservice SOAs in the cloud. Ocean uses
|
231
|
+
OceanDynamo as a central component:
|
226
232
|
* http://wiki.oceanframework.net
|
227
233
|
|
228
|
-
* AWS Ruby SDK v2 for DynamoDB: http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB.html
|
229
|
-
|
230
234
|
|
231
235
|
== Contributing
|
232
236
|
|
@@ -238,12 +242,9 @@ All contributed code must therefore also be exhaustively tested.
|
|
238
242
|
|
239
243
|
== Running the specs
|
240
244
|
|
241
|
-
To run the specs for the OceanDynamo gem, you must first install DynamoDB Local.
|
242
|
-
|
243
|
-
|
244
|
-
Starting with +ocean-dynamo+ 0.8.0, we're using v2 of the AWS SDK Ruby gem and the latest version
|
245
|
-
of the DynamoDB API (2012-08-10). This means that we now have access to secondary indices,
|
246
|
-
amongst other things.
|
245
|
+
To run the specs for the OceanDynamo gem, you must first install DynamoDB Local.
|
246
|
+
It's a Java clone of Amazon DynamoDB which runs locally on your computer. We use
|
247
|
+
it for development and testing.
|
247
248
|
|
248
249
|
Download DynamoDB Local from the following location: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Tools.DynamoDBLocal.html
|
249
250
|
|
@@ -251,13 +252,16 @@ Next, copy the AWS configuration file from the template:
|
|
251
252
|
|
252
253
|
cp spec/dummy/config/aws.yml.example spec/dummy/config/aws.yml
|
253
254
|
|
254
|
-
NB: +aws.yml+
|
255
|
-
safely.
|
255
|
+
NB: +aws.yml+ should be excluded from source control. This allows you to enter your AWS
|
256
|
+
credentials safely. On the other hand, +aws.yml.example+ SHOULD be under source control.
|
257
|
+
Don't put sensitive information in it.
|
256
258
|
|
257
259
|
You're now ready to start DynamoDB Local:
|
258
260
|
|
259
261
|
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb
|
260
262
|
|
263
|
+
Replace +-sharedDb+ with +-inMemory+ to run the DB in RAM.
|
264
|
+
|
261
265
|
With DynamoDB Local running, you should now be able to do
|
262
266
|
|
263
267
|
rspec
|
@@ -268,18 +272,23 @@ All tests should pass.
|
|
268
272
|
=== Resetting the DynamoDB Local database
|
269
273
|
|
270
274
|
You might want to add the following to your spec_helper.rb file, inside the +RSpec.configure+
|
271
|
-
block:
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
275
|
+
block. It deletes all test tables before your test suite is run:
|
276
|
+
|
277
|
+
config.before(:suite) do
|
278
|
+
c = Aws::DynamoDB::Client.new
|
279
|
+
regexp = Regexp.new("^.+_[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}_test$")
|
280
|
+
c.list_tables.table_names.each do |t|
|
281
|
+
next unless t =~ regexp
|
282
|
+
c.delete_table({table_name: t})
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
You can add an +after(:suite)+ block too if you like, to remove all test tables after
|
287
|
+
the suite has run. Later, we will add automatic removal of only those tables created
|
288
|
+
by the test run itself, which is required when tests are done in parallel against
|
289
|
+
the real AWS service. Until then, you might want to modify the above code to do nothing
|
290
|
+
when running against AWS and clear your test tables manually. (If you're running Ocean,
|
291
|
+
an Ocean CronJob will already take care of this for you each night.)
|
283
292
|
|
284
293
|
== Rails console
|
285
294
|
|
data/lib/ocean-dynamo/version.rb
CHANGED