Example #1
0
 def clientConnectionLost(self, connector, reason):
     if self.closed:
         log.info("Connection to the AMQP broker closed.")
         return
     
     log.error('Connection to AMQP broker lost. Reason {0}'.format(reason))
     super(AMQClientFactory, self).clientConnectionLost(connector, reason)
Example #2
0
 def startService(self):
     self.client = self.parent.client_factory.build_client
     
     yield self.server(self.address, self.processor, self.handler)
     super(ThriftAMQService, self).startService()
     
     log.info("ThriftAMQService started, notifying handler")
     self.handler.amq_start(self)
Example #3
0
 def __init__(self, *args, **kwargs):
     super(SimpleDiskArchiver, self).__init__(*args, **kwargs)
     
     self.uploads = {}
     """Register of all currently running uploads"""
     
     self.root = os.path.realpath(settings.data_root)
     """Base directory where all files are contained"""
     
     log.info("Serving files from {0}".format(self.root))
Example #4
0
 def startService(self):
     log.info("Starting {0} service".format(self.name))
     
     c = protocol.ClientCreator(reactor, self.protocol, self.delegate,
             self.vhost, self.specs)
     self.client = yield c.connectTCP(self.host, self.port)
     
     log.debug("Connection OK")
     
     yield self.client.authenticate(self.user, self.password)
     
     log.debug("Authentication OK")
     
     channel = yield self.client.channel(self.channel)
     yield channel.channel_open()
     
     self.client_factory = SMACClientFactory(self.client, channel)
     self.server_factory = SMACServerFactory(self.client, channel)
     
     super(AMQService, self).startService()
Example #5
0
 def __init__(self, transfer_key, path, size, parent='', hashmethod=hashlib.md5):
     super(FileReceiver, self).__init__(parent=parent)
     
     self.transfer_key = transfer_key
     self.path = path
     fd, temp = tempfile.mkstemp()
     self.tempfile = os.fdopen(fd, 'w+b', self.bufsize), temp
     self.start_time = time.time()
     self.size = size
     self.remaining_size = size
     self.received = 0
     self.checksum = hashmethod()
     self.deferred_completed = defer.Deferred()
     
     log.info("Initializing transfer with key '{0}'".format(transfer_key))
     log.debug(" - Temporary file: {0}".format(self.tempfile[1]))
     log.debug(" - Transfer size:  {0}".format(sizeof_fmt(size)))
     log.debug(" - Final path:     {0}".format(path))
     log.debug(" - Hash method:    {0}".format(hashmethod.__name__))
     
     self.start()
Example #6
0
 def finish(self, checksum):
     # Wait for the transfer to complete
     yield self.deferred_completed
     
     # @todo: Cleanup queues and make sure the tempfile is removed from the
     #        system
     
     # Close the file and move it to the final destination
     fh, temppath = self.tempfile
     
     # Remove references to allow garbage collecting the file handler
     del self.tempfile
     
     # Close the file handler
     fh.close()
     
     # Move the file to the final destination in another thread to avoid to
     # block the reactor if the move operation acts on different disks
     yield threads.deferToThread(os.rename, temppath, self.path)
     
     self.duration = time.time() - self.start_time
     error = self.checksum.hexdigest() != checksum
     
     if error:
         log.error("Transfer with key '{0}' failed".format(self.transfer_key))
         log.debug(" - Checksums:     source {0}".format(checksum))
         log.debug("                  receiv {0}".format(self.checksum.hexdigest()))
     else:
         log.info("Transfer with key '{0}' successfully completed".format(self.transfer_key))
         log.debug(" - Checksum:      {0}".format(checksum))
     
     log.debug(" - Duration:      {0:.1f} s".format(self.duration))
     log.debug(" - Average speed: {0}/s".format(sizeof_fmt(self.size / self.duration)))
     
     if error:
         raise InvalidChecksum(self.transfer_key)
Example #7
0
 def stopService(self):
     log.info("ThriftRPCService stopping, notifying handler")
     yield self.handler.rpc_stop()
     log.info("ThriftRPCService handler shutdown procedure terminated, stopping service")
     super(ThriftRPCService, self).stopService()
Example #8
0
 def startService(self):
     super(ThriftRPCService, self).startService()
     log.info("ThriftRPCService started, notifying handler")
     self.handler.rpc_start(self)
Example #9
0
 def startService(self):
     from smac import amqp
     amqp._client_factory = self.parent.client_factory
     amqp._server_factory = self.parent.server_factory
     amqp._delegate = self
     log.info("Global factories setted")