From 0d724dcc5a8bf841d3e8e50cc3adfecea320e610 Mon Sep 17 00:00:00 2001 From: Romain Rigaux Date: Mon, 18 Mar 2019 10:58:45 -0700 Subject: [PATCH] HUE-8741 [doc] How to document how to access the shell and count documents --- docs/ROADMAP.md | 2 +- .../administrator/administration/_index.md | 8 ++ .../docs-site/content/developer/api/_index.md | 84 ++++++++++++++++++- 3 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 docs/docs-site/content/administrator/administration/_index.md diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index df5f8f1ab01..f07c9a0f600 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -20,7 +20,7 @@ High Level Roadmap * [ ] Gunicorn [HUE-8739](https://issues.cloudera.org/browse/HUE-8739) * [x] Web Server [NGINX](http://gethue.com/using-nginx-to-speed-up-hue-3-8-0/) * [ ] SQL Alchemy full support [HUE-8740](https://issues.cloudera.org/browse/HUE-8740) -* [ ] Documentation refresh [HUE-8741](https://issues.cloudera.org/browse/HUE-8741) +* [x] Documentation refresh [HUE-8741](https://issues.cloudera.org/browse/HUE-8741) * [ ] Public REST APIs [HUE-1450](https://issues.cloudera.org/browse/HUE-1450) * [ ] Git integration [HUE-951](https://issues.cloudera.org/browse/HUE-951) diff --git a/docs/docs-site/content/administrator/administration/_index.md b/docs/docs-site/content/administrator/administration/_index.md new file mode 100644 index 00000000000..fb82b249396 --- /dev/null +++ b/docs/docs-site/content/administrator/administration/_index.md @@ -0,0 +1,8 @@ +--- +title: "Administration" +date: 2019-03-13T18:28:09-07:00 +draft: false +weight: 4 +--- + +This sections details the "ops" part of Hue, e.g. how to monitor the servers, manage users and permissions. \ No newline at end of file diff --git a/docs/docs-site/content/developer/api/_index.md b/docs/docs-site/content/developer/api/_index.md index 7cca5fd975e..c10f06b4d90 100644 --- a/docs/docs-site/content/developer/api/_index.md +++ b/docs/docs-site/content/developer/api/_index.md @@ -5,12 +5,92 @@ draft: false weight: 2 --- -## CLI +Hue can be accessed directly via a Django Python Shell or by its REST API (recommended). + +## Python * [Hue API: Execute some builtin or shell commands](http://gethue.com/hue-api-execute-some-builtin-commands/). * [How to manage the Hue database with the shell](http://gethue.com/how-to-manage-the-hue-database-with-the-shell/). -## API +### How to count documents of a user + +On the command line: + + ./build/env/bin/hue shell + +If using Cloudera Manager, as a `root` user launch the shell. + +Export the configuration directory: + + export HUE_CONF_DIR="/var/run/cloudera-scm-agent/process/`ls -alrt /var/run/cloudera-scm-agent/process | grep HUE_SERVER | tail -1 | awk '{print $9}'`" + echo $HUE_CONF_DIR + > /var/run/cloudera-scm-agent/process/2061-hue-HUE_SERVER + +Get the process id: + + lsof -i :8888|grep -m1 hue|awk '{ print $2 }' + > 14850 + +In order to export all Hue's env variables: + + for line in `strings /proc/$(lsof -i :8888|grep -m1 hue|awk '{ print $2 }')/environ|egrep -v "^HOME=|^TERM=|^PWD="`;do export $line;done + +And finally launch the shell by: + + HUE_IGNORE_PASSWORD_SCRIPT_ERRORS=1 /opt/cloudera/parcels/CDH/lib/hue/build/env/bin/hue shell + > ALERT: This appears to be a CM Managed environment + > ALERT: HUE_CONF_DIR must be set when running hue commands in CM Managed environment + > ALERT: Please run 'hue --cm-managed' + +Then use the Python code to access a certain user information: + + Python 2.7.6 (default, Oct 26 2016, 20:30:19) + Type "copyright", "credits" or "license" for more information. + + IPython 5.2.0 -- An enhanced Interactive Python. + ? -> Introduction and overview of IPython's features. + %quickref -> Quick reference. + help -> Python's own help system. + object? -> Details about 'object', use 'object??' for extra details. + + from django.contrib.auth.models import User + from desktop.models import Document2 + + user = User.objects.get(username='demo') + Document2.objects.documents(user=user).count() + + In [8]: Document2.objects.documents(user=user).count() + Out[8]: 1167 + + In [10]: Document2.objects.documents(user=user, perms='own').count() + Out[10]: 1166 + + In [11]: Document2.objects.documents(user=user, perms='own', include_history=True).count() + Out[11]: 7125 + + In [12]: Document2.objects.documents(user=user, perms='own', include_history=True, include_trashed=True).count() + Out[12]: 7638 + + In [13]: Document2.objects.documents(user=user, perms='own', include_history=True, include_trashed=True, include_managed=True).count() + Out[13]: 31408 + + Out[14]: + (85667L, + {u'desktop.Document': 18524L, + u'desktop.Document2': 31409L, + u'desktop.Document2Permission': 556L, + u'desktop.Document2Permission_groups': 277L, + u'desktop.Document2Permission_users': 0L, + u'desktop.Document2_dependencies': 15087L, + u'desktop.DocumentPermission': 1290L, + u'desktop.DocumentPermission_groups': 0L, + u'desktop.DocumentPermission_users': 0L, + u'desktop.Document_tags': 18524L}) + + +## REST + +The API is being made public via [HUE-1450](https://issues.cloudera.org/browse/HUE-1450). ### Metadata Catalog