diff --git a/marathon_lb.py b/marathon_lb.py index a8584c41..60857eb7 100755 --- a/marathon_lb.py +++ b/marathon_lb.py @@ -126,7 +126,7 @@ class MarathonService(object): def __init__(self, appId, servicePort, healthCheck, strictMode): self.appId = appId self.servicePort = servicePort - self.backends = set() + self.backends = {} self.hostname = None self.proxypath = None self.revproxypath = None @@ -156,7 +156,21 @@ def __init__(self, appId, servicePort, healthCheck, strictMode): self.mode = 'http' def add_backend(self, host, ip, port, draining): - self.backends.add(MarathonBackend(host, ip, port, draining)) + """ + A backend server is unique by host, ip and port, not include draining + property. When backend servers repeated, the draining property should + be true if any server is draining. + """ + backend = MarathonBackend(host, ip, port, draining) + if backend in self.backends: + oldBackend = self.backends[backend] + msg_fmt = ("backend server(%s, %s, %d, %s) duplicated, exists" + "draining status is: %s") + logger.warning(msg_fmt, host, ip, port, draining, + oldBackend.draining) + oldBackend.draining = oldBackend.draining or draining + else: + self.backends[backend] = backend def __hash__(self): return hash(self.servicePort)