flapjack 1.1.0 → 1.2.0rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +12 -7
  5. data/CHANGELOG.md +12 -0
  6. data/Gemfile +6 -2
  7. data/Gemfile-ruby1.9 +29 -0
  8. data/Gemfile-ruby1.9.lock +251 -0
  9. data/README.md +2 -2
  10. data/Rakefile +1 -0
  11. data/etc/flapjack_config.yaml.example +2 -2
  12. data/features/steps/events_steps.rb +2 -2
  13. data/features/steps/flapjack-netsaint-parser_steps.rb +1 -1
  14. data/features/support/env.rb +1 -6
  15. data/lib/flapjack/cli/import.rb +2 -5
  16. data/lib/flapjack/cli/purge.rb +4 -4
  17. data/lib/flapjack/cli/receiver.rb +122 -54
  18. data/lib/flapjack/cli/server.rb +0 -5
  19. data/lib/flapjack/coordinator.rb +6 -0
  20. data/lib/flapjack/data/contact.rb +10 -62
  21. data/lib/flapjack/data/entity.rb +36 -52
  22. data/lib/flapjack/data/entity_check.rb +90 -21
  23. data/lib/flapjack/data/event.rb +4 -5
  24. data/lib/flapjack/data/notification.rb +8 -10
  25. data/lib/flapjack/data/notification_rule.rb +32 -35
  26. data/lib/flapjack/data/tagged.rb +48 -0
  27. data/lib/flapjack/gateways/jabber.rb +4 -5
  28. data/lib/flapjack/gateways/jsonapi/check_methods.rb +45 -7
  29. data/lib/flapjack/gateways/jsonapi/check_presenter.rb +1 -1
  30. data/lib/flapjack/gateways/jsonapi/contact_methods.rb +8 -2
  31. data/lib/flapjack/gateways/jsonapi/entity_methods.rb +26 -8
  32. data/lib/flapjack/gateways/jsonapi/medium_methods.rb +13 -9
  33. data/lib/flapjack/gateways/jsonapi/metrics_methods.rb +2 -2
  34. data/lib/flapjack/gateways/jsonapi/notification_rule_methods.rb +1 -1
  35. data/lib/flapjack/gateways/jsonapi/pagerduty_credential_methods.rb +24 -17
  36. data/lib/flapjack/gateways/jsonapi/rack/json_params_parser.rb +1 -1
  37. data/lib/flapjack/gateways/jsonapi/report_methods.rb +4 -4
  38. data/lib/flapjack/gateways/jsonapi.rb +52 -31
  39. data/lib/flapjack/gateways/oobetet.rb +2 -3
  40. data/lib/flapjack/gateways/pagerduty.rb +9 -8
  41. data/lib/flapjack/gateways/web/public/js/backbone.jsonapi.js +19 -0
  42. data/lib/flapjack/gateways/web/public/js/flapjack.js +6 -2
  43. data/lib/flapjack/gateways/web/public/js/modules/contact.js +9 -14
  44. data/lib/flapjack/gateways/web/public/js/modules/medium.js +1 -0
  45. data/lib/flapjack/gateways/web/public/js/self_stats.js +1 -1
  46. data/lib/flapjack/gateways/web/views/edit_contacts.html.erb +3 -3
  47. data/lib/flapjack/gateways/web.rb +8 -7
  48. data/lib/flapjack/notifier.rb +2 -4
  49. data/lib/flapjack/processor.rb +2 -2
  50. data/lib/flapjack/version.rb +1 -1
  51. data/lib/flapjack.rb +10 -0
  52. data/spec/lib/flapjack/coordinator_spec.rb +18 -0
  53. data/spec/lib/flapjack/data/contact_spec.rb +4 -12
  54. data/spec/lib/flapjack/data/entity_check_spec.rb +56 -3
  55. data/spec/lib/flapjack/data/entity_spec.rb +79 -67
  56. data/spec/lib/flapjack/data/event_spec.rb +78 -78
  57. data/spec/lib/flapjack/data/notification_rule_spec.rb +4 -2
  58. data/spec/lib/flapjack/gateways/jsonapi/check_methods_spec.rb +94 -11
  59. data/spec/lib/flapjack/gateways/jsonapi/entity_methods_spec.rb +84 -0
  60. data/spec/lib/flapjack/gateways/pagerduty_spec.rb +5 -3
  61. data/spec/lib/flapjack/gateways/web_spec.rb +3 -3
  62. data/spec/service_consumers/pact_helper.rb +74 -0
  63. data/spec/service_consumers/pacts/flapjack-diner_v1.0.json +4522 -0
  64. data/spec/service_consumers/provider_states_for_flapjack-diner.rb +356 -0
  65. data/spec/spec_helper.rb +0 -8
  66. data/spec/support/jsonapi_helper.rb +1 -1
  67. data/tasks/benchmarks.rake +6 -3
  68. data/tasks/profile.rake +1 -1
  69. data/tmp/acknowledge.rb +0 -3
  70. data/tmp/create_event_ok.rb +0 -3
  71. data/tmp/create_event_unknown.rb +0 -3
  72. data/tmp/create_events_failure.rb +0 -3
  73. data/tmp/create_events_ok.rb +0 -3
  74. data/tmp/create_events_ok_fail_ack_ok.rb +0 -3
  75. data/tmp/create_events_ok_failure.rb +2 -5
  76. data/tmp/create_events_ok_failure_ack.rb +0 -3
  77. data/tmp/test_json_post.rb +4 -3
  78. data/tmp/test_notification_rules_api.rb +2 -3
  79. metadata +13 -8
  80. data/lib/flapjack/data/tag.rb +0 -61
  81. data/lib/flapjack/data/tag_set.rb +0 -16
  82. data/spec/lib/flapjack/data/tag_spec.rb +0 -36
@@ -167,7 +167,7 @@ module Flapjack
167
167
  check_stats
168
168
  @adjective = ''
169
169
 
170
- checks_by_entity = Flapjack::Data::EntityCheck.find_current_by_entity(:redis => redis)
170
+ checks_by_entity = Flapjack::Data::EntityCheck.find_current_names_by_entity(:redis => redis)
171
171
  @states = checks_by_entity.keys.inject({}) {|result, entity_name|
172
172
  Flapjack::Data::Entity.find_by_name(entity_name, :redis => redis, :create => true)
173
173
  result[entity_name] = checks_by_entity[entity_name].sort.map {|check|
@@ -184,7 +184,7 @@ module Flapjack
184
184
  check_stats
185
185
  @adjective = 'failing'
186
186
 
187
- checks_by_entity = Flapjack::Data::EntityCheck.find_current_failing_by_entity(:redis => redis)
187
+ checks_by_entity = Flapjack::Data::EntityCheck.find_current_names_failing_by_entity(:redis => redis)
188
188
  @states = checks_by_entity.keys.inject({}) {|result, entity|
189
189
  result[entity] = checks_by_entity[entity].sort.map {|check|
190
190
  [check] + entity_check_state(entity, check)
@@ -211,7 +211,7 @@ module Flapjack
211
211
  self_stats
212
212
  entity_stats
213
213
  check_stats
214
- {
214
+ json_data = {
215
215
  'events_queued' => @events_queued,
216
216
  'all_entities' => @count_current_entities,
217
217
  'failing_entities' => @count_failing_entities,
@@ -231,7 +231,8 @@ module Flapjack
231
231
  'boottime' => @boot_time,
232
232
  'current_time' => Time.now,
233
233
  'executive_instances' => @executive_instances,
234
- }.to_json
234
+ }
235
+ Flapjack.dump_json(json_data)
235
236
  end
236
237
 
237
238
  get '/entities_all' do
@@ -258,7 +259,7 @@ module Flapjack
258
259
  get '/entities_failing' do
259
260
  entity_stats
260
261
  @adjective = 'failing'
261
- @entities = Flapjack::Data::Entity.find_all_with_failing_checks(:redis => redis)
262
+ @entities = Flapjack::Data::Entity.find_all_names_with_failing_checks(:redis => redis)
262
263
 
263
264
  erb 'entities.html'.to_sym
264
265
  end
@@ -266,7 +267,7 @@ module Flapjack
266
267
  get '/entity/:entity' do
267
268
  @entity = params[:entity]
268
269
  entity_stats
269
- @states = Flapjack::Data::EntityCheck.find_current_for_entity_name(@entity, :redis => redis).sort.map { |check|
270
+ @states = Flapjack::Data::EntityCheck.find_current_names_for_entity_name(@entity, :redis => redis).sort.map { |check|
270
271
  [check] + entity_check_state(@entity, check)
271
272
  }.sort_by {|parts| parts }
272
273
 
@@ -488,7 +489,7 @@ module Flapjack
488
489
 
489
490
  def entity_stats(entities = nil)
490
491
  @count_current_entities = (entities || Flapjack::Data::Entity.all(:enabled => true, :redis => redis)).length
491
- @count_failing_entities = Flapjack::Data::Entity.find_all_with_failing_checks(:redis => redis).length
492
+ @count_failing_entities = Flapjack::Data::Entity.find_all_names_with_failing_checks(:redis => redis).length
492
493
  end
493
494
 
494
495
  def check_stats
@@ -4,8 +4,6 @@ require 'active_support/time'
4
4
 
5
5
  require 'em-hiredis'
6
6
 
7
- require 'oj'
8
-
9
7
  require 'flapjack/data/contact'
10
8
  require 'flapjack/data/entity_check'
11
9
  require 'flapjack/data/notification'
@@ -79,7 +77,7 @@ module Flapjack
79
77
  redis_uri = @redis_config[:path] ||
80
78
  "redis://#{@redis_config[:host] || '127.0.0.1'}:#{@redis_config[:port] || '6379'}/#{@redis_config[:db] || '0'}"
81
79
  shutdown_redis = EM::Hiredis.connect(redis_uri)
82
- shutdown_redis.rpush(@notifications_queue, Oj.dump('type' => 'shutdown'))
80
+ shutdown_redis.rpush(@notifications_queue, Flapjack.dump_json('type' => 'shutdown'))
83
81
  end
84
82
 
85
83
  private
@@ -171,7 +169,7 @@ module Flapjack
171
169
  when :sns
172
170
  Resque.enqueue_to(@queues['sns'], Flapjack::Gateways::AwsSns, contents)
173
171
  else
174
- @redis.rpush(@queues[media_type.to_s], Oj.dump(contents))
172
+ @redis.rpush(@queues[media_type.to_s], Flapjack.dump_json(contents))
175
173
  end
176
174
  end
177
175
  end
@@ -129,7 +129,7 @@ module Flapjack
129
129
  redis_uri = @redis_config[:path] ||
130
130
  "redis://#{@redis_config[:host] || '127.0.0.1'}:#{@redis_config[:port] || '6379'}/#{@redis_config[:db] || '0'}"
131
131
  shutdown_redis = EM::Hiredis.connect(redis_uri)
132
- shutdown_redis.rpush('events', Oj.dump('type' => 'noop'))
132
+ shutdown_redis.rpush('events', Flapjack.dump_json('type' => 'noop'))
133
133
  end
134
134
  end
135
135
 
@@ -151,7 +151,7 @@ module Flapjack
151
151
  entity_check = Flapjack::Data::EntityCheck.for_event_id(event.id, :create_entity => true, :redis => @redis)
152
152
  timestamp = Time.now.to_i
153
153
 
154
- event.tags = (event.tags || Flapjack::Data::TagSet.new) + entity_check.tags
154
+ event.tags = (event.tags || Set.new) + entity_check.tags
155
155
 
156
156
  should_notify, previous_state = update_keys(event, entity_check, timestamp)
157
157
 
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  module Flapjack
4
- VERSION = "1.1.0"
4
+ VERSION = "1.2.0rc1"
5
5
  end
6
6
 
data/lib/flapjack.rb CHANGED
@@ -1,6 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'oj'
4
+
3
5
  module Flapjack
4
6
 
7
+ def self.load_json(data)
8
+ Oj.load(data, :mode => :strict, :symbol_keys => false)
9
+ end
10
+
11
+ def self.dump_json(data)
12
+ Oj.dump(data, :mode => :compat, :time_format => :ruby, :indent => 0)
13
+ end
14
+
5
15
  end
6
16
 
@@ -9,6 +9,8 @@ describe Flapjack::Coordinator do
9
9
 
10
10
  let(:logger) { double(Flapjack::Logger) }
11
11
 
12
+ let(:redis) { double(::Redis) }
13
+
12
14
  let!(:time) { Time.now }
13
15
 
14
16
  it "starts and stops a pikelet" do
@@ -19,6 +21,10 @@ describe Flapjack::Coordinator do
19
21
  expect(config).to receive(:for_redis).and_return({})
20
22
  expect(config).to receive(:all).twice.and_return(cfg)
21
23
 
24
+ expect(redis).to receive(:keys).with('entity_tag:*').and_return([])
25
+ expect(redis).to receive(:keys).with('check_tag:*').and_return([])
26
+ expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
27
+
22
28
  processor = double('processor')
23
29
  expect(processor).to receive(:start)
24
30
  expect(processor).to receive(:stop)
@@ -52,6 +58,10 @@ describe Flapjack::Coordinator do
52
58
  expect(config).to receive(:for_redis).and_return({})
53
59
  expect(config).to receive(:all).twice.and_return(cfg)
54
60
 
61
+ expect(redis).to receive(:keys).with('entity_tag:*').and_return([])
62
+ expect(redis).to receive(:keys).with('check_tag:*').and_return([])
63
+ expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
64
+
55
65
  processor = double('processor')
56
66
  expect(processor).to receive(:start).and_raise(RuntimeError)
57
67
  expect(processor).to receive(:stop)
@@ -79,6 +89,10 @@ describe Flapjack::Coordinator do
79
89
  expect(config).to receive(:for_redis).and_return({})
80
90
  expect(config).to receive(:all).twice.and_return(cfg)
81
91
 
92
+ expect(redis).to receive(:keys).with('entity_tag:*').and_return([])
93
+ expect(redis).to receive(:keys).with('check_tag:*').and_return([])
94
+ expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
95
+
82
96
  processor = double('processor')
83
97
  expect(processor).to receive(:start)
84
98
  expect(processor).to receive(:stop)
@@ -121,6 +135,10 @@ describe Flapjack::Coordinator do
121
135
  expect(config).to receive(:for_redis).and_return({})
122
136
  expect(config).to receive(:all).twice.and_return(cfg)
123
137
 
138
+ expect(redis).to receive(:keys).with('entity_tag:*').and_return([])
139
+ expect(redis).to receive(:keys).with('check_tag:*').and_return([])
140
+ expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
141
+
124
142
  processor = double('processor')
125
143
  expect(processor).to receive(:start)
126
144
  expect(processor).to receive(:stop)
@@ -1,11 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- require 'active_support/time_with_zone'
4
- require 'ice_cube'
5
3
  require 'flapjack/data/contact'
6
- require 'flapjack/data/entity_check'
7
- require 'flapjack/data/notification_rule'
8
- require 'flapjack/data/tag_set'
9
4
 
10
5
  describe Flapjack::Data::Contact, :redis => true do
11
6
 
@@ -24,7 +19,7 @@ describe Flapjack::Data::Contact, :redis => true do
24
19
 
25
20
  let(:general_notification_rule_data) {
26
21
  {:entities => [],
27
- :tags => Flapjack::Data::TagSet.new([]),
22
+ :tags => Set.new([]),
28
23
  :time_restrictions => [],
29
24
  :unknown_media => [],
30
25
  :warning_media => ['email', 'sms', 'sms_twilio', 'jabber', 'pagerduty', 'sns'],
@@ -193,9 +188,8 @@ describe Flapjack::Data::Contact, :redis => true do
193
188
  expect(rules.select {|r| r.is_specific? }.size).to eq(1)
194
189
  end
195
190
 
196
- it "deletes a contact by id, including linked entities, checks, tags and notification rules" do
191
+ it "deletes a contact by id, including linked entities, checks and notification rules" do
197
192
  contact = Flapjack::Data::Contact.find_by_id('c362', :redis => @redis)
198
- contact.add_tags('admin')
199
193
 
200
194
  entity_name = 'abc-123'
201
195
 
@@ -206,10 +200,8 @@ describe Flapjack::Data::Contact, :redis => true do
206
200
 
207
201
  expect {
208
202
  expect {
209
- expect {
210
- contact.delete!
211
- }.to change { Flapjack::Data::Contact.all(:redis => @redis).size }.by(-1)
212
- }.to change { @redis.smembers('contact_tag:admin').size }.by(-1)
203
+ contact.delete!
204
+ }.to change { Flapjack::Data::Contact.all(:redis => @redis).size }.by(-1)
213
205
  }.to change { entity.contacts.size }.by(-1)
214
206
  end
215
207
 
@@ -1,8 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- require 'flapjack/data/entity'
4
3
  require 'flapjack/data/entity_check'
5
- require 'flapjack/data/tag_set'
6
4
 
7
5
  describe Flapjack::Data::EntityCheck, :redis => true do
8
6
 
@@ -88,6 +86,61 @@ describe Flapjack::Data::EntityCheck, :redis => true do
88
86
  }.to raise_error
89
87
  end
90
88
 
89
+ it 'registers with current_checks and current_entities if explicitly added' do
90
+ expect(@redis.zrange("current_checks:#{name}", 0, -1)).to eq([])
91
+ expect(@redis.zrange("current_entities", 0, -1)).to eq([])
92
+
93
+ check_data = {'entity_id' => '5000',
94
+ 'name' => 'ssh'}
95
+
96
+ Flapjack::Data::EntityCheck.add(check_data, :redis => @redis)
97
+
98
+ expect(@redis.zrange("current_checks:#{name}", 0, -1)).to eq(["ssh"])
99
+ expect(@redis.zrange("current_entities", 0, -1)).to eq([name])
100
+ end
101
+
102
+ it 'creates tags if passed when explicitly added' do
103
+ check_data = {'entity_id' => '5000',
104
+ 'name' => 'ssh',
105
+ 'tags' => ['virtual', 'staging']}
106
+
107
+ Flapjack::Data::EntityCheck.add(check_data, :redis => @redis)
108
+
109
+ entity_check = Flapjack::Data::EntityCheck.for_event_id("#{name}:ssh", :redis => @redis)
110
+ expect(entity_check).not_to be_nil
111
+ expect(entity_check.tags).to eq(Set.new(['abc-123', 'ssh', 'virtual', 'staging']))
112
+ end
113
+
114
+ it "adds tags to checks" do
115
+ entity_check = Flapjack::Data::EntityCheck.for_entity_name(name, 'ping', :redis => @redis)
116
+
117
+ entity_check.add_tags('source:foobar', 'foo')
118
+
119
+ expect(entity_check.tags).to include("source:foobar")
120
+ expect(entity_check.tags).to include("foo")
121
+
122
+ # and test the tags as read back from redis
123
+ entity_check = Flapjack::Data::EntityCheck.for_event_id("#{name}:ping", :redis => @redis)
124
+ expect(entity_check.tags).to include("source:foobar")
125
+ expect(entity_check.tags).to include("foo")
126
+ end
127
+
128
+ it "deletes tags from checks" do
129
+ entity_check = Flapjack::Data::EntityCheck.for_entity_name(name, 'ping', :redis => @redis)
130
+
131
+ entity_check.add_tags('source:foobar', 'foo')
132
+
133
+ expect(entity_check.tags).to include("source:foobar")
134
+ expect(entity_check.tags).to include("foo")
135
+
136
+ entity_check.delete_tags('source:foobar')
137
+
138
+ # and test the tags as read back from redis
139
+ entity_check = Flapjack::Data::EntityCheck.for_event_id("#{name}:ping", :redis => @redis)
140
+ expect(entity_check.tags).not_to include("source:foobar")
141
+ expect(entity_check.tags).to include("foo")
142
+ end
143
+
91
144
  context "maintenance" do
92
145
 
93
146
  it "returns that it is in unscheduled maintenance" do
@@ -1349,7 +1402,7 @@ describe Flapjack::Data::EntityCheck, :redis => true do
1349
1402
  ec = Flapjack::Data::EntityCheck.for_entity_name('foo-app-01.example.com', 'Disk / Utilisation', :create_entity => true, :redis => @redis)
1350
1403
  tags = ec.tags
1351
1404
  expect(tags).not_to be_nil
1352
- expect(tags).to be_a(Flapjack::Data::TagSet)
1405
+ expect(tags).to be_a(Set)
1353
1406
  expect(['foo-app-01', 'example.com', 'disk', '/', 'utilisation'].to_set.subset?(tags)).to be true
1354
1407
  end
1355
1408
 
@@ -14,6 +14,17 @@ describe Flapjack::Data::Entity, :redis => true do
14
14
  expect(@redis.get("entity_id:#{name}")).to match(/^\S+$/)
15
15
  end
16
16
 
17
+ it 'creates tags if passed when added' do
18
+ Flapjack::Data::Entity.add({'id' => '5000',
19
+ 'name' => name,
20
+ 'tags' => ['database', 'virtual']},
21
+ :redis => @redis)
22
+
23
+ entity = Flapjack::Data::Entity.find_by_id('5000', :redis => @redis)
24
+ expect(entity).not_to be_nil
25
+ expect(entity.tags).to eq(Set.new(['database', 'virtual']))
26
+ end
27
+
17
28
  it "adds a registered contact with an entity" do
18
29
  Flapjack::Data::Contact.add({'id' => '362',
19
30
  'first_name' => 'John',
@@ -182,73 +193,74 @@ describe Flapjack::Data::Entity, :redis => true do
182
193
 
183
194
  end
184
195
 
185
- it "finds entities by tag" do
186
- entity0 = Flapjack::Data::Entity.add({'id' => '5000',
187
- 'name' => 'abc-123',
188
- 'contacts' => []},
189
- :redis => @redis)
190
-
191
- entity1 = Flapjack::Data::Entity.add({'id' => '5001',
192
- 'name' => 'def-456',
193
- 'contacts' => []},
194
- :redis => @redis)
195
-
196
- entity0.add_tags('source:foobar', 'abc')
197
- entity1.add_tags('source:foobar', 'def')
198
-
199
- expect(entity0).not_to be_nil
200
- expect(entity0).to be_an(Flapjack::Data::Entity)
201
- expect(entity0.tags).to include("source:foobar")
202
- expect(entity0.tags).to include("abc")
203
- expect(entity0.tags).not_to include("def")
204
- expect(entity1).not_to be_nil
205
- expect(entity1).to be_an(Flapjack::Data::Entity)
206
- expect(entity1.tags).to include("source:foobar")
207
- expect(entity1.tags).to include("def")
208
- expect(entity1.tags).not_to include("abc")
209
-
210
- entities = Flapjack::Data::Entity.find_all_with_tags(['abc'], :redis => @redis)
211
- expect(entities).to be_an(Array)
212
- expect(entities.size).to eq(1)
213
- expect(entities.first).to eq('abc-123')
214
-
215
- entities = Flapjack::Data::Entity.find_all_with_tags(['donkey'], :redis => @redis)
216
- expect(entities).to be_an(Array)
217
- expect(entities).to be_empty
218
- end
219
-
220
- it "finds entities with several tags" do
221
- entity0 = Flapjack::Data::Entity.add({'id' => '5000',
222
- 'name' => 'abc-123',
223
- 'contacts' => []},
224
- :redis => @redis)
225
-
226
- entity1 = Flapjack::Data::Entity.add({'id' => '5001',
227
- 'name' => 'def-456',
228
- 'contacts' => []},
229
- :redis => @redis)
230
-
231
- entity0.add_tags('source:foobar', 'abc')
232
- entity1.add_tags('source:foobar', 'def')
233
-
234
- expect(entity0).not_to be_nil
235
- expect(entity0).to be_an(Flapjack::Data::Entity)
236
- expect(entity0.tags).to include("source:foobar")
237
- expect(entity0.tags).to include("abc")
238
- expect(entity1).not_to be_nil
239
- expect(entity1).to be_an(Flapjack::Data::Entity)
240
- expect(entity1.tags).to include("source:foobar")
241
- expect(entity1.tags).to include("def")
242
-
243
- entities = Flapjack::Data::Entity.find_all_with_tags(['source:foobar'], :redis => @redis)
244
- expect(entities).to be_an(Array)
245
- expect(entities.size).to eq(2)
246
-
247
- entities = Flapjack::Data::Entity.find_all_with_tags(['source:foobar', 'def'], :redis => @redis)
248
- expect(entities).to be_an(Array)
249
- expect(entities.size).to eq(1)
250
- expect(entities.first).to eq('def-456')
251
- end
196
+ # # Not used anywhere
197
+ # it "finds entities by tag" do
198
+ # entity0 = Flapjack::Data::Entity.add({'id' => '5000',
199
+ # 'name' => 'abc-123',
200
+ # 'contacts' => []},
201
+ # :redis => @redis)
202
+
203
+ # entity1 = Flapjack::Data::Entity.add({'id' => '5001',
204
+ # 'name' => 'def-456',
205
+ # 'contacts' => []},
206
+ # :redis => @redis)
207
+
208
+ # entity0.add_tags('source:foobar', 'abc')
209
+ # entity1.add_tags('source:foobar', 'def')
210
+
211
+ # expect(entity0).not_to be_nil
212
+ # expect(entity0).to be_an(Flapjack::Data::Entity)
213
+ # expect(entity0.tags).to include("source:foobar")
214
+ # expect(entity0.tags).to include("abc")
215
+ # expect(entity0.tags).not_to include("def")
216
+ # expect(entity1).not_to be_nil
217
+ # expect(entity1).to be_an(Flapjack::Data::Entity)
218
+ # expect(entity1.tags).to include("source:foobar")
219
+ # expect(entity1.tags).to include("def")
220
+ # expect(entity1.tags).not_to include("abc")
221
+
222
+ # entities = Flapjack::Data::Entity.find_all_with_tags(['abc'], :redis => @redis)
223
+ # expect(entities).to be_an(Array)
224
+ # expect(entities.size).to eq(1)
225
+ # expect(entities.first).to eq('abc-123')
226
+
227
+ # entities = Flapjack::Data::Entity.find_all_with_tags(['donkey'], :redis => @redis)
228
+ # expect(entities).to be_an(Array)
229
+ # expect(entities).to be_empty
230
+ # end
231
+
232
+ # it "finds entities with several tags" do
233
+ # entity0 = Flapjack::Data::Entity.add({'id' => '5000',
234
+ # 'name' => 'abc-123',
235
+ # 'contacts' => []},
236
+ # :redis => @redis)
237
+
238
+ # entity1 = Flapjack::Data::Entity.add({'id' => '5001',
239
+ # 'name' => 'def-456',
240
+ # 'contacts' => []},
241
+ # :redis => @redis)
242
+
243
+ # entity0.add_tags('source:foobar', 'abc')
244
+ # entity1.add_tags('source:foobar', 'def')
245
+
246
+ # expect(entity0).not_to be_nil
247
+ # expect(entity0).to be_an(Flapjack::Data::Entity)
248
+ # expect(entity0.tags).to include("source:foobar")
249
+ # expect(entity0.tags).to include("abc")
250
+ # expect(entity1).not_to be_nil
251
+ # expect(entity1).to be_an(Flapjack::Data::Entity)
252
+ # expect(entity1.tags).to include("source:foobar")
253
+ # expect(entity1.tags).to include("def")
254
+
255
+ # entities = Flapjack::Data::Entity.find_all_with_tags(['source:foobar'], :redis => @redis)
256
+ # expect(entities).to be_an(Array)
257
+ # expect(entities.size).to eq(2)
258
+
259
+ # entities = Flapjack::Data::Entity.find_all_with_tags(['source:foobar', 'def'], :redis => @redis)
260
+ # expect(entities).to be_an(Array)
261
+ # expect(entities.size).to eq(1)
262
+ # expect(entities.first).to eq('def-456')
263
+ # end
252
264
 
253
265
  context 'renaming and merging' do
254
266