예제 #1
0
        public DeleteTableResponse DeleteTable(DeleteTableRequest request)
        {
            try
            {
                var options = new TransactionOptions()
                {
                    IsolationLevel = System.Transactions.IsolationLevel.Serializable,
                    Timeout        = new TimeSpan(0, TransactionTimeout, 0)
                };
                using (var trScope = new TransactionScope(TransactionScopeOption.Required, options))
                {
                    List <DroppedDependencyDbo> droppedKeys = DeleteTheTable(request.Table, request.disableDependencies);
                    var rzlt = new DeleteTableResponse()
                    {
                        DroppedDependencies = droppedKeys,
                        ErrorMessage        = String.Format("Table '{0}' is deleted.", request.Table),
                        IsSuccess           = true
                    };

                    string logMsg          = String.Format("Table {0} was deleted.", request.Table);
                    Guid   historyRecordId = LogTableOperation(request.Table, logMsg, request.CFC_DB_Major_Version,
                                                               request.CFC_DB_Minor_Version);

                    trScope.Complete();
                    return(rzlt);
                }
            }
            catch (Exception ex)
            {
                return(new DeleteTableResponse()
                {
                    IsSuccess = false, ErrorMessage = ex.Message
                });
            }
        }
예제 #2
0
        public static async Task <DescribeTableResponse> WaitTillTableDeleted(IAmazonDynamoDB client, string tableName,
                                                                              DeleteTableResponse response)
        {
            DescribeTableResponse resp = new DescribeTableResponse();
            var tableDescription       = response.TableDescription;

            string status = tableDescription.TableStatus;

            Int32 sleepDuration = 1000; // One second

            while ((status == "DELETING") && (sleepDuration < 10000))
            {
                System.Threading.Thread.Sleep(sleepDuration);

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

                status = resp.Table.TableStatus;

                sleepDuration *= 2;
            }

            return(resp);
        }
예제 #3
0
        public void DeleteTable(string tableName)
        {
            if (dynamoService == null || string.IsNullOrEmpty(tableName))
            {
                return;
            }

            try
            {
                dynamoService.RestartDynamoDBContext();

                using (IAmazonDynamoDB client = dynamoService.DynamoClient)
                {
                    DeleteTableRequest  deleteTableRequest  = new DeleteTableRequest(tableName.ToLower());
                    DeleteTableResponse deleteTableResponse = client.DeleteTable(deleteTableRequest);
                    TableDescription    tableDescription    = deleteTableResponse.TableDescription;
                    TableStatus         tableStatus         = tableDescription.TableStatus;

                    ConsoleHelper.Write("\nDelete table ");
                    ConsoleHelper.Write(tableName.ToUpper(), ConsoleColor.Yellow);
                    ConsoleHelper.Write(" command sent to Amazon, status after deletion: ");
                    ConsoleHelper.Write(tableDescription.TableStatus, ConsoleColor.Green);
                }
            }
            catch (AmazonDynamoDBException exception)
            {
                ConsoleHelper.Write(string.Format("Exception while deleting new dynamoDB table: {0}", exception.Message), ConsoleColor.Red);
                ConsoleHelper.WriteLine(string.Concat("Error code: {0}, error type: {1}", exception.ErrorCode, exception.ErrorType), ConsoleColor.Red);
            }
        }
        private async Task WaitTillTableDeletedAsync(string tableName, DeleteTableResponse response)
        {
            var tableDescription = response.TableDescription;

            string status = tableDescription.TableStatus;

            // Wait until table is created. Call DescribeTable
            try
            {
                while (status == "DELETING")
                {
                    System.Threading.Thread.Sleep(5000);

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

                    status = res.Table.TableStatus;
                }
            }
            catch (ResourceNotFoundException)
            {
                // Table deleted
            }
        }
예제 #5
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)
        {
            DeleteTableResponse response = new DeleteTableResponse();


            return(response);
        }
예제 #6
0
        private static void WaitTillTableDeleted(AmazonDynamoDBClient client, string tableName,
                                                 DeleteTableResponse response)
        {
            var tableDescription = response.TableDescription;

            string status = tableDescription.TableStatus;

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

            // Let us wait until table is created. Call DescribeTable
            try
            {
                while (status == "DELETING")
                {
                    System.Threading.Thread.Sleep(5000); // wait 5 seconds

                    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;
                }
            }
            catch (ResourceNotFoundException)
            {
                // Table deleted.
            }
        }
예제 #7
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);
        }
예제 #8
0
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            DeleteTableResponse response = new DeleteTableResponse();

            context.Read();
            response.DeleteTableResult = DeleteTableResultUnmarshaller.GetInstance().Unmarshall(context);

            return(response);
        }
예제 #9
0
        public async Task DynamoDbService_Should_Delete_A_DynamoDb_Table()
        {
            var tableName = Guid.NewGuid().ToString();

            await CreateTestTable(tableName);

            DeleteTableResponse deleteTableResponse = await DeleteTestTable(tableName);

            Assert.Equal(HttpStatusCode.OK, deleteTableResponse.HttpStatusCode);
        }
예제 #10
0
 public void Dispose()
 {
     try
     {
         DeleteTableResponse deleteTableResponse = amazonDynamoDbClient.DeleteTableAsync(TableName).Result;
     }
     catch (AggregateException)
     {
         // There is no such table.
     }
 }
 public void Dispose()
 {
     try
     {
         DeleteTableResponse deleteTableResponse = tempDynamoDbClient
                                                   .DeleteTableAsync(dynamoDbMetastoreImpl.TableName)
                                                   .Result;
     }
     catch (AggregateException)
     {
         // There is no such table.
     }
 }
        private async Task DeleteDynamoDbTableAsync(string tableName)
        {
            var response = new DeleteTableResponse();

            try
            {
                var deleteResponse = _dynamoDbClient.DeleteTableAsync(tableName);
                response = await deleteResponse;
            }
            catch (Exception ex)
            {
                Logger.Log($"ERROR: Failed to delete the table, because:\n {ex.Message}");
            }

            await WaitTillTableDeletedAsync(tableName, response);
        }
        public static DeleteTableResponse Unmarshall(UnmarshallerContext _ctx)
        {
            DeleteTableResponse deleteTableResponse = new DeleteTableResponse();

            deleteTableResponse.HttpResponse = _ctx.HttpResponse;
            deleteTableResponse.RequestId    = _ctx.StringValue("DeleteTable.RequestId");

            DeleteTableResponse.DeleteTable_TaskInfo taskInfo = new DeleteTableResponse.DeleteTable_TaskInfo();
            taskInfo.TaskId              = _ctx.StringValue("DeleteTable.TaskInfo.TaskId");
            taskInfo.Content             = _ctx.StringValue("DeleteTable.TaskInfo.Content");
            taskInfo.Status              = _ctx.StringValue("DeleteTable.TaskInfo.Status");
            taskInfo.NextTaskId          = _ctx.StringValue("DeleteTable.TaskInfo.NextTaskId");
            deleteTableResponse.TaskInfo = taskInfo;

            return(deleteTableResponse);
        }
        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);
        }
예제 #15
0
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            DeleteTableResponse response = new DeleteTableResponse();

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

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

            return(response);
        }
        public async Task DeleteTable()
        {
            try
            {
                Console.WriteLine("\n*** Deleting table {0} ***", tableName);
                DeleteTableRequest request = new DeleteTableRequest
                {
                    TableName = tableName
                };

                DeleteTableResponse response = await client.DeleteTableAsync(request);

                Console.WriteLine("Table {0} is being deleted...", tableName);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
예제 #17
0
        public static async void DeleteTableDemo(string tableName)
        {
            try
            {
                using (IAmazonDynamoDB client = GetDynamoDbClient())
                {
                    DeleteTableRequest  deleteTableRequest  = new DeleteTableRequest(tableName);
                    DeleteTableResponse deleteTableResponse = await client.DeleteTableAsync(deleteTableRequest);

                    TableDescription tableDescription = deleteTableResponse.TableDescription;
                    TableStatus      tableStatus      = tableDescription.TableStatus;
                    Debug.WriteLine(string.Format("Delete table command sent to Amazon for table {0}, status after deletion: {1}", tableName
                                                  , tableDescription.TableStatus));
                }
            }
            catch (AmazonDynamoDBException exception)
            {
                Debug.WriteLine(string.Concat("Exception while deleting DynamoDb table: {0}", exception.Message));
                Debug.WriteLine(String.Concat("Error code: {0}, error type: {1}", exception.ErrorCode, exception.ErrorType));
            }
        }
예제 #18
0
        private static void UnmarshallResult(JsonUnmarshallerContext context, DeleteTableResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

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

                if (context.CurrentDepth <= originalDepth)
                {
                    return;
                }
            }

            return;
        }
예제 #19
0
        public async Task DeleteTable()
        {
            Console.WriteLine("Deleting table");
            try
            {
                var deleteTableRequest = new DeleteTableRequest
                {
                    DatabaseName = Constants.DATABASE_NAME,
                    TableName    = Constants.TABLE_NAME
                };
                DeleteTableResponse response = await writeClient.DeleteTableAsync(deleteTableRequest);

                Console.WriteLine($"Table {Constants.TABLE_NAME} delete request status: {response.HttpStatusCode}");
            }
            catch (ResourceNotFoundException)
            {
                Console.WriteLine($"Table {Constants.TABLE_NAME} does not exists");
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while deleting table:" + e.ToString());
            }
        }
        public async Task DeleteTable(IAmazonTimestreamWrite writeClient, string databaseName, string tableName)
        {
            Console.WriteLine($"Deleting table {tableName}");
            try
            {
                var deleteTableRequest = new DeleteTableRequest
                {
                    DatabaseName = databaseName,
                    TableName    = tableName
                };
                DeleteTableResponse response = await writeClient.DeleteTableAsync(deleteTableRequest);

                Console.WriteLine($"Table {tableName} delete request status: {response.HttpStatusCode}");
            }
            catch (ResourceNotFoundException)
            {
                Console.WriteLine($"Table {tableName} does not exists");
            }
            catch (Exception e)
            {
                Console.WriteLine($"Exception while deleting table: {e}");
            }
        }
예제 #21
0
        public static async Task WaitTillTableDeleted(AmazonDynamoDBClient client, string tableName, DeleteTableResponse response)
        {
            var tableDescription = response.TableDescription;

            string status = tableDescription.TableStatus;

            Console.WriteLine("Waiting for delete - " + tableName + " : " + status);

            // Let us wait until table is created. Call DescribeTable
            try
            {
                while (status == "DELETING")
                {
                    System.Threading.Thread.Sleep(5000); // wait 5 seconds

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

                    Console.WriteLine("Table name: {0}, status: {1}", res.Table.TableName, res.Table.TableStatus);
                    status = res.Table.TableStatus;
                }
            }
            catch (ResourceNotFoundException exRnf)
            {
                for (Exception ex = exRnf; ex != null; ex = ex.InnerException)
                {
                    Debug.WriteLine(ex.GetType().Name + " - " + ex.Message);
                }
            }
        }