def deadHost(self, senderFactory, reason='', doLog=True): """ This method gets called when a proxied host is unreachable. """ # if this throws an exception here, I think it's because all the hosts # have been removed from the pool try: epochTime, hostPort = self.openconns[senderFactory] except KeyError: if doLog: msg = """Wow, Bender says "We're boned." No hosts available.\n""" logging.log(msg) return if not self.failed.has_key(hostPort): self.failed[hostPort] = 1 else: self.failed[hostPort] += 1 if hostPort in self.hosts: if doLog: logging.log("marking host %s down (%s)\n" % ( str(hostPort), reason.getErrorMessage())) self.hosts.remove(hostPort) if self.available.has_key(hostPort): del self.available[hostPort] # XXX I don't think we want to delete the previously gathered stats for # the hosts that go bad... I'll keep this code here (but commented out) # in case there's a good reason for it and I'm nost not thinking of it # right now #if self.totalconns.has_key(hostPort): # del self.totalconns[hostPort] self.badhosts[hostPort] = (time.time(), reason) # make sure we also mark this session as done. self.doneHost(senderFactory)
def clientConnectionFailed(self, connector, reason): """ """ # without overriding, this would hang up the inbound. We don't want # that self.receiver.factory.tracker.deadHost(self, reason) next = self.receiver.factory.tracker.getHost( self, self.receiver.client_addr) if next: logging.log("retrying with %s\n" % repr(next)) host, port = next reactor.connectTCP(host, port, self) else: # No working servers!? logging.log("no working servers, manager -> aggressive\n") self.receiver.transport.loseConnection()
def checkBadHosts(configuration, director): """ This function checks the director's hosts marked as "unavailable" and puts them back into use. """ if not configuration.manager.hostCheckEnabled: return for name, service in director.getServices(): # since all proxies for a service share a tracker, # we only need to check the first proxy. group = service.getEnabledGroup() tracker = director.getTracker(name, group.name) badHosts = tracker.badhosts for hostPort, timeAndError in badHosts.items(): when, what = badHosts[hostPort] logging.log("re-adding %s automatically\n" % str(hostPort)) hostname = tracker.getHostNames()[hostPort] del badHosts[hostPort] tracker.newHost(hostPort, hostname)
def dataReceived(self, data): if self.receiver is None: logging.log("client got data, no receiver, tho\n") else: self.receiver.transport.write(data)