Skip to content

Commit

Permalink
fixed #10
Browse files Browse the repository at this point in the history
  • Loading branch information
dcvan24 committed Mar 21, 2018
1 parent e588d7c commit 3fc5ee3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion container/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class ContainerManager(Loggable, metaclass=Singleton):

CONTAINER_REC_TTL = timedelta(seconds=5)
CONTAINER_REC_TTL = timedelta(seconds=3)

def __init__(self, config):
self.__config = config
Expand Down
20 changes: 18 additions & 2 deletions container/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class HealthCheck:

def __init__(self, path, protocol='TCP', port_index=0, max_consecutive_failures=3,
def __init__(self, path='/', protocol='MESOS_TCP', port_index=0, max_consecutive_failures=3,
grace_period_seconds=300, interval_seconds=60, timeout_seconds=20):
self.__path = path
self.__protocol = protocol
Expand Down Expand Up @@ -64,12 +64,13 @@ def to_request(self):

class Service(Container):

def __init__(self, instances=1, labels={}, health_checks=[],
def __init__(self, instances=1, labels={}, health_checks=[], default_health_checks=True,
maximum_capacity=1., minimum_capacity=1., **kwargs):
super(Service, self).__init__(**kwargs)
self.__instances = instances
self.__labels = dict(labels)
self.__health_checks = [HealthCheck(**hc) for hc in health_checks]
self.__default_health_checks = default_health_checks
self.__minimum_capacity = minimum_capacity
self.__maximum_capacity = maximum_capacity

Expand All @@ -85,6 +86,10 @@ def labels(self):
def health_checks(self):
return list(self.__health_checks)

@property
def default_health_checks(self):
return self.__default_health_checks

@property
def maximum_capacity(self):
return self.__maximum_capacity
Expand Down Expand Up @@ -138,18 +143,22 @@ def to_render(self):
instances=self.instances,
labels=self.labels,
health_checks=[hc.to_render() for hc in self.health_checks],
default_health_checks=self.default_health_checks,
maximum_capacity=self.__maximum_capacity,
minimum_capacity=self.minimum_capacity)

def to_save(self):
self._add_default_health_checks()
return dict(**super(Service, self).to_save(),
instances=self.instances,
labels=self.labels,
health_checks=[hc.to_save() for hc in self.health_checks],
default_health_checks=self.default_health_checks,
maximum_capacity=self.__maximum_capacity,
minimum_capacity=self.minimum_capacity)

def to_request(self):
self._add_default_health_checks()
r = dict(id=str(self), instances=self.instances,
**self.resources.to_request(),
env={k: parse_container_short_id(v, self.appliance)
Expand Down Expand Up @@ -196,6 +205,13 @@ def to_request(self):
r.setdefault('constraints', []).append(['hostname', 'CLUSTER', self.host])
return r

def _add_default_health_checks(self):
if not self.health_checks and self.default_health_checks:
for i, p in enumerate(self.ports):
if p.protocol != 'tcp':
continue
self.add_health_check(HealthCheck(port_index=i))

def __str__(self):
return '/%s/%s'%(self.appliance, self.id)

Expand Down

0 comments on commit 3fc5ee3

Please sign in to comment.