Exemple #1
0
    def validate(self, visibility_field):
        """Validates the query content and does the necessary conversions."""
        if self.original_query.filter is wtypes.Unset:
            self.filter_expr = None
        else:
            try:
                self.filter_expr = json.loads(self.original_query.filter)
                self._validate_filter(self.filter_expr)
            except (ValueError, jsonschema.exceptions.ValidationError) as e:
                raise base.ClientSideError(
                    _("Filter expression not valid: %s") % e)
            self._replace_isotime_with_datetime(self.filter_expr)
            self._convert_operator_to_lower_case(self.filter_expr)
            self._normalize_field_names_for_db_model(self.filter_expr)

        self._force_visibility(visibility_field)

        if self.original_query.orderby is wtypes.Unset:
            self.orderby = None
        else:
            try:
                self.orderby = json.loads(self.original_query.orderby)
                self._validate_orderby(self.orderby)
            except (ValueError, jsonschema.exceptions.ValidationError) as e:
                raise base.ClientSideError(
                    _("Order-by expression not valid: %s") % e)
            self._convert_orderby_to_lower_case(self.orderby)
            self._normalize_field_names_in_orderby(self.orderby)

        self.limit = (None if self.original_query.limit is wtypes.Unset
                      else self.original_query.limit)

        self.limit = v2_utils.enforce_limit(self.limit)
Exemple #2
0
    def validate(self, visibility_field):
        """Validates the query content and does the necessary conversions."""
        if self.original_query.filter is wtypes.Unset:
            self.filter_expr = None
        else:
            try:
                self.filter_expr = json.loads(self.original_query.filter)
                self._validate_filter(self.filter_expr)
            except (ValueError, jsonschema.exceptions.ValidationError) as e:
                raise base.ClientSideError(
                    _("Filter expression not valid: %s") % e)
            self._replace_isotime_with_datetime(self.filter_expr)
            self._convert_operator_to_lower_case(self.filter_expr)
            self._normalize_field_names_for_db_model(self.filter_expr)

        self._force_visibility(visibility_field)

        if self.original_query.orderby is wtypes.Unset:
            self.orderby = None
        else:
            try:
                self.orderby = json.loads(self.original_query.orderby)
                self._validate_orderby(self.orderby)
            except (ValueError, jsonschema.exceptions.ValidationError) as e:
                raise base.ClientSideError(
                    _("Order-by expression not valid: %s") % e)
            self._convert_orderby_to_lower_case(self.orderby)
            self._normalize_field_names_in_orderby(self.orderby)

        self.limit = (None if self.original_query.limit is wtypes.Unset else
                      self.original_query.limit)

        self.limit = v2_utils.enforce_limit(self.limit)
Exemple #3
0
    def get_all(self, q=None, limit=None):
        """Return all known meters, based on the data recorded so far.

        :param q: Filter rules for the meters to be returned.
        """

        rbac.enforce("get_meters", pecan.request)

        q = q or []

        # Timestamp field is not supported for Meter queries
        limit = v2_utils.enforce_limit(limit)
        kwargs = v2_utils.query_to_kwargs(q, pecan.request.storage_conn.get_meters, allow_timestamps=False)
        return [Meter.from_db_model(m) for m in pecan.request.storage_conn.get_meters(limit=limit, **kwargs)]
Exemple #4
0
    def get_all(self, q=None, limit=None):
        """Return samples for the meter.

        :param q: Filter rules for the data to be returned.
        :param limit: Maximum number of samples to return.
        """

        rbac.enforce("get_samples", pecan.request)

        q = q or []
        limit = v2_utils.enforce_limit(limit)
        kwargs = v2_utils.query_to_kwargs(q, storage.SampleFilter.__init__)
        kwargs["meter"] = self.meter_name
        f = storage.SampleFilter(**kwargs)
        return [OldSample.from_db_model(e) for e in pecan.request.storage_conn.get_samples(f, limit=limit)]
Exemple #5
0
    def get_all(self, q=None, limit=None):
        """Return all known samples, based on the data recorded so far.

        :param q: Filter rules for the samples to be returned.
        :param limit: Maximum number of samples to be returned.
        """

        rbac.enforce("get_samples", pecan.request)

        q = q or []

        limit = utils.enforce_limit(limit)
        kwargs = utils.query_to_kwargs(q, storage.SampleFilter.__init__)
        f = storage.SampleFilter(**kwargs)
        return map(Sample.from_db_model, pecan.request.storage_conn.get_samples(f, limit=limit))
Exemple #6
0
    def get_all(self, q=None, limit=None):
        """Return all known samples, based on the data recorded so far.

        :param q: Filter rules for the samples to be returned.
        :param limit: Maximum number of samples to be returned.
        """

        rbac.enforce('get_samples', pecan.request)

        q = q or []

        limit = utils.enforce_limit(limit)
        kwargs = utils.query_to_kwargs(q, storage.SampleFilter.__init__)
        f = storage.SampleFilter(**kwargs)
        return map(Sample.from_db_model,
                   pecan.request.storage_conn.get_samples(f, limit=limit))
Exemple #7
0
    def get_all(self, q=None, limit=None):
        """Return all events matching the query filters.

        :param q: Filter arguments for which Events to return
        :param limit: Maximum number of samples to be returned.
        """
        q = q or []
        limit = v2_utils.enforce_limit(limit)
        event_filter = _event_query_to_event_filter(q)
        return [Event(message_id=event.message_id,
                      event_type=event.event_type,
                      generated=event.generated,
                      traits=event.traits,
                      raw=event.raw)
                for event in
                pecan.request.event_storage_conn.get_events(event_filter,
                                                            limit)]
Exemple #8
0
    def get_all(self, q=None, limit=None, meter_links=1):
        """Retrieve definitions of all of the resources.

        :param q: Filter rules for the resources to be returned.
        :param meter_links: option to include related meter links
        """

        rbac.enforce("get_resources", pecan.request)

        q = q or []
        limit = utils.enforce_limit(limit)
        kwargs = utils.query_to_kwargs(q, pecan.request.storage_conn.get_resources, ["limit"])
        resources = [
            Resource.from_db_and_links(r, self._resource_links(r.resource_id, meter_links))
            for r in pecan.request.storage_conn.get_resources(limit=limit, **kwargs)
        ]
        return resources
Exemple #9
0
    def get_all(self, q=None, limit=None):
        """Return samples for the meter.

        :param q: Filter rules for the data to be returned.
        :param limit: Maximum number of samples to return.
        """

        rbac.enforce('get_samples', pecan.request)

        q = q or []
        limit = v2_utils.enforce_limit(limit)
        kwargs = v2_utils.query_to_kwargs(q, storage.SampleFilter.__init__)
        kwargs['meter'] = self.meter_name
        f = storage.SampleFilter(**kwargs)
        return [OldSample.from_db_model(e)
                for e in pecan.request.storage_conn.get_samples(f, limit=limit)
                ]
Exemple #10
0
    def get_all(self, q=[], limit=None):
        """Return all known meters, based on the data recorded so far.

        :param q: Filter rules for the meters to be returned.
        :param limit: limit of the number of meter types to return.
        """

        rbac.enforce('get_meters', pecan.request)

        q = q or []
        # Timestamp field is not supported for Meter queries
        lim = v2_utils.enforce_limit(limit)
        kwargs = v2_utils.query_to_kwargs(
            q, pecan.request.storage_conn.get_meter_types,
            ['limit'], allow_timestamps=False)
        return [MeterType.from_db_model(m)
                for m in pecan.request.storage_conn.get_meter_types(limit=lim,
                                                                    **kwargs)]
Exemple #11
0
    def get_all(self, q=None, limit=None):
        """Return all events matching the query filters.

        :param q: Filter arguments for which Events to return
        :param limit: Maximum number of samples to be returned.
        """
        rbac.enforce("events:index", pecan.request)
        q = q or []
        limit = v2_utils.enforce_limit(limit)
        event_filter = _event_query_to_event_filter(q)
        return [Event(message_id=event.message_id,
                      event_type=event.event_type,
                      generated=event.generated,
                      traits=event.traits,
                      raw=event.raw)
                for event in
                pecan.request.event_storage_conn.get_events(event_filter,
                                                            limit)]
Exemple #12
0
    def get_all(self, q=None, limit=None, meter_links=1):
        """Retrieve definitions of all of the resources.

        :param q: Filter rules for the resources to be returned.
        :param meter_links: option to include related meter links
        """

        rbac.enforce("get_resources", pecan.request)

        q = q or []
        limit = utils.enforce_limit(limit)
        kwargs = utils.query_to_kwargs(q, pecan.request.storage_conn.get_resources)
        if "limit" in kwargs:
            raise base.ClientSideError(_("Limit is not a valid field for queries, " "use 'limit' parameter."))
        resources = [
            Resource.from_db_and_links(r, self._resource_links(r.resource_id, meter_links))
            for r in pecan.request.storage_conn.get_resources(limit=limit, **kwargs)
        ]
        return resources
Exemple #13
0
    def get_all(self, q=None, limit=None, meter_links=1):
        """Retrieve definitions of all of the resources.

        :param q: Filter rules for the resources to be returned.
        :param meter_links: option to include related meter links
        """
        rbac.enforce('get_resources', pecan.request)

        q = q or []
        limit = utils.enforce_limit(limit)
        kwargs = utils.query_to_kwargs(
            q, pecan.request.storage_conn.get_resources, ['limit'])
        resources = [
            Resource.from_db_and_links(r,
                                       self._resource_links(r.resource_id,
                                                            meter_links))
            for r in pecan.request.storage_conn.get_resources(limit=limit,
                                                              **kwargs)]
        return resources
Exemple #14
0
    def get_all(self, q=None, limit=None, unique=''):
        """Return all known meters, based on the data recorded so far.

        :param q: Filter rules for the meters to be returned.
        :param unique: flag to indicate unique meters to be returned.
        """

        rbac.enforce('get_meters', pecan.request)

        q = q or []

        # Timestamp field is not supported for Meter queries
        limit = v2_utils.enforce_limit(limit)
        kwargs = v2_utils.query_to_kwargs(
            q, pecan.request.storage_conn.get_meters,
            ['limit'], allow_timestamps=False)
        return [Meter.from_db_model(m)
                for m in pecan.request.storage_conn.get_meters(
                limit=limit, unique=strutils.bool_from_string(unique),
                **kwargs)]
Exemple #15
0
    def get_all(self, q=None, limit=None):
        """Return all known meters, based on the data recorded so far.

        :param q: Filter rules for the meters to be returned.
        """

        rbac.enforce('get_meters', pecan.request)

        q = q or []

        # Timestamp field is not supported for Meter queries
        limit = v2_utils.enforce_limit(limit)
        kwargs = v2_utils.query_to_kwargs(
            q, pecan.request.storage_conn.get_meters, allow_timestamps=False)
        if 'limit' in kwargs:
            raise base.ClientSideError(_(
                "Limit is not a valid field for queries, "
                "use 'limit' parameter."))
        return [Meter.from_db_model(m)
                for m in pecan.request.storage_conn.get_meters(limit=limit,
                                                               **kwargs)]
    def get_all(self, q=None, limit=None, meter_links=0):
        """Retrieve definitions of all of the resources.

        :param q: Filter rules for the resources to be returned.
        :param limit: Maximum number of resources to return.
        :param meter_links: option to include related meter links.
        """

        rbac.enforce('get_resources', pecan.request)

        q = q or []
        r_ids = []
        if len(q) == 1:
            # Improve query time for meter-based stats reports from
            # Horizon. Get resource info for specified resource ids in one
            # call as opposed to one by one.
            # q is a list of Query objects. Convert the first and
            # only item to dictionary to retrieve the list of resource ids.
            d = q[0].as_dict()
            if d['field'] == 'resource_ids':
                r_ids = ast.literal_eval(d['value'])

        if r_ids:
            resources = [
                Resource.from_db_and_links(
                    r, self._resource_links(r.resource_id, meter_links))
                for r in pecan.request.storage_conn.get_resources_batch(r_ids)
            ]
            return resources
        else:
            limit = utils.enforce_limit(limit)
            kwargs = utils.query_to_kwargs(
                q, pecan.request.storage_conn.get_resources, ['limit'])
            resources = [
                Resource.from_db_and_links(
                    r, self._resource_links(r.resource_id, meter_links))
                for r in pecan.request.storage_conn.get_resources(limit=limit,
                                                                  **kwargs)
            ]
            return resources