Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

account for stack when selecting dea to run an app

  • Loading branch information...
commit 475d2f8988b6a902b2131d6ec1ebb8661b9ca01f 1 parent 6591288
Bob Nugmanov and Dmitriy Kalinin authored
2  lib/cloud_controller/dea/dea_client.rb
View
@@ -225,7 +225,7 @@ def start_instances_with_message(app, indices, message_override)
indices.each do |idx|
msg[:index] = idx
- dea_id = dea_pool.find_dea(app.memory, app.runtime.name)
+ dea_id = dea_pool.find_dea(app.memory, app.runtime.name, app.stack.name)
if dea_id
dea_publish("#{dea_id}.start", msg.merge(message_override))
else
12 lib/cloud_controller/dea/dea_pool.rb
View
@@ -29,13 +29,13 @@ def process_advertise_message(msg)
end
end
- def find_dea(mem, runtime)
+ def find_dea(mem, runtime, stack)
mutex.synchronize do
@deas.keys.shuffle.each do |id|
dea = @deas[id]
if dea_expired?(dea)
@deas.delete(id)
- elsif dea_meets_needs?(dea, mem, runtime)
+ elsif dea_meets_needs?(dea, mem, runtime, stack)
return id
end
end
@@ -49,10 +49,14 @@ def dea_expired?(dea)
(Time.now.to_i - dea[:last_update].to_i) > ADVERTISEMENT_EXPIRATION
end
- def dea_meets_needs?(dea, mem, runtime)
+ def dea_meets_needs?(dea, mem, runtime, stack)
stats = dea[:advertisement]
+
+ has_runtime = stats[:runtimes].nil? || stats[:runtimes].include?(runtime)
+ has_stack = stats[:stacks].include?(stack)
+
if stats[:available_memory] >= mem
- (stats[:runtimes].nil? || stats[:runtimes].member?(runtime))
+ has_runtime && has_stack
else
false
end
6 spec/dea/dea_client_spec.rb
View
@@ -13,8 +13,10 @@ module VCAP::CloudController
NUM_SVC_INSTANCES.times do
instance = Models::ServiceInstance.make(:space => @app.space)
- binding = Models::ServiceBinding.make(:app => @app,
- :service_instance => instance)
+ binding = Models::ServiceBinding.make(
+ :app => @app,
+ :service_instance => instance
+ )
@app.add_service_binding(binding)
end
end
44 spec/dea/dea_pool_spec.rb
View
@@ -12,6 +12,7 @@ module VCAP::CloudController
let(:dea_advertise_msg) do
{
:id => "dea-id",
+ :stacks => ["stack"],
:available_memory => 1024,
:runtimes => ["ruby18", "java"],
}
@@ -24,7 +25,7 @@ module VCAP::CloudController
mock_nats.publish("dea.advertise", JSON.dump(dea_advertise_msg))
end
end
- subject.find_dea(0, "ruby18").should == "dea-id"
+ subject.find_dea(0, "ruby18", "stack").should == "dea-id"
end
end
@@ -33,6 +34,7 @@ module VCAP::CloudController
let(:dea_advertise_msg) do
{
:id => "dea-id",
+ :stacks => ["stack"],
:available_memory => 1024,
:runtimes => ["ruby18"],
}
@@ -41,7 +43,7 @@ module VCAP::CloudController
it "only finds registered deas" do
expect {
subject.process_advertise_message(dea_advertise_msg)
- }.to change { subject.find_dea(0, "ruby18") }.from(nil).to("dea-id")
+ }.to change { subject.find_dea(0, "ruby18", "stack") }.from(nil).to("dea-id")
end
end
@@ -49,6 +51,7 @@ module VCAP::CloudController
let(:dea_advertise_msg) do
{
:id => "dea-id",
+ :stacks => ["stack"],
:available_memory => 1024,
:runtimes => ["ruby18"],
}
@@ -59,10 +62,10 @@ module VCAP::CloudController
subject.process_advertise_message(dea_advertise_msg)
Timecop.travel(10)
- subject.find_dea(1024, "ruby18").should == "dea-id"
+ subject.find_dea(1024, "ruby18", "stack").should == "dea-id"
Timecop.travel(1)
- subject.find_dea(1024, "ruby18").should be_nil
+ subject.find_dea(1024, "ruby18", "stack").should be_nil
end
end
end
@@ -71,6 +74,7 @@ module VCAP::CloudController
let(:dea_advertise_msg) do
{
:id => "dea-id",
+ :stacks => ["stack"],
:available_memory => 1024,
:runtimes => ["ruby18"],
}
@@ -78,8 +82,8 @@ module VCAP::CloudController
it "only finds deas that can satisfy memory request" do
subject.process_advertise_message(dea_advertise_msg)
- subject.find_dea(1025, "ruby18").should be_nil
- subject.find_dea(1024, "ruby18").should == "dea-id"
+ subject.find_dea(1025, "ruby18", "stack").should be_nil
+ subject.find_dea(1024, "ruby18", "stack").should == "dea-id"
end
end
@@ -87,6 +91,7 @@ module VCAP::CloudController
let(:dea_advertise_msg) do
{
:id => "dea-id",
+ :stacks => ["stack"],
:available_memory => 1024,
:runtimes => ["ruby18"],
}
@@ -94,8 +99,8 @@ module VCAP::CloudController
it "only finds deas that can satisfy runtime request" do
subject.process_advertise_message(dea_advertise_msg)
- subject.find_dea(0, "ruby19").should be_nil
- subject.find_dea(0, "ruby18").should == "dea-id"
+ subject.find_dea(0, "ruby19", "stack").should be_nil
+ subject.find_dea(0, "ruby18", "stack").should == "dea-id"
end
end
@@ -103,6 +108,7 @@ module VCAP::CloudController
let(:dea_with_runtimes) do
{
:id => "dea-with-runtimes-id",
+ :stacks => ["stack"],
:available_memory => 1024,
:runtimes => ["ruby18"],
}
@@ -111,6 +117,7 @@ module VCAP::CloudController
let(:dea_without_runtimes) do
{
:id => "dea-without-runtimes-id",
+ :stacks => ["stack"],
:available_memory => 1024,
:runtimes => nil,
}
@@ -118,10 +125,27 @@ module VCAP::CloudController
it "only finds deas that do not have runtimes specified" do
subject.process_advertise_message(dea_with_runtimes)
- subject.find_dea(0, "some-runtime").should be_nil
+ subject.find_dea(0, "some-runtime", "stack").should be_nil
subject.process_advertise_message(dea_without_runtimes)
- subject.find_dea(0, "some-runtime").should == "dea-without-runtimes-id"
+ subject.find_dea(0, "some-runtime", "stack").should == "dea-without-runtimes-id"
+ end
+ end
+
+ describe "stacks availability" do
+ let(:dea_advertise_msg) do
+ {
+ :id => "dea-id",
+ :available_memory => 1024,
+ :stacks => ["known-stack"],
+ :runtimes => ["ruby18"],
+ }
+ end
+
+ it "only finds deas that can satisfy stack request" do
+ subject.process_advertise_message(dea_advertise_msg)
+ subject.find_dea(0, "ruby18", "unknown-stack").should be_nil
+ subject.find_dea(0, "ruby18", "known-stack").should == "dea-id"
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.