Beispiel #1
0
    def handle(self, *args, **options):
        days = int(args[0]) if len(args) >= 1 else 7
        close_all = args[1] == 'all' if len(args) >= 2 else False

        self.stdout.write(
            'Closing (all=%s) HiveServer2 queries older than %s days...\n' %
            (close_all, days))

        queries = QueryHistory.objects.filter(last_state__in=[
            QueryHistory.STATE.expired.value, QueryHistory.STATE.failed.value,
            QueryHistory.STATE.available.value
        ])

        if close_all:
            queries = QueryHistory.objects.all()

        queries = queries.filter(submission_date__lte=datetime.today() -
                                 timedelta(days=days))

        import os
        import beeswax
        from beeswax import conf
        from beeswax import hive_site
        try:
            beeswax.conf.HIVE_CONF_DIR.set_for_testing(
                os.environ['HIVE_CONF_DIR'])
        except:
            LOG.exception('failed to lookup HIVE_CONF_DIR in environment')
            self.stdout.write('Did you export HIVE_CONF_DIR=/etc/hive/conf?\n')
            raise

        hive_site.reset()
        hive_site.get_conf()

        closed_queries = 0
        already_closed_queries = 0

        for query in queries:
            try:
                query_history = QueryHistory.get(id=query.id)
                if query_history.server_id is not None:
                    handle = query_history.get_handle()
                    dbms.get(user=query_history.owner).close_operation(handle)
                    closed_queries += 1
                else:
                    already_closed_queries += 1

                query.last_state = QueryHistory.STATE.expired.value
                query.save()
            except Exception as e:
                if 'None' in str(e) or 'Invalid OperationHandle' in str(e):
                    already_closed_queries += 1
                    query.last_state = QueryHistory.STATE.expired.value
                    query.save()
                else:
                    self.stdout.write('Info: %s\n' % e)

        self.stdout.write('%s queries closed. %s queries already closed.\n' %
                          (closed_queries, already_closed_queries))
Beispiel #2
0
    def handle(self, *args, **options):
        days = int(args[0]) if len(args) >= 1 else 7
        close_all = args[1] == 'all' if len(args) >= 2 else False

        self.stdout.write(
            'Closing (all=%s) HiveServer2 sessions older than %s days...\n' %
            (close_all, days))

        sessions = Session.objects.filter(status_code=0)

        if not close_all:
            sessions = sessions.filter(application='beeswax')

        sessions = sessions.filter(last_used__lte=datetime.today() -
                                   timedelta(days=days))

        self.stdout.write('Found %d open HiveServer2 sessions to close' %
                          len(sessions))

        import os
        import beeswax
        from beeswax import hive_site

        try:
            beeswax.conf.HIVE_CONF_DIR.set_for_testing(
                os.environ['HIVE_CONF_DIR'])
        except:
            LOG.exception('failed to lookup HIVE_CONF_DIR in environment')
            self.stdout.write('Did you export HIVE_CONF_DIR=/etc/hive/conf?\n')
            raise

        hive_site.reset()
        hive_site.get_conf()

        closed = 0
        skipped = 0
        for session in sessions:
            try:
                session = dbms.get(user=session.owner).close_session(session)
                closed += 1
            except Exception as e:
                skipped += 1
                self.stdout.write(
                    'Session with ID %d could not be closed: %s' %
                    (session.id, str(e)))

        self.stdout.write(
            '%d sessions closed.\n%d sessions skipped because already closed.'
            % (closed, skipped))
Beispiel #3
0
  def handle(self, *args, **options):
    days = int(args[0]) if len(args) >= 1 else 7
    close_all = args[1] == 'all' if len(args) >= 2 else False

    self.stdout.write('Closing (all=%s) HiveServer2 queries older than %s days...\n' % (close_all, days))

    queries = QueryHistory.objects.filter(last_state__in=[QueryHistory.STATE.expired.value, QueryHistory.STATE.failed.value, QueryHistory.STATE.available.value])

    if close_all:
      queries = QueryHistory.objects.all()

    queries = queries.filter(submission_date__lte=datetime.today() - timedelta(days=days))

    import os
    import beeswax
    from beeswax import conf
    from beeswax import hive_site
    try:
      beeswax.conf.HIVE_CONF_DIR.set_for_testing(os.environ['HIVE_CONF_DIR'])
    except:
      LOG.exception('failed to lookup HIVE_CONF_DIR in environment')
      self.stdout.write('Did you export HIVE_CONF_DIR=/etc/hive/conf?\n')
      raise

    hive_site.reset()
    hive_site.get_conf()

    closed_queries = 0
    already_closed_queries = 0

    for query in queries:
      try:
        query_history = QueryHistory.get(id=query.id)
        if query_history.server_id is not None:
          handle = query_history.get_handle()
          dbms.get(user=query_history.owner).close_operation(handle)
          closed_queries += 1
        else:
          already_closed_queries += 1

        query.last_state = QueryHistory.STATE.expired.value
        query.save()
      except Exception, e:
        if 'None' in str(e) or 'Invalid OperationHandle' in str(e):
          already_closed_queries += 1
          query.last_state = QueryHistory.STATE.expired.value
          query.save()
        else:
          self.stdout.write('Info: %s\n' % e)
Beispiel #4
0
    def handle(self, *args, **options):
        days = int(args[0]) if len(args) >= 1 else 7
        close_all = args[1] == 'all' if len(args) >= 2 else False

        self.stdout.write(
            'Closing (all=%s) HiveServer2 sessions older than %s days...\n' %
            (close_all, days))

        n = 0
        sessions = Session.objects.all()

        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
        try:
            beeswax.conf.HIVE_CONF_DIR.set_for_testing(
                os.environ['HIVE_CONF_DIR'])
        except:
            LOG.exception('failed to lookup HIVE_CONF_DIR in environment')
            self.stdout.write('Did you export HIVE_CONF_DIR=/etc/hive/conf?\n')
            raise

        hive_site.reset()
        hive_site.get_conf()

        for session in sessions:
            try:
                resp = dbms.get(user=session.owner).close_session(session)
                if not 'Session does not exist!' in str(resp):
                    self.stdout.write('Info: %s\n' % resp)
                    n += 1
            except Exception, e:
                if not 'Session does not exist!' in str(e):
                    self.stdout.write('Info: %s\n' % e)
Beispiel #5
0
  def handle(self, *args, **options):
    days = int(args[0]) if len(args) >= 1 else 7
    close_all = args[1] == 'all' if len(args) >= 2 else False

    self.stdout.write('Closing (all=%s) HiveServer2 sessions older than %s days...\n' % (close_all, days))

    sessions = Session.objects.filter(status_code=0)

    if not close_all:
      sessions = sessions.filter(application='beeswax')

    sessions = sessions.filter(last_used__lte=datetime.today() - timedelta(days=days))

    self.stdout.write('Found %d open HiveServer2 sessions to close' % len(sessions))

    import os
    import beeswax
    from beeswax import hive_site

    try:
      beeswax.conf.HIVE_CONF_DIR.set_for_testing(os.environ['HIVE_CONF_DIR'])
    except:
      LOG.exception('failed to lookup HIVE_CONF_DIR in environment')
      self.stdout.write('Did you export HIVE_CONF_DIR=/etc/hive/conf?\n')
      raise

    hive_site.reset()
    hive_site.get_conf()

    closed = 0
    skipped = 0
    for session in sessions:
      try:
        session = dbms.get(user=session.owner).close_session(session)
        closed += 1
      except Exception, e:
        skipped += 1
        self.stdout.write('Session with ID %d could not be closed: %s' % (session.id, str(e)))
Beispiel #6
0
    def handle(self, *args, **options):
        days = int(args[0]) if len(args) >= 1 else 7
        close_all = args[1] == "all" if len(args) >= 2 else False

        self.stdout.write("Closing (all=%s) HiveServer2 sessions older than %s days...\n" % (close_all, days))

        n = 0
        sessions = Session.objects.all()

        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

        try:
            beeswax.conf.HIVE_CONF_DIR.set_for_testing(os.environ["HIVE_CONF_DIR"])
        except:
            LOG.exception("failed to lookup HIVE_CONF_DIR in environment")
            self.stdout.write("Did you export HIVE_CONF_DIR=/etc/hive/conf?\n")
            raise

        hive_site.reset()
        hive_site.get_conf()

        for session in sessions:
            try:
                resp = dbms.get(user=session.owner).close_session(session)
                if not "Session does not exist!" in str(resp):
                    self.stdout.write("Info: %s\n" % resp)
                    n += 1
            except Exception, e:
                if not "Session does not exist!" in str(e):
                    self.stdout.write("Info: %s\n" % e)