Beispiel #1
0
        private static DeleteTableResponse DeleteTable()
        {
            switch (provider)
            {
            case Provider.NOSQL:
                try
                {
                    AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                    var request = new DeleteTableRequest {
                        TableName = tableName
                    };
                    return(client.DeleteTable(request));
                }
                catch (AmazonDynamoDBException e)
                {
                    Console.WriteLine(e.Message);
                }
                catch (AmazonServiceException e)
                {
                    Console.WriteLine(e.Message);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                break;
            }
            return(null);
        }
Beispiel #2
0
 private static void Cleanup()
 {
     using (var client = new AmazonDynamoDBClient(RegionEndpoint.USEast1))
     {
         Console.WriteLine("Deleting table");
         client.DeleteTable(tableName);
     }
 }
 private static void DeleteTable(string tableName)
 {
     Console.WriteLine("Deleting table " + tableName + "...");
     client.DeleteTable(new DeleteTableRequest()
     {
         TableName = tableName
     });
     WaitForTableToBeDeleted(tableName);
 }
        public void DeleteTable()
        {
            var response = client.DeleteTable(BackupTableName);

            if (response.HttpStatusCode.IsSuccess())
            {
                Console.WriteLine("Table has been deleted successfully");
                Console.WriteLine($"Table status: {response.TableDescription.TableStatus.Value}");
            }
        }
Beispiel #5
0
        public void DeleteTable()
        {
            var response = client.DeleteTable(tableName);

            if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                Console.WriteLine("Table has been deleted!");
                Console.WriteLine($"Table status: {response.TableDescription.TableStatus.Value}");
            }
        }
Beispiel #6
0
 /// <summary>
 /// IMPORTANT: This method will delete and re-create the DynamoDB table in order to reduce read/write capacity costs, make sure the proper table name and throughput properties are set!
 /// TODO: This method may take upwards of a minute to complete, need to look into a faster implementation
 /// </summary>
 public void FlushAll()
 {
     // Is this the cheapest method per AWS pricing to clear a table? (instead of table scan / remove each item) ??
     _client.DeleteTable(new DeleteTableRequest {
         TableName = CacheTableName
     });
     // Scaning the table is limited to 1 MB chunks, with a large cache it could result in many Read requests and many Delete requests occurring very quickly which may tap out
     // the throughput capacity...
     WaitUntilTableDeleted(_cacheTableName);
     CreateDynamoCacheTable();
 }
 public void Cleanup()
 {
     try
     {
         var request = new DeleteTableRequest {
             TableName = _tableName
         };
         var response = _client.DeleteTable(request);
     }
     catch { }
 }
        // DELETE api/<controller>/5
        public void Delete(string id)
        {
            var response           = _client.ListTables();
            var lowerCaseTableName = id.ToLower();

            if (!response.TableNames.Contains(lowerCaseTableName))
            {
                return;
            }
            _client.DeleteTable(lowerCaseTableName);
        }
Beispiel #9
0
        private void DeleteExampleTable(string tableName)
        {
            Trace.WriteLine("\n*** Deleting table ***");
            var request = new DeleteTableRequest
            {
                TableName = tableName
            };

            var response = client.DeleteTable(request);

            Trace.WriteLine("Table is being deleted...");
        }
        private static void DeleteExampleTable()
        {
            Console.WriteLine("\n*** Deleting table ***");
            var request = new DeleteTableRequest
            {
                TableName = tableName
            };

            var response = client.DeleteTable(request);

            Console.WriteLine("Table is being deleted...");
        }
        public static void DeleteExampleTable(this AmazonDynamoDBClient client, string tableName)
        {
            Console.WriteLine("\n*** Deleting table ***");
            var request = new DeleteTableRequest
            {
                TableName = tableName
            };

            client.DeleteTable(request);

            Console.WriteLine("Table is being deleted...");
        }
Beispiel #12
0
        void DeleteTable(AmazonDynamoDBClient client, string tableName)
        {
            try
            {
                client.DeleteTable(tableName);

                Console.WriteLine("\nTable Deleted");
            }
            catch (Exception ex)
            {
                Console.WriteLine("\n Error: failed to delete table; " + ex.Message);
            }
        }
 public void CommandDelete()
 {
     try {
         client.DeleteTable(new DeleteTableRequest()
         {
             TableName = tableName
         });
         WaitTillTableDeleted(client, tableName);
         Console.WriteLine("Table deleted.");
     }
     catch (ResourceNotFoundException) {
         Console.WriteLine("No such table.");
     }
 }
Beispiel #14
0
 private static void DeleteTable(string tableName)
 {
     try
     {
         var deleteTableResponse = client.DeleteTable(new DeleteTableRequest()
         {
             TableName = tableName
         });
         WaitTillTableDeleted(client, tableName, deleteTableResponse);
     }
     catch (ResourceNotFoundException)
     {
         // There is no such table.
     }
 }
Beispiel #15
0
        private static void RemoveInfectionsTableIfExists()
        {
            try
            {
                string tableName = InfectionsTableName;
                Debug.WriteLine("Attempting to delete DynamoDB table if one already exists.");

                var request = new DeleteTableRequest {
                    TableName = tableName
                };
                dynamoDBClient.DeleteTable(request);
            }
            catch (ResourceNotFoundException e)
            {
                Debug.Write("{0} table does not exist. Do not need to remove it. \n", InfectionsTableName + " " + e.Message);
            }
        }
Beispiel #16
0
        private static void DeleteTable()
        {
            var request = new DeleteTableRequest
            {
                TableName = tableName
            };

            try 
            {
                var response = ddbClient.DeleteTable(request);
            }
            catch (ResourceNotFoundException)
            {

            }

        }
Beispiel #17
0
        public void DeleteTable()
        {
            DeleteTableRequest request = new DeleteTableRequest
            {
                TableName = tableName
            };

            var response = client.DeleteTable(request);

            if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                Console.WriteLine("Table has been Deleted");
                Console.WriteLine($"Table Status=> {response.TableDescription.TableStatus.Value}");
                Console.WriteLine($"Table Name =>{response.TableDescription.TableName}");
            }
            Console.ReadLine();
        }
 private void DeleteTable(bool waitTillTableDeleted = false)
 {
     try
     {
         var deleteTableResponse = client.DeleteTable(new DeleteTableRequest()
         {
             TableName = TableName
         });
         if (waitTillTableDeleted)
         {
             WaitTillTableDeleted(client, TableName, deleteTableResponse);
         }
     }
     catch (ResourceNotFoundException)
     {
         // There is no such table.
     }
 }
        static void Main(string[] args)
        {
            // Get an AmazonDynamoDBClient for the local DynamoDB database
            AmazonDynamoDBClient client = GetLocalClient();

            try
            {
                client.DeleteTable("Movies");
            }
            catch (Exception ex)
            {
                Console.WriteLine("\n Error: the \'Movies\" table could not be deleted!\n    Reason: " + ex.Message);
                Console.Write("\n\n ...Press any key to continue");
                Console.ReadKey();
                Console.WriteLine();
                return;
            }
            Console.WriteLine("\n Deleted the \'Movies\" table successfully!");
        }
        private static void DeleteExampleTable()
        {
            try
            {
                Console.WriteLine("\n*** Deleting {0} Table ***", tableName);
                var request = new DeleteTableRequest
                {
                    TableName = tableName
                };

                var response = client.DeleteTable(request);
                var result   = response;
                Console.WriteLine("{0} is being deleted...", tableName);
                WaitUntilTableDeleted(tableName);
            }
            catch (ResourceNotFoundException)
            {
                Console.WriteLine("{0} Table delete failed: Table does not exist", tableName);
            }
        }
Beispiel #21
0
        public virtual void DeleteTable(AmazonDynamoDBClient ddbClient, string tableName)
        {
            switch (GetTableStatus(ddbClient, tableName))
            {
            case "ACTIVE":
                Console.WriteLine("Deleting pre-existing table.");
                var deleteTableRequest = new DeleteTableRequest {
                    TableName = tableName
                };
                ddbClient.DeleteTable(deleteTableRequest);
                WaitForStatus(ddbClient, tableName, "NOTFOUND");

                Console.WriteLine("Table deletion confirmed.");
                break;

            case "NOTFOUND":
                Console.WriteLine("Skipped deletion operation. Table not found.");
                break;

            default:
                Console.WriteLine("Skipped deletion operation. Table not in correct state.");
                break;
            }
        }
Beispiel #22
0
        /// <summary>
        /// Deletes all sample tables
        /// </summary>
        /// <param name="client"></param>
        public static void DeleteSampleTables(AmazonDynamoDBClient client)
        {
            foreach (var table in SAMPLE_TABLE_NAMES)
            {
                Console.WriteLine("Deleting table " + table);
                client.DeleteTable(new DeleteTableRequest {
                    TableName = table
                });
            }

            int remainingTables;

            do
            {
                Console.WriteLine("While sample tables still exist, sleeping for 5 seconds...");
                Thread.Sleep(TimeSpan.FromSeconds(5));

                Console.WriteLine("Getting list of tables");
                var currentTables = client.ListTables().TableNames;
                remainingTables = currentTables.Intersect(SAMPLE_TABLE_NAMES).Count();
            } while (remainingTables > 0);

            Console.WriteLine("Sample tables deleted");
        }
Beispiel #23
0
        public void Can_put_item_with_null_value()
        {
            var db = new AmazonDynamoDBClient("keyId", "key", new AmazonDynamoDBConfig
            {
                ServiceURL = "http://localhost:8000",
            });

            try
            {
                db.DeleteTable(new DeleteTableRequest
                {
                    TableName = "Test",
                });

                Thread.Sleep(1000);
            }
            catch (Exception) { /*ignore*/ }

            db.CreateTable(new CreateTableRequest
            {
                TableName = "Test",
                KeySchema = new List <KeySchemaElement>
                {
                    new KeySchemaElement
                    {
                        AttributeName = "Id",
                        KeyType       = "HASH"
                    }
                },
                AttributeDefinitions = new List <AttributeDefinition>
                {
                    new AttributeDefinition
                    {
                        AttributeName = "Id",
                        AttributeType = "N",
                    }
                },
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits  = 10,
                    WriteCapacityUnits = 5,
                }
            });

            Thread.Sleep(1000);

            db.PutItem(new PutItemRequest
            {
                TableName = "Test",
                Item      = new Dictionary <string, AttributeValue>
                {
                    { "Id", new AttributeValue {
                          N = "1"
                      } },
                    { "Name", new AttributeValue {
                          S = "Foo"
                      } },
                    { "Empty", new AttributeValue {
                          NULL = true
                      } },
                }
            });

            var response = db.GetItem(new GetItemRequest
            {
                TableName      = "Test",
                ConsistentRead = true,
                Key            = new Dictionary <string, AttributeValue> {
                    { "Id", new AttributeValue {
                          N = "1"
                      } }
                }
            });

            Assert.That(response.IsItemSet);
            Assert.That(response.Item["Id"].N, Is.EqualTo("1"));
            Assert.That(response.Item["Name"].S, Is.EqualTo("Foo"));
            Assert.That(response.Item["Empty"].NULL);
        }
        public void DataPlaneSamples()
        {
            {
                #region CreateTable Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Define table schema:
                //  Table has a hash-key "Author" and a range-key "Title"
                List <KeySchemaElement> schema = new List <KeySchemaElement>
                {
                    new KeySchemaElement
                    {
                        AttributeName = "Author", KeyType = "HASH"
                    },
                    new KeySchemaElement
                    {
                        AttributeName = "Title", KeyType = "RANGE"
                    }
                };

                // Define key attributes:
                //  The key attributes "Author" and "Title" are string types
                List <AttributeDefinition> definitions = new List <AttributeDefinition>
                {
                    new AttributeDefinition
                    {
                        AttributeName = "Author", AttributeType = "S"
                    },
                    new AttributeDefinition
                    {
                        AttributeName = "Title", AttributeType = "S"
                    }
                };

                // Define table throughput:
                //  Table has capacity of 20 reads and 50 writes
                ProvisionedThroughput throughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits  = 20,
                    WriteCapacityUnits = 50
                };

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

                // View new table properties
                TableDescription tableDescription = client.CreateTable(request).TableDescription;
                Console.WriteLine("Table name: {0}", tableDescription.TableName);
                Console.WriteLine("Creation time: {0}", tableDescription.CreationDateTime);
                Console.WriteLine("Item count: {0}", tableDescription.ItemCount);
                Console.WriteLine("Table size (bytes): {0}", tableDescription.TableSizeBytes);
                Console.WriteLine("Table status: {0}", tableDescription.TableStatus);

                // List table key schema
                List <KeySchemaElement> tableSchema = tableDescription.KeySchema;
                for (int i = 0; i < tableSchema.Count; i++)
                {
                    KeySchemaElement element = tableSchema[i];
                    Console.WriteLine("Key: Name = {0}, KeyType = {1}",
                                      element.AttributeName, element.KeyType);
                }

                // List attribute definitions
                List <AttributeDefinition> attributeDefinitions = tableDescription.AttributeDefinitions;
                for (int i = 0; i < attributeDefinitions.Count; i++)
                {
                    AttributeDefinition definition = attributeDefinitions[i];
                    Console.WriteLine("Attribute: Name = {0}, Type = {1}",
                                      definition.AttributeName, definition.AttributeType);
                }

                Console.WriteLine("Throughput: Reads = {0}, Writes = {1}",
                                  tableDescription.ProvisionedThroughput.ReadCapacityUnits,
                                  tableDescription.ProvisionedThroughput.WriteCapacityUnits);

                #endregion
            }

            {
                #region DescribeTable Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Create DescribeTable request
                DescribeTableRequest request = new DescribeTableRequest
                {
                    TableName = "SampleTable"
                };

                // Issue DescribeTable request and retrieve the table description
                TableDescription tableDescription = client.DescribeTable(request).Table;

                // View new table properties
                Console.WriteLine("Table name: {0}", tableDescription.TableName);
                Console.WriteLine("Creation time: {0}", tableDescription.CreationDateTime);
                Console.WriteLine("Item count: {0}", tableDescription.ItemCount);
                Console.WriteLine("Table size (bytes): {0}", tableDescription.TableSizeBytes);
                Console.WriteLine("Table status: {0}", tableDescription.TableStatus);
                // List table key schema
                List <KeySchemaElement> tableSchema = tableDescription.KeySchema;
                for (int i = 0; i < tableSchema.Count; i++)
                {
                    KeySchemaElement element = tableSchema[i];
                    Console.WriteLine("Key: Name = {0}, KeyType = {1}",
                                      element.AttributeName, element.KeyType);
                }

                // List attribute definitions
                List <AttributeDefinition> attributeDefinitions = tableDescription.AttributeDefinitions;
                for (int i = 0; i < attributeDefinitions.Count; i++)
                {
                    AttributeDefinition definition = attributeDefinitions[i];
                    Console.WriteLine("Attribute: Name = {0}, Type = {1}",
                                      definition.AttributeName, definition.AttributeType);
                }
                Console.WriteLine("Throughput: Reads = {0}, Writes = {1}",
                                  tableDescription.ProvisionedThroughput.ReadCapacityUnits,
                                  tableDescription.ProvisionedThroughput.WriteCapacityUnits);

                #endregion
            }

            {
                #region ListTables Paging Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                string startTableName = null;
                do
                {
                    // Configure ListTables request with the marker value
                    ListTablesRequest request = new ListTablesRequest
                    {
                        ExclusiveStartTableName = startTableName,
                    };

                    // Issue call
                    ListTablesResult result = client.ListTables(request);

                    // List retrieved tables
                    List <string> tables = result.TableNames;
                    Console.WriteLine("Retrieved tables: {0}",
                                      string.Join(", ", tables));

                    // Update marker value from the result
                    startTableName = result.LastEvaluatedTableName;
                } while (!string.IsNullOrEmpty(startTableName)); // Test marker value

                #endregion
            }

            {
                #region ListTables NonPaging Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Issue call
                ListTablesResult result = client.ListTables();

                // List retrieved tables
                List <string> tables = result.TableNames;
                Console.WriteLine("Retrieved tables: {0}",
                                  string.Join(", ", tables));

                #endregion
            }

            TableUtils.WaitUntilTableActive("SampleTable", TestClient);

            {
                #region UpdateTable Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Define new table throughput:
                //  Table will now have capacity of 40 reads and 50 writes
                ProvisionedThroughput throughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits  = 40,
                    WriteCapacityUnits = 50
                };

                // Compose the UpdateTable request
                UpdateTableRequest request = new UpdateTableRequest
                {
                    TableName             = "SampleTable",
                    ProvisionedThroughput = throughput
                };

                // View new table properties
                TableDescription tableDescription = client.UpdateTable(request).TableDescription;
                Console.WriteLine("Table name: {0}", tableDescription.TableName);
                Console.WriteLine("Throughput: Reads = {0}, Writes = {1}",
                                  tableDescription.ProvisionedThroughput.ReadCapacityUnits,
                                  tableDescription.ProvisionedThroughput.WriteCapacityUnits);

                #endregion
            }

            TableUtils.WaitUntilTableActive("SampleTable", TestClient);

            {
                #region DeleteTable Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Configure the DeleteTable request
                DeleteTableRequest request = new DeleteTableRequest
                {
                    TableName = "SampleTable"
                };

                // Issue DeleteTable request and retrieve the table description
                TableDescription tableDescription = client.DeleteTable(request).TableDescription;
                Console.WriteLine("Table name: {0}", tableDescription.TableName);
                Console.WriteLine("Table status: {0}", tableDescription.TableStatus);

                #endregion
            }
        }
Beispiel #25
0
        public static void ClassTearDown()
        {
            var request = new DeleteTableRequest(TestTableName);

            Client.DeleteTable(request);
        }
Beispiel #26
0
 private void DeleteTable()
 {
     client.DeleteTable(tableName);
     AWSSDK_DotNet.IntegrationTests.Tests.DynamoDB.DynamoDBTests.WaitForTableStatus(tableName, null);
 }