Example #1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            if (!ConfirmDelete("OCINosqlTable", "Remove"))
            {
                return;
            }

            DeleteTableRequest request;

            try
            {
                request = new DeleteTableRequest
                {
                    TableNameOrId = TableNameOrId,
                    CompartmentId = CompartmentId,
                    IsIfExists    = IsIfExists,
                    IfMatch       = IfMatch,
                    OpcRequestId  = OpcRequestId
                };

                response = client.DeleteTable(request).GetAwaiter().GetResult();
                WriteOutput(response, CreateWorkRequestObject(response.OpcWorkRequestId));
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
Example #2
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);
            }
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        protected static void DelTable(Type type)
        {
            #region 初始化缓存
            if (!tableNames.ContainsKey(type))
            {
                foreach (var attr in type.CustomAttributes)
                {
                    if (attr.AttributeType == typeof(System.ComponentModel.DataAnnotations.Schema.TableAttribute))
                    {
                        tableNames.TryAdd(type, attr.ConstructorArguments[0].Value.ToString());
                        break;
                    }
                }
            }
            #endregion

            var name = tableNames.ContainsKey(type) ? tableNames[type] : type.Name.ToLower();
            #region  除已有表
            try
            {
                var request = new DeleteTableRequest(name);
                new OTSClient(OtsConfig).DeleteTable(request);
                log.Info("Delete table succeeded, table name:" + name);
            }
            // 处理异常
            catch (Exception ex)
            {
                Console.WriteLine("Delete table failed, exception:{0}", ex.Message);
            }
            #endregion
        }
        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
                });
            }
        }
Example #5
0
        private static async Task DeleteTable(IAmazonDynamoDB client, CancellationToken token)
        {
            DeleteTableRequest request = new DeleteTableRequest(MyTableName);

            await client.DeleteTableAsync(request, token);

            DescribeTableResponse response;

            string expectedExceptionMessage =
                $"Requested resource not found: Table: {MyTableName} not found";

            try
            {
                do
                {
                    Thread.Sleep(2000);
                    Console.WriteLine($"Deleting table {MyTableName}...");

                    response = await client.DescribeTableAsync(MyTableName, token);
                } while (response.Table.TableStatus == TableStatus.DELETING);
            }
            catch (ResourceNotFoundException e) when(CheckDeleteTableException(e, expectedExceptionMessage))
            {
                Console.WriteLine($"\nTable {MyTableName} was successfully deleted.");
            }

            Console.WriteLine("\nPress any key to continue...\n");
            Console.ReadKey();
        }
Example #6
0
        /// <summary>
        /// <para>The <i>DeleteTable</i> operation deletes a table and all of its items. After a <i>DeleteTable</i> request, the specified table is in
        /// the <c>DELETING</c> state until DynamoDB completes the deletion. If the table is in the <c>ACTIVE</c> state, you can delete it. If a table
        /// is in <c>CREATING</c> or <c>UPDATING</c> states, then DynamoDB returns a
        /// <i>ResourceInUseException</i> . If the specified table does not exist, DynamoDB returns a
        /// <i>ResourceNotFoundException</i> . If table is already in the <c>DELETING</c> state, no error is returned. </para> <para><b>NOTE:</b>
        /// DynamoDB might continue to accept data read and write operations, such as GetItem and PutItem, on a table in the DELETING state until the
        /// table deletion is complete. </para> <para>When you delete a table, any indexes on that table are also deleted.</para> <para>Use the
        /// <i>DescribeTable</i> API to check the status of the table. </para>
        /// </summary>
        ///
        /// <param name="deleteTableRequest">Container for the necessary parameters to execute the DeleteTable service method on
        /// AmazonDynamoDBv2.</param>
        ///
        /// <returns>The response from the DeleteTable service method, as returned by AmazonDynamoDBv2.</returns>
        ///
        /// <exception cref="T:Amazon.DynamoDBv2.Model.ResourceInUseException" />
        /// <exception cref="T:Amazon.DynamoDBv2.Model.ResourceNotFoundException" />
        /// <exception cref="T:Amazon.DynamoDBv2.Model.LimitExceededException" />
        /// <exception cref="T:Amazon.DynamoDBv2.Model.InternalServerErrorException" />
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        public Task <DeleteTableResponse> DeleteTableAsync(DeleteTableRequest deleteTableRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new DeleteTableRequestMarshaller();
            var unmarshaller = DeleteTableResponseUnmarshaller.GetInstance();

            return(Invoke <IRequest, DeleteTableRequest, DeleteTableResponse>(deleteTableRequest, marshaller, unmarshaller, signer, cancellationToken));
        }
Example #7
0
        /// <summary>
        /// Delete a table by tableNameOrId.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public DeleteTableResponse DeleteTable(DeleteTableRequest request)
        {
            var uriStr   = $"{GetEndPoint(NoSQLServices.Tables, this.Region)}/{request.TableNameOrId}";
            var optional = request.GetOptionalQuery();

            if (!string.IsNullOrEmpty(optional))
            {
                uriStr = $"{uriStr}?{optional}";
            }

            var uri = new Uri(uriStr);

            var httpRequestHeaderParam = new HttpRequestHeaderParam()
            {
                IfMatch      = request.IfMatch,
                OpcRequestId = request.OpcRequestId
            };

            using (var webResponse = this.RestClient.Delete(uri, httpRequestHeaderParam))
                using (var stream = webResponse.GetResponseStream())
                    using (var reader = new StreamReader(stream))
                    {
                        var response = reader.ReadToEnd();

                        return(new DeleteTableResponse()
                        {
                            OpcRequestId = webResponse.Headers.Get("opc-request-id"),
                            OpcWorkRequestId = webResponse.Headers.Get("opc-work-request-id")
                        });
                    }
        }
Example #8
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);
        }
Example #9
0
        public async Task <IActionResult> Delete(string tableName)
        {
            System.Console.WriteLine($"Deleting {tableName} table.");
            var req = new DeleteTableRequest();

            req.TableName = tableName;

            try
            {
                var res = await _dynamoClient.DeleteTableAsync(req);

                Console.WriteLine($"Deleted table: {req.TableName}");
                return(StatusCode(204));
            }
            catch (AmazonDynamoDBException addbe)
            {
                return(AmazonExceptionHandlers.HandleAmazonDynamoDBException(addbe));
            }
            catch (AmazonServiceException ase)
            {
                AmazonExceptionHandlers.HandleAmazonServiceExceptionException(ase);
            }
            catch (AmazonClientException ace)
            {
                AmazonExceptionHandlers.HandleAmazonClientExceptionException(ace);
            }
            return(StatusCode(500));
        }
Example #10
0
        public void TestDisableErrorLog()
        {
            var clientConfig = new OTSClientConfig(
                TestEndPoint,
                TestAccessKeyID,
                TestAccessKeySecret,
                TestInstanceName)
            {
                OTSErrorLogHandler = null
            };
            var otsClient = new OTSClient(clientConfig);

            var request = new DeleteTableRequest("blahblah");

            try {
                otsClient.DeleteTable(request);
                Assert.Fail();
            } catch (OTSServerException exception) {
                AssertOTSServerException(new OTSServerException(
                                             "/DeleteTable",
                                             HttpStatusCode.NotFound,
                                             "OTSObjectNotExist",
                                             "Requested table does not exist."), exception);
            }
        }
        internal DeleteTableResponse DeleteTable(DeleteTableRequest request)
        {
            var marshaller   = new DeleteTableRequestMarshaller();
            var unmarshaller = DeleteTableResponseUnmarshaller.Instance;

            return(Invoke <DeleteTableRequest, DeleteTableResponse>(request, marshaller, unmarshaller));
        }
        private void DeleteTable(OTSClient client, String tableName)
        {
            DeleteTableRequest req = new DeleteTableRequest(tableName);

            client.DeleteTable(req);
            Console.WriteLine("DeleteTable success");
        }
Example #13
0
        private void DeleteTable()
        {
            var otsClient = OTSClient;

            var deleteTableRequest = new DeleteTableRequest("SampleTable");

            otsClient.DeleteTable(deleteTableRequest);
        }
        /// <summary>
        /// Initiates the asynchronous execution of the DeleteTable operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the DeleteTable operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task <DeleteTableResponse> DeleteTableAsync(DeleteTableRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new DeleteTableRequestMarshaller();
            var unmarshaller = DeleteTableResponseUnmarshaller.Instance;

            return(InvokeAsync <DeleteTableRequest, DeleteTableResponse>(request, marshaller,
                                                                         unmarshaller, cancellationToken));
        }
Example #15
0
        DeleteTableRequest GetDeleteTableRequest()
        {
            var request = new DeleteTableRequest()
            {
            };

            return(request);
        }
Example #16
0
        public async Task DeleteTableAsync(string tableName)
        {
            var request = new DeleteTableRequest {
                Name = tableName.ToTableId(ClusterId)
            };
            await _client.DeleteTableAsync(request);

            await Task.Yield();
        }
Example #17
0
        public static void TearDownStore(string tableName)
        {
            var request = new DeleteTableRequest()
            {
                TableName = tableName
            };

            _dynamoDbClient.DeleteTableAsync(request);
        }
        internal static async Task <DeleteTableResponse> Build(string tableName, AmazonDynamoDBClient dynamodbClient)
        {
            DeleteTableRequest deleteTableRequest = new DeleteTableRequest()
            {
                TableName = tableName
            };

            return(await dynamodbClient.DeleteTableAsync(deleteTableRequest));
        }
Example #19
0
        public async Task DeleteDynamoDbTable(string tableName)
        {
            var request = new DeleteTableRequest
            {
                TableName = tableName
            };

            await _dynamoDbClient.DeleteTableAsync(request);
        }
Example #20
0
        public static void DeleteTable()
        {
            OTSClient otsClient = Config.GetClient();

            Console.WriteLine("Start delete table...");
            DeleteTableRequest request = new DeleteTableRequest(TableName);

            otsClient.DeleteTable(request);
            Console.WriteLine("Table is deleted.");
        }
        public static void TableOperations()
        {
            // 创建表
            OTSClient otsClient = Config.GetClient();
            {
                Console.WriteLine("Start create table...");
                PrimaryKeySchema primaryKeySchema = new PrimaryKeySchema
                {
                    { "pk0", ColumnValueType.Integer },
                    { "pk1", ColumnValueType.String }
                };
                TableMeta tableMeta = new TableMeta(TableName, primaryKeySchema);

                CapacityUnit       reservedThroughput = new CapacityUnit(0, 0);
                CreateTableRequest request            = new CreateTableRequest(tableMeta, reservedThroughput);
                otsClient.CreateTable(request);

                Console.WriteLine("Table is created: " + TableName);
            }

            // 更新表
            {
                Thread.Sleep(60 * 1000);                                         // 每次更新表需要至少间隔1分钟
                Console.WriteLine("Start update table...");
                CapacityUnit        reservedThroughput = new CapacityUnit(0, 0); // 将预留CU调整为0,0
                UpdateTableRequest  request            = new UpdateTableRequest(TableName, reservedThroughput);
                UpdateTableResponse response           = otsClient.UpdateTable(request);
                Console.WriteLine("LastIncreaseTime: " + response.ReservedThroughputDetails.LastIncreaseTime);
                Console.WriteLine("LastDecreaseTime: " + response.ReservedThroughputDetails.LastDecreaseTime);
                Console.WriteLine("NumberOfDecreaseToday: " + response.ReservedThroughputDetails.LastIncreaseTime);
                Console.WriteLine("ReadCapacity: " + response.ReservedThroughputDetails.CapacityUnit.Read);
                Console.WriteLine("WriteCapacity: " + response.ReservedThroughputDetails.CapacityUnit.Write);
            }

            // 描述表
            {
                Console.WriteLine("Start describe table...");
                DescribeTableRequest  request  = new DescribeTableRequest(TableName);
                DescribeTableResponse response = otsClient.DescribeTable(request);
                Console.WriteLine("LastIncreaseTime: " + response.ReservedThroughputDetails.LastIncreaseTime);
                Console.WriteLine("LastDecreaseTime: " + response.ReservedThroughputDetails.LastDecreaseTime);
                Console.WriteLine("NumberOfDecreaseToday: " + response.ReservedThroughputDetails.LastIncreaseTime);
                Console.WriteLine("ReadCapacity: " + response.ReservedThroughputDetails.CapacityUnit.Read);
                Console.WriteLine("WriteCapacity: " + response.ReservedThroughputDetails.CapacityUnit.Write);
            }

            // 删除表
            {
                Console.WriteLine("Start delete table...");
                DeleteTableRequest request = new DeleteTableRequest(TableName);
                otsClient.DeleteTable(request);
                Console.WriteLine("Table is deleted.");
            }
        }
Example #22
0
        public async Task <DeleteTableResponse> DeleteTableExecution(string tableName)
        {
            var request = new DeleteTableRequest
            {
                TableName = tableName
            };

            var response = await _amazonDynamoDB.DeleteTableAsync(request);

            return(response);
        }
Example #23
0
        public async Task <DeleteTableResponse> ExecuteTableDelete(string tableName)
        {
            var request = new DeleteTableRequest
            {
                TableName = tableName
            };

            var response = await _dynamoClient.DeleteTableAsync(request);

            return(response);
        }
 public void Cleanup()
 {
     try
     {
         var request = new DeleteTableRequest {
             TableName = _tableName
         };
         var response = _client.DeleteTable(request);
     }
     catch { }
 }
Example #25
0
        /// <summary>
        /// Deletes a <paramref name="table"/> and all of its items as an asynchronous operation.
        /// </summary>
        /// <param name="table">The name of the table to delete.</param>
        /// <param name="setup">The <see cref="AsyncOptions" /> which need to be configured.</param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task <DeleteTableResponse> DeleteAsync(string table, Action <AsyncOptions> setup = null)
        {
            DynamoValidator.ThrowIfTableNameIsNotValid(table);
            var options = setup.ConfigureOptions();
            var dtr     = new DeleteTableRequest()
            {
                TableName = table
            };

            return(Client.DeleteTableAsync(dtr, options.CancellationToken));
        }
Example #26
0
        /// <summary>
        ///     Delete a table
        /// </summary>
        /// <param name="tableName">Name of table you want to delete</param>
        private static void DeleteTable(string tableName)
        {
            var request = new DeleteTableRequest
            {
                TableName = tableName
            };

            var response = _client.DeleteTableAsync(request);

            Logger.WriteLine("Attempted to Delete Table: " + tableName);
        }
        public void DeleteTable(string tableName = null)
        {
            if (tableName == null)
            {
                tableName = TestTableName;
            }

            var otsClient          = OTSClient;
            var deleteTableRequest = new DeleteTableRequest(tableName);

            otsClient.DeleteTable(deleteTableRequest);
        }
        private async Task DeleteExampleTable()
        {
            Console.WriteLine("\n*** Deleting table ***");
            var request = new DeleteTableRequest
            {
                TableName = tableName
            };

            var response = await client.DeleteTableAsync(request);

            Console.WriteLine("Table is being deleted...");
        }
Example #29
0
        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 override bool EnsureDeleted([NotNull] IModel model)
        {
            Check.NotNull(model, "model");

            var deleted = false;
            foreach (var type in model.EntityTypes)
            {
                var request = new DeleteTableRequest(new AtsTable(type.TableName()));
                deleted |= _connection.ExecuteRequest(request);
            }
            return 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...");
        }
Example #32
0
 public DeleteTableResponse DropTable(DeleteTableRequest request)
 {
     return client.DeleteTable(request);
 }
Example #33
0
        public bool DropTableReadyForUse(DeleteTableRequest request)
        {
            var count = 0;
            var list = client.ListTables(new ListTablesRequest()).ListTablesResult.TableNames;
            if (list.Contains(request.TableName))
            {
                client.DeleteTable(request);
            }

            while (list.Contains(request.TableName) && count < UpdateStatusRepeatCount)
            {
                Thread.Sleep(UpdateStatusRepeatTimeOut);
                list = client.ListTables(new ListTablesRequest()).ListTablesResult.TableNames;
                count++;
            }

            return list.Contains(request.TableName);
        }