コード例 #1
0
        protected Task WaitTillTableCreated(CreateTableResponse response)
        {
            var tableDescription = response.TableDescription;

            string status = tableDescription.TableStatus;

            Console.WriteLine(TABLENAME + " - " + status);

            // Let us wait until table is created. Call DescribeTable.
            while (status != "ACTIVE")
            {
                System.Threading.Thread.Sleep(5000); // Wait 5 seconds.
                try
                {
                    var res = Provider.DynamoDBClient.DescribeTableAsync(TABLENAME).Result;
                    Console.WriteLine("Table name: {0}, status: {1}", res.Table.TableName,
                                      res.Table.TableStatus);
                    status = res.Table.TableStatus;
                }
                // Try-catch to handle potential eventual-consistency issue.
                catch (ResourceNotFoundException)
                { }
            }
            return(Task.CompletedTask);
        }
コード例 #2
0
        public void CreateTable(CreateTableRequest request)
        {
            TableDescription tableDescription;
            var tableExists = TableExists(request.TableName);

            if (tableExists)
            {
                Console.WriteLine("Table found, deleting");
                DeleteTableResponse deleteResponse = Client.DeleteTableAsync(request.TableName).Result;
                Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode);

                tableDescription = Client.DescribeTableAsync(request.TableName).Result.Table;
                Assert.AreEqual(TableStatus.DELETING, tableDescription.TableStatus);
                do
                {
                    System.Threading.Thread.Sleep(200);
                    tableExists = TableExists(request.TableName);
                    Console.WriteLine("Table found after deleting, waiting.");
                } while (tableExists);
            }

            CreateTableResponse response = Client.CreateTableAsync(request).Result;

            Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);

            tableDescription = Client.DescribeTableAsync(request.TableName).Result.Table;
            Assert.AreEqual(TableStatus.CREATING, tableDescription.TableStatus);
            WaitForTableStatus(request.TableName, TableStatus.ACTIVE);
        }
コード例 #3
0
        public async Task DynamoDbService_Should_Create_A_DynamoDb_Table()
        {
            var tableName = Guid.NewGuid().ToString();
            CreateTableResponse createTableResponse = await CreateTestTable(tableName);

            Assert.Equal(HttpStatusCode.OK, createTableResponse.HttpStatusCode);
        }
コード例 #4
0
        private static void WaitTillTableCreated(AmazonDynamoDBClient client, string tableName,
                                                 CreateTableResponse response)
        {
            var tableDescription = response.TableDescription;

            string status = tableDescription.TableStatus;

            Console.WriteLine(tableName + " - " + status);

            // Let us wait until table is created. Call DescribeTable.
            while (status != "ACTIVE")
            {
                System.Threading.Thread.Sleep(5000); // Wait 5 seconds.
                try
                {
                    var res = client.DescribeTable(new DescribeTableRequest
                    {
                        TableName = tableName
                    });
                    Console.WriteLine("Table name: {0}, status: {1}", res.Table.TableName,
                                      res.Table.TableStatus);
                    status = res.Table.TableStatus;
                }
                // Try-catch to handle potential eventual-consistency issue.
                catch (ResourceNotFoundException)
                { }
            }
        }
コード例 #5
0
        private async Task WaitTillTableCreatedAsync(string tableName, CreateTableResponse response)
        {
            var tableDescription = response.TableDescription;

            string status = tableDescription.TableStatus;

            // Wait until table is created
            while (status != "ACTIVE")
            {
                System.Threading.Thread.Sleep(5000);

                try
                {
                    var res = await _dynamoDbClient.DescribeTableAsync(new DescribeTableRequest
                    {
                        TableName = tableName
                    });

                    status = res.Table.TableStatus;
                }
                catch (ResourceNotFoundException)
                {
                    // Try-catch to handle potential eventual-consistency issue
                }
            }
        }
        private void CreateTableHandler(CreateTableRequest request)
        {
            CreateTableResponse response = new CreateTableResponse(request);

            if (request.IsCreate)
            {
                if (request.TableNumber != -1)
                {
                    if (TableIsExists(Server.Receivers, request.TableNumber))
                    {
                        response.IsSuccess = false;
                    }
                    else
                    {
                        this.InGameProperties.Room = request.TableNumber;
                        this.Status        = StatusEnum.InProcess;
                        response.IsSuccess = true;
                    }
                }
                else
                {
                    this.InGameProperties.Room = GetRandomTable(Server.Receivers);
                    this.Status        = StatusEnum.InProcess;
                    response.IsSuccess = true;
                }
            }
            else
            {
                Status             = StatusEnum.Validated;
                response.IsSuccess = true;
            }
            SendMessage(response);

            UpdateTableInProcessRequestHandler();
        }
コード例 #7
0
        public static async Task <DescribeTableResponse> WaitTillTableCreated(IAmazonDynamoDB client, string tableName,
                                                                              CreateTableResponse response)
        {
            DescribeTableResponse resp = new DescribeTableResponse();

            var tableDescription = response.TableDescription;

            string status = tableDescription.TableStatus;

            Int32 sleepDuration = 1000;                             // One second

            while ((status != "ACTIVE") && (sleepDuration < 10000)) // Don't wait more than 10 seconds
            {
                System.Threading.Thread.Sleep(sleepDuration);

                resp = await client.DescribeTableAsync(new DescribeTableRequest
                {
                    TableName = tableName
                });

                status = resp.Table.TableStatus;

                sleepDuration *= 2;
            }

            return(resp);
        }
コード例 #8
0
        public async Task CreateTable()
        {
            Console.WriteLine("Creating Table");

            try
            {
                var createTableRequest = new CreateTableRequest
                {
                    DatabaseName        = Constants.DATABASE_NAME,
                    TableName           = Constants.TABLE_NAME,
                    RetentionProperties = new RetentionProperties
                    {
                        MagneticStoreRetentionPeriodInDays = Constants.CT_TTL_DAYS,
                        MemoryStoreRetentionPeriodInHours  = Constants.HT_TTL_HOURS
                    }
                };
                CreateTableResponse response = await writeClient.CreateTableAsync(createTableRequest);

                Console.WriteLine($"Table {Constants.TABLE_NAME} created");
            }
            catch (ConflictException)
            {
                Console.WriteLine("Table already exists.");
            }
            catch (Exception e)
            {
                Console.WriteLine("Create table failed:" + e.ToString());
            }
        }
コード例 #9
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateTableResponse response = new CreateTableResponse();


            return(response);
        }
コード例 #10
0
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateTableResponse response = new CreateTableResponse();

            context.Read();
            response.CreateTableResult = CreateTableResultUnmarshaller.GetInstance().Unmarshall(context);

            return(response);
        }
コード例 #11
0
        private Table CreateTable()
        {
            CreateTableRequest createRequest = new CreateTableRequest
            {
                TableName = this._tableName,
                KeySchema = new List <KeySchemaElement>
                {
                    new KeySchemaElement
                    {
                        AttributeName = ATTRIBUTE_SESSION_ID, KeyType = "HASH"
                    }
                },
                AttributeDefinitions = new List <AttributeDefinition>
                {
                    new AttributeDefinition
                    {
                        AttributeName = ATTRIBUTE_SESSION_ID, AttributeType = "S"
                    }
                },
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits  = this._initialReadUnits,
                    WriteCapacityUnits = this._initialWriteUnits
                }
            };

            createRequest.BeforeRequestEvent += this.UserAgentRequestEventHandler;

            CreateTableResponse response = this._ddbClient.CreateTable(createRequest);

            DescribeTableRequest descRequest = new DescribeTableRequest
            {
                TableName = this._tableName
            };

            descRequest.BeforeRequestEvent += this.UserAgentRequestEventHandler;

            // Wait till table is active
            bool isActive = false;

            while (!isActive)
            {
                Thread.Sleep(DESCRIBE_INTERVAL);
                DescribeTableResponse descResponse = this._ddbClient.DescribeTable(descRequest);
                string tableStatus = descResponse.Table.TableStatus;

                if (string.Equals(tableStatus, ACTIVE_STATUS, StringComparison.InvariantCultureIgnoreCase))
                {
                    isActive = true;
                }
            }

            Table table = Table.LoadTable(this._ddbClient, this._tableName, Table.DynamoDBConsumer.SessionStateProvider, DynamoDBEntryConversion.V1);

            return(table);
        }
コード例 #12
0
        public string CreateTable(CreateTableRequest createTableRequest)
        {
            CreateTableResponse createTableResponse = DynamoClient.CreateTable(createTableRequest);

            while (createTableResponse.TableDescription.TableStatus != "ACTIVE")
            {
                System.Threading.Thread.Sleep(5000);
            }
            return(createTableResponse.TableDescription.TableStatus.Value.ToString());
        }
コード例 #13
0
        private async Task CreateDynamoDbTableAsync(string tableName)
        {
            var response = new CreateTableResponse();

            try
            {
                var request = new CreateTableRequest
                {
                    TableName            = tableName,
                    AttributeDefinitions = new List <AttributeDefinition>
                    {
                        new AttributeDefinition
                        {
                            AttributeName = "Id",
                            AttributeType = "S"
                        },
                        new AttributeDefinition
                        {
                            AttributeName = "Version",
                            AttributeType = "S"
                        }
                    },
                    KeySchema = new List <KeySchemaElement>
                    {
                        new KeySchemaElement {
                            AttributeName = "Id", KeyType = KeyType.HASH
                        },
                        new KeySchemaElement {
                            AttributeName = "Version", KeyType = KeyType.RANGE
                        }
                    },
                    ProvisionedThroughput = new ProvisionedThroughput
                    {
                        ReadCapacityUnits  = 5,
                        WriteCapacityUnits = 5
                    },
                    StreamSpecification = new StreamSpecification
                    {
                        StreamViewType = StreamViewType.NEW_IMAGE,
                        StreamEnabled  = true
                    }
                };

                var createTableResponse = _dynamoDbClient.CreateTableAsync(request);
                response = await createTableResponse;
            }
            catch (Exception ex)
            {
                Logger.Log($"ERROR: Failed to create the new table, because: {ex.Message}");
            }

            await WaitTillTableCreatedAsync(tableName, response);
        }
コード例 #14
0
        private async Task <bool> CreateTable(CreateTableRequest table)
        {
            bool returnValue = false;

            if (!await this.TableExists(table))
            {
                CreateTableResponse response = await this.Client.CreateTableAsync(table);

                returnValue = (response.HttpStatusCode == System.Net.HttpStatusCode.OK);
            }

            return(returnValue);
        }
コード例 #15
0
        public string InitTableProcess()
        {
            List <string> currentTables = DynamoClient.ListTables().TableNames;

            if (!currentTables.Contains("DVD"))
            {
                var createTableRequest = new CreateTableRequest
                {
                    TableName             = "DVD",
                    ProvisionedThroughput = new ProvisionedThroughput
                    {
                        ReadCapacityUnits  = 1,
                        WriteCapacityUnits = 1
                    },
                    KeySchema = new List <KeySchemaElement>
                    {
                        new KeySchemaElement
                        {
                            AttributeName = "Title",
                            KeyType       = "HASH"
                        },
                        new KeySchemaElement
                        {
                            AttributeName = "ReleaseYear",
                            KeyType       = "RANGE"
                        },
                    },
                    AttributeDefinitions = new List <AttributeDefinition>()
                    {
                        new AttributeDefinition()
                        {
                            AttributeName = "Title", AttributeType = "S"
                        },
                        new AttributeDefinition()
                        {
                            AttributeName = "ReleaseYear", AttributeType = "N"
                        }
                    }
                };


                CreateTableResponse createTableResponse = DynamoClient.CreateTable(createTableRequest);

                while (createTableResponse.TableDescription.TableStatus != "ACTIVE")
                {
                    System.Threading.Thread.Sleep(5000);
                }
                return(createTableResponse.TableDescription.TableStatus.Value.ToString());
            }
            return("Empty Hand");
        }
コード例 #16
0
        // TODO: move this to terraform
        private async Task <Table> CreateTable(string tableName)
        {
            // Build a 'CreateTableRequest' for the new table
            CreateTableRequest createRequest = new CreateTableRequest
            {
                TableName            = tableName,
                AttributeDefinitions = new List <AttributeDefinition>()
                {
                    new AttributeDefinition
                    {
                        AttributeName = "ObjectKey",
                        AttributeType = "S"
                    },
                    new AttributeDefinition
                    {
                        AttributeName = "UpdatedDate",
                        AttributeType = "S"
                    }
                },
                KeySchema = new List <KeySchemaElement>()
                {
                    new KeySchemaElement
                    {
                        AttributeName = "ObjectKey",
                        KeyType       = "HASH"
                    },
                    new KeySchemaElement
                    {
                        AttributeName = "UpdatedDate",
                        KeyType       = "RANGE"
                    }
                },
            };

            createRequest.ProvisionedThroughput = new ProvisionedThroughput(1, 1);

            try
            {
                CreateTableResponse createResponse = await _dynamoDbClient.CreateTableAsync(createRequest);

                Console.WriteLine("\n\n Created table successfully!\n    Status of the new table: '{0}'", createResponse.TableDescription.TableStatus);
                Thread.Sleep(3000); // wait some times for creating table - TODO: should have better option
                return(Table.LoadTable(_dynamoDbClient, TableName));
            }
            catch (Exception ex)
            {
                Console.WriteLine("\n Error: failed to create the new table; " + ex.Message);
            }
            return(null);
        }
コード例 #17
0
        public void Init()
        {
            List <string> currentTables = _client.ListTables().TableNames;

            if (!currentTables.Contains("Reservation"))
            {
                var createTableRequest = new CreateTableRequest
                {
                    TableName             = "Reservation",
                    ProvisionedThroughput = new ProvisionedThroughput
                    {
                        ReadCapacityUnits  = 1,
                        WriteCapacityUnits = 1
                    },
                    KeySchema = new List <KeySchemaElement>
                    {
                        new KeySchemaElement
                        {
                            AttributeName = "Fullname",
                            KeyType       = "HASH"
                        },
                        new KeySchemaElement
                        {
                            AttributeName = "DateTime",
                            KeyType       = "RANGE"
                        },
                    },
                    AttributeDefinitions = new List <AttributeDefinition>()
                    {
                        new AttributeDefinition()
                        {
                            AttributeName = "Fullname", AttributeType = "S"
                        },
                        new AttributeDefinition()
                        {
                            AttributeName = "DateTime", AttributeType = "S"
                        }
                    }
                };

                CreateTableResponse createTableResponse = _client.CreateTable(createTableRequest);

                while (createTableResponse.TableDescription.TableStatus != "ACTIVE")
                {
                    System.Threading.Thread.Sleep(5000);
                }
            }
        }
コード例 #18
0
        public static CreateTableResponse Unmarshall(UnmarshallerContext _ctx)
        {
            CreateTableResponse createTableResponse = new CreateTableResponse();

            createTableResponse.HttpResponse = _ctx.HttpResponse;
            createTableResponse.RequestId    = _ctx.StringValue("CreateTable.RequestId");

            CreateTableResponse.CreateTable_TaskInfo taskInfo = new CreateTableResponse.CreateTable_TaskInfo();
            taskInfo.TaskId              = _ctx.StringValue("CreateTable.TaskInfo.TaskId");
            taskInfo.Content             = _ctx.StringValue("CreateTable.TaskInfo.Content");
            taskInfo.Status              = _ctx.StringValue("CreateTable.TaskInfo.Status");
            taskInfo.NextTaskId          = _ctx.StringValue("CreateTable.TaskInfo.NextTaskId");
            createTableResponse.TaskInfo = taskInfo;

            return(createTableResponse);
        }
コード例 #19
0
        public void CreateTable(CreateTableRequest request, bool deleteIfTableExists)
        {
            TableDescription tableDescription;
            var tableExists = TableExists(request.TableName);

            if (tableExists && !deleteIfTableExists)
            {
                throw new Exception(request.TableName + " already exists");
            }
            if (tableExists)
            {
                Console.WriteLine("Table found, deleting");
                DeleteTableResponse deleteResponse = Client.DeleteTableAsync(request.TableName).Result;
                if (HttpStatusCode.OK != deleteResponse.HttpStatusCode)
                {
                    throw new Exception("Table delete failed: " + deleteResponse.HttpStatusCode);
                }

                tableDescription = Client.DescribeTableAsync(request.TableName).Result.Table;
                if (tableDescription.TableStatus != TableStatus.DELETING)
                {
                    throw new Exception("Table isn't deleting after delete was issued. Current status: " + tableDescription.TableStatus);
                }

                do
                {
                    System.Threading.Thread.Sleep(200);
                    tableExists = TableExists(request.TableName);
                    Console.WriteLine("Table found after deleting, waiting.");
                } while (tableExists);
            }

            CreateTableResponse response = Client.CreateTableAsync(request).Result;

            if (response.HttpStatusCode != HttpStatusCode.OK)
            {
                throw new Exception("Create table failed: " + response.HttpStatusCode);
            }

            tableDescription = Client.DescribeTableAsync(request.TableName).Result.Table;
            if (tableDescription.TableStatus != TableStatus.CREATING)
            {
                throw new Exception("Table isn't creating after create was issued. Current status: " + tableDescription.TableStatus);
            }
            WaitForTableStatus(request.TableName, TableStatus.ACTIVE);
        }
コード例 #20
0
        private void CreateTable()
        {
            AmazonDynamoDBClient client  = new AmazonDynamoDBClient();
            CreateTableRequest   request = new CreateTableRequest
            {
                TableName = s_TableName,
                KeySchema = new List <KeySchemaElement>
                {
                    new KeySchemaElement("Application", KeyType.HASH),
                    new KeySchemaElement("ErrorId", KeyType.RANGE),
                },
                AttributeDefinitions = new List <AttributeDefinition>
                {
                    new AttributeDefinition("Application", ScalarAttributeType.S),
                    new AttributeDefinition("ErrorId", ScalarAttributeType.S),
                    new AttributeDefinition("TimeUtc", ScalarAttributeType.S),
                    new AttributeDefinition("AllXml", ScalarAttributeType.S),
                },
                GlobalSecondaryIndexes = new List <GlobalSecondaryIndex>
                {
                    new GlobalSecondaryIndex
                    {
                        IndexName = "Application-TimeUtc-index",
                        KeySchema = new List <KeySchemaElement>
                        {
                            new KeySchemaElement("Application", KeyType.HASH),
                            new KeySchemaElement("TimeUtc", KeyType.RANGE),
                        }
                    },
                },
                ProvisionedThroughput = new ProvisionedThroughput(40, 64),
                StreamSpecification   = new StreamSpecification
                {
                    StreamEnabled  = true,
                    StreamViewType = StreamViewType.NEW_IMAGE,
                },
            };

            CreateTableResponse response = client.CreateTable(request);

            if ((int)response.HttpStatusCode >= 400)
            {
                throw new AmazonDynamoDBException(string.Format("CreateTable request ID {0} was unsuccessful.", response.ResponseMetadata.RequestId));
            }
        }
コード例 #21
0
        private void CreateDynamoTable(string tablename)
        {
            CreateTableRequest request = new CreateTableRequest()
            {
                TableName             = tablename,
                ProvisionedThroughput = new ProvisionedThroughput(25, 25),
                KeySchema             = new List <KeySchemaElement>()
                {
                    new KeySchemaElement {
                        AttributeName = "Id",
                        KeyType       = KeyType.HASH
                    },
                    new KeySchemaElement {
                        AttributeName = "DateCreated",
                        KeyType       = KeyType.RANGE
                    }
                },
                AttributeDefinitions = new List <AttributeDefinition>()
                {
                    new AttributeDefinition {
                        AttributeName = "Id",
                        AttributeType = ScalarAttributeType.N
                    },
                    new AttributeDefinition {
                        AttributeName = "DateCreated",
                        AttributeType = ScalarAttributeType.N
                    }
                }
            };

            try
            {
                CreateTableResponse response = _DynamoClient.CreateTableAsync(request).Result;
                string status = String.Empty;
                do
                {
                    Thread.Sleep(TimeSpan.FromSeconds(5));
                    status = response.TableDescription.TableStatus;
                } while (status != TableStatus.ACTIVE);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #22
0
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateTableResponse response = new CreateTableResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("TableDescription", targetDepth))
                {
                    response.TableDescription = TableDescriptionUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
コード例 #23
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateTableResponse response = new CreateTableResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("resourceArn", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.ResourceArn = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
コード例 #24
0
        private void CreateTable()
        {
            List <string> currentTables = _client.ListTables().TableNames;

            if (!currentTables.Contains(SchemaVersionTableName))
            {
                #region Form table creation

                var schema = new List <KeySchemaElement>
                {
                    new KeySchemaElement {
                        AttributeName = "ScriptName", KeyType = "HASH"
                    }
                };

                // The key attributes "FormId" is a string type and "InstanceId" is numeric type
                var definitions = new List <AttributeDefinition>
                {
                    new AttributeDefinition {
                        AttributeName = "ScriptName", AttributeType = "S"
                    }
                };

                var throughput = new ProvisionedThroughput {
                    ReadCapacityUnits = 1, WriteCapacityUnits = 1
                };

                // Configure the CreateTable request
                var request = new CreateTableRequest
                {
                    TableName             = SchemaVersionTableName,
                    KeySchema             = schema,
                    ProvisionedThroughput = throughput,
                    AttributeDefinitions  = definitions
                };

                CreateTableResponse response = _client.CreateTable(request);
                string currentStatus         = response.TableDescription.TableStatus;
                WaitUntilTableReady(SchemaVersionTableName, currentStatus);

                #endregion
            }
        }
コード例 #25
0
        private void CreateTableSchema(IAmazonDynamoDB client, string tableName)
        {
            CreateTableRequest request = new CreateTableRequest
            {
                TableName            = tableName,
                AttributeDefinitions = new List <AttributeDefinition>
                {
                    new AttributeDefinition(PartitionKey, ScalarAttributeType.S),
                    new AttributeDefinition(SortKey, ScalarAttributeType.N),
                },
                KeySchema = new List <KeySchemaElement>
                {
                    new KeySchemaElement(PartitionKey, KeyType.HASH),
                    new KeySchemaElement(SortKey, KeyType.RANGE),
                },
                ProvisionedThroughput = new ProvisionedThroughput(1L, 1L),
            };

            CreateTableResponse createTableResponse = client.CreateTableAsync(request).Result;
        }
コード例 #26
0
        public DynamoDbMetastoreImplTest(DynamoDBContainerFixture dynamoDbContainerFixture)
        {
            AmazonDynamoDBConfig clientConfig = new AmazonDynamoDBConfig
            {
                ServiceURL = dynamoDbContainerFixture.ServiceUrl
            };

            amazonDynamoDbClient = new AmazonDynamoDBClient(clientConfig);

            CreateTableRequest request = new CreateTableRequest
            {
                TableName            = TableName,
                AttributeDefinitions = new List <AttributeDefinition>
                {
                    new AttributeDefinition(PartitionKey, ScalarAttributeType.S),
                    new AttributeDefinition(SortKey, ScalarAttributeType.N)
                },
                KeySchema = new List <KeySchemaElement>
                {
                    new KeySchemaElement(PartitionKey, KeyType.HASH),
                    new KeySchemaElement(SortKey, KeyType.RANGE)
                },
                ProvisionedThroughput = new ProvisionedThroughput(1L, 1L)
            };

            CreateTableResponse createTableResponse = amazonDynamoDbClient.CreateTableAsync(request).Result;

            table = Table.LoadTable(amazonDynamoDbClient, TableName);

            JObject  jObject  = JObject.FromObject(keyRecord);
            Document document = new Document
            {
                [PartitionKey]       = TestKey,
                [SortKey]            = created.ToUnixTimeSeconds(),
                [AttributeKeyRecord] = Document.FromJson(jObject.ToString())
            };

            Document result = table.PutItemAsync(document).Result;

            dynamoDbMetastoreImpl = new DynamoDbMetastoreImpl(amazonDynamoDbClient);
        }
コード例 #27
0
        private async Task CreateTableAsync(CancellationToken cancellationToken = default)
        {
            // Created the table metadata

            CreateTableRequest request = new()
            {
                TableName             = this.TableName,
                KeySchema             = AddKeySchema(),
                AttributeDefinitions  = AddAttributeDefinitions(),
                ProvisionedThroughput = AddThroughputValues()
            };

            // Creates the table

            CreateTableResponse response = await this.Client.CreateTableAsync(request, cancellationToken).ConfigureAwait(false);

            if (response.HttpStatusCode != System.Net.HttpStatusCode.Created && response.HttpStatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new PrismaException();
            }
        }
コード例 #28
0
        private Table CreateTable()
        {
            CreateTableRequest createRequest = new CreateTableRequest()
                                               .WithTableName(this._tableName)
                                               .WithKeySchema(new KeySchema()
                                                              .WithHashKeyElement(new KeySchemaElement()
                                                                                  .WithAttributeName(ATTRIBUTE_SESSION_ID)
                                                                                  .WithAttributeType("S")))
                                               .WithProvisionedThroughput(new ProvisionedThroughput()
                                                                          .WithReadCapacityUnits(this._initialReadUnits)
                                                                          .WithWriteCapacityUnits(this._initialWriteUnits));

            createRequest.BeforeRequestEvent += this.UserAgentRequestEventHandler;

            CreateTableResponse response = this._ddbClient.CreateTable(createRequest);

            DescribeTableRequest descRequest = new DescribeTableRequest()
                                               .WithTableName(this._tableName);

            descRequest.BeforeRequestEvent += this.UserAgentRequestEventHandler;

            // Wait till table is active
            bool isActive = false;

            while (!isActive)
            {
                Thread.Sleep(DESCRIBE_INTERVAL);
                DescribeTableResponse descResponse = this._ddbClient.DescribeTable(descRequest);
                string tableStatus = descResponse.DescribeTableResult.Table.TableStatus;

                if (string.Equals(tableStatus, ACTIVE_STATUS, StringComparison.InvariantCultureIgnoreCase))
                {
                    isActive = true;
                }
            }

            Table table = Table.LoadTable(this._ddbClient, this._tableName, Table.DynamoDBConsumer.SessionStateProvider);

            return(table);
        }
コード例 #29
0
        private async Task EnsureTable()
        {
            if (this.client == null)
            {
                throw new Exception("Database is not connected");
            }

            ListTablesResponse listTablesResponse = await this.client.ListTablesAsync();

            if (listTablesResponse.TableNames.Contains(this.InternalName))
            {
                return;
            }

            CreateTableRequest request = new CreateTableRequest
            {
                TableName            = this.InternalName,
                AttributeDefinitions = new List <AttributeDefinition>()
                {
                    new AttributeDefinition("Id", ScalarAttributeType.S),
                },
                KeySchema = new List <KeySchemaElement>()
                {
                    new KeySchemaElement("Id", KeyType.HASH),
                },
                ProvisionedThroughput = new ProvisionedThroughput(1, 1),
            };

            try
            {
                CreateTableResponse createTableResponse = await this.client.CreateTableAsync(request);

                Log.Write("Created the Table: \"" + this.InternalName + "\"", "Database");
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to create table: \"" + this.InternalName + "\"", ex);
            }
        }
コード例 #30
0
        private async Task CreateTableIfNotExistsAsync()
        {
            List <string> currentTables = (await _dynamoDbClient.ListTablesAsync()).TableNames;

            if (currentTables.Contains(_tableName))
            {
                return;
            }

            var request = GenerateCreateTableRequest();

            try
            {
                CreateTableResponse response = await _dynamoDbClient.CreateTableAsync(request);

                Debug.WriteLine(response.ResponseMetadata.RequestId);
            }
            catch (Exception e)
            {
                throw new BadRequestException(e.Message);
            }
        }