Ejemplo n.º 1
0
def get_metastore():
  """
  Get first metastore information from local hive-site.xml.
  """
  global _METASTORE_LOC_CACHE
  if not _METASTORE_LOC_CACHE:
    thrift_uris = get_conf().get(_CNF_METASTORE_URIS)
    is_local = thrift_uris is None or thrift_uris == ''

    if not is_local:
      use_sasl = str(get_conf().get(_CNF_METASTORE_SASL, 'false')).lower() == 'true'
      thrift_uri = thrift_uris.split(",")[0] # First URI
      host = socket.getfqdn()
      match = _THRIFT_URI_RE.match(thrift_uri)
      if not match:
        LOG.error('Cannot understand remote metastore uri "%s"' % thrift_uri)
      else:
        host, port = match.groups()
      kerberos_principal = security_util.get_kerberos_principal(get_conf().get(_CNF_METASTORE_KERBEROS_PRINCIPAL, None), host)

      _METASTORE_LOC_CACHE = {
          'use_sasl': use_sasl,
          'thrift_uri': thrift_uri,
          'kerberos_principal': kerberos_principal
      }
    else:
      LOG.error('Hue requires a remote metastore configuration')
  return _METASTORE_LOC_CACHE
Ejemplo n.º 2
0
def get_metastore():
  """
  get_metastore() -> (is_local, host, port, kerberos_principal)

  Look at both hive-site.xml and beeswax.conf, and return the metastore information.

  hive-site.xml supersedes beeswax.conf.
  - If hive-site says local metastore (default), then get host & port from beeswax.conf.
  - If hive-site says remote, then use the URI specified there, so that we don't need to
    configure things twice.
  """
  global _METASTORE_LOC_CACHE
  if not _METASTORE_LOC_CACHE:
    kerberos_principal = security_util.get_kerberos_principal(get_conf().get(_CNF_METASTORE_KERBEROS_PRINCIPAL, None))
    kerberos_principal_components = security_util.get_components(kerberos_principal)
    thrift_uris = get_conf().get(_CNF_METASTORE_URIS)
    is_local = thrift_uris is None or thrift_uris == ''
    if is_local:
      host = beeswax.conf.BEESWAX_META_SERVER_HOST.get()
      port = beeswax.conf.BEESWAX_META_SERVER_PORT.get()
    else:
      thrift_uri = thrift_uris.split(",")[0]
      host, port = 'undefined', '0'
      match = _THRIFT_URI_RE.match(thrift_uri)
      if not match:
        LOG.fatal('Cannot understand remote metastore uri "%s"' % thrift_uri)
      else:
        host, port = match.groups()
      if str(get_conf().get(_CNF_METASTORE_SASL, 'false')).lower() == 'true' and len(kerberos_principal_components) == 3:
        host = kerberos_principal_components[1]
    _METASTORE_LOC_CACHE = (is_local, host, int(port), kerberos_principal)
  return _METASTORE_LOC_CACHE
Ejemplo n.º 3
0
def get_metastore():
    """
  Get first metastore information from local hive-site.xml.
  """
    global _METASTORE_LOC_CACHE
    if not _METASTORE_LOC_CACHE:
        thrift_uris = get_conf().get(_CNF_METASTORE_URIS)
        is_local = thrift_uris is None or thrift_uris == ''

        if not is_local:
            use_sasl = str(get_conf().get(_CNF_METASTORE_SASL,
                                          'false')).lower() == 'true'
            thrift_uri = thrift_uris.split(",")[0]  # First URI
            host = socket.getfqdn()
            match = _THRIFT_URI_RE.match(thrift_uri)
            if not match:
                LOG.error('Cannot understand remote metastore uri "%s"' %
                          thrift_uri)
            else:
                host, port = match.groups()
            kerberos_principal = security_util.get_kerberos_principal(
                get_conf().get(_CNF_METASTORE_KERBEROS_PRINCIPAL, None), host)

            _METASTORE_LOC_CACHE = {
                'use_sasl': use_sasl,
                'thrift_uri': thrift_uri,
                'kerberos_principal': kerberos_principal
            }
        else:
            LOG.error('Hue requires a remote metastore configuration')
    return _METASTORE_LOC_CACHE
Ejemplo n.º 4
0
def get_metastore():
    """
  get_metastore() -> (is_local, host, port, kerberos_principal)

  Look at both hive-site.xml and beeswax.conf, and return the metastore information.

  hive-site.xml supersedes beeswax.conf.
  - If hive-site says local metastore (default), then get host & port from beeswax.conf.
  - If hive-site says remote, then use the URI specified there, so that we don't need to
    configure things twice.
  """
    global _METASTORE_LOC_CACHE
    if not _METASTORE_LOC_CACHE:
        kerberos_principal = security_util.get_kerberos_principal(
            get_conf().get(_CNF_METASTORE_KERBEROS_PRINCIPAL, None))
        kerberos_principal_components = security_util.get_components(
            kerberos_principal)
        thrift_uri = get_conf().get(_CNF_METASTORE_URIS)
        is_local = thrift_uri is None or thrift_uri == ''
        if is_local:
            host = beeswax.conf.BEESWAX_META_SERVER_HOST.get()
            port = beeswax.conf.BEESWAX_META_SERVER_PORT.get()
        else:
            host, port = 'undefined', '0'
            match = _THRIFT_URI_RE.match(thrift_uri)
            if not match:
                LOG.fatal('Cannot understand remote metastore uri "%s"' %
                          (thrift_uri, ))
            else:
                host, port = match.groups()
            if str(get_conf().get(_CNF_METASTORE_SASL, 'false')).lower(
            ) == 'true' and len(kerberos_principal_components) == 3:
                host = kerberos_principal_components[1]
        _METASTORE_LOC_CACHE = (is_local, host, int(port), kerberos_principal)
    return _METASTORE_LOC_CACHE
Ejemplo n.º 5
0
def get_sentry_server_principal():
  # Get kerberos principal and replace host pattern
  principal = get_conf().get(_CONF_SENTRY_SERVER_PRINCIPAL, None)
  if principal:
    fqdn = security_util.get_fqdn(HOSTNAME.get())
    return security_util.get_kerberos_principal(principal, fqdn)
  else:
    return None
Ejemplo n.º 6
0
def get_sentry_server_principal():  
  # Get kerberos principal and replace host pattern
  principal = get_conf().get(_CONF_SENTRY_SERVER_PRINCIPAL, None)
  if principal:
    fqdn = security_util.get_fqdn(HOSTNAME.get())
    return security_util.get_kerberos_principal(principal, fqdn)
  else:
    return None
Ejemplo n.º 7
0
def get_metastore():
    """
  get_metastore() -> (is_local, host, port, kerberos_principal)

  Look at both hive-site.xml and beeswax.conf, and return the metastore information.

  hive-site.xml supersedes beeswax.conf.
  - If hive-site says local metastore (default), then get host & port from beeswax.conf.
  - If hive-site says remote, then use the URI specified there, so that we don't need to
    configure things twice.
  """
    global _METASTORE_LOC_CACHE
    if not _METASTORE_LOC_CACHE:
        thrift_uris = get_conf().get(_CNF_METASTORE_URIS)
        is_local = thrift_uris is None or thrift_uris == ''

        if is_local:
            cluster_conf = cluster.get_cluster_conf_for_job_submission()
            use_sasl = cluster_conf is not None and cluster_conf.SECURITY_ENABLED.get(
            )
            host = beeswax.conf.BEESWAX_META_SERVER_HOST.get()
            port = beeswax.conf.BEESWAX_META_SERVER_PORT.get()
            kerberos_principal = security_util.get_kerberos_principal(
                KERBEROS.HUE_PRINCIPAL.get(), socket.getfqdn())
        else:
            use_sasl = str(get_conf().get(_CNF_METASTORE_SASL,
                                          'false')).lower() == 'true'
            thrift_uri = thrift_uris.split(",")[0]
            host, port = 'undefined', '0'
            match = _THRIFT_URI_RE.match(thrift_uri)
            if not match:
                LOG.fatal('Cannot understand remote metastore uri "%s"' %
                          thrift_uri)
            else:
                host, port = match.groups()
            kerberos_principal = security_util.get_kerberos_principal(
                get_conf().get(_CNF_METASTORE_KERBEROS_PRINCIPAL, None),
                socket.getfqdn())

        kerberos_principal_components = security_util.get_components(
            kerberos_principal)
        if use_sasl and len(kerberos_principal_components) == 3:
            host = kerberos_principal_components[1]

        _METASTORE_LOC_CACHE = (is_local, host, int(port), kerberos_principal)
    return _METASTORE_LOC_CACHE
Ejemplo n.º 8
0
def get_hiveserver2_kerberos_principal(hostname_or_ip):
  """
  Retrieves principal for HiveServer 2.

  Raises socket.herror
  """
  fqdn = security_util.get_fqdn(hostname_or_ip)
  # Get kerberos principal and replace host pattern
  principal = get_conf().get(_CNF_HIVESERVER2_KERBEROS_PRINCIPAL, None)
  if principal:
    return security_util.get_kerberos_principal(principal, fqdn)
  else:
    return None
Ejemplo n.º 9
0
Archivo: hive_site.py Proyecto: ymc/hue
def get_hiveserver2_kerberos_principal(hostname_or_ip):
    """
  Retrieves principal for HiveServer 2.

  Raises socket.herror
  """
    fqdn = security_util.get_fqdn(hostname_or_ip)
    # Get kerberos principal and replace host pattern
    principal = get_conf().get(_CNF_HIVESERVER2_KERBEROS_PRINCIPAL, None)
    if principal:
        return security_util.get_kerberos_principal(principal, fqdn)
    else:
        return None
Ejemplo n.º 10
0
def get_hiveserver2_kerberos_principal():
    return security_util.get_kerberos_principal(
        get_conf().get(_CNF_HIVESERVER2_KERBEROS_PRINCIPAL, None),
        socket.getfqdn())
Ejemplo n.º 11
0
def get_hiveserver2_kerberos_principal():
  return security_util.get_kerberos_principal(get_conf().get(_CNF_HIVESERVER2_KERBEROS_PRINCIPAL, None), socket.getfqdn())