Class: CloudfoundryBlueGreenDeploy::BlueGreenDeployConfig
- Inherits:
-
Object
- Object
- CloudfoundryBlueGreenDeploy::BlueGreenDeployConfig
- Defined in:
- lib/cloudfoundry_blue_green_deploy/blue_green_deploy_config.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#hot_url ⇒ Object
readonly
Returns the value of attribute hot_url.
-
#target_color ⇒ Object
Returns the value of attribute target_color.
-
#with_shutter ⇒ Object
readonly
Returns the value of attribute with_shutter.
-
#worker_app_names ⇒ Object
readonly
Returns the value of attribute worker_app_names.
Class Method Summary collapse
- .all_app_names(web_app_name, worker_app_names) ⇒ Object
- .colorize_name(app_name, color) ⇒ Object
- .get_color_stem(app_name) ⇒ Object
- .strip_color(app_name_with_color) ⇒ Object
- .toggle_app_color(target_app_name) ⇒ Object
- .toggle_color(target_color) ⇒ Object
- .valid_name_check(web_app_name, worker_app_names, manifest) ⇒ Object
Instance Method Summary collapse
-
#initialize(cf_manifest, web_app_name, worker_app_names, with_shutter = nil) ⇒ BlueGreenDeployConfig
constructor
A new instance of BlueGreenDeployConfig.
- #is_in_target?(app) ⇒ Boolean
- #shutter_app_name ⇒ Object
- #target_web_app_name ⇒ Object
- #target_worker_app_names ⇒ Object
Constructor Details
#initialize(cf_manifest, web_app_name, worker_app_names, with_shutter = nil) ⇒ BlueGreenDeployConfig
Returns a new instance of BlueGreenDeployConfig.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cloudfoundry_blue_green_deploy/blue_green_deploy_config.rb', line 10 def initialize(cf_manifest, web_app_name, worker_app_names, with_shutter = nil) manifest = cf_manifest['applications'] self.class.valid_name_check(web_app_name, worker_app_names, manifest) item = manifest.find { |item| self.class.strip_color(item['name']) == web_app_name } if item.nil? raise InvalidManifestError.new("Could not find \"#{web_app_name}-green\" nor \"#{web_app_name}-blue\" in the Cloud Foundry manifest:\n" + "#{cf_manifest.inspect}") end host = item['host'] if host.nil? raise InvalidManifestError.new( "Could not find the \"host\" property associated with the \"#{item['name']}\" application in the Cloud Foundry manifest:\n" + "#{cf_manifest.inspect}") end @domain = item['domain'] if @domain.nil? raise InvalidManifestError.new( "Could not find the \"domain\" property associated with the \"#{item['name']}\" application in the Cloud Foundry manifest:\n" + "#{cf_manifest.inspect}") end @web_app_name = web_app_name @hot_url = host.slice(0, host.rindex('-')) @worker_app_names = worker_app_names @with_shutter = with_shutter @target_color = nil end |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
7 8 9 |
# File 'lib/cloudfoundry_blue_green_deploy/blue_green_deploy_config.rb', line 7 def domain @domain end |
#hot_url ⇒ Object (readonly)
Returns the value of attribute hot_url.
7 8 9 |
# File 'lib/cloudfoundry_blue_green_deploy/blue_green_deploy_config.rb', line 7 def hot_url @hot_url end |
#target_color ⇒ Object
Returns the value of attribute target_color.
8 9 10 |
# File 'lib/cloudfoundry_blue_green_deploy/blue_green_deploy_config.rb', line 8 def target_color @target_color end |
#with_shutter ⇒ Object (readonly)
Returns the value of attribute with_shutter.
7 8 9 |
# File 'lib/cloudfoundry_blue_green_deploy/blue_green_deploy_config.rb', line 7 def with_shutter @with_shutter end |
#worker_app_names ⇒ Object (readonly)
Returns the value of attribute worker_app_names.
7 8 9 |
# File 'lib/cloudfoundry_blue_green_deploy/blue_green_deploy_config.rb', line 7 def worker_app_names @worker_app_names end |
Class Method Details
.all_app_names(web_app_name, worker_app_names) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/cloudfoundry_blue_green_deploy/blue_green_deploy_config.rb', line 95 def self.all_app_names(web_app_name, worker_app_names) all_app_names = [] all_app_names << colorize_name(web_app_name, 'blue') all_app_names << colorize_name(web_app_name, 'green') worker_app_names.each do |app| all_app_names << colorize_name(app, 'green') all_app_names << colorize_name(app, 'blue') end all_app_names end |
.colorize_name(app_name, color) ⇒ Object
91 92 93 |
# File 'lib/cloudfoundry_blue_green_deploy/blue_green_deploy_config.rb', line 91 def self.colorize_name(app_name, color) "#{app_name}-#{color}" end |
.get_color_stem(app_name) ⇒ Object
83 84 85 |
# File 'lib/cloudfoundry_blue_green_deploy/blue_green_deploy_config.rb', line 83 def self.get_color_stem(app_name) app_name.slice((app_name.rindex('-') + 1)..(app_name.length)) end |
.strip_color(app_name_with_color) ⇒ Object
73 74 75 |
# File 'lib/cloudfoundry_blue_green_deploy/blue_green_deploy_config.rb', line 73 def self.strip_color(app_name_with_color) app_name_with_color.slice((0..app_name_with_color.rindex('-') - 1)) end |
.toggle_app_color(target_app_name) ⇒ Object
77 78 79 80 81 |
# File 'lib/cloudfoundry_blue_green_deploy/blue_green_deploy_config.rb', line 77 def self.toggle_app_color(target_app_name) new_color = toggle_color(get_color_stem(target_app_name)) new_app = target_app_name.slice(0..(target_app_name.rindex('-') - 1)) new_app = "#{new_app}-#{new_color}" end |
.toggle_color(target_color) ⇒ Object
87 88 89 |
# File 'lib/cloudfoundry_blue_green_deploy/blue_green_deploy_config.rb', line 87 def self.toggle_color(target_color) target_color == 'green' ? 'blue' : 'green' end |
.valid_name_check(web_app_name, worker_app_names, manifest) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/cloudfoundry_blue_green_deploy/blue_green_deploy_config.rb', line 62 def self.valid_name_check(web_app_name, worker_app_names, manifest) all_apps = all_app_names(web_app_name, worker_app_names) all_apps.each do |app_name| if manifest.none? { |record| record['name'] == app_name } raise InvalidManifestError.new("Could not find \"#{app_name}\" in the Cloud Foundry manifest:\n" + "#{manifest}") end end end |
Instance Method Details
#is_in_target?(app) ⇒ Boolean
51 52 53 |
# File 'lib/cloudfoundry_blue_green_deploy/blue_green_deploy_config.rb', line 51 def is_in_target?(app) self.class.get_color_stem(app) == @target_color end |
#shutter_app_name ⇒ Object
43 44 45 |
# File 'lib/cloudfoundry_blue_green_deploy/blue_green_deploy_config.rb', line 43 def shutter_app_name "#{@web_app_name}-shutter" end |
#target_web_app_name ⇒ Object
47 48 49 |
# File 'lib/cloudfoundry_blue_green_deploy/blue_green_deploy_config.rb', line 47 def target_web_app_name "#{@web_app_name}-#{@target_color}" end |
#target_worker_app_names ⇒ Object
55 56 57 58 59 |
# File 'lib/cloudfoundry_blue_green_deploy/blue_green_deploy_config.rb', line 55 def target_worker_app_names @worker_app_names.map do |app| "#{app}-#{@target_color}" end end |