Esempio n. 1
0
    def scan(self, req, body, project_id, table_name):

        validation.validate_params(self.schema, body)

        req.context.tenant = project_id

        try:
            # TODO ikhudoshyn: table_name may be index name

            attrs_to_get = body.get(parser.Props.ATTRIBUTES_TO_GET)

            select = body.get(parser.Props.SELECT)

            select_type = parser.Parser.parse_select_type(select, attrs_to_get)

            limit = body.get(parser.Props.LIMIT)

            exclusive_start_key = body.get(parser.Props.EXCLUSIVE_START_KEY)

            exclusive_start_key = (
                parser.Parser.parse_item_attributes(exclusive_start_key) if exclusive_start_key else None
            )

            scan_filter = body.get(parser.Props.SCAN_FILTER, {})

            condition_map = parser.Parser.parse_attribute_conditions(scan_filter)

            segment = body.get(parser.Props.SEGMENT, 0)
            total_segments = body.get(parser.Props.TOTAL_SEGMENTS, 1)

            assert segment < total_segments
        except Exception:
            raise exception.AWSErrorResponseException()

        try:
            result = storage.scan(
                req.context,
                table_name,
                condition_map,
                attributes_to_get=attrs_to_get,
                limit=limit,
                exclusive_start_key=exclusive_start_key,
            )

            response = {parser.Props.COUNT: result.count, parser.Props.SCANNED_COUNT: result.scanned_count}

            if not select_type.is_count:
                response[parser.Props.ITEMS] = [parser.Parser.format_item_attributes(row) for row in result.items]

            if result.last_evaluated_key:
                response[parser.Props.LAST_EVALUATED_KEY] = parser.Parser.format_item_attributes(
                    result.last_evaluated_key
                )

            return response
        except exception.AWSErrorResponseException as e:
            raise e
        except Exception:
            raise exception.AWSErrorResponseException()
Esempio n. 2
0
    def scan(self, req, body, project_id, table_name):
        utils.check_project_id(req.context, project_id)
        jsonschema.validate(body, self.schema)

        req.context.tenant = project_id

        #TODO ikhudoshyn: table_name may be index name

        attrs_to_get = body.get(parser.Props.ATTRIBUTES_TO_GET)

        select = body.get(parser.Props.SELECT)

        select_type = parser.Parser.parse_select_type(select, attrs_to_get)

        limit = body.get(parser.Props.LIMIT)

        exclusive_start_key = body.get(parser.Props.EXCLUSIVE_START_KEY)

        exclusive_start_key = parser.Parser.parse_item_attributes(
            exclusive_start_key) if exclusive_start_key else None

        scan_filter = body.get(parser.Props.SCAN_FILTER, {})

        condition_map = parser.Parser.parse_attribute_conditions(scan_filter)

        segment = body.get(parser.Props.SEGMENT, 0)
        total_segments = body.get(parser.Props.TOTAL_SEGMENTS, 1)

        assert segment < total_segments

        result = storage.scan(req.context,
                              table_name,
                              condition_map,
                              attributes_to_get=attrs_to_get,
                              limit=limit,
                              exclusive_start_key=exclusive_start_key)

        response = {
            parser.Props.COUNT: result.count,
            parser.Props.SCANNED_COUNT: result.scanned_count
        }

        if not select_type.is_count:
            response[parser.Props.ITEMS] = [
                parser.Parser.format_item_attributes(row)
                for row in result.items
            ]

        if result.last_evaluated_key:
            response[parser.Props.LAST_EVALUATED_KEY] = (
                parser.Parser.format_item_attributes(
                    result.last_evaluated_key))

        return response
Esempio n. 3
0
    def scan(self, req, body, project_id, table_name):
        utils.check_project_id(req.context, project_id)
        req.context.tenant = project_id

        with probe.Probe(__name__ + '.validation'):
            validation.validate_object(body, "body")

            # get attributes_to_get
            attributes_to_get = body.pop(parser.Props.ATTRIBUTES_TO_GET, None)
            if attributes_to_get:
                validation.validate_list(attributes_to_get,
                                         parser.Props.ATTRIBUTES_TO_GET)
                for attr_name in attributes_to_get:
                    validation.validate_attr_name(attr_name)

            select = body.pop(parser.Props.SELECT, None)

            if select is None:
                if attributes_to_get:
                    select = models.SelectType.SELECT_TYPE_SPECIFIC
                else:
                    select = models.SelectType.SELECT_TYPE_ALL
            else:
                validation.validate_string(select, parser.Props.SELECT)
            select_type = models.SelectType(select, attributes_to_get)

            limit = body.pop(parser.Props.LIMIT, None)
            if limit is not None:
                limit = validation.validate_integer(limit, parser.Props.LIMIT,
                                                    min_val=0)

            # parse exclusive_start_key_attributes
            exclusive_start_key_attributes_json = body.pop(
                parser.Props.EXCLUSIVE_START_KEY, None)
            if exclusive_start_key_attributes_json is not None:
                validation.validate_object(exclusive_start_key_attributes_json,
                                           parser.Props.EXCLUSIVE_START_KEY)
                exclusive_start_key_attributes = (
                    parser.Parser.parse_item_attributes(
                        exclusive_start_key_attributes_json
                    )
                )
            else:
                exclusive_start_key_attributes = None

            scan_filter_json = body.pop(parser.Props.SCAN_FILTER, None)
            if scan_filter_json:
                validation.validate_object(scan_filter_json,
                                           parser.Props.SCAN_FILTER)

                condition_map = parser.Parser.parse_attribute_conditions(
                    scan_filter_json, condition_class=ScanCondition
                )
            else:
                condition_map = None

            total_segments = body.pop(parser.Props.TOTAL_SEGMENTS, 1)
            total_segments = validation.validate_integer(
                total_segments, parser.Props.TOTAL_SEGMENTS, min_val=1,
                max_val=4096
            )

            segment = body.pop(parser.Props.SEGMENT, 0)
            segment = validation.validate_integer(
                segment, parser.Props.SEGMENT, min_val=0,
                max_val=total_segments
            )

            validation.validate_unexpected_props(body, "body")

        result = storage.scan(
            req.context, table_name, condition_map,
            attributes_to_get=attributes_to_get, limit=limit,
            exclusive_start_key=exclusive_start_key_attributes)

        response = {
            parser.Props.COUNT: result.count,
            parser.Props.SCANNED_COUNT: result.scanned_count
        }

        if not select_type.is_count:
            response[parser.Props.ITEMS] = [
                parser.Parser.format_item_attributes(row)
                for row in result.items]

        if result.last_evaluated_key:
            response[parser.Props.LAST_EVALUATED_KEY] = (
                parser.Parser.format_item_attributes(
                    result.last_evaluated_key
                )
            )

        return response
Esempio n. 4
0
    def scan(self, req, body, project_id, table_name):
        utils.check_project_id(req.context, project_id)
        req.context.tenant = project_id

        with probe.Probe(__name__ + '.validation'):
            validation.validate_object(body, "body")

            # get attributes_to_get
            attributes_to_get = body.pop(parser.Props.ATTRIBUTES_TO_GET, None)
            if attributes_to_get:
                validation.validate_list(attributes_to_get,
                                         parser.Props.ATTRIBUTES_TO_GET)
                for attr_name in attributes_to_get:
                    validation.validate_attr_name(attr_name)

            select = body.pop(parser.Props.SELECT, None)

            if select is None:
                if attributes_to_get:
                    select = models.SelectType.SELECT_TYPE_SPECIFIC
                else:
                    select = models.SelectType.SELECT_TYPE_ALL
            else:
                validation.validate_string(select, parser.Props.SELECT)
            select_type = models.SelectType(select, attributes_to_get)

            limit = body.pop(parser.Props.LIMIT, None)
            if limit is not None:
                limit = validation.validate_integer(limit,
                                                    parser.Props.LIMIT,
                                                    min_val=0)

            # parse exclusive_start_key_attributes
            exclusive_start_key_attributes_json = body.pop(
                parser.Props.EXCLUSIVE_START_KEY, None)
            if exclusive_start_key_attributes_json is not None:
                validation.validate_object(exclusive_start_key_attributes_json,
                                           parser.Props.EXCLUSIVE_START_KEY)
                exclusive_start_key_attributes = (
                    parser.Parser.parse_item_attributes(
                        exclusive_start_key_attributes_json))
            else:
                exclusive_start_key_attributes = None

            scan_filter_json = body.pop(parser.Props.SCAN_FILTER, None)
            if scan_filter_json:
                validation.validate_object(scan_filter_json,
                                           parser.Props.SCAN_FILTER)

                condition_map = parser.Parser.parse_attribute_conditions(
                    scan_filter_json, condition_class=ScanCondition)
            else:
                condition_map = None

            total_segments = body.pop(parser.Props.TOTAL_SEGMENTS, 1)
            total_segments = validation.validate_integer(
                total_segments,
                parser.Props.TOTAL_SEGMENTS,
                min_val=1,
                max_val=4096)

            segment = body.pop(parser.Props.SEGMENT, 0)
            segment = validation.validate_integer(segment,
                                                  parser.Props.SEGMENT,
                                                  min_val=0,
                                                  max_val=total_segments)

            validation.validate_unexpected_props(body, "body")

        result = storage.scan(
            req.context,
            table_name,
            condition_map,
            attributes_to_get=attributes_to_get,
            limit=limit,
            exclusive_start_key=exclusive_start_key_attributes)

        response = {
            parser.Props.COUNT: result.count,
            parser.Props.SCANNED_COUNT: result.scanned_count
        }

        if not select_type.is_count:
            response[parser.Props.ITEMS] = [
                parser.Parser.format_item_attributes(row)
                for row in result.items
            ]

        if result.last_evaluated_key:
            response[parser.Props.LAST_EVALUATED_KEY] = (
                parser.Parser.format_item_attributes(
                    result.last_evaluated_key))

        return response
Esempio n. 5
0
    def __call__(self):
        try:
            #TODO ikhudoshyn: table_name may be index name
            table_name = self.action_params.get(parser.Props.TABLE_NAME, None)

            attrs_to_get = self.action_params.get(
                parser.Props.ATTRIBUTES_TO_GET, None)

            select = self.action_params.get(
                parser.Props.SELECT, None)

            select_type = parser.Parser.parse_select_type(select, attrs_to_get)

            limit = self.action_params.get(parser.Props.LIMIT, None)

            return_consumed_capacity = self.action_params.get(
                parser.Props.RETURN_CONSUMED_CAPACITY,
                parser.Values.RETURN_CONSUMED_CAPACITY_NONE
            )

            exclusive_start_key = self.action_params.get(
                parser.Props.EXCLUSIVE_START_KEY, None
            )

            exclusive_start_key = parser.Parser.parse_item_attributes(
                exclusive_start_key) if exclusive_start_key else None

            scan_filter = self.action_params.get(
                parser.Props.SCAN_FILTER, {}
            )

            condition_map = parser.Parser.parse_attribute_conditions(
                scan_filter
            )

            segment = self.action_params.get(parser.Props.SEGMENT, 0)
            total_segments = self.action_params.get(
                parser.Props.TOTAL_SEGMENTS, 1
            )

            assert segment < total_segments
        except Exception:
            raise exception.AWSErrorResponseException()

        try:
            result = storage.scan(
                self.context, table_name, condition_map,
                attributes_to_get=attrs_to_get, limit=limit,
                exclusive_start_key=exclusive_start_key)

            response = {
                parser.Props.COUNT: result.count,
                parser.Props.SCANNED_COUNT: result.scanned_count
            }

            if not select_type.is_count:
                response[parser.Props.ITEMS] = [
                    parser.Parser.format_item_attributes(row)
                    for row in result.items]

            if (return_consumed_capacity !=
                    parser.Values.RETURN_CONSUMED_CAPACITY_NONE):
                response[parser.Props.CONSUMED_CAPACITY] = (
                    parser.Parser.format_consumed_capacity(
                        return_consumed_capacity, None
                    )
                )

            if result.last_evaluated_key:
                response[parser.Props.LAST_EVALUATED_KEY] = (
                    parser.Parser.format_item_attributes(
                        result.last_evaluated_key
                    )
                )

            return response
        except exception.AWSErrorResponseException as e:
            raise e
        except Exception:
            raise exception.AWSErrorResponseException()
Esempio n. 6
0
    def __call__(self):
        try:
            #TODO ikhudoshyn: table_name may be index name
            table_name = self.action_params.get(parser.Props.TABLE_NAME, None)

            attrs_to_get = self.action_params.get(
                parser.Props.ATTRIBUTES_TO_GET, None)

            select = self.action_params.get(parser.Props.SELECT, None)

            select_type = parser.Parser.parse_select_type(select, attrs_to_get)

            limit = self.action_params.get(parser.Props.LIMIT, None)

            return_consumed_capacity = self.action_params.get(
                parser.Props.RETURN_CONSUMED_CAPACITY,
                parser.Values.RETURN_CONSUMED_CAPACITY_NONE)

            exclusive_start_key = self.action_params.get(
                parser.Props.EXCLUSIVE_START_KEY, None)

            exclusive_start_key = parser.Parser.parse_item_attributes(
                exclusive_start_key) if exclusive_start_key else None

            scan_filter = self.action_params.get(parser.Props.SCAN_FILTER, {})

            condition_map = parser.Parser.parse_attribute_conditions(
                scan_filter)

            segment = self.action_params.get(parser.Props.SEGMENT, 0)
            total_segments = self.action_params.get(
                parser.Props.TOTAL_SEGMENTS, 1)

            assert segment < total_segments
        except Exception:
            raise exception.AWSErrorResponseException()

        try:
            result = storage.scan(self.context,
                                  table_name,
                                  condition_map,
                                  attributes_to_get=attrs_to_get,
                                  limit=limit,
                                  exclusive_start_key=exclusive_start_key)

            response = {
                parser.Props.COUNT: result.count,
                parser.Props.SCANNED_COUNT: result.scanned_count
            }

            if not select_type.is_count:
                response[parser.Props.ITEMS] = [
                    parser.Parser.format_item_attributes(row)
                    for row in result.items
                ]

            if (return_consumed_capacity !=
                    parser.Values.RETURN_CONSUMED_CAPACITY_NONE):
                response[parser.Props.CONSUMED_CAPACITY] = (
                    parser.Parser.format_consumed_capacity(
                        return_consumed_capacity, None))

            if result.last_evaluated_key:
                response[parser.Props.LAST_EVALUATED_KEY] = (
                    parser.Parser.format_item_attributes(
                        result.last_evaluated_key))

            return response
        except exception.AWSErrorResponseException as e:
            raise e
        except Exception:
            raise exception.AWSErrorResponseException()
Esempio n. 7
0
    def __call__(self):
        #TODO ikhudoshyn: table_name may be index name
        table_name = self.action_params.get(parser.Props.TABLE_NAME, None)

        attrs_to_get = self.action_params.get(
            parser.Props.ATTRIBUTES_TO_GET, None)

        select = self.action_params.get(
            parser.Props.SELECT, None)

        select_type = parser.Parser.parse_select_type(select, attrs_to_get)

        limit = self.action_params.get(parser.Props.LIMIT, None)

        return_consumed_capacity = self.action_params.get(
            parser.Props.RETURN_CONSUMED_CAPACITY,
            parser.Values.RETURN_CONSUMED_CAPACITY_NONE
        )

        exclusive_start_key = self.action_params.get(
            parser.Props.EXCLUSIVE_START_KEY, None
        )

        exclusive_start_key = parser.Parser.parse_item_attributes(
            exclusive_start_key) if exclusive_start_key else None

        scan_filter = self.action_params.get(
            parser.Props.SCAN_FILTER, None
        )

        segment = self.action_params.get(parser.Props.SEGMENT, 0)
        total_segments = self.action_params.get(parser.Props.TOTAL_SEGMENTS, 1)

        assert segment < total_segments

        condition_map = None

        result = storage.scan(
            self.context, table_name, condition_map,
            attributes_to_get=attrs_to_get, limit=limit,
            exclusive_start_key=exclusive_start_key)

        response = {}

        if select_type.is_count:
            response[parser.Props.COUNT] = result
        else:
            response[parser.Props.ITEMS] = [
                parser.Parser.format_item_attributes(row)
                for row in result]

            response[parser.Props.COUNT] = len(response)

            response[parser.Props.LAST_EVALUATED_KEY] = None

        if (return_consumed_capacity !=
                parser.Values.RETURN_CONSUMED_CAPACITY_NONE):
            response[parser.Props.CONSUMED_CAPACITY] = (
                parser.Parser.format_consumed_capacity(
                    return_consumed_capacity, None
                )
            )

        return response