Skip to content
Browse files

Merge "add domains to app summary json"

  • Loading branch information...
2 parents 9e9ba76 + f6aa4ca commit 7f51a66febdd2999c9bc5e5842a0853e6d3d3960 Dennis Schmidt & Roberto Ostinelli committed with Gerrit Code Review Jan 16, 2013
View
3 lib/cloud_controller/api/app_summary.rb
@@ -25,7 +25,8 @@ def summary(id)
:running_instances => app.running_instances,
:services => app.service_instances.map do |instance|
service_instance_summary(instance)
- end
+ end,
+ :available_domains => app.space.domains.map(&:as_summary_json)
}.merge(app.to_hash)
Yajl::Encoder.encode(app_info)
View
8 lib/cloud_controller/models/domain.rb
@@ -87,6 +87,14 @@ def overlaps_domain_in_other_org?
overlapping_domains.count != 0
end
+ def as_summary_json
+ {
+ :guid => guid,
+ :name => name,
+ :owning_organization_guid => (owning_organization ? owning_organization.guid : nil)
+ }
+ end
+
def intermediate_domains
self.class.intermediate_domains(name)
end
View
9 lib/cloud_controller/models/route.rb
@@ -22,7 +22,14 @@ def fqdn
end
def as_summary_json
- { "guid" => guid, "host" => host, "domain" => { "name" => domain.name }}
+ {
+ :guid => guid,
+ :host => host,
+ :domain => {
+ :guid => domain.guid,
+ :name => domain.name
+ }
+ }
end
def organization
View
32 spec/api/app_summary_spec.rb
@@ -13,6 +13,10 @@ module VCAP::CloudController
end
before :all do
+ @system_domain = Models::Domain.new(:name => Sham.domain,
+ :owning_organization => nil)
+ @system_domain.save(:validate => false)
+
@space = Models::Space.make
@route1 = Models::Route.make(:space => @space)
@route2 = Models::Route.make(:space => @space)
@@ -36,6 +40,10 @@ module VCAP::CloudController
@app.add_route(@route2)
end
+ after(:all) do
+ @system_domain.destroy
+ end
+
describe "GET /v2/apps/:id/summary" do
before do
HealthManagerClient.should_receive(:healthy_instances).
@@ -56,7 +64,20 @@ module VCAP::CloudController
end
it "should return the app routes" do
- decoded_response["routes"].should == [ @route1.as_summary_json, @route2.as_summary_json ]
+ decoded_response["routes"].should == [{
+ "guid" => @route1.guid,
+ "host" => nil,
+ "domain" => {
+ "guid" => @route1.domain.guid,
+ "name" => @route1.domain.name
+ }
+ }, {
+ "guid" => @route2.guid,
+ "host" => nil,
+ "domain" => {
+ "guid" => @route2.domain.guid,
+ "name" => @route2.domain.name}
+ }]
end
it "should return the app framework" do
@@ -79,6 +100,15 @@ module VCAP::CloudController
end
end
+ it "should contain list of available domains" do
+ _, domain1, domain2 = @app.space.domains
+ decoded_response["available_domains"].should =~ [
+ {"guid" => domain1.guid, "name" => domain1.name, "owning_organization_guid" => domain1.owning_organization.guid},
+ {"guid" => domain2.guid, "name" => domain2.name, "owning_organization_guid" => domain2.owning_organization.guid},
+ {"guid" => @system_domain.guid, "name" => @system_domain.name, "owning_organization_guid" => nil}
+ ]
+ end
+
it "should return num_services services" do
decoded_response["services"].size.should == num_services
end
View
15 spec/api/space_summary_spec.rb
@@ -91,7 +91,20 @@ module VCAP::CloudController
"guid" => app.guid,
"name" => app.name,
"urls" => [@route1.fqdn, @route2.fqdn],
- "routes" => [@route1.as_summary_json, @route2.as_summary_json],
+ "routes" => [{
+ "guid" => @route1.guid,
+ "host" => nil,
+ "domain" => {
+ "guid" => @route1.domain.guid,
+ "name" => @route1.domain.name
+ }
+ }, {
+ "guid" => @route2.guid,
+ "host" => nil,
+ "domain" => {
+ "guid" => @route2.domain.guid,
+ "name" => @route2.domain.name}
+ }],
"service_count" => num_services,
"instances" => app.instances,
"running_instances" => expected_running_instances,
View
27 spec/models/domain_spec.rb
@@ -40,6 +40,33 @@ module VCAP::CloudController
}
}
+ describe "#as_summary_json" do
+ context "with a system domain" do
+ subject { Models::Domain.new(:name => Sham.domain, :owning_organization => nil) }
+
+ it "returns a hash containing the domain details" do
+ subject.as_summary_json.should == {
+ :guid => subject.guid,
+ :name => subject.name,
+ :owning_organization_guid => nil
+ }
+ end
+ end
+
+ context "with a custom domain" do
+ let(:organization) { Models::Organization.make }
+ subject { Models::Domain.new(:name => Sham.domain, :owning_organization => organization) }
+
+ it "returns a hash containing the domain details" do
+ subject.as_summary_json.should == {
+ :guid => subject.guid,
+ :name => subject.name,
+ :owning_organization_guid => subject.owning_organization.guid
+ }
+ end
+ end
+ end
+
describe "#intermidiate_domains" do
context "name is nil" do
it "should return nil" do
View
11 spec/models/route_spec.rb
@@ -171,13 +171,20 @@ module VCAP::CloudController
end
describe "#as_summary_json" do
- it "returns a hash containing the route id, host, and domain name" do
+ it "returns a hash containing the route id, host, and domain details" do
r = Models::Route.make(
:host => "www",
:domain => domain,
:space => space,
)
- r.as_summary_json.should == { "guid" => r.guid, "host" => r.host, "domain" => { "name" => r.domain.name } }
+ r.as_summary_json.should == {
+ :guid => r.guid,
+ :host => r.host,
+ :domain => {
+ :guid => r.domain.guid,
+ :name => r.domain.name
+ }
+ }
end
end
end

0 comments on commit 7f51a66

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