예제 #1
0
    def create(self,
               context,
               event_id,
               project_id,
               resource_type=None,
               resource_uuid=None,
               level="ERROR"):
        """Create a message with the specified information."""
        LOG.info(_LI("Creating message record for request_id = %s"),
                 context.request_id)
        # Ensure valid event_id
        defined_messages.get_message_text(event_id)
        # Updates expiry time for message as per message_ttl config.
        expires_at = (timeutils.utcnow() +
                      datetime.timedelta(seconds=CONF.message_ttl))

        message_record = {
            'project_id': project_id,
            'request_id': context.request_id,
            'resource_type': resource_type,
            'resource_uuid': resource_uuid,
            'event_id': event_id,
            'message_level': level,
            'expires_at': expires_at
        }
        try:
            self.db.message_create(context, message_record)
        except Exception:
            LOG.exception(
                _LE("Failed to create message record "
                    "for request_id %s"), context.request_id)
예제 #2
0
    def index(self, req):
        """Returns a list of messages, transformed through view builder."""
        context = req.environ['cinder.context']
        check_policy(context, 'get_all')
        filters = None
        marker = None
        limit = None
        offset = None
        sort_keys = None
        sort_dirs = None

        if (req.api_version_request.matches("3.5")):
            filters = req.params.copy()
            marker, limit, offset = common.get_pagination_params(filters)
            sort_keys, sort_dirs = common.get_sort_params(filters)

        if req.api_version_request.matches(common.FILTERING_VERSION):
            common.reject_invalid_filters(context, filters, 'message')

        messages = self.message_api.get_all(context,
                                            filters=filters,
                                            marker=marker,
                                            limit=limit,
                                            offset=offset,
                                            sort_keys=sort_keys,
                                            sort_dirs=sort_dirs)

        for message in messages:
            # Fetches message text based on event id passed to it.
            user_message = defined_messages.get_message_text(
                message['event_id'])
            message['user_message'] = user_message

        messages = self._view_builder.index(req, messages)
        return messages
예제 #3
0
파일: messages.py 프로젝트: C2python/cinder
    def index(self, req):
        """Returns a list of messages, transformed through view builder."""
        context = req.environ['cinder.context']
        check_policy(context, 'get_all')
        filters = None
        marker = None
        limit = None
        offset = None
        sort_keys = None
        sort_dirs = None

        if (req.api_version_request.matches("3.5")):
            filters = req.params.copy()
            marker, limit, offset = common.get_pagination_params(filters)
            sort_keys, sort_dirs = common.get_sort_params(filters)

        messages = self.message_api.get_all(context, filters=filters,
                                            marker=marker, limit=limit,
                                            offset=offset,
                                            sort_keys=sort_keys,
                                            sort_dirs=sort_dirs)

        for message in messages:
            # Fetches message text based on event id passed to it.
            user_message = defined_messages.get_message_text(
                message['event_id'])
            message['user_message'] = user_message

        messages = self._view_builder.index(req, messages)
        return messages
예제 #4
0
 def _expected_message_from_controller(self, id):
     message = v3_fakes.fake_message(id)
     links = [
         {
             'href': 'http://localhost/v3/fakeproject/messages/%s' % id,
             'rel': 'self'
         },
         {
             'href': 'http://localhost/fakeproject/messages/%s' % id,
             'rel': 'bookmark'
         },
     ]
     return {
         'message': {
             'id':
             message.get('id'),
             'user_message':
             defined_messages.get_message_text(message.get('event_id')),
             'request_id':
             message.get('request_id'),
             'event_id':
             message.get('event_id'),
             'created_at':
             message.get('created_at'),
             'message_level':
             message.get('message_level'),
             'guaranteed_until':
             message.get('expires_at'),
             'links':
             links,
         }
     }
예제 #5
0
 def _build_user_message(self, message):
     # NOTE(tommylikehu): if the `action_id` is empty, we use 'event_id'
     # to translate the user message.
     if message is None:
         return
     if message['action_id'] is None and message['event_id'] is not None:
         message['user_message'] = defined_messages.get_message_text(
             message['event_id'])
     else:
         message['user_message'] = "%s:%s" % (
             message_field.translate_action(message['action_id']),
             message_field.translate_detail(message['detail_id']))
예제 #6
0
 def _build_user_message(self, message):
     # NOTE(tommylikehu): if the `action_id` is empty, we use 'event_id'
     # to translate the user message.
     if message is None:
         return
     if message['action_id'] is None and message['event_id'] is not None:
         message['user_message'] = defined_messages.get_message_text(
             message['event_id'])
     else:
         message['user_message'] = "%s:%s" % (
             message_field.translate_action(message['action_id']),
             message_field.translate_detail(message['detail_id']))
예제 #7
0
    def show(self, req, id):
        """Return the given message."""
        context = req.environ['cinder.context']

        # Not found exception will be handled at the wsgi level
        message = self.message_api.get(context, id)

        check_policy(context, 'get', message)

        # Fetches message text based on event id passed to it.
        message['user_message'] = defined_messages.get_message_text(
            message['event_id'])

        return self._view_builder.detail(req, message)
예제 #8
0
파일: messages.py 프로젝트: C2python/cinder
    def show(self, req, id):
        """Return the given message."""
        context = req.environ['cinder.context']

        # Not found exception will be handled at the wsgi level
        message = self.message_api.get(context, id)

        check_policy(context, 'get', message)

        # Fetches message text based on event id passed to it.
        message['user_message'] = defined_messages.get_message_text(
            message['event_id'])

        return self._view_builder.detail(req, message)
예제 #9
0
파일: api.py 프로젝트: C2python/cinder
    def create(self, context, event_id, project_id, resource_type=None,
               resource_uuid=None, level="ERROR"):
        """Create a message with the specified information."""
        LOG.info(_LI("Creating message record for request_id = %s"),
                 context.request_id)
        # Ensure valid event_id
        defined_messages.get_message_text(event_id)
        # Updates expiry time for message as per message_ttl config.
        expires_at = (timeutils.utcnow() + datetime.timedelta(
                      seconds=CONF.message_ttl))

        message_record = {'project_id': project_id,
                          'request_id': context.request_id,
                          'resource_type': resource_type,
                          'resource_uuid': resource_uuid,
                          'event_id': event_id,
                          'message_level': level,
                          'expires_at': expires_at}
        try:
            self.db.message_create(context, message_record)
        except Exception:
            LOG.exception(_LE("Failed to create message record "
                              "for request_id %s"), context.request_id)
예제 #10
0
파일: messages.py 프로젝트: bopopescu/stack
    def index(self, req):
        """Returns a list of messages, transformed through view builder."""
        context = req.environ['cinder.context']
        check_policy(context, 'get_all')

        messages = self.message_api.get_all(context)

        for message in messages:
            # Fetches message text based on event id passed to it.
            user_message = defined_messages.get_message_text(
                message['event_id'])
            message['user_message'] = user_message

        messages = self._view_builder.index(req, messages)
        return messages
예제 #11
0
    def show(self, req, id):
        """Return the given message."""
        context = req.environ['cinder.context']

        try:
            message = self.message_api.get(context, id)
        except exception.MessageNotFound as error:
            raise exc.HTTPNotFound(explanation=error.msg)

        check_policy(context, 'get', message)

        # Fetches message text based on event id passed to it.
        message['user_message'] = defined_messages.get_message_text(
            message['event_id'])

        return self._view_builder.detail(req, message)
예제 #12
0
    def show(self, req, id):
        """Return the given message."""
        context = req.environ['cinder.context']

        try:
            message = self.message_api.get(context, id)
        except exception.MessageNotFound as error:
            raise exc.HTTPNotFound(explanation=error.msg)

        check_policy(context, 'get', message)

        # Fetches message text based on event id passed to it.
        message['user_message'] = defined_messages.get_message_text(
            message['event_id'])

        return self._view_builder.detail(req, message)
예제 #13
0
 def _expected_message_from_controller(self, id):
     message = stubs.stub_message(id)
     links = [
         {"href": "http://localhost/v3/fakeproject/messages/%s" % id, "rel": "self"},
         {"href": "http://localhost/fakeproject/messages/%s" % id, "rel": "bookmark"},
     ]
     return {
         "message": {
             "id": message.get("id"),
             "user_message": defined_messages.get_message_text(message.get("event_id")),
             "request_id": message.get("request_id"),
             "event_id": message.get("event_id"),
             "created_at": message.get("created_at"),
             "message_level": message.get("message_level"),
             "guaranteed_until": message.get("expires_at"),
             "links": links,
         }
     }
예제 #14
0
 def _expected_message_from_controller(self, id):
     message = v3_fakes.fake_message(id)
     links = [
         {'href': 'http://localhost/v3/fakeproject/messages/%s' % id,
          'rel': 'self'},
         {'href': 'http://localhost/fakeproject/messages/%s' % id,
          'rel': 'bookmark'},
     ]
     return {
         'message': {
             'id': message.get('id'),
             'user_message': defined_messages.get_message_text(
                 message.get('event_id')),
             'request_id': message.get('request_id'),
             'event_id': message.get('event_id'),
             'created_at': message.get('created_at'),
             'message_level': message.get('message_level'),
             'guaranteed_until': message.get('expires_at'),
             'links': links,
         }
     }
예제 #15
0
 def test_event_id_missing_prefix(self):
     self.assertTrue(defined_messages.get_message_text('000001'))