Skip to content
Browse files

Drop runaway quota and free / paid memory limits.

[finishes #42829779]

Change-Id: Ia71b6ed946237c493393fc2cc790b38abe9be3f9
  • Loading branch information...
1 parent 3bea89e commit 5c07b49a66803c5539eb4be9ed4cbf9530f6303b Kowshik Prakasam and Nate Clark committed Jan 31, 2013
View
11 config/cloud_controller.yml
@@ -66,18 +66,11 @@ quota_definitions:
free:
non_basic_services_allowed: false
total_services: 2
- free_memory_limit: 1024 # 1 GB
- paid_memory_limit: 0
+ memory_limit: 512 # 0.5 GB
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
+ memory_limit: 204800 # 20 GB
default_quota_definition: free
View
18 db/migrations/20130131215943_rename_memory_quota_definitions.rb
@@ -0,0 +1,18 @@
+# Copyright (c) 2009-2012 VMware, Inc.
+
+Sequel.migration do
+ change do
+ alter_table :quota_definitions do
+ drop_column :paid_memory_limit
+ rename_column :free_memory_limit, :memory_limit
+
+ # this is hacky, but sequel doesn't preserve db constraints for sqlite
+ # when adding new ones, like we just did above. So, re-add the unique
+ # name constraint. We should seriously consider only using PG for
+ # development.
+ if @db.kind_of?(Sequel::SQLite::Database)
+ add_unique_constraint(:name)
+ end
+ end
+ end
+end
View
6 lib/cloud_controller/api/app.rb
@@ -76,10 +76,8 @@ def self.translate_validation_exception(e, attributes)
if space_and_name_errors && space_and_name_errors.include?(:unique)
Errors::AppNameTaken.new(attributes["name"])
elsif memory_quota_errors
- if memory_quota_errors.include?(:free_quota_exceeded)
- Errors::AppMemoryFreeQuotaExceeded.new
- elsif memory_quota_errors.include?(:paid_quota_exceeded)
- Errors::AppMemoryPaidQuotaExceeded.new
+ if memory_quota_errors.include?(:quota_exceeded)
+ Errors::AppMemoryQuotaExceeded.new
end
else
Errors::AppInvalid.new(e.errors.full_messages)
View
3 lib/cloud_controller/api/quota_definition.rb
@@ -11,8 +11,7 @@ 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
+ attribute :memory_limit, Integer
end
query_parameters :name
View
3 lib/cloud_controller/errors.rb
@@ -62,8 +62,7 @@ module VCAP::CloudController::Errors
["AppInvalid", HTTP::BAD_REQUEST, 100001, "The app is invalid: %s"],
["AppNameTaken", HTTP::BAD_REQUEST, 100002, "The app name is taken: %s"],
["AppNotFound", HTTP::NOT_FOUND, 100004, "The app name could not be found: %s"],
- ["AppMemoryFreeQuotaExceeded", HTTP::BAD_REQUEST, 100005, "You have exceeded your organization's memory limit. Please login to your account and upgrade."],
- ["AppMemoryPaidQuotaExceeded", HTTP::BAD_REQUEST, 100006, "You have exceeded your organization's memory limit. Please file a support ticket to request additional resources."],
+ ["AppMemoryQuotaExceeded", HTTP::BAD_REQUEST, 100005, "You have exceeded your organization's memory limit. Please login to your account and upgrade."],
["ServicePlanInvalid", HTTP::BAD_REQUEST, 110001, "The service plan is invalid: %s"],
["ServicePlanNameTaken", HTTP::BAD_REQUEST, 110002, "The service plan name is taken: %s"],
View
11 lib/cloud_controller/models/app.rb
@@ -210,15 +210,8 @@ def additional_memory_requested
end
def check_memory_quota
- if space
- org = space.organization
- if production
- if org.paid_memory_remaining - additional_memory_requested < 0
- errors.add(:memory, :paid_quota_exceeded)
- end
- elsif org.free_memory_remaining - additional_memory_requested < 0
- errors.add(:memory, :free_quota_exceeded)
- end
+ if space && (space.organization.memory_remaining < additional_memory_requested)
+ errors.add(:memory, :quota_exceeded)
end
end
View
19 lib/cloud_controller/models/organization.rb
@@ -102,22 +102,9 @@ def paid_services_allowed?
quota_definition.non_basic_services_allowed
end
- def free_memory_apps
- apps_dataset.filter(:production => false)
- end
-
- def paid_memory_apps
- apps_dataset.filter(:production => true)
- end
-
- def free_memory_remaining
- free_memory_used = free_memory_apps.sum(:memory * :instances) || 0
- quota_definition.free_memory_limit - free_memory_used
- end
-
- def paid_memory_remaining
- paid_memory_used = paid_memory_apps.sum(:memory * :instances) || 0
- quota_definition.paid_memory_limit - paid_memory_used
+ def memory_remaining
+ memory_used = apps_dataset.sum(:memory * :instances) || 0
+ quota_definition.memory_limit - memory_used
end
def self.user_visibility_filter(user)
View
7 lib/cloud_controller/models/quota_definition.rb
@@ -4,17 +4,16 @@ module VCAP::CloudController::Models
class QuotaDefinition < Sequel::Model
export_attributes :name, :non_basic_services_allowed, :total_services,
- :free_memory_limit, :paid_memory_limit
+ :memory_limit
import_attributes :name, :non_basic_services_allowed, :total_services,
- :free_memory_limit, :paid_memory_limit
+ :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
+ validates_presence :memory_limit
end
def self.populate_from_config(config)
View
29 spec/api/app_spec.rb
@@ -493,32 +493,11 @@ module VCAP::CloudController
end
describe "Quota enforcement" do
- let(:paid_quota) { Models::QuotaDefinition.make(:paid_memory_limit => 0) }
- let(:free_quota) do
- Models::QuotaDefinition.make(:free_memory_limit => 0)
- end
-
- context "paid quota" do
- it "should enforce quota check on memory" do
- org = Models::Organization.make(:quota_definition => paid_quota)
- space = Models::Space.make(:organization => org)
- req = Yajl::Encoder.encode(:name => Sham.name,
- :space_guid => space.guid,
- :memory => 128,
- :production => true,
- :framework_guid => Models::Framework.make.guid,
- :runtime_guid => Models::Runtime.make.guid)
-
- post("/v2/apps", req, headers_for(make_developer_for_space(space)))
-
- last_response.status.should == 400
- decoded_response["description"].should =~ /file a support ticket to request additional resources/
- end
- end
+ let(:quota) { Models::QuotaDefinition.make(:memory_limit => 0) }
- context "free quota" do
+ context "quota" do
it "should enforce quota check on memory" do
- org = Models::Organization.make(:quota_definition => free_quota)
+ org = Models::Organization.make(:quota_definition => quota)
space = Models::Space.make(:organization => org)
req = Yajl::Encoder.encode(:name => Sham.name,
:space_guid => space.guid,
@@ -529,7 +508,7 @@ module VCAP::CloudController
post("/v2/apps", req, headers_for(make_developer_for_space(space)))
last_response.status.should == 400
- decoded_response["description"].should =~ /login to your account and upgrade/
+ decoded_response["description"].should =~ /exceeded your organization's memory limit/
end
end
end
View
6 spec/api/quota_definition_spec.rb
@@ -9,11 +9,9 @@ module VCAP::CloudController
:path => "/v2/quota_definitions",
:model => Models::QuotaDefinition,
:basic_attributes => [:name, :non_basic_services_allowed,
- :total_services, :free_memory_limit,
- :paid_memory_limit],
+ :total_services, :memory_limit],
:required_attributes => [:name, :non_basic_services_allowed,
- :total_services, :free_memory_limit,
- :paid_memory_limit],
+ :total_services, :memory_limit],
:unique_attributes => :name,
}
end
View
3 spec/blueprints.rb
@@ -162,7 +162,6 @@ module VCAP::CloudController::Models
name { Sham.name }
non_basic_services_allowed { true }
total_services { 60 }
- free_memory_limit { 20480 } # 10 GB
- paid_memory_limit { 20480 } # 20 GB
+ memory_limit { 20480 } # 20 GB
end
end
View
139 spec/models/app_spec.rb
@@ -590,113 +590,56 @@ def self.it_emits_app_start_and_stop_events(&block)
end
describe "quota" do
- let(:paid_quota) do
- Models::QuotaDefinition.make(:paid_memory_limit => 128)
- end
-
- let(:free_quota) do
- Models::QuotaDefinition.make(:free_memory_limit => 128)
- end
-
- context "paid quota" do
- context "app creation" do
- it "should raise error when quota is exceeded" do
- org = Models::Organization.make(:quota_definition => paid_quota)
- space = Models::Space.make(:organization => org)
- expect do
- Models::App.make(:space => space,
- :production => true,
- :memory => 65,
- :instances => 2)
- end.to raise_error(Sequel::ValidationFailed,
- /memory paid_quota_exceeded/)
- end
-
- it "should not raise error when quota is not exceeded" do
- org = Models::Organization.make(:quota_definition => paid_quota)
- space = Models::Space.make(:organization => org)
- expect do
- Models::App.make(:space => space,
- :production => true,
- :memory => 64,
- :instances => 2)
- end.to_not raise_error
- end
+ let(:quota) do
+ Models::QuotaDefinition.make(:memory_limit => 128)
+ end
+
+ context "app creation" do
+ it "should raise error when quota is exceeded" do
+ org = Models::Organization.make(:quota_definition => quota)
+ space = Models::Space.make(:organization => org)
+ expect do
+ Models::App.make(:space => space,
+ :memory => 65,
+ :instances => 2)
+ end.to raise_error(Sequel::ValidationFailed,
+ /memory quota_exceeded/)
end
- context "app update" do
- it "should raise error when quota is exceeded" do
- org = Models::Organization.make(:quota_definition => paid_quota)
- space = Models::Space.make(:organization => org)
- app = Models::App.make(:space => space,
- :production => true,
- :memory => 64,
- :instances => 2)
- app.memory = 65
- expect { app.save }.to raise_error(Sequel::ValidationFailed,
- /memory paid_quota_exceeded/)
- end
-
- it "should not raise error when quota is not exceeded" do
- org = Models::Organization.make(:quota_definition => paid_quota)
- space = Models::Space.make(:organization => org)
- app = Models::App.make(:space => space,
- :production => true,
- :memory => 63,
- :instances => 2)
- app.memory = 64
- expect { app.save }.to_not raise_error
- end
+ it "should not raise error when quota is not exceeded" do
+ org = Models::Organization.make(:quota_definition => quota)
+ space = Models::Space.make(:organization => org)
+ expect do
+ Models::App.make(:space => space,
+ :memory => 64,
+ :instances => 2)
+ end.to_not raise_error
end
end
- context "free quota" do
- context "app creation" do
- it "should raise error when quota is exceeded" do
- org = Models::Organization.make(:quota_definition => free_quota)
- space = Models::Space.make(:organization => org)
- expect do
- Models::App.make(:space => space,
- :memory => 65,
- :instances => 2)
- end.to raise_error(Sequel::ValidationFailed,
- /memory free_quota_exceeded/)
- end
-
- it "should not raise error when quota is not exceeded" do
- org = Models::Organization.make(:quota_definition => free_quota)
- space = Models::Space.make(:organization => org)
- expect do
- Models::App.make(:space => space,
- :memory => 64,
- :instances => 2)
- end.to_not raise_error
- end
+ context "app update" do
+ it "should raise error when quota is exceeded" do
+ org = Models::Organization.make(:quota_definition => quota)
+ space = Models::Space.make(:organization => org)
+ app = Models::App.make(:space => space,
+ :memory => 64,
+ :instances => 2)
+ app.memory = 65
+ expect { app.save }.to raise_error(Sequel::ValidationFailed,
+ /memory quota_exceeded/)
end
- context "app update" do
- it "should raise error when quota is exceeded" do
- org = Models::Organization.make(:quota_definition => free_quota)
- space = Models::Space.make(:organization => org)
- app = Models::App.make(:space => space,
- :memory => 64,
- :instances => 2)
- app.memory = 65
- expect { app.save }.to raise_error(Sequel::ValidationFailed,
- /memory free_quota_exceeded/)
- end
-
- it "should not raise error when quota is not exceeded" do
- org = Models::Organization.make(:quota_definition => free_quota)
- space = Models::Space.make(:organization => org)
- app = Models::App.make(:space => space,
- :memory => 63,
- :instances => 2)
- app.memory = 64
- expect { app.save }.to_not raise_error
- end
+ it "should not raise error when quota is not exceeded" do
+ org = Models::Organization.make(:quota_definition => quota)
+ space = Models::Space.make(:organization => org)
+ app = Models::App.make(:space => space,
+ :memory => 63,
+ :instances => 2)
+ app.memory = 64
+ expect { app.save }.to_not raise_error
end
end
+
end
describe "file_descriptors" do
View
13 spec/models/organization_spec.rb
@@ -157,31 +157,26 @@ module VCAP::CloudController
context "memory quota" do
let(:quota) do
- Models::QuotaDefinition.make(:free_memory_limit => 500,
- :paid_memory_limit => 500)
+ Models::QuotaDefinition.make(:memory_limit => 500)
end
it "should return the memory available when no apps are running" do
org = Models::Organization.make(:quota_definition => quota)
- org.free_memory_remaining.should == 500
- org.paid_memory_remaining.should == 500
+ org.memory_remaining.should == 500
end
it "should return the memory remaining when apps are consuming memory" do
org = Models::Organization.make(:quota_definition => quota)
space = Models::Space.make(:organization => org)
Models::App.make(:space => space,
- :production => false,
:memory => 200,
:instances => 2)
Models::App.make(:space => space,
- :production => true,
- :memory => 100,
+ :memory => 50,
:instances => 1)
- org.free_memory_remaining.should == 100
- org.paid_memory_remaining.should == 400
+ org.memory_remaining.should == 50
end
end
end
View
14 spec/models/quota_definition_spec.rb
@@ -6,8 +6,7 @@ module VCAP::CloudController
describe VCAP::CloudController::Models::QuotaDefinition do
it_behaves_like "a CloudController model", {
:required_attributes => [:name, :non_basic_services_allowed,
- :total_services, :free_memory_limit,
- :paid_memory_limit],
+ :total_services, :memory_limit],
:unique_attributes => [:name]
}
@@ -18,12 +17,11 @@ module VCAP::CloudController
# see config/cloud_controller.yml
Models::QuotaDefinition.populate_from_config(config)
- Models::QuotaDefinition.count.should == 3
- 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
+ Models::QuotaDefinition.count.should == 2
+ paid = Models::QuotaDefinition[:name => "paid"]
+ paid.non_basic_services_allowed.should == true
+ paid.total_services.should == 500
+ paid.memory_limit.should == 204800
end
end

0 comments on commit 5c07b49

Please sign in to comment.
Something went wrong with that request. Please try again.