classify_cluster 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/examples/cluster.rb CHANGED
@@ -1,25 +1,97 @@
1
+ # classify_cluster v.0.0.3a
1
2
  cluster_common = %w{ ntp conary sysstat }
2
- onpremise_common = %w{ sudo cron monit::disabled }
3
+ onpremise_common = %w{ sudo::onpremise cron::onpremise monit::onpremise logrotate::onpremise }
3
4
 
4
5
  cluster :"appliance-cluster" do |cluster|
5
6
  (cluster_common + onpremise_common).each do |common_class|
6
7
  cluster.klass common_class
7
8
  end
8
- {}.each_pair do |key, value|
9
+ {
10
+
11
+ # Cluster-wide configuration variables
12
+
13
+ :socialcast_domain => "localhost.localdomain",
14
+ :database_username => 'socialcast',
15
+ :database_password => '',
16
+
17
+ :database_root_password => '',
18
+
19
+ :flickr_key => '',
20
+ :flickr_secret => '',
21
+
22
+ :email_dropbox_account => '',
23
+ :email_dropbox_password => '',
24
+
25
+ :jabber_account => '',
26
+ :jabber_password => '',
27
+
28
+ :smtp_gateway_address => "foobar.local",
29
+ :smtp_gateway_port => '493',
30
+ :smtp_gateway_tls_enabled => 'true',
31
+ :smtp_gateway_anonymous_access_enabled => 'true',
32
+ :smtp_gateway_username => 'foo@bar',
33
+ :smtp_gateway_password => 'bazquux',
34
+
35
+ :email_dropbox_server => '',
36
+ :email_dropbox_port => '993',
37
+ :innodb_buffer_pool_size => '100M',
38
+ :number_of_rails => '3',
39
+ :number_of_worklings => '2',
40
+
41
+
42
+ # Defaults
43
+ 'socialcast_mode' => 'appliance',
44
+ 'socialcast_filestore' => 'secure_file_system',
45
+ 'cluster_name' => 'appliance-cluster',
46
+ 'deployment_root' => '/var/www/socialcast',
47
+ 'app_root' => '/var/www/socialcast',
48
+ 'app_shared_root' => '/var/www/socialcast',
49
+ 'app_user' => 'socialcast',
50
+ 'ssl_pem_path' => '/etc/ssl/pem',
51
+ 'app_pem_file' => 'raa.pem',
52
+ 'cdn_disabled' => 'true',
53
+ 'solr_jvm_options' => '-server -d32 -Xmx500M -Xms64M', # Needs more granular configuration
54
+ 'rails_env' => 'production',
55
+ 'scheduler_env' => 'production',
56
+
57
+ # Variables that don't directly apply to the appliance
58
+ :backup_s3_app_name => "appliance",
59
+ :solr_newrelic_app_name => "appliance",
60
+ :newrelic_app_name => 'appliance',
61
+ :database_database => 'centurion_production',
62
+
63
+ :aws_access_key_id => '',
64
+ :aws_secret_access_key => '',
65
+ :s3_bucket => '',
66
+ :backup_s3_bucket => '',
67
+
68
+ :cloudkick_oauth_key => '',
69
+ :cloudkick_oauth_secret => ''
70
+
71
+ }.each_pair do |key, value|
9
72
  cluster.variable key, value
10
73
  end
11
- {}.each_pair do |key, value|
12
- cluster.resource do |resource|
13
- resource.type value[:type]
14
- resource.name key
15
- resource.options value[:options]
16
- end
74
+
75
+ cluster.node 'node1.fqdn', '10.11.11.321' do |node|
76
+
77
+ node.role :db, :primary => true
78
+ node.role :queue
79
+ node.role :cron, :primary => true, :backup => true
80
+ node.role :app
81
+ node.role :worker
82
+ node.role :munin, :node => true
83
+
84
+ node.variable 'serverid', 1
85
+
17
86
  end
18
- cluster.node :"example.com" do |node|
19
- node.klass "webserver"
20
- node.variable :appservers, ['123.456.28.1']
21
- node.role do |role|
22
- role.type :web
23
- end
87
+
88
+ cluster.node 'node2.fqdn', '10.11.11.123' do |node|
89
+
90
+ node.role :web
91
+ node.role :app
92
+ node.role :puppet_master
93
+ node.role :munin, :master => true, :node => true
94
+ node.role :search
95
+
24
96
  end
25
- end
97
+ end
@@ -1,21 +1,48 @@
1
1
  module ClassifyCluster
2
2
  module Configurator
3
3
  class Cluster
4
- attr_reader :nodes, :name, :classes, :variables, :resources
4
+ ROLE_2_VARIABLE_MAP = {
5
+ 'app' => ['app_servers', []],
6
+ 'db' => ['database_server', ''],
7
+ 'queue' => ['queue_server', ''],
8
+ 'push' => ['blow_server', ''],
9
+ 'search' => ['solr_host', '']
10
+ }
11
+ attr_reader :nodes, :name, :classes, :variables, :resources, :hostnames
5
12
  def initialize(*args, &block)
6
13
  @nodes = {}
7
14
  @variables = {}
8
15
  @resources = []
9
16
  @classes = []
10
17
  @name = args.first
11
- block.call self
18
+ @hostnames = {}
19
+ returned = block.call(self)
20
+ @nodes.each_pair do |fqdn, node|
21
+ @variables['hostnames'] = [] unless @variables['hostnames']
22
+ @variables['hostnames'] << "#{fqdn}/#{node.private_ip}"
23
+ node.roles.each do |role|
24
+ next unless ROLE_2_VARIABLE_MAP.has_key?(role.type.to_s)
25
+
26
+ variable_name = ROLE_2_VARIABLE_MAP[role.type.to_s].first
27
+ variable_initial_value = ROLE_2_VARIABLE_MAP[role.type.to_s][1]
28
+ @variables[variable_name] = variable_initial_value unless @variables.has_key?(variable_name)
29
+
30
+ if @variables[variable_name].is_a?(Array)
31
+ @variables[variable_name] << node.private_ip
32
+ else
33
+ @variables[variable_name] = node.private_ip
34
+ end
35
+ end
36
+ end
37
+ returned
12
38
  end
13
39
  def name(value=nil)
14
40
  return @name unless value
15
41
  @name = value
16
42
  end
17
- def node(node_name, &block)
18
- @nodes[node_name] = ClassifyCluster::Configurator::Node.new(node_name, &block)
43
+ def node(node_name, private_ip, &block)
44
+ @hostnames[node_name] = private_ip
45
+ @nodes[node_name] = ClassifyCluster::Configurator::Node.new(node_name, private_ip, &block)
19
46
  end
20
47
  def variable(name, value)
21
48
  @variables[name] = value
@@ -1,15 +1,39 @@
1
1
  module ClassifyCluster
2
2
  module Configurator
3
3
  class Node
4
- attr_reader :fqdn, :variables, :resources, :classes, :public_ip, :private_ip, :roles, :default
4
+ ROLE_2_KLASS_MAP = {
5
+ 'db' => { 'primary' => 'databaseserver::onpremise', 'backup' => 'databasereplicationserver::onpremise'},
6
+ 'queue' => 'queueserver::onpremise',
7
+ 'app' => 'appserver::onpremise',
8
+ 'worker' => 'workerserver::onpremise',
9
+ 'web' => 'webserver::onpremise',
10
+ 'puppet_master' => 'puppetmaster::onpremise',
11
+ 'munin' => { 'master' => 'munin::master::onpremise', 'node' => 'munin::node::onpremise' },
12
+ 'push' => 'pushserver::onpremise',
13
+ 'cache' => 'memcached',
14
+ 'search' => 'searchserver::onpremise'
15
+ }
16
+ attr_reader :fqdn, :variables, :resources, :classes, :private_ip, :public_ip, :roles, :default
5
17
  def initialize(*args, &block)
6
18
  @variables = {}
7
19
  @resources = []
8
20
  @classes = []
9
21
  @roles = []
10
22
  @fqdn = (args.first.to_s == 'default' ? '' : args.first)
23
+ @private_ip = (args[1].to_s == 'default' ? '' : args[1])
11
24
  @default = args.first.to_s == 'default'
12
- block.call self
25
+ returned = block.call(self)
26
+ @roles.each do |role|
27
+ if ROLE_2_KLASS_MAP.has_key?(role.type.to_s)
28
+ if role.options.size > 0
29
+ role.options.each_pair do |key, value|
30
+ @classes << ROLE_2_KLASS_MAP[role.type.to_s][key.to_s]
31
+ end
32
+ else
33
+ @classes << ROLE_2_KLASS_MAP[role.type.to_s]
34
+ end
35
+ end
36
+ end
13
37
  end
14
38
  def default?
15
39
  return @default
@@ -18,16 +42,16 @@ module ClassifyCluster
18
42
  return @fqdn unless value
19
43
  @fqdn = value
20
44
  end
21
- def public_ip(value = nil)
22
- return @public_ip unless value
23
- @public_ip = value
24
- end
25
45
  def private_ip(value = nil)
26
46
  return @private_ip unless value
27
47
  @private_ip = value
28
48
  end
29
- def role(&block)
30
- @roles << ClassifyCluster::Configurator::Role.new(&block)
49
+ def public_ip(value = nil)
50
+ return (@public_ip || @private_ip) unless value
51
+ @public_ip = value
52
+ end
53
+ def role(type, options={})
54
+ @roles << ClassifyCluster::Configurator::Role.new(type, options)
31
55
  end
32
56
  def variable(name, value)
33
57
  @variables[name] = value
@@ -2,9 +2,9 @@ module ClassifyCluster
2
2
  module Configurator
3
3
  class Role
4
4
  attr_reader :type, :options
5
- def initialize(*args, &block)
6
- @options = {}
7
- block.call self
5
+ def initialize(type, options={})
6
+ @type = type
7
+ @options = options
8
8
  end
9
9
  def type(value = nil)
10
10
  return @type unless value
@@ -1,3 +1,3 @@
1
1
  module ClassifyCluster
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -10,7 +10,11 @@ module ClassifyCluster
10
10
  roles = node.roles
11
11
  next if roles.empty?
12
12
  roles.each do |role|
13
- capistrano_configurator.role(role.type, node.public_ip, role.options)
13
+ if role.type == 'queue'
14
+ capistrano_configurator.role('rabbitmq', node.public_ip, role.options)
15
+ else
16
+ capistrano_configurator.role(role.type, node.public_ip, role.options)
17
+ end
14
18
  end
15
19
  end
16
20
  end
@@ -35,7 +35,8 @@ module ClassifyCluster
35
35
  node.classes.each do |klass|
36
36
  file.write(output("include #{klass}", :indent => 1))
37
37
  end
38
- file.write(output("}"))
38
+ file.write(output("include socialcast::onpremise", :indent => 1))
39
+ file.write(output("}\n"))
39
40
  end
40
41
  end
41
42
  end; nil
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: classify_cluster
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sean Cashin