コード例 #1
0
ファイル: worker.py プロジェクト: gbraad/openstack-astara
    def _repopulate(self):
        """Repopulate local state machines given the new DHT

        After the hash ring has been rebalanced, this ensures the workers'
        TRMs are populated with the correct set of state machines given the
        current layout of the ring. We also consult the dispatcher to ensure
        we're creating state machines on the correct worker process.  This
        also cleans up state machines that are no longer mapped here.
        """
        LOG.debug('Running post-rebalance repopulate for worker %s',
                  self.proc_name)
        for resource in populate.repopulate():
            target_hosts = self.hash_ring_mgr.ring.get_hosts(resource.id)
            if self.host not in target_hosts:
                tid = _normalize_uuid(resource.tenant_id)
                if tid in self.tenant_managers:
                    trm = self.tenant_managers[tid]
                    trm.unmanage_resource(resource.id)
                    continue

            tgt = self.scheduler.dispatcher.pick_workers(resource.tenant_id)[0]

            if tgt['worker'].name != self.proc_name:
                # Typically, state machine creation doesn't happen until the
                # dispatcher has scheduled a msg to a single worker. rebalances
                # are scheduled to all workers so we need to consult the
                # dispatcher here to avoid creating state machines in all
                # workers.
                continue

            for trm in self._get_trms(resource.tenant_id):
                # creates a state machine if one does not exist.
                e = event.Event(resource=resource, crud=None, body={})
                trm.get_state_machines(e, self._context)
コード例 #2
0
ファイル: test_populate.py プロジェクト: raceli/astara
 def test_repopulate(self, enabled_drivers):
     drivers = []
     for i in range(2):
         driver = mock.Mock()
         driver.pre_populate_hook = mock.Mock()
         driver.pre_populate_hook.return_value = [
             'driver_%s_resource' % i,
         ]
         drivers.append(driver)
     enabled_drivers.return_value = drivers
     res = populate.repopulate()
     self.assertEqual(
         set(['driver_0_resource', 'driver_1_resource']), set(res))
コード例 #3
0
 def test_repopulate(self, enabled_drivers):
     drivers = []
     for i in range(2):
         driver = mock.Mock()
         driver.pre_populate_hook = mock.Mock()
         driver.pre_populate_hook.return_value = [
             'driver_%s_resource' % i,
         ]
         drivers.append(driver)
     enabled_drivers.return_value = drivers
     res = populate.repopulate()
     self.assertEqual(set(res),
                      set(['driver_0_resource', 'driver_1_resource']))
コード例 #4
0
ファイル: worker.py プロジェクト: gocloudxyz/astara
    def _repopulate(self):
        """Repopulate local state machines given the new DHT

        After the hash ring has been rebalanced, this ensures the workers'
        TRMs are populated with the correct set of state machines given the
        current layout of the ring. We also consult the dispatcher to ensure
        we're creating state machines on the correct worker process.  This
        also cleans up state machines that are no longer mapped here.
        """
        LOG.debug('Running post-rebalance repopulate for worker %s',
                  self.proc_name)
        for resource in populate.repopulate():
            target_hosts = self.hash_ring_mgr.ring.get_hosts(
                resource.id)
            if self.host not in target_hosts:
                tid = _normalize_uuid(resource.tenant_id)
                if tid in self.tenant_managers:
                    trm = self.tenant_managers[tid]
                    trm.unmanage_resource(resource.id)
                    continue

            tgt = self.scheduler.dispatcher.pick_workers(
                resource.tenant_id)[0]

            if tgt['worker'].name != self.proc_name:
                # Typically, state machine creation doesn't happen until the
                # dispatcher has scheduled a msg to a single worker. rebalances
                # are scheduled to all workers so we need to consult the
                # dispatcher here to avoid creating state machines in all
                # workers.
                continue

            for trm in self._get_trms(resource.tenant_id):
                # creates a state machine if one does not exist.
                e = event.Event(resource=resource, crud=None, body={})
                trm.get_state_machines(e, self._context)