MovableInkAWS 0.1.12 → 0.1.13

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
  SHA256:
3
- metadata.gz: 6068f47fd36870a62486fe861142c4f54d039d08699eb7067de12e2601345dce
4
- data.tar.gz: 0ddae90ec17a4ed18309e8c6116a6b803cf93b8292611a6a74098772e461b2c0
3
+ metadata.gz: 9940e314b3dc8c1174f75e495f67a2879b057c2dff22e9cc10e5b85c848684c9
4
+ data.tar.gz: d65a2015d5c254bf1520a8bcffd5dbb3b73d9c2c587f3425204f69244be1b5b6
5
5
  SHA512:
6
- metadata.gz: d6426c56c304a32b4943fddf5fa566aed036d06c1bf36c03c3432f1b4508b004894c15aca331e810d4d6bdde539587902212876f0f5839d24ba74a7c403e6f2f
7
- data.tar.gz: 24ff69fdb3dfcf9e6f01a90c9fdc0e5a5bc957676554c63dbe179e4103e98a8e4620908bfb132d59c78c1704aa028b835077048bf86058ac21dc33486b3f0112
6
+ metadata.gz: 8d7ce1acf9e30f3f0e5b2015656ee19d6378f947f2f4ee026ab7f5f98e94dc74a4721633fe460defc7b3f66f14ed0c860beabd58d488d4e8bf910c8dd0952453
7
+ data.tar.gz: 5376c892106c465b0cb8c27fcfbe0164c19c4e4eaae0b633d61e13a9cbc2eb5979f993c61021362fa5b280a2134d346c2efba08bbdf8347caf2037c2b5522618
@@ -0,0 +1,48 @@
1
+ module MovableInk
2
+ class AWS
3
+ module ElastiCache
4
+ def elasticache(region: my_region)
5
+ @elasticache_client ||= {}
6
+ @elasticache_client[region] ||= Aws::ElastiCache::Client.new(region: region)
7
+ end
8
+
9
+ def replication_group(role)
10
+ run_with_backoff do
11
+ @replication_group ||= elasticache.describe_replication_groups({replication_group_id: role}).replication_groups.first
12
+ end
13
+ end
14
+
15
+ def elasticache_primary(role)
16
+ replication_group(role).node_groups
17
+ .first
18
+ .primary_endpoint
19
+ .address
20
+ end
21
+
22
+ def all_elasticache_replicas(role)
23
+ replication_group(role).node_groups
24
+ .first
25
+ .node_group_members
26
+ .select{|ng| ng.current_role == 'replica'}
27
+ .map{|member| member.read_endpoint.address}
28
+ end
29
+
30
+ def elasticache_replica_in_my_az(role)
31
+ members = replication_group(role).node_groups
32
+ .first
33
+ .node_group_members
34
+ .select{|ng| ng.preferred_availability_zone == availability_zone}
35
+ begin
36
+ members.select{|ng| ng.current_role == 'replica'}
37
+ .first
38
+ .read_endpoint
39
+ .address
40
+ rescue NoMethodError
41
+ members.first
42
+ .read_endpoint
43
+ .address
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -8,6 +8,8 @@ require_relative 'aws/route53'
8
8
  require_relative 'aws/ssm'
9
9
  require_relative 'aws/athena'
10
10
  require_relative 'aws/s3'
11
+ require_relative 'aws/elasticache'
12
+
11
13
 
12
14
  module MovableInk
13
15
  class AWS
@@ -18,6 +20,7 @@ module MovableInk
18
20
  include SSM
19
21
  include Athena
20
22
  include S3
23
+ include ElastiCache
21
24
 
22
25
  class << self
23
26
  def regions
@@ -1,5 +1,5 @@
1
1
  module MovableInk
2
2
  class AWS
3
- VERSION = '0.1.12'
3
+ VERSION = '0.1.13'
4
4
  end
5
5
  end
@@ -0,0 +1,51 @@
1
+ require_relative '../lib/movable_ink/aws'
2
+
3
+ describe MovableInk::AWS::ElastiCache do
4
+ let(:aws) { MovableInk::AWS.new }
5
+ let(:elasticache) { Aws::ElastiCache::Client.new(stub_responses: true) }
6
+
7
+ describe "elasticache_replica_in_my_az" do
8
+ let(:replication_group) { elasticache.stub_data(:describe_replication_groups, replication_groups: [
9
+ replication_group_id: 'foo',
10
+ node_groups: [{
11
+ primary_endpoint: {address: 'primary'},
12
+ node_group_members: [
13
+ {preferred_availability_zone: 'us-foo-1a',
14
+ read_endpoint: {address: 'address-1a'},
15
+ current_role: 'replica' },
16
+ {preferred_availability_zone: 'us-foo-1a',
17
+ read_endpoint: {address: 'address-1a-primary'},
18
+ current_role: 'primary' },
19
+ {preferred_availability_zone: 'us-foo-1b',
20
+ read_endpoint: {address: 'address-1b'},
21
+ current_role: 'primary' },
22
+ {preferred_availability_zone: 'us-foo-1c',
23
+ read_endpoint: {address: 'address-1c'},
24
+ current_role: 'replica' },
25
+ ]
26
+ }],
27
+ ]
28
+ )}
29
+
30
+ before(:each) do
31
+ elasticache.stub_responses(:describe_replication_groups, replication_group)
32
+ allow(aws).to receive(:mi_env).and_return('test')
33
+ allow(aws).to receive(:elasticache).and_return(elasticache)
34
+ end
35
+
36
+ it "should return the correct read address" do
37
+ allow(aws).to receive(:availability_zone).and_return('us-foo-1a')
38
+ expect(aws.elasticache_replica_in_my_az("foo")).to eq("address-1a")
39
+ end
40
+
41
+ it "should return the primary if there is no replica" do
42
+ allow(aws).to receive(:availability_zone).and_return('us-foo-1b')
43
+ expect(aws.elasticache_replica_in_my_az("foo")).to eq("address-1b")
44
+ end
45
+
46
+ it "should return an array of all replicas" do
47
+ allow(aws).to receive(:availability_zone).and_return('us-foo-1b')
48
+ expect(aws.all_elasticache_replicas("foo")).to eq(["address-1a", "address-1c"])
49
+ end
50
+ end
51
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: MovableInkAWS
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Chesler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-23 00:00:00.000000000 Z
11
+ date: 2018-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -45,6 +45,7 @@ files:
45
45
  - lib/movable_ink/aws/athena.rb
46
46
  - lib/movable_ink/aws/autoscaling.rb
47
47
  - lib/movable_ink/aws/ec2.rb
48
+ - lib/movable_ink/aws/elasticache.rb
48
49
  - lib/movable_ink/aws/errors.rb
49
50
  - lib/movable_ink/aws/route53.rb
50
51
  - lib/movable_ink/aws/s3.rb
@@ -54,6 +55,7 @@ files:
54
55
  - spec/autoscaling_spec.rb
55
56
  - spec/aws_spec.rb
56
57
  - spec/ec2_spec.rb
58
+ - spec/elasticache_spec.rb
57
59
  - spec/route53_spec.rb
58
60
  - spec/s3_spec.rb
59
61
  - spec/sns_spec.rb