Permalink
Browse files

Initial memory quota implementation.

Change-Id: I49006b444724dc78bb594775a17bc281c2c1d857
  • Loading branch information...
kowshik committed Dec 20, 2012
1 parent 1fde17b commit ad4911f7349d2923acb3c6cc95e00a9fd66577b5
@@ -66,11 +66,17 @@ quota_definitions:
free:
non_basic_services_allowed: false
total_services: 2
+ free_memory_limit: 1024 # 1 GB
+ paid_memory_limit: 0
paid:
non_basic_services_allowed: true
total_services: 32
+ free_memory_limit: 1024 # 1 GB
+ paid_memory_limit: 32768 # 32 GB
runaway:
non_basic_services_allowed: true
total_services: 500
+ free_memory_limit: 1024 # 1 GB
+ paid_memory_limit: 204800 # 200 GB
default_quota_definition: free
@@ -0,0 +1,30 @@
+# Copyright (c) 2009-2012 VMware, Inc.
+
+Sequel.migration do
+ change do
+ alter_table :quota_definitions do
+ add_column :free_memory_limit, Integer
+ add_column :paid_memory_limit, Integer
+ end
+
+ self[:quota_definitions].all do |r|
+ self[:quota_definitions].filter(:name => r[:name]).
+ update(:free_memory_limit => 1024)
+ self[:quota_definitions].filter(:name => r[:name]).
+ update(:paid_memory_limit => 0)
+ end
+
+ alter_table :quota_definitions do
+ set_column_not_null :free_memory_limit
+ set_column_not_null :paid_memory_limit
+
+ # Sequel doesn't preserve db constraints for sqlite when adding new
+ # constraints, like we did just above. So, we add the unique name
+ # constraint again. We should seriously consider only using Postgres
+ # for development.
+ if @db.kind_of?(Sequel::SQLite::Database)
+ add_unique_constraint(:name)
+ end
+ end
+ end
+end
@@ -11,6 +11,8 @@ module VCAP::CloudController
attribute :name, String
attribute :non_basic_services_allowed, Message::Boolean
attribute :total_services, Integer
+ attribute :free_memory_limit, Integer
+ attribute :paid_memory_limit, Integer
end
query_parameters :name
@@ -3,14 +3,18 @@
module VCAP::CloudController::Models
class QuotaDefinition < Sequel::Model
- export_attributes :name, :non_basic_services_allowed, :total_services
- import_attributes :name, :non_basic_services_allowed, :total_services
+ export_attributes :name, :non_basic_services_allowed, :total_services,
+ :free_memory_limit, :paid_memory_limit
+ import_attributes :name, :non_basic_services_allowed, :total_services,
+ :free_memory_limit, :paid_memory_limit
def validate
validates_presence :name
validates_unique :name
validates_presence :non_basic_services_allowed
validates_presence :total_services
+ validates_presence :free_memory_limit
+ validates_presence :paid_memory_limit
end
def self.populate_from_config(config)
@@ -8,8 +8,12 @@ module VCAP::CloudController
it_behaves_like "a CloudController API", {
:path => "/v2/quota_definitions",
:model => Models::QuotaDefinition,
- :basic_attributes => [:name, :non_basic_services_allowed, :total_services],
- :required_attributes => [:name, :non_basic_services_allowed, :total_services],
+ :basic_attributes => [:name, :non_basic_services_allowed,
+ :total_services, :free_memory_limit,
+ :paid_memory_limit],
+ :required_attributes => [:name, :non_basic_services_allowed,
+ :total_services, :free_memory_limit,
+ :paid_memory_limit],
:unique_attributes => :name,
}
end
View
@@ -162,5 +162,7 @@ module VCAP::CloudController::Models
name { Sham.name }
non_basic_services_allowed { true }
total_services { 60 }
+ free_memory_limit { 1024 } # 1 GB
+ paid_memory_limit { 2048 } # 1 GB
end
end
@@ -5,7 +5,9 @@
module VCAP::CloudController
describe VCAP::CloudController::Models::QuotaDefinition do
it_behaves_like "a CloudController model", {
- :required_attributes => [:name, :non_basic_services_allowed, :total_services],
+ :required_attributes => [:name, :non_basic_services_allowed,
+ :total_services, :free_memory_limit,
+ :paid_memory_limit],
:unique_attributes => [:name]
}
@@ -20,6 +22,8 @@ module VCAP::CloudController
runaway = Models::QuotaDefinition[:name => "runaway"]
runaway.non_basic_services_allowed.should == true
runaway.total_services.should == 500
+ runaway.free_memory_limit.should == 1024
+ runaway.paid_memory_limit.should == 204800
end
end

0 comments on commit ad4911f

Please sign in to comment.