Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 3ffc02af19bcf122a19ceeeca5e36c5b9df2f173 0 parents
Cloud Foundry Engineer authored
Showing with 18,024 additions and 0 deletions.
  1. +13 −0 .gitignore
  2. +9 −0 .gitmodules
  3. +1 −0  .rvmrc
  4. +32 −0 AUTHORS
  5. +7,136 −0 LICENSE
  6. +10 −0 NOTICE
  7. +253 −0 README
  8. +28 −0 Rakefile
  9. +48 −0 bin/cloud_controller
  10. +4 −0 bin/dea
  11. +4 −0 bin/health_manager
  12. +4 −0 bin/router
  13. +7 −0 bin/services/memcache_service
  14. +4 −0 bin/services/mongodb_gateway
  15. +3 −0  bin/services/mongodb_node
  16. +4 −0 bin/services/mysql_gateway
  17. +3 −0  bin/services/mysql_node
  18. +4 −0 bin/services/nuke_service
  19. +3 −0  bin/services/rabbit_gateway
  20. +4 −0 bin/services/rabbit_node
  21. +6 −0 bin/services/rabbit_service
  22. +4 −0 bin/services/redis_gateway
  23. +3 −0  bin/services/redis_node
  24. +548 −0 bin/vcap
  25. +7 −0 cloud_controller/.gitignore
  26. +1 −0  cloud_controller/.rspec
  27. +52 −0 cloud_controller/Gemfile
  28. +156 −0 cloud_controller/Gemfile.lock
  29. +256 −0 cloud_controller/README
  30. +13 −0 cloud_controller/Rakefile
  31. +17 −0 cloud_controller/TODO
  32. +140 −0 cloud_controller/app/controllers/application_controller.rb
  33. +350 −0 cloud_controller/app/controllers/apps_controller.rb
  34. +68 −0 cloud_controller/app/controllers/binding_tokens_controller.rb
  35. +57 −0 cloud_controller/app/controllers/default_controller.rb
  36. +81 −0 cloud_controller/app/controllers/legacy_services_controller.rb
  37. +11 −0 cloud_controller/app/controllers/resource_pool_controller.rb
  38. +216 −0 cloud_controller/app/controllers/services_controller.rb
  39. +14 −0 cloud_controller/app/controllers/user_tokens_controller.rb
  40. +61 −0 cloud_controller/app/controllers/users_controller.rb
  41. +25 −0 cloud_controller/app/helpers/services_helper.rb
  42. +43 −0 cloud_controller/app/models/account_capacity.rb
  43. +538 −0 cloud_controller/app/models/app.rb
  44. +8 −0 cloud_controller/app/models/app_collaboration.rb
  45. +579 −0 cloud_controller/app/models/app_manager.rb
  46. +130 −0 cloud_controller/app/models/app_package.rb
  47. +26 −0 cloud_controller/app/models/binding_token.rb
  48. +61 −0 cloud_controller/app/models/route.rb
  49. +121 −0 cloud_controller/app/models/service.rb
  50. +29 −0 cloud_controller/app/models/service_binding.rb
  51. +136 −0 cloud_controller/app/models/service_config.rb
  52. +109 −0 cloud_controller/app/models/user.rb
  53. +79 −0 cloud_controller/app/models/user_token.rb
  54. +27 −0 cloud_controller/app/subscriptions/health_manager_channel.rb
  55. +24 −0 cloud_controller/app/subscriptions/router_status.rb
  56. +4 −0 cloud_controller/config.ru
  57. +146 −0 cloud_controller/config/appconfig.rb
  58. +63 −0 cloud_controller/config/application.rb
  59. +97 −0 cloud_controller/config/boot.rb
  60. +78 −0 cloud_controller/config/cloud_controller.yml
  61. +18 −0 cloud_controller/config/environment.rb
  62. +34 −0 cloud_controller/config/environments/development.rb
  63. +32 −0 cloud_controller/config/environments/production.rb
  64. +37 −0 cloud_controller/config/environments/test.rb
  65. +9 −0 cloud_controller/config/final_stage/activate.rb
  66. +10 −0 cloud_controller/config/final_stage/check_database.rb
  67. +1 −0  cloud_controller/config/final_stage/check_staging.rb
  68. +2 −0  cloud_controller/config/final_stage/descriptor_table_size.rb
  69. +33 −0 cloud_controller/config/final_stage/event_log.rb
  70. +4 −0 cloud_controller/config/final_stage/log_boot_completion.rb
  71. +33 −0 cloud_controller/config/final_stage/message_bus.rb
  72. +37 −0 cloud_controller/config/final_stage/varz.rb
  73. +2 −0  cloud_controller/config/initializers/admins.rb
  74. +7 −0 cloud_controller/config/initializers/backtrace_silencers.rb
  75. +4 −0 cloud_controller/config/initializers/configure_capacity.rb
  76. +1 −0  cloud_controller/config/initializers/errors.rb
  77. +1 −0  cloud_controller/config/initializers/external_uri.rb
  78. +10 −0 cloud_controller/config/initializers/inflections.rb
  79. +5 −0 cloud_controller/config/initializers/reactor_warning.rb
  80. +6 −0 cloud_controller/config/initializers/resource_pool.rb
  81. +9 −0 cloud_controller/config/initializers/staging.rb
  82. +3 −0  cloud_controller/config/initializers/user_tokens.rb
  83. +5 −0 cloud_controller/config/locales/en.yml
  84. +58 −0 cloud_controller/config/routes.rb
  85. +15 −0 cloud_controller/db/migrate/20110126062250_create_users.rb
  86. +23 −0 cloud_controller/db/migrate/20110126062316_create_apps.rb
  87. +15 −0 cloud_controller/db/migrate/20110126062345_create_routes.rb
  88. +33 −0 cloud_controller/db/migrate/20110126062406_create_services.rb
  89. +26 −0 cloud_controller/db/migrate/20110126062425_create_service_configs.rb
  90. +31 −0 cloud_controller/db/migrate/20110126062436_create_service_bindings.rb
  91. +9 −0 cloud_controller/db/migrate/20110301225049_add_package_state_to_apps.rb
  92. +13 −0 cloud_controller/db/migrate/20110301225941_add_environment_to_apps.rb
  93. +15 −0 cloud_controller/db/migrate/20110301230838_add_association_indexes.rb
  94. +33 −0 cloud_controller/db/migrate/20110302110958_correct_app_columns.rb
  95. +11 −0 cloud_controller/db/migrate/20110302195209_add_staged_hash_to_apps.rb
  96. +9 −0 cloud_controller/db/migrate/20110302212336_add_name_to_service_config.rb
  97. +24 −0 cloud_controller/db/migrate/20110310010144_create_binding_tokens.rb
  98. +9 −0 cloud_controller/db/migrate/20110314085943_rename_staging_model_to_framework.rb
  99. +9 −0 cloud_controller/db/migrate/20110314090011_rename_staging_stack_to_runtime.rb
  100. +13 −0 cloud_controller/db/migrate/20110314222252_add_missing_app_quotas.rb
  101. +11 −0 cloud_controller/db/migrate/20110315234708_remove_uniqueness_constraint_on_routes.rb
  102. +9 −0 cloud_controller/db/migrate/20110316011344_add_lock_version_to_apps.rb
  103. +18 −0 cloud_controller/db/migrate/20110317203902_create_app_collaborations.rb
  104. +8 −0 cloud_controller/db/migrate/20110317224537_rename_user_id_to_owner_id_for_app.rb
  105. +11 −0 cloud_controller/db/migrate/20110325054423_add_plan_and_plan_option_to_service_config.rb
  106. +11 −0 cloud_controller/db/migrate/20110330070602_drop_unique_name_index_constraint_from_app.rb
  107. +9 −0 cloud_controller/db/migrate/20110331005646_add_index_on_app_id_and_service_config_id_for_service_binding.rb
  108. +9 −0 cloud_controller/db/migrate/20110404125844_add_run_count_to_apps.rb
  109. +141 −0 cloud_controller/db/schema.rb
  110. +63 −0 cloud_controller/lib/cloud_error.rb
  111. +17 −0 cloud_controller/lib/legacy_vmc_messages.rb
  112. +19 −0 cloud_controller/lib/nats_timed_request.rb
  113. +59 −0 cloud_controller/lib/resource_pool/filesystem_pool.rb
  114. +77 −0 cloud_controller/lib/resource_pool/resource_pool.rb
  115. +33 −0 cloud_controller/lib/rfc822.rb
  116. +148 −0 cloud_controller/lib/secure_user_manager.rb
  117. +13 −0 cloud_controller/lib/timed_section.rb
  118. 0  cloud_controller/log/.gitkeep
  119. +26 −0 cloud_controller/public/404.html
  120. +26 −0 cloud_controller/public/422.html
  121. +26 −0 cloud_controller/public/500.html
  122. 0  cloud_controller/public/favicon.ico
  123. +2 −0  cloud_controller/public/robots.txt
  124. +5 −0 cloud_controller/script/create_secure_users.rb
  125. +6 −0 cloud_controller/script/rails
  126. +103 −0 cloud_controller/script/service_lifecycle_tester.rb
  127. +123 −0 cloud_controller/spec/controllers/binding_tokens_controller_spec.rb
  128. +631 −0 cloud_controller/spec/controllers/services_controller_spec.rb
  129. +27 −0 cloud_controller/spec/fixtures/apps/rails3_gitgems/source/Gemfile
  130. +184 −0 cloud_controller/spec/fixtures/apps/rails3_gitgems/source/Gemfile.lock
  131. +7 −0 cloud_controller/spec/fixtures/apps/rails3_gitgems/source/Rakefile
  132. +2 −0  cloud_controller/spec/fixtures/apps/rails3_gitgems/source/app/controllers/application_controller.rb
  133. +5 −0 cloud_controller/spec/fixtures/apps/rails3_gitgems/source/app/controllers/welcome_controller.rb
  134. +2 −0  cloud_controller/spec/fixtures/apps/rails3_gitgems/source/app/helpers/application_helper.rb
  135. +14 −0 cloud_controller/spec/fixtures/apps/rails3_gitgems/source/app/views/layouts/application.html.erb
  136. +4 −0 cloud_controller/spec/fixtures/apps/rails3_gitgems/source/config.ru
  137. +10 −0 cloud_controller/spec/fixtures/apps/rails3_gitgems/source/config/application.rb
  138. +6 −0 cloud_controller/spec/fixtures/apps/rails3_gitgems/source/config/boot.rb
  139. +5 −0 cloud_controller/spec/fixtures/apps/rails3_gitgems/source/config/environment.rb
  140. +11 −0 cloud_controller/spec/fixtures/apps/rails3_gitgems/source/config/environments/development.rb
  141. +9 −0 cloud_controller/spec/fixtures/apps/rails3_gitgems/source/config/environments/production.rb
  142. +10 −0 cloud_controller/spec/fixtures/apps/rails3_gitgems/source/config/environments/test.rb
  143. +7 −0 cloud_controller/spec/fixtures/apps/rails3_gitgems/source/config/initializers/backtrace_silencers.rb
  144. +10 −0 cloud_controller/spec/fixtures/apps/rails3_gitgems/source/config/initializers/inflections.rb
  145. +5 −0 cloud_controller/spec/fixtures/apps/rails3_gitgems/source/config/initializers/mime_types.rb
  146. +7 −0 cloud_controller/spec/fixtures/apps/rails3_gitgems/source/config/initializers/secret_token.rb
  147. +8 −0 cloud_controller/spec/fixtures/apps/rails3_gitgems/source/config/initializers/session_store.rb
  148. +5 −0 cloud_controller/spec/fixtures/apps/rails3_gitgems/source/config/locales/en.yml
  149. +3 −0  cloud_controller/spec/fixtures/apps/rails3_gitgems/source/config/routes.rb
  150. 0  cloud_controller/spec/fixtures/apps/rails3_gitgems/source/public/favicon.ico
  151. +6 −0 cloud_controller/spec/fixtures/apps/rails3_gitgems/source/script/rails
  152. +4 −0 cloud_controller/spec/fixtures/apps/rails3_no_assets/source/Gemfile
  153. +78 −0 cloud_controller/spec/fixtures/apps/rails3_no_assets/source/Gemfile.lock
  154. +7 −0 cloud_controller/spec/fixtures/apps/rails3_no_assets/source/Rakefile
  155. +2 −0  cloud_controller/spec/fixtures/apps/rails3_no_assets/source/app/controllers/application_controller.rb
  156. +5 −0 cloud_controller/spec/fixtures/apps/rails3_no_assets/source/app/controllers/welcome_controller.rb
  157. +2 −0  cloud_controller/spec/fixtures/apps/rails3_no_assets/source/app/helpers/application_helper.rb
  158. +14 −0 cloud_controller/spec/fixtures/apps/rails3_no_assets/source/app/views/layouts/application.html.erb
  159. +4 −0 cloud_controller/spec/fixtures/apps/rails3_no_assets/source/config.ru
  160. +10 −0 cloud_controller/spec/fixtures/apps/rails3_no_assets/source/config/application.rb
  161. +6 −0 cloud_controller/spec/fixtures/apps/rails3_no_assets/source/config/boot.rb
  162. +5 −0 cloud_controller/spec/fixtures/apps/rails3_no_assets/source/config/environment.rb
  163. +11 −0 cloud_controller/spec/fixtures/apps/rails3_no_assets/source/config/environments/development.rb
  164. +10 −0 cloud_controller/spec/fixtures/apps/rails3_no_assets/source/config/environments/production.rb
  165. +10 −0 cloud_controller/spec/fixtures/apps/rails3_no_assets/source/config/environments/test.rb
  166. +7 −0 cloud_controller/spec/fixtures/apps/rails3_no_assets/source/config/initializers/backtrace_silencers.rb
  167. +10 −0 cloud_controller/spec/fixtures/apps/rails3_no_assets/source/config/initializers/inflections.rb
  168. +5 −0 cloud_controller/spec/fixtures/apps/rails3_no_assets/source/config/initializers/mime_types.rb
  169. +7 −0 cloud_controller/spec/fixtures/apps/rails3_no_assets/source/config/initializers/secret_token.rb
  170. +8 −0 cloud_controller/spec/fixtures/apps/rails3_no_assets/source/config/initializers/session_store.rb
  171. +5 −0 cloud_controller/spec/fixtures/apps/rails3_no_assets/source/config/locales/en.yml
  172. +3 −0  cloud_controller/spec/fixtures/apps/rails3_no_assets/source/config/routes.rb
  173. 0  cloud_controller/spec/fixtures/apps/rails3_no_assets/source/public/favicon.ico
  174. +6 −0 cloud_controller/spec/fixtures/apps/rails3_no_assets/source/script/rails
  175. +3 −0  cloud_controller/spec/fixtures/apps/rails3_nodb/source/Gemfile
  176. +71 −0 cloud_controller/spec/fixtures/apps/rails3_nodb/source/Gemfile.lock
  177. +7 −0 cloud_controller/spec/fixtures/apps/rails3_nodb/source/Rakefile
  178. +2 −0  cloud_controller/spec/fixtures/apps/rails3_nodb/source/app/controllers/application_controller.rb
  179. +5 −0 cloud_controller/spec/fixtures/apps/rails3_nodb/source/app/controllers/welcome_controller.rb
  180. +2 −0  cloud_controller/spec/fixtures/apps/rails3_nodb/source/app/helpers/application_helper.rb
  181. +14 −0 cloud_controller/spec/fixtures/apps/rails3_nodb/source/app/views/layouts/application.html.erb
  182. +4 −0 cloud_controller/spec/fixtures/apps/rails3_nodb/source/config.ru
  183. +10 −0 cloud_controller/spec/fixtures/apps/rails3_nodb/source/config/application.rb
  184. +6 −0 cloud_controller/spec/fixtures/apps/rails3_nodb/source/config/boot.rb
  185. +5 −0 cloud_controller/spec/fixtures/apps/rails3_nodb/source/config/environment.rb
  186. +11 −0 cloud_controller/spec/fixtures/apps/rails3_nodb/source/config/environments/development.rb
  187. +9 −0 cloud_controller/spec/fixtures/apps/rails3_nodb/source/config/environments/production.rb
  188. +10 −0 cloud_controller/spec/fixtures/apps/rails3_nodb/source/config/environments/test.rb
  189. +7 −0 cloud_controller/spec/fixtures/apps/rails3_nodb/source/config/initializers/backtrace_silencers.rb
  190. +10 −0 cloud_controller/spec/fixtures/apps/rails3_nodb/source/config/initializers/inflections.rb
  191. +5 −0 cloud_controller/spec/fixtures/apps/rails3_nodb/source/config/initializers/mime_types.rb
  192. +7 −0 cloud_controller/spec/fixtures/apps/rails3_nodb/source/config/initializers/secret_token.rb
  193. +8 −0 cloud_controller/spec/fixtures/apps/rails3_nodb/source/config/initializers/session_store.rb
  194. +5 −0 cloud_controller/spec/fixtures/apps/rails3_nodb/source/config/locales/en.yml
  195. +3 −0  cloud_controller/spec/fixtures/apps/rails3_nodb/source/config/routes.rb
  196. 0  cloud_controller/spec/fixtures/apps/rails3_nodb/source/public/favicon.ico
  197. +6 −0 cloud_controller/spec/fixtures/apps/rails3_nodb/source/script/rails
  198. +12 −0 cloud_controller/spec/fixtures/apps/sinatra_trivial/source/app.rb
  199. BIN  cloud_controller/spec/fixtures/apps/spring_guestbook/source.war
  200. +46 −0 cloud_controller/spec/models/app_spec.rb
  201. +13 −0 cloud_controller/spec/models/binding_token_spec.rb
  202. +16 −0 cloud_controller/spec/models/route_spec.rb
  203. +57 −0 cloud_controller/spec/models/service_binding_spec.rb
  204. +41 −0 cloud_controller/spec/models/service_config_spec.rb
  205. +152 −0 cloud_controller/spec/models/service_spec.rb
  206. +104 −0 cloud_controller/spec/models/user_spec.rb
  207. +64 −0 cloud_controller/spec/models/user_token_spec.rb
  208. +17 −0 cloud_controller/spec/requests/app_create_spec.rb
  209. +36 −0 cloud_controller/spec/requests/info_spec.rb
  210. +36 −0 cloud_controller/spec/requests/proxy_user_spec.rb
  211. +53 −0 cloud_controller/spec/requests/user_spec.rb
  212. +14 −0 cloud_controller/spec/requests/user_tokens_spec.rb
  213. +50 −0 cloud_controller/spec/spec_helper.rb
  214. +118 −0 cloud_controller/spec/staging/rails3_spec.rb
  215. +35 −0 cloud_controller/spec/staging/sinatra_spec.rb
  216. +85 −0 cloud_controller/spec/staging/spring_spec.rb
  217. +47 −0 cloud_controller/spec/support/cloud_spec_helpers.rb
  218. +33 −0 cloud_controller/spec/support/custom_matchers.rb
  219. +67 −0 cloud_controller/spec/support/staging_spec_helpers.rb
  220. +142 −0 cloud_controller/spec/support/synchronous_service_gateway.rb
  221. +7 −0 cloud_controller/staging/README
  222. +499 −0 cloud_controller/staging/common.rb
  223. +44 −0 cloud_controller/staging/gem_cache.rb
  224. +82 −0 cloud_controller/staging/gemfile_support.rb
  225. +280 −0 cloud_controller/staging/gemfile_task.rb
  226. +89 −0 cloud_controller/staging/grails/plugin.rb
  227. +7 −0 cloud_controller/staging/grails/stage
  228. BIN  cloud_controller/staging/java_common/resources/auto-reconfiguration-0.6.0-BUILD-SNAPSHOT.jar
  229. +16 −0 cloud_controller/staging/java_common/resources/autostaging_template_grails.xml
  230. +16 −0 cloud_controller/staging/java_common/resources/autostaging_template_spring.xml
  231. +2 −0  cloud_controller/staging/java_common/resources/droplet.yaml
  232. +60 −0 cloud_controller/staging/java_common/resources/generate_server_xml
  233. +15 −0 cloud_controller/staging/java_common/resources/set_environment
  234. BIN  cloud_controller/staging/java_common/resources/tomcat.zip
  235. +189 −0 cloud_controller/staging/java_common/tomcat.rb
  236. +20 −0 cloud_controller/staging/manifests/grails.yml
  237. +12 −0 cloud_controller/staging/manifests/node.yml
  238. +3 −0  cloud_controller/staging/manifests/platform.yml
  239. +33 −0 cloud_controller/staging/manifests/rails3.yml
  240. +35 −0 cloud_controller/staging/manifests/sinatra.yml
  241. +20 −0 cloud_controller/staging/manifests/spring.yml
  242. +50 −0 cloud_controller/staging/node/plugin.rb
  243. +5 −0 cloud_controller/staging/node/stage
  244. +73 −0 cloud_controller/staging/rails3/database_support.rb
  245. +90 −0 cloud_controller/staging/rails3/plugin.rb
  246. +8 −0 cloud_controller/staging/rails3/stage
  247. +62 −0 cloud_controller/staging/sinatra/plugin.rb
  248. +5 −0 cloud_controller/staging/sinatra/stage
  249. +70 −0 cloud_controller/staging/spring/plugin.rb
  250. +7 −0 cloud_controller/staging/spring/stage
  251. BIN  cloud_controller/vendor/cache/abstract-1.0.0.gem
  252. BIN  cloud_controller/vendor/cache/actionmailer-3.0.5.gem
  253. BIN  cloud_controller/vendor/cache/actionpack-3.0.5.gem
  254. BIN  cloud_controller/vendor/cache/activemodel-3.0.5.gem
  255. BIN  cloud_controller/vendor/cache/activerecord-3.0.5.gem
  256. BIN  cloud_controller/vendor/cache/activeresource-3.0.5.gem
  257. BIN  cloud_controller/vendor/cache/activesupport-3.0.5.gem
  258. BIN  cloud_controller/vendor/cache/addressable-2.2.4.gem
  259. BIN  cloud_controller/vendor/cache/arel-2.0.9.gem
  260. BIN  cloud_controller/vendor/cache/bcrypt-ruby-2.1.4.gem
  261. BIN  cloud_controller/vendor/cache/builder-2.1.2.gem
  262. BIN  cloud_controller/vendor/cache/ci_reporter-1.6.4.gem
  263. BIN  cloud_controller/vendor/cache/daemons-1.1.2.gem
  264. BIN  cloud_controller/vendor/cache/diff-lcs-1.1.2.gem
  265. BIN  cloud_controller/vendor/cache/em-http-request-1.0.0.beta.3.gem
  266. BIN  cloud_controller/vendor/cache/em-redis-0.3.0.gem
  267. BIN  cloud_controller/vendor/cache/em-socksify-0.1.0.gem
  268. BIN  cloud_controller/vendor/cache/erubis-2.6.6.gem
  269. BIN  cloud_controller/vendor/cache/eventmachine-0.12.10.gem
  270. BIN  cloud_controller/vendor/cache/http_parser.rb-0.5.1.gem
  271. BIN  cloud_controller/vendor/cache/i18n-0.5.0.gem
  272. BIN  cloud_controller/vendor/cache/json_pure-1.5.1.gem
  273. BIN  cloud_controller/vendor/cache/mail-2.2.15.gem
  274. BIN  cloud_controller/vendor/cache/mime-types-1.16.gem
  275. BIN  cloud_controller/vendor/cache/mocha-0.9.12.gem
  276. BIN  cloud_controller/vendor/cache/mysql2-0.2.7.gem
  277. BIN  cloud_controller/vendor/cache/nats-0.4.8.gem
  278. BIN  cloud_controller/vendor/cache/nokogiri-1.4.4.gem
  279. BIN  cloud_controller/vendor/cache/pg-0.10.1.gem
  280. BIN  cloud_controller/vendor/cache/polyglot-0.3.1.gem
  281. BIN  cloud_controller/vendor/cache/rack-1.2.2.gem
  282. BIN  cloud_controller/vendor/cache/rack-fiber_pool-0.9.1.gem
  283. BIN  cloud_controller/vendor/cache/rack-mount-0.6.14.gem
  284. BIN  cloud_controller/vendor/cache/rack-test-0.5.7.gem
  285. BIN  cloud_controller/vendor/cache/rails-3.0.5.gem
  286. BIN  cloud_controller/vendor/cache/railties-3.0.5.gem
  287. BIN  cloud_controller/vendor/cache/rake-0.8.7.gem
  288. BIN  cloud_controller/vendor/cache/rcov-0.9.9.gem
  289. BIN  cloud_controller/vendor/cache/rspec-2.5.0.gem
  290. BIN  cloud_controller/vendor/cache/rspec-core-2.5.1.gem
  291. BIN  cloud_controller/vendor/cache/rspec-expectations-2.5.0.gem
  292. BIN  cloud_controller/vendor/cache/rspec-mocks-2.5.0.gem
  293. BIN  cloud_controller/vendor/cache/rspec-rails-2.5.0.gem
  294. BIN  cloud_controller/vendor/cache/ruby-hmac-0.4.0.gem
  295. BIN  cloud_controller/vendor/cache/sinatra-1.2.1.gem
  296. BIN  cloud_controller/vendor/cache/sqlite3-1.3.3.gem
  297. BIN  cloud_controller/vendor/cache/thin-1.2.11.gem
  298. BIN  cloud_controller/vendor/cache/thor-0.14.6.gem
  299. BIN  cloud_controller/vendor/cache/tilt-1.2.2.gem
  300. BIN  cloud_controller/vendor/cache/treetop-1.4.9.gem
Sorry, we could not display the entire diff because too many files (420) changed.
13 .gitignore
@@ -0,0 +1,13 @@
+*~
+.idea
+\#*\#
+.\#*
+.bundle
+bundler
+spec_reports
+spec_coverage
+ci-artifacts-dir
+ci-working-dir
+*.rbc
+*.swp
+.rvmrc
9 .gitmodules
@@ -0,0 +1,9 @@
+[submodule "services"]
+ path = services
+ url = git@github.com:cloudfoundry/vcap-services.git
+[submodule "tests"]
+ path = tests
+ url = git@github.com:cloudfoundry/vcap-tests.git
+[submodule "java"]
+ path = java
+ url = git@github.com:cloudfoundry/vcap-java.git
1  .rvmrc
@@ -0,0 +1 @@
+rvm use 1.9.2
32 AUTHORS
@@ -0,0 +1,32 @@
+# Authors
+# =========
+#
+# This is a reasonably complete list of everyone who has committed
+# code to the Cloud Foundry project. The list is just ordered by first
+# name here, but the file is (and should be kept) YAML-formatted.
+#
+# Please feel free to add any personal details.
+
+---
+- Ananthan Srinivasan { email: asrinivasan@vmware.com, name: AB}
+- Christian Dupuis { email: cdupuis@vmware.com}
+- Derek Collison { email: dcollison@vmware.com }
+- Ezra Zygmuntowicz { email: ez@vmware.com }
+- Kent Skaar { email: skaar@vmware.com }
+- Killian Murphy { email: kmurphy@vmware.com}
+- Mahesh Patil { email: mpatil@vmware.com }
+- Mark Lucovsky { email: markl@vmware.com }
+- Matt Page { email: mpage@vmware.com}
+- Nicholas Kushmerick { email: nicholask@vmware.com}
+- Oleg Shaldybin { email: olegs@vmware.com}
+- Pat Bozeman { email: patb@vmware.com}
+- Peter Kukol { email: peterk@vmware.com }
+- Pieter Noordhuis { email: pcnoordhuis@gmail.com }
+- Ramnivas Laddad { email: rladdad@vmware.com }
+- Salvatore Sanfilippo { email: sanfilippo@vmware.com }
+- Scott Andrews { email: andrewss@vmware.com }
+- Shane Becker { email: sbecker@vmware.com }
+- Tal Garfinkel { email: talg@vmware.com }
+- Vadim Spivak { email: vspivak@vmware.com }
+- Wilson Bilkovich { email: wilsonb@vmware.com }
+- Woon Jung { email: whj@vmware.com }
7,136 LICENSE
7,136 additions, 0 deletions not shown
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.
253 README
@@ -0,0 +1,253 @@
+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.
+
+== License
+
+Cloud Foundry uses the Apache 2 license. See LICENSE for details.
+
+== Installation Notes
+
+Cloud Foundry is made up of a number of system components (cloud controller,
+health manager, dea, router, etc.). These components can run co-located in a
+single vm/single os or can be spread across several machines/vm's.
+
+For development purposes, the preferred environment is to run all of the core
+components within a single vm and then interact with the system from outside of
+the vm via an ssh tunnel. The pre-defined domain *.vcap.me maps to local host,
+so when you use this setup, the end result is that your development environment
+is available at http://api.vcap.me.
+
+For large scale or multi-vm deployments, the system is flexible enough to allow
+you to place system components on multiple vm's, run multiple nodes of a given
+type (e.g., 8 routers, 4 cloud controllers, etc.)
+
+The detailed install instructions below walk you through the install process
+for a single vm installation.
+
+Versions of these instructions have been used for production deployments, and
+for our own development purposes. many of us develop on mac laptops, so some
+additional instructions for this environment have been included.
+
+== Detailed Install/Run Instructions:
+
+
+- step #-1:
+ - setup a VM with a pristine Ubuntu 10.04.2 server 64bit image,
+ (http://www.ubuntu.com/business/get-ubuntu/download)
+ - you may wish to snapshot your VM now in case things go pear shaped.
+ - great snapshot spots are here and after step #4
+ - to enable remote access (more fun than using the console), install ssh.
+
+ sudo apt-get install openssh-server
+
+
+- step #0, install system and rvm dependencies
+ sudo apt-get install autoconf curl git-core ruby bison build-essential zlib1g-dev libssl-dev libreadline5-dev
+
+- step #1, install rvm
+ #for detailed rvm install instructions see: [https://rvm.beginrescueend.com/rvm/install/]
+ #or follow the quick steps below.
+
+ #grab rvm
+ #note, he -k switch is only needed if the certificate validation fails
+ bash < <(curl -s -k -B https://rvm.beginrescueend.com/install/rvm)
+
+ #follow the instructions given by the RVM installer (a copy is
+ #include below for your convenience).
+
+ # you must complete the install by loading RVM in new shells.
+ #
+ #
+ # 1) Place the folowing line at the end of your shell's loading files
+ # (.bashrc or .bash_profile for bash and .zshrc for zsh),
+ # after all PATH/variable settings:
+ #
+ # # This loads RVM into a shell session.
+ # [[ -s \"$rvm_path/scripts/rvm\" ]] && source \"$rvm_path/scripts/rvm\"
+ #
+ # You only need to add this line the first time you install rvm.
+ #
+ # 2) Ensure that there is no 'return' from inside the ~/.bashrc file,
+ # otherwise rvm may be prevented from working properly.
+ #
+ # This means that if you see something like:
+ #
+ # '[ -z \"\$PS1\" ] && return'
+ #
+ # then you change this line to:
+ #
+ # if [[ -n \"\$PS1\" ]] ; then
+ #
+ # # ... original content that was below the '&& return' line ...
+ #
+ # fi # <= be sure to close the if at the end of the .bashrc.
+ #
+ # # this is a good place to source rvm
+ # [[ -s \"$rvm_path/scripts/rvm\" ]] && source \"$rvm_path/scripts/rvm\"
+ #
+ # <EOF> - this marks the end of the .bashrc
+ #
+ # Be absolutely *sure* to REMOVE the '&& return'.
+ #
+ # If you wish to DRY up your config you can 'source ~/.bashrc' at the
+ # bottom of your .bash_profile.
+ #
+ # Placing all non-interactive (non login) items in the .bashrc,
+ # including the 'source' line above and any environment settings.
+ #
+ # 3) CLOSE THIS SHELL and open a new one in order to use rvm.
+
+
+- step #2, use rvm to install ruby 1.9.2 and make it default
+ rvm install 1.9.2-p180
+ rvm --default 1.9.2-p180
+
+- step #3, use rvm to install ruby 1.8.7
+ rvm install 1.8.7
+
+- step #4, clone the vcap and vmc repos:
+ mkdir ~/cloudfoundry; cd ~/cloudfoundry
+ # optionally create new ssh keys and add them to your github account: ssh-keygen -t rsa -C markl@vmware.com
+ # note, this release uses a handful of submodules. its important
+ # to understand the impact of this which is:
+ # 1) after clonding the vcap repo, you must run git submodule update --init
+ # this ends up mounting the services and tests repos in the directory tree of vcap
+ #
+ # 2) any time you git pull in vcap, you must also git submodule update
+ git clone git@github.com:cloudfoundry/vcap.git
+
+ # note, there should be a .rvmrc file in vcap/rvmrc
+ # make sure that the vcap/.rvmrc is present and that it contains
+ # rvm use 1.9.2
+ cd vcap
+ git submodule update --init
+ gem install vmc --no-rdoc --no-ri
+
+- step #5, run vcap_setup to prep cloudfoundry for launch
+ # Points to keep in mind.
+ # 1) Answer Y to all questions
+ # 2) Remember your mysql password, you will need it in a minute
+ cd ~/cloudfoundry/vcap
+ sudo setup/vcap_setup
+
+ # after vcap_setup completes, edit your mysql_node config file
+ # with the correct password created during install
+ cd ~/cloudfoundry/vcap/services/mysql/config
+ vi mysql_node.yml and change mysql.pass to your password
+
+- step #6, restart nginx with a custom config
+ cd cloudfoundry/vcap
+ sudo cp setup/simple.nginx.conf /etc/nginx/nginx.conf
+ sudo /etc/init.d/nginx restart
+
+- step #7, install bundler gem and run bundler:install
+ cd cloudfoundry/vcap
+ gem install bundler --no-rdoc --no-ri
+ rake bundler:install
+
+- step #8, start the system
+ cd cloudfoundry/vcap
+ bin/vcap start
+ bin/vcap tail # see aggregate logs
+
+
+- step #9 *Optional, mac users only*, create a local ssh tunnel
+ # from your vm, run ifconfig and note eth0, possiby 192.168.252.130
+ # go to your mac terminal window and create a local port 80 tunnel as
+ # once you do this, from both your mac, and from within the vm, api.vcap.me and *.vcap.me
+ # map to localhost which maps to your running cloudfoundry instance
+ sudo ssh -L 80:192.168.252.130:80 mhl@192.168.252.130 -N
+
+===Trying your setup
+
+- step #10, validate that you can connect and tests pass
+ # from the console of your vm, or from your mac (thanks to local tunnel)
+
+ #try
+ vmc target api.vcap.me
+ vmc info
+
+ #it should produce roughly the following...
+
+ VMware's Cloud Application Platform
+ For support visit support@cloudfoundry.com
+
+ Target: http://api.vcap.me (v0.999)
+ Client: v0.3.7
+
+
+ #play around as a user, start with
+ vmc register --email foo@bar.com --passwd password
+ vmc login --email foo@bar.com --passwd password
+
+ #to see what else you can do try
+ vmc help
+
+== Testing your setup
+
+#Once the system is installed, you can run the following command Basic System
+#Validation Tests (BVT) to ensure that major functionality is working.
+cd cloudfoundry/vcap
+cd tests && bundle package; bundle install && cd ..
+rake tests
+
+# unit tests can also be run using the following.
+cd cloudcontroller
+rake spec
+cd ../dea
+rake spec
+cd ../router
+rake spec
+cd ../health_manager
+rake spec
+
+-step #11, you are done, make sure you can run a simple hello world app.
+ #1) create an empty directory for your test app (lets call it env), and enter it.
+ cd env
+
+ #2) cut and paste the following app into a ruby file (lets say env.rb)
+ vi env.rb
+
+ ==== cut ===
+
+require 'rubygems'
+require 'sinatra'
+
+get '/' do
+ host = ENV['VMC_APP_HOST']
+ port = ENV['VMC_APP_PORT']
+ "<h1>XXXXX Hello from the Cloud! via: #{host}:#{port}</h1>"
+end
+
+get '/env' do
+ res = ''
+ ENV.each do |k, v|
+ res << "#{k}: #{v}<br/>"
+ end
+ res
+end
+
+ === cut ===
+
+ # run the following the create/push a 4 instance version of this app
+ # validate by running vmc apps, note the 4 instance running app
+ # then go to a browser and hit env.vcap.me/, note that hitting refresh
+ # will show a different port in each refresh reflecting the different
+ # active instances
+ vmc push env --instances 4 --mem 64M --url env.vcap.me -n
+
+ #running
+ vmc apps
+
+ #should give the following output.
+ #+-------------+----+---------+-------------+----------+
+ #| Application | # | Health | URLS | Services |
+ #+-------------+----+---------+-------------+----------+
+ #| env | 1 | RUNNING | env.vcap.me | |
+ #+-------------+----+---------+-------------+----------+
+
28 Rakefile
@@ -0,0 +1,28 @@
+# Bundler tasks are defined in rakelib/bundler.rake
+#
+desc "Run specs"
+task "spec" do |t|
+ CoreComponents.in_each_dir do
+ system "rake spec"
+ end
+end
+
+desc "Run specs using RCov"
+task "spec:rcov" do |t|
+ CoreComponents.in_each_dir do
+ system "rake spec:rcov"
+ end
+end
+
+desc "Run integration tests. (Requires a running cloud)"
+task "tests" do |t|
+ system "cd tests; rake tests"
+end
+
+namespace "db" do
+ desc "Create or update the configured CloudController database"
+ task "migrate" do
+ system "cd cloud_controller; rake db:create db:migrate"
+ end
+end
+task "migrate" => "db:migrate"
48 bin/cloud_controller
@@ -0,0 +1,48 @@
+#!/usr/bin/env ruby
+# Copyright (c) 2009-2011 VMware, Inc.
+
+require 'optparse'
+opts_parser = OptionParser.new do |opts|
+ opts.on('-p PORT') { |port| $cc_port = port.to_i }
+ opts.on('-c CONFIG_FILE') { |cfg| $cc_config_file = cfg.to_s }
+end
+opts_parser.parse!(ARGV.dup)
+
+if $cc_config_file
+ if File.exists?($cc_config_file)
+ ENV['CLOUD_CONTROLLER_CONFIG'] = $cc_config_file
+ else
+ $stderr.puts "Could not find specified config file at #{$cc_config_file.inspect}"
+ exit 1
+ end
+end
+
+cc_root = File.expand_path('../../cloud_controller', __FILE__)
+cc_boot = File.join(cc_root, 'config', 'boot')
+require cc_boot
+
+# Sets TCP/IP environment for sub-processes as well.
+if $cc_port && $cc_port.nonzero?
+ CloudController.instance_port = $cc_port
+end
+
+begin
+ pid_file = CloudController.pid
+ FileUtils.mkdir_p(File.dirname(pid_file)) # ensure pidfile directory exists
+ File.open(pid_file, 'wb') do |handle|
+ handle.print(Process.pid)
+ at_exit { File.unlink(pid_file) rescue nil }
+ end
+rescue
+ $stderr.puts "Unable to write to pidfile at: #{pid_file}"
+ exit 1
+end
+
+require 'thin'
+server = Thin::Server.new(CloudController.bind_address, CloudController.instance_port)
+cc_rack = File.join(cc_root, 'config.ru')
+server.app = Rack::Adapter.load(cc_rack)
+# The routers proxying to us handle killing inactive connections. Set an upper limit
+# just to be safe.
+server.timeout = 15 * 60 # 15 min
+server.start
4 bin/dea
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+# Copyright (c) 2009-2011 VMware, Inc.
+
+exec(File.expand_path("../../dea/bin/dea", __FILE__), *ARGV)
4 bin/health_manager
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+# Copyright (c) 2009-2011 VMware, Inc.
+
+exec(File.expand_path("../../health_manager/bin/health_manager", __FILE__), *ARGV)
4 bin/router
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+# Copyright (c) 2009-2011 VMware, Inc.
+
+exec(File.expand_path("../../router/bin/router", __FILE__), *ARGV)
7 bin/services/memcache_service
@@ -0,0 +1,7 @@
+#!/usr/bin/env ruby
+# Copyright (c) 2009-2011 VMware, Inc.
+
+ENV['BUNDLE_GEMFILE'] = File.dirname(__FILE__) + '/../../services/memcache/Gemfile'
+$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../services/memcache')
+
+require 'memcache_service'
4 bin/services/mongodb_gateway
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+# Copyright (c) 2009-2011 VMware, Inc.
+
+exec(File.expand_path("../../../services/mongodb/bin/mongodb_gateway", __FILE__), *ARGV)
3  bin/services/mongodb_node
@@ -0,0 +1,3 @@
+#!/usr/bin/env ruby
+
+exec(File.expand_path("../../../services/mongodb/bin/mongodb_node", __FILE__), *ARGV)
4 bin/services/mysql_gateway
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+# Copyright (c) 2009-2011 VMware, Inc.
+
+exec(File.expand_path("../../../services/mysql/bin/mysql_gateway", __FILE__), *ARGV)
3  bin/services/mysql_node
@@ -0,0 +1,3 @@
+#!/usr/bin/env ruby
+
+exec(File.expand_path("../../../services/mysql/bin/mysql_node", __FILE__), *ARGV)
4 bin/services/nuke_service
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+# Copyright (c) 2009-2011 VMware, Inc.
+
+exec(File.expand_path("../../../services/common/nuke_service.rb", __FILE__), *ARGV)
3  bin/services/rabbit_gateway
@@ -0,0 +1,3 @@
+#!/usr/bin/env ruby
+
+exec(File.expand_path("../../../services/rabbit/bin/rabbit_gateway", __FILE__), *ARGV)
4 bin/services/rabbit_node
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+# Copyright (c) 2009-2011 VMware, Inc.
+
+exec(File.expand_path("../../../services/rabbit/bin/rabbit_node", __FILE__), *ARGV)
6 bin/services/rabbit_service
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+
+ENV['BUNDLE_GEMFILE'] = File.dirname(__FILE__) + '/../../services/rabbit/Gemfile'
+$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../services/rabbit')
+
+require 'rabbit_service'
4 bin/services/redis_gateway
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+# Copyright (c) 2009-2011 VMware, Inc.
+
+exec(File.expand_path("../../../services/redis/bin/redis_gateway", __FILE__), *ARGV)
3  bin/services/redis_node
@@ -0,0 +1,3 @@
+#!/usr/bin/env ruby
+
+exec(File.expand_path("../../../services/redis/bin/redis_node", __FILE__), *ARGV)
548 bin/vcap
@@ -0,0 +1,548 @@
+#!/usr/bin/env ruby
+# Copyright (c) 2009-2011 VMware, Inc.
+#
+# Usage: bin/vcap_system [start|stop|restart|tail|status] [component ...]
+#
+# Omit component name to apply the operation to these components:
+#
+# core
+# - router
+# - cloud_controller
+# - health_manager
+# - dea
+#
+# services
+# - redis
+# - mysql
+# - mongo
+#
+
+require 'yaml'
+require 'fileutils'
+require 'optparse'
+
+require 'rubygems'
+require 'eventmachine'
+require 'nats/client'
+
+DIR = File.dirname(__FILE__)
+SERVICE_DIR = File.join(DIR, '/services')
+TMP = "/tmp/vcap-run"
+FileUtils.mkdir_p(TMP)
+
+class Component
+ attr :name
+ attr :path
+
+ def initialize(name, configuration_path = nil)
+ @name = name
+ @configuration_path = configuration_path
+
+ if core?
+ @path = File.join(DIR, name)
+ # Sane default for location of configuration file
+ @configuration_path ||= File.join(DIR, "..", name, "config", "#{name}.yml")
+ else
+ @path = File.join(SERVICE_DIR, name)
+ # Sane default for location of service configuration file
+ pre = name.sub(/_node|_gateway/,'')
+ @configuration_path ||= File.join(DIR, "../services", pre, "config", "#{name}.yml")
+ end
+ end
+
+ def is_cloud_controller?
+ @name =~ /cloud_controller/i
+ end
+
+ def is_router?
+ @name =~ /router/i
+ end
+
+ def to_s
+ name
+ end
+
+ def core?
+ Run.core.include? name
+ end
+
+ def service?
+ Run.services.include? name
+ end
+
+ def exists?
+ File.exists? @path
+ end
+
+ def configuration
+ @configuration ||= YAML.load(File.read(@configuration_path))
+ end
+
+ def pid_file
+ configuration["pid"] || raise("#{@configuration_path} does not specify location of pid file")
+ end
+
+ def log_file?
+ !configuration["log_file"].nil?
+ end
+
+ def log_file
+ log_file = configuration["log_file"]
+ log_file || File.join(TMP, "#{name}.log")
+ end
+
+ def pid
+ if File.exists?(pid_file)
+ body = File.read(pid_file)
+ body.to_i if body
+ end
+ end
+
+ def running?
+ running = false
+ # Only evaluate 'pid' once per call to 'running?'
+ if procid = pid
+ running = `ps -o rss= -p #{procid}`.length > 0
+ end
+ running
+ end
+
+ def component_start_path
+ exec_path = path.dup
+ if $configdir
+ config_file = File.join($configdir, "#{name}.yml")
+ if File.exists?(config_file)
+ exec_path << " -c #{config_file}"
+ end
+ end
+ if is_router? && $port
+ exec_path << " -p #{$port}"
+ end
+ exec_path
+ end
+
+ def start
+ if !running?
+
+ pid = fork do
+ # Capture STDOUT when no log file is configured
+ if !log_file?
+ stdout = File.open(log_file, 'w')
+ STDOUT.reopen(stdout)
+ stderr = File.open(log_file, 'a')
+ STDERR.reopen(stderr)
+ end
+ # Make sure db is setup, this is slow and we should make it faster, but
+ # should help for now.
+ if is_cloud_controller?
+ `cd ../cloud_controller; rake db:migrate`
+ end
+ exec("#{component_start_path}")
+ end
+
+ Process.detach(pid)
+
+ start = Time.now
+ while ((Time.now - start) < 10)
+ break if running?
+ sleep (0.25)
+ end
+ end
+
+ status
+
+ if !running?
+ if File.exists?(log_file)
+ log = File.read(log_file)
+ STDERR.puts "LOG:\n #{log}" if !log.empty?
+ end
+ end
+ end
+
+ def stop
+ return status unless running?
+
+ kill = "kill -TERM #{pid}"
+ `#{kill} 2> /dev/null`
+
+ if $? != 0
+ STDERR.puts "#{'Failed'.red} to stop #{name}, possible permission problem\?"
+ return
+ end
+
+ # Return status if we succeeded in stopping
+ return status unless running?
+
+ if running?
+ sleep(0.25)
+ if running?
+ kill = "kill -9 #{pid}"
+ `#{kill} 2> /dev/null`
+ end
+ end
+ status
+ end
+
+ def status
+ status = running? ? 'RUNNING'.green : 'STOPPED'.red
+ puts "#{name.ljust(20)}:\t #{status}"
+ end
+
+end
+
+# This is used to bring up and down the NATS messaging server.
+class NatsServer
+
+ attr_reader :was_running
+ alias :was_running? :was_running
+
+ class << self
+ def kill_autostart_server
+ pid ||= File.read(NATS::AUTOSTART_PID_FILE).chomp.to_i
+ %x[kill -9 #{pid}] if pid
+ %x[rm #{NATS::AUTOSTART_PID_FILE}]
+ %x[rm #{NATS::AUTOSTART_LOG_FILE}]
+ end
+ end
+
+ def initialize(uri=NATS::DEFAULT_URI, pid_file=NATS::AUTOSTART_PID_FILE)
+ @uri = URI.parse(uri)
+ @pid_file = pid_file
+ end
+
+ def server_pid
+ @pid ||= File.read(@pid_file).chomp.to_i
+ end
+
+ def start_server
+ if NATS.server_running? @uri
+ @was_running = true
+ return
+ end
+
+ nats_server = `which nats-server`
+ unless $? == 0 && nats_server
+ STDERR.puts "Could not locate a nats-server, exiting.".red
+ exit 1
+ end
+ nats_server.chomp!
+ `#{nats_server} -p #{@uri.port} -P #{@pid_file} -d 2> /dev/null`
+ NATS.wait_for_server(@uri, 5)
+ end
+
+ def is_running?
+ NATS.server_running? @uri
+ end
+
+ def kill_server
+ if File.exists? @pid_file
+ %x[kill -9 #{server_pid} 2> /dev/null]
+ %x[rm #{@pid_file} 2> /dev/null]
+ %x[rm #{NATS::AUTOSTART_LOG_FILE} 2> /dev/null]
+ end
+ end
+end
+
+module Run
+ def self.start_init
+ nats_server = NatsServer.new
+ nats_server.start_server
+ end
+
+ def self.start(args)
+ self.start_init
+ components(args).each(&:start)
+ end
+
+ def self.stop_cleanup
+ # Only process this if no one else running..
+ running_components = components([]).select {|c| c.running?}.map{|c| c.name }
+ return unless running_components.empty?
+ nats_server = NatsServer.new
+ return unless nats_server.is_running?
+ nats_server.kill_server
+ end
+
+ def self.stop(args)
+ components(args).each(&:stop)
+ self.stop_cleanup
+ end
+
+ def self.restart(args)
+ stop(args)
+ start(args)
+ end
+
+ def self.reset(args)
+ unless $noprompt
+ exit unless ask_to_continue "#{'CAUTION'.red}: All data will be lost. Continue?"
+ end
+
+ # Try not to shoot ourselves in the foot..
+ running_components = components([]).select {|c| c.running?}.map{|c| c.name }
+ unless running_components.empty?
+ puts "It looks like the following components are already running: #{running_components.join(', ')}"
+ puts "Resetting VCAP now may produce unintended results."
+ exit unless ask_to_continue
+ puts
+ end
+
+ cc_dir = File.expand_path(File.join(DIR, '..', 'cloud_controller'))
+ run_command("Resetting the CloudController database", "cd #{cc_dir} 2>&1 && rake db:drop 2>&1")
+ puts
+
+ cc_log_dir = File.join(cc_dir, 'log')
+ run_command("Clearing the CloudController logs", "cd #{cc_log_dir} 2>&1 && rm -f *.log 2>&1")
+ puts
+
+ # TODO - Need to connect to mysql and unprovision any orphaned DBs
+ kill_service_instances('redis', /redis-server/)
+ puts
+ kill_service_instances('mongodb', /mongod/)
+ puts
+
+ puts "Cleaning shared directories:"
+ dirs = %w[/var/vcap/services /var/vcap/shared /var/vcap/sys /var/vcap.local/* /tmp/vcap-run]
+ max_len = dirs.reduce(0) {|cur_max, dir| dir.length > cur_max ? dir.length : cur_max}
+ dirs.each do |dir|
+ run_command(" %-#{max_len}s" % [dir], "rm -rf #{dir}")
+ end
+ end
+
+ # Make tail exits fast and clean
+ def self.exit_tails
+ unless @tpids.empty?
+ kill = "kill -9 #{@tpids.join(' ')}"
+ `#{kill} 2> /dev/null`
+ end
+ exit!
+ end
+
+ def self.tail(args)
+ tail = 'tail'
+
+ # Annoying when CTRL-C takes forever
+ trap('TERM') { Run.exit_tails }
+ trap('INT') { Run.exit_tails }
+
+ if RUBY_PLATFORM =~ /linux/i
+ # tail in coreutils 7.5 uses inotify
+ tail_version = `tail --version | grep coreutils | head -n1`.slice(/\d+.\d+/)
+ if tail_version < '7.5'
+ path = `which inotail`
+ tail = path.strip if $?.success?
+ end
+ end
+
+ @tpids = []
+ EM.run do
+ components(args).map do |component|
+ next unless component.running?
+ args = [tail, '-f', component.log_file]
+ tpid = EM.get_subprocess_pid( EM.popen(args.join(' '), Tail, component).signature )
+ @tpids << tpid
+ end
+ if @tpids.empty?
+ puts 'No tailable components currently running.'
+ EM.stop
+ end
+ end
+ end
+
+ module Tail
+ include EM::Protocols::LineText2
+
+ def initialize(component)
+ @component = component
+ end
+
+ def prefix
+ "%s --> " % @component.name.rjust(15)
+ end
+
+ def receive_line(line)
+ puts prefix + line
+ if line.start_with?('F') # FATAL
+ puts prefix + "fatal error, closing tail"
+ close_connection_after_writing
+ end
+ end
+
+ end
+
+ def self.status(args)
+ components(args).each(&:status)
+ end
+
+ private
+
+ def self.core
+ %w(router cloud_controller dea health_manager)
+ end
+
+ def self.services
+ %w(redis mysql mongodb)
+ end
+
+ def self.alias_args(args)
+ aliased = []
+ args.each do |arg|
+ case arg
+ when 'all'
+ aliased.concat(Run.core + Run.services)
+ when 'core'
+ aliased.concat Run.core
+ when 'services'
+ aliased.concat Run.services
+ when 'mongo'
+ aliased << 'mongodb'
+ else
+ aliased << arg
+ end
+ end
+ aliased
+ end
+
+ def self.expand_args(args)
+ args = Run.alias_args(args)
+ new_args = []
+ args.each do |arg|
+ if Run.core.include? arg
+ new_args << arg
+ else # This is a service, expand in place here..
+ new_args << "#{arg}_gateway"
+ new_args << "#{arg}_node"
+ end
+ end
+ new_args
+ end
+
+ def self.components(args)
+ args = (Run.core + Run.services) if args.empty?
+ args = Run.expand_args(args)
+ components = args.map do |arg|
+ component = Component.new(arg)
+ component if component.exists?
+ end.compact
+ STDERR.puts "Don't know how to process '#{args.inspect}' \?\?" if components.empty?
+ components
+ end
+
+ def self.pad_left(str, padlen=2)
+ pad_str = " " * padlen
+ str.split("\n") \
+ .map {|line| pad_str + line } \
+ .join("\n")
+ end
+
+ def self.run_command(desc, command)
+ print desc
+ output = `#{command}`
+ if $? == 0
+ puts " Ok".green
+ else
+ puts " Failed".red
+ puts " '#{command}' exited with status '#{$?}', output:"
+ puts pad_left(output, 2)
+ end
+ [$?, output]
+ end
+
+ def self.ask_to_continue(prompt="Would you like to continue?")
+ should_continue = nil
+ while should_continue == nil
+ print prompt + " (y/N) "
+ choice = STDIN.gets.chomp
+ if choice.empty? || /^n/i.match(choice)
+ should_continue = false
+ elsif /^y/i.match(choice)
+ should_continue = true
+ end
+ end
+ should_continue
+ end
+
+ def self.find_processes(cmd_re)
+ output = `ps ax -o pid= -o command=`
+ ret = []
+ output.split("\n").each do |line|
+ pid, cmd = line.split(' ', 2)
+ ret << {:pid => pid, :command => cmd} if cmd_re.match(cmd)
+ end
+ ret
+ end
+
+ def self.kill_service_instances(name, cmd_re)
+ print "Checking for stray #{name} instances"
+ instances = find_processes(cmd_re)
+ puts " Ok".green
+
+ return if instances.empty?
+
+ puts "The following #{name} instances are running:"
+ puts " PID COMMAND"
+ instances.each do |instance|
+ puts " %-6d %s" % [instance[:pid], instance[:command]]
+ end
+
+ if ask_to_continue("Would you like to kill them?")
+ run_command("Killing instances", "kill -9 #{instances.map{|i| i[:pid]}.join(' ')}")
+ end
+ end
+
+end
+
+module VcapStringExtensions
+
+ def red
+ colorize("\e[0m\e[31m")
+ end
+
+ def green
+ colorize("\e[0m\e[32m")
+ end
+
+ def yellow
+ colorize("\e[0m\e[33m")
+ end
+
+ def bold
+ colorize("\e[0m\e[1m")
+ end
+
+ def colorize(color_code)
+ unless $nocolor
+ "#{color_code}#{self}\e[0m"
+ else
+ self
+ end
+ end
+end
+
+class String
+ include VcapStringExtensions
+end
+
+args = ARGV.dup
+opts_parser = OptionParser.new do |opts|
+ opts.on('--port PORT') { |port| $port = port.to_i }
+ opts.on('--configdir CONFIGDIR', '-c CONFIGDIR') { |dir| $configdir = File.expand_path(dir.to_s) }
+ opts.on('--config CONFIGDIR') { |dir| $configdir = File.expand_path(dir.to_s) }
+ opts.on('--no-color', '--nocolor', '--nc') { $nocolor = true }
+ opts.on('--noprompt', '-n') { $noprompt = true }
+
+end
+args = opts_parser.parse!(args)
+
+$nocolor = true unless STDOUT.tty?
+
+if args.empty?
+ STDERR.puts "Usage: #{$0} [start|stop|restart|tail|status] [COMPONENT] [--no-color] [--config CONFIGDIR]"
+else
+ command = args.shift.downcase
+ if Run.respond_to?(command)
+ Run.send(command, args)
+ else
+ STDERR.puts "Don't know what to do with #{command.inspect}"
+ end
+end
7 cloud_controller/.gitignore
@@ -0,0 +1,7 @@
+*.log
+tags
+db/*.sqlite3
+db/*.sqlite3-journal
+cloudcontroller.db
+cloud_controller.db
+
1  cloud_controller/.rspec
@@ -0,0 +1 @@
+--colour
52 cloud_controller/Gemfile
@@ -0,0 +1,52 @@
+source 'http://rubygems.org'
+
+# Rails itself
+gem 'rails', '~> 3.0.5'
+# Message bus
+gem 'nats', '>= 0.4.8', :require => 'nats/client'
+
+# VCAP common components
+gem 'vcap_common', :require => ['vcap/common', 'vcap/component'], :path => '../common'
+
+# Databases
+gem 'sqlite3'
+group :production do
+ gem 'pg'
+ # Get blocking postgres working for now, try nonblocking drivers when we have more time
+ # gem 'postgres-pr', '0.6.3'
+ # gem 'em_postgresql', '0.3.0'
+
+ gem 'mysql2', '>= 0.2.6', :require => nil
+ # mysql2 includes an EventMachine driver (mysql2/em), don't use em-mysqlplus.
+ # To enable, set the :database_env :adapter to 'em_mysql2' in config/cloud_controller.yml
+ #
+ # Requires a Ruby with Fibers (1.9, rbx, etc), thin (or similar EM-driven appserver), and
+ # rack-fiber_pool middleware. Additionally there is a patch applied via plugin if this
+ # adapter is selected.
+end
+
+# EventMachine and async support
+gem 'eventmachine', '~> 0.12.10'
+gem 'thin', '> 1.2'
+gem 'em-http-request', '~> 1.0.0.beta.3', :require => 'em-http'
+gem 'em-redis', :require => nil
+gem 'rack-fiber_pool', :require => nil
+
+# Support libraries
+gem 'yajl-ruby', '>= 0.7.9'
+gem 'nokogiri', '>= 1.4.4'
+gem 'bcrypt-ruby', '>= 2.1.4'
+gem 'ruby-hmac', :require => 'hmac-sha1'
+gem 'SystemTimer', :platforms => :mri_18
+gem 'uuidtools'
+
+# rspec-rails is outside the 'test' group in order to consistently provide Rake tasks.
+gem 'rspec-rails', '>= 2.4.1'
+group :test do
+ gem 'rspec', '>= 2.4.0', :require => nil
+ gem 'rcov'
+ gem 'mocha'
+ gem 'ci_reporter'
+ gem 'sinatra' # For service gateway shims
+end
+
156 cloud_controller/Gemfile.lock
@@ -0,0 +1,156 @@
+PATH
+ remote: ../common
+ specs:
+ vcap_common (0.99)
+ eventmachine (~> 0.12.10)
+ nats
+ thin
+ yajl-ruby
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ SystemTimer (1.2.3)
+ abstract (1.0.0)
+ actionmailer (3.0.5)
+ actionpack (= 3.0.5)
+ mail (~> 2.2.15)
+ actionpack (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.13)
+ rack-test (~> 0.5.7)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.5)
+ activesupport (= 3.0.5)
+ builder (~> 2.1.2)
+ i18n (~> 0.4)
+ activerecord (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ activesupport (3.0.5)
+ addressable (2.2.4)
+ arel (2.0.9)
+ bcrypt-ruby (2.1.4)
+ builder (2.1.2)
+ ci_reporter (1.6.4)
+ builder (>= 2.1.2)
+ daemons (1.1.2)
+ diff-lcs (1.1.2)
+ em-http-request (1.0.0.beta.3)
+ addressable (>= 2.2.3)
+ em-socksify
+ eventmachine
+ http_parser.rb (>= 0.5.1)
+ em-redis (0.3.0)
+ eventmachine
+ em-socksify (0.1.0)
+ eventmachine
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ eventmachine (0.12.10)
+ http_parser.rb (0.5.1)
+ i18n (0.5.0)
+ json_pure (1.5.1)
+ mail (2.2.15)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ mocha (0.9.12)
+ mysql2 (0.2.7)
+ nats (0.4.8)
+ daemons (>= 1.1.0)
+ eventmachine (>= 0.12.10)
+ json_pure (>= 1.5.1)
+ nokogiri (1.4.4)
+ pg (0.10.1)
+ polyglot (0.3.1)
+ rack (1.2.2)
+ rack-fiber_pool (0.9.1)
+ rack-mount (0.6.14)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rails (3.0.5)
+ actionmailer (= 3.0.5)
+ actionpack (= 3.0.5)
+ activerecord (= 3.0.5)
+ activeresource (= 3.0.5)
+ activesupport (= 3.0.5)
+ bundler (~> 1.0)
+ railties (= 3.0.5)
+ railties (3.0.5)
+ actionpack (= 3.0.5)
+ activesupport (= 3.0.5)
+ rake (>= 0.8.7)
+ thor (~> 0.14.4)
+ rake (0.8.7)
+ rcov (0.9.9)
+ rspec (2.5.0)
+ rspec-core (~> 2.5.0)
+ rspec-expectations (~> 2.5.0)
+ rspec-mocks (~> 2.5.0)
+ rspec-core (2.5.1)
+ rspec-expectations (2.5.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.5.0)
+ rspec-rails (2.5.0)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (~> 2.5.0)
+ ruby-hmac (0.4.0)
+ sinatra (1.2.1)
+ rack (~> 1.1)
+ tilt (< 2.0, >= 1.2.2)
+ sqlite3 (1.3.3)
+ thin (1.2.11)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
+ thor (0.14.6)
+ tilt (1.2.2)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.26)
+ uuidtools (2.1.2)
+ yajl-ruby (0.8.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ SystemTimer
+ bcrypt-ruby (>= 2.1.4)
+ ci_reporter
+ em-http-request (~> 1.0.0.beta.3)
+ em-redis
+ eventmachine (~> 0.12.10)
+ mocha
+ mysql2 (>= 0.2.6)
+ nats (>= 0.4.8)
+ nokogiri (>= 1.4.4)
+ pg
+ rack-fiber_pool
+ rails (~> 3.0.5)
+ rcov
+ rspec (>= 2.4.0)
+ rspec-rails (>= 2.4.1)
+ ruby-hmac
+ sinatra
+ sqlite3
+ thin (> 1.2)
+ uuidtools
+ vcap_common!
+ yajl-ruby (>= 0.7.9)
256 cloud_controller/README
@@ -0,0 +1,256 @@
+== Welcome to Rails
+
+Rails is a web-application framework that includes everything needed to create
+database-backed web applications according to the Model-View-Control pattern.
+
+This pattern splits the view (also called the presentation) into "dumb"
+templates that are primarily responsible for inserting pre-built data in between
+HTML tags. The model contains the "smart" domain objects (such as Account,
+Product, Person, Post) that holds all the business logic and knows how to
+persist themselves to a database. The controller handles the incoming requests
+(such as Save New Account, Update Product, Show Post) by manipulating the model
+and directing data to the view.
+
+In Rails, the model is handled by what's called an object-relational mapping
+layer entitled Active Record. This layer allows you to present the data from
+database rows as objects and embellish these data objects with business logic
+methods. You can read more about Active Record in
+link:files/vendor/rails/activerecord/README.html.
+
+The controller and view are handled by the Action Pack, which handles both
+layers by its two parts: Action View and Action Controller. These two layers
+are bundled in a single package due to their heavy interdependence. This is
+unlike the relationship between the Active Record and Action Pack that is much
+more separate. Each of these packages can be used independently outside of
+Rails. You can read more about Action Pack in
+link:files/vendor/rails/actionpack/README.html.
+
+
+== Getting Started
+
+1. At the command prompt, create a new Rails application:
+ <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
+
+2. Change directory to <tt>myapp</tt> and start the web server:
+ <tt>cd myapp; rails server</tt> (run with --help for options)
+
+3. Go to http://localhost:3000/ and you'll see:
+ "Welcome aboard: You're riding Ruby on Rails!"
+
+4. Follow the guidelines to start developing your application. You can find
+the following resources handy:
+
+* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
+* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
+
+
+== Debugging Rails
+
+Sometimes your application goes wrong. Fortunately there are a lot of tools that
+will help you debug it and get it back on the rails.
+
+First area to check is the application log files. Have "tail -f" commands
+running on the server.log and development.log. Rails will automatically display
+debugging and runtime information to these files. Debugging info will also be
+shown in the browser on requests from 127.0.0.1.
+
+You can also log your own messages directly into the log file from your code
+using the Ruby logger class from inside your controllers. Example:
+
+ class WeblogController < ActionController::Base
+ def destroy
+ @weblog = Weblog.find(params[:id])
+ @weblog.destroy
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
+ end
+ end
+
+The result will be a message in your log file along the lines of:
+
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
+
+More information on how to use the logger is at http://www.ruby-doc.org/core/
+
+Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
+several books available online as well:
+
+* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
+* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
+
+These two books will bring you up to speed on the Ruby language and also on
+programming in general.
+
+
+== Debugger
+
+Debugger support is available through the debugger command when you start your
+Mongrel or WEBrick server with --debugger. This means that you can break out of
+execution at any point in the code, investigate and change the model, and then,
+resume execution! You need to install ruby-debug to run the server in debugging
+mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
+
+ class WeblogController < ActionController::Base
+ def index
+ @posts = Post.find(:all)
+ debugger
+ end
+ end
+
+So the controller will accept the action, run the first line, then present you
+with a IRB prompt in the server window. Here you can do things like:
+
+ >> @posts.inspect
+ => "[#<Post:0x14a6be8
+ @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
+ #<Post:0x14a6620
+ @attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
+ >> @posts.first.title = "hello from a debugger"
+ => "hello from a debugger"
+
+...and even better, you can examine how your runtime objects actually work:
+
+ >> f = @posts.first
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
+ >> f.
+ Display all 152 possibilities? (y or n)
+
+Finally, when you're ready to resume execution, you can enter "cont".
+
+
+== Console
+
+The console is a Ruby shell, which allows you to interact with your
+application's domain model. Here you'll have all parts of the application
+configured, just like it is when the application is running. You can inspect
+domain models, change values, and save to the database. Starting the script
+without arguments will launch it in the development environment.
+
+To start the console, run <tt>rails console</tt> from the application
+directory.
+
+Options:
+
+* Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
+ made to the database.
+* Passing an environment name as an argument will load the corresponding
+ environment. Example: <tt>rails console production</tt>.
+
+To reload your controllers and models after launching the console run
+<tt>reload!</tt>
+
+More information about irb can be found at:
+link:http://www.rubycentral.com/pickaxe/irb.html
+
+
+== dbconsole
+
+You can go to the command line of your database directly through <tt>rails
+dbconsole</tt>. You would be connected to the database with the credentials
+defined in database.yml. Starting the script without arguments will connect you
+to the development database. Passing an argument will connect you to a different
+database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
+PostgreSQL and SQLite 3.
+
+== Description of Contents
+
+The default directory structure of a generated Ruby on Rails application:
+
+ |-- app
+ | |-- controllers
+ | |-- helpers
+ | |-- mailers
+ | |-- models
+ | `-- views
+ | `-- layouts
+ |-- config
+ | |-- environments
+ | |-- initializers
+ | `-- locales
+ |-- db
+ |-- doc
+ |-- lib
+ | `-- tasks
+ |-- log
+ |-- public
+ | |-- images
+ | |-- javascripts
+ | `-- stylesheets
+ |-- script
+ |-- test
+ | |-- fixtures
+ | |-- functional
+ | |-- integration
+ | |-- performance
+ | `-- unit
+ |-- tmp
+ | |-- cache
+ | |-- pids
+ | |-- sessions
+ | `-- sockets
+ `-- vendor
+ `-- plugins
+
+app
+ Holds all the code that's specific to this particular application.
+
+app/controllers
+ Holds controllers that should be named like weblogs_controller.rb for
+ automated URL mapping. All controllers should descend from
+ ApplicationController which itself descends from ActionController::Base.
+
+app/models
+ Holds models that should be named like post.rb. Models descend from
+ ActiveRecord::Base by default.
+
+app/views
+ Holds the template files for the view that should be named like
+ weblogs/index.html.erb for the WeblogsController#index action. All views use
+ eRuby syntax by default.
+
+app/views/layouts
+ Holds the template files for layouts to be used with views. This models the
+ common header/footer method of wrapping views. In your views, define a layout
+ using the <tt>layout :default</tt> and create a file named default.html.erb.
+ Inside default.html.erb, call <% yield %> to render the view using this
+ layout.
+
+app/helpers
+ Holds view helpers that should be named like weblogs_helper.rb. These are
+ generated for you automatically when using generators for controllers.
+ Helpers can be used to wrap functionality for your views into methods.
+
+config
+ Configuration files for the Rails environment, the routing map, the database,
+ and other dependencies.
+
+db
+ Contains the database schema in schema.rb. db/migrate contains all the
+ sequence of Migrations for your schema.
+
+doc
+ This directory is where your application documentation will be stored when
+ generated using <tt>rake doc:app</tt>
+
+lib
+ Application specific libraries. Basically, any kind of custom code that
+ doesn't belong under controllers, models, or helpers. This directory is in
+ the load path.
+
+public
+ The directory available for the web server. Contains subdirectories for
+ images, stylesheets, and javascripts. Also contains the dispatchers and the
+ default HTML files. This should be set as the DOCUMENT_ROOT of your web
+ server.
+
+script
+ Helper scripts for automation and generation.
+
+test
+ Unit and functional tests along with fixtures. When using the rails generate
+ command, template test files will be generated for you and placed in this
+ directory.
+
+vendor
+ External libraries that the application depends on. Also includes the plugins
+ subdirectory. If the app has frozen rails, those gems also go here, under
+ vendor/rails/. This directory is in the load path.
13 cloud_controller/Rakefile
@@ -0,0 +1,13 @@
+require File.expand_path('../config/application', __FILE__)
+CloudController::Application.load_tasks
+
+Rake.application.instance_eval do
+ %w[test test:recent test:uncommitted].each {|n| @tasks.delete(n) }
+end
+
+task :spec => :install_development_bundle
+task :install_development_bundle do
+ Bundler.with_clean_env do
+ system "bundle install --local --without production"
+ end
+end
17 cloud_controller/TODO
@@ -0,0 +1,17 @@
+#MUST DO.
+
+-support for fd,memory,disk,io quota's.
+-make sure Resque gets setup todo authentication!!!
+
+
+
+#Someday
+-delete verb allows any user to delete any other
+if remote-registration is allowed, which seems overly permissive.
+
+-a terabyres of compressed zero bits (or similar super-compressed objects) could
+be used to blow out the file system. (in resource pool and staging)
+
+-create cache reaper (clean out old stuff?), see space concerns above.
+
+
140 cloud_controller/app/controllers/application_controller.rb
@@ -0,0 +1,140 @@
+class ApplicationController < ActionController::Base
+ # use before_filter :require_user or :require_admin in subclasses to enforce logged-in status.
+ before_filter :fetch_user_from_token
+ rescue_from Exception, :with => :handle_general_exception
+ rescue_from CloudError, :with => :render_cloud_error
+ rescue_from ActiveRecord::StaleObjectError, :with => :handle_locking_error
+
+ def process_action(method_name, *args)
+
+ unless VCAP::Component.varz.nil?
+ VCAP::Component.varz[:requests] += 1
+ VCAP::Component.varz[:pending_requests] += 1
+ end
+
+ @error = nil
+ ret = super
+
+ if CloudController.events # Not set in test environment.
+ user_email = user ? user.email : 'N/A'
+ method = "#{request.method}:#{request.path}"
+ status = @error ? [:FAILED, @error.to_s] : [:SUCCEEDED]
+ ev_args = @event_args || []
+ ev_args.compact!
+ CloudController.events.user_event(user_email, method, *@event_args, *status)
+ end
+
+ ret
+
+ ensure
+ VCAP::Component.varz[:pending_requests] -= 1 unless VCAP::Component.varz.nil?
+ end
+
+ protected
+ def http_aget(url, auth)
+ f = Fiber.current
+ http = EM::HttpRequest.new(url).get :head => { "authorization" => auth }
+ http.errback { f.resume(http) }
+ http.callback { f.resume(http) }
+ return Fiber.yield
+ end
+
+ def user
+ @proxy_user || @current_user
+ end
+
+ def body_params
+ if request.body.blank?
+ {}
+ else
+ @body_params ||= Yajl::Parser.parse(request.body.read, :symbolize_keys => true)
+ end
+ rescue Yajl::ParseError
+ raise CloudError.new(CloudError::BAD_REQUEST)
+ end
+
+ def request_body
+ request.body.rewind
+ request.body.read
+ end
+
+ def json_param(name)
+ raw = params[name]
+ Yajl::Parser.parse(raw, :symbolize_keys => true)
+ rescue Yajl::ParseError
+ raise CloudError.new(CloudError::BAD_REQUEST)
+ end
+
+ def fetch_user_from_token
+ reset_user!
+ unless auth_token_header.blank?
+ token = UserToken.decode(auth_token_header)
+ if token.valid?
+ @current_user = ::User.find_by_email(token.user_name)
+ end
+ end
+ fetch_proxy_user
+ rescue UserToken::DecodeError
+ logger.warn "Invalid user token in request: #{auth_token_header.inspect}"
+ end
+
+ def reset_user!
+ @current_user, @proxy_user = nil, nil
+ end
+
+ def fetch_proxy_user
+ return if proxy_user_header.blank?
+ evs = [(@current_user ? @current_user.email : 'UNKNOWN_USER'),'PROXY ATTEMPT', proxy_user_header]
+ if @current_user && @current_user.admin?
+ @proxy_user = ::User.find_by_email(proxy_user_header)
+ if @proxy_user.nil?
+ CloudController.events.sys_event(*evs, :FAILED, CloudError::USER_NOT_FOUND[2])
+ raise CloudError.new(CloudError::USER_NOT_FOUND)
+ end
+ else
+ CloudController.events.sys_event(*evs, :FAILED, CloudError::FORBIDDEN[2])
+ raise CloudError.new(CloudError::FORBIDDEN)
+ end
+ CloudController.events.sys_event(*evs, :SUCCEEDED)
+ end
+
+ def require_user
+ unless user
+ raise CloudError.new(CloudError::FORBIDDEN)
+ end
+ end
+
+ def require_admin
+ unless user && user.admin?
+ raise CloudError.new(CloudError::FORBIDDEN)
+ end
+ end
+
+ def auth_token_header
+ request.headers['HTTP_AUTHORIZATION']
+ end
+
+ def proxy_user_header
+ request.headers['HTTP_PROXY_USER']
+ end
+
+ def remote_request?
+ request.remote_ip != '127.0.0.1'
+ end
+
+ # Called whenever an action raises a CloudError.
+ # See lib/cloud_error.rb for details.
+ def render_cloud_error(e)
+ @error = e
+ render :status => e.status, :json => e.to_json
+ end
+
+ def handle_locking_error
+ render_cloud_error CloudError.new(CloudError::LOCKING_ERROR)
+ end
+
+ def handle_general_exception(e)
+ render_cloud_error CloudError.new(CloudError::SYSTEM_ERROR)
+ end
+
+end
350 cloud_controller/app/controllers/apps_controller.rb
@@ -0,0 +1,350 @@
+class AppsController < ApplicationController
+ before_filter :require_user, :except => [:download_staged]
+ before_filter :find_app_by_name, :except => [:create, :list, :download_staged]
+
+ def process_action(method_name, *args)
+ app = @app ? @app.name : (params[:name] || (body_params && body_params[:name]))
+ @event_args = [app]
+ super(method_name, *args)
+ end
+
+ # POST /apps
+ def create
+ name = body_params[:name]
+ app = ::App.new(:owner => user, :name => name)
+ begin
+ update_app_from_params(app)
+ rescue => e
+ app.destroy
+ raise e
+ end
+ app_url = app_get_url(name)
+ render :json => {:result => 'success', :redirect => app_url }, :location => app_url, :status => 302
+ end
+
+ # PUT /apps/:name
+ def update
+ update_app_from_params(@app)
+ render :nothing => true
+ end
+
+ def get
+ render :json => @app.as_json
+ end
+
+ def stats
+ render :json => AppManager.new(@app).find_stats
+ end
+
+ def list
+ render :json => user.get_apps.to_a
+ end
+
+ def delete
+ @app.purge_all_resources!
+ @app.destroy
+ render :nothing => true, :status => 200
+ end
+
+ # POST /apps/:name/application
+ def upload
+ app_bits = params[:application]
+ resources = json_param(:resources)
+ package = AppPackage.new(@app, app_bits, resources)
+ @app.latest_bits_from(package)
+ render :nothing => true, :status => 200
+ end
+
+ def download
+ path = @app.package_path
+ if path && File.exists?(path)
+ send_file path
+ else
+ raise CloudError.new(CloudError::APP_NOT_FOUND)
+ end
+ end
+
+ def download_staged
+ app = App.find_by_id(params[:id])
+ raise CloudError.new(CloudError::APP_NOT_FOUND) unless app && (app.staged_package_hash == params[:hash])
+
+ path = app.staged_package_path
+ if path && File.exists?(path)
+ send_file path
+ else
+ raise CloudError.new(CloudError::APP_NOT_FOUND)
+ end
+ end
+
+ def crashes
+ render :json => {:crashes => @app.find_recent_crashes}
+ end
+
+ def instances
+ render :json => {:instances => @app.find_instances}
+ end
+
+ # PUT /apps/:name/update
+ def start_update
+ raise CloudError.new(CloudError::APP_STOPPED) unless @app.started?
+ # Simulate a start call
+ error_on_lock_mismatch(@app)
+ @app.lock_version += 1
+ manager = AppManager.new(@app)
+ manager.stage if @app.needs_staging?
+ manager.stop_all
+ manager.started
+ render :nothing => true, :status => 204
+ end
+
+ # GET /apps/:name/update
+ # This is simple now versus older version, but need to hack old behavior
+ def check_update
+ data = { :state => :NONE, :since => @app.last_updated }
+
+ if @app.state =~ /STARTED/i
+ case @app.package_state
+ when /PENDING/i
+ data[:state] = :UPDATING
+ when /FAILED/i
+ data[:state] = :CANARY_FAILED
+ when /STAGED/i
+ running = @app.running_instances
+ if (running == @app.instances)
+ data[:state] = :SUCCEEDED
+ else
+ # Check for crashes, or leave as updating
+ crashes = @app.find_recent_crashes
+ if crashes.empty?
+ data[:state] = :UPDATING
+ else
+ data[:state] = :CANARY_FAILED
+ end
+ end
+ end
+ else
+ data[:state] = :CANARY_FAILED
+ end
+
+ render :json => data
+ end
+
+ # GET /apps/:name/instances/:instance_id/files/:path'
+ def files
+ # will Fiber.yield
+ url, auth = AppManager.new(@app).get_file_url(params[:instance_id], params[:path])
+ raise CloudError.new(CloudError::APP_FILE_ERROR, params[:path] || '/') unless url
+
+ # FIXME, need to stream responses. Seems broken with Fibers, EM,
+ # and response_body=proc
+
+ # will Fiber.yield
+ http = http_aget(url, auth)
+ if http.response_header.status != 200
+ raise CloudError.new(CloudError::APP_FILE_ERROR, params[:path] || '/')
+ end
+ # We ignore headers here since upstream will redo as they see fit
+ #render :text => http.response, :status => 200
+ self.response_body = http.response
+ end
+
+ private
+
+ def find_app_by_name
+ # XXX - What do we want semantics to be like for multiple apps w/ same name (possible w/ contribs)
+ @app = user.apps_owned.find_by_name(params[:name])
+ raise CloudError.new(CloudError::APP_NOT_FOUND) unless @app
+
+ # TODO - Deliberately leaving off 'user.admin? ||' here.
+ # This logic requires admins to proxy as the user that owns the app.
+ # Is it OK to be this draconian?
+
+ #raise CloudError.new(CloudError::APP_NOT_FOUND) unless @app.user == user
+ raise CloudError.new(CloudError::APP_NOT_FOUND) unless @app.collaborator?(user)
+ end
+
+ # Checks to make sure the update can proceed, then updates the given
+ # App from the request params and makes the necessary AppManager calls.
+ def update_app_from_params(app)
+ error_on_lock_mismatch(app)
+ app.lock_version += 1
+
+ previous_state = app.state
+ update_app_state(app)
+ # State needs to be changed from above before capacity check.
+ check_has_capacity_for?(app, previous_state)
+ check_app_uris(app)
+ update_app_mem(app)
+ update_app_env(app)
+ update_app_staging(app)
+ delta_instances = update_app_instances(app)
+
+ changed = app.changed
+
+ # 'app.save' can actually raise an exception, if whatever is
+ # invalid happens all the way down at the DB layer.
+ begin
+ app.save!
+ rescue
+ logger.debug "Failed to save new app, app invalid"
+ raise CloudError.new(CloudError::APP_INVALID)
+ end
+
+ # This needs to be called after the app is saved, but before staging.
+ update_app_services(app)
+ app.save if app.changed?
+
+ # Process any changes that require action on out part here.
+ manager = AppManager.new(app)
+ manager.stage if app.needs_staging?
+
+ if changed.include?('state')
+ if app.stopped?
+ manager.stopped
+ elsif app.started?
+ manager.started
+ end
+ manager.updated
+ elsif app.started?
+ # Instances (up or down) and uris we will handle in place, since it does not
+ # involve staging changes.
+ if changed.include?('instances')
+ manager.change_running_instances(delta_instances)
+ manager.updated
+ end
+ end
+
+ # Now add in URLs
+ manager.update_uris if update_app_uris(app)
+
+ yield(app) if block_given?
+ end
+
+ def update_app_mem(app)
+ return unless body_params && body_params[:resources] && body_params[:resources][:memory]
+ app.memory = body_params[:resources][:memory].to_i
+ end
+
+ def update_app_env(app)
+ return unless body_params && body_params[:env]
+ app.environment = body_params[:env].uniq
+ end
+
+ def update_app_instances(app)
+ return 0 unless body_params && body_params[:instances]
+ updated_instances = body_params[:instances].to_i
+ current_instances = app.instances
+ app.instances = updated_instances
+ updated_instances - current_instances
+ end
+
+ def error_on_lock_mismatch(app)
+ if body_params && body_params[:meta] && body_params[:meta][:version]
+ if body_params[:meta][:version].to_i != app.lock_version
+ raise CloudError.new(CloudError::LOCKING_ERROR)
+ end
+ end
+ end
+
+ def check_app_uris(app)
+ return unless body_params && body_params[:uris]
+ uris = body_params[:uris]
+ # Normalize URLs
+ uris.each { |u| u.gsub!(/^http(s*):\/\//i, '') }
+ limit = app.owner.account_capacity[:app_uris]
+ if uris.length > limit
+ raise CloudError.new(CloudError::ACCOUNT_APP_TOO_MANY_URIS, uris.length, limit)
+ end
+ end
+
+ # Only call this after an app has been saved.
+ def update_app_uris(app)
+ return false unless body_params && body_params[:uris]
+ app.set_urls(body_params[:uris])
+ end
+
+ def update_app_staging(app)
+ if body_params && body_params[:staging]
+ # This is the legacy model, we will continue to support that for now.
+ if body_params[:staging][:model]
+ app.framework = body_params[:staging][:model]
+ app.runtime = body_params[:staging][:stack]
+ else
+ app.framework = body_params[:staging][:framework]
+ app.runtime = body_params[:staging][:runtime]
+ end
+ end
+ unless app.framework
+ logger.debug "No app framework indicated"
+ raise CloudError.new(CloudError::APP_INVALID_FRAMEWORK, 'NONE')
+ end
+ end
+
+ def update_app_state(app)
+ return if body_params.nil?
+ state = body_params[:state]
+ return if state.nil? || app.state.to_s =~ /#{state}/i
+ case state
+ when /STARTED/i
+ app.state = 'STARTED'
+ when /STOPPED/i
+ app.state = 'STOPPED'
+ end
+ end
+
+ # This is needed to support the legacy VMC client
+ # only call this after an app has been saved
+ def update_app_services(app)
+ return if body_params.nil?
+ added_configs, removed_configs = app.diff_configs(body_params[:services])
+ return if added_configs.empty? && removed_configs.empty?
+ logger.debug "Adding services: #{added_configs.inspect}"
+ logger.debug "Removing services: #{removed_configs.inspect}"
+
+ # Bind services
+ added_configs.each do |cfg_alias|
+ cfg = ServiceConfig.find_by_alias_and_user_id(cfg_alias, user.id)
+ raise CloudError.new(CloudError::SERVICE_NOT_FOUND) unless cfg
+ raise CloudError.new(CloudError::FORBIDDEN) unless app.collaborator?(user)
+ app.bind_to_config(cfg)
+ end
+
+ # Unbind services
+ removed_configs.each do |cfg_alias|
+ cfg = ServiceConfig.find_by_alias_and_user_id(cfg_alias, user.id)
+ raise CloudError.new(CloudError::SERVICE_NOT_FOUND) unless cfg
+ raise CloudError.new(CloudError::FORBIDDEN) unless app.collaborator?(user)
+ app.unbind_from_config(cfg)
+ end
+ # Since we made binding changes, we expect to be restaged.
+ app.package_state = 'PENDING'
+ end
+
+ # Note that the state needs to be updated prior to calling this check.
+ def check_has_capacity_for?(app, previous_state)
+ return unless body_params
+ owner = app.owner
+ # If we are creating this app, check to make sure the user
+ # has not allocated too many apps, regardless of state.
+ if app.new_record?
+ if current_apps = owner.no_more_apps?
+ app_quota = owner.account_capacity[:apps]
+ raise CloudError.new(CloudError::ACCOUNT_APPS_TOO_MANY, current_apps, app_quota)
+ end
+ end
+
+ # Only worry about apps that are running or they want to run.
+ return true unless app.state =~ /STARTED/i
+
+ # Whether it is a creation or an update, check memory capacity.
+ memory = body_params[:resources] && body_params[:resources][:memory]
+ instances = body_params[:instances] || app.instances
+ per_instance = memory || app.memory
+ existing = (previous_state =~ /STARTED/i) ? app.total_memory : 0
+
+ unless owner.has_memory_for?(instances, per_instance, existing, previous_state)
+ mem_quota = owner.account_capacity[:memory]
+ raise CloudError.new(CloudError::ACCOUNT_NOT_ENOUGH_MEMORY, "#{mem_quota}M")
+ end
+ end
+end
68 cloud_controller/app/controllers/binding_tokens_controller.rb
@@ -0,0 +1,68 @@
+require 'json_message'
+require 'services/api'
+
+class BindingTokensController < ApplicationController
+ before_filter :validate_content_type
+ before_filter :require_user, :only => [:create, :delete]