Selaa lähdekoodia

HADOOP-2961: Avoids unnecessary checks for some configuration parameters related to service configuration. Contributed by Vinod Kumar Vavilapalli.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@663075 13f79535-47bb-0310-9956-ffa450edef68
Devaraj Das 17 vuotta sitten
vanhempi
commit
a35cb3ddef

+ 3 - 0
src/contrib/hod/CHANGES.txt

@@ -15,6 +15,9 @@ Trunk (unreleased changes)
  
  
   BUG FIXES
   BUG FIXES
 
 
+    HADOOP-2961: Avoids unnecessary checks for some configuration parameters
+    related to service configuration. (Vinod Kumar Vavilapalli via ddas)
+
 Release 0.17.0 - Unreleased
 Release 0.17.0 - Unreleased
 
 
   INCOMPATIBLE CHANGES
   INCOMPATIBLE CHANGES

+ 38 - 6
src/contrib/hod/bin/hod

@@ -232,13 +232,13 @@ defList = { 'hod' : (
               False, False, True, True),
               False, False, True, True),
               
               
              ('host', 'hostname', 'Mapred hostname.', 
              ('host', 'hostname', 'Mapred hostname.', 
-              False, 'localhost', False, True),
+              False, 'localhost', False, False),
 
 
              ('info_port', 'pos_int', 'Mapred info port.',
              ('info_port', 'pos_int', 'Mapred info port.',
-              False, None, True, True), 
+              False, None, False, False),
              
              
              ('tracker_port', 'pos_int', 'Mapred job tracker port.',
              ('tracker_port', 'pos_int', 'Mapred job tracker port.',
-              False, None, True, True),
+              False, None, False, False),
                         
                         
              ('cmdline-params', 'keyval', 'Hadoop cmdline key/value list.',
              ('cmdline-params', 'keyval', 'Hadoop cmdline key/value list.',
               False, None, False, False),
               False, None, False, False),
@@ -261,13 +261,13 @@ defList = { 'hod' : (
               False, False, True, True),
               False, False, True, True),
              
              
              ('host', 'hostname', 'HDFS hostname.', 
              ('host', 'hostname', 'HDFS hostname.', 
-              False, 'localhost', False, True),
+              False, 'localhost', False, False),
              
              
              ('fs_port', 'pos_int', 'HDFS port.',
              ('fs_port', 'pos_int', 'HDFS port.',
-              False, None, True, True),
+              False, None, False, False),
               
               
              ('info_port', 'pos_int', 'HDFS info port.',
              ('info_port', 'pos_int', 'HDFS info port.',
-              False, None, True, True), 
+              False, None, False, False), 
              
              
              ('cmdline-params', 'keyval', 'Hadoop cmdline key/value list.',
              ('cmdline-params', 'keyval', 'Hadoop cmdline key/value list.',
               False, None, False, False),
               False, None, False, False),
@@ -388,6 +388,38 @@ if __name__ == '__main__':
       print >>sys.stderr,"error: %s not found. Specify the path to the HOD configuration file, or define the environment variable %s under which a file named hodrc can be found." % (hodOptions['config'], 'HOD_CONF_DIR')
       print >>sys.stderr,"error: %s not found. Specify the path to the HOD configuration file, or define the environment variable %s under which a file named hodrc can be found." % (hodOptions['config'], 'HOD_CONF_DIR')
       sys.exit(1)
       sys.exit(1)
   
   
+    # Conditional validation
+    statusMsgs = []
+
+    if hodConfig.normalizeValue('gridservice-hdfs', 'external'):
+      # For external HDFS
+      statusMsgs.extend(hodConfig.validateValue('gridservice-hdfs',
+                                                'fs_port'))
+      statusMsgs.extend(hodConfig.validateValue('gridservice-hdfs',
+                                                'info_port'))
+      statusMsgs.extend(hodConfig.validateValue('gridservice-hdfs',
+                                                'host'))
+    else:
+      hodConfig['gridservice-hdfs']['fs_port'] = 0 # Dummy
+      hodConfig['gridservice-hdfs']['info_port'] = 0 # Not used at all
+
+    if hodConfig.normalizeValue('gridservice-mapred', 'external'):
+      statusMsgs.extend(hodConfig.validateValue('gridservice-mapred',
+                                                'tracker_port'))
+      statusMsgs.extend(hodConfig.validateValue('gridservice-mapred',
+                                                'info_port'))
+      statusMsgs.extend(hodConfig.validateValue('gridservice-mapred',
+                                                'host'))
+    else:
+      hodConfig['gridservice-mapred']['tracker_port'] = 0 # Dummy
+      hodConfig['gridservice-mapred']['info_port'] = 0 # Not used at all
+
+    if len(statusMsgs) != 0:
+      for msg in statusMsgs:
+        print >>sys.stderr, msg
+      sys.exit(1)
+    # End of conditional validation
+
     status = True
     status = True
     statusMsgs = []
     statusMsgs = []
   
   

+ 18 - 2
src/contrib/hod/bin/ringmaster

@@ -164,7 +164,7 @@ defList = { 'ringmaster' : (
               False, None, False, False),
               False, None, False, False),
               
               
              ('pkgs', 'directory', "directory where the package is installed",
              ('pkgs', 'directory', "directory where the package is installed",
-              False, None, False, True)), 
+              False, None, False, False)), 
                
                
                
                
             'gridservice-hdfs' : (
             'gridservice-hdfs' : (
@@ -193,7 +193,7 @@ defList = { 'ringmaster' : (
               False, None, False, False),
               False, None, False, False),
 
 
              ('pkgs', 'directory', "directory where the package is installed",
              ('pkgs', 'directory', "directory where the package is installed",
-              False, None, False, True)),          
+              False, None, False, False)),          
              
              
              
              
             'hodring' : (
             'hodring' : (
@@ -278,6 +278,22 @@ if __name__ == '__main__':
   log = None
   log = None
 
 
   try:
   try:
+    statusMsgs = []
+    # Conditional validation
+    if not ringMasterOptions['ringmaster'].has_key('hadoop-tar-ball') or \
+        not ringMasterOptions['ringmaster']['hadoop-tar-ball']:
+      # If tarball is not used
+      if not ringMasterOptions.normalizeValue('gridservice-hdfs', 'external'):
+        # And if hdfs is not external, validate gridservice-hdfs.pkgs
+        statusMsgs.extend(ringMasterOptions.validateValue(
+                                                  'gridservice-hdfs', 'pkgs'))
+      statusMsgs.extend(ringMasterOptions.validateValue(
+                                                  'gridservice-mapred', 'pkgs'))
+
+    if len(statusMsgs) != 0:
+      raise Exception("%s" % statusMsgs)
+    # End of conditional validation
+
     (status, statusMsgs) = ringMasterOptions.verify()
     (status, statusMsgs) = ringMasterOptions.verify()
     if not status:
     if not status:
       raise Exception("%s" % statusMsgs)
       raise Exception("%s" % statusMsgs)

+ 21 - 2
src/contrib/hod/hodlib/Common/setup.py

@@ -26,7 +26,8 @@ import sys, os, re, pprint
 from ConfigParser import SafeConfigParser
 from ConfigParser import SafeConfigParser
 from optparse import OptionParser, IndentedHelpFormatter, OptionGroup
 from optparse import OptionParser, IndentedHelpFormatter, OptionGroup
 from util import get_perms, replace_escapes
 from util import get_perms, replace_escapes
-from types import typeValidator, is_valid_type, typeToString
+from types import typeValidator, typeValidatorInstance, is_valid_type, \
+                  typeToString
 from hodlib.Hod.hod import hodHelp
 from hodlib.Hod.hod import hodHelp
 
 
 reEmailAddress = re.compile("^.*@.*$")
 reEmailAddress = re.compile("^.*@.*$")
@@ -224,7 +225,7 @@ class baseConfig:
             
             
         return status
         return status
 
 
-    # 'private' method which prints an configuration error messages
+    # Prints configuration error messages
     def var_error(self, section, option, *addData):
     def var_error(self, section, option, *addData):
         errorStrings = []  
         errorStrings = []  
         if not self._dict[section].has_key(option):
         if not self._dict[section].has_key(option):
@@ -393,6 +394,24 @@ class baseConfig:
 
 
         return status,statusMsgs
         return status,statusMsgs
 
 
+    def normalizeValue(self, section, option)  :
+      return typeValidatorInstance.normalize(
+                                  self._configDef[section][option]['type'],
+                                  self[section][option])
+
+    def validateValue(self, section, option):
+      # Validates a section.option and exits on error
+      valueInfo = typeValidatorInstance.verify(
+                                  self._configDef[section][option]['type'],
+                                  self[section][option])
+      if valueInfo['isValid'] == 1:
+        return []
+      else:
+        if valueInfo['errorData']:
+          return self.var_error(section, option, valueInfo['errorData'])
+        else:
+          return self.var_error(section, option)
+
 class config(SafeConfigParser, baseConfig):
 class config(SafeConfigParser, baseConfig):
     def __init__(self, configFile, configDef=None, originalDir=None, 
     def __init__(self, configFile, configDef=None, originalDir=None, 
                  options=None, checkPerms=False):
                  options=None, checkPerms=False):