forked from cloudfoundry-attic/vcap-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add classes to create Mongo, Redis, AMQP, Carrot, MySQL, and Postgresql connections to CF services - Fix auto-reconfig log messages if 0 or more than one services of a type are found - Add cfruntime rdoc - Move supported version constants to AutoReconfiguration module - Remove complex passing of URL argument during AMQP auto-config - Null path option during Redis auto-config Change-Id: Iccab8a424dbb6e73b94feb6057859e17020005c5
- Loading branch information
Jennifer Hickey
committed
Dec 16, 2011
1 parent
25777a8
commit af46612
Showing
37 changed files
with
1,042 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
# Copyright (c) 2009-2011 VMware, Inc. | ||
require 'cfautoconfig/configurer' | ||
require 'cfautoconfig/version' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,24 @@ | ||
require 'cfruntime/properties' | ||
require 'cfruntime/redis' | ||
|
||
module AutoReconfiguration | ||
module Redis | ||
def self.included( base ) | ||
base.send( :alias_method, :original_initialize, :initialize) | ||
base.send( :alias_method, :initialize, :initialize_with_cf ) | ||
end | ||
SUPPORTED_REDIS_VERSION = '2.0' | ||
module Redis | ||
def self.included( base ) | ||
base.send( :alias_method, :original_initialize, :initialize) | ||
base.send( :alias_method, :initialize, :initialize_with_cf ) | ||
end | ||
|
||
def initialize_with_cf(options = {}) | ||
service_props = CFRuntime::CloudApp.service_props('redis') | ||
if(service_props.nil?) | ||
puts "No Redis service bound to app. Skipping auto-reconfiguration." | ||
original_initialize options | ||
else | ||
puts "Auto-reconfiguring Redis." | ||
cfoptions = options | ||
if !cfoptions[:path].nil? | ||
#Host and port are ignored if a path is specified | ||
cfoptions[:path] = "#{service_props[:host]}:#{service_props[:port]}" | ||
end | ||
cfoptions[:host] = service_props[:host] | ||
cfoptions[:port] = service_props[:port] | ||
cfoptions[:password] = service_props[:password] | ||
original_initialize cfoptions | ||
end | ||
end | ||
end | ||
def initialize_with_cf(options = {}) | ||
service_names = CFRuntime::CloudApp.service_names_of_type('redis') | ||
if service_names.length == 1 | ||
puts "Auto-reconfiguring Redis." | ||
cfoptions = CFRuntime::RedisClient.options_for_svc(service_names[0],options) | ||
original_initialize cfoptions | ||
else | ||
puts "Found #{service_names.length} redis services. Skipping auto-reconfiguration." | ||
original_initialize options | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,30 @@ | ||
require 'cfruntime/properties' | ||
require 'cfruntime/amqp' | ||
|
||
module AutoReconfiguration | ||
module AMQP | ||
def self.included( base ) | ||
base.send( :alias_method, :original_connect, :connect) | ||
base.send( :alias_method, :connect, :connect_with_cf ) | ||
end | ||
SUPPORTED_AMQP_VERSION = '0.8' | ||
module AMQP | ||
def self.included( base ) | ||
base.send( :alias_method, :original_connect, :connect) | ||
base.send( :alias_method, :connect, :connect_with_cf ) | ||
end | ||
|
||
def connect_with_cf(connection_options_or_string = {}, other_options = {}, &block) | ||
service_props = CFRuntime::CloudApp.service_props('rabbitmq') | ||
if(service_props.nil?) | ||
puts "No RabbitMQ service bound to app. Skipping auto-reconfiguration." | ||
original_connect(connection_options_or_string, other_options, &block) | ||
else | ||
puts "Auto-reconfiguring AMQP." | ||
url_provided = false | ||
case connection_options_or_string | ||
when String then | ||
url_provided = true | ||
cfoptions = {} | ||
else | ||
cfoptions = connection_options_or_string | ||
end | ||
if service_props[:url] && url_provided | ||
#If user passed in a URL and we have a URL for service, use it | ||
original_connect(service_props[:url], other_options, &block) | ||
else | ||
cfoptions[:host] = service_props[:host] | ||
cfoptions[:port] = service_props[:port] | ||
cfoptions[:user] = service_props[:username] | ||
cfoptions[:pass] = service_props[:password] | ||
cfoptions[:vhost] = service_props[:vhost] | ||
original_connect(cfoptions, other_options, &block) | ||
end | ||
end | ||
end | ||
end | ||
def connect_with_cf(connection_options_or_string = {}, other_options = {}, &block) | ||
service_names = CFRuntime::CloudApp.service_names_of_type('rabbitmq') | ||
if service_names.length == 1 | ||
puts "Auto-reconfiguring AMQP." | ||
case connection_options_or_string | ||
when String then | ||
cfoptions = {} | ||
else | ||
cfoptions = connection_options_or_string | ||
end | ||
original_connect(CFRuntime::AMQPClient.options_for_svc(service_names[0],cfoptions), | ||
other_options, &block) | ||
else | ||
puts "Found #{service_names.length} rabbitmq services. Skipping auto-reconfiguration." | ||
original_connect(connection_options_or_string, other_options, &block) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 19 additions & 22 deletions
41
auto-reconfiguration/lib/cfautoconfig/messaging/carrot.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,24 @@ | ||
require 'cfruntime/properties' | ||
require 'cfruntime/carrot' | ||
|
||
module AutoReconfiguration | ||
module Carrot | ||
def self.included( base ) | ||
base.send( :alias_method, :original_initialize, :initialize) | ||
base.send( :alias_method, :initialize, :initialize_with_cf ) | ||
end | ||
SUPPORTED_CARROT_VERSION = '1.0' | ||
module Carrot | ||
def self.included( base ) | ||
base.send( :alias_method, :original_initialize, :initialize) | ||
base.send( :alias_method, :initialize, :initialize_with_cf ) | ||
end | ||
|
||
def initialize_with_cf(opts = {}) | ||
service_props = CFRuntime::CloudApp.service_props('rabbitmq') | ||
if(service_props.nil?) | ||
puts "No RabbitMQ service bound to app. Skipping auto-reconfiguration." | ||
original_initialize opts | ||
else | ||
puts "Auto-reconfiguring Carrot." | ||
cfoptions = opts | ||
cfoptions[:host] = service_props[:host] | ||
cfoptions[:port] = service_props[:port] | ||
cfoptions[:user] = service_props[:username] | ||
cfoptions[:pass] = service_props[:password] | ||
cfoptions[:vhost] = service_props[:vhost] | ||
original_initialize opts | ||
end | ||
end | ||
end | ||
def initialize_with_cf(opts = {}) | ||
service_names = CFRuntime::CloudApp.service_names_of_type('rabbitmq') | ||
if service_names.length == 1 | ||
puts "Auto-reconfiguring Carrot." | ||
cfopts = CFRuntime::CarrotClient.options_for_svc(service_names[0],opts) | ||
original_initialize cfopts | ||
else | ||
puts "Found #{service_names.length} rabbitmq services. Skipping auto-reconfiguration." | ||
original_initialize opts | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.