Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit b0873cec3919e72f0c1bdd89f46ed2695621c57c Cloud Foundry Engineer committed Apr 12, 2011
Showing with 14,104 additions and 0 deletions.
  1. +13 −0 .gitignore
  2. +7,136 −0 LICENSE
  3. +10 −0 NOTICE
  4. +22 −0 README
  5. +1 −0 backup/manager/Gemfile
  6. +19 −0 backup/manager/README
  7. +39 −0 backup/manager/Rakefile
  8. +79 −0 backup/manager/bin/backup_manager
  9. +3 −0 backup/manager/config/backup_manager.yml
  10. +63 −0 backup/manager/lib/backup_manager/manager.rb
  11. +160 −0 backup/manager/lib/backup_manager/rotator.rb
  12. +41 −0 backup/manager/spec/Rakefile
  13. +158 −0 backup/manager/spec/backup_manager_spec.rb
  14. +74 −0 backup/manager/spec/spec_helper.rb
  15. +42 −0 backup/manager/spec/test_directories/complicated/populate.rb
  16. 0 backup/manager/spec/test_directories/empty/foo
  17. 0 backup/manager/spec/test_directories/invalid/foo/bar/baz/biz/buz/bim/bam/data.txt
  18. 0 ...manager/spec/test_directories/one_very_new/sampleservice/ab/cd/ef/abcdefghijk/1263978610/data.txt
  19. +1 −0 ...manager/spec/test_directories/one_very_old/sampleservice/ab/cd/ef/abcdefghijk/1134567890/data.txt
  20. +20 −0 base/Gemfile
  21. +106 −0 base/Gemfile.lock
  22. +39 −0 base/Rakefile
  23. +12 −0 base/TODO
  24. +11 −0 base/lib/base/abstract.rb
  25. +54 −0 base/lib/base/barrier.rb
  26. +51 −0 base/lib/base/base.rb
  27. +99 −0 base/lib/base/gateway.rb
  28. +113 −0 base/lib/base/node.rb
  29. +228 −0 base/lib/base/provisioner.rb
  30. +41 −0 base/spec/Rakefile
  31. +218 −0 base/spec/base_spec.rb
  32. +211 −0 base/spec/spec_helper.rb
  33. +315 −0 common/asynchronous_service_gateway.rb
  34. +139 −0 common/nuke_service.rb
  35. +27 −0 common/util.rb
  36. +3 −0 mongodb/.gitignore
  37. +23 −0 mongodb/Gemfile
  38. +126 −0 mongodb/Gemfile.lock
  39. +39 −0 mongodb/Rakefile
  40. +77 −0 mongodb/bin/mongodb_backup
  41. +28 −0 mongodb/bin/mongodb_gateway
  42. +97 −0 mongodb/bin/mongodb_node
  43. +8 −0 mongodb/config/mongodb_backup.yml
  44. +13 −0 mongodb/config/mongodb_gateway.yml
  45. +13 −0 mongodb/config/mongodb_node.yml
  46. +12 −0 mongodb/lib/mongodb_service/common.rb
  47. +372 −0 mongodb/lib/mongodb_service/mongodb_node.rb
  48. +14 −0 mongodb/lib/mongodb_service/mongodb_provisioner.rb
  49. +24 −0 mongodb/resources/mongodb.conf.erb
  50. +41 −0 mongodb/spec/Rakefile
  51. +155 −0 mongodb/spec/mongodb_gateway_spec.rb
  52. +138 −0 mongodb/spec/mongodb_node_bind_spec.rb
  53. +89 −0 mongodb/spec/mongodb_node_provision_spec.rb
  54. +118 −0 mongodb/spec/spec_helper.rb
  55. BIN mongodb/vendor/cache/addressable-2.2.4.gem
  56. BIN mongodb/vendor/cache/bcrypt-ruby-2.1.4.gem
  57. BIN mongodb/vendor/cache/bson-1.2.4.gem
  58. BIN mongodb/vendor/cache/bson_ext-1.2.4.gem
  59. BIN mongodb/vendor/cache/builder-3.0.0.gem
  60. BIN mongodb/vendor/cache/ci_reporter-1.6.4.gem
  61. BIN mongodb/vendor/cache/daemons-1.1.2.gem
  62. BIN mongodb/vendor/cache/data_objects-0.10.3.gem
  63. BIN mongodb/vendor/cache/datamapper-1.1.0.gem
  64. BIN mongodb/vendor/cache/diff-lcs-1.1.2.gem
  65. BIN mongodb/vendor/cache/dm-aggregates-1.1.0.gem
  66. BIN mongodb/vendor/cache/dm-constraints-1.1.0.gem
  67. BIN mongodb/vendor/cache/dm-core-1.1.0.gem
  68. BIN mongodb/vendor/cache/dm-do-adapter-1.1.0.gem
  69. BIN mongodb/vendor/cache/dm-migrations-1.1.0.gem
  70. BIN mongodb/vendor/cache/dm-serializer-1.1.0.gem
  71. BIN mongodb/vendor/cache/dm-sqlite-adapter-1.1.0.gem
  72. BIN mongodb/vendor/cache/dm-timestamps-1.1.0.gem
  73. BIN mongodb/vendor/cache/dm-transactions-1.1.0.gem
  74. BIN mongodb/vendor/cache/dm-types-1.1.0.gem
  75. BIN mongodb/vendor/cache/dm-validations-1.1.0.gem
  76. BIN mongodb/vendor/cache/do_sqlite3-0.10.3.gem
  77. BIN mongodb/vendor/cache/em-http-request-0.3.0.gem
  78. BIN mongodb/vendor/cache/escape_utils-0.2.3.gem
  79. BIN mongodb/vendor/cache/eventmachine-0.12.10.gem
  80. BIN mongodb/vendor/cache/fastercsv-1.5.4.gem
  81. BIN mongodb/vendor/cache/json-1.4.6.gem
  82. BIN mongodb/vendor/cache/json_pure-1.5.1.gem
  83. BIN mongodb/vendor/cache/mongo-1.2.4.gem
  84. BIN mongodb/vendor/cache/nats-0.4.8.gem
  85. BIN mongodb/vendor/cache/rack-1.2.2.gem
  86. BIN mongodb/vendor/cache/rake-0.8.7.gem
  87. BIN mongodb/vendor/cache/rcov-0.9.9.gem
  88. BIN mongodb/vendor/cache/rspec-2.5.0.gem
  89. BIN mongodb/vendor/cache/rspec-core-2.5.1.gem
  90. BIN mongodb/vendor/cache/rspec-expectations-2.5.0.gem
  91. BIN mongodb/vendor/cache/rspec-mocks-2.5.0.gem
  92. BIN mongodb/vendor/cache/ruby-hmac-0.4.0.gem
  93. BIN mongodb/vendor/cache/sinatra-1.2.1.gem
  94. BIN mongodb/vendor/cache/stringex-1.2.1.gem
  95. BIN mongodb/vendor/cache/thin-1.2.11.gem
  96. BIN mongodb/vendor/cache/tilt-1.2.2.gem
  97. BIN mongodb/vendor/cache/uuidtools-2.1.2.gem
  98. BIN mongodb/vendor/cache/yajl-ruby-0.8.2.gem
  99. +1 −0 mysql/.gitignore
  100. +24 −0 mysql/Gemfile
  101. +123 −0 mysql/Gemfile.lock
  102. +7 −0 mysql/README
  103. +39 −0 mysql/Rakefile
  104. +90 −0 mysql/bin/mysql_gateway
  105. +83 −0 mysql/bin/mysql_node
  106. +15 −0 mysql/config/mysql_gateway.yml
  107. +17 −0 mysql/config/mysql_node.yml
  108. +54 −0 mysql/lib/mysql_service/barrier.rb
  109. +245 −0 mysql/lib/mysql_service/node.rb
  110. +187 −0 mysql/lib/mysql_service/provisioner.rb
  111. +85 −0 mysql/lib/mysql_service/storage_quota.rb
  112. +50 −0 mysql/lib/mysql_service/util.rb
  113. +41 −0 mysql/spec/Rakefile
  114. +9 −0 mysql/spec/mysql_spec.rb
  115. +17 −0 mysql/spec/spec_helper.rb
  116. BIN mysql/vendor/cache/addressable-2.2.4.gem
  117. BIN mysql/vendor/cache/bcrypt-ruby-2.1.4.gem
  118. BIN mysql/vendor/cache/builder-3.0.0.gem
  119. BIN mysql/vendor/cache/ci_reporter-1.6.4.gem
  120. BIN mysql/vendor/cache/daemons-1.1.2.gem
  121. BIN mysql/vendor/cache/data_objects-0.10.3.gem
  122. BIN mysql/vendor/cache/datamapper-1.1.0.gem
  123. BIN mysql/vendor/cache/diff-lcs-1.1.2.gem
  124. BIN mysql/vendor/cache/dm-aggregates-1.1.0.gem
  125. BIN mysql/vendor/cache/dm-constraints-1.1.0.gem
  126. BIN mysql/vendor/cache/dm-core-1.1.0.gem
  127. BIN mysql/vendor/cache/dm-do-adapter-1.1.0.gem
  128. BIN mysql/vendor/cache/dm-migrations-1.1.0.gem
  129. BIN mysql/vendor/cache/dm-serializer-1.1.0.gem
  130. BIN mysql/vendor/cache/dm-sqlite-adapter-1.1.0.gem
  131. BIN mysql/vendor/cache/dm-timestamps-1.1.0.gem
  132. BIN mysql/vendor/cache/dm-transactions-1.1.0.gem
  133. BIN mysql/vendor/cache/dm-types-1.1.0.gem
  134. BIN mysql/vendor/cache/dm-validations-1.1.0.gem
  135. BIN mysql/vendor/cache/do_sqlite3-0.10.3.gem
  136. BIN mysql/vendor/cache/em-http-request-0.3.0.gem
  137. BIN mysql/vendor/cache/escape_utils-0.2.3.gem
  138. BIN mysql/vendor/cache/eventmachine-0.12.10.gem
  139. BIN mysql/vendor/cache/fastercsv-1.5.4.gem
  140. BIN mysql/vendor/cache/json-1.4.6.gem
  141. BIN mysql/vendor/cache/json_pure-1.5.1.gem
  142. BIN mysql/vendor/cache/mysql-2.8.1.gem
  143. BIN mysql/vendor/cache/nats-0.4.8.gem
  144. BIN mysql/vendor/cache/rack-1.2.2.gem
  145. BIN mysql/vendor/cache/rake-0.8.7.gem
  146. BIN mysql/vendor/cache/rcov-0.9.9.gem
  147. BIN mysql/vendor/cache/rspec-2.5.0.gem
  148. BIN mysql/vendor/cache/rspec-core-2.5.1.gem
  149. BIN mysql/vendor/cache/rspec-expectations-2.5.0.gem
  150. BIN mysql/vendor/cache/rspec-mocks-2.5.0.gem
  151. BIN mysql/vendor/cache/ruby-hmac-0.4.0.gem
  152. BIN mysql/vendor/cache/sinatra-1.2.1.gem
  153. BIN mysql/vendor/cache/stringex-1.2.1.gem
  154. BIN mysql/vendor/cache/thin-1.2.11.gem
  155. BIN mysql/vendor/cache/tilt-1.2.2.gem
  156. BIN mysql/vendor/cache/uuidtools-2.1.2.gem
  157. BIN mysql/vendor/cache/yajl-ruby-0.8.2.gem
  158. +24 −0 rabbit/Gemfile
  159. +124 −0 rabbit/Gemfile.lock
  160. +39 −0 rabbit/Rakefile
  161. +25 −0 rabbit/bin/rabbit_gateway
  162. +96 −0 rabbit/bin/rabbit_node
  163. +13 −0 rabbit/config/rabbit_gateway.yml
  164. +12 −0 rabbit/config/rabbit_node.yml
  165. +54 −0 rabbit/lib/rabbit_service/barrier.rb
  166. +12 −0 rabbit/lib/rabbit_service/common.rb
  167. +187 −0 rabbit/lib/rabbit_service/rabbit_node.rb
  168. +15 −0 rabbit/lib/rabbit_service/rabbit_provisioner.rb
  169. +42 −0 rabbit/spec/Rakefile
  170. +311 −0 rabbit/spec/node_spec.rb
  171. +21 −0 rabbit/spec/provisioner_spec.rb
  172. +13 −0 rabbit/spec/spec_helper.rb
  173. BIN rabbit/vendor/cache/addressable-2.2.4.gem
  174. BIN rabbit/vendor/cache/amqp-0.7.1.gem
  175. BIN rabbit/vendor/cache/bcrypt-ruby-2.1.4.gem
  176. BIN rabbit/vendor/cache/builder-3.0.0.gem
  177. BIN rabbit/vendor/cache/ci_reporter-1.6.4.gem
  178. BIN rabbit/vendor/cache/daemons-1.1.0.gem
  179. BIN rabbit/vendor/cache/data_objects-0.10.3.gem
  180. BIN rabbit/vendor/cache/datamapper-1.1.0.gem
  181. BIN rabbit/vendor/cache/diff-lcs-1.1.2.gem
  182. BIN rabbit/vendor/cache/dm-aggregates-1.1.0.gem
  183. BIN rabbit/vendor/cache/dm-constraints-1.1.0.gem
  184. BIN rabbit/vendor/cache/dm-core-1.1.0.gem
  185. BIN rabbit/vendor/cache/dm-do-adapter-1.1.0.gem
  186. BIN rabbit/vendor/cache/dm-migrations-1.1.0.gem
  187. BIN rabbit/vendor/cache/dm-serializer-1.1.0.gem
  188. BIN rabbit/vendor/cache/dm-sqlite-adapter-1.1.0.gem
  189. BIN rabbit/vendor/cache/dm-timestamps-1.1.0.gem
  190. BIN rabbit/vendor/cache/dm-transactions-1.1.0.gem
  191. BIN rabbit/vendor/cache/dm-types-1.1.0.gem
  192. BIN rabbit/vendor/cache/dm-validations-1.1.0.gem
  193. BIN rabbit/vendor/cache/do_sqlite3-0.10.3.gem
  194. BIN rabbit/vendor/cache/em-http-request-0.3.0.gem
  195. BIN rabbit/vendor/cache/escape_utils-0.2.3.gem
  196. BIN rabbit/vendor/cache/eventmachine-0.12.10.gem
  197. BIN rabbit/vendor/cache/fastercsv-1.5.4.gem
  198. BIN rabbit/vendor/cache/json-1.4.6.gem
  199. BIN rabbit/vendor/cache/json_pure-1.5.1.gem
  200. BIN rabbit/vendor/cache/nats-0.4.8.gem
  201. BIN rabbit/vendor/cache/rack-1.2.2.gem
  202. BIN rabbit/vendor/cache/rake-0.8.7.gem
  203. BIN rabbit/vendor/cache/rcov-0.9.9.gem
  204. BIN rabbit/vendor/cache/rspec-2.5.0.gem
  205. BIN rabbit/vendor/cache/rspec-core-2.5.1.gem
  206. BIN rabbit/vendor/cache/rspec-expectations-2.5.0.gem
  207. BIN rabbit/vendor/cache/rspec-mocks-2.5.0.gem
  208. BIN rabbit/vendor/cache/ruby-hmac-0.4.0.gem
  209. BIN rabbit/vendor/cache/sinatra-1.2.1.gem
  210. BIN rabbit/vendor/cache/stringex-1.2.1.gem
  211. BIN rabbit/vendor/cache/thin-1.2.8.gem
  212. BIN rabbit/vendor/cache/tilt-1.2.2.gem
  213. BIN rabbit/vendor/cache/uuidtools-2.1.2.gem
  214. BIN rabbit/vendor/cache/yajl-ruby-0.8.2.gem
  215. +3 −0 redis/.gitignore
  216. +21 −0 redis/Gemfile
  217. +120 −0 redis/Gemfile.lock
  218. +39 −0 redis/Rakefile
  219. +89 −0 redis/bin/redis_gateway
  220. +98 −0 redis/bin/redis_node
  221. +90 −0 redis/bin/redis_service
  222. +14 −0 redis/config/redis_gateway.yml
  223. +15 −0 redis/config/redis_node.yml
  224. +54 −0 redis/lib/redis_service/barrier.rb
  225. +263 −0 redis/lib/redis_service/redis_node.rb
  226. +186 −0 redis/lib/redis_service/redis_provisioner.rb
  227. +33 −0 redis/resources/redis.conf.erb
  228. +41 −0 redis/spec/Rakefile
  229. +9 −0 redis/spec/redis_spec.rb
  230. +17 −0 redis/spec/spec_helper.rb
  231. BIN redis/vendor/cache/addressable-2.2.4.gem
  232. BIN redis/vendor/cache/bcrypt-ruby-2.1.4.gem
  233. BIN redis/vendor/cache/builder-3.0.0.gem
  234. BIN redis/vendor/cache/ci_reporter-1.6.4.gem
  235. BIN redis/vendor/cache/daemons-1.1.2.gem
  236. BIN redis/vendor/cache/data_objects-0.10.3.gem
  237. BIN redis/vendor/cache/datamapper-1.1.0.gem
  238. BIN redis/vendor/cache/diff-lcs-1.1.2.gem
  239. BIN redis/vendor/cache/dm-aggregates-1.1.0.gem
  240. BIN redis/vendor/cache/dm-constraints-1.1.0.gem
  241. BIN redis/vendor/cache/dm-core-1.1.0.gem
  242. BIN redis/vendor/cache/dm-do-adapter-1.1.0.gem
  243. BIN redis/vendor/cache/dm-migrations-1.1.0.gem
  244. BIN redis/vendor/cache/dm-serializer-1.1.0.gem
  245. BIN redis/vendor/cache/dm-sqlite-adapter-1.1.0.gem
  246. BIN redis/vendor/cache/dm-timestamps-1.1.0.gem
  247. BIN redis/vendor/cache/dm-transactions-1.1.0.gem
  248. BIN redis/vendor/cache/dm-types-1.1.0.gem
  249. BIN redis/vendor/cache/dm-validations-1.1.0.gem
  250. BIN redis/vendor/cache/do_sqlite3-0.10.3.gem
  251. BIN redis/vendor/cache/em-http-request-0.3.0.gem
  252. BIN redis/vendor/cache/escape_utils-0.2.3.gem
  253. BIN redis/vendor/cache/eventmachine-0.12.10.gem
  254. BIN redis/vendor/cache/fastercsv-1.5.4.gem
  255. BIN redis/vendor/cache/json-1.4.6.gem
  256. BIN redis/vendor/cache/json_pure-1.5.1.gem
  257. BIN redis/vendor/cache/nats-0.4.8.gem
  258. BIN redis/vendor/cache/rack-1.2.2.gem
  259. BIN redis/vendor/cache/rake-0.8.7.gem
  260. BIN redis/vendor/cache/rcov-0.9.9.gem
  261. BIN redis/vendor/cache/rspec-2.5.0.gem
  262. BIN redis/vendor/cache/rspec-core-2.5.1.gem
  263. BIN redis/vendor/cache/rspec-expectations-2.5.0.gem
  264. BIN redis/vendor/cache/rspec-mocks-2.5.0.gem
  265. BIN redis/vendor/cache/ruby-hmac-0.4.0.gem
  266. BIN redis/vendor/cache/sinatra-1.2.1.gem
  267. BIN redis/vendor/cache/stringex-1.2.1.gem
  268. BIN redis/vendor/cache/thin-1.2.11.gem
  269. BIN redis/vendor/cache/tilt-1.2.2.gem
  270. BIN redis/vendor/cache/uuidtools-2.1.2.gem
  271. BIN redis/vendor/cache/yajl-ruby-0.8.2.gem
  272. +2 −0 redis/wipe_clean
@@ -0,0 +1,13 @@
+*~
+.idea
+\#*\#
+.\#*
+.bundle
+bundler
+spec_reports
+spec_coverage
+ci-artifacts-dir
+ci-working-dir
+*.rbc
+*.swp
+.rvmrc
7,136 LICENSE

Large diffs are not rendered by default.

Oops, something went wrong.
10 NOTICE
@@ -0,0 +1,10 @@
+Cloud Foundry 2011.04.12 beta
+Copyright (c) [2009-2011] VMware, Inc. All Rights Reserved.
+
+This product is licensed to you under the Apache License, Version 2.0 (the "License").
+You may not use this product except in compliance with the License.
+
+This product includes a number of subcomponents with
+separate copyright notices and license terms. Your use of these
+subcomponents is subject to the terms and conditions of the
+subcomponent's license, as noted in the LICENSE file.
22 README
@@ -0,0 +1,22 @@
+Copyright (c) 2009-2011 VMware, Inc.
+
+== What is Cloud Foundry?
+
+Cloud Foundry is an open platform-as-a-service (PaaS). The system supports
+multiple frameworks, multiple application infrastructure services and
+deployment to multiple clouds.
+
+== What is this component
+
+The services repo contains a collection of sample cloud foundry services.
+The repo has a position in the overall vcap namespace at
+vcap/services and uses the git submodule mechanism to be mounted in that location.
+The code is exposed via the vcap-services repo.
+
+== License
+
+Cloud Foundry uses the Apache 2 license. See LICENSE for details.
+
+== Installation Notes
+
+Complete installation notes are present in the README for vcap
@@ -0,0 +1 @@
+source "http://rubygems.org"
@@ -0,0 +1,19 @@
+The backup manager manages backups. Currently, its only job is
+rotation: it inspects the backup directory to prune old backups.
+
+The backup manager can be run in two modes:
+
+ - it can do its work once and then exit [the default]; or
+
+ - it can spawn a daemon process that periodically wakes up and does
+ its work
+
+The backup manager is configured by config/backup_manager.yaml.
+
+The main entry point is
+"core/services/backup/manager/bin/backup_manager". Here's how to run
+it:
+ Usage: backup_manager [options]
+ -c, --config [ARG] Configuration File
+ -d, --[no-]daemon Run as a daemon
+ -h, --help Help
@@ -0,0 +1,39 @@
+require 'rake'
+
+desc "Run specs"
+task "spec" => ["bundler:install:test", "test:spec"]
+
+desc "Run specs using RCov"
+task "spec:rcov" => ["bundler:install:test", "test:spec:rcov"]
+
+namespace "bundler" do
+ desc "Install gems"
+ task "install" do
+ sh("bundle install")
+ end
+
+ desc "Install gems for test"
+ task "install:test" do
+ sh("bundle install --without development production")
+ end
+
+ desc "Install gems for production"
+ task "install:production" do
+ sh("bundle install --without development test")
+ end
+
+ desc "Install gems for development"
+ task "install:development" do
+ sh("bundle install --without test production")
+ end
+end
+
+namespace "test" do
+ task "spec" do |t|
+ sh("cd spec && rake spec")
+ end
+
+ task "spec:rcov" do |t|
+ sh("cd spec && rake spec:rcov")
+ end
+end
@@ -0,0 +1,79 @@
+#!/usr/bin/env ruby
+# Copyright (c) 2009-2011 VMware, Inc.
+
+ENV["BUNDLE_GEMFILE"] ||= File.join(File.dirname(__FILE__), "..", "Gemfile")
+
+require "rubygems"
+require "bundler/setup"
+require "set"
+require "logger"
+
+daemon = false
+config_file = File.join(File.dirname(__FILE__), "..", "config", "backup_manager.yml")
+
+OptionParser.new do |opts|
+ opts.banner = "Usage: backup_manager [options]"
+ opts.on("-c", "--config [ARG]", "Configuration File") do |opt|
+ config_file = opt
+ end
+ opts.on("-d", "--[no-]daemon", "Run as a daemon") do |opt|
+ daemon = opt
+ end
+ opts.on("-h", "--help", "Help") do
+ puts opts
+ exit
+ end
+end.parse!
+
+begin
+ config = YAML.load_file(config_file)
+rescue => e
+ raise "Could not read configuration file: #{e}"
+end
+
+def parse_property(hash, key, type, options = {})
+ obj = hash[key]
+ if obj.nil?
+ raise "Missing required option: #{key}" unless options[:optional]
+ nil
+ elsif type == Range
+ raise "Invalid Range object: #{obj}" unless obj.kind_of?(Hash)
+ first, last = obj["first"], obj["last"]
+ raise "Invalid Range object: #{obj}" unless first.kind_of?(Integer) and last.kind_of?(Integer)
+ Range.new(first, last)
+ else
+ raise "Invalid #{type} object: #{obj}" unless obj.kind_of?(type)
+ obj
+ end
+end
+
+logger = Logger.new(parse_property(config, "log_file", String, :optional => true) || STDOUT, "daily")
+logger.level = case (parse_property(config, "log_level", String, :optional => true) || "INFO")
+ when "DEBUG" then Logger::DEBUG
+ when "INFO" then Logger::INFO
+ when "WARN" then Logger::WARN
+ when "ERROR" then Logger::ERROR
+ when "FATAL" then Logger::FATAL
+ else Logger::UNKNOWN
+end
+
+DEFAULT_ROTATION_MAX_DAYS = 7
+rotation = parse_property(config, "rotation", Hash, :optional => true) || Hash.new
+rotation = {
+ :max_days => rotation['max_days'] || DEFAULT_ROTATION_MAX_DAYS
+}
+
+DEFAULT_WAKEUP_INTERVAL = 60*60 # one hour
+
+options = {
+ :daemon => daemon,
+ :logger => logger,
+ :root => parse_property(config, "root", String),
+ :wakeup_interval => parse_property(config, "wakeup_interval", Integer, :optional => true) || DEFAULT_WAKEUP_INTERVAL,
+ :rotation => rotation
+}
+
+$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
+require 'backup_manager/manager'
+
+VCAP::Services::Backup::Manager.new(options).start
@@ -0,0 +1,3 @@
+---
+log_level: DEBUG
+root: /home/nick/projects/fork/core/services/backup/manager/spec/test_directories/complicated
@@ -0,0 +1,63 @@
+# Copyright (c) 2009-2011 VMware, Inc.
+module VCAP
+ module Services
+ module Backup
+ end
+ end
+end
+
+$LOAD_PATH.unshift File.dirname(__FILE__)
+require 'rotator'
+
+class VCAP::Services::Backup::Manager
+
+ def initialize(options)
+ @logger = options[:logger]
+ @daemon = options[:daemon]
+ @logger.info("#{self.class}: Initializing")
+ @wakeup_interval = options[:wakeup_interval]
+ @root = options[:root]
+ @tasks = [
+ VCAP::Services::Backup::Rotator.new(self, options[:rotation])
+ ]
+ end
+
+ attr_reader :root
+ attr_reader :logger
+
+ def start
+ @logger.info("#{self.class}: Starting")
+ if @daemon
+ pid = fork
+ if pid
+ @logger.info("#{self.class}: Forked process #{pid}")
+ Process.detach(pid)
+ else
+ @logger.info("#{self.class}: Daemon starting")
+ loop {
+ sleep @wakeup_interval
+ run
+ }
+ end
+ else
+ run
+ end
+ end
+
+ def run
+ @logger.info("#{self.class}: Running")
+ @tasks.each { |task|
+ unless task.run
+ @logger.warn("#{self.class}: #{task.class} failed")
+ end
+ }
+ rescue => x
+ # tasks should catch their own exceptions, but just in case...
+ @logger.error("#{self.class}: Exception while running: #{x.to_s}")
+ end
+
+ def time
+ Time.now.to_i
+ end
+
+end
Oops, something went wrong.

0 comments on commit b0873ce

Please sign in to comment.