Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 41e2c2c1165e96f2506bf7b56e1c407c335ea4cd Cloud Foundry Engineer committed Apr 12, 2011
Showing with 2,492 additions and 0 deletions.
  1. +19 −0 Gemfile
  2. +65 −0 Gemfile.lock
  3. +39 −0 Rakefile
  4. +48 −0 bin/close_fds
  5. +5 −0 bin/dea
  6. +39 −0 config/dea.yml
  7. +40 −0 config/dea2.yml
  8. +52 −0 lib/dea.rb
  9. +1,434 −0 lib/dea/agent.rb
  10. +137 −0 lib/dea/directory.rb
  11. +122 −0 lib/dea/secure.rb
  12. +41 −0 spec/Rakefile
  13. +309 −0 spec/functional/agent_spec.rb
  14. +84 −0 spec/functional/spec_helper.rb
  15. +26 −0 spec/functional/start_tcpserver.rb
  16. +21 −0 spec/functional/stop_tcpserver.rb
  17. +11 −0 spec/spec_helper.rb
19 Gemfile
@@ -0,0 +1,19 @@
+source "http://rubygems.org"
+
+gem 'bundler', '>= 1.0.10'
+gem 'nats', '>= 0.4.8', :require => 'nats/client'
+gem 'eventmachine', '~> 0.12.10'
+gem 'em-http-request', '~> 1.0.0.beta.3', :require => 'em-http'
+
+gem 'rack', :require => ["rack/utils", "rack/mime"]
+gem 'rake'
+gem 'thin'
+gem 'yajl-ruby', :require => ['yajl', 'yajl/json_gem']
+
+gem 'vcap_common', :path => '../common'
+
+group :test do
+ gem "rspec"
+ gem "rcov"
+ gem "ci_reporter"
+end
@@ -0,0 +1,65 @@
+PATH
+ remote: ../common
+ specs:
+ vcap_common (0.99)
+ eventmachine (~> 0.12.10)
+ nats
+ thin
+ yajl-ruby
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ addressable (2.2.4)
+ builder (3.0.0)
+ 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-socksify (0.1.0)
+ eventmachine
+ eventmachine (0.12.10)
+ http_parser.rb (0.5.1)
+ json_pure (1.5.1)
+ nats (0.4.8)
+ daemons (>= 1.1.0)
+ eventmachine (>= 0.12.10)
+ json_pure (>= 1.5.1)
+ rack (1.2.2)
+ 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)
+ thin (1.2.11)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
+ yajl-ruby (0.8.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bundler (>= 1.0.10)
+ ci_reporter
+ em-http-request (~> 1.0.0.beta.3)
+ eventmachine (~> 0.12.10)
+ nats (>= 0.4.8)
+ rack
+ rake
+ rcov
+ rspec
+ thin
+ vcap_common!
+ yajl-ruby
@@ -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,48 @@
+#!/usr/bin/env ruby
+# Copyright (c) 2009-2011 VMware, Inc.
+
+require "fileutils"
+
+def close_fds
+ 3.upto(get_max_open_fd) do |fd|
+ begin
+ IO.for_fd(fd, "r").close
+ rescue
+ end
+ end
+end
+
+def get_max_open_fd
+ max = 0
+
+ dir = nil
+ if File.directory?("/proc/self/fd/") # Linux
+ dir = "/proc/self/fd/"
+ elsif File.directory?("/dev/fd/") # Mac
+ dir = "/dev/fd/"
+ end
+
+ if dir
+ Dir.foreach(dir) do |entry|
+ begin
+ pid = Integer(entry)
+ max = pid if pid > max
+ rescue
+ end
+ end
+ else
+ max = 65535
+ end
+
+ max
+end
+
+close_fds
+
+# deletes itself when run by the DEA
+delete_script = ARGV.shift
+if delete_script == "true"
+ FileUtils.rm(__FILE__)
+end
+
+exec(*ARGV)
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+
+home = File.join(File.dirname(__FILE__), '/..')
+ENV['BUNDLE_GEMFILE'] = "#{home}/Gemfile"
+require File.join(home, 'lib/dea')
@@ -0,0 +1,39 @@
+---
+base_dir: /var/vcap.local/dea
+local_route: 127.0.0.1
+filer_port: 12345
+mbus: nats://localhost:4222/
+intervals:
+ heartbeat: 10
+log_level: DEBUG
+multi_tenant: true
+max_memory: 4096
+secure: false
+pid: /var/vcap/sys/run/dea.pid
+
+# This is where the execution agent determines its available runtimes.
+# version flags are assumed to be '-v' unless noted below.
+
+runtimes:
+ ruby18:
+ executable: /usr/bin/ruby
+ version: 1.8.7
+ version_flag: "-e 'puts RUBY_VERSION'"
+ additional_checks: "-e 'puts RUBY_PATCHLEVEL >= 174'"
+ environment:
+ ruby19:
+ executable: ruby
+ version: 1.9.2
+ version_flag: "-e 'puts RUBY_VERSION'"
+ additional_checks: "-e 'puts RUBY_PATCHLEVEL >= 180'"
+ environment:
+ node:
+ executable: node
+ version: 0.4.[2-9]
+ version_flag: '-v'
+ environment:
+ java:
+ executable: java
+ version: 1.6.0
+ version_flag: '-version'
+ environment:
@@ -0,0 +1,40 @@
+---
+base_dir: /var/vcap.local/dea2
+local_route: 127.0.0.1
+filer_port: 12346
+mbus: nats://localhost:4222/
+intervals:
+ heartbeat: 10
+log_level: DEBUG
+multi_tenant: true
+max_memory: 4096
+secure: false
+pid: /var/vcap/sys/run/dea2.pid
+
+# This is where the execution agent determines its available runtimes.
+# version flags are assumed to be '-v' unless noted below.
+
+runtimes:
+ ruby18:
+ executable: /usr/bin/ruby
+ version: 1.8.7
+ version_flag: "-e 'puts RUBY_VERSION'"
+ additional_checks: "-e 'puts RUBY_PATCHLEVEL >= 174'"
+ environment:
+ ruby19:
+ executable: ruby
+ version: 1.9.2
+ version_flag: "-e 'puts RUBY_VERSION'"
+ additional_checks: "-e 'puts RUBY_PATCHLEVEL >= 180'"
+ environment:
+ node:
+ executable: node
+ version: 0.4.[2-9]
+ version_flag: '-v'
+ environment:
+ java:
+ executable: java
+ version: 1.6.0
+ version_flag: '-version'
+ environment:
+
@@ -0,0 +1,52 @@
+# Copyright (c) 2009-2011 VMware, Inc.
+$:.unshift(File.join(File.dirname(__FILE__), 'lib'))
+$:.unshift(File.dirname(__FILE__))
+
+require 'optparse'
+require 'yaml'
+
+require 'rubygems'
+require 'bundler/setup'
+
+require 'dea/agent'
+
+cfg_overrides = { 'config_file' => File.join(File.dirname(__FILE__), '../config/dea.yml') }
+
+options = OptionParser.new do |opts|
+ opts.banner = 'Usage: dea [OPTIONS]'
+ opts.on("-c", "--config [ARG]", "Configuration File") do |opt|
+ cfg_overrides['config_file'] = opt
+ end
+ opts.on("-s", "--secure", "Secure Application Environment") do |opt|
+ cfg_overrides['secure'] = true
+ end
+ opts.on("--disable_dir_cleanup", "Don't cleanup App directories") do |opt|
+ cfg_overrides['disable_dir_cleanup'] = true
+ end
+ opts.on("-h", "--help", "Help") do
+ puts opts
+ exit
+ end
+end
+options.parse!(ARGV.dup)
+
+begin
+ config = File.open(cfg_overrides['config_file']) do |f|
+ YAML.load(f)
+ end
+rescue => e
+ puts "Could not read configuration file: #{e}"
+ exit 1
+end
+
+config.update(cfg_overrides)
+
+# XXX(mjp) - Not sure if this is needed...
+config['config_file'] = File.expand_path(config['config_file'])
+
+EM.epoll
+EM.run {
+ agent = DEA::Agent.new(config)
+ agent.run()
+}
+
Oops, something went wrong.

0 comments on commit 41e2c2c

Please sign in to comment.