Пример #1
0
    def _update_host_state_map(self, context):

        # Get resource usage across the available share nodes:
        topic = CONF.share_topic
        share_services = db.service_get_all_by_topic(context, topic)

        for service in share_services:
            host = service['host']

            # Warn about down services and remove them from host_state_map
            if not utils.service_is_up(service) or service['disabled']:
                LOG.warning(_LW("Share service is down. (host: %s).") % host)
                if self.host_state_map.pop(host, None):
                    LOG.info(_LI("Removing non-active host: %s from "
                                 "scheduler cache.") % host)
                continue

            # Create and register host_state if not in host_state_map
            capabilities = self.service_states.get(host, None)
            host_state = self.host_state_map.get(host)
            if not host_state:
                host_state = self.host_state_cls(
                    host,
                    capabilities=capabilities,
                    service=dict(six.iteritems(service)))
                self.host_state_map[host] = host_state

            # Update capabilities and attributes in host_state
            host_state.update_from_share_capability(
                capabilities, service=dict(six.iteritems(service)))
Пример #2
0
    def hosts_up(self, context, topic):
        """Return the list of hosts that have a running service for topic."""

        services = db.service_get_all_by_topic(context, topic)
        return [service['host']
                for service in services
                if utils.service_is_up(service)]
Пример #3
0
    def get_all_host_states_share(self, context):
        """Returns a dict of all the hosts the HostManager
          knows about. Also, each of the consumable resources in HostState
          are pre-populated and adjusted based on data in the db.

          For example:
          {'192.168.1.100': HostState(), ...}
        """

        # Get resource usage across the available share nodes:
        topic = CONF.share_topic
        share_services = db.service_get_all_by_topic(context, topic)
        for service in share_services:
            if not utils.service_is_up(service) or service['disabled']:
                LOG.warn(_("service is down or disabled."))
                continue
            host = service['host']
            capabilities = self.service_states.get(host, None)
            host_state = self.host_state_map.get(host)
            if host_state:
                # copy capabilities to host_state.capabilities
                host_state.update_capabilities(capabilities,
                                               dict(six.iteritems(service)))
            else:
                host_state = self.host_state_cls(
                    host,
                    capabilities=capabilities,
                    service=dict(six.iteritems(service)))
                self.host_state_map[host] = host_state
            # update host_state
            host_state.update_from_share_capability(capabilities)

        return self.host_state_map.itervalues()
Пример #4
0
    def test_hosts_up(self):
        service1 = {'host': 'host1'}
        service2 = {'host': 'host2'}
        services = [service1, service2]

        self.mox.StubOutWithMock(db, 'service_get_all_by_topic')
        self.mox.StubOutWithMock(utils, 'service_is_up')

        db.service_get_all_by_topic(self.context,
                                    self.topic).AndReturn(services)
        utils.service_is_up(service1).AndReturn(False)
        utils.service_is_up(service2).AndReturn(True)

        self.mox.ReplayAll()
        result = self.driver.hosts_up(self.context, self.topic)
        self.assertEqual(result, ['host2'])
Пример #5
0
    def get_all_host_states_share(self, context):
        """Get all hosts and their states.

        Returns a dict of all the hosts the HostManager knows
        about. Also, each of the consumable resources in HostState are
        pre-populated and adjusted based on data in the db.

        For example:
          {'192.168.1.100': HostState(), ...}
        """

        # Get resource usage across the available share nodes:
        topic = CONF.share_topic
        share_services = db.service_get_all_by_topic(context, topic)
        for service in share_services:
            if not utils.service_is_up(service) or service['disabled']:
                LOG.warn(_LW("service is down or disabled."))
                continue
            host = service['host']
            capabilities = self.service_states.get(host, None)
            host_state = self.host_state_map.get(host)
            if host_state:
                # copy capabilities to host_state.capabilities
                host_state.update_capabilities(capabilities,
                                               dict(six.iteritems(service)))
            else:
                host_state = self.host_state_cls(host,
                                                 capabilities=capabilities,
                                                 service=dict(
                                                     six.iteritems(service)))
                self.host_state_map[host] = host_state
            # update host_state
            host_state.update_from_share_capability(capabilities)

        return self.host_state_map.itervalues()
Пример #6
0
    def _update_host_state_map(self, context):

        # Get resource usage across the available share nodes:
        topic = CONF.share_topic
        share_services = db.service_get_all_by_topic(context, topic)

        for service in share_services:
            host = service['host']

            # Warn about down services and remove them from host_state_map
            if not utils.service_is_up(service) or service['disabled']:
                LOG.warn(_LW("Share service is down. (host: %s)") % host)
                if self.host_state_map.pop(host, None):
                    LOG.info(_LI("Removing non-active host: %s from "
                                 "scheduler cache.") % host)
                continue

            # Create and register host_state if not in host_state_map
            capabilities = self.service_states.get(host, None)
            host_state = self.host_state_map.get(host)
            if not host_state:
                host_state = self.host_state_cls(
                    host,
                    capabilities=capabilities,
                    service=dict(six.iteritems(service)))
                self.host_state_map[host] = host_state

            # Update capabilities and attributes in host_state
            host_state.update_from_share_capability(
                capabilities, service=dict(six.iteritems(service)))
Пример #7
0
    def hosts_up(self, context, topic):
        """Return the list of hosts that have a running service for topic."""

        services = db.service_get_all_by_topic(context, topic)
        return [service['host']
                for service in services
                if utils.service_is_up(service)]
Пример #8
0
    def test_get_all_host_states_share(self):
        context = 'fake_context'
        topic = CONF.share_topic

        self.mox.StubOutWithMock(db, 'service_get_all_by_topic')
        self.mox.StubOutWithMock(host_manager.LOG, 'warn')

        ret_services = fakes.SHARE_SERVICES
        db.service_get_all_by_topic(context, topic).AndReturn(ret_services)
        # Disabled service
        host_manager.LOG.warn("service is down or disabled.")

        self.mox.ReplayAll()
        self.host_manager.get_all_host_states_share(context)
        host_state_map = self.host_manager.host_state_map

        self.assertEqual(len(host_state_map), 4)
        # Check that service is up
        for i in xrange(4):
            share_node = fakes.SHARE_SERVICES[i]
            host = share_node['host']
            self.assertEqual(host_state_map[host].service,
                             share_node)
Пример #9
0
def mox_host_manager_db_calls_share(mock, context):
    mock.StubOutWithMock(db, 'service_get_all_by_topic')

    db.service_get_all_by_topic(mox.IgnoreArg(),
                                mox.IgnoreArg()).AndReturn(SHARE_SERVICES)