ey_stonith 0.3.6 → 0.4.1.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/.gitignore +10 -0
  2. data/Gemfile +3 -0
  3. data/Rakefile +26 -0
  4. data/ey_stonith.gemspec +36 -0
  5. data/features/check.feature +57 -0
  6. data/features/cron.feature +67 -0
  7. data/features/fixtures/dead.ru +6 -0
  8. data/features/fixtures/healthy.ru +1 -0
  9. data/features/help.feature +7 -0
  10. data/features/not_found.feature +24 -0
  11. data/features/notify.feature +35 -0
  12. data/features/resume.feature +49 -0
  13. data/features/steps/stonith_steps.rb +40 -0
  14. data/features/stop.feature +48 -0
  15. data/features/support/env.rb +77 -0
  16. data/lib/ey_stonith/awsm_notifier.rb +13 -8
  17. data/lib/ey_stonith/commands/abstract.rb +0 -4
  18. data/lib/ey_stonith/commands/check.rb +13 -36
  19. data/lib/ey_stonith/commands/claim.rb +5 -96
  20. data/lib/ey_stonith/commands/cron.rb +3 -5
  21. data/lib/ey_stonith/commands/info.rb +1 -4
  22. data/lib/ey_stonith/commands/not_found.rb +1 -0
  23. data/lib/ey_stonith/commands/notify.rb +16 -55
  24. data/lib/ey_stonith/commands/reset.rb +0 -1
  25. data/lib/ey_stonith/commands/stop.rb +0 -1
  26. data/lib/ey_stonith/commands/takeover.rb +5 -90
  27. data/lib/ey_stonith/commands.rb +1 -1
  28. data/lib/ey_stonith/config.rb +17 -66
  29. data/lib/ey_stonith/rackapp.rb +26 -2
  30. data/lib/ey_stonith.rb +8 -15
  31. data/spec/config_spec.rb +53 -0
  32. data/spec/fixtures/config.yml +11 -0
  33. data/spec/fixtures/empty.yml +1 -0
  34. data/spec/helpers.rb +15 -0
  35. data/spec/history_spec.rb +58 -0
  36. data/spec/rackapp_spec.rb +100 -0
  37. data/spec/spec_helper.rb +24 -0
  38. metadata +240 -60
  39. data/lib/ey_stonith/address_stealer.rb +0 -40
  40. data/lib/ey_stonith/check_recorder.rb +0 -55
  41. data/lib/ey_stonith/data.rb +0 -11
  42. data/lib/ey_stonith/database.rb +0 -78
@@ -1,78 +0,0 @@
1
- require 'redis'
2
-
3
- module EY
4
- module Stonith
5
- class Database
6
- def initialize(config)
7
- @config = config
8
- end
9
-
10
- def with_locked_data
11
- raise "Already locked!" if @locked
12
- @locked = true
13
- data = locked_get
14
- yield data
15
- ensure
16
- set(data) if @locked
17
- end
18
-
19
- def with_data
20
- raise "Locked!" if @locked
21
- data = get
22
- yield data if data
23
- end
24
-
25
- def set(data)
26
- unless get # very small race condition (very)
27
- redis.lpush(master_key, Marshal.dump(data))
28
- @locked = false
29
- true
30
- end
31
- end
32
-
33
- def reset
34
- redis.ltrim master_key, 1, 0
35
- end
36
-
37
- private
38
-
39
- def get
40
- result = redis.lindex(master_key, 0) # index 0
41
- result && Marshal.load(result)
42
- end
43
-
44
- # popping & locking
45
- def locked_get
46
- Marshal.load redis.blpop(master_key, @config.redis_timeout).last
47
- end
48
-
49
- def master_key
50
- "#{@config.redis_key}:master"
51
- end
52
-
53
- def redis
54
- @redis ||= load_redis
55
- end
56
-
57
- def load_redis
58
- redis = Redis.new(:host => @config.redis_host, :port => @config.redis_port, :db => @config.redis_db, :timeout => @config.redis_timeout)
59
- check_redis_version redis.info['redis_version']
60
- redis
61
- rescue Errno::ECONNREFUSED
62
- abort "Unable to connect to redis"
63
- end
64
-
65
- def check_redis_version(version)
66
- major, minor, patch = version.split('.').map { |num| num.to_i }
67
- unless major > 1 ||
68
- (major == 1 && minor > 3) ||
69
- (major == 1 && minor == 3 && patch >= 1)
70
- abort <<-ERROR
71
- Redis server version [#{version}] is too old.
72
- >= 1.3.1 required for blpop support.
73
- ERROR
74
- end
75
- end
76
- end
77
- end
78
- end