Class: PcfBlueGreen::Routing

Inherits:
Object
  • Object
show all
Defined in:
lib/pcf_blue_green.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, user, pass, org, space, call_login = false, opts = {}) ⇒ Routing

Returns a new instance of Routing.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pcf_blue_green.rb', line 12

def initialize(url, user, pass, org, space,  = false, opts = {})
  @options = {:login => '--skip-ssl-validation'}.merge(opts)
  @url = url
  @user = user
  @pass = pass
  @org = org
  @space = space
  @login_options = @options[:login]
   if 
  cmd = "echo $(gem which pcf_blue_green)"
  shell = Mixlib::ShellOut.new(cmd)
  shell.run_command
  gem_path = shell.stdout
  sdf_path = gem_path.gsub("pcf_blue_green.rb\n", "shared-deploy-functions.sh")
  @source_cmd = "source \'#{sdf_path}\'"
end

Instance Method Details

#cleanup_blueObject



29
30
31
32
33
34
35
# File 'lib/pcf_blue_green.rb', line 29

def cleanup_blue
  remap_routes
  status = bash("#{@source_cmd} && remove-blue")
  raise PcfBlueGreen::BlueGreenDeploymentFailed unless status
  remove_routes
  bash("#{@source_cmd} && announce-success")
end

#remap_routesObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/pcf_blue_green.rb', line 64

def remap_routes
  puts "Remapping routes..."
  puts "cf_app is #{ENV['cf_app']}"
  puts "green is #{ENV['green']}"
  mapped_routes = []
  entity = entity_for(ENV['cf_app'])
  if entity
    routes_stdout(entity)['resources'].each do |resource|
      domain_url = resource['entity']['domain_url']
      domain = domain_for(domain_url)
      if resource['entity']['path'].empty?
        cmd = "#{map_route_command} #{ENV['green']} #{domain} -n #{resource['entity']['host']}"
      else
        cmd = "#{map_route_command} #{ENV['green']} #{domain} -n #{resource['entity']['host']} --path #{resource['entity']['path']}"
      end
      puts cmd
      shell = Mixlib::ShellOut.new(cmd)
      shell.run_command
      mapped_routes += shell.stdout.split("\n")
      unless shell.stderr.empty?
        puts shell.stderr
        raise PcfBlueGreen::BlueGreenDeploymentFailed
      end
    end
  end
  puts "Mappped routes: #{mapped_routes.uniq.join(',  ')} "
  mapped_routes.uniq.join(",\n")
end

#remove_routesObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/pcf_blue_green.rb', line 37

def remove_routes
  removed_routes = []
  if entity = entity_for(ENV['cf_app'])
    routes_stdout(entity)['resources'].each do |resource|
      domain_url = resource['entity']['domain_url']
      domain = domain_for(domain_url)
      if resource['entity']['host'] == ENV['green']
        if resource['entity']['path'].empty?
          cmd = "#{delete_route_command} #{domain} -n #{resource['entity']['host']} -f"
        else
          cmd = "#{delete_route_command} #{domain} -n #{resource['entity']['host']} --path #{resource['entity']['path']} -f"
        end
        puts cmd
        shell = Mixlib::ShellOut.new(cmd)
        shell.run_command
        removed_routes += shell.stdout.split("\n")
        unless shell.stderr.empty?
          puts shell.stderr
          raise PcfBlueGreen::BlueGreenDeploymentFailed
        end
      end
    end
  end
  puts "Removed routes: #{removed_routes.uniq.join(',  ')} "
  removed_routes.uniq.join(",\n")
end