|
|
@@ -1,13 +1,14 @@
|
|
|
-# Licensed to the Apache Software Foundation (ASF) under one
|
|
|
+#!/usr/bin/env python
|
|
|
+# Licensed to Cloudera, Inc. under one
|
|
|
# or more contributor license agreements. See the NOTICE file
|
|
|
# distributed with this work for additional information
|
|
|
-# regarding copyright ownership. The ASF licenses this file
|
|
|
+# regarding copyright ownership. Cloudera, Inc. licenses this file
|
|
|
# to you under the Apache License, Version 2.0 (the
|
|
|
# "License"); you may not use this file except in compliance
|
|
|
# with the License. You may obtain a copy of the License at
|
|
|
-
|
|
|
+#
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
-
|
|
|
+#
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
@@ -17,58 +18,69 @@
|
|
|
from desktop.lib.django_util import render
|
|
|
from django.http import Http404
|
|
|
|
|
|
-from zkui import settings
|
|
|
-from zkui.stats import ZooKeeperStats
|
|
|
-from zkui.rest import ZooKeeper
|
|
|
-from zkui.utils import get_cluster_or_404
|
|
|
-from zkui.forms import CreateZNodeForm, EditZNodeForm
|
|
|
+from zookeeper import settings
|
|
|
+
|
|
|
+from zookeeper.conf import CLUSTERS
|
|
|
+from zookeeper.forms import CreateZNodeForm, EditZNodeForm
|
|
|
+from zookeeper.stats import ZooKeeperStats
|
|
|
+from zookeeper.rest import ZooKeeper
|
|
|
+from zookeeper.utils import get_cluster_or_404
|
|
|
+
|
|
|
|
|
|
def _get_global_overview():
|
|
|
- overview = []
|
|
|
- for c in settings.CLUSTERS:
|
|
|
- overview.append(_get_overview(c))
|
|
|
- return overview
|
|
|
+ clusters = CLUSTERS.get()
|
|
|
+ return dict([(c, _get_overview(clusters[c].HOST_PORTS.get())) for c in clusters])
|
|
|
+
|
|
|
|
|
|
-def _get_overview(cluster):
|
|
|
+def _get_overview(host_ports):
|
|
|
stats = {}
|
|
|
- for s in cluster['hostport'].split(','):
|
|
|
+
|
|
|
+ for s in host_ports.split(','):
|
|
|
host, port = map(str.strip, s.split(':'))
|
|
|
|
|
|
zks = ZooKeeperStats(host, port)
|
|
|
stats[s] = zks.get_stats() or {}
|
|
|
|
|
|
- cluster['stats'] = stats
|
|
|
- return cluster
|
|
|
+ return stats
|
|
|
|
|
|
-def _group_stats_by_role(cluster):
|
|
|
+
|
|
|
+def _group_stats_by_role(stats):
|
|
|
leader, followers = None, []
|
|
|
- for host, stats in cluster['stats'].items():
|
|
|
+ for host, stats in stats.items():
|
|
|
stats['host'] = host
|
|
|
|
|
|
if stats.get('zk_server_state') == 'leader':
|
|
|
leader = stats
|
|
|
|
|
|
elif stats.get('zk_server_state') == 'follower':
|
|
|
- followers.append(stats)
|
|
|
+ followers.append(stats)
|
|
|
+
|
|
|
+ return leader, followers
|
|
|
+
|
|
|
|
|
|
- return leader, followers
|
|
|
-
|
|
|
def index(request):
|
|
|
- overview = _get_global_overview()
|
|
|
- return render('index.mako', request,
|
|
|
- dict(overview=overview))
|
|
|
+ overview = _get_global_overview()
|
|
|
+
|
|
|
+ return render('index.mako', request, {
|
|
|
+ 'clusters': CLUSTERS.get(),
|
|
|
+ 'overview': overview
|
|
|
+ })
|
|
|
+
|
|
|
|
|
|
def view(request, id):
|
|
|
cluster = get_cluster_or_404(id)
|
|
|
|
|
|
- cluster = _get_overview(cluster)
|
|
|
- leader, followers = _group_stats_by_role(cluster)
|
|
|
+ stats = _get_overview(cluster['host_ports'])
|
|
|
+ leader, followers = _group_stats_by_role(stats)
|
|
|
+
|
|
|
+ return render('view.mako', request, {
|
|
|
+ 'cluster': cluster, 'leader': leader, 'followers': followers,
|
|
|
+ 'clusters': CLUSTERS.get(),
|
|
|
+ })
|
|
|
|
|
|
- return render('view.mako', request,
|
|
|
- dict(cluster=cluster, leader=leader, followers=followers))
|
|
|
|
|
|
def clients(request, host):
|
|
|
- parts = host.split(':')
|
|
|
+ parts = host.split(':')
|
|
|
if len(parts) != 2:
|
|
|
raise Http404
|
|
|
|
|
|
@@ -79,21 +91,21 @@ def clients(request, host):
|
|
|
return render('clients.mako', request,
|
|
|
dict(host=host, port=port, clients=clients))
|
|
|
|
|
|
+
|
|
|
def tree(request, id, path):
|
|
|
cluster = get_cluster_or_404(id)
|
|
|
- zk = ZooKeeper(cluster['rest_gateway'])
|
|
|
+ zk = ZooKeeper(cluster['rest_url'])
|
|
|
|
|
|
znode = zk.get(path)
|
|
|
children = sorted(zk.get_children_paths(path))
|
|
|
-
|
|
|
- return render('tree.mako', request,
|
|
|
- dict(cluster=cluster, path=path, \
|
|
|
- znode=znode, children=children))
|
|
|
+
|
|
|
+ return render('tree.mako', request, {'cluster': cluster, 'path': path, 'znode': znode, 'children': children, 'clusters': CLUSTERS.get(),})
|
|
|
+
|
|
|
|
|
|
def delete(request, id, path):
|
|
|
cluster = get_cluster_or_404(id)
|
|
|
if request.method == 'POST':
|
|
|
- zk = ZooKeeper(cluster['rest_gateway'])
|
|
|
+ zk = ZooKeeper(cluster['rest_url'])
|
|
|
try:
|
|
|
zk.recursive_delete(path)
|
|
|
except ZooKeeper.NotFound:
|
|
|
@@ -101,30 +113,28 @@ def delete(request, id, path):
|
|
|
|
|
|
return tree(request, id, path[:path.rindex('/')] or '/')
|
|
|
|
|
|
+
|
|
|
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_gateway'])
|
|
|
+ zk = ZooKeeper(cluster['rest_url'])
|
|
|
|
|
|
- full_path = ("%s/%s" % (path, form.cleaned_data['name']))\
|
|
|
- .replace('//', '/')
|
|
|
+ full_path = ("%s/%s" % (path, form.cleaned_data['name'])).replace('//', '/')
|
|
|
|
|
|
- zk.create(full_path, \
|
|
|
- form.cleaned_data['data'], \
|
|
|
- sequence = form.cleaned_data['sequence'])
|
|
|
+ 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,
|
|
|
- dict(path=path, form=form))
|
|
|
+ return render('create.mako', request, {'path': path, 'form': form, 'clusters': CLUSTERS.get(),})
|
|
|
+
|
|
|
|
|
|
def edit_as_base64(request, id, path):
|
|
|
cluster = get_cluster_or_404(id)
|
|
|
- zk = ZooKeeper(cluster['rest_gateway'])
|
|
|
+ zk = ZooKeeper(cluster['rest_url'])
|
|
|
node = zk.get(path)
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
@@ -137,15 +147,15 @@ def edit_as_base64(request, id, path):
|
|
|
return tree(request, id, path)
|
|
|
else:
|
|
|
form = EditZNodeForm(dict(\
|
|
|
- data=node.get('data64', ''),
|
|
|
+ data=node.get('data64', ''),
|
|
|
version=node.get('version', '-1')))
|
|
|
|
|
|
- return render('edit.mako', request,
|
|
|
- dict(path=path, form=form))
|
|
|
+ return render('edit.mako', request, {'path': path, 'form': form, 'clusters': CLUSTERS.get(),})
|
|
|
+
|
|
|
|
|
|
def edit_as_text(request, id, path):
|
|
|
cluster = get_cluster_or_404(id)
|
|
|
- zk = ZooKeeper(cluster['rest_gateway'])
|
|
|
+ zk = ZooKeeper(cluster['rest_url'])
|
|
|
node = zk.get(path)
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
@@ -155,11 +165,6 @@ def edit_as_text(request, id, path):
|
|
|
|
|
|
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,
|
|
|
- dict(path=path, form=form))
|
|
|
-
|
|
|
+ form = EditZNodeForm(dict(data=node.get('data64', '').decode('base64').strip(), version=node.get('version', '-1')))
|
|
|
|
|
|
+ return render('edit.mako', request, {'path': path, 'form': form, 'clusters': CLUSTERS.get(),})
|