~nchohan/appscale/CassandraMapReduce

« back to all changes in this revision

Viewing changes to AppController/haproxy.rb

  • Committer: Jonathan Kupferman
  • Date: 2010-04-21 20:53:02 UTC
  • Revision ID: jkupferman@cs.ucsb.edu-20100421205302-2bab6ftq0tua2knb
Integrated AppMonitoring so that it starts up automatically with AppScale.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
$:.unshift File.join(File.dirname(__FILE__))
4
4
require 'helperfunctions'
5
5
require 'fileutils'
 
6
require 'load_balancer'
 
7
require 'monitoring'
6
8
 
7
9
# A class to wrap all the interactions with the haproxy load balacer
8
10
class HAProxy
23
25
  # The first port to listen on
24
26
  START_PORT = 10000
25
27
 
26
 
  APP_LOAD_BALANCER_PORTS = [8000, 8001, 8002]
27
 
 
28
28
  def self.stop
29
29
    `service haproxy stop`
30
30
  end
37
37
    `service haproxy reload`
38
38
  end
39
39
 
40
 
  def self.app_load_balancer_ports
41
 
    APP_LOAD_BALANCER_PORTS
42
 
  end
43
 
 
44
40
  # The port that the load balancer will be listening on for the given app number
45
41
  def self.app_listen_port(app_number)
46
42
    START_PORT + app_number
48
44
 
49
45
  # Create the configuration file for the AppLoadBalancer Rails application
50
46
  def self.create_app_load_balancer_config(my_ip, listen_port)
51
 
 
 
47
    self.create_app_config(my_ip, listen_port, LoadBalancer.server_ports, LoadBalancer.name)
 
48
  end
 
49
 
 
50
  # Create the configuration file for the AppMonitoring Rails application
 
51
  def self.create_app_monitoring_config(my_ip, listen_port)
 
52
    self.create_app_config(my_ip, listen_port, Monitoring.server_ports, Monitoring.name)
 
53
  end
 
54
 
 
55
  # A generic function for creating haproxy config files used by appscale services
 
56
  def self.create_app_config(my_ip, listen_port, server_ports, name)
52
57
    servers = []
53
 
    APP_LOAD_BALANCER_PORTS.each_with_index do |port, index|
54
 
      servers << HAProxy.server_config("as_alb", index, my_ip, port)
 
58
    server_ports.each_with_index do |port, index|
 
59
      servers << HAProxy.server_config(name, index, my_ip, port)
55
60
    end
56
61
 
57
 
    alb_config = "# Create a load balancer for the AppLoadBalancer Rails application \n"
58
 
    alb_config << "listen as_alb #{my_ip}:#{listen_port} \n"
59
 
    alb_config << servers.join("\n")
 
62
    config = "# Create a load balancer for the #{name} application \n"
 
63
    config << "listen #{name} #{my_ip}:#{listen_port} \n"
 
64
    config << servers.join("\n")
60
65
 
61
 
    alb_config_path = File.join(SITES_ENABLED_PATH, "as_alb.#{CONFIG_EXTENSION}")
62
 
    File.open(alb_config_path, "w") { |dest_file| dest_file.write(alb_config) }
 
66
    config_path = File.join(SITES_ENABLED_PATH, "#{name}.#{CONFIG_EXTENSION}")
 
67
    File.open(config_path, "w") { |dest_file| dest_file.write(config) }
63
68
 
64
69
    HAProxy.regenerate_config
65
70
  end