OSDN Git Service

improve the backup and restore scripts.
[metasearch/grid-chef-repo.git] / roles / ptolemy-gm.rb
1 #
2 # Copyright 2013-2014, whitestar
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16
17 $LOAD_PATH.push("#{File.dirname(__FILE__)}/_lib")
18 #${chef-repo}/roles/_lib/grid.rb
19 require 'grid'
20 require 'rubygems'
21 require 'bracecomp'
22 require 'socket'
23
24 cluster_name = 'ptolemy'
25 cluster_sym = cluster_name.to_sym
26 datanode_prefix = 'dn4'
27 datanode_digit_nums = 4
28
29 name "#{cluster_name}-gm"
30 description "#{cluster_name.capitalize} ganglia gmetad node"
31
32 run_list(
33   'role[node_commons]',
34   #'role[nameservice-client-grid]',
35   'role[ganglia-gmond]',
36   'role[ganglia-gmetad]',
37   'role[ganglia-web]'
38 )
39
40 #env_run_lists()
41
42 this_subcluster = Grid::CLUSTERS[cluster_sym][:gmetads]
43 mcast_addr = this_subcluster[:mcast_addr]
44 port = '8649'
45 polling_interval = '30'
46 # uni-cast
47 udp_send_channels4ucast = []
48 this_subcluster[:nodes].first(2).each {|host|
49   udp_send_channels4ucast.push(
50     {
51       'mcast_join' => '',
52       'host' => "#{host}.#{Grid::DOMAIN}",
53       #'host' => IPSocket.getaddress("#{host}.#{Grid::DOMAIN}"),
54       'port' => port,
55       'ttl' => ''
56     }
57   )
58 }
59
60 # for non-DataNodes
61 data_sources = []
62 Grid::CLUSTERS[cluster_sym].select{|key| key != :datanodes}.each {|key, cluster|
63   data_sources.push(
64     {
65       :name => cluster[:alias],
66       :polling_interval => polling_interval,
67       # head nodes: 2
68       :address_list => cluster[:nodes].first(2).map{|host| "#{host}.#{Grid::DOMAIN}"}
69     }
70   )
71 }
72
73 # for DataNodes
74 head_node_nums = 2
75 digit_nums = datanode_digit_nums
76 padstr = '0'
77 dn_data_sources = []
78 (0...2).step(40) {|v|
79 #(0...80).step(40) {|v|
80   first_head = v.to_s.rjust(digit_nums, padstr)
81   last_head = (v + head_node_nums -1).to_s.rjust(digit_nums, padstr)
82   dn_data_sources.push( 
83     {
84       :name => "DataNode#{first_head}",
85       :polling_interval => polling_interval,
86       # dn40000
87       :address_list => "#{datanode_prefix}{#{first_head}..#{last_head}}.#{Grid::DOMAIN}".expand
88     }
89   )
90 }
91
92 default_attributes(
93   'ganglia' => {
94     'web' => {
95 =begin
96       'Allow' => [
97         "from .#{Grid::DOMAIN}",
98         'from 192.168.0.0/16'],
99       'AuthType' => 'Kerberos',
100       'mod_auth_kerb' => {
101         'KrbAuthRealms' => Grid::REALM,
102         'Krb5Keytab' => '/etc/krb5.keytab'
103       }
104 =end
105     }
106   },
107 )
108
109 nagios_nodes = []
110 if defined? Grid::CLUSTERS[cluster_sym][:nagioses][:nodes] then
111   nagios_nodes = Grid::CLUSTERS[cluster_sym][:nagioses][:nodes].map{|host| "#{host}.#{Grid::DOMAIN}"}
112 end
113
114 override_attributes(
115   'ganglia' => {
116     # gmond
117     'cluster' => {
118       'name' => this_subcluster[:alias],
119       'owner' => Grid::DOMAIN
120     },
121     'static' => {
122 =begin
123       ## static multi-cast
124       'udp_send_channels' => [
125         {
126           'mcast_join' => mcast_addr,
127           'host' => '',
128           'port' => port,
129           'ttl' => '1'
130         }
131       ],
132       'udp_recv_channels' => [
133         {
134           'mcast_join' => mcast_addr,
135           'port' => port,
136           'bind' => mcast_addr
137         }
138       ],
139 =end
140       ## static uni-cast
141       'udp_send_channels' => udp_send_channels4ucast,
142       'udp_recv_channels' => [
143         {
144           'mcast_join' => '',
145           'port' => port,
146           'bind' => ''
147         }
148       ],
149     },
150     # gmetad
151     'gridname' => cluster_name.capitalize,
152     'trusted_hosts' => ['127.0.0.1'] + nagios_nodes,
153     'data_sources' => data_sources + dn_data_sources
154   }
155 )