Ejemplo n.º 1
0
 def execute_json(self, session_id, stmt):
     """execute_json interface with session_id and ngql
     :param session_id: the session id get from result of authenticate interface
     :param stmt: the ngql
     :return: string json representing the execution result
     """
     try:
         resp = self._connection.executeJson(session_id, stmt)
         return resp
     except Exception as te:
         if isinstance(te, TTransportException):
             if te.message.find("timed out") > 0:
                 self._reopen()
                 raise IOErrorException(IOErrorException.E_TIMEOUT,
                                        te.message)
             elif te.type == TTransportException.END_OF_FILE:
                 raise IOErrorException(IOErrorException.E_CONNECT_BROKEN,
                                        te.message)
             elif te.type == TTransportException.NOT_OPEN:
                 raise IOErrorException(IOErrorException.E_NOT_OPEN,
                                        te.message)
             else:
                 raise IOErrorException(IOErrorException.E_UNKNOWN,
                                        te.message)
         raise
Ejemplo n.º 2
0
 def execute(self, stmt):
     """
     execute statement
     :param stmt: the ngql
     :return: ResultSet
     """
     if self._connection is None:
         raise RuntimeError('The session has released')
     try:
         return ResultSet(self._connection.execute(self.session_id, stmt))
     except IOErrorException as ie:
         if ie.type == IOErrorException.E_CONNECT_BROKEN:
             self._pool.update_servers_status()
             if self._retry_connect:
                 if not self._reconnect():
                     logging.warning('Retry connect failed')
                     raise IOErrorException(IOErrorException.E_ALL_BROKEN,
                                            'All connections are broken')
                 try:
                     return ResultSet(
                         self._connection.execute(self.session_id, stmt))
                 except Exception:
                     raise
         raise
     except Exception:
         raise
Ejemplo n.º 3
0
    def execute(self, stmt):
        """execute statement

        :param stmt: the ngql
        :return: ResultSet
        """
        if self._connection is None:
            raise RuntimeError('The session has released')
        try:
            start_time = time.time()
            resp = self._connection.execute(self._session_id, stmt)
            end_time = time.time()
            return ResultSet(resp,
                             all_latency=int((end_time - start_time) * 1000000),
                             timezone_offset=self._timezone_offset)
        except IOErrorException as ie:
            if ie.type == IOErrorException.E_CONNECT_BROKEN:
                self._pool.update_servers_status()
                if self._retry_connect:
                    if not self._reconnect():
                        logging.warning('Retry connect failed')
                        raise IOErrorException(IOErrorException.E_ALL_BROKEN, ie.message)
                    resp = self._connection.execute(self._session_id, stmt)
                    end_time = time.time()
                    return ResultSet(resp,
                                     all_latency=int((end_time - start_time) * 1000000),
                                     timezone_offset=self._timezone_offset)
            raise
        except Exception:
            raise
Ejemplo n.º 4
0
 def execute(self, session_id, stmt):
     try:
         resp = self._connection.execute(session_id, stmt)
         return resp
     except TTransportException as te:
         if te.type == TTransportException.END_OF_FILE:
             self.close()
         raise IOErrorException(IOErrorException.E_CONNECT_BROKEN)
Ejemplo n.º 5
0
 def authenticate(self, user_name, password):
     try:
         resp = self._connection.authenticate(user_name, password)
         if resp.error_code != ttypes.ErrorCode.SUCCEEDED:
             raise AuthFailedException(resp.error_msg)
         return resp.session_id
     except TTransportException as te:
         if te.type == TTransportException.END_OF_FILE:
             self.close()
         raise IOErrorException(IOErrorException.E_CONNECT_BROKEN)
Ejemplo n.º 6
0
 def authenticate(self, user_name, password):
     try:
         resp = self._connection.authenticate(user_name, password)
         if resp.error_code != ErrorCode.SUCCEEDED:
             raise AuthFailedException(resp.error_msg)
         return AuthResult(resp.session_id, resp.time_zone_offset_seconds,
                           resp.time_zone_name)
     except TTransportException as te:
         if te.type == TTransportException.END_OF_FILE:
             self.close()
         raise IOErrorException(IOErrorException.E_CONNECT_BROKEN,
                                te.message)
Ejemplo n.º 7
0
    def authenticate(self, user_name, password):
        """authenticate to graphd

        :param user_name: the user name
        :param password: the password
        :return:
        """
        try:
            resp = self._connection.authenticate(user_name, password)
            if resp.error_code != ErrorCode.SUCCEEDED:
                raise AuthFailedException(resp.error_msg)
            return AuthResult(resp.session_id, resp.time_zone_offset_seconds, resp.time_zone_name)
        except TTransportException as te:
            if te.message.find("timed out"):
                self._reopen()
            if te.type == TTransportException.END_OF_FILE:
                self.close()
            raise IOErrorException(IOErrorException.E_CONNECT_BROKEN, te.message)
Ejemplo n.º 8
0
 def execute_json(self, stmt):
     """execute statement and return the result as a JSON string
         Date and Datetime will be returned in UTC
         JSON struct:
         {
             "results": [
             {
                 "columns": [],
                 "data": [
                 {
                     "row": [
                     "row-data"
                     ],
                     "meta": [
                     "metadata"
                     ]
                 }
                 ],
                 "latencyInUs": 0,
                 "spaceName": "",
                 "planDesc ": {
                 "planNodeDescs": [
                     {
                     "name": "",
                     "id": 0,
                     "outputVar": "",
                     "description": {
                         "key": ""
                     },
                     "profiles": [
                         {
                         "rows": 1,
                         "execDurationInUs": 0,
                         "totalDurationInUs": 0,
                         "otherStats": {}
                         }
                     ],
                     "branchInfo": {
                         "isDoBranch": false,
                         "conditionNodeId": -1
                     },
                     "dependencies": []
                     }
                 ],
                 "nodeIndexMap": {},
                 "format": "",
                 "optimize_time_in_us": 0
                 },
                 "comment ": ""
             }
             ],
             "errors": [
             {
                 "code": 0,
                 "message": ""
             }
             ]
         }
     :param stmt: the ngql
     :return: JSON string
     """
     if self._connection is None:
         raise RuntimeError('The session has released')
     try:
         resp_json = self._connection.execute_json(self._session_id, stmt)
         return resp_json
     except IOErrorException as ie:
         if ie.type == IOErrorException.E_CONNECT_BROKEN:
             self._pool.update_servers_status()
             if self._retry_connect:
                 if not self._reconnect():
                     logging.warning('Retry connect failed')
                     raise IOErrorException(
                         IOErrorException.E_ALL_BROKEN, ie.message)
                 resp_json = self._connection.execute_json(
                     self._session_id, stmt)
                 return resp_json
         raise
     except Exception:
         raise