source: proiecte/HadoopJUnit/hadoop-0.20.1/contrib/hod/bin/ringmaster @ 173

Last change on this file since 173 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 13.4 KB
Line 
1#!/bin/sh
2
3# Licensed to the Apache Software Foundation (ASF) under one or more
4# contributor license agreements.  See the NOTICE file distributed with
5# this work for additional information regarding copyright ownership.
6# The ASF licenses this file to You under the Apache License, Version 2.0
7# (the "License"); you may not use this file except in compliance with
8# the License.  You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18
19""":"
20work_dir=$(dirname $0)
21base_name=$(basename $0)
22cd $work_dir
23
24if [ $HOD_PYTHON_HOME ]; then
25    exec $HOD_PYTHON_HOME -OO $base_name ${1+"$@"}
26elif [ -e /usr/bin/python ]; then
27    exec /usr/bin/python -OO $base_name ${1+"$@"}
28elif [ -e /usr/local/bin/python ]; then
29    exec /usr/local/bin/python -OO $base_name ${1+"$@"}
30else
31    exec python -OO $base_name ${1+"$@"}
32fi
33":"""
34
35"""The executable to be used by the user"""
36import sys, os, re, getpass
37
38myName          = os.path.basename(sys.argv[0])
39myName          = re.sub(".*/", "", myName)
40binDirectory    = os.path.realpath(sys.argv[0])
41rootDirectory   = re.sub("/bin/.*", "", binDirectory)
42libDirectory    = rootDirectory
43
44sys.path.append(libDirectory)
45
46from hodlib.RingMaster.ringMaster import main
47from hodlib.Common.setup import *
48from hodlib.Common.descGenerator import *
49from hodlib.Common.util import local_fqdn, filter_warnings, to_http_url, \
50                        get_exception_string, get_exception_error_string
51from hodlib.Common.logger import getLogger, ensureLogDir
52from hodlib.Common.xmlrpc import hodXRClient
53import logging
54
55filter_warnings()
56
57reVersion = re.compile(".*(\d+_\d+).*")
58
59VERSION = '$HeadURL$'
60
61reMatch = reVersion.match(VERSION)
62if reMatch:
63    VERSION = reMatch.group(1)
64    VERSION = re.sub("_", ".", VERSION)
65else:
66    VERSION = 'DEV'
67
68# Definition tuple is of the form:
69#  (name, type, description, default value, required?, validate?)
70#
71defList = { 'ringmaster' : (
72             ('work-dirs', 'list', 'hod work directories',
73              False, None, True, False),
74
75             ('temp-dir', 'directory', 'Ringmaster temporary directory.',
76              False, None, True, False),
77             
78             ('log-dir', 'directory', 'hod logging directory.',
79              False, os.path.join(rootDirectory, 'logs'), False, True),
80             
81             ('syslog-address', 'address', 'Syslog address.',
82              False, None, False, True),
83               
84             ('xrs-port-range', 'range', 'XML-RPC port range n-m.',
85              False, None, True, True),
86             
87             ('http-port-range', 'range', 'HTTP port range n-m.',
88              False, None, True, True),
89             
90             ('debug', 'pos_int', 'Debugging level, 0-4.',
91              False, 3, True,   True),
92               
93             ('register', 'bool', 'Register with service registry?',
94              False, True, True, True),
95               
96             ('stream', 'bool', 'Output to stderr.',
97              False, False, False, True),
98             
99             ('userid', 'user_account',
100              'User ID the hod shell is running under.',
101              False, None, True, False),
102               
103             ('svcrgy-addr', 'address', 'Download HTTP address.',
104              False, None, False, True),             
105             
106             ('hadoop-tar-ball', 'uri', 'hadoop program tar ball.',
107              False, None, False, False),
108       
109             ('max-connect','pos_int','max connections allowed for a single tarball server',
110             False, 30, False, True),
111
112             ('jt-poll-interval', 'pos_int', 'How often to poll the Job tracker for idleness',
113             False, 120, False, True),
114
115             ('idleness-limit', 'pos_int', 'Limit after which to deallocate the cluster',
116             False, 3600, False, True),
117
118             ('max-master-failures', 'pos_int',
119              'Defines how many times a master can fail before' \
120              ' failing cluster allocation', False, 5, True, True),
121
122             ('workers_per_ring', 'pos_int', 'Defines number of workers per service per hodring',
123              False, 1, False, True)),
124
125            'resource_manager' : (
126             ('id', 'string', 'Batch scheduler ID: torque|condor.',
127              False, None, True, True),
128
129             ('pbs-user', 'user_account', 'User ID jobs are submitted under.',
130              False, None, False, True),
131
132             ('pbs-server', 'hostname', 'Hostname of PBS server.',
133              False, None, False, True),   
134
135             ('pbs-account', 'string', 'User Account jobs are submitted under.',
136              False, None, False, False),
137
138             ('queue', 'string', 'Queue of the batch scheduler to query.',
139              False, None, False, False),
140             
141             ('batch-home', 'directory', 'Scheduler installation directory.',
142              False, None, True, True),
143             
144             ('options', 'keyval', 'Options to pass to the scheduler.',
145              False, None, False, True),                   
146
147             ('env-vars', 'keyval', 'Environment variables to pass to the submitted jobs.',
148              False, None, False, True)),
149
150            'gridservice-mapred' : (   
151             ('external', 'bool', "Connect to an already running MapRed?",
152              False, False, True, True),
153                         
154             ('host', 'hostname', 'Mapred hostname.',
155              False, 'localhost', False, True),
156
157             ('info_port', 'pos_int', 'Mapred info port.',
158              False, None, True, True),
159             
160             ('tracker_port', 'pos_int', 'Mapred job tracker port.',
161              False, None, True, True),                 
162                         
163             ('cmdline-params', 'keyval', 'Hadoop cmdline key/value list.',
164              False, None, False, False),
165
166             ('server-params', 'keyval', 'Hadoop xml key/value list',
167              False, None, False, False),
168
169             ('final-server-params', 'keyval', 'Hadoop final xml params',
170              False, None, False, False),
171             
172             ('envs', 'keyval', 'environment to run this package in',
173              False, None, False, False),
174             
175             ('pkgs', 'directory', "directory where the package is installed",
176              False, None, False, False)),
177               
178               
179            'gridservice-hdfs' : (
180             ('external', 'bool', "Connect to an already running HDFS?",
181              False, False, True, True),
182             
183             ('host', 'hostname', 'HDFS hostname.',
184              False, 'localhost', True, True),
185             
186             ('fs_port', 'pos_int', 'HDFS port range.',
187              False, None, True, True),
188             
189             ('info_port', 'pos_int', 'HDFS info port.',
190              False, None, True, True),
191             
192             ('cmdline-params', 'keyval', 'Hadoop cmdline key/value list.',
193              False, None, False, False),
194
195             ('server-params', 'keyval', 'Hadoop xml key/value list',
196              False, None, False, False),
197
198             ('final-server-params', 'keyval', 'Hadoop final xml params',
199              False, None, False, False),
200           
201             ('envs', 'keyval', 'Environment in which to run this package.',
202              False, None, False, False),
203
204             ('pkgs', 'directory', "directory where the package is installed",
205              False, None, False, False)),         
206             
207             
208            'hodring' : (
209             ('temp-dir', 'directory', 'hod work directories',
210              False, None, True, False),
211             
212             ('log-dir', 'directory', 'hod logging directory.',
213              False, os.path.join(rootDirectory, 'logs'), False, False),
214
215             ('log-destination-uri', 'string',
216              'URI to store logs to, local://some_path or '
217              + 'hdfs://host:port/some_path',
218              False, None, False, True),             
219
220             ('pkgs', 'directory', 'Path to Hadoop to use in case of uploading to HDFS',
221              False, None, False, True),
222             
223             ('syslog-address', 'address', 'Syslog address.',
224              False, None, False, True),
225         
226             ('java-home', 'directory', 'Java home directory.',
227              False, None, True, False),
228             
229             ('debug', 'pos_int', 'Debugging level, 0-4.',
230              False, 3, True, True),
231               
232             ('register', 'bool', 'Register with service registry?',
233              False, True, True, True),
234               
235             ('stream', 'bool', 'Output to stderr.',
236              False, False, False, True),
237
238             ('userid', 'user_account',
239              'User ID the hod shell is running under.',
240              False, None, True, False),
241
242             ('xrs-port-range', 'range', 'XML-RPC port range n-m.',
243              False, None, True, True),
244               
245             ('http-port-range', 'range', 'HTTP port range n-m.',
246              False, None, True, True),
247               
248             ('command', 'string', 'Command for hodring to run.',
249              False, None, False, True),
250             
251             ('service-id', 'string', 'Service ID.',
252              False, None, False, True),
253             
254             ('download-addr', 'address', 'Download HTTP address.',
255              False, None, False, True),
256               
257             ('svcrgy-addr', 'address', 'Download HTTP address.',
258              False, None, False, True),
259   
260             ('ringmaster-xrs-addr', 'address', 'Ringmaster XML-RPC address.',
261              False, None, False, True),
262 
263             ('tarball-retry-initial-time', 'pos_float','initial retry time for tarball download',
264              False, 1, False, True),
265             
266             ('tarball-retry-interval', 'pos_float','interval to spread retries for tarball download',
267              False, 3, False, True),
268             
269             ('cmd-retry-initial-time', 'pos_float','initial retry time for getting commands',
270              False, 2, False, True),
271             
272             ('cmd-retry-interval', 'pos_float','interval to spread retries for getting commands',
273              False, 2, False, True),
274 
275             ('mapred-system-dir-root', 'string', 'Root under which mapreduce system directory names are generated by HOD.',
276              False, '/mapredsystem', False, False))
277              }   
278
279             
280defOrder = [ 'ringmaster', 'hodring', 'resource_manager',
281             'gridservice-mapred', 'gridservice-hdfs' ]
282
283if __name__ == '__main__':
284  confDef = definition()
285  confDef.add_defs(defList, defOrder)
286  ringMasterOptions = options(confDef, "./%s [OPTIONS]" % myName, VERSION)
287  log = logging.getLogger()
288
289  try:
290
291    # Set up logging before anything else.
292    ensureLogDir(ringMasterOptions.normalizeValue('ringmaster', 'log-dir'))
293    log = getLogger(ringMasterOptions['ringmaster'],'ringmaster')
294    # End of setting up logging
295
296    # Verify and process options
297    statusMsgs = []
298    # Conditional validation
299    if not ringMasterOptions['ringmaster'].has_key('hadoop-tar-ball') or \
300        not ringMasterOptions['ringmaster']['hadoop-tar-ball']:
301      # If tarball is not used
302      if not ringMasterOptions.normalizeValue('gridservice-hdfs', 'external'):
303        # And if hdfs is not external, validate gridservice-hdfs.pkgs
304        statusMsgs.extend(ringMasterOptions.validateValue(
305                                                  'gridservice-hdfs', 'pkgs'))
306      statusMsgs.extend(ringMasterOptions.validateValue(
307                                                  'gridservice-mapred', 'pkgs'))
308
309    if len(statusMsgs) != 0:
310      # format status messages into a single string
311      errStr = ''
312      for msg in statusMsgs:
313        errStr = "%s%s\n" % (errStr, msg)
314      raise Exception("%s" % errStr)
315    # End of conditional validation
316
317    (status, statusMsgs) = ringMasterOptions.verify()
318    if not status:
319      # format status messages into a single string
320      errStr = ''
321      for msg in statusMsgs:
322        errStr = "%s%s\n" % (errStr, msg)
323      raise Exception("%s" % errStr)
324
325    ringMasterOptions.replace_escape_seqs()
326    ringMasterOptions['ringmaster']['base-dir'] = rootDirectory
327    # End of option processing
328
329    ret = main(ringMasterOptions,log)
330    sys.exit(ret)
331  except Exception, e:
332    log.error("bin/ringmaster failed to start.%s. Stack trace follows:\n%s" % (get_exception_error_string(),get_exception_string()))
333
334    # Report errors to the client if possible
335    try:
336      serviceAddr = to_http_url(ringMasterOptions.normalizeValue( \
337                                     'ringmaster', 'svcrgy-addr'))
338      serviceClient = hodXRClient(serviceAddr)
339      if serviceClient is not None:
340        serviceClient.setRMError([local_fqdn(), str(e), \
341                                    get_exception_string()])
342        log.info("Reported errors to service registry at %s" % serviceAddr)
343    except Exception, e:
344      log.error("Failed to report errors to service registry.")
345      log.error("Reason : %s" % get_exception_string())
346    # End of reporting errors to the client
347
348    # Ringmaster failing to start is a ringmaster error. Exit with the appropriate exit code.
349    sys.exit(6)
Note: See TracBrowser for help on using the repository browser.