Ejemplo n.º 1
0
    def test_describe_unexisting_table(self):
        self.storage_mocker.StubOutWithMock(storage, "describe_table")

        storage.describe_table(IgnoreArg(), "test_table1").AndRaise(TableNotExistsException)

        self.storage_mocker.ReplayAll()

        headers = {
            "Host": "localhost:8080",
            "Content-Type": "application/x-amz-json-1.0",
            "X-Amz-Target": "DynamoDB_20120810.DescribeTable",
        }

        conn = httplib.HTTPConnection("localhost:8080")
        conn.request("POST", "/", body='{"TableName": "test_table1"}', headers=headers)

        response = conn.getresponse()

        json_response = response.read()
        response_model = json.loads(json_response)

        self.assertEqual(response_model["__type"], "com.amazonaws.dynamodb.v20111205#ResourceNotFoundException")

        self.assertEqual(response_model["message"], "The resource which is being requested does not exist.")

        self.assertEqual(400, response.status)

        self.assertEqual(response.getheader("Content-Type"), "application/x-amz-json-1.0")
Ejemplo n.º 2
0
    def test_delete_table(self):
        self.storage_mocker.StubOutWithMock(storage, 'delete_table')
        self.storage_mocker.StubOutWithMock(storage, 'describe_table')
        storage.delete_table(mox.IgnoreArg(), 'test_table')

        storage.describe_table(mox.IgnoreArg(), 'test_table').AndReturn(
            models.TableMeta(
                '00000000-0000-0000-0000-000000000000',
                models.TableSchema(
                    {
                        'city1': models.AttributeType('S'),
                        'id': models.AttributeType('S'),
                        'name': models.AttributeType('S')
                    },
                    ['id', 'name'],
                    {'index_name': models.IndexDefinition('id', 'city1')}
                ),
                models.TableMeta.TABLE_STATUS_ACTIVE,
                None
            )
        )

        self.storage_mocker.ReplayAll()

        table = ddb_table.Table(
            'test_table',
            connection=self.DYNAMODB_CON
        )

        self.assertTrue(table.delete())

        self.storage_mocker.VerifyAll()
Ejemplo n.º 3
0
    def test_update_item(self):
        self.storage_mocker.StubOutWithMock(storage, 'get_item')

        hash_key = "4.5621201231232132132132132132132142354E126"
        range_key = "range"

        storage.get_item(
            mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg(),
            select_type=mox.IgnoreArg(),
            consistent=mox.IgnoreArg()
        ).AndReturn(
            models.SelectResult(
                items=[
                    {
                        "hash_key": models.AttributeValue('N', hash_key),
                        "range_key": models.AttributeValue('S', range_key),
                        "attr_value": models.AttributeValue('S', 'val')
                    }
                ]
            )
        )

        self.storage_mocker.StubOutWithMock(storage, 'describe_table')

        storage.describe_table(mox.IgnoreArg(), 'test_table').AndReturn(
            models.TableMeta(
                '00000000-0000-0000-0000-000000000000',
                models.TableSchema(
                    {
                        'hash_key': models.AttributeType('N'),
                        'range_key': models.AttributeType('S')
                    },
                    ['hash_key', 'range_key'],
                ),
                models.TableMeta.TABLE_STATUS_ACTIVE,
                None
            )
        )

        self.storage_mocker.StubOutWithMock(storage, 'update_item')
        storage.update_item(
            mox.IgnoreArg(), mox.IgnoreArg(),
            key_attribute_map=mox.IgnoreArg(),
            attribute_action_map=mox.IgnoreArg(),
            expected_condition_map=mox.IgnoreArg()).AndReturn((True, None))

        self.storage_mocker.ReplayAll()

        table = ddb_table.Table(
            'test_table',
            connection=self.DYNAMODB_CON
        )

        item = table.get_item(consistent=False, hash_key=1, range_key="range")

        item['attr_value'] = 'updated'

        item.partial_save()

        self.storage_mocker.VerifyAll()
Ejemplo n.º 4
0
    def test_describe_unexisting_table(self):

        self.storage_mocker.StubOutWithMock(storage, 'describe_table')

        storage.describe_table(
            mox.IgnoreArg(), 'test_table1'
        ).AndRaise(exception.TableNotExistsException)

        self.storage_mocker.ReplayAll()

        table = ddb_table.Table(
            'test_table1',
            connection=self.DYNAMODB_CON
        )

        try:
            table.describe()
        except boto_exc.JSONResponseError as e:
            self.assertEqual(
                e.body['__type'],
                'com.amazonaws.dynamodb.v20111205#ResourceNotFoundException')

            self.assertEqual(
                e.body['message'],
                'The resource which is being requested does not exist.')
Ejemplo n.º 5
0
    def test_describe_unexisting_table(self):
        self.storage_mocker.StubOutWithMock(storage, 'describe_table')

        storage.describe_table(mox.IgnoreArg(), 'test_table1').AndRaise(
            exception.TableNotExistsException
        )

        self.storage_mocker.ReplayAll()

        headers = {'Host': 'localhost:8080',
                   'Content-Type': 'application/x-amz-json-1.0',
                   'X-Amz-Target': 'DynamoDB_20120810.DescribeTable'}

        conn = httplib.HTTPConnection('localhost:8080')
        conn.request("POST", "/", body='{"TableName": "test_table1"}',
                     headers=headers)

        response = conn.getresponse()

        json_response = response.read()
        response_model = json.loads(json_response)

        self.assertEqual(
            response_model['__type'],
            'com.amazonaws.dynamodb.v20111205#ResourceNotFoundException')

        self.assertEqual(
            response_model['message'],
            'The resource which is being requested does not exist.')

        self.assertEqual(400, response.status)

        self.assertEqual(
            response.getheader('Content-Type'), 'application/x-amz-json-1.0')
Ejemplo n.º 6
0
    def test_describe_table(self):

        self.storage_mocker.StubOutWithMock(storage, 'describe_table')

        storage.describe_table(IgnoreArg(), 'test_table').AndReturn(
            models.TableMeta(
                models.TableSchema(
                    {
                        'city1': models.ATTRIBUTE_TYPE_STRING,
                        'id': models.ATTRIBUTE_TYPE_STRING,
                        'name': models.ATTRIBUTE_TYPE_STRING
                    }, ['id', 'name'],
                    {'index_name': models.IndexDefinition('city1')}),
                models.TableMeta.TABLE_STATUS_ACTIVE))

        self.storage_mocker.ReplayAll()

        table = Table('test_table', connection=self.DYNAMODB_CON)

        table_description = table.describe()

        self.storage_mocker.VerifyAll()

        self.assertEquals('test_table',
                          table_description['Table']['TableName'])
        self.assertItemsEqual([{
            "AttributeName": "city1",
            "AttributeType": "S"
        }, {
            "AttributeName": "id",
            "AttributeType": "S"
        }, {
            "AttributeName": "name",
            "AttributeType": "S"
        }], table_description['Table']['AttributeDefinitions'])
Ejemplo n.º 7
0
    def test_delete_table(self):
        self.storage_mocker.StubOutWithMock(storage, 'delete_table')
        self.storage_mocker.StubOutWithMock(storage, 'describe_table')
        storage.delete_table(IgnoreArg(), 'test_table')

        storage.describe_table(IgnoreArg(), 'test_table').AndReturn(
            models.TableMeta(
                models.TableSchema(
                    {
                        'city1': models.ATTRIBUTE_TYPE_STRING,
                        'id': models.ATTRIBUTE_TYPE_STRING,
                        'name': models.ATTRIBUTE_TYPE_STRING
                    },
                    ['id', 'name'],
                    {'index_name': models.IndexDefinition('city1')}
                ),
                models.TableMeta.TABLE_STATUS_ACTIVE
            )
        )

        self.storage_mocker.ReplayAll()

        table = Table('test_table', connection=self.DYNAMODB_CON)

        self.assertTrue(table.delete())

        self.storage_mocker.VerifyAll()
Ejemplo n.º 8
0
    def test_update_item(self):
        self.storage_mocker.StubOutWithMock(storage, 'get_item')

        hash_key = "4.5621201231232132132132132132132142354E126"
        range_key = "range"

        storage.get_item(
            IgnoreArg(), IgnoreArg(), IgnoreArg(),
            select_type=IgnoreArg(),
            consistent=IgnoreArg()
        ).AndReturn(
            models.SelectResult(
                items=[
                    {
                        "hash_key": models.AttributeValue('N', hash_key),
                        "range_key": models.AttributeValue('S', range_key),
                        "attr_value": models.AttributeValue('S', 'val')
                    }
                ]
            )
        )

        self.storage_mocker.StubOutWithMock(storage, 'describe_table')

        storage.describe_table(IgnoreArg(), 'test_table').AndReturn(
            models.TableMeta(
                '00000000-0000-0000-0000-000000000000',
                models.TableSchema(
                    {
                        'hash_key': models.AttributeType('N'),
                        'range_key': models.AttributeType('S')
                    },
                    ['hash_key', 'range_key'],
                ),
                models.TableMeta.TABLE_STATUS_ACTIVE,
                None
            )
        )

        self.storage_mocker.StubOutWithMock(storage, 'update_item')
        storage.update_item(
            IgnoreArg(), IgnoreArg(),
            key_attribute_map=IgnoreArg(),
            attribute_action_map=IgnoreArg(),
            expected_condition_map=IgnoreArg()).AndReturn((True, None))

        self.storage_mocker.ReplayAll()

        table = Table('test_table', connection=self.DYNAMODB_CON)

        item = table.get_item(consistent=False, hash_key=1, range_key="range")

        item['attr_value'] = 'updated'

        item.partial_save()

        self.storage_mocker.VerifyAll()
Ejemplo n.º 9
0
    def test_update_item(self):
        self.storage_mocker.StubOutWithMock(storage, 'select_item')

        hash_key = "4.5621201231232132132132132132132142354E126"
        range_key = "range"

        storage.select_item(
            IgnoreArg(), IgnoreArg(), IgnoreArg(),
            select_type=IgnoreArg(), limit=IgnoreArg(),
            consistent=IgnoreArg()
        ).AndReturn(
            models.SelectResult(
                items=[
                    {
                        "hash_key": models.AttributeValue.number(hash_key),
                        "range_key": models.AttributeValue.str(range_key),
                        "attr_value": models.AttributeValue.str('val')
                    }
                ]
            )
        )

        self.storage_mocker.StubOutWithMock(storage, 'describe_table')

        storage.describe_table(IgnoreArg(), 'test_table').AndReturn(
            models.TableSchema(
                'test_table',
                {
                    'hash_key': models.ATTRIBUTE_TYPE_NUMBER,
                    'range_key': models.ATTRIBUTE_TYPE_STRING
                },
                ['hash_key', 'range_key'],
            )
        )

        self.storage_mocker.StubOutWithMock(storage, 'update_item')
        storage.update_item(
            IgnoreArg(), IgnoreArg(),
            key_attribute_map=IgnoreArg(),
            attribute_action_map=IgnoreArg(),
            expected_condition_map=IgnoreArg()).AndReturn(True)

        self.storage_mocker.ReplayAll()

        table = Table('test_table', connection=self.DYNAMODB_CON)

        item = table.get_item(consistent=False, hash_key=1, range_key="range")

        item['attr_value'] = 'updated'

        item.partial_save()

        self.storage_mocker.VerifyAll()
Ejemplo n.º 10
0
    def test_update_item(self):
        self.storage_mocker.StubOutWithMock(storage, 'select_item')

        hash_key = "4.5621201231232132132132132132132142354E126"
        range_key = "range"

        storage.select_item(
            IgnoreArg(),
            IgnoreArg(),
            IgnoreArg(),
            select_type=IgnoreArg(),
            limit=IgnoreArg(),
            consistent=IgnoreArg()).AndReturn(
                models.SelectResult(
                    items=[{
                        "hash_key": models.AttributeValue.number(hash_key),
                        "range_key": models.AttributeValue.str(range_key),
                        "attr_value": models.AttributeValue.str('val')
                    }]))

        self.storage_mocker.StubOutWithMock(storage, 'describe_table')

        storage.describe_table(IgnoreArg(), 'test_table').AndReturn(
            models.TableMeta(
                models.TableSchema(
                    {
                        'hash_key': models.ATTRIBUTE_TYPE_NUMBER,
                        'range_key': models.ATTRIBUTE_TYPE_STRING
                    },
                    ['hash_key', 'range_key'],
                ), models.TableMeta.TABLE_STATUS_ACTIVE))

        self.storage_mocker.StubOutWithMock(storage, 'update_item')
        storage.update_item(IgnoreArg(),
                            IgnoreArg(),
                            key_attribute_map=IgnoreArg(),
                            attribute_action_map=IgnoreArg(),
                            expected_condition_map=IgnoreArg()).AndReturn(True)

        self.storage_mocker.ReplayAll()

        table = Table('test_table', connection=self.DYNAMODB_CON)

        item = table.get_item(consistent=False, hash_key=1, range_key="range")

        item['attr_value'] = 'updated'

        item.partial_save()

        self.storage_mocker.VerifyAll()
    def projects_usage_details(self, req):
        if 'metrics' not in req.GET:
            keys = ['size', 'item_count']
        else:
            keys = req.GET['metrics'].split(',')

        tables = storage.list_tenant_tables(
            last_evaluated_project=req.GET.get('last_evaluated_project'),
            last_evaluated_table=req.GET.get('last_evaluated_table'),
            limit=req.GET.get('limit', 1000)
        )

        for row in tables:
            req.context.tenant = row["tenant"]
            try:
                row["usage_detailes"] = storage.get_table_statistics(
                    req.context, row["name"], keys
                )
            except exception.ValidationError:
                table_meta = storage.describe_table(req.context,
                                                    row["name"])
                row["status"] = table_meta.status
                row["usage_detailes"] = {}

        return tables
Ejemplo n.º 12
0
    def test_describe_table(self):

        self.storage_mocker.StubOutWithMock(storage, 'describe_table')

        storage.describe_table(IgnoreArg(), 'test_table').AndReturn(
            models.TableMeta(
                '00000000-0000-0000-0000-000000000000',
                models.TableSchema(
                    {
                        'city1': models.AttributeType('S'),
                        'id': models.AttributeType('S'),
                        'name': models.AttributeType('S')
                    },
                    ['id', 'name'],
                    {'index_name': models.IndexDefinition('id', 'city1')}
                ),
                models.TableMeta.TABLE_STATUS_ACTIVE,
                None
            )
        )

        self.storage_mocker.ReplayAll()

        table = Table('test_table', connection=self.DYNAMODB_CON)

        table_description = table.describe()

        self.storage_mocker.VerifyAll()

        self.assertEqual('test_table',
                         table_description['Table']['TableName'])
        self.assertItemsEqual(
            [
                {
                    "AttributeName": "city1",
                    "AttributeType": "S"
                },
                {
                    "AttributeName": "id",
                    "AttributeType": "S"
                },
                {
                    "AttributeName": "name",
                    "AttributeType": "S"
                }
            ], table_description['Table']['AttributeDefinitions'])
Ejemplo n.º 13
0
    def test_describe_table(self):

        self.storage_mocker.StubOutWithMock(storage, 'describe_table')

        storage.describe_table(IgnoreArg(), 'test_table').AndReturn(
            models.TableSchema(
                'test_table',
                {
                    'city1': models.ATTRIBUTE_TYPE_STRING,
                    'id': models.ATTRIBUTE_TYPE_STRING,
                    'name': models.ATTRIBUTE_TYPE_STRING
                },
                ['id', 'name'],
                {'index_name': models.IndexDefinition('city1')}
            )
        )

        self.storage_mocker.ReplayAll()

        table = Table('test_table', connection=self.DYNAMODB_CON)

        table_description = table.describe()

        self.storage_mocker.VerifyAll()

        self.assertEquals('test_table',
                          table_description['Table']['TableName'])
        self.assertItemsEqual(
            [
                {
                    "AttributeName": "city1",
                    "AttributeType": "S"
                },
                {
                    "AttributeName": "id",
                    "AttributeType": "S"
                },
                {
                    "AttributeName": "name",
                    "AttributeType": "S"
                }
            ], table_description['Table']['AttributeDefinitions'])
Ejemplo n.º 14
0
    def describe_table(self, req, project_id, table_name):
        try:
            req.context.tenant = project_id

            table_schema = storage.describe_table(req.context, table_name)

            url = req.path_url
            bookmark = req.path_url

            return {
                parser.Props.TABLE: {
                    parser.Props.ATTRIBUTE_DEFINITIONS: (
                        parser.Parser.format_attribute_definitions(
                            table_schema.attribute_type_map
                        )
                    ),
                    parser.Props.CREATION_DATE_TIME: 0,
                    parser.Props.ITEM_COUNT: 0,
                    parser.Props.KEY_SCHEMA: (
                        parser.Parser.format_key_schema(
                            table_schema.key_attributes
                        )
                    ),
                    parser.Props.LOCAL_SECONDARY_INDEXES: (
                        parser.Parser.format_local_secondary_indexes(
                            table_schema.key_attributes[0],
                            table_schema.index_def_map
                        )
                    ),
                    parser.Props.TABLE_NAME: table_schema.table_name,

                    parser.Props.TABLE_STATUS: (
                        parser.Values.TABLE_STATUS_ACTIVE),
                    parser.Props.TABLE_SIZE_BYTES: 0,

                    parser.Props.LINKS: [
                        {
                            parser.Props.HREF: url,
                            parser.Props.REL: parser.Values.SELF
                        },
                        {
                            parser.Props.HREF: bookmark,
                            parser.Props.REL: parser.Values.BOOKMARK
                        }
                    ]
                }
            }

        except exception.TableNotExistsException as e:
            raise exception.ResourceNotFoundException(e.message)
        except exception.AWSErrorResponseException as e:
            raise e
        except Exception:
            raise exception.AWSErrorResponseException()
Ejemplo n.º 15
0
    def describe_table(self, req, project_id, table_name):
        utils.check_project_id(req.context, project_id)
        req.context.tenant = project_id

        validation.validate_table_name(table_name)

        table_meta = storage.describe_table(req.context, table_name)

        url = req.path_url
        bookmark = req.path_url

        result = {
            parser.Props.TABLE: {
                parser.Props.ATTRIBUTE_DEFINITIONS: (
                    parser.Parser.format_attribute_definitions(
                        table_meta.schema.attribute_type_map)),

                parser.Props.CREATION_DATE_TIME: table_meta.creation_date_time,
                parser.Props.ITEM_COUNT: 0,

                parser.Props.KEY_SCHEMA: (
                    parser.Parser.format_key_schema(
                        table_meta.schema.key_attributes)),

                parser.Props.TABLE_ID: str(table_meta.id),
                parser.Props.TABLE_NAME: table_name,

                parser.Props.TABLE_STATUS: (
                    parser.Parser.format_table_status(table_meta.status)),

                parser.Props.TABLE_SIZE_BYTES: 0,

                parser.Props.LINKS: [
                    {
                        parser.Props.HREF: url,
                        parser.Props.REL: parser.Values.SELF
                    },
                    {
                        parser.Props.HREF: bookmark,
                        parser.Props.REL: parser.Values.BOOKMARK
                    }
                ]
            }
        }

        if table_meta.schema.index_def_map:
            table_def = result[parser.Props.TABLE]
            table_def[parser.Props.LOCAL_SECONDARY_INDEXES] = (
                parser.Parser.format_local_secondary_indexes(
                    table_meta.schema.key_attributes[0],
                    table_meta.schema.index_def_map
                )
            )
        return result
Ejemplo n.º 16
0
    def __call__(self):

        table_name = self.action_params.get(parser.Props.TABLE_NAME, None)

        if not table_name:
            raise ddb_exception.AWSValidationException(
                message='Table name is not defined'
            )

        try:
            table_meta = storage.describe_table(self.context, table_name)

            result = {
                parser.Props.TABLE: {
                    parser.Props.ATTRIBUTE_DEFINITIONS: (
                        parser.Parser.format_attribute_definitions(
                            table_meta.schema.attribute_type_map
                        )
                    ),
                    parser.Props.CREATION_DATE_TIME: 0,
                    parser.Props.ITEM_COUNT: 0,
                    parser.Props.KEY_SCHEMA: (
                        parser.Parser.format_key_schema(
                            table_meta.schema.key_attributes
                        )
                    ),
                    parser.Props.PROVISIONED_THROUGHPUT: (
                        parser.Values.PROVISIONED_THROUGHPUT_DUMMY
                    ),
                    parser.Props.TABLE_NAME: table_name,
                    parser.Props.TABLE_STATUS: (
                        parser.Parser.format_table_status(table_meta.status)
                    ),
                    parser.Props.TABLE_SIZE_BYTES: 0
                }
            }

            if table_meta.schema.index_def_map:
                table_def = result[parser.Props.TABLE]
                table_def[parser.Props.LOCAL_SECONDARY_INDEXES] = (
                    parser.Parser.format_local_secondary_indexes(
                        table_meta.schema.key_attributes[0],
                        table_meta.schema.index_def_map
                    )
                )
            return result

        except exception.TableNotExistsException:
            raise ddb_exception.AWSResourceNotFoundException()
        except ddb_exception.AWSErrorResponseException as e:
            raise e
        except Exception:
            raise ddb_exception.AWSErrorResponseException()
Ejemplo n.º 17
0
    def describe_table(self, req, project_id, table_name):
        validation.validate_table_name(table_name)

        table_meta = storage.describe_table(req.context, table_name)

        url = req.path_url
        bookmark = req.path_url

        result = {
            parser.Props.TABLE: {
                parser.Props.ATTRIBUTE_DEFINITIONS: (
                    parser.Parser.format_attribute_definitions(
                        table_meta.schema.attribute_type_map)),

                parser.Props.CREATION_DATE_TIME: table_meta.creation_date_time,
                parser.Props.ITEM_COUNT: 0,

                parser.Props.KEY_SCHEMA: (
                    parser.Parser.format_key_schema(
                        table_meta.schema.key_attributes)),

                parser.Props.TABLE_ID: str(table_meta.id),
                parser.Props.TABLE_NAME: table_name,

                parser.Props.TABLE_STATUS: (
                    parser.Parser.format_table_status(table_meta.status)),

                parser.Props.TABLE_SIZE_BYTES: 0,

                parser.Props.LINKS: [
                    {
                        parser.Props.HREF: url,
                        parser.Props.REL: parser.Values.SELF
                    },
                    {
                        parser.Props.HREF: bookmark,
                        parser.Props.REL: parser.Values.BOOKMARK
                    }
                ]
            }
        }

        if table_meta.schema.index_def_map:
            table_def = result[parser.Props.TABLE]
            table_def[parser.Props.LOCAL_SECONDARY_INDEXES] = (
                parser.Parser.format_local_secondary_indexes(
                    table_meta.schema.key_attributes[0],
                    table_meta.schema.index_def_map
                )
            )

        return result
Ejemplo n.º 18
0
    def test_describe_unexisting_table(self):

        self.storage_mocker.StubOutWithMock(storage, 'describe_table')

        storage.describe_table(
            IgnoreArg(), 'test_table1'
        ).AndRaise(TableNotExistsException)

        self.storage_mocker.ReplayAll()

        table = Table('test_table1', connection=self.DYNAMODB_CON)

        try:
            table.describe()
        except JSONResponseError as e:
            self.assertEqual(
                e.body['__type'],
                'com.amazonaws.dynamodb.v20111205#ResourceNotFoundException')

            self.assertEqual(
                e.body['message'],
                'The resource which is being requested does not exist.')
Ejemplo n.º 19
0
    def test_delete_table(self):
        self.storage_mocker.StubOutWithMock(storage, 'delete_table')
        self.storage_mocker.StubOutWithMock(storage, 'describe_table')
        storage.delete_table(IgnoreArg(), 'test_table')

        storage.describe_table(IgnoreArg(), 'test_table').AndReturn(
            models.TableMeta(
                models.TableSchema(
                    {
                        'city1': models.ATTRIBUTE_TYPE_STRING,
                        'id': models.ATTRIBUTE_TYPE_STRING,
                        'name': models.ATTRIBUTE_TYPE_STRING
                    }, ['id', 'name'],
                    {'index_name': models.IndexDefinition('city1')}),
                models.TableMeta.TABLE_STATUS_ACTIVE))

        self.storage_mocker.ReplayAll()

        table = Table('test_table', connection=self.DYNAMODB_CON)

        self.assertTrue(table.delete())

        self.storage_mocker.VerifyAll()
Ejemplo n.º 20
0
    def test_describe_unexisting_table(self):
        self.storage_mocker.StubOutWithMock(storage, 'describe_table')

        storage.describe_table(IgnoreArg(),
                               'test_table1').AndRaise(TableNotExistsException)

        self.storage_mocker.ReplayAll()

        headers = {
            'Host': 'localhost:8080',
            'Content-Type': 'application/x-amz-json-1.0',
            'X-Amz-Target': 'DynamoDB_20120810.DescribeTable'
        }

        conn = httplib.HTTPConnection('localhost:8080')
        conn.request("POST",
                     "/",
                     body='{"TableName": "test_table1"}',
                     headers=headers)

        response = conn.getresponse()

        json_response = response.read()
        response_model = json.loads(json_response)

        self.assertEqual(
            response_model['__type'],
            'com.amazonaws.dynamodb.v20111205#ResourceNotFoundException')

        self.assertEqual(
            response_model['message'],
            'The resource which is being requested does not exist.')

        self.assertEqual(400, response.status)

        self.assertEqual(response.getheader('Content-Type'),
                         'application/x-amz-json-1.0')
Ejemplo n.º 21
0
    def delete_table(self, req, project_id, table_name):
        utils.check_project_id(req.context, project_id)
        req.context.tenant = project_id

        table_schema = storage.describe_table(req.context, table_name)
        storage.delete_table(req.context, table_name)

        url = req.path_url
        bookmark = req.path_url

        return {
            parser.Props.TABLE_DESCRIPTION: {
                parser.Props.ATTRIBUTE_DEFINITIONS: (
                    parser.Parser.format_attribute_definitions(
                        table_schema.schema.attribute_type_map
                    )
                ),
                parser.Props.CREATION_DATE_TIME: 0,
                parser.Props.ITEM_COUNT: 0,
                parser.Props.KEY_SCHEMA: (
                    parser.Parser.format_key_schema(
                        table_schema.schema.key_attributes
                    )
                ),
                parser.Props.LOCAL_SECONDARY_INDEXES: (
                    parser.Parser.format_local_secondary_indexes(
                        table_schema.schema.key_attributes[0],
                        table_schema.schema.index_def_map
                    )
                ),
                parser.Props.TABLE_NAME: table_name,

                parser.Props.TABLE_STATUS: (
                    parser.Values.TABLE_STATUS_ACTIVE),
                parser.Props.TABLE_SIZE_BYTES: 0,

                parser.Props.LINKS: [
                    {
                        parser.Props.HREF: url,
                        parser.Props.REL: parser.Values.SELF
                    },
                    {
                        parser.Props.HREF: bookmark,
                        parser.Props.REL: parser.Values.BOOKMARK
                    }
                ]
            }
        }
Ejemplo n.º 22
0
    def __call__(self):

        table_name = self.action_params.get(parser.Props.TABLE_NAME, None)

        if not table_name:
            raise ddb_exception.AWSValidationException(
                message='Table name is not defined')

        try:
            table_meta = storage.describe_table(self.context, table_name)

            result = {
                parser.Props.TABLE: {
                    parser.Props.ATTRIBUTE_DEFINITIONS:
                    (parser.Parser.format_attribute_definitions(
                        table_meta.schema.attribute_type_map)),
                    parser.Props.CREATION_DATE_TIME:
                    0,
                    parser.Props.ITEM_COUNT:
                    0,
                    parser.Props.KEY_SCHEMA: (parser.Parser.format_key_schema(
                        table_meta.schema.key_attributes)),
                    parser.Props.PROVISIONED_THROUGHPUT:
                    (parser.Values.PROVISIONED_THROUGHPUT_DUMMY),
                    parser.Props.TABLE_NAME:
                    table_name,
                    parser.Props.TABLE_STATUS:
                    (parser.Parser.format_table_status(table_meta.status)),
                    parser.Props.TABLE_SIZE_BYTES:
                    0
                }
            }

            if table_meta.schema.index_def_map:
                table_def = result[parser.Props.TABLE]
                table_def[parser.Props.LOCAL_SECONDARY_INDEXES] = (
                    parser.Parser.format_local_secondary_indexes(
                        table_meta.schema.key_attributes[0],
                        table_meta.schema.index_def_map))
            return result

        except exception.TableNotExistsException:
            raise ddb_exception.AWSResourceNotFoundException()
        except ddb_exception.AWSErrorResponseException as e:
            raise e
        except Exception:
            raise ddb_exception.AWSErrorResponseException()
Ejemplo n.º 23
0
    def __call__(self):

        table_name = self.action_params.get(Props.TABLE_NAME, None)

        try:
            table_meta = storage.describe_table(self.context, table_name)

            storage.delete_table(self.context, table_name)

            # TODO (isviridov): fill ITEM_COUNT, TABLE_SIZE_BYTES,
            # CREATION_DATE_TIME with real data
            return {
                Props.TABLE_DESCRIPTION: {
                    Props.ATTRIBUTE_DEFINITIONS: (
                        Parser.format_attribute_definitions(
                            table_meta.schema.attribute_type_map
                        )
                    ),
                    Props.CREATION_DATE_TIME: 0,
                    Props.ITEM_COUNT: 0,
                    Props.KEY_SCHEMA: (
                        Parser.format_key_schema(
                            table_meta.schema.key_attributes
                        )
                    ),
                    Props.LOCAL_SECONDARY_INDEXES: (
                        Parser.format_local_secondary_indexes(
                            table_meta.schema.key_attributes[0],
                            table_meta.schema.index_def_map
                        )
                    ),
                    Props.PROVISIONED_THROUGHPUT: (
                        Values.PROVISIONED_THROUGHPUT_DUMMY
                    ),
                    Props.TABLE_NAME: table_name,
                    Props.TABLE_STATUS: Parser.format_table_status(
                        table_meta.status
                    ),
                    Props.TABLE_SIZE_BYTES: 0
                }
            }
        except exception.AWSErrorResponseException as e:
            raise e
        except Exception:
            raise exception.AWSErrorResponseException()
Ejemplo n.º 24
0
    def __call__(self):

        table_name = self.action_params.get(parser.Props.TABLE_NAME, None)

        try:
            table_meta = storage.describe_table(self.context, table_name)

            storage.delete_table(self.context, table_name)

            # TODO(isviridov): fill ITEM_COUNT, TABLE_SIZE_BYTES,
            # CREATION_DATE_TIME with real data
            return {
                parser.Props.TABLE_DESCRIPTION: {
                    parser.Props.ATTRIBUTE_DEFINITIONS: (
                        parser.Parser.format_attribute_definitions(
                            table_meta.schema.attribute_type_map
                        )
                    ),
                    parser.Props.CREATION_DATE_TIME: 0,
                    parser.Props.ITEM_COUNT: 0,
                    parser.Props.KEY_SCHEMA: (
                        parser.Parser.format_key_schema(
                            table_meta.schema.key_attributes
                        )
                    ),
                    parser.Props.LOCAL_SECONDARY_INDEXES: (
                        parser.Parser.format_local_secondary_indexes(
                            table_meta.schema.key_attributes[0],
                            table_meta.schema.index_def_map
                        )
                    ),
                    parser.Props.PROVISIONED_THROUGHPUT: (
                        parser.Values.PROVISIONED_THROUGHPUT_DUMMY
                    ),
                    parser.Props.TABLE_NAME: table_name,
                    parser.Props.TABLE_STATUS: (
                        parser.Parser.format_table_status(table_meta.status)
                    ),
                    parser.Props.TABLE_SIZE_BYTES: 0
                }
            }
        except exception.AWSErrorResponseException as e:
            raise e
        except Exception:
            raise exception.AWSErrorResponseException()
Ejemplo n.º 25
0
    def delete_table(self, req, project_id, table_name):
        utils.check_project_id(req.context, project_id)
        req.context.tenant = project_id

        table_schema = storage.describe_table(req.context, table_name)
        storage.delete_table(req.context, table_name)

        url = req.path_url
        bookmark = req.path_url

        return {
            parser.Props.TABLE_DESCRIPTION: {
                parser.Props.ATTRIBUTE_DEFINITIONS:
                (parser.Parser.format_attribute_definitions(
                    table_schema.schema.attribute_type_map)),
                parser.Props.CREATION_DATE_TIME:
                0,
                parser.Props.ITEM_COUNT:
                0,
                parser.Props.KEY_SCHEMA: (parser.Parser.format_key_schema(
                    table_schema.schema.key_attributes)),
                parser.Props.LOCAL_SECONDARY_INDEXES:
                (parser.Parser.format_local_secondary_indexes(
                    table_schema.schema.key_attributes[0],
                    table_schema.schema.index_def_map)),
                parser.Props.TABLE_NAME:
                table_name,
                parser.Props.TABLE_STATUS: (parser.Values.TABLE_STATUS_ACTIVE),
                parser.Props.TABLE_SIZE_BYTES:
                0,
                parser.Props.LINKS: [{
                    parser.Props.HREF: url,
                    parser.Props.REL: parser.Values.SELF
                }, {
                    parser.Props.HREF: bookmark,
                    parser.Props.REL: parser.Values.BOOKMARK
                }]
            }
        }
Ejemplo n.º 26
0
    def projects_usage_details(self, req):
        if 'metrics' not in req.GET:
            keys = ['size', 'item_count']
        else:
            keys = req.GET['metrics'].split(',')

        tables = storage.list_tenant_tables(
            last_evaluated_project=req.GET.get('last_evaluated_project'),
            last_evaluated_table=req.GET.get('last_evaluated_table'),
            limit=req.GET.get('limit', 1000))

        for row in tables:
            req.context.tenant = row["tenant"]
            try:
                row["usage_detailes"] = storage.get_table_statistics(
                    req.context, row["name"], keys)
            except exception.ValidationError:
                table_meta = storage.describe_table(req.context, row["name"])
                row["status"] = table_meta.status
                row["usage_detailes"] = {}

        return tables
Ejemplo n.º 27
0
    def __call__(self):

        table_name = self.action_params.get(Props.TABLE_NAME, None)

        table_schema = storage.describe_table(self.context, table_name)

        storage.delete_table(self.context, table_name)

        #TODO (isviridov): fill ITEM_COUNT, TABLE_SIZE_BYTES,
        # CREATION_DATE_TIME with real data
        return {
            Props.TABLE_DESCRIPTION: {
                Props.ATTRIBUTE_DEFINITIONS: (
                    map(Parser.format_attribute_definition,
                        table_schema.attribute_defs)
                ),
                Props.CREATION_DATE_TIME: 0,
                Props.ITEM_COUNT: 0,
                Props.KEY_SCHEMA: (
                    Parser.format_key_schema(
                        table_schema.key_attributes
                    )
                ),
                Props.LOCAL_SECONDARY_INDEXES: (
                    Parser.format_local_secondary_indexes(
                        table_schema.key_attributes[0],
                        table_schema.index_defs
                    )
                ),
                Props.PROVISIONED_THROUGHPUT: (
                    Values.PROVISIONED_THROUGHPUT_DUMMY
                ),
                Props.TABLE_NAME: table_schema.table_name,
                Props.TABLE_STATUS: Values.TABLE_STATUS_ACTIVE,
                Props.TABLE_SIZE_BYTES: 0
            }
        }
Ejemplo n.º 28
0
    def __call__(self):

        table_name = self.action_params.get(Props.TABLE_NAME, None)

        table_schema = storage.describe_table(self.context, table_name)

        if not table_name:
#           TODO (isviridov) implement the table not found
#           scenario should be ResourceNotFoundException HTTP status 400
            raise NotImplementedError()
        else:
            return {Props.TABLE: {
                Props.ATTRIBUTE_DEFINITIONS: (
                    map(Parser.format_attribute_definition,
                        table_schema.attribute_defs)
                    ),
                Props.CREATION_DATE_TIME: 0,
                Props.ITEM_COUNT: 0,
                Props.KEY_SCHEMA: (
                    Parser.format_key_schema(
                        table_schema.key_attributes
                    )
                ),
                Props.LOCAL_SECONDARY_INDEXES: (
                    Parser.format_local_secondary_indexes(
                        table_schema.key_attributes[0],
                        table_schema.index_defs
                    )
                ),
                Props.PROVISIONED_THROUGHPUT: (
                    Values.PROVISIONED_THROUGHPUT_DUMMY
                ),
                Props.TABLE_NAME: table_schema.table_name,
                Props.TABLE_STATUS: Values.TABLE_STATUS_ACTIVE,
                Props.TABLE_SIZE_BYTES: 0
            }}