Skip to content

Commit

Permalink
add min_size policy for the resource pool
Browse files Browse the repository at this point in the history
Change-Id: I7a2e03c7dd2100d8cd5254997c086f16b44efae0
  • Loading branch information
Glenn Oppegard & Patrick Bozeman committed Jan 29, 2013
1 parent 3635865 commit c071e15
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/cloud_controller/config.rb
Expand Up @@ -95,6 +95,7 @@ class VCAP::CloudController::Config < VCAP::Config


:resource_pool => { :resource_pool => {
optional(:maximum_size) => Integer, optional(:maximum_size) => Integer,
optional(:minimum_size) => Integer,
optional(:resource_directory_key) => String, optional(:resource_directory_key) => String,
:fog_connection => { :fog_connection => {
:provider => String, :provider => String,
Expand Down
14 changes: 11 additions & 3 deletions lib/cloud_controller/resource_pool.rb
Expand Up @@ -17,6 +17,7 @@ def configure(config = {})
opts = config[:resource_pool] || {} opts = config[:resource_pool] || {}
@connection_config = opts[:fog_connection] @connection_config = opts[:fog_connection]
@resource_directory_key = opts[:resource_directory_key] || "cc-resources" @resource_directory_key = opts[:resource_directory_key] || "cc-resources"
@minimum_size = opts[:minimum_size] || 0
@maximum_size = opts[:maximum_size] || 512 * 1024 * 1024 # MB @maximum_size = opts[:maximum_size] || 512 * 1024 * 1024 # MB
end end


Expand Down Expand Up @@ -84,13 +85,20 @@ def logger
end end


def resource_known?(descriptor) def resource_known?(descriptor)
key = key_from_sha1(descriptor["sha1"]) size = descriptor["size"]
resource_dir.files.head(key) if size_allowed?(size)
key = key_from_sha1(descriptor["sha1"])
resource_dir.files.head(key)
end
end end


def resource_allowed?(path) def resource_allowed?(path)
stat = File.stat(path) stat = File.stat(path)
File.file?(path) && !stat.symlink? && stat.size < maximum_size File.file?(path) && !stat.symlink? && size_allowed?(stat.size)
end

def size_allowed?(size)
size && size > minimum_size && size < maximum_size
end end


# Called after we sanity-check the input. # Called after we sanity-check the input.
Expand Down
25 changes: 25 additions & 0 deletions spec/resource_pool_spec.rb
Expand Up @@ -44,5 +44,30 @@ module VCAP::CloudController
ResourcePool.add_directory(@tmpdir) ResourcePool.add_directory(@tmpdir)
end end
end end

describe "#size_allowed?" do
before do
@minimum_size = 5
@maximum_size = 7
ResourcePool.minimum_size = @minimum_size
ResourcePool.maximum_size = @maximum_size
end

it "should return true for a size between min and max size" do
ResourcePool.send(:size_allowed?, @minimum_size + 1).should be_true
end

it "should return false for a size < min size" do
ResourcePool.send(:size_allowed?, @minimum_size - 1).should be_false
end

it "should return false for a size > max size" do
ResourcePool.send(:size_allowed?, @maximum_size + 1).should be_false
end

it "should return false for a nil size" do
ResourcePool.send(:size_allowed?, nil).should be_false
end
end
end end
end end

0 comments on commit c071e15

Please sign in to comment.