def GetNodeProtocolInfo(self, n): def handler(message): if not message: logging.error("ProtocolInfo failed") return payload = message[4:-1] if len(payload) < 5: logging.error("bad ProtocolInfo payload: %s", message) return self._ProcessProtocolInfo(n, payload) logging.warning("[%d] GetNodeProtocolInfo", n) m = zmessage.MakeRawMessage(z.API_ZW_GET_NODE_PROTOCOL_INFO, [n]) self._SendMessage(n, m, zmessage.ControllerPriority(), handler)
def _UpdateIsFailedNode(self, n, cb): def handler(mesg): if mesg is None: return logging.info("[%s] is failed check: %d, %s", _NodeName(n), mesg[4], zmessage.PrettifyRawMessage(mesg)) failed = mesg[4] != 0 self._PushToListeners(n, time.time(), command.CUSTOM_COMMAND_FAILED_NODE, {"failed": failed}) if cb: cb(failed) m = zmessage.MakeRawMessage(z.API_ZW_IS_FAILED_NODE_ID, [n]) self._SendMessage(n, m, zmessage.ControllerPriority(), handler)
def _RequestNodeInfo(self, n, retries): """This usually triggers send "API_ZW_APPLICATION_UPDATE:""" def handler(_): # if we timeout m will be None if m is not None and m[4] != 0: return # success logging.warning("[%d] RequestNodeInfo failed: %s", n, zmessage.PrettifyRawMessage(m)) self._RequestNodeInfo(n, retries - 1) if retries > 0: logging.warning("[%d] RequestNodeInfo try:%d", n, retries) m = zmessage.MakeRawMessage(z.API_ZW_REQUEST_NODE_INFO, [n]) self._SendMessage(n, m, zmessage.ControllerPriority(), handler) else: logging.error("[%d] RequestNodeInfo failed permanently", n)
def SendCommand(self, func, data, handler): raw = zmessage.MakeRawMessage(func, data) mesg = zmessage.Message(raw, self.Priority(), handler, -1) self._mq.SendMessage(mesg)