Exemplo n.º 1
0
 def get_state(self, transfer_jobs, via_socket=False):
     transfer_jobs = listify(transfer_jobs)
     rval = []
     for tj in transfer_jobs:
         if via_socket and tj.state not in tj.terminal_states and tj.socket:
             try:
                 request = jsonrpc_request(method='get_state', id=True)
                 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                 sock.settimeout(5)
                 sock.connect(('localhost', tj.socket))
                 sock.send(json.dumps(request))
                 response = sock.recv(8192)
                 valid, response = validate_jsonrpc_response(
                     response, id=request['id'])
                 if not valid:
                     # No valid response received, make some pseudo-json-rpc
                     raise Exception(
                         dict(
                             code=128,
                             message=
                             'Did not receive valid response from transfer daemon for state'
                         ))
                 if 'error' in response:
                     # Response was valid but Request resulted in an error
                     raise Exception(response['error'])
                 else:
                     # Request was valid
                     response['result']['transfer_job_id'] = tj.id
                     rval.append(response['result'])
             except Exception as e:
                 # State checking via the transfer daemon failed, just
                 # return the state from the database instead.  Callers can
                 # look for the 'error' member of the response to see why
                 # the check failed.
                 self.sa_session.refresh(tj)
                 error = e.args
                 if type(error) != dict:
                     error = dict(
                         code=256,
                         message='Error connecting to transfer daemon',
                         data=str(e))
                 rval.append(
                     dict(transfer_job_id=tj.id,
                          state=tj.state,
                          error=error))
         else:
             self.sa_session.refresh(tj)
             rval.append(dict(transfer_job_id=tj.id, state=tj.state))
     for tj_state in rval:
         if tj_state['state'] in self.app.model.TransferJob.terminal_states:
             log.debug('Transfer job %s is in terminal state: %s' %
                       (tj_state['transfer_job_id'], tj_state['state']))
         elif tj_state[
                 'state'] == self.app.model.TransferJob.states.PROGRESS and 'percent' in tj_state:
             log.debug('Transfer job %s is %s%% complete' %
                       (tj_state['transfer_job_id'], tj_state['percent']))
     if len(rval) == 1:
         return rval[0]
     return rval
Exemplo n.º 2
0
 def get_state( self, transfer_jobs, via_socket=False ):
     transfer_jobs = listify( transfer_jobs )
     rval = []
     for tj in transfer_jobs:
         if via_socket and tj.state not in tj.terminal_states and tj.socket:
             try:
                 request = jsonrpc_request( method='get_state', id=True )
                 sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
                 sock.settimeout( 5 )
                 sock.connect( ( 'localhost', tj.socket ) )
                 sock.send( json.dumps( request ) )
                 response = sock.recv( 8192 )
                 valid, response = validate_jsonrpc_response( response, id=request['id'] )
                 if not valid:
                     # No valid response received, make some pseudo-json-rpc
                     raise Exception( dict( code=128, message='Did not receive valid response from transfer daemon for state' ) )
                 if 'error' in response:
                     # Response was valid but Request resulted in an error
                     raise Exception( response['error'])
                 else:
                     # Request was valid
                     response['result']['transfer_job_id'] = tj.id
                     rval.append( response['result'] )
             except Exception as e:
                 # State checking via the transfer daemon failed, just
                 # return the state from the database instead.  Callers can
                 # look for the 'error' member of the response to see why
                 # the check failed.
                 self.sa_session.refresh( tj )
                 error = e.args
                 if type( error ) != dict:
                     error = dict( code=256, message='Error connecting to transfer daemon', data=str( e ) )
                 rval.append( dict( transfer_job_id=tj.id, state=tj.state, error=error ) )
         else:
             self.sa_session.refresh( tj )
             rval.append( dict( transfer_job_id=tj.id, state=tj.state ) )
     for tj_state in rval:
         if tj_state['state'] in self.app.model.TransferJob.terminal_states:
             log.debug( 'Transfer job %s is in terminal state: %s' % ( tj_state['transfer_job_id'], tj_state['state'] ) )
         elif tj_state['state'] == self.app.model.TransferJob.states.PROGRESS and 'percent' in tj_state:
             log.debug( 'Transfer job %s is %s%% complete' % ( tj_state[ 'transfer_job_id' ], tj_state[ 'percent' ] ) )
     if len( rval ) == 1:
         return rval[0]
     return rval
Exemplo n.º 3
0
 def get_state(self, transfer_jobs, via_socket=False):
     transfer_jobs = listify(transfer_jobs)
     rval = []
     for tj in transfer_jobs:
         if via_socket and tj.state not in tj.terminal_states and tj.socket:
             try:
                 request = json.jsonrpc_request(method="get_state", id=True)
                 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                 sock.settimeout(5)
                 sock.connect(("localhost", tj.socket))
                 sock.send(json.dumps(request))
                 response = sock.recv(8192)
                 valid, response = json.validate_jsonrpc_response(response, id=request["id"])
                 if not valid:
                     # No valid response received, make some pseudo-json-rpc
                     raise Exception(
                         dict(code=128, message="Did not receive valid response from transfer daemon for state")
                     )
                 if "error" in response:
                     # Response was valid but Request resulted in an error
                     raise Exception(response["error"])
                 else:
                     # Request was valid
                     response["result"]["transfer_job_id"] = tj.id
                     rval.append(response["result"])
             except Exception, e:
                 # State checking via the transfer daemon failed, just
                 # return the state from the database instead.  Callers can
                 # look for the 'error' member of the response to see why
                 # the check failed.
                 self.sa_session.refresh(tj)
                 error = e.args
                 if type(error) != dict:
                     error = dict(code=256, message="Error connecting to transfer daemon", data=str(e))
                 rval.append(dict(transfer_job_id=tj.id, state=tj.state, error=error))
         else:
             self.sa_session.refresh(tj)
             rval.append(dict(transfer_job_id=tj.id, state=tj.state))