Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
MySQL Gateway VARZ to advertise available, max, and used capacity [#4…
Browse files Browse the repository at this point in the history
…7406705]
  • Loading branch information
Georg Apitz and Ryan Tang committed May 2, 2013
1 parent b9ccdf8 commit 70a4608
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ng/mysql/config/mysql_gateway.yml
Expand Up @@ -4,7 +4,7 @@ service:
name: mysql
version: "5.1"
description: 'MySQL database'
plans: ['free']
plans: ['free','expensive']
default_plan: free
tags: ['relational']
ip_route: localhost
Expand Down Expand Up @@ -34,6 +34,14 @@ plan_management:
quota: 5
serialization: enable
job: enable
expensive:
low_water: 1
high_water: 20
lifecycle:
snapshot:
quota: 5
serialization: enable
job: enable
#allow_over_provisioning: false

# z_interval: 30
Expand Down
26 changes: 26 additions & 0 deletions ng/mysql/lib/mysql_service/provisioner.rb
Expand Up @@ -30,4 +30,30 @@ def import_from_url_job
VCAP::Services::Mysql::Serialization::ImportFromURLJob
end

def varz_details
varz = super

@plan_mgmt.each do |plan, v|
plan_nodes = @nodes.select { |_, node| node["plan"] == plan.to_s }.values
available_capacity, max_capacity, used_capacity = compute_availability(plan_nodes)
varz.fetch(:plans).each do |plan_detail|
if (plan_detail.fetch(:plan) == plan)
plan_detail.merge!({available_capacity: available_capacity})
plan_detail.merge!({max_capacity: max_capacity})
plan_detail.merge!({used_capacity: used_capacity})
end
end
end
varz
end

private

def compute_availability(plan_nodes)
max_capacity = plan_nodes.inject(0) { |sum, node| sum + node['max_capacity'] }
available_capacity = plan_nodes.inject(0) { |sum, node| sum + node['available_capacity'] }
used_capacity = max_capacity - available_capacity
return available_capacity, max_capacity, used_capacity
end

end
45 changes: 45 additions & 0 deletions ng/mysql/spec/mysql_provisioner_spec.rb
Expand Up @@ -64,4 +64,49 @@ def default_config_file
res.should == 5
end

describe "#varz_details" do
it 'returns everything super returns plus the max_capacity, used_capacity and available_capacity' do
EM.run do
msg1 = {
"id" => "node-1",
"plan" => "free",
"available_capacity" => 195,
"max_capacity" => 200,
"capacity_unit" => 1,
"supported_versions" => ["1.0"],
"time" => Time.now.to_i
}
msg2 = {
"id" => "node-2",
"plan" => "free",
"available_capacity" => 900,
"max_capacity" => 1000,
"capacity_unit" => 1,
"supported_versions" => ["1.0"],
"time" => Time.now.to_i
}
msg3 = {
"id" => "node-3",
"plan" => "expensive",
"available_capacity" => 2,
"max_capacity" => 20,
"capacity_unit" => 1,
"supported_versions" => ["1.0"],
"time" => Time.now.to_i
}
@provisioner.on_announce(Yajl::Encoder.encode(msg1))
@provisioner.on_announce(Yajl::Encoder.encode(msg2))
@provisioner.on_announce(Yajl::Encoder.encode(msg3))
EM.stop
end
varz_details = @provisioner.varz_details
varz_details[:plans][0].fetch(:max_capacity).should == 1200
varz_details[:plans][0].fetch(:used_capacity).should == 105
varz_details[:plans][0].fetch(:available_capacity).should == 1095
varz_details[:plans][1].fetch(:max_capacity).should == 20
varz_details[:plans][1].fetch(:used_capacity).should == 18
varz_details[:plans][1].fetch(:available_capacity).should == 2
end
end

end

0 comments on commit 70a4608

Please sign in to comment.