Browse Source

[beeswax] Integrate hive-site.xml into the Hive commands

export HIVE_CONF_DIR="/var/run/cloudera-scm-agent/process/`ls -alrt /var/run/cloudera-scm-agent/process | grep HUE | tail -1 | awk '{print $9}'`/hive-conf"

./build/env/bin/hue close_sessions 0
Closing (all=False) HiveServer2/Impala sessions older than 0 days...
Error: TCloseSessionResp(status=TStatus(errorCode=None, errorMessage=None, sqlState=None, infoMessages=None, statusCode=0))
1 sessions closed.

./build/env/bin/hue close_queries 0
Closing (all=False) HiveServer2/Impala queries older than 0 days...
/var/run/cloudera-scm-agent/process/588-hue-HUE_SERVER/hive-conf
0 queries closed.
Romain Rigaux 11 years ago
parent
commit
ec11741

+ 10 - 0
apps/beeswax/src/beeswax/management/commands/close_queries.py

@@ -49,6 +49,16 @@ class Command(BaseCommand):
 
     queries = queries.filter(submission_date__lte=datetime.today() - timedelta(days=days))
 
+    import os
+    import beeswax
+    from beeswax import conf
+    from beeswax import hive_site
+    beeswax.conf.BEESWAX_HIVE_CONF_DIR.set_for_testing(os.environ['HIVE_CONF_DIR'])
+
+    hive_site.reset()
+    hive_site.get_conf()
+
+
     for query in queries:
       try:
         query_history = HiveServerQueryHistory.objects.get(id=query.id)

+ 14 - 7
apps/beeswax/src/beeswax/management/commands/close_sessions.py

@@ -32,25 +32,32 @@ class Command(BaseCommand):
   Closing (all=True) queries older than 7 days...
   0 queries closed.
   """
-  args = '<age_in_days> <hive,impala,all> (default is 7 and hive)'
+  args = '<age_in_days> <all> (default is 7)'
   help = 'Close finished Hive queries older than 7 days. If \'all\' is specified, also close the Impala ones.'
 
   def handle(self, *args, **options):
     days = int(args[0]) if len(args) >= 1 else 7
-    query_type = args[1] if len(args) >= 2 else None
-    if query_type == 'hive' or query_type is None:
-      query_type = 'beeswax'
+    close_all = args[1] == 'all' if len(args) >= 2 else False
 
-    self.stdout.write('Closing (all=%s) HiveServer2/Impala sessions older than %s days...\n' % (query_type, days))
+    self.stdout.write('Closing (all=%s) HiveServer2/Impala sessions older than %s days...\n' % (close_all, days))
 
     n = 0
     sessions = Session.objects.all()
 
-    if query_type != 'all':
-      sessions = sessions.filter(application=query_type)
+    if not close_all:
+      sessions = sessions.filter(application='beeswax')
 
     sessions = sessions.filter(last_used__lte=datetime.today() - timedelta(days=days))
 
+    import os
+    import beeswax
+    from beeswax import conf
+    from beeswax import hive_site
+    beeswax.conf.BEESWAX_HIVE_CONF_DIR.set_for_testing(os.environ['HIVE_CONF_DIR'])
+
+    hive_site.reset()
+    hive_site.get_conf()
+
     for session in sessions:
       try:
           resp = dbms.get(user=session.owner).close_session(session)