Beispiel #1
0
  def _fetch_result(self, api, session, cell, start_over):
    try:
      response = api.fetch_data(session['id'], cell)
    except Exception as e:
      message = force_unicode(str(e))
      if re.search("session ('\d+' )?not found", message):
        raise SessionExpired(e)
      else:
        raise PopupException(_(message))

    content = response['output']

    if content['status'] == 'ok':
      data = content['data']
      images = []

      try:
        table = data['application/vnd.livy.table.v1+json']
      except KeyError:
        try:
          images = [data['image/png']]
        except KeyError:
          images = []
        if 'application/json' in data:
          result = data['application/json']
          data = result['data']
          meta = [{'name': field['name'], 'type': field['type'], 'comment': ''} for field in result['schema']['fields']]
          type = 'table'
        else:
          data = [[data['text/plain']]]
          meta = [{'name': 'Header', 'type': 'STRING_TYPE', 'comment': ''}]
          type = 'text'
      else:
        data = table['data']
        headers = table['headers']
        meta = [{'name': h['name'], 'type': h['type'], 'comment': ''} for h in headers]
        type = 'table'

      # Non start_over not supported
      if not start_over:
        data = []

      return {
          'data': data,
          'images': images,
          'meta': meta,
          'type': type
      }
    elif content['status'] == 'error':
      msg = content.get('ename', 'unknown error')
      evalue = content.get('evalue')

      if evalue is not None:
        msg = '%s: %s' % (msg, ''.join(evalue))

      tb = content.get('traceback', None)
      if tb is not None and tb != []:
        msg += ' ' + ''.join(tb)

      raise QueryError(msg)
Beispiel #2
0
    def close_session(self, session):
        api = get_spark_api(self.user)

        if session['id'] is not None:
            try:
                api.close(session['id'])
                return {'session': session['id'], 'status': 0}
            except RestException, e:
                if e.code == 404 or e.code == 500:  # TODO remove the 500
                    raise SessionExpired(e)
Beispiel #3
0
  def fetch_result(self, notebook, snippet, rows, start_over):
    api = get_spark_api(self.user)
    session = _get_snippet_session(notebook, snippet)
    cell = snippet['result']['handle']['id']

    try:
      response = api.fetch_data(session['id'], cell)
    except Exception, e:
      message = force_unicode(str(e)).lower()
      if 'session not found' in message:
        raise SessionExpired(e)
      else:
        raise e
Beispiel #4
0
  def execute(self, notebook, snippet):
    api = get_spark_api(self.user)
    session = _get_snippet_session(notebook, snippet)

    try:
      response = api.submit_statement(session['id'], snippet['statement'])
      return {
          'id': response['id'],
          'has_result_set': True,
      }
    except Exception, e:
      message = force_unicode(str(e)).lower()
      if 'session not found' in message or 'connection refused' in message or 'session is in state busy' in message:
        raise SessionExpired(e)
      else:
        raise e
Beispiel #5
0
  def check_status(self, notebook, snippet):
    api = get_spark_api(self.user)
    session = _get_snippet_session(notebook, snippet)
    cell = snippet['result']['handle']['id']

    try:
      response = api.fetch_data(session['id'], cell)
      return {
          'status': response['state'],
      }
    except Exception, e:
      message = force_unicode(str(e)).lower()
      if 'session not found' in message:
        raise SessionExpired(e)
      else:
        raise e
Beispiel #6
0
    def check_status(self, notebook, snippet):
        api = self.get_api()
        session = _get_snippet_session(notebook, snippet)
        cell = snippet['result']['handle']['id']

        try:
            response = api.fetch_data(session['id'], cell)
            return {
                'status': response['state'],
            }
        except Exception as e:
            message = force_unicode(str(e)).lower()
            if re.search("session ('\d+' )?not found", message):
                raise SessionExpired(e)
            else:
                raise e
Beispiel #7
0
    def close_session(self, session):
        api = self.get_api()
        session_key = self._get_session_key()

        if session['id'] is not None:
            try:
                api.close(session['id'])
                return {'session': session['id'], 'status': 0}
            except RestException as e:
                if e.code == 404 or e.code == 500:  # TODO remove the 500
                    raise SessionExpired(e)
            finally:
                if SESSIONS.get(session_key):
                    del SESSIONS[session_key]
        else:
            return {'status': -1}
Beispiel #8
0
  def close_session(self, session):
    api = self.get_api()

    if session['id'] is not None:
      try:
        api.close(session['id'])
        return {
          'session': session['id'],
          'status': 0
        }
      except RestException as e:
        if e.code == 404 or e.code == 500: # TODO remove the 500
          raise SessionExpired(e)
      finally:
        stored_session_info = self._get_session_info_from_user()
        if stored_session_info and session['id'] == stored_session_info['id']:
          self._remove_session_info_from_user()
    else:
      return {'status': -1}
Beispiel #9
0
    def execute(self, notebook, snippet):
        api = self.get_api()
        session = _get_snippet_session(notebook, snippet)

        try:
            response = api.submit_statement(session['id'],
                                            snippet['statement'])
            return {
                'id': response['id'],
                'has_result_set': True,
                'sync': False
            }
        except Exception as e:
            message = force_unicode(str(e)).lower()
            if re.search(
                    "session ('\d+' )?not found", message
            ) or 'connection refused' in message or 'session is in state busy' in message:
                raise SessionExpired(e)
            else:
                raise e
Beispiel #10
0
  def _execute(self, api, session, snippet_type, statement):
    if not session or not self._check_session(session):
      stored_session_info = self._get_session_info_from_user()
      if stored_session_info and self._check_session(stored_session_info):
        session = stored_session_info
      else:
        session = self.create_session(snippet_type)

    try:
      response = api.submit_statement(session['id'], statement)
      return {
          'id': response['id'],
          'has_result_set': True,
          'sync': False
      }
    except Exception as e:
      message = force_unicode(str(e)).lower()
      if re.search("session ('\d+' )?not found", message) or 'connection refused' in message or 'session is in state busy' in message:
        raise SessionExpired(e)
      else:
        raise e
Beispiel #11
0
    def _execute(self, api, session, statement):
        session_key = self._get_session_key()

        if session['id'] is None and SESSIONS.get(session_key) is not None:
            session = SESSIONS[session_key]

        try:
            response = api.submit_statement(session['id'], statement)
            return {
                'id': response['id'],
                'has_result_set': True,
                'sync': False
            }
        except Exception as e:
            message = force_unicode(str(e)).lower()
            if re.search(
                    "session ('\d+' )?not found", message
            ) or 'connection refused' in message or 'session is in state busy' in message:
                raise SessionExpired(e)
            else:
                raise e