Exemple #1
0
    def register_config(self, connection):
        if self.peer is None:
            raise NoPeerError()

        msg = cmsg.fill_msg(types.REGISTER_PEER_CONFIG, sender=self.peer_id)

        params = self.core.local_params
        cmsg.dict2params(params, msg)
        ext_params = self.core.ext_param_defs
        # register also external param definitions: param_name <---> (peer_id_of_config_source, param_name)
        for par in ext_params:
            ext_def = ext_params[par]
            symname = ext_def[0]
            ext_params[par] = (self.core.config_sources[symname], ext_def[1])

        cmsg.dict2params(ext_params, msg, field_name="ext_params")

        #connection.send_message(message=msg, type=types.REGISTER_PEER_CONFIG)
        reply = self.__query(connection, cmsg.pack_msg(msg),
                             types.REGISTER_PEER_CONFIG)
        #print 'AAAAAAAAAAAAAAAAAA', reply, "(rq:", types.REGISTER_PEER_CONFIG,\
        #                            "exp:", types.PEER_REGISTERED, ')'
        if reply is None:
            self.logger.error('config registration unsuccesful!!!! %s',
                              str(reply))
        elif not reply.type == types.PEER_REGISTERED:
            self.logger.error('config registration unsuccesful!!!! %s',
                              str(reply))
Exemple #2
0
    def register_config(self, connection):
        if self.peer is None:
            raise NoPeerError()

        msg = cmsg.fill_msg(types.REGISTER_PEER_CONFIG, sender=self.peer_id)

        params = self.core.local_params
        cmsg.dict2params(params, msg)
        ext_params = self.core.ext_param_defs
        # register also external param definitions: param_name <---> (peer_id_of_config_source, param_name)
        for par in ext_params:
            ext_def = ext_params[par]
            symname = ext_def[0]
            ext_params[par] = (self.core.config_sources[symname], ext_def[1])

        cmsg.dict2params(ext_params, msg, field_name="ext_params")

        # connection.send_message(message=msg, type=types.REGISTER_PEER_CONFIG)
        reply = self.__query(connection, cmsg.pack_msg(msg),
                             types.REGISTER_PEER_CONFIG)
        # print 'AAAAAAAAAAAAAAAAAA', reply, "(rq:", types.REGISTER_PEER_CONFIG,\
        #                            "exp:", types.PEER_REGISTERED, ')'
        if reply is None:
            self.logger.error('config registration unsuccesful!!!! %s',
                              str(reply))
        elif not reply.type == types.PEER_REGISTERED:
            self.logger.error('config registration unsuccesful!!!! %s',
                              str(reply))
Exemple #3
0
    def handle_config_message(self, mxmsg):

        if mxmsg.type in cmsg.MX_CFG_MESSAGES:
            message = cmsg.unpack_msg(mxmsg.type, mxmsg.message)

            msg, mtype = self._call_handler(mxmsg.type, message)
            if msg is None:
                self.peer.no_response()
            else:
                msg = cmsg.pack_msg(msg)
                self.peer.send_message(message=msg, type=mtype, to=int(mxmsg.from_), flush=True)
Exemple #4
0
    def _request_ext_params(self, connection, retries=400):
        #TODO set timeout and retry count
        self.logger.info("requesting external parameters")
        if self.peer is None:
            raise NoPeerError

        def _unset_param_count():
            return reduce(lambda x, y: x + y,
                            [len(self.core.unset_params_for_source(src)) \
                                for src in self.core.used_config_sources()], 0)

        ready, details = self.core.config_ready()
        while not ready and retries:
            for src in self.core.used_config_sources():
                params = self.core.unset_params_for_source(src).keys()

                msg = cmsg.fill_msg(types.GET_CONFIG_PARAMS,
                                    sender=self.peer_id,
                                    param_names=params,
                                    receiver=self.core.config_sources[src])

                #print "requesting: {0}".format(msg)
                reply = self.__query(connection, cmsg.pack_msg(msg),
                                     types.GET_CONFIG_PARAMS)

                if reply == None:
                    # raise something?
                    continue

                if reply.type == types.CONFIG_ERROR:
                    self.logger.warning("peer {0} has not yet started".format(
                        msg.receiver))

                elif reply.type == types.CONFIG_PARAMS:
                    reply_msg = cmsg.unpack_msg(reply.type, reply.message)
                    params = cmsg.params2dict(reply_msg)

                    for par, val in params.iteritems():
                        self.core.set_param_from_source(
                            reply_msg.sender, par, val)
                else:
                    self.logger.error("WTF? {0}".format(reply.message))

            # print '.',#"{0} external params still unset".format(_unset_param_count())
            time.sleep(0.4)
            ready, details = self.core.config_ready()
            retries -= 1

        if ready:
            self.logger.info("External parameters initialised %s",
                             str(self.core.config_ready()))

        return ready, details
Exemple #5
0
    def _request_ext_params(self, connection, retries=400):
        # TODO set timeout and retry count
        self.logger.info("requesting external parameters")
        if self.peer is None:
            raise NoPeerError

        def _unset_param_count():
            return reduce(lambda x, y: x + y,
                          [len(self.core.unset_params_for_source(src))
                           for src in self.core.used_config_sources()], 0)

        ready, details = self.core.config_ready()
        while not ready and retries:
            for src in self.core.used_config_sources():
                params = list(self.core.unset_params_for_source(src).keys())

                msg = cmsg.fill_msg(types.GET_CONFIG_PARAMS,
                                    sender=self.peer_id,
                                    param_names=params,
                                    receiver=self.core.config_sources[src])

                # print "requesting: {0}".format(msg)
                reply = self.__query(connection, cmsg.pack_msg(msg),
                                     types.GET_CONFIG_PARAMS)

                if reply is None:
                    # raise something?
                    continue

                if reply.type == types.CONFIG_ERROR:
                    self.logger.warning("peer {0} has not yet started".format(msg.receiver))

                elif reply.type == types.CONFIG_PARAMS:
                    reply_msg = cmsg.unpack_msg(reply.type, reply.message)
                    params = cmsg.params2dict(reply_msg)

                    for par, val in params.items():
                        self.core.set_param_from_source(reply_msg.sender, par, val)
                else:
                    self.logger.error("WTF? {0}".format(reply.message))

            # print '.',#"{0} external params still unset".format(_unset_param_count())
            time.sleep(0.4)
            ready, details = self.core.config_ready()
            retries -= 1

        if ready:
            self.logger.info("External parameters initialised %s",
                             str(self.core.config_ready()))

        return ready, details
Exemple #6
0
    def handle_config_message(self, mxmsg):

        if mxmsg.type in cmsg.MX_CFG_MESSAGES:
            message = cmsg.unpack_msg(mxmsg.type, mxmsg.message)

            msg, mtype = self._call_handler(mxmsg.type, message)
            if msg is None:
                self.peer.no_response()
            else:
                msg = cmsg.pack_msg(msg)
                self.peer.send_message(message=msg,
                                       type=mtype,
                                       to=int(mxmsg.from_),
                                       flush=True)
    def handle_message(self, mxmsg):

        message = cmsg.unpack_msg(mxmsg.type, mxmsg.message)

        msg, mtype, launcher_msg = self._call_handler(mxmsg.type, message)
        if msg is None:
            self.no_response()
        else:
            msg = cmsg.pack_msg(msg)
            if self.__to_all:
                self.send_message(message=msg, to=0, type=mtype, flush=True)
                self.__to_all = False
            else:
                self.send_message(message=msg, to=int(mxmsg.from_), type=mtype, flush=True)
        if launcher_msg is not None and self.launcher_sock is not None:
            self.logger.info('SENDING msg ' + launcher_msg[:100] + '[...]')
            send_msg(self.launcher_sock, launcher_msg)
            time.sleep(0.1) # TODO - temporary kind-of bug fix...
Exemple #8
0
    def handle_message(self, mxmsg):

        message = cmsg.unpack_msg(mxmsg.type, mxmsg.message)

        msg, mtype, launcher_msg = self._call_handler(mxmsg.type, message)
        if msg is None:
            self.no_response()
        else:
            msg = cmsg.pack_msg(msg)
            if self.__to_all:
                self.send_message(message=msg, to=0, type=mtype, flush=True)
                self.__to_all = False
            else:
                self.send_message(message=msg, to=int(mxmsg.from_), type=mtype, flush=True)
        if launcher_msg is not None and self.launcher_sock is not None:
            self.logger.info('SENDING msg ' + launcher_msg[:100] + '[...]')
            send_msg(self.launcher_sock, launcher_msg)
            time.sleep(0.1) # TODO - temporary kind-of bug fix...