Example #1
0
 def on_died(self, agent, brothers, monitor):
     agent.info("Shard partner died.")
     if agent.is_migrating():
         return
     recipients = map(operator.attrgetter("recipient"), brothers)
     task = agent.collectively_restart_shard(recipients, self.recipient.key, monitor)
     return partners.accept_responsability(task)
Example #2
0
    def testSimpleCheckinsAndCancels(self):
        # First query shard structure and make asserts on the result
        self.info("Starting test testcase.")
        resp = yield self.export_agent.get_shard_structure()
        self.assertEqual(1, len(resp))
        shard = resp[0]
        self.assertEqual(4, len(shard.hosts))
        for x in self.driver.iter_agents('host_agent'):
            self.assertTrue(x.get_agent_id() in shard.hosts)

        # Prepare migration of the host 0
        recp = yield self.host1.get_own_address()
        migration = yield self.export_agent.prepare_migration(recp)
        self.assertIsInstance(migration, export_agent.Migration)
        self.assertTrue(migration.is_completable())
        self.assertEqual(5, len(migration.get_steps()))
        agents = yield self._get_agents_at(self.host1)
        for agent in agents:
            self.assertTrue(agent.is_migrating())
        # Canceling the migration
        yield self.export_agent.cancel_migration(migration)
        for agent in agents:
            self.assertFalse(agent.is_migrating())

        # Prepare migration of host 1 (should fail as it runs export agent)
        self.info("Now preparing for host running export agent.")
        recp = yield self.host2.get_own_address()
        migration = yield self.export_agent.prepare_migration(recp)
        self.assertIsInstance(migration, export_agent.Migration)
        self.assertFalse(migration.is_completable())
        self.assertEqual(1, len(migration.get_steps()))
        agents = yield self._get_agents_at(self.host2)
        self.assertEqual(3, len(agents))
        for agent in agents:
            self.assertFalse(agent.is_migrating())

        # Prepare migration of host 2 (should be successful)
        self.info("Now preparing for host running signal agent.")
        recp = yield self.host3.get_own_address()
        migration = yield self.export_agent.prepare_migration(recp)
        self.assertIsInstance(migration, export_agent.Migration)
        self.assertTrue(migration.is_completable())
        self.assertEqual(4, len(migration.get_steps()))
        agents = yield self._get_agents_at(self.host3)
        self.assertEqual(3, len(agents))
        for agent in agents:
            self.assertTrue(agent.is_migrating())
        yield self.export_agent.cancel_migration(migration)
        for agent in agents:
            self.assertFalse(agent.is_migrating())

        # Prepare migration of host 3 (should be successful)
        self.info("Now preparing for host running only worker agent.")
        recp = yield self.host4.get_own_address()
        migration = yield self.export_agent.prepare_migration(recp)
        self.assertIsInstance(migration, export_agent.Migration)
        self.assertTrue(migration.is_completable())
        self.assertEqual(4, len(migration.get_steps()))
        agents = yield self._get_agents_at(self.host4)

        self.assertEqual(2, len(agents))
        for agent in agents:
            self.assertTrue(agent.is_migrating())
        yield self.export_agent.cancel_migration(migration)
        for agent in agents:
            self.assertFalse(agent.is_migrating())
Example #3
0
 def _handle_no_shard(self, agent, brothers):
     if agent.is_migrating():
         return
     recipients = map(operator.attrgetter('recipient'), brothers)
     return agent.resolve_missing_shard_agent_problem(recipients)