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(), })
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"
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(), })
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(), })
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 })
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(), })
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
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
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')
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(), })
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 })
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"
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
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(),})
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(), })
def _get_global_overview(): clusters = CLUSTERS.get() return dict([(c, _get_overview(clusters[c].HOST_PORTS.get())) for c in clusters])
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(),})
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(),})
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(),})