예제 #1
0
    def get_all(self):
        """Return all services."""
        acl.enforce('services:list', context.ctx())

        LOG.info("Fetch services.")

        if not cfg.CONF.coordination.backend_url:
            raise exc.CoordinationException("Service API is not supported.")

        service_coordinator = coordination.get_service_coordinator()

        if not service_coordinator.is_active():
            raise exc.CoordinationException(
                "Failed to connect to coordination backend.")

        services_list = []
        service_group = ['%s_group' % i for i in launch.LAUNCH_OPTIONS]

        try:
            for group in service_group:
                members = service_coordinator.get_members(group)
                services_list.extend([
                    resources.Service.from_dict({
                        'type': group,
                        'name': member
                    }) for member in members
                ])
        except tooz.coordination.ToozError as e:
            # In the scenario of network interruption or manually shutdown
            # connection shutdown, ToozError will be raised.
            raise exc.CoordinationException(
                "Failed to get service members from coordination backend. %s" %
                six.text_type(e))

        return resources.Services(services=services_list)
예제 #2
0
    def get_all(self):
        """Return all services."""
        acl.enforce('services:list', context.ctx())

        LOG.debug("Fetch services.")

        if not cfg.CONF.coordination.backend_url:
            raise exc.CoordinationNotSupportedException("Service API "
                                                        "is not supported.")

        service_coordinator = coordination.get_service_coordinator()

        if not service_coordinator.is_active():
            raise exc.CoordinationException(
                "Failed to connect to coordination backend.")

        # Should be the same as LAUNCH_OPTIONS in launch.py
        # At the moment there is a duplication, need to solve it.
        # We cannot depend on launch.py since it uses eventlet monkey patch
        # under wsgi it causes problems
        mistral_services = {
            'api', 'engine', 'executor', 'event-engine', 'notifier'
        }
        services_list = []
        service_group = ['%s_group' % i for i in mistral_services]

        try:
            for group in service_group:
                members = service_coordinator.get_members(group)

                members_list = [
                    resources.Service.from_dict({
                        'type': group,
                        'name': member
                    }) for member in members
                ]

                services_list.extend(members_list)
        except tooz.coordination.ToozError as e:
            # In the scenario of network interruption or manually shutdown
            # connection shutdown, ToozError will be raised.
            raise exc.CoordinationException(
                "Failed to get service members from coordination backend. %s" %
                six.text_type(e))

        return resources.Services(services=services_list)