コード例 #1
0
ファイル: api.py プロジェクト: rackerlabs/otter
def setup_selfheal_service(clock, config, dispatcher, health_checker, log):
    """
    Setup selfheal timer service and return it.

    :param clock: :obj:`IReactorTime` provider
    :param dict config: Configuration dict containing selfheal info
    :param dispatcher: Effect dispatcher
    :param health_checker: ``HealthChecker`` object where SelfHeal's health
        check will be added
    :param log: :obj:`BoundLog` logger used by service

    :return: selfheal service or None if relevant config is not found
    :rtype: :obj:`IService`
    """
    if "selfheal" not in config:
        return None
    interval = get_in(["selfheal", "interval"], config, no_default=True)
    selfheal = SelfHeal(clock, dispatcher, config_value, interval, log)
    func, lock = zk.locked_logged_func(
        dispatcher, "/selfheallock", log, "selfheal-lock-acquired",
        selfheal.setup)
    health_checker.checks["selfheal"] = zk.create_health_check(lock)
    sh_timer = TimerService(interval, func)
    sh_timer.clock = clock
    return sh_timer
コード例 #2
0
def setup_selfheal_service(clock, config, dispatcher, health_checker, log):
    """
    Setup selfheal timer service and return it.

    :param clock: :obj:`IReactorTime` provider
    :param dict config: Configuration dict containing selfheal info
    :param dispatcher: Effect dispatcher
    :param health_checker: ``HealthChecker`` object where SelfHeal's health
        check will be added
    :param log: :obj:`BoundLog` logger used by service

    :return: selfheal service or None if relevant config is not found
    :rtype: :obj:`IService`
    """
    if "selfheal" not in config:
        return None
    interval = get_in(["selfheal", "interval"], config, no_default=True)
    selfheal = SelfHeal(clock, dispatcher, config_value, interval, log)
    func, lock = zk.locked_logged_func(dispatcher, "/selfheallock", log,
                                       "selfheal-lock-acquired",
                                       selfheal.setup)
    health_checker.checks["selfheal"] = zk.create_health_check(lock)
    sh_timer = TimerService(interval, func)
    sh_timer.clock = clock
    return sh_timer
コード例 #3
0
ファイル: test_zk.py プロジェクト: rackerlabs/otter
    def test_composition(self):
        """
        Ensure :func:`locked` and :func:`add_acquired_log` are called in
        sequence with correct parameters
        """
        self.patch(zk, "PollingLock", exp_func(self, "lock", "disp", "/path"))
        self.patch(zk, "locked",
                   exp_func(self, "locked_f", "lock", "disp", "func", 1))
        self.patch(zk, "add_acquired_log",
                   exp_func(self, "llf", "log", "msg", "locked_f"))

        wf, lock = zk.locked_logged_func("disp", "/path", "log", "msg",
                                         "func", 1)

        self.assertEqual(wf, "llf")
        self.assertEqual(lock, "lock")
コード例 #4
0
ファイル: test_zk.py プロジェクト: stephamon/otter
    def test_composition(self):
        """
        Ensure :func:`locked` and :func:`add_acquired_log` are called in
        sequence with correct parameters
        """
        self.patch(zk, "PollingLock", exp_func(self, "lock", "disp", "/path"))
        self.patch(zk, "locked",
                   exp_func(self, "locked_f", "lock", "disp", "func", 1))
        self.patch(zk, "add_acquired_log",
                   exp_func(self, "llf", "log", "msg", "locked_f"))

        wf, lock = zk.locked_logged_func("disp", "/path", "log", "msg", "func",
                                         1)

        self.assertEqual(wf, "llf")
        self.assertEqual(lock, "lock")