def connectionLost(self, reason=ConnectionDone):
     if isinstance(reason, ConnectionLost):
         self.errorOut('connection lost: {}'.format(reason))
     elif self.waiting_for_response:
         self.errorOut('Server closed connection without sending a response.')
     else:
         log.debug('connection terminated.')
Exemplo n.º 2
0
 def requestTimedOut(self):
     self.retry_count += 1
     if self.retry_count > self.retries:
         self.errorOut("Request timed out; server failed to respond.")
     else:
         log.debug('Retrying...')
         self.connectionMade()
Exemplo n.º 3
0
 def requestTimedOut(self):
     self.retry_count += 1
     if self.retry_count > self.retries:
         self.errorOut("Request timed out; server failed to respond.")
     else:
         log.debug('Retrying...')
         self.connectionMade()
Exemplo n.º 4
0
 def connectionLost(self, reason=ConnectionDone):
     if isinstance(reason, ConnectionLost):
         self.errorOut('connection lost: {}'.format(reason))
     elif self.waiting_for_response:
         self.errorOut('Server closed connection without sending a response.')
     else:
         log.debug('connection terminated.')
Exemplo n.º 5
0
 def sendRequest(self, command, **params):
     self.sent_request = DaqServerRequest(command, params)
     request_string = self.sent_request.serialize()
     log.debug('sending request: {}'.format(request_string))
     self.transport.write(''.join([request_string, '\r\n']))
     self.timeoutCallback = reactor.callLater(self.timeout, self.requestTimedOut)
     self.waiting_for_response = True
Exemplo n.º 6
0
 def waitForTransfersToCompleteAndExit(self):
     if self.transfers_in_progress:
         reactor.callLater(self.wait_delay,
                           self.waitForTransfersToCompleteAndExit)
     else:
         log.debug('Stopping the reactor.')
         reactor.stop()
Exemplo n.º 7
0
 def sendRequest(self, command, **params):
     self.sent_request = DaqServerRequest(command, params)
     request_string = self.sent_request.serialize()
     log.debug('sending request: {}'.format(request_string))
     self.transport.write(''.join([request_string, '\r\n']))
     self.timeoutCallback = reactor.callLater(self.timeout,
                                              self.requestTimedOut)
     self.waiting_for_response = True
Exemplo n.º 8
0
 def resumeProducing(self):
     if not self.proto:
         raise ProtocolError('resumeProducing called with no protocol set.')
     self._paused = False
     try:
         while not self._paused:
             line = self.fh.next().rstrip('\n') + '\r\n'
             self.proto.transport.write(line)
     except StopIteration:
         log.debug('Sent everything.')
         self.stopProducing()
Exemplo n.º 9
0
 def resumeProducing(self):
     if not self.proto:
         raise ProtocolError('resumeProducing called with no protocol set.')
     self._paused = False
     try:
         while not self._paused:
             line = self.fh.next().rstrip('\n') + '\r\n'
             self.proto.transport.write(line)
     except StopIteration:
         log.debug('Sent everything.')
         self.stopProducing()
 def resumeProducing(self):
     if not self.proto:
         raise ProtocolError('resumeProducing called with no protocol set.')
     self._paused = False
     try:
         while not self._paused:
             line = next(self.fh).rstrip('\n') + '\r\n'
             if sys.version_info[0] == 3:
                 self.proto.transport.write(line.encode('utf-8'))
             else:
                 self.proto.transport.write(line)
     except StopIteration:
         log.debug('Sent everything.')
         self.stopProducing()
 def __init__(self, config, command, timeout=10, retries=1):
     self.config = config
     self.command = command
     self.timeout = timeout
     self.retries = retries
     self.result = CommandResult()
     self.done = False
     self.transfers_in_progress = {}
     if command.name == 'get_data':
         if 'output_directory' not in command.params:
             self.errorOut('output_directory not specifed for get_data command.')
         self.output_directory = command.params['output_directory']
         if not os.path.isdir(self.output_directory):
             log.debug('Creating output directory {}'.format(self.output_directory))
             os.makedirs(self.output_directory)
Exemplo n.º 12
0
 def __init__(self, config, command, timeout=10, retries=1):
     self.config = config
     self.command = command
     self.timeout = timeout
     self.retries = retries
     self.result = CommandResult()
     self.done = False
     self.transfers_in_progress = {}
     if command.name == 'get_data':
         if 'output_directory' not in command.params:
             self.errorOut('output_directory not specifed for get_data command.')
         self.output_directory = command.params['output_directory']
         if not os.path.isdir(self.output_directory):
             log.debug('Creating output directory {}'.format(self.output_directory))
             os.makedirs(self.output_directory)
Exemplo n.º 13
0
    def perform_cleanup(self):
        """
        Cleanup and old uncollected data files to recover disk space.

        """
        log.msg('Performing cleanup of the output directory...')
        base_directory = self.server.base_output_directory
        current_time = datetime.now()
        for entry in os.listdir(base_directory):
            entry_path = os.path.join(base_directory, entry)
            entry_ctime = datetime.fromtimestamp(os.path.getctime(entry_path))
            existence_time = current_time - entry_ctime
            if existence_time > self.cleanup_threshold:
                log.debug('Removing {} (existed for {})'.format(entry, existence_time))
                shutil.rmtree(entry_path)
            else:
                log.debug('Keeping {} (existed for {})'.format(entry, existence_time))
        log.msg('Cleanup complete.')
    def perform_cleanup(self):
        """
        Cleanup and old uncollected data files to recover disk space.

        """
        log.msg('Performing cleanup of the output directory...')
        base_directory = self.server.base_output_directory
        current_time = datetime.now()
        for entry in os.listdir(base_directory):
            entry_path = os.path.join(base_directory, entry)
            entry_ctime = datetime.fromtimestamp(os.path.getctime(entry_path))
            existence_time = current_time - entry_ctime
            if existence_time > self.cleanup_threshold:
                log.debug('Removing {} (existed for {})'.format(
                    entry, existence_time))
                shutil.rmtree(entry_path)
            else:
                log.debug('Keeping {} (existed for {})'.format(
                    entry, existence_time))
        log.msg('Cleanup complete.')
Exemplo n.º 15
0
 def stop(self):
     self.is_running = False
     log.debug('Stopping DAQ Task.')
     self.task.StopTask()
     log.debug('Stopping sample processor.')
     self.processor.stop()
     log.debug('Runner stopped.')
Exemplo n.º 16
0
 def start(self):
     log.debug('Starting sample processor.')
     self.processor.start()
     log.debug('Starting DAQ Task.')
     self.task.StartTask()
     self.is_running = True
     log.debug('Runner started.')
 def start(self):
     log.debug('Starting sample processor.')
     self.processor.start()
     log.debug('Starting DAQ Task.')
     self.task.StartTask()
     self.is_running = True
     log.debug('Runner started.')
 def stop(self):
     self.is_running = False
     log.debug('Stopping DAQ Task.')
     self.task.StopTask()
     log.debug('Stopping sample processor.')
     self.processor.stop()
     log.debug('Runner stopped.')
Exemplo n.º 19
0
 def waitForTransfersToCompleteAndExit(self):
     if self.transfers_in_progress:
         reactor.callLater(self.wait_delay, self.waitForTransfersToCompleteAndExit)
     else:
         log.debug('Stopping the reactor.')
         reactor.stop()
Exemplo n.º 20
0
 def clientConnectionLost(self, connector, reason):
     if self.transfers_in_progress:
         log.debug('Waiting for the transfer(s) to complete.')
     self.waitForTransfersToCompleteAndExit()
Exemplo n.º 21
0
 def transferComplete(self, session):
     connector = self.transfers_in_progress[session]
     log.debug('Transfer on port {} complete.'.format(connector.port))
     del self.transfers_in_progress[session]
Exemplo n.º 22
0
 def initiateFileTransfer(self, filename, port):
     log.debug('Downloading {} from port {}'.format(filename, port))
     filepath = os.path.join(self.output_directory, filename)
     session = FileReceiverFactory(filepath, self)
     connector = reactor.connectTCP(self.config.host, port, session)
     self.transfers_in_progress[session] = connector
Exemplo n.º 23
0
 def initiateFileTransfer(self, filename, port):
     log.debug('Downloading {} from port {}'.format(filename, port))
     filepath = os.path.join(self.output_directory, filename)
     session = FileReceiverFactory(filepath, self)
     connector = reactor.connectTCP(self.config.host, port, session)
     self.transfers_in_progress[session] = connector
Exemplo n.º 24
0
 def transferComplete(self, session):
     connector = self.transfers_in_progress[session]
     log.debug('Transfer on port {} complete.'.format(connector.port))
     del self.transfers_in_progress[session]
Exemplo n.º 25
0
 def clientConnectionLost(self, connector, reason):
     if self.transfers_in_progress:
         log.debug('Waiting for the transfer(s) to complete.')
     self.waitForTransfersToCompleteAndExit()