Permalink
Browse files

Marketplace Updates - 2

 - Reverse map to marketplace service id when provisioning service
 - Make whitelist / service mapping optional
 - Reuse fields from proxied services listing when deactivating service

Change-Id: I195ad2c41ca646fb33a0657b8892c7f883b91c8b
  • Loading branch information...
1 parent 2a30f3d commit 9c33fc5b99a26ce3c7a635439b81a98567893c4f Harshawardhan Gadgil committed Sep 7, 2012
View
25 marketplace/lib/base/marketplace_async_gateway.rb
@@ -43,7 +43,8 @@ def setup(opts)
@host = opts[:host]
@port = opts[:port]
- @router_register_uri = (URI.parse(opts[:external_uri])).host
+ @external_uri = opts[:external_uri]
+ @router_register_uri = (URI.parse(@external_uri)).host
@node_timeout = opts[:node_timeout]
@logger = opts[:logger] || make_logger()
@token = opts[:token]
@@ -139,17 +140,19 @@ def refresh_catalog
def deactivate_disabled_services
disabled_count = 0
+
+ current_offerings = []
+ @catalog_in_marketplace.each { |k, v|
+ current_offerings << v["id"]
+ }
+
@catalog_in_ccdb.each do |label, svc|
- if (!@catalog_in_marketplace.keys.include?(label))
- service_name, version = label.split(/-/)
- svc["version"] = version
- req = {
- :label => svc["label"],
- :active => false,
- :url => @external_uri,
- :supported_versions => [ version ],
- :version_aliases => { "current" => version },
- }
+ service_name, version = label.split(/-/)
+
+ if (@marketplace_client.offering_disabled?(service_name, current_offerings))
+ req = svc.dup
+ req[:active] = false
+
@logger.warn("#{@marketplace_client.name} service offering: #{label} not found in latest offering. Deactivating...")
advertise_service_to_cc(req)
View
4 marketplace/lib/base/marketplace_base.rb
@@ -19,6 +19,10 @@ def generate_cc_advertise_request(name, bsvc, active = true)
{}
end
+ def offering_disabled?(name, offerings)
+ false
+ end
+
def provision_service(request_body)
end
View
2 marketplace/lib/marketplaces/appdirect/appdirect_helper.rb
@@ -46,7 +46,7 @@ def get_catalog
data.each do |service|
# Add checks for specific categories which determine whether the addon should be listed on cc
@logger.debug("Got service '#{service["id"]}' from AppDirect")
- if (@whitelist.include?(service["id"]))
+ if (@whitelist.nil? || @whitelist.include?(service["id"]))
catalog["#{service["id"]}-#{service["version"]}"] = service
else
@logger.warn("Ignoring service Offering: #{service["id"]} since it is not whitelisted")
View
35 marketplace/lib/marketplaces/appdirect/appdirect_marketplace.rb
@@ -22,7 +22,15 @@ def initialize(opts)
@node_timeout = opts[:node_timeout]
@acls = opts[:acls]
@helper = AppdirectHelper.new(opts, @logger)
- @mapping = opts[:offering_mapping]
+ @mapping = opts[:offering_mapping] || []
+
+ # Maintain a reverse mapping since we'll be changing the service name for CC advertisement
+ # A provision request will require the actual service name rather than the one in CCDB
+ @service_id_map = {}
+ @mapping.keys.each { |k|
+ service_name = @mapping[k.to_sym][:name]
+ @service_id_map[service_name] = k.to_s
+ }
end
def name
@@ -34,11 +42,15 @@ def get_catalog
end
def generate_cc_advertise_request(name, bsvc, active = true)
- raise "Service: #{name} was whitelisted but no mapping was defined" unless @mapping.keys.include?(name.to_sym)
- service_mapping = @mapping[name.to_sym]
- name = service_mapping[:name]
- provider = service_mapping[:provider]
+ if (@mapping.keys.include?(name.to_sym))
+ service_mapping = @mapping[name.to_sym]
+ name = service_mapping[:name]
+ provider = service_mapping[:provider]
+ else
+ # We'll use the service name as provider unless appdirect sends otherwise
+ provider = bsvc["provider"] || name
+ end
req = {}
req[:label] = "#{name}-#{bsvc["version"]}"
@@ -78,11 +90,20 @@ def generate_cc_advertise_request(name, bsvc, active = true)
req
end
+ def offering_disabled?(id, offerings_list)
+ # Translate service name if a custom mapping was defined
+ id = @service_id_map[id] if @service_id_map.keys.include?(id)
+
+ # Check if its still listed
+ @logger.info("Offering: #{id} - Present in offering list: #{offerings_list.include?(id)}")
+ !(offerings_list.include?(id))
+ end
+
def provision_service(request_body)
request = VCAP::Services::Api::GatewayProvisionRequest.decode(request_body)
- @logger.info("Provision request for label=#{request.label} plan=#{request.plan}, version=#{request.version}")
-
id,version = request.label.split("-")
+ id = @service_id_map[id] if @service_id_map.keys.include?(id)
+ @logger.debug("Provision request for label=#{request.label} (id=#{id}) plan=#{request.plan}, version=#{request.version}")
order = {
"user" => {

0 comments on commit 9c33fc5

Please sign in to comment.