alephant-broker 3.1.1 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -2
- data/alephant-broker.gemspec +1 -1
- data/lib/alephant/broker/load_strategy/s3/archived.rb +17 -0
- data/lib/alephant/broker/load_strategy/s3/base.rb +89 -0
- data/lib/alephant/broker/load_strategy/s3/sequenced.rb +35 -0
- data/lib/alephant/broker/version.rb +1 -1
- data/spec/archive_spec.rb +24 -0
- data/spec/rack_spec.rb +7 -7
- data/spec/spec_helper.rb +2 -1
- metadata +56 -52
- data/lib/alephant/broker/load_strategy/s3.rb +0 -93
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70103bf930de096da5829872125d161af9a9d17a
|
4
|
+
data.tar.gz: 95a5865427ae88a3b456f1f38e0ae7583f309f37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51e92cb40072fbe3088e08495fabfc90e4140255572ac8ae0a720398c8e25ed4d5b87e86bbaa850c5b276b83c4e2640debf35917a7bd4b496c158a252207d0f0
|
7
|
+
data.tar.gz: a5fae01f6f1d2463e9dc028b0850cdbf7c767853aaf0787acd522bf626739c77863e79b130d2aa16723fc9b82dab004987ac917c15a65eec34bab8dd40468a61
|
data/.travis.yml
CHANGED
data/alephant-broker.gemspec
CHANGED
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
|
|
33
33
|
|
34
34
|
spec.add_runtime_dependency "alephant-lookup"
|
35
35
|
spec.add_runtime_dependency "alephant-cache"
|
36
|
-
spec.add_runtime_dependency
|
36
|
+
spec.add_runtime_dependency "alephant-logger", "~> 0"
|
37
37
|
spec.add_runtime_dependency 'alephant-sequencer'
|
38
38
|
spec.add_runtime_dependency "dalli-elasticache"
|
39
39
|
spec.add_runtime_dependency "pmap"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "alephant/broker/load_strategy/s3/base"
|
2
|
+
|
3
|
+
module Alephant
|
4
|
+
module Broker
|
5
|
+
module LoadStrategy
|
6
|
+
module S3
|
7
|
+
class Archived < Base
|
8
|
+
def s3_path(component_meta)
|
9
|
+
component_meta.id.tap do |location|
|
10
|
+
raise InvalidCacheKey if location.nil?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require "alephant/broker/cache"
|
2
|
+
require "alephant/broker/errors/content_not_found"
|
3
|
+
require "alephant/broker/errors/invalid_cache_key"
|
4
|
+
require "alephant/logger"
|
5
|
+
|
6
|
+
module Alephant
|
7
|
+
module Broker
|
8
|
+
module LoadStrategy
|
9
|
+
module S3
|
10
|
+
class Base
|
11
|
+
include Logger
|
12
|
+
|
13
|
+
def load(component_meta)
|
14
|
+
add_s3_headers(
|
15
|
+
cache_object(component_meta),
|
16
|
+
component_meta
|
17
|
+
)
|
18
|
+
rescue
|
19
|
+
logger.metric(
|
20
|
+
:name => "BrokerLoadStrategyS3CacheMiss",
|
21
|
+
:unit => "Count",
|
22
|
+
:value => 1
|
23
|
+
)
|
24
|
+
add_s3_headers(
|
25
|
+
cache.set(
|
26
|
+
component_meta.cache_key,
|
27
|
+
retrieve_object(component_meta)
|
28
|
+
),
|
29
|
+
component_meta
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
protected
|
34
|
+
|
35
|
+
def headers(component_meta)
|
36
|
+
Hash.new
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def s3_path(component_meta)
|
42
|
+
fail NotImplementedError
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_s3_headers(component_data, component_meta)
|
46
|
+
component_data.merge(
|
47
|
+
:headers => headers(component_meta)
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def cache
|
52
|
+
@cache ||= Cache::Client.new
|
53
|
+
end
|
54
|
+
|
55
|
+
def retrieve_object(component_meta)
|
56
|
+
component_meta.cached = false
|
57
|
+
s3.get s3_path(component_meta)
|
58
|
+
rescue AWS::S3::Errors::NoSuchKey, InvalidCacheKey
|
59
|
+
logger.metric(
|
60
|
+
:name => "BrokerLoadStrategyS3InvalidCacheKey",
|
61
|
+
:unit => "Count",
|
62
|
+
:value => 1
|
63
|
+
)
|
64
|
+
raise Alephant::Broker::Errors::ContentNotFound
|
65
|
+
end
|
66
|
+
|
67
|
+
def cache_object(component_meta)
|
68
|
+
cache.get(component_meta.cache_key) do
|
69
|
+
retrieve_object component_meta
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def s3
|
74
|
+
@s3 ||= Alephant::Cache.new(
|
75
|
+
Broker.config[:s3_bucket_id],
|
76
|
+
Broker.config[:s3_object_path]
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
def lookup
|
81
|
+
@lookup ||= Alephant::Lookup.create(
|
82
|
+
Broker.config[:lookup_table_name]
|
83
|
+
)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "alephant/broker/load_strategy/s3/base"
|
2
|
+
|
3
|
+
module Alephant
|
4
|
+
module Broker
|
5
|
+
module LoadStrategy
|
6
|
+
module S3
|
7
|
+
class Sequenced < Base
|
8
|
+
def sequence(component_meta)
|
9
|
+
sequencer.get_last_seen component_meta.key
|
10
|
+
end
|
11
|
+
|
12
|
+
def headers(component_meta)
|
13
|
+
{ "X-Sequence" => sequence(component_meta).to_s }
|
14
|
+
end
|
15
|
+
|
16
|
+
def s3_path(component_meta)
|
17
|
+
lookup.read(
|
18
|
+
component_meta.id,
|
19
|
+
component_meta.options,
|
20
|
+
sequence(component_meta)
|
21
|
+
).tap do |obj|
|
22
|
+
fail InvalidCacheKey if obj.location.nil?
|
23
|
+
end.location unless sequence(component_meta).nil?
|
24
|
+
end
|
25
|
+
|
26
|
+
def sequencer
|
27
|
+
@sequencer ||= Alephant::Sequencer.create(
|
28
|
+
Broker.config[:sequencer_table_name], nil
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Alephant::Broker::LoadStrategy::S3::Archived do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
describe "#s3_path" do
|
7
|
+
let(:id) { 42 }
|
8
|
+
let(:component_meta) { double(:id => id) }
|
9
|
+
|
10
|
+
specify do
|
11
|
+
expect(subject.s3_path component_meta).to eq id
|
12
|
+
end
|
13
|
+
|
14
|
+
context "no location associated with component meta" do
|
15
|
+
let(:component_meta) { double(:id => nil) }
|
16
|
+
|
17
|
+
specify do
|
18
|
+
expect do
|
19
|
+
subject.s3_path component_meta
|
20
|
+
end.to raise_error Alephant::Broker::InvalidCacheKey
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/rack_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Alephant::Broker::Application do
|
|
5
5
|
|
6
6
|
let(:app) do
|
7
7
|
described_class.new(
|
8
|
-
Alephant::Broker::LoadStrategy::S3.new,
|
8
|
+
Alephant::Broker::LoadStrategy::S3::Sequenced.new,
|
9
9
|
{
|
10
10
|
:lookup_table_name => 'test_table',
|
11
11
|
:bucket_id => 'test_bucket',
|
@@ -52,7 +52,7 @@ describe Alephant::Broker::Application do
|
|
52
52
|
specify { expect(last_response.body).to eql 'ok' }
|
53
53
|
end
|
54
54
|
|
55
|
-
describe '404 endpoint `/banana`' do
|
55
|
+
describe '404 endpoint `/banana`' do
|
56
56
|
before { get '/banana' }
|
57
57
|
specify { expect(last_response.status).to eql 404 }
|
58
58
|
specify { expect(last_response.body).to eq 'Not found' }
|
@@ -77,7 +77,7 @@ describe Alephant::Broker::Application do
|
|
77
77
|
specify { expect(last_response.status).to eq 200 }
|
78
78
|
specify { expect(last_response.body).to eq 'Test' }
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
context 'when using valid batch asset data' do
|
82
82
|
before { post '/components/batch', batch_json, 'CONTENT_TYPE' => 'application/json' }
|
83
83
|
specify { expect(last_response.status).to eql 200 }
|
@@ -89,10 +89,10 @@ describe Alephant::Broker::Application do
|
|
89
89
|
let(:cache_double) do
|
90
90
|
instance_double(
|
91
91
|
'Alephant::Broker::Cache::Client',
|
92
|
-
:set => {
|
92
|
+
:set => {
|
93
93
|
:content_type => 'test/html',
|
94
|
-
:content => '<p>Some data</p>'
|
95
|
-
},
|
94
|
+
:content => '<p>Some data</p>'
|
95
|
+
},
|
96
96
|
:get => '<p>Some data</p>'
|
97
97
|
)
|
98
98
|
end
|
@@ -117,7 +117,7 @@ describe Alephant::Broker::Application do
|
|
117
117
|
end
|
118
118
|
it 'should update the cache (call `.set`)' do
|
119
119
|
expect(cache_double).to receive(:set).once
|
120
|
-
end
|
120
|
+
end
|
121
121
|
after { get '/component/test_component' }
|
122
122
|
end
|
123
123
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,7 +3,8 @@ $: << File.join(File.dirname(__FILE__), '..', 'lib')
|
|
3
3
|
require 'pry'
|
4
4
|
require 'json'
|
5
5
|
require 'alephant/broker'
|
6
|
-
require 'alephant/broker/load_strategy/s3'
|
6
|
+
require 'alephant/broker/load_strategy/s3/sequenced'
|
7
|
+
require 'alephant/broker/load_strategy/s3/archived'
|
7
8
|
require "alephant/broker/load_strategy/http"
|
8
9
|
require "alephant/broker/cache"
|
9
10
|
require "alephant/broker/errors/content_not_found"
|
metadata
CHANGED
@@ -1,281 +1,281 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alephant-broker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.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:
|
11
|
+
date: 2015-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: rspec
|
15
|
-
version_requirements: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '>='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
14
|
requirement: !ruby/object:Gem::Requirement
|
21
15
|
requirements:
|
22
16
|
- - '>='
|
23
17
|
- !ruby/object:Gem::Version
|
24
18
|
version: '0'
|
19
|
+
name: rspec
|
25
20
|
prerelease: false
|
26
21
|
type: :development
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec-nc
|
29
22
|
version_requirements: !ruby/object:Gem::Requirement
|
30
23
|
requirements:
|
31
24
|
- - '>='
|
32
25
|
- !ruby/object:Gem::Version
|
33
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
34
28
|
requirement: !ruby/object:Gem::Requirement
|
35
29
|
requirements:
|
36
30
|
- - '>='
|
37
31
|
- !ruby/object:Gem::Version
|
38
32
|
version: '0'
|
33
|
+
name: rspec-nc
|
39
34
|
prerelease: false
|
40
35
|
type: :development
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: guard
|
43
36
|
version_requirements: !ruby/object:Gem::Requirement
|
44
37
|
requirements:
|
45
38
|
- - '>='
|
46
39
|
- !ruby/object:Gem::Version
|
47
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
48
42
|
requirement: !ruby/object:Gem::Requirement
|
49
43
|
requirements:
|
50
44
|
- - '>='
|
51
45
|
- !ruby/object:Gem::Version
|
52
46
|
version: '0'
|
47
|
+
name: guard
|
53
48
|
prerelease: false
|
54
49
|
type: :development
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: guard-rspec
|
57
50
|
version_requirements: !ruby/object:Gem::Requirement
|
58
51
|
requirements:
|
59
52
|
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
62
56
|
requirement: !ruby/object:Gem::Requirement
|
63
57
|
requirements:
|
64
58
|
- - '>='
|
65
59
|
- !ruby/object:Gem::Version
|
66
60
|
version: '0'
|
61
|
+
name: guard-rspec
|
67
62
|
prerelease: false
|
68
63
|
type: :development
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: pry
|
71
64
|
version_requirements: !ruby/object:Gem::Requirement
|
72
65
|
requirements:
|
73
66
|
- - '>='
|
74
67
|
- !ruby/object:Gem::Version
|
75
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
76
70
|
requirement: !ruby/object:Gem::Requirement
|
77
71
|
requirements:
|
78
72
|
- - '>='
|
79
73
|
- !ruby/object:Gem::Version
|
80
74
|
version: '0'
|
75
|
+
name: pry
|
81
76
|
prerelease: false
|
82
77
|
type: :development
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: pry-remote
|
85
78
|
version_requirements: !ruby/object:Gem::Requirement
|
86
79
|
requirements:
|
87
80
|
- - '>='
|
88
81
|
- !ruby/object:Gem::Version
|
89
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
90
84
|
requirement: !ruby/object:Gem::Requirement
|
91
85
|
requirements:
|
92
86
|
- - '>='
|
93
87
|
- !ruby/object:Gem::Version
|
94
88
|
version: '0'
|
89
|
+
name: pry-remote
|
95
90
|
prerelease: false
|
96
91
|
type: :development
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: pry-nav
|
99
92
|
version_requirements: !ruby/object:Gem::Requirement
|
100
93
|
requirements:
|
101
94
|
- - '>='
|
102
95
|
- !ruby/object:Gem::Version
|
103
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
104
98
|
requirement: !ruby/object:Gem::Requirement
|
105
99
|
requirements:
|
106
100
|
- - '>='
|
107
101
|
- !ruby/object:Gem::Version
|
108
102
|
version: '0'
|
103
|
+
name: pry-nav
|
109
104
|
prerelease: false
|
110
105
|
type: :development
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rake-rspec
|
113
106
|
version_requirements: !ruby/object:Gem::Requirement
|
114
107
|
requirements:
|
115
108
|
- - '>='
|
116
109
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
118
112
|
requirement: !ruby/object:Gem::Requirement
|
119
113
|
requirements:
|
120
114
|
- - '>='
|
121
115
|
- !ruby/object:Gem::Version
|
122
116
|
version: 0.0.2
|
117
|
+
name: rake-rspec
|
123
118
|
prerelease: false
|
124
119
|
type: :development
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: bundler
|
127
120
|
version_requirements: !ruby/object:Gem::Requirement
|
128
121
|
requirements:
|
129
|
-
- -
|
122
|
+
- - '>='
|
130
123
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
124
|
+
version: 0.0.2
|
125
|
+
- !ruby/object:Gem::Dependency
|
132
126
|
requirement: !ruby/object:Gem::Requirement
|
133
127
|
requirements:
|
134
128
|
- - ~>
|
135
129
|
- !ruby/object:Gem::Version
|
136
130
|
version: '1.5'
|
131
|
+
name: bundler
|
137
132
|
prerelease: false
|
138
133
|
type: :development
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: rake
|
141
134
|
version_requirements: !ruby/object:Gem::Requirement
|
142
135
|
requirements:
|
143
|
-
- -
|
136
|
+
- - ~>
|
144
137
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
138
|
+
version: '1.5'
|
139
|
+
- !ruby/object:Gem::Dependency
|
146
140
|
requirement: !ruby/object:Gem::Requirement
|
147
141
|
requirements:
|
148
142
|
- - '>='
|
149
143
|
- !ruby/object:Gem::Version
|
150
144
|
version: '0'
|
145
|
+
name: rake
|
151
146
|
prerelease: false
|
152
147
|
type: :development
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: rack-test
|
155
148
|
version_requirements: !ruby/object:Gem::Requirement
|
156
149
|
requirements:
|
157
150
|
- - '>='
|
158
151
|
- !ruby/object:Gem::Version
|
159
152
|
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
160
154
|
requirement: !ruby/object:Gem::Requirement
|
161
155
|
requirements:
|
162
156
|
- - '>='
|
163
157
|
- !ruby/object:Gem::Version
|
164
158
|
version: '0'
|
159
|
+
name: rack-test
|
165
160
|
prerelease: false
|
166
161
|
type: :development
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
|
-
name: alephant-lookup
|
169
162
|
version_requirements: !ruby/object:Gem::Requirement
|
170
163
|
requirements:
|
171
164
|
- - '>='
|
172
165
|
- !ruby/object:Gem::Version
|
173
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
174
168
|
requirement: !ruby/object:Gem::Requirement
|
175
169
|
requirements:
|
176
170
|
- - '>='
|
177
171
|
- !ruby/object:Gem::Version
|
178
172
|
version: '0'
|
173
|
+
name: alephant-lookup
|
179
174
|
prerelease: false
|
180
175
|
type: :runtime
|
181
|
-
- !ruby/object:Gem::Dependency
|
182
|
-
name: alephant-cache
|
183
176
|
version_requirements: !ruby/object:Gem::Requirement
|
184
177
|
requirements:
|
185
178
|
- - '>='
|
186
179
|
- !ruby/object:Gem::Version
|
187
180
|
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
188
182
|
requirement: !ruby/object:Gem::Requirement
|
189
183
|
requirements:
|
190
184
|
- - '>='
|
191
185
|
- !ruby/object:Gem::Version
|
192
186
|
version: '0'
|
187
|
+
name: alephant-cache
|
193
188
|
prerelease: false
|
194
189
|
type: :runtime
|
195
|
-
- !ruby/object:Gem::Dependency
|
196
|
-
name: alephant-logger
|
197
190
|
version_requirements: !ruby/object:Gem::Requirement
|
198
191
|
requirements:
|
199
192
|
- - '>='
|
200
193
|
- !ruby/object:Gem::Version
|
201
194
|
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
202
196
|
requirement: !ruby/object:Gem::Requirement
|
203
197
|
requirements:
|
204
|
-
- -
|
198
|
+
- - ~>
|
205
199
|
- !ruby/object:Gem::Version
|
206
200
|
version: '0'
|
201
|
+
name: alephant-logger
|
207
202
|
prerelease: false
|
208
203
|
type: :runtime
|
209
|
-
- !ruby/object:Gem::Dependency
|
210
|
-
name: alephant-sequencer
|
211
204
|
version_requirements: !ruby/object:Gem::Requirement
|
212
205
|
requirements:
|
213
|
-
- -
|
206
|
+
- - ~>
|
214
207
|
- !ruby/object:Gem::Version
|
215
208
|
version: '0'
|
209
|
+
- !ruby/object:Gem::Dependency
|
216
210
|
requirement: !ruby/object:Gem::Requirement
|
217
211
|
requirements:
|
218
212
|
- - '>='
|
219
213
|
- !ruby/object:Gem::Version
|
220
214
|
version: '0'
|
215
|
+
name: alephant-sequencer
|
221
216
|
prerelease: false
|
222
217
|
type: :runtime
|
223
|
-
- !ruby/object:Gem::Dependency
|
224
|
-
name: dalli-elasticache
|
225
218
|
version_requirements: !ruby/object:Gem::Requirement
|
226
219
|
requirements:
|
227
220
|
- - '>='
|
228
221
|
- !ruby/object:Gem::Version
|
229
222
|
version: '0'
|
223
|
+
- !ruby/object:Gem::Dependency
|
230
224
|
requirement: !ruby/object:Gem::Requirement
|
231
225
|
requirements:
|
232
226
|
- - '>='
|
233
227
|
- !ruby/object:Gem::Version
|
234
228
|
version: '0'
|
229
|
+
name: dalli-elasticache
|
235
230
|
prerelease: false
|
236
231
|
type: :runtime
|
237
|
-
- !ruby/object:Gem::Dependency
|
238
|
-
name: pmap
|
239
232
|
version_requirements: !ruby/object:Gem::Requirement
|
240
233
|
requirements:
|
241
234
|
- - '>='
|
242
235
|
- !ruby/object:Gem::Version
|
243
236
|
version: '0'
|
237
|
+
- !ruby/object:Gem::Dependency
|
244
238
|
requirement: !ruby/object:Gem::Requirement
|
245
239
|
requirements:
|
246
240
|
- - '>='
|
247
241
|
- !ruby/object:Gem::Version
|
248
242
|
version: '0'
|
243
|
+
name: pmap
|
249
244
|
prerelease: false
|
250
245
|
type: :runtime
|
251
|
-
- !ruby/object:Gem::Dependency
|
252
|
-
name: faraday
|
253
246
|
version_requirements: !ruby/object:Gem::Requirement
|
254
247
|
requirements:
|
255
248
|
- - '>='
|
256
249
|
- !ruby/object:Gem::Version
|
257
250
|
version: '0'
|
251
|
+
- !ruby/object:Gem::Dependency
|
258
252
|
requirement: !ruby/object:Gem::Requirement
|
259
253
|
requirements:
|
260
254
|
- - '>='
|
261
255
|
- !ruby/object:Gem::Version
|
262
256
|
version: '0'
|
257
|
+
name: faraday
|
263
258
|
prerelease: false
|
264
259
|
type: :runtime
|
265
|
-
- !ruby/object:Gem::Dependency
|
266
|
-
name: crimp
|
267
260
|
version_requirements: !ruby/object:Gem::Requirement
|
268
261
|
requirements:
|
269
262
|
- - '>='
|
270
263
|
- !ruby/object:Gem::Version
|
271
264
|
version: '0'
|
265
|
+
- !ruby/object:Gem::Dependency
|
272
266
|
requirement: !ruby/object:Gem::Requirement
|
273
267
|
requirements:
|
274
268
|
- - '>='
|
275
269
|
- !ruby/object:Gem::Version
|
276
270
|
version: '0'
|
271
|
+
name: crimp
|
277
272
|
prerelease: false
|
278
273
|
type: :runtime
|
274
|
+
version_requirements: !ruby/object:Gem::Requirement
|
275
|
+
requirements:
|
276
|
+
- - '>='
|
277
|
+
- !ruby/object:Gem::Version
|
278
|
+
version: '0'
|
279
279
|
description: Brokers requests for alephant components
|
280
280
|
email:
|
281
281
|
- stevenmajack@gmail.com
|
@@ -303,7 +303,9 @@ files:
|
|
303
303
|
- lib/alephant/broker/errors/invalid_asset_id.rb
|
304
304
|
- lib/alephant/broker/errors/invalid_cache_key.rb
|
305
305
|
- lib/alephant/broker/load_strategy/http.rb
|
306
|
-
- lib/alephant/broker/load_strategy/s3.rb
|
306
|
+
- lib/alephant/broker/load_strategy/s3/archived.rb
|
307
|
+
- lib/alephant/broker/load_strategy/s3/base.rb
|
308
|
+
- lib/alephant/broker/load_strategy/s3/sequenced.rb
|
307
309
|
- lib/alephant/broker/request.rb
|
308
310
|
- lib/alephant/broker/request/asset.rb
|
309
311
|
- lib/alephant/broker/request/batch.rb
|
@@ -315,6 +317,7 @@ files:
|
|
315
317
|
- lib/alephant/broker/response/batch.rb
|
316
318
|
- lib/alephant/broker/response/factory.rb
|
317
319
|
- lib/alephant/broker/version.rb
|
320
|
+
- spec/archive_spec.rb
|
318
321
|
- spec/component_meta_spec.rb
|
319
322
|
- spec/fixtures/json/batch.json
|
320
323
|
- spec/fixtures/json/batch_compiled.json
|
@@ -347,6 +350,7 @@ signing_key:
|
|
347
350
|
specification_version: 4
|
348
351
|
summary: Brokers requests for alephant components
|
349
352
|
test_files:
|
353
|
+
- spec/archive_spec.rb
|
350
354
|
- spec/component_meta_spec.rb
|
351
355
|
- spec/fixtures/json/batch.json
|
352
356
|
- spec/fixtures/json/batch_compiled.json
|
@@ -1,93 +0,0 @@
|
|
1
|
-
require "alephant/broker/cache"
|
2
|
-
require 'alephant/broker/errors/content_not_found'
|
3
|
-
require 'alephant/broker/errors/invalid_cache_key'
|
4
|
-
require 'alephant/logger'
|
5
|
-
|
6
|
-
module Alephant
|
7
|
-
module Broker
|
8
|
-
module LoadStrategy
|
9
|
-
class S3
|
10
|
-
include Logger
|
11
|
-
|
12
|
-
def load(component_meta)
|
13
|
-
add_s3_headers(
|
14
|
-
cache_object(component_meta),
|
15
|
-
component_meta
|
16
|
-
)
|
17
|
-
rescue
|
18
|
-
logger.metric(:name => "BrokerLoadStrategyS3CacheMiss", :unit => "Count", :value => 1)
|
19
|
-
add_s3_headers(
|
20
|
-
cache.set(
|
21
|
-
component_meta.cache_key,
|
22
|
-
retrieve_object(component_meta)
|
23
|
-
),
|
24
|
-
component_meta
|
25
|
-
)
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def add_s3_headers(component_data, component_meta)
|
31
|
-
component_data.merge(
|
32
|
-
{ headers: headers(component_meta) }
|
33
|
-
)
|
34
|
-
end
|
35
|
-
|
36
|
-
def cache
|
37
|
-
@cache ||= Cache::Client.new
|
38
|
-
end
|
39
|
-
|
40
|
-
def headers(component_meta)
|
41
|
-
{ 'X-Sequence' => sequence(component_meta).to_s }
|
42
|
-
end
|
43
|
-
|
44
|
-
def sequence(component_meta)
|
45
|
-
sequencer.get_last_seen component_meta.key
|
46
|
-
end
|
47
|
-
|
48
|
-
def retrieve_object(component_meta)
|
49
|
-
component_meta.cached = false
|
50
|
-
s3.get s3_path(component_meta)
|
51
|
-
rescue AWS::S3::Errors::NoSuchKey, InvalidCacheKey
|
52
|
-
logger.metric(:name => "BrokerLoadStrategyS3InvalidCacheKey", :unit => "Count", :value => 1)
|
53
|
-
raise Alephant::Broker::Errors::ContentNotFound
|
54
|
-
end
|
55
|
-
|
56
|
-
def cache_object(component_meta)
|
57
|
-
cache.get(component_meta.cache_key) do
|
58
|
-
retrieve_object component_meta
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def s3
|
63
|
-
@s3 ||= Alephant::Cache.new(
|
64
|
-
Broker.config[:s3_bucket_id],
|
65
|
-
Broker.config[:s3_object_path]
|
66
|
-
)
|
67
|
-
end
|
68
|
-
|
69
|
-
def s3_path(component_meta)
|
70
|
-
lookup.read(
|
71
|
-
component_meta.id,
|
72
|
-
component_meta.options,
|
73
|
-
sequence(component_meta)
|
74
|
-
).tap do |obj|
|
75
|
-
raise InvalidCacheKey if obj.location.nil?
|
76
|
-
end.location unless sequence(component_meta).nil?
|
77
|
-
end
|
78
|
-
|
79
|
-
def lookup
|
80
|
-
@lookup ||= Alephant::Lookup.create(
|
81
|
-
Broker.config[:lookup_table_name]
|
82
|
-
)
|
83
|
-
end
|
84
|
-
|
85
|
-
def sequencer
|
86
|
-
@sequencer ||= Alephant::Sequencer.create(
|
87
|
-
Broker.config[:sequencer_table_name], nil
|
88
|
-
)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|