예제 #1
0
파일: views.py 프로젝트: ztwu/hue
def edit_as_text(request, id, path):
    cluster = get_cluster_or_404(id)
    zk = ZooKeeper(cluster['rest_url'])
    node = zk.get(path)

    if request.method == 'POST':
        if not request.user.is_superuser:
            raise PopupException(_('You are not a superuser'))
        form = EditZNodeForm(request.POST)
        if form.is_valid():
            zk.set(path, form.cleaned_data['data'])

        return tree(request, id, path)
    else:
        form = EditZNodeForm(
            dict(data=node.get('data64', '').decode('base64').strip(),
                 version=node.get('version', '-1')))

    return render(
        'edit.mako', request, {
            'cluster': cluster,
            'path': path,
            'form': form,
            'clusters': CLUSTERS.get(),
        })
예제 #2
0
def zkensemble():
    """
  Try to guess the value if no values are specified.
  """

    from django.conf import settings

    if 'zookeeper' in settings.INSTALLED_APPS:
        try:
            # Backward compatibility until Hue 4
            from zookeeper.conf import CLUSTERS
            clusters = CLUSTERS.get()
            if clusters['default'].HOST_PORTS.get() != 'localhost:2181':
                return '%s' % clusters['default'].HOST_PORTS.get()
        except:
            LOG.warn('Could not get zookeeper ensemble from the zookeeper app')

    if 'search' in settings.INSTALLED_APPS:
        try:
            from search.conf import SOLR_URL
            parsed = urlparse(SOLR_URL.get())
            return "%s:2181" % (parsed.hostname or 'localhost')
        except:
            LOG.warn('Could not get zookeeper ensemble from the search app')

    return "localhost:2181"
예제 #3
0
파일: views.py 프로젝트: ztwu/hue
def create(request, id, path):
    if not request.user.is_superuser:
        raise PopupException(_('You are not a superuser'))
    cluster = get_cluster_or_404(id)

    if request.method == 'POST':
        form = CreateZNodeForm(request.POST)
        if form.is_valid():
            zk = ZooKeeper(cluster['rest_url'])

            full_path = ("%s/%s" % (path, form.cleaned_data['name'])).replace(
                '//', '/')

            zk.create(full_path,
                      form.cleaned_data['data'],
                      sequence=form.cleaned_data['sequence'])
            return tree(request, id, path)
    else:
        form = CreateZNodeForm()

    return render(
        'create.mako', request, {
            'cluster': cluster,
            'path': path,
            'form': form,
            'clusters': CLUSTERS.get(),
        })
예제 #4
0
파일: conf.py 프로젝트: orenmazor/hue
def zkensemble():
  """
  Try to guess the value if no values are specified.
  """

  from django.conf import settings

  if 'zookeeper' in settings.INSTALLED_APPS:
    try:
      # Backward compatibility until Hue 4
      from zookeeper.conf import CLUSTERS
      clusters = CLUSTERS.get()
      if clusters['default'].HOST_PORTS.get() != 'localhost:2181':
        return '%s' % clusters['default'].HOST_PORTS.get()
    except:
      LOG.warn('Could not get zookeeper ensemble from the zookeeper app')

  if 'search' in settings.INSTALLED_APPS:
    try:
      from search.conf import SOLR_URL
      parsed = urlparse(SOLR_URL.get())
      return "%s:2181" % (parsed.hostname or 'localhost')
    except:
      LOG.warn('Could not get zookeeper ensemble from the search app')

  return "localhost:2181"
예제 #5
0
파일: views.py 프로젝트: branchp/hue
def edit_as_base64(request, id, path):
    cluster = get_cluster_or_404(id)
    zk = ZooKeeper(cluster['rest_url'])
    node = zk.get(path)

    if request.method == 'POST':
        form = EditZNodeForm(request.POST)
        if form.is_valid():
            # TODO is valid base64 string?
            data = form.cleaned_data['data'].decode('base64')
            zk.set(path, data, form.cleaned_data['version'])

        return tree(request, id, path)
    else:
        form = EditZNodeForm(dict(\
          data=node.get('data64', ''),
          version=node.get('version', '-1')))

    return render(
        'edit.mako', request, {
            'cluster': cluster,
            'path': path,
            'form': form,
            'clusters': CLUSTERS.get(),
        })
예제 #6
0
def index(request):
  try:
    overview = _get_global_overview()
  except Exception as e:
    raise PopupException(_('Could not correctly connect to Zookeeper.'), detail=e)

  return render('index.mako', request, {
      'clusters': CLUSTERS.get(),
      'overview': overview
  })
예제 #7
0
파일: views.py 프로젝트: ymc/hue
def view(request, id):
  cluster = get_cluster_or_404(id)

  stats = _get_overview(cluster['host_ports'])
  leader, followers = _group_stats_by_role(stats)

  return render('view.mako', request, {
      'cluster': cluster, 'all_stats': stats, 'leader': leader, 'followers': followers,
      'clusters': CLUSTERS.get(),
  })
예제 #8
0
파일: api.py 프로젝트: vishwakarmarahul/hue
def _get_server_properties():
    global _api_cache

    if _api_cache is None:
        _api_cache_lock.acquire()

        try:
            if _api_cache is None:

                if get_sentry_server_ha_has_security():
                    try:
                        from zookeeper.conf import CLUSTERS
                        sasl_server_principal = CLUSTERS.get(
                        )['default'].PRINCIPAL_NAME.get()
                    except Exception, e:
                        LOG.error(
                            "Could not get principal name from ZooKeeper app config: %s. Using 'zookeeper' as principal name."
                            % e)
                        sasl_server_principal = 'zookeeper'
                else:
                    sasl_server_principal = None

                zk = KazooClient(hosts=get_sentry_server_ha_zookeeper_quorum(),
                                 read_only=True,
                                 sasl_server_principal=sasl_server_principal)

                zk.start()

                servers = []
                namespace = get_sentry_server_ha_zookeeper_namespace()

                children = zk.get_children(
                    "/%s/sentry-service/sentry-service/" % namespace)
                for node in children:
                    data, stat = zk.get(
                        "/%s/sentry-service/sentry-service/%s" %
                        (namespace, node))
                    server = json.loads(data.decode("utf-8"))
                    servers.append({
                        'hostname':
                        server['address'],
                        'port':
                        server['sslPort']
                        if server['sslPort'] else server['port']
                    })

                zk.stop()

                _api_cache = servers
        finally:
            _api_cache_lock.release()

    return _api_cache
예제 #9
0
파일: utils.py 프로젝트: 10sr/hue
def get_cluster_or_404(id):
  try:
    name = id
    cluster = CLUSTERS.get()[name]
  except (TypeError, ValueError):
    raise Http404()

  cluster = {
    'id': id,
    'nice_name': id,
    'host_ports': cluster.HOST_PORTS.get(),
    'rest_url': cluster.REST_URL.get(),
  }

  return cluster
예제 #10
0
파일: utils.py 프로젝트: ranade1/hue-3
def get_cluster_or_404(id):
    try:
        name = id
        cluster = CLUSTERS.get()[name]
    except (TypeError, ValueError):
        raise Http404()

    cluster = {
        'id': id,
        'nice_name': id,
        'host_ports': cluster.HOST_PORTS.get(),
        'rest_url': cluster.REST_URL.get(),
    }

    return cluster
예제 #11
0
def zkensemble():
    """
  ZooKeeper Ensemble
  """
    try:
        from zookeeper.conf import CLUSTERS
        clusters = CLUSTERS.get()
        if clusters['default'].HOST_PORTS.get() != 'localhost:2181':
            return '%s/solr' % clusters['default'].HOST_PORTS.get()
    except:
        pass

    from search.conf import SOLR_URL
    parsed = urlparse(SOLR_URL.get())
    return "%s:2181/solr" % (parsed.hostname or 'localhost')
예제 #12
0
파일: conf.py 프로젝트: 9629831527/hue
def zkensemble():
  """
  ZooKeeper Ensemble
  """
  try:
    from zookeeper.conf import CLUSTERS
    clusters = CLUSTERS.get()
    if clusters['default'].HOST_PORTS.get() != 'localhost:2181':
      return '%s/solr' % clusters['default'].HOST_PORTS.get()
  except:
    pass

  from search.conf import SOLR_URL
  parsed = urlparse(SOLR_URL.get())
  return "%s:2181/solr" % (parsed.hostname or 'localhost')
예제 #13
0
파일: views.py 프로젝트: ztwu/hue
def tree(request, id, path):
    cluster = get_cluster_or_404(id)
    zk = ZooKeeper(cluster['rest_url'])

    znode = zk.get(path)
    children = sorted(zk.get_children_paths(path))

    return render(
        'tree.mako', request, {
            'cluster': cluster,
            'path': path,
            'znode': znode,
            'children': children,
            'clusters': CLUSTERS.get(),
        })
예제 #14
0
파일: views.py 프로젝트: ymc/hue
def clients(request, id, host):
  cluster = get_cluster_or_404(id)

  parts = host.split(':')
  if len(parts) != 2:
    raise Http404

  host, port = parts
  zks = stats.ZooKeeperStats(host, port)
  clients = zks.get_clients()

  return render('clients.mako', request, {
    'clusters': CLUSTERS.get(),
    'cluster': cluster,
    'host': host,
    'port': port,
    'clients': clients
  })
예제 #15
0
파일: conf.py 프로젝트: cyc821211/hue
def zkensemble():
  """
  Try to guess the value if no values are specified.
  """
  try:
    # Backward compatibility until Hue 4
    from zookeeper.conf import CLUSTERS
    clusters = CLUSTERS.get()
    if clusters['default'].HOST_PORTS.get() != 'localhost:2181':
      return '%s/solr' % clusters['default'].HOST_PORTS.get()
  except:
    LOG.exception('failed to get zookeeper ensemble')

  try:
    from search.conf import SOLR_URL
    parsed = urlparse(SOLR_URL.get())
    return "%s:2181/solr" % (parsed.hostname or 'localhost')
  except:
    LOG.exception('failed to get solr url')

  return "localhost:2181"
예제 #16
0
def _get_server_properties():
  global _api_cache

  if _api_cache is None:
    _api_cache_lock.acquire()

    try:
      if _api_cache is None:

        if get_sentry_server_ha_has_security():
          try:
            from zookeeper.conf import CLUSTERS
            sasl_server_principal = CLUSTERS.get()['default'].PRINCIPAL_NAME.get()
          except Exception, e:
            LOG.warn("Could not get principal name from ZooKeeper app config: %s. Using 'zookeeper' as principal name." % e)
            sasl_server_principal = 'zookeeper'
        else:
          sasl_server_principal = None

        zk = KazooClient(hosts=get_sentry_server_ha_zookeeper_quorum(), read_only=True, sasl_server_principal=sasl_server_principal)

        zk.start()

        servers = []
        namespace = get_sentry_server_ha_zookeeper_namespace()

        children = zk.get_children("/%s/sentry-service/sentry-service/" % namespace)
        for node in children:
          data, stat = zk.get("/%s/sentry-service/sentry-service/%s" % (namespace, node))
          server = json.loads(data.decode("utf-8"))
          servers.append({'hostname': server['address'], 'port': server['sslPort'] if server['sslPort'] else server['port']})

        zk.stop()

        _api_cache = servers
    finally:
      _api_cache_lock.release()

  return _api_cache
예제 #17
0
파일: views.py 프로젝트: 15580056814/hue
def edit_as_base64(request, id, path):
  cluster = get_cluster_or_404(id)
  zk = ZooKeeper(cluster['rest_url'])
  node = zk.get(path)

  if request.method == 'POST':
    if not request.user.is_superuser:
      raise PopupException(_('You are not a superuser'))
    form = EditZNodeForm(request.POST)
    if form.is_valid():
      # TODO is valid base64 string?
      data = form.cleaned_data['data'].decode('base64')
      zk.set(path, data, form.cleaned_data['version'])

    return tree(request, id, path)
  else:
    form = EditZNodeForm(dict(\
      data=node.get('data64', ''),
      version=node.get('version', '-1')))

  return render('edit.mako', request, {'cluster': cluster, 'path': path, 'form': form, 'clusters': CLUSTERS.get(),})
예제 #18
0
파일: views.py 프로젝트: ymc/hue
      leader = stats

    elif stats.get('zk_server_state') == 'follower':
      followers.append(stats)

  return leader, followers


def index(request):
  try:
    overview = _get_global_overview()
  except Exception, e:
    raise PopupException(_('Could not correctly connect to Zookeeper.'), detail=e)

  return render('index.mako', request, {
      'clusters': CLUSTERS.get(),
      'overview': overview
  })


def view(request, id):
  cluster = get_cluster_or_404(id)

  stats = _get_overview(cluster['host_ports'])
  leader, followers = _group_stats_by_role(stats)

  return render('view.mako', request, {
      'cluster': cluster, 'all_stats': stats, 'leader': leader, 'followers': followers,
      'clusters': CLUSTERS.get(),
  })
예제 #19
0
파일: views.py 프로젝트: ymc/hue
def _get_global_overview():
  clusters = CLUSTERS.get()
  return dict([(c, _get_overview(clusters[c].HOST_PORTS.get())) for c in clusters])
예제 #20
0
파일: views.py 프로젝트: Web5design/hue
def edit_as_text(request, id, path):
  cluster = get_cluster_or_404(id)
  zk = ZooKeeper(cluster['rest_url'])
  node = zk.get(path)

  if request.method == 'POST':
    form = EditZNodeForm(request.POST)
    if form.is_valid():
      zk.set(path, form.cleaned_data['data'])

    return tree(request, id, path)
  else:
    form = EditZNodeForm(dict(data=node.get('data64', '').decode('base64').strip(), version=node.get('version', '-1')))

  return render('edit.mako', request, {'cluster': cluster, 'path': path, 'form': form, 'clusters': CLUSTERS.get(),})
예제 #21
0
파일: views.py 프로젝트: Web5design/hue
def create(request, id, path):
  cluster = get_cluster_or_404(id)

  if request.method == 'POST':
    form = CreateZNodeForm(request.POST)
    if form.is_valid():
      zk = ZooKeeper(cluster['rest_url'])

      full_path = ("%s/%s" % (path, form.cleaned_data['name'])).replace('//', '/')

      zk.create(full_path, form.cleaned_data['data'], sequence = form.cleaned_data['sequence'])
      return tree(request, id, path)
  else:
    form = CreateZNodeForm()

  return render('create.mako', request, {'cluster': cluster, 'path': path, 'form': form, 'clusters': CLUSTERS.get(),})
예제 #22
0
파일: views.py 프로젝트: Web5design/hue
def tree(request, id, path):
  cluster = get_cluster_or_404(id)
  zk = ZooKeeper(cluster['rest_url'])

  znode = zk.get(path)
  children = sorted(zk.get_children_paths(path))

  return render('tree.mako', request, {'cluster': cluster, 'path': path, 'znode': znode, 'children': children, 'clusters': CLUSTERS.get(),})