Пример #1
0
class QueryHandler(object):
    '''
    classdocs
    '''

    jsonSuccessTemplate = """{
        'query_id' : '%s',
        'timeout' : %d,
        'details' : %r
    }"""

    def __init__(self, content):
        '''
        Constructor
        '''
        self.validator = QueryValidator(content)
    
    def process(self):
        
        errors = self.validator.validateQuery()
        if errors is not None:
            logger.error("Problems while validating the query...")
            return errors
        else:
            try :
                logger.debug("Build query json")
                self.queryId = str(uuid.uuid4())
                
                queryJson = self._buildQuery()
                
                logger.debug("Build executable and params")
                inputParams = self._buildInputParams()
                queryJson['input_params'] = inputParams
            
                logger.debug("Insert query in the DB")
                self._storeInTheDB(queryJson)
                
                # This must be executed in thread!!
                t = threading.Thread(target=self._executeQueryInParallel, args=(inputParams,))
                t.start()
                ####
                                
                # Return
                successMessageStr = self.jsonSuccessTemplate%(self.queryId,
                                                              self.validator.timeout,
                                                              self.validator.executable)
                logger.debug("Message to send to the client:" + successMessageStr)
                
                return ast.literal_eval(successMessageStr)
            except Exception, e:
                message = "Problems while processing the query..."
                logger.exception(message  + str(e))
                return Messages.error(message, str(e));
Пример #2
0
 def testValidatorInvalidJson(self):
     content = self.invalidJson
     v = QueryValidator(content)
     message = v.validateQuery()
     self.assertDictContainsSubset({'success' : 'False'}, message)
Пример #3
0
 def testValidatorSuccess(self):
     content = self.validJson
     v = QueryValidator(content)
     message = v.validateQuery()
     self.assertEqual(message, None)