Example #1
0
 def __init__(self, clock, store_query, manager):
     self._runner = RecurringTask(3, self._do_update)
     self.store_query = store_query
     self.manager = manager
     self._limiter = TokenBucketRateLimiter(clock, 10, 30)
     self.start = self._runner.start
     self.stop = self._runner.stop
Example #2
0
 def __init__(self, clock, store_query, manager, policy):
     self._runner = RecurringTask(3, self._do_schedule)
     self.clock = clock
     self.store_query = store_query
     self.manager = manager
     self.policy = policy
     self._limiter = TokenBucketRateLimiter(clock, 10, 30)
     self.start = self._runner.start
     self.stop = self._runner.stop
Example #3
0
 def __init__(self, clock, store_query, manager):
     self._runner = RecurringTask(3, self._do_update)
     self.store_query = store_query
     self.manager = manager
     self._limiter = TokenBucketRateLimiter(clock, 10, 30)
     self.start = self._runner.start
     self.stop = self._runner.stop
Example #4
0
class Updater(object):
    log = logging.getLogger('scheduler.updater')

    def __init__(self, clock, store_query, manager):
        self._runner = RecurringTask(3, self._do_update)
        self.store_query = store_query
        self.manager = manager
        self._limiter = TokenBucketRateLimiter(clock, 10, 30)
        self.start = self._runner.start
        self.stop = self._runner.stop

    def _equal_instance_container(self, inst, cont):
        inst_env = inst.env or {}
        cont_env = cont.env or {}
        inst_ports = inst.ports or []
        cont_ports = cont.ports or []
        return (inst.image == cont.image
                and inst.command == cont.command
                and inst_env == cont_env
                and inst_ports == cont_ports)

    def _do_update(self):
        instances = list(self.store_query.index())
        for instance, container in zip(
                instances, self.manager.containers(instances)):
            if container is None:
                continue
            if not _is_running(instance):
                continue
            if not self._equal_instance_container(instance, container):
                if not self._limiter.check():
                    break
                self.log.info("restarting %s/%s because of config change" % (
                        instance.formation, instance.name))
                instance.restart(self.manager)
            elif instance.state == instance.STATE_MIGRATING:
                if not self._limiter.check():
                    break
                # XXX: special case for instances that are stuck in
                # migrating but migration has happened, but it has not
                # been recoreded. this can happen when we're migrating
                # outselves.
                self.log.info("setting merging instance %s/%s to running" % (
                        instance.formation, instance.name))
                instance.update(state=instance.STATE_RUNNING)
Example #5
0
 def __init__(self, clock, store_query, manager, policy):
     self._runner = RecurringTask(3, self._do_schedule)
     self.clock = clock
     self.store_query = store_query
     self.manager = manager
     self.policy = policy
     self._limiter = TokenBucketRateLimiter(clock, 10, 30)
     self.start = self._runner.start
     self.stop = self._runner.stop
Example #6
0
class Updater(object):
    log = logging.getLogger('scheduler.updater')

    def __init__(self, clock, store_query, manager):
        self._runner = RecurringTask(3, self._do_update)
        self.store_query = store_query
        self.manager = manager
        self._limiter = TokenBucketRateLimiter(clock, 10, 30)
        self.start = self._runner.start
        self.stop = self._runner.stop

    def _equal_instance_container(self, inst, cont):
        inst_env = inst.env or {}
        cont_env = cont.env or {}
        inst_ports = inst.ports or []
        cont_ports = cont.ports or []
        return (inst.image == cont.image and inst.command == cont.command
                and inst_env == cont_env and inst_ports == cont_ports)

    def _do_update(self):
        instances = list(self.store_query.index())
        for instance, container in zip(instances,
                                       self.manager.containers(instances)):
            if container is None:
                continue
            if not _is_running(instance):
                continue
            if not self._equal_instance_container(instance, container):
                if not self._limiter.check():
                    break
                self.log.info("restarting %s/%s because of config change" %
                              (instance.formation, instance.name))
                instance.restart(self.manager)
            elif instance.state == instance.STATE_MIGRATING:
                if not self._limiter.check():
                    break
                # XXX: special case for instances that are stuck in
                # migrating but migration has happened, but it has not
                # been recoreded. this can happen when we're migrating
                # outselves.
                self.log.info("setting merging instance %s/%s to running" %
                              (instance.formation, instance.name))
                instance.update(state=instance.STATE_RUNNING)
Example #7
0
class Terminator(object):
    """Process responsible for moving instances from "shutting down"
    into "terminated" by killing them off.
    """
    def __init__(self, clock, store_query, manager):
        self._runner = RecurringTask(3, self._do_terminate)
        self.store_query = store_query
        self.manager = manager
        self._limiter = TokenBucketRateLimiter(clock, 10, 30)
        self.start = self._runner.start
        self.stop = self._runner.stop

    def _do_terminate(self):
        for instance in self.store_query.shutting_down():
            if not self._limiter.check():
                break
            instance.terminate(self.manager)
Example #8
0
class Terminator(object):
    """Process responsible for moving instances from "shutting down"
    into "terminated" by killing them off.
    """

    def __init__(self, clock, store_query, manager):
        self._runner = RecurringTask(3, self._do_terminate)
        self.store_query = store_query
        self.manager = manager
        self._limiter = TokenBucketRateLimiter(clock, 10, 30)
        self.start = self._runner.start
        self.stop = self._runner.stop

    def _do_terminate(self):
        for instance in self.store_query.shutting_down():
            if not self._limiter.check():
                break
            instance.terminate(self.manager)
Example #9
0
class Scheduler(object):
    def __init__(self, clock, store_query, manager, policy):
        self._runner = RecurringTask(3, self._do_schedule)
        self.clock = clock
        self.store_query = store_query
        self.manager = manager
        self.policy = policy
        self._limiter = TokenBucketRateLimiter(clock, 10, 30)
        self.start = self._runner.start
        self.stop = self._runner.stop

    def _do_schedule(self):
        for instance in self.store_query.unassigned():
            if not self._limiter.check():
                break
            if instance.assigned_to:
                instance.dispatch(self.manager, instance.assigned_to)
            else:
                executor = self.policy.select(self.manager.clients(),
                                              instance.placement or {})
                if executor is not None:
                    instance.dispatch(self.manager, executor.name)
Example #10
0
class Scheduler(object):

    def __init__(self, clock, store_query, manager, policy):
        self._runner = RecurringTask(3, self._do_schedule)
        self.clock = clock
        self.store_query = store_query
        self.manager = manager
        self.policy = policy
        self._limiter = TokenBucketRateLimiter(clock, 10, 30)
        self.start = self._runner.start
        self.stop = self._runner.stop
        
    def _do_schedule(self):
        for instance in self.store_query.unassigned():
            if not self._limiter.check():
                break
            if instance.assigned_to:
                instance.dispatch(self.manager, instance.assigned_to)
            else:
                executor = self.policy.select(self.manager.clients(),
                                              instance.placement or {})
                if executor is not None:
                    instance.dispatch(self.manager, executor.name)