Example #1
0
 def _messageReceived(self, msg):
     dataUriMsg = dynamicserialize.deserialize(msg)
     dataUris = dataUriMsg.getDataURIs()
     dataTimes = [
         self._getDataTime(dataUri)
         for dataUri in dataUris
         if self.__notificationFilter.accept(dataUri)
         ]
     if dataTimes:
         secondTry = False
         while True:
             try:
                 data = self.getData(self.__request, dataTimes)
                 break
             except ThriftRequestException:
                 if secondTry:
                     try:
                         self.close()
                     except Exception:
                         pass
                     raise
                 else:
                     secondTry = True
                     time.sleep(5)
         try:
             self.__callback(data)
         except Exception as e:
             # don't want callback to blow up the notifier itself.
             traceback.print_exc()
Example #2
0
def pypies_response(request):
    timeMap.clear()
    try:
        startTime = time.time()
        try:
            data = request.data
            timeMap['receiveData'] = time.time() - startTime
            startTime = time.time()
            obj = dynamicserialize.deserialize(data)
        except:
            msg = 'Error deserializing request: ' + IDataStore._exc()
            logger.error(msg)
            resp = ErrorResponse()
            resp.setError(msg)
            return __prepareResponse(resp)
        timeMap['deserialize'] = time.time() - startTime
        # add the hdf5 directory path to the file name
        filename = hdf5Dir + obj.getFilename()
        obj.setFilename(filename)

        clz = obj.__class__
        if logger.isEnabledFor(logging.DEBUG):
            logger.debug(str(clz) + ": " + obj.getFilename())
        success = False
        if datastoreMap.has_key(clz):
            try:
                resp = datastoreMap[clz][0](obj)
                success = True
            except:
                msg = 'Error processing ' + datastoreMap[clz][
                    1] + ' on file ' + obj.getFilename(
                    ) + ': ' + IDataStore._exc()
                logger.error(msg)
                resp = ErrorResponse()
                resp.setError(msg)
        else:
            msg = 'IDataStore unable to process request of type ' + str(
                obj.__class__)
            logger.error(msg)
            resp = ErrorResponse()
            resp.setError(msg)

        startSerialize = time.time()
        httpResp = __prepareResponse(resp)
        if success:
            endTime = time.time()
            timeMap['serialize'] = endTime - startSerialize
            timeMap['total'] = endTime - startTime
            logger.info({
                'request': datastoreMap[clz][1],
                'time': timeMap,
                'file': obj.getFilename()
            })
            #logger.info("pid=" + str(os.getpid()) + " " + datastoreMap[clz][1] + " on " + obj.getFilename() + " processed in " + ('%.3f' % (t1-t0)) + " seconds")
        return httpResp
    except:
        # Absolutely should not reach this, if we do, need to fix code
        logger.error("Uncaught exception! " + IDataStore._exc())
        # want to re-raise the error as that will cause PyPIES to return http error code 500
        raise
Example #3
0
def main():
    data = readObject()
    obj = dynamicserialize.deserialize(data)
    print obj
    print obj.getPoints()
    
    writeObject()
 def receivedMessage(self, msg):
     try:
         obj = dynamicserialize.deserialize(msg)
         print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), obj
         if type(obj) == ClusterActivationNotification:
             self.stop()
     except:
         traceback.print_exc()
Example #5
0
 def receivedMessage(self, msg):
     obj = dynamicserialize.deserialize(msg)
     t = type(obj)
     if t is list:
         for notification in obj:
             self.addMessageToQueue(notification, type(notification))
     else:
         self.addMessageToQueue(obj, t)
Example #6
0
 def receivedMessage(self, msg):
     try:
         obj = dynamicserialize.deserialize(msg)
         t = type(obj)
         if t is list:
             for notification in obj:
                 self.addMessageToQueue(notification, type(notification))
         else:
             self.addMessageToQueue(obj, t)
     except:
         import traceback
         traceback.print_exc()
 def messageReceived(self, msg):
     dataUriMsg = dynamicserialize.deserialize(msg)
     dataUris = dataUriMsg.getDataURIs()
     dataTimes = set()
     for dataUri in dataUris:
         if self.notificationFilter.accept(dataUri):
             dataTimes.add(self.getDataTime(dataUri))
     if dataTimes:
         try:
             data = self.getData(self.request, list(dataTimes))
             self.callback(data)
         except Exception as e:
             traceback.print_exc()
Example #8
0
 def messageReceived(self, msg):
     dataUriMsg = dynamicserialize.deserialize(msg)
     dataUris = dataUriMsg.getDataURIs()
     dataTimes = set()
     for dataUri in dataUris:
         if self.notificationFilter.accept(dataUri):
             dataTimes.add(self.getDataTime(dataUri))
     if dataTimes:
         try:
             data = self.getData(self.request, list(dataTimes))
             self.callback(data)
         except ValueError:
             traceback.print_exc()
Example #9
0
 def messageReceived(self, msg):
     dataUriMsg = dynamicserialize.deserialize(msg)
     dataUris = dataUriMsg.getDataURIs()
     for dataUri in dataUris:
         if not self.notificationFilter.accept(dataUri):
             continue
         try:
             # This improves performance over requesting by datatime since it requests only the
             # parameter that the notification was received for (instead of this and all previous
             # parameters for the same forecast hour)
             # TODO: This utterly fails for derived requests
             newReq = self.DAL.newDataRequest(self.request.getDatatype())
             newReq.addIdentifier("dataURI", dataUri)
             newReq.setParameters(self.request.getParameters())
             data = self.getData(newReq, [])
             self.callback(data)
         except Exception as e:
             traceback.print_exc()
Example #10
0
def main():
    req = RetrieveRequest()
    req.setIncludeInterpolated(False)
    req.setGroup('/bufrua')
    req.setFilename('/home/njensen/temp/corruptHdf5/bufrua-2010-10-07-18.h5')

    message = dynamicserialize.serialize(req)

    httpConn = httplib.HTTPConnection("localhost", 9582, timeout=90)
    httpConn.connect()
    httpConn.request("POST", '/', message)
    response = httpConn.getresponse()
    if (response.status != 200):
        print response, response.status, response.msg
        print dir(response)
        raise RuntimeError("Unable to post request to server")

    rval = dynamicserialize.deserialize(response.read())
    httpConn.close()
    print rval.getError()