alephant-harness 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e44f5190ecab68c2e9b31e07b9c431922a75b21e
4
- data.tar.gz: 4be42c40689f4aa9cf16d40bc1340b610d6b3d33
3
+ metadata.gz: c7c2f7020c1df1e241c8aeba1d979b6cfd18ea5e
4
+ data.tar.gz: 5a7a8a2302d20af4cef6be3eddf91fce8b0417cf
5
5
  SHA512:
6
- metadata.gz: ef13d337d3af7d18a86662e7ef1142a902aab924dcb852781255feb28d36204d4a11deea19268cd98b9a691c38c81bdd8ffdba8b206465a842d9b098744c5f2b
7
- data.tar.gz: 2729ab1692a3e49849199bbdb597deb4204292a590b18d5daa49c034c55d9946eee49c84b6b7fb4299893211f58136254a3b95574c72375435e9f7b3a5b3ec74
6
+ metadata.gz: 192d57c3bd1e1d02f9357462cb53fdd619cfb78a6b5f1195b5fd9042a4dc3113dd34607dced786d7b652f06b09a878bbef82498769b80459531ae23201d72387
7
+ data.tar.gz: 91d9bc269c4b79d232e8281e5c89df7d011087c7f9bbf8e60d2e56d0e6bdc957ccd9b50987298215b9f2b2864f09e36054b5990176cc3ff814bca4f9be73e9a1
@@ -10,21 +10,18 @@ module Alephant
10
10
  @@client ||= ::AWS::DynamoDB::Client::V20120810.new
11
11
  end
12
12
 
13
- def self.create(table_name, schema_name)
14
- schema = load_schema(schema_name).tap { |s| s[:table_name] = table_name }
13
+ def self.create(table_name, schema)
14
+ schema.tap { |s| s[:table_name] = table_name }
15
15
  client.create_table schema
16
16
  end
17
17
 
18
- def self.remove(tables)
19
- tables.each do |table_name|
20
- begin
21
- client.delete_table({ :table_name => table_name })
22
- rescue Exception => e
23
- #If table doesn't exist fail silently
24
- end
25
- end
18
+ def self.remove(table_name)
19
+ client.delete_table({ :table_name => table_name })
20
+ rescue Exception => e
21
+ #If table doesn't exist fail silently
26
22
  end
27
23
 
24
+
28
25
  def self.load_schema(schema_name)
29
26
  YAML::load_file(File.join([File.dirname(__FILE__), *(%w'..' * 4), 'schema', "#{schema_name}.yaml"]))
30
27
  end
@@ -37,6 +37,18 @@ module Alephant
37
37
  get_object(id, object_id).delete
38
38
  end
39
39
 
40
+ def self.bucket_exists?(bucket_id)
41
+ begin
42
+ exists = client.buckets[bucket_id].exists?
43
+ rescue ::AWS::S3::Errors::NoSuchKey => e
44
+ exists = false
45
+ end
46
+
47
+ exists.tap do |e|
48
+ yeild if e && block_given?
49
+ end
50
+ end
51
+
40
52
  def self.exists?(id, object_id)
41
53
  if get_object(id, object_id)
42
54
  yield
@@ -2,51 +2,67 @@ require "alephant/harness/service/dynamo_db"
2
2
  require "alephant/harness/service/s3"
3
3
  require "alephant/harness/service/sqs"
4
4
  require "alephant/harness/aws"
5
+ require "logger"
5
6
 
6
7
  module Alephant
7
8
  module Harness
8
9
  module Setup
9
10
 
11
+ def self.logger
12
+ @@logger ||= ::Logger.new(STDOUT)
13
+ end
14
+
10
15
  def self.configure(opts = {}, env = nil)
11
16
  AWS.configure(env)
12
17
 
13
- opts[:queues].each do |queue_name|
14
- recreate_sqs queue_name
18
+ unless opts[:queues].nil?
19
+ logger.info "Adding #{opts[:queues].length} queue(s)"
20
+ opts[:queues].each do |queue_name|
21
+ recreate_sqs queue_name
22
+ end
15
23
  end
16
24
 
17
- bucket = opts[:bucket_id] and recreate_s3 bucket
18
-
19
- tables = {
20
- :lookup => opts[:lookup_table_name],
21
- :sequencer => opts[:sequencer_table_name],
22
- } and recreate_dynamo_db tables
25
+ unless opts[:buckets].nil?
26
+ logger.info "Adding #{opts[:buckets].length} bucket(s)"
27
+ opts[:buckets].each do |bucket|
28
+ recreate_s3 bucket
29
+ end
30
+ end
23
31
 
32
+ unless opts[:tables].nil?
33
+ logger.info "Adding #{opts[:tables].length} table(s)"
34
+ opts[:tables].each do |data|
35
+ recreate_dynamo_db(data[:name], data[:schema])
36
+ end
37
+ end
24
38
  end
25
39
 
26
40
  def self.recreate_sqs(queue_name)
27
41
  Service::SQS.exists?(queue_name) do
42
+ logger.warn "SQS queue #{queue_name} exists, removing"
28
43
  Service::SQS.delete(queue_name)
29
44
  end
30
45
 
46
+ logger.info "Adding SQS queue #{queue_name}"
31
47
  Service::SQS.create(queue_name)
32
48
  end
33
49
 
34
50
  def self.recreate_s3(bucket)
35
- Service::S3.exists?(bucket) do
51
+ Service::S3.bucket_exists?(bucket) do
52
+ logger.warn "S3 bucket #{bucket} exists, removing"
36
53
  Service::S3.delete(bucket)
37
54
  end
38
55
 
39
- Service::S3.create(queue_name)
56
+ logger.info "Adding S3 bucket #{bucket}"
57
+ Service::S3.create(bucket)
40
58
  end
41
59
 
42
- def self.recreate_dynamo_db(tables)
43
- Service::DynamoDB.remove(tables.values)
44
-
45
- tables.each do |schema_name, table_name|
46
- Service::DynamoDB.create(table_name, schema_name)
47
- end
60
+ def self.recreate_dynamo_db(table_name, schema)
61
+ logger.info "Adding DynamoDB table #{table_name}"
62
+ Service::DynamoDB.remove(table_name)
63
+ schema = schema.is_a?(Hash) ? schema : Service::DynamoDB.load_schema(schema)
64
+ Service::DynamoDB.create(table_name, schema)
48
65
  end
49
-
50
66
  end
51
67
  end
52
68
  end
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Harness
3
- VERSION = "0.1.3"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -7,12 +7,13 @@ describe Alephant::Harness::Service::DynamoDB do
7
7
 
8
8
  table_name = 'test_lookup'
9
9
  schema_name = 'lookup'
10
+ schema = subject.load_schema(schema_name)
10
11
 
11
12
  expected_schema = YAML::load_file(File.join(File.dirname(__FILE__), *[%w'..' * 2], 'schema', "#{schema_name}.yaml"))
12
13
  expected_schema[:table_name] = table_name
13
14
 
14
15
  expect_any_instance_of(AWS::DynamoDB::Client::V20120810).to receive(:create_table).with(expected_schema)
15
- subject.create(table_name, schema_name)
16
+ subject.create(table_name, schema)
16
17
 
17
18
  end
18
19
  end
@@ -23,14 +24,16 @@ describe Alephant::Harness::Service::DynamoDB do
23
24
  context "When tables exist" do
24
25
  it "removes specified tables" do
25
26
  expect_any_instance_of(AWS::DynamoDB::Client::V20120810).to receive(:delete_table).twice
26
- subject.remove(tables)
27
+ tables.each do |table|
28
+ subject.remove(table)
29
+ end
27
30
  end
28
31
  end
29
32
 
30
33
  context "When tables don't exist" do
31
34
  it "Fails silently" do
32
- expect_any_instance_of(AWS::DynamoDB::Client::V20120810).to receive(:delete_table).twice.and_raise(Exception)
33
- expect { subject.remove(tables) }.to_not raise_error(Exception)
35
+ expect_any_instance_of(AWS::DynamoDB::Client::V20120810).to receive(:delete_table).and_raise(Exception)
36
+ expect { subject.remove('blah') }.to_not raise_error(Exception)
34
37
  end
35
38
  end
36
39
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant-harness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Jack
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-11 00:00:00.000000000 Z
11
+ date: 2014-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk