Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Store Service#unique_id and send it on service provision

unique_id has a default value of "#{provider}_#{label}"

[Finishes #46953645]
  • Loading branch information...
commit fad6072c4d2774ae2bacf61fe491230228f1cc63 1 parent c4fae4f
David Stevenson and Matt Royal authored
View
2  Gemfile
@@ -11,7 +11,7 @@ gem "sinatra-contrib"
gem "yajl-ruby"
gem 'vcap-concurrency', :git => 'https://github.com/cloudfoundry/vcap-concurrency.git', :ref => '2a5b0179'
gem "membrane", "~> 0.0.2"
-gem "vcap_common", "~> 2.0.8", :git => 'https://github.com/cloudfoundry/vcap-common.git', :ref => '2e755172'
+gem "vcap_common", "~> 2.0.8", :git => 'https://github.com/cloudfoundry/vcap-common.git'
gem "cf-uaa-lib", "~> 1.3.7", :git => 'https://github.com/cloudfoundry/cf-uaa-lib.git', :ref => '8d34eede'
gem "httpclient"
gem "steno", "~> 1.0.0"
View
21 Gemfile.lock
@@ -18,8 +18,7 @@ GIT
GIT
remote: https://github.com/cloudfoundry/vcap-common.git
- revision: 2e755172e0cb76b82fedb77e16e33d71dcde140a
- ref: 2e755172
+ revision: 9ac7e259689a14c6033454cd91db8e1a44c0d0ee
specs:
vcap_common (2.0.10)
em-http-request (~> 1.0.0.beta3, < 1.0.0.beta4)
@@ -46,14 +45,14 @@ GEM
activesupport (3.2.8)
i18n (~> 0.6)
multi_json (~> 1.0)
- addressable (2.3.2)
+ addressable (2.3.3)
backports (2.6.1)
bcrypt-ruby (3.0.1)
builder (3.0.0)
ci_reporter (1.7.0)
builder (>= 2.1.2)
crack (0.3.1)
- daemons (1.1.8)
+ daemons (1.1.9)
diff-lcs (1.1.3)
em-http-request (1.0.0.beta.3)
addressable (>= 2.2.3)
@@ -62,7 +61,7 @@ GEM
http_parser.rb (>= 0.5.1)
em-socksify (0.2.1)
eventmachine (>= 1.0.0.beta.4)
- eventmachine (1.0.0)
+ eventmachine (1.0.3)
excon (0.16.10)
fog (1.9.0)
builder
@@ -93,27 +92,27 @@ GEM
http_parser.rb (0.5.3)
httpclient (2.3.3)
i18n (0.6.1)
- json_pure (1.7.4)
+ json_pure (1.7.7)
listen (0.5.3)
machinist (1.0.6)
membrane (0.0.2)
- mime-types (1.19)
+ mime-types (1.21)
multi_json (1.3.6)
multi_xml (0.5.1)
multipart-post (1.2.0)
mysql2 (0.3.11)
- nats (0.4.24)
+ nats (0.4.26)
daemons (>= 1.1.5)
eventmachine (>= 0.12.10)
json_pure (>= 1.7.3)
- thin (>= 1.3.1)
+ thin (>= 1.4.1)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-ssh (2.6.3)
nokogiri (1.5.6)
pg (0.13.2)
posix-spawn (0.3.6)
- rack (1.4.1)
+ rack (1.5.2)
rack-accept (0.4.5)
rack (>= 0.4)
rack-mount (0.8.3)
@@ -156,7 +155,7 @@ GEM
steno (1.0.0)
grape
yajl-ruby (~> 1.0)
- thin (1.3.1)
+ thin (1.5.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
View
20 db/migrations/20130328225143_add_unique_id_to_services.rb
@@ -0,0 +1,20 @@
+# Copyright (c) 2009-2012 VMware, Inc.
+
+Sequel.migration do
+ change do
+ alter_table :services do
+ add_column :unique_id, String
+ add_index :unique_id, unique: true
+ end
+
+ if self.class.name.match /mysql/i
+ run "UPDATE services SET unique_id=CONCAT(provider, '_', label)"
+ else
+ run "UPDATE services SET unique_id=(provider || '_' || label)"
+ end
+
+ alter_table :services do
+ set_column_allow_null :unique_id, false
+ end
+ end
+end
View
2  lib/cloud_controller/legacy_api/legacy_service_gateway.rb
@@ -31,7 +31,7 @@ def create_offering
VCAP::CloudController::SecurityContext.set(self.class.legacy_api_user)
Sequel::Model.db.transaction do
service = Models::Service.update_or_create(
- :label => label, :provider => DEFAULT_PROVIDER
+ :label => label, :provider => provider
) do |svc|
if svc.new?
logger.debug2("Creating service")
View
3  lib/cloud_controller/models/service.rb
@@ -10,7 +10,7 @@ class Service < Sequel::Model
default_order_by :label
export_attributes :label, :provider, :url, :description,
- :version, :info_url, :active, :extra
+ :version, :info_url, :active, :extra, :unique_id
import_attributes :label, :provider, :url, :description,
:version, :info_url, :active
@@ -18,6 +18,7 @@ class Service < Sequel::Model
strip_attributes :label, :provider
def validate
+ self.unique_id ||= "#{provider}_#{label}"
validates_presence :label
validates_presence :provider
validates_presence :url
View
28 lib/cloud_controller/models/service_instance.rb
@@ -127,10 +127,10 @@ def as_summary_json
:guid => service_plan.guid,
:name => service_plan.name,
:service => {
- :guid => service_plan.service.guid,
- :label => service_plan.service.label,
- :provider => service_plan.service.provider,
- :version => service_plan.service.version,
+ :guid => service.guid,
+ :label => service.label,
+ :provider => service.provider,
+ :version => service.version,
}
}
}
@@ -208,21 +208,27 @@ def service_gateway_client(plan = service_plan)
end
end
+ def service
+ service_plan.service
+ end
+
+
def provision_on_gateway
service_gateway_client
logger.debug "provisioning service for instance #{guid}"
gw_attrs = client.provision(
# TODO: we shouldn't still be using this compound label
- :label => "#{service_plan.service.label}-#{service_plan.service.version}",
+ :label => "#{service.label}-#{service.version}",
:name => name,
:email => VCAP::CloudController::SecurityContext.current_user_email,
:plan => service_plan.name,
:plan_option => {}, # TODO: remove this
- :version => service_plan.service.version,
- :provider => service_plan.service.provider,
+ :version => service.version,
+ :provider => service.provider,
:space_guid => space.guid,
- :organization_guid => space.organization_guid
+ :organization_guid => space.organization_guid,
+ :unique_id => service.unique_id,
)
logger.debug "provision response for instance #{guid} #{gw_attrs.inspect}"
@@ -245,11 +251,11 @@ def deprovision_on_gateway
end
def create_snapshot(name)
- NGServiceGatewayClient.new(service_plan.service, gateway_name).create_snapshot(name)
+ NGServiceGatewayClient.new(service, gateway_name).create_snapshot(name)
end
def enum_snapshots
- NGServiceGatewayClient.new(service_plan.service, gateway_name).enum_snapshots
+ NGServiceGatewayClient.new(service, gateway_name).enum_snapshots
end
def snapshot_details(sid)
@@ -290,7 +296,7 @@ def import_from_data(opts)
sds_client = sds_client(upload_url, upload_token, upload_timeout)
sds_client.import_from_data(
- :service => service_plan.service.label,
+ :service => service.label,
:service_id => gateway_name,
:msg => file_path,
)
View
6 spec/api/legacy_service_gateway_spec.rb
@@ -84,12 +84,13 @@ def build_offering(attrs={})
last_response.status.should == 400
end
- it "should create service offerings for builtin services" do
+ it "should create service offerings for label/provider services and generate a unique_id" do
post path, build_offering.encode, auth_header
last_response.status.should == 200
svc = Models::Service.find(:label => "foobar", :provider => "core")
svc.should_not be_nil
svc.version.should == "2.0"
+ svc.unique_id.should == "core_foobar"
end
it "should create services with 'extra' data" do
@@ -239,8 +240,7 @@ def create_service_instance_using_plan(plan_name)
end
end
-
- it "should update service offerings for builtin services" do
+ it "should update service offerings for label/provider services" do
post path, build_offering.encode, auth_header
offer = build_offering
offer.url = "http://newurl.com"
View
2  spec/api/service_spec.rb
@@ -8,7 +8,7 @@ module VCAP::CloudController
it_behaves_like "a CloudController API", {
:path => "/v2/services",
:model => Models::Service,
- :basic_attributes => [:label, :provider, :url, :description, :version, :info_url, :extra],
+ :basic_attributes => [:label, :provider, :url, :description, :version, :info_url, :extra, :unique_id],
:required_attributes => [:label, :provider, :url, :description, :version],
:unique_attributes => [:label, :provider],
:one_to_many_collection_ids => {
View
1  spec/models/helpers/unique_attributes.rb
@@ -111,6 +111,7 @@ module VCAP::CloudController::ModelSpecHelper
expect {
described_class.new do |instance|
instance.set_all(dup_opts)
+ instance.valid? # run validations but ignore results
end.save(:validate => false)
}.to raise_error Sequel::DatabaseError, /#{db_exception_match}/
end
View
1  spec/models/service_instance_spec.rb
@@ -172,6 +172,7 @@ module VCAP::CloudController
:plan_option => {}, # TODO: remove this
:provider => service_instance.service_plan.service.provider,
:version => service_instance.service_plan.service.version,
+ :unique_id => service_instance.service_plan.service.unique_id,
:space_guid => service_instance.space.guid,
:organization_guid => service_instance.space.organization_guid
)
View
18 spec/models/service_spec.rb
@@ -29,5 +29,23 @@ module VCAP::CloudController
}
end
end
+
+ describe "validation" do
+ context "when unique_id is not provided" do
+ it "creates a composite unique_id" do
+ service = Models::Service.new(provider: "core", label: "ponies")
+ service.valid?
+ service.unique_id.should == "core_ponies"
+ end
+ end
+
+ context "when unique_id is provided" do
+ it "uses provided unique_id" do
+ service = Models::Service.new(provider: "core", label: "ponies", unique_id: "glue-factory")
+ service.valid?
+ service.unique_id.should == "glue-factory"
+ end
+ end
+ end
end
end
View
1  spec/support/fakes/blueprints.rb
@@ -75,6 +75,7 @@ module VCAP::CloudController::Models
provider { Sham.provider }
url { Sham.url }
version { Sham.version }
+ unique_id { "#{provider}_#{label}" }
description do
# Hack since Sequel does not allow two foreign keys natively
# and putting this side effect outside memoizes the label and provider
Please sign in to comment.
Something went wrong with that request. Please try again.