def _create_event_triggers(self):
        triggers = self._config["triggers"]
        sup_tr = triggers["support"]
        user_support = ev.Trigger(
            prob_check=pck.ProbCheck(sup_tr["get_called"]),
            node_check=dck.AnyDepCheck(dck.NeqCheck("run")),
            event_builder=ev.EventBuilder(
                "User complained for poor web service"))
        webs1 = ev.Trigger(
            node_check=dck.OrCheck(
                dck.EqCheck("stop"), dck.DepCheck(dck.EqCheck("off")),
                dck.DepCheck(dck.DepCheck(dck.EqCheck("off")))),
            prob_check=pck.NoProbCheck(),
            event_builder=ev.EventBuilder("Application is down"))
        webs2 = ev.Trigger(
            node_check=dck.EqCheck("slow"),
            prob_check=pck.NoProbCheck(),
            event_builder=ev.EventBuilder("Application is slow"))
        host = ev.Trigger(
            node_check=dck.OrCheck(dck.EqCheck("off"),
                                   dck.DepCheck(dck.EqCheck("off"))),
            prob_check=pck.NoProbCheck(),
            event_builder=ev.EventBuilder("Host is unreachable or down"))
        switch = ev.Trigger(
            node_check=dck.EqCheck("off"),
            prob_check=pck.NoProbCheck(),
            event_builder=ev.EventBuilder("Switch is unreachable or down"))

        return {
            "switch": switch,
            "host": host,
            "web_service": [webs1, webs2],
            "support": user_support
        }
Exemplo n.º 2
0
 def test_second_order_dep_check(self):
     state = DummyState()
     state1 = DummyState()
     state.dependencies.append(state1)
     state1.dependencies.append(DummyState(1))
     dc = dck.DepCheck(dck.DepCheck(dck.EqCheck(1)))
     self.assertTrue(dc(state))
     state = DummyState()
     self.assertFalse(dc(state))
     self.assertFalse(dc(state1))
Exemplo n.º 3
0
 def test_combiner_or_dep_check(self):
     state = DummyState()
     state1 = DummyState(1)
     state.dependencies.append(state1)
     state1.dependencies.append(DummyState(2))
     dc = dck.OrCheck(c1=dck.DepCheck(dck.EqCheck(1)),
                      c2=dck.DepCheck(dck.DepCheck(dck.EqCheck(2))))
     self.assertTrue(dc(state))
     self.assertFalse(dc(state1))
     state1.dependencies[0].state = 1
     self.assertTrue(dc(state))
     self.assertTrue(dc(state1))
     state1.state = 2
     self.assertFalse(dc(state))
     state = DummyState()
     self.assertFalse(dc(state))
Exemplo n.º 4
0
    def __init__(self, from_state, to_state, prob_check, deps_check=None):
        """Create a new Transition instance.

        :param from_state: precondition for the node. It must be in this
        state in order to have a chance to be promoted into `to_state`
        :param to_state: next state if the condition is met.
        :param prob_check: the markov condition.
        :param deps_check: deterministic check performed on dependencies.
        """
        self._from_state = from_state
        self._to_state = to_state
        if deps_check is not None:
            self._deps_check = sc.DepCheck(deps_check)
        else:
            self._deps_check = sc.TrueCheck()
        self._prob_check = prob_check
    def _create_markov_chain_models(self):
        transitions = self._config["transitions"]

        # Switch Transitions
        sw_tr = transitions["switch"]
        tr1 = tr.Transition(from_state="on",
                            to_state="off",
                            prob_check=pck.ProbCheck(sw_tr["on=>off"]))
        tr2 = tr.Transition(from_state="off",
                            to_state="on",
                            prob_check=pck.ProbCheck(sw_tr["off=>on"]))
        switch_mc = tr.MarkovChain([tr1, tr2])

        # Host Transitions
        hs_tr = transitions["host"]
        tr1 = tr.Transition(from_state="on",
                            to_state="off",
                            prob_check=pck.ProbCheck(hs_tr["on=>off"]))
        tr2 = tr.Transition(from_state="off",
                            to_state="on",
                            prob_check=pck.ProbCheck(hs_tr["off=>on"]))
        host_mc = tr.MarkovChain([tr1, tr2])

        # Web service Transitions
        ws_tr = transitions["web_service"]
        tr1 = tr.Transition(from_state="run",
                            to_state="stop",
                            prob_check=pck.NoProbCheck(),
                            deps_check=dck.EqCheck("off"))
        tr2 = tr.Transition(from_state="slow",
                            to_state="stop",
                            prob_check=pck.NoProbCheck(),
                            deps_check=dck.EqCheck("off"))
        tr3 = tr.Transition(from_state="slow",
                            to_state="run",
                            prob_check=pck.NoProbCheck(),
                            deps_check=dck.AndCheck(
                                dck.EqCheck("on"),
                                dck.DepCheck(dck.EqCheck("off"))))
        tr4 = tr.Transition(from_state="run",
                            to_state="slow",
                            prob_check=pck.ProbCheck(ws_tr["run=>slow"]),
                            deps_check=dck.AndCheck(
                                dck.EqCheck("on"),
                                dck.DepCheck(dck.EqCheck("on"))))
        tr5 = tr.Transition(from_state="slow",
                            to_state="run",
                            prob_check=pck.ProbCheck(ws_tr["slow=>run"]),
                            deps_check=dck.AndCheck(
                                dck.EqCheck("on"),
                                dck.DepCheck(dck.EqCheck("on"))))
        tr6 = tr.Transition(from_state="stop",
                            to_state="run",
                            prob_check=pck.ProbCheck(ws_tr["stop=>run"]),
                            deps_check=dck.EqCheck("on"))
        webs_mc = tr.MarkovChain([tr1, tr2, tr3, tr4, tr5, tr6])

        # User support markov chain
        sup_mc = tr.MarkovChain([])

        return {
            "switch": switch_mc,
            "host": host_mc,
            "web_service": webs_mc,
            "support": sup_mc
        }