def register_player(self): ''' register player to conductor ''' rtn = False if self.node_id: reply_to_conductor.register_player(self.node_id, self.connection, self.exchange, self.routing_key) rtn = True logger.debug( "Register as node_id ({node_id})".format(node_id=self.node_id)) admin_logger.debug( "{name} at {hostname} with node id {node_id} registered to conductor." .format(name=self.__class__.__name__, hostname=self.hostname, node_id=self.node_id)) else: # log errors logger.error( "{hostname} has no node_id".format(hostname=self.hostname)) admin_logger.error( "{name} at {hostname} with node id {node_id} failed to register to conductor. Please check {hostname}" .format(name=self.__class__.__name__, hostname=self.hostname, node_id=self.node_id)) return rtn
def test_ACK_COMMAND_DISCONNECT_PGPOOL(self): reply_to_conductor.register_player(112, self.__connection, conductor.exchange, Constants.CONDUCTOR_ROUTING_KEY) reply_to_conductor.register_player(115, self.__connection, conductor.exchange, Constants.CONDUCTOR_ROUTING_KEY) reply_to_conductor.acknowledgement_pgpool_disconnected(112, self.__connection, conductor.exchange, Constants.CONDUCTOR_ROUTING_KEY) time.sleep(2) player_tracker = PlayerTracker() self.assertTrue(player_tracker.is_pgpool_disconnected(112)) self.assertFalse(player_tracker.is_pgpool_disconnected(115))
def test_ACK_COMMAND_FIND_PLAYER(self): reply_to_conductor.register_player(112, self.__connection, conductor.exchange, Constants.CONDUCTOR_ROUTING_KEY) reply_to_conductor.register_player(115, self.__connection, conductor.exchange, Constants.CONDUCTOR_ROUTING_KEY) time.sleep(2) player_tracker = PlayerTracker() ids = player_tracker.get_player_ids(timeout=5) self.assertEqual(2, len(ids)) self.assertIn(112, ids) self.assertIn(115, ids)
def test_ACK_COMMAND_DISCONNECT_PGPOOL(self): reply_to_conductor.register_player(112, self.__connection, conductor.exchange, Constants.CONDUCTOR_ROUTING_KEY) reply_to_conductor.register_player(115, self.__connection, conductor.exchange, Constants.CONDUCTOR_ROUTING_KEY) reply_to_conductor.acknowledgement_pgpool_disconnected( 112, self.__connection, conductor.exchange, Constants.CONDUCTOR_ROUTING_KEY) time.sleep(2) player_tracker = PlayerTracker() self.assertTrue(player_tracker.is_pgpool_disconnected(112)) self.assertFalse(player_tracker.is_pgpool_disconnected(115))
def test_ACK_COMMAND_CONNECT_MASTER(self): reply_to_conductor.register_player(112, self.__connection, conductor.exchange, Constants.CONDUCTOR_ROUTING_KEY) reply_to_conductor.register_player(115, self.__connection, conductor.exchange, Constants.CONDUCTOR_ROUTING_KEY) time.sleep(2) player_tracker = PlayerTracker() self.assertFalse(player_tracker.is_replication_started(112)) self.assertFalse(player_tracker.is_replication_started(115)) reply_to_conductor.acknowledgement_master_disconnected(112, self.__connection, conductor.exchange, Constants.CONDUCTOR_ROUTING_KEY) time.sleep(2) self.assertTrue(player_tracker.is_replication_stopped(112)) self.assertFalse(player_tracker.is_replication_started(115)) reply_to_conductor.acknowledgement_master_connected(112, self.__connection, conductor.exchange, Constants.CONDUCTOR_ROUTING_KEY) time.sleep(2) self.assertTrue(player_tracker.is_replication_started(112)) self.assertFalse(player_tracker.is_replication_started(115))
def test_register_player(self): message, exchange, routing_key = register_player(111, self.__conn, self.__exchange, self.__routing_key) body = json.loads(message['body']) self.assertEqual(Constants.ACK_COMMAND_FIND_PLAYER, body[Constants.MESSAGE_ACK_COMMAND]) self.assertEqual(111, body[Constants.MESSAGE_NODE_ID]) self.assertEqual(self.__exchange.name, exchange) self.assertEqual(self.__routing_key, routing_key)
def test_register_player(self): message, exchange, routing_key = register_player( 111, self.__conn, self.__exchange, self.__routing_key) body = json.loads(message['body']) self.assertEqual(Constants.ACK_COMMAND_FIND_PLAYER, body[Constants.MESSAGE_ACK_COMMAND]) self.assertEqual(111, body[Constants.MESSAGE_NODE_ID]) self.assertEqual(self.__exchange.name, exchange) self.assertEqual(self.__routing_key, routing_key)
def register_player(self): ''' register player to conductor ''' rtn = False if self.node_id: reply_to_conductor.register_player(self.node_id, self.connection, self.exchange, self.routing_key) rtn = True logger.debug("Register as node_id ({node_id})".format(node_id=self.node_id)) admin_logger.debug("{name} at {hostname} with node id {node_id} registered to conductor.". format(name=self.__class__.__name__, hostname=self.hostname, node_id=self.node_id)) else: # log errors logger.error("{hostname} has no node_id".format(hostname=self.hostname)) admin_logger.error("{name} at {hostname} with node id {node_id} failed to register to conductor. Please check {hostname}". format(name=self.__class__.__name__, hostname=self.hostname, node_id=self.node_id)) return rtn
def test_ACK_COMMAND_CONNECT_MASTER(self): reply_to_conductor.register_player(112, self.__connection, conductor.exchange, Constants.CONDUCTOR_ROUTING_KEY) reply_to_conductor.register_player(115, self.__connection, conductor.exchange, Constants.CONDUCTOR_ROUTING_KEY) time.sleep(2) player_tracker = PlayerTracker() self.assertFalse(player_tracker.is_replication_started(112)) self.assertFalse(player_tracker.is_replication_started(115)) reply_to_conductor.acknowledgement_master_disconnected( 112, self.__connection, conductor.exchange, Constants.CONDUCTOR_ROUTING_KEY) time.sleep(2) self.assertTrue(player_tracker.is_replication_stopped(112)) self.assertFalse(player_tracker.is_replication_started(115)) reply_to_conductor.acknowledgement_master_connected( 112, self.__connection, conductor.exchange, Constants.CONDUCTOR_ROUTING_KEY) time.sleep(2) self.assertTrue(player_tracker.is_replication_started(112)) self.assertFalse(player_tracker.is_replication_started(115))
def register_player(self): reply_to_conductor.register_player(self.node_id, self.connection, self.exchange, self.routing_key)