Exemplo n.º 1
0
 def test_accept_players(self):
     with Conductor() as conductor1:
         conductor1.accept_players()
         PlayerTracker().add_player(12345)
         ids = conductor1.get_player_ids()
     self.assertEqual(1, len(ids))
     self.assertEqual(12345, ids[0])
def replication_admin_monitor(replication_lag_tolerance=100,
                              apply_lag_tolerance=100,
                              time_lag_tolerance=60,
                              interval_check=3600):
    while True:
        # use Conductor to check replication is ready to monitor.
        # if Conducotor is blocked, it means actual migration is in process.
        logger.debug('replication admin monitor prepare starting...')
        with Conductor(locktimeout=-1) as conductor:
            logger.debug('replication admin monitor starts')
            with RepMgrDBConnection() as connector:
                repl_status = connector.get_table(Constants.REPL_STATUS)
                query = get_repl_status_query(repl_status)
                status_records = connector.get_result(query)
                for status_record in status_records:
                    replication_ok = check_replication_ok(
                        status_record,
                        replication_lag_tolerance=replication_lag_tolerance,
                        apply_lag_tolerance=apply_lag_tolerance,
                        time_lag_tolerance=time_lag_tolerance)
                    if not replication_ok:
                        standby_node = status_record[
                            Constants.REPL_STANDBY_NODE]
                        logger.error('Node ID[' + str(standby_node) +
                                     '] is out of sync.')
                        admin_logger.error('Replication monitor: Node ID[' +
                                           str(standby_node) +
                                           '] is out of sync.')
            logger.debug('replication admin monitor finishes')
        if interval_check < 0:
            break
        time.sleep(interval_check)
 def test_is_migration_in_process(self):
     playertracker1 = PlayerTracker()
     self.assertFalse(playertracker1.is_migration_in_process())
     conductor = Conductor()
     self.assertTrue(playertracker1.is_migration_in_process())
     del conductor
     self.assertFalse(playertracker1.is_migration_in_process())
Exemplo n.º 4
0
 def test_reject_players(self):
     tested = False
     with Conductor() as conductor1:
         conductor1.reject_players()
         playerTracker = PlayerTracker()
         self.assertRaises(PlayerDelayedRegistrationException, playerTracker.add_player, 123123)
         tested = True
     self.assertTrue(tested)
Exemplo n.º 5
0
 def test_send_reset_players(self):
     with Conductor() as conductor1:
         conductor1.send_reset_players()
         self.assertRaises(Empty, Test._queue.get, timeout=1)
         playerTracker = PlayerTracker()
         playerTracker.set_accept_player(True)
         playerTracker.add_player(222)
         playerTracker.set_accept_player(False)
         conductor1.send_reset_players()
         message = Test._queue.get(timeout=5)
     self.assertEqual(Constants.ACK_COMMAND_RESET_PLAYERS, message.payload[Constants.MESSAGE_ACK_COMMAND])
Exemplo n.º 6
0
 def test_send_start_replication(self):
     with Conductor() as conductor1:
         conductor1.send_start_replication()
         self.assertRaises(Empty, Test._queue.get, timeout=1)
         playerTracker = PlayerTracker()
         playerTracker.set_accept_player(True)
         playerTracker.add_player(222)
         playerTracker.set_accept_player(False)
         conductor1.send_start_replication()
         message = Test._queue.get(timeout=5)
     self.assertEqual(Constants.ACK_COMMAND_START_REPLICATION, message.payload[Constants.MESSAGE_ACK_COMMAND])
Exemplo n.º 7
0
 def test_send_disconnect_PGPool(self):
     with Conductor() as conductor1:
         conductor1.send_disconnect_PGPool()
         self.assertRaises(Empty, Test._queue.get, timeout=1)
         playerTracker = PlayerTracker()
         playerTracker.set_accept_player(True)
         playerTracker.add_player(222)
         playerTracker.set_accept_player(False)
         conductor1.send_disconnect_PGPool()
         message = Test._queue.get(timeout=5)
     self.assertEqual(Constants.ACK_COMMAND_DISCONNECT_PGPOOL, message.payload[Constants.MESSAGE_ACK_COMMAND])
Exemplo n.º 8
0
 def test_wait_replication_started(self):
     tested = False
     with Conductor() as conductor1:
         playerTracker = PlayerTracker()
         playerTracker.set_accept_player(True)
         playerTracker.add_player(222)
         playerTracker.set_accept_player(False)
         self.assertRaises(ConductorTimeoutException, conductor1.wait_replication_started, timeout=1)
         playerTracker.set_replication_started(222)
         conductor1.wait_replication_started(timeout=1)
         tested = True
     self.assertTrue(tested)
Exemplo n.º 9
0
 def test_grouping_players(self):
     tested = False
     with Conductor() as conductor1:
         playerTracker = PlayerTracker()
         playerTracker.set_accept_player(True)
         playerTracker.add_player(123)
         playerTracker.add_player(222)
         playerTracker.add_player(333)
         playerTracker.add_player(444)
         playerTracker.set_accept_player(False)
         conductor1.grouping_players()
         groupA = playerTracker.get_player_ids(Constants.PLAYER_GROUP_A)
         self.assertEqual(2, len(groupA))
         groupB = playerTracker.get_player_ids(Constants.PLAYER_GROUP_B)
         self.assertEqual(2, len(groupB))
         tested = True
     self.assertTrue(tested)
Exemplo n.º 10
0
 def test_get_player_ids(self):
     tested = False
     with Conductor() as conductor1:
         playerTracker = PlayerTracker()
         playerTracker.set_accept_player(True)
         playerTracker.add_player(123)
         playerTracker.add_player(222)
         playerTracker.add_player(333)
         playerTracker.add_player(444)
         playerTracker.set_accept_player(False)
         self.assertRaises(PlayerDelayedRegistrationException, playerTracker.add_player, 123123)
         ids = conductor1.get_player_ids()
         self.assertEqual(4, len(ids))
         self.assertIn(123, ids)
         self.assertIn(222, ids)
         self.assertIn(333, ids)
         self.assertIn(444, ids)
         ids = playerTracker.get_player_ids(Constants.PLAYER_GROUP_A)
         self.assertEqual(0, len(ids))
         tested = True
     self.assertTrue(tested)
def process_conductor(player_find_time_wait=5, replication_lag_tolerance=100, apply_lag_tolerance=100, time_lag_tolerance=100, monitor_timeout=28800, mail_server=None, mail_sender=None, tenant=None):
    logger.debug('conductor process started')
    batch = get_batches_to_migrate(tenant=tenant)
    if batch:
        with Conductor(replication_lag_tolerance=replication_lag_tolerance, apply_lag_tolerance=apply_lag_tolerance, time_lag_tolerance=time_lag_tolerance, monitor_timeout=monitor_timeout) as conductor:
            conductor.accept_players()
            conductor.find_players()
            time.sleep(player_find_time_wait)
            conductor.reject_players()
            conductor.send_reset_players()
            players_ids = conductor.get_player_ids()
            if players_ids:
                number_of_players = len(players_ids)
                if number_of_players == 1:
                    single_player_process(conductor, tenant=tenant)
                else:
                    regular_process(conductor, tenant=tenant)
            else:
                logger.info('No player was detected')
                admin_logger.info('No player was detected by the conductor')
    else:
        logger.debug('no batch to process')
        admin_logger.info('no batch found to process')
    send_notifications(mail_server, mail_sender)
Exemplo n.º 12
0
 def test_find_players(self):
     with Conductor() as conductor1:
         conductor1.find_players()
         message = Test._queue.get(timeout=5)
     self.assertEqual(Constants.ACK_COMMAND_FIND_PLAYER, message.payload[Constants.MESSAGE_ACK_COMMAND])
     self.assertEqual(222, message.payload[Constants.MESSAGE_NODE_ID])
Exemplo n.º 13
0
 def test_conductor_lock(self):
     tested = False
     with Conductor() as conductor1:
         self.assertRaises(ConductorTimeoutException, Conductor, locktimeout=1)
         tested = True
     self.assertTrue(tested)