def get_serialization(): default_serialization='PROTOBUF' env=os.environ.copy() if os.name == 'posix': hbase_exec_name = 'hbase' elif os.name == 'nt': hbase_exec_name = 'hbase.cmd' else: print 'Unknown platform "%s", defaulting to HBase executable of "hbase"' % os.name hbase_exec_name = 'hbase' hbase_cmd = phoenix_utils.which(hbase_exec_name) if hbase_cmd is None: print 'Failed to find hbase executable on PATH, defaulting serialization to %s.' % default_serialization return default_serialization env['HBASE_CONF_DIR'] = phoenix_utils.hbase_conf_dir proc = subprocess.Popen([hbase_cmd, 'org.apache.hadoop.hbase.util.HBaseConfTool', serialization_key], env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = proc.communicate() if proc.returncode != 0: print 'Failed to extract serialization from hbase-site.xml, defaulting to %s.' % default_serialization return default_serialization # Don't expect this to happen, but give a default value just in case if stdout is None: return default_serialization stdout = stdout.strip() if stdout == 'null': return default_serialization return stdout
def get_hbase_param(key, default): env=os.environ.copy() if os.name == 'posix': hbase_exec_name = 'hbase' elif os.name == 'nt': hbase_exec_name = 'hbase.cmd' else: print('Unknown platform "%s", defaulting to HBase executable of "hbase"' % os.name) hbase_exec_name = 'hbase' hbase_cmd = phoenix_utils.which(hbase_exec_name) if hbase_cmd is None: print('Failed to find hbase executable on PATH, defaulting %s to %s.' % (key, default)) return default env['HBASE_CONF_DIR'] = phoenix_utils.hbase_conf_dir proc = subprocess.Popen([hbase_cmd, 'org.apache.hadoop.hbase.util.HBaseConfTool', key], env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = proc.communicate() if proc.returncode != 0: print('Failed to extract %s from hbase-site.xml, defaulting to %s.' % (key, default)) return default # Don't expect this to happen, but give a default value just in case if stdout is None: return default stdout = tryDecode(stdout.strip()) if stdout == 'null': return default return stdout