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))
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))
def run(self): conn = connect_client(type=peers.CONFIGURER, addresses=settings.MULTIPLEXER_ADDRESSES) time.sleep(4) for i in range(5): msg = cmsg.fill_msg(types.UPDATE_PARAMS, sender="p_a") params = dict(p=str(i)) cmsg.dict2params(params, msg) try: conn.send_message(message=msg, type=types.UPDATE_PARAMS) resp, sth = conn.receive_message() msg = cmsg.unpack_msg(resp.type, resp.message) print "got ", msg except Exception as e: print "error: ", e.args, " ", type(e) print i
def set_param(self, p_name, p_value): result = self.core.update_local_param(p_name, p_value) #TODO let know other peers... if self.query_conn: msg = cmsg.fill_msg(types.UPDATE_PARAMS, sender=self.peer_id) params = {p_name: p_value} cmsg.dict2params(params, msg) reply = self.__query(self.query_conn, msg, types.UPDATE_PARAMS) #self.connection.send_message(message=msg, type=types.UPDATE_PARAMS) val_short = str(p_value)[:300] + '[...]' self.logger.info(' param update:: %s %s', p_name, val_short) else: self.logger.warning('param updated locally %s, %s, %s', p_name, val_short, str(result)) return result
def set_param(self, p_name, p_value): result = self.core.update_local_param(p_name, p_value) # TODO let know other peers... if self.query_conn: msg = cmsg.fill_msg(types.UPDATE_PARAMS, sender=self.peer_id) params = {p_name: p_value} cmsg.dict2params(params, msg) self.__query(self.query_conn, msg, types.UPDATE_PARAMS) # self.connection.send_message(message=msg, type=types.UPDATE_PARAMS) val_short = str(p_value)[:300] + '[...]' self.logger.info(' param update:: %s %s', p_name, val_short) else: self.logger.warning('param updated locally %s, %s, %s', p_name, val_short, str(result)) return result
def handle_get_config_params(self, message_obj): param_owner = message_obj.receiver names = message_obj.param_names if param_owner == 'config_server': params = dict(experiment_uuid=self.exp_uuid) # elif param_owner not in self._configs: # return cmsg.fill_msg(types.CONFIG_ERROR), types.CONFIG_ERROR, None else: #TODO error when param_name does not exist? # params = {} # for name in names: # if name in self._configs[param_owner]: # params[name] = self._configs[param_owner][name] params = self._get_params(param_owner, names) if isinstance(params, tuple): return params mtype = types.CONFIG_PARAMS msg = cmsg.fill_msg(mtype, sender=param_owner) cmsg.dict2params(params, msg) return msg, mtype, None
def handle_update_params(self, message_obj): params = cmsg.params2dict(message_obj) param_owner = message_obj.sender if param_owner not in self._configs: launcher_msg = None return cmsg.fill_msg(types.CONFIG_ERROR, error_str="Peer unknown: {0}".format(param_owner)),\ types.CONFIG_ERROR,\ launcher_msg updated = {} for param in params: if param in self._configs[param_owner]: self._configs[param_owner][param] = params[param] updated[param] = params[param] if updated: mtype = types.PARAMS_CHANGED msg = cmsg.fill_msg(types.PARAMS_CHANGED, sender=param_owner) cmsg.dict2params(updated, msg) launcher_msg = self.mtool.fill_msg('obci_peer_params_changed', peer_id=param_owner, params=updated) self._save_config() return msg, mtype, launcher_msg return None, None, None