private static void WaitUntilTableReady(string tableName) { string status = null; // Let us wait until table is created. Call DescribeTable. do { 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; } catch (ResourceNotFoundException) { // DescribeTable is eventually consistent. So you might // get resource not found. So we handle the potential exception. } } while (status != "ACTIVE"); }
public override int GetErrors(int pageIndex, int pageSize, IList errorEntryList) { AssertTableExists(); var max = pageSize * (pageIndex + 1); Dictionary <string, AttributeValue> lastEvaluatedKey = null; var errors = new List <ErrorLogEntry>(max); // have to start at the beginning and go through up to the current page, this means it will perform worse as we go through more pages // usually, we are just looking at the first few pages so ¯\_(ツ)_/¯ // low level scanning http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LowLevelDotNetScanning.html#LowLevelDotNetScanningOptions do { var request = new QueryRequest(TableName) { KeyConditionExpression = "Application = :v_appl", ExpressionAttributeValues = new Dictionary <string, AttributeValue> { { ":v_appl", new AttributeValue(ApplicationName) } }, IndexName = "Application-TimeUtc-index", ScanIndexForward = false, Limit = max, Select = Select.ALL_PROJECTED_ATTRIBUTES }; if (lastEvaluatedKey != null) { request.ExclusiveStartKey = lastEvaluatedKey; } var response = _client.Query(request); errors.AddRange(from item in response.Items let errorXml = item["AllXml"].S let errorId = item["ErrorId"].S let error = ErrorXml.DecodeString(errorXml) select new ErrorLogEntry(this, errorId, error)); lastEvaluatedKey = response.LastEvaluatedKey; } while (lastEvaluatedKey != null && lastEvaluatedKey.Count > 0 && errors.Count < max); var numberToSkip = pageIndex * pageSize; errors = errors.Skip(numberToSkip).Take(pageSize).ToList(); errors.ForEach(err => errorEntryList.Add(err)); // get total count of items in the table. // This value is stale (updates every six hours) but will do the job in most cases // the other alternative would be to do another scan of the entire index with a Select.COUNT var total = _client.DescribeTable(new DescribeTableRequest(TableName)).Table.ItemCount; return(Convert.ToInt32(Math.Max(errorEntryList.Count, total))); }
public static void WaitUntilTableReady(this AmazonDynamoDBClient client, string tableName, string currentStatus = null) { int attempts = 0; if (!string.IsNullOrEmpty(currentStatus) && !currentStatus.Equals("ACTIVE", StringComparison.OrdinalIgnoreCase)) { string status = null; // Let us wait until table is created. Call DescribeTable. do { if (attempts > 10) { throw new TimeoutException("Waited for 30 seconds for table " + tableName + " to be created."); } System.Threading.Thread.Sleep(3000); // Wait 3 seconds. try { attempts++; 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 is eventually consistent. So you might get resource not found. So we handle the potential exception. } } while (status != "ACTIVE"); } }
public static void WaitUntilTableDeleted(this AmazonDynamoDBClient client, string tableName) { int attempts = 0; string status = null; // Let us wait until table is deleted. Call DescribeTable. do { if (attempts > 10) { throw new TimeoutException("Waited for 30 seconds for table " + tableName + " to be deleted."); } attempts++; System.Threading.Thread.Sleep(3000); // Wait 5 seconds. try { var res = client.DescribeTable(new DescribeTableRequest { TableName = tableName }); status = res.Table.TableStatus; } catch (ResourceNotFoundException) { // Table not found. It is deleted return; } } while (status == "DELETING"); }
private void WaitUntilTableReady(string tableName, string currentStatus) { if (!currentStatus.Equals("ACTIVE", StringComparison.OrdinalIgnoreCase)) { string status = null; // Let us wait until table is created. Call DescribeTable. do { System.Threading.Thread.Sleep(3000); // Wait 3 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; } catch (ResourceNotFoundException) { // Table is eventually consistent. So you might get resource not found. So we handle the potential exception. } } while (status != "ACTIVE"); } }
private void WaitTillTableDeleted(AmazonDynamoDBClient client, string tableName) { Console.Write("Deleting the table: "); string status; try { do { System.Threading.Thread.Sleep(50); var res = client.DescribeTable(new DescribeTableRequest { TableName = tableName }); if (res.Table.TableStatus == "DELETING") { Console.Write("."); } else { Console.Write("[{0}]", res.Table.TableStatus); } status = res.Table.TableStatus; }while (status == "DELETING"); } catch (ResourceNotFoundException) { Console.WriteLine(" Done."); } }
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. } }
private void WaitTillTableCreated(AmazonDynamoDBClient client, string tableName) { string status; Console.Write("Creating the table: "); do { System.Threading.Thread.Sleep(50); try { var res = client.DescribeTable(new DescribeTableRequest { TableName = tableName }); if (res.Table.TableStatus == "ACTIVE") { break; } if (res.Table.TableStatus == "CREATING") { Console.Write("."); } else { Console.Write("[{0}]", res.Table.TableStatus); } status = res.Table.TableStatus; } catch (ResourceNotFoundException) { Console.Write("?"); // Okay to appear, since the consistency is eventual. status = "EXCEPTION"; } } while (status != "ACTIVE"); Console.WriteLine(" Done."); }
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) { } } }
private static void WaitUntilTableReady(string tableName) { var config = new AmazonDynamoDBConfig(); config.ServiceURL = "http://dynamodb.us-east-1.amazonaws.com"; client = new AmazonDynamoDBClient(config); string status = null; // Let us wait until table is created. Call DescribeTable. do { 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.DescribeTableResult.Table.TableName, res.DescribeTableResult.Table.TableStatus); status = res.DescribeTableResult.Table.TableStatus; } catch (Amazon.DynamoDBv2.Model.ResourceNotFoundException resourceNotFound) { // DescribeTable is eventually consistent. So you might // get resource not found. So we handle the potential exception. } } while (status != "ACTIVE"); }
public void TestCache() { Func <string, TableDescription> creator = tn => client.DescribeTable(tn).Table; var tableName = GetTableName(); var tableCache = SdkCache.GetCache <string, TableDescription>(client, DynamoDBTests.TableCacheIdentifier, StringComparer.Ordinal); Assert.AreEqual(0, tableCache.ItemCount); using (var counter = new ServiceResponseCounter(client)) { var table = tableCache.GetValue(tableName, creator); Assert.AreEqual(1, counter.ResponseCount); Assert.AreEqual(1, tableCache.ItemCount); // verify the item is still there table = tableCache.GetValue(tableName, creator); Assert.AreEqual(1, counter.ResponseCount); // verify item was reloaded tableCache.Clear(tableName); table = tableCache.GetValue(tableName, creator); Assert.AreEqual(2, counter.ResponseCount); Assert.AreEqual(1, tableCache.ItemCount); // test item expiration tableCache.MaximumItemLifespan = TimeSpan.FromSeconds(1); Thread.Sleep(tableCache.MaximumItemLifespan); table = tableCache.GetValue(tableName, creator); Assert.AreEqual(3, counter.ResponseCount); Assert.AreEqual(1, tableCache.ItemCount); } }
// GET api/<controller>/5 public DescribeTableResponse Get(string id) { var response = _client.ListTables(); return(response.TableNames.Contains(id) ? _client.DescribeTable(id) : null); }
private static bool GetTableInformation() { Console.WriteLine("\n*** Retrieving table information ***"); var request = new DescribeTableRequest { TableName = "Employee" }; try { var response = ddbClient.DescribeTable(request); TableDescription description = response.Table; return true; } catch(Amazon.DynamoDBv2.Model.ResourceNotFoundException ex) { return false; } }
private static bool PharmaDataExists() { bool pharmaDataExists = false; try { dynamoDBClient.DescribeTable(new DescribeTableRequest { TableName = PharmaTableName }); pharmaDataExists = true; } catch (ResourceNotFoundException e) { Debug.WriteLine(PharmaTableName + " DynamoDB table does not exist. " + e.Message); } return(pharmaDataExists); }
private static void GetTableInformation() { Console.WriteLine("\n*** Retrieving table information ***"); var request = new DescribeTableRequest { TableName = tableName }; var response = client.DescribeTable(request); TableDescription description = response.Table; Console.WriteLine("Name: {0}", description.TableName); Console.WriteLine("# of items: {0}", description.ItemCount); Console.WriteLine("Provision Throughput (reads/sec): {0}", description.ProvisionedThroughput.ReadCapacityUnits); Console.WriteLine("Provision Throughput (writes/sec): {0}", description.ProvisionedThroughput.WriteCapacityUnits); }
public void DescribeTable() { DescribeTableRequest request = new DescribeTableRequest { TableName = TableName }; var response = client.DescribeTable(request); if (response.HttpStatusCode.IsSuccess()) { Console.WriteLine($"TableArn: {response.Table.TableArn}"); } }
/*-------------------------------------------------------------------------- * checkingTableExistence *--------------------------------------------------------------------------*/ public bool CheckTableIsReady(string tableName) { try { var result = DynamoClient.DescribeTable(tableName); return(result?.Table != null && result.Table.TableStatus == TableStatus.ACTIVE); } catch { return(false); } }
private void CreateTable(string tabNam, string hashKey) { client = new AmazonDynamoDBClient(); var tableResponse = client.ListTables(); if (!tableResponse.TableNames.Contains(tabNam)) { MessageBox.Show("Shelf doesn't exist, creating shelf " + tabNam); client.CreateTable(new CreateTableRequest { TableName = tabNam, ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 3, WriteCapacityUnits = 1 }, KeySchema = new List <KeySchemaElement> { new KeySchemaElement { AttributeName = hashKey, KeyType = KeyType.HASH } }, AttributeDefinitions = new List <AttributeDefinition> { new AttributeDefinition { AttributeName = hashKey, AttributeType = ScalarAttributeType.S } } }); bool isTableAvailable = false; while (!isTableAvailable) { Console.WriteLine("Waiting for table to be active..."); Thread.Sleep(5000); var tableStatus = client.DescribeTable(tabNam); isTableAvailable = tableStatus.Table.TableStatus == "ACTIVE"; } MessageBox.Show($"Shelf {tabNam} Created Successfully!"); SaveBookinShelf(); enableBtns(); //resetBtns(); } else { MessageBox.Show($"{tabNam} exist already!, Adding {txtTitle.Text} book in the shelf"); SaveBookinShelf(); //resetBtns(); enableBtns(); } }
private void AssertDynamoDbExists(string tableName) { var request = new DescribeTableRequest { TableName = tableName }; try { var response = _client.DescribeTable(request); } catch (ResourceNotFoundException) { Assert.Fail("Table {0} doesn't exist!", _tableName); } }
private static void WaitUntilTableActive(AmazonDynamoDBClient client) { Console.WriteLine("Waiting for table to be active"); while (true) { var status = client.DescribeTable(tableName).Table.TableStatus; if (status == TableStatus.ACTIVE) { break; } Console.WriteLine("Table status = {0}, sleeping...", status); Thread.Sleep(TimeSpan.FromSeconds(1)); } Console.WriteLine("Table created"); }
public void GetInformationTable() { DescribeTableRequest request = new DescribeTableRequest { TableName = "DynamoDbEmployeeBackup" }; var response = client.DescribeTable(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine($"Table ARN =>{response.Table.TableArn}"); Console.WriteLine($"Table ARN =>{response.Table.TableId}"); Console.WriteLine($"Table ARN =>{response.Table.TableName}"); } Console.ReadLine(); }
private void CreateTable() { var credentials = new BasicAWSCredentials(accessKey, secretKey); client = new AmazonDynamoDBClient(credentials, RegionEndpoint.USWest1); var tableResponse = client.ListTables(); if (!tableResponse.TableNames.Contains(tableName)) { MessageBox.Show("Table not found, creating table => " + tableName); client.CreateTable(new CreateTableRequest { TableName = tableName, ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 3, WriteCapacityUnits = 1 }, KeySchema = new List <KeySchemaElement> { new KeySchemaElement { AttributeName = hashKey, KeyType = KeyType.HASH } }, AttributeDefinitions = new List <AttributeDefinition> { new AttributeDefinition { AttributeName = hashKey, AttributeType = ScalarAttributeType.S } } }); bool isTableAvailable = false; while (!isTableAvailable) { Console.WriteLine("Waiting for table to be active..."); Thread.Sleep(5000); var tableStatus = client.DescribeTable(tableName); isTableAvailable = tableStatus.Table.TableStatus == "ACTIVE"; } MessageBox.Show("DynamoDB Table Created Successfully!"); } }
/// <summary> /// Retrieves a table status. Returns empty string if table does not exist. /// </summary> /// <param name="client"></param> /// <param name="tableName"></param> /// <returns></returns> private static TableStatus GetTableStatus(AmazonDynamoDBClient client, string tableName) { try { var table = client.DescribeTable(new DescribeTableRequest { TableName = tableName }).Table; return((table == null) ? null : table.TableStatus); } catch (AmazonDynamoDBException db) { if (db.ErrorCode == "ResourceNotFoundException") { return(string.Empty); } throw; } }
private static bool DoesTableExist(AmazonDynamoDBClient client) { bool tableExists; try { Console.WriteLine("Testing if table exists"); client.DescribeTable(tableName); Console.WriteLine("Table exists"); tableExists = true; } catch { Console.WriteLine("Table does not exist"); tableExists = false; } return(tableExists); }
/** * Check the table's status using the DescribeTable method * Wait for the table to become active * * @return Table Status */ private static string GetTableStatus() { string status = null; System.Threading.Thread.Sleep(5000); try { var res = dynamoDBClient.DescribeTable(new DescribeTableRequest { TableName = InfectionsTableName }); status = res.Table.TableStatus; } catch (AmazonDynamoDBException ex) { Debug.WriteLine("An exception has occured: " + ex.Message); } return(status); }
public static string GetTableStatus(AmazonDynamoDBClient dynamoDBClient, string InfectionsTableName) { Debug.WriteLine(String.Format("RUNNING SOLUTION CODE: {0}! Follow the steps in the lab guide to replace this method with your own implementation.\n", "GetTableStatus")); string status = null; System.Threading.Thread.Sleep(5000); try { var res = dynamoDBClient.DescribeTable(new DescribeTableRequest { TableName = InfectionsTableName }); status = res.Table.TableStatus; } catch (AmazonDynamoDBException ex) { Debug.WriteLine("An exception has occured: " + ex.Message); } return(status); }
public DDBOperation() { credentials = new Amazon.Runtime.BasicAWSCredentials( ConfigurationManager.AppSettings["accessId"], ConfigurationManager.AppSettings["secretKey"]); client = new AmazonDynamoDBClient(credentials, Amazon.RegionEndpoint.USEast1); context = new DynamoDBContext(client); // Check the existence of the User database and creating one if it does not exist try { var res = client.DescribeTable(new DescribeTableRequest { TableName = "User" }); } catch (Exception) { CreateTable(); } }
private static void WaitTilTableCreated(string tableName, CreateTableResponse response) { var tableDescription = response.TableDescription; string status = tableDescription.TableStatus; Util.LogInfo(tableName + " - " + status); // Let us wait until table is created. Call DescribeTable. while (status != "ACTIVE") { Thread.Sleep(5000); // Wait 5 seconds. try { var res = client.DescribeTable(new DescribeTableRequest { TableName = tableName }); Util.LogInfo("Table name: " + res.Table.TableName + ", status: " + res.Table.TableStatus); status = res.Table.TableStatus; } // Try-catch to handle potential eventual-consistency issue. catch (ResourceNotFoundException) { } } }
public virtual TableDescription GetTableDescription(AmazonDynamoDBClient ddbClient, string tableName) { try { DescribeTableResponse describeTableResponse = ddbClient.DescribeTable( new DescribeTableRequest { TableName = tableName }); return(describeTableResponse.Table); } catch (AmazonServiceException ase) { // If the table isn't found, there's no problem. // If the error is something else, rethrow the exception to bubble it up to the caller. if (!ase.ErrorCode.Equals("ResourceNotFoundException")) { throw; } return(null); } }
private static void WaitUntilTableReady(AmazonDynamoDBClient client, TableStatus targetStatus) { var startTime = DateTime.Now; TableStatus status; while ((DateTime.Now - startTime) < tableActiveMaxTime) { try { status = client.DescribeTable(tableName).Table.TableStatus; } catch (ResourceNotFoundException) { status = null; } if (status == targetStatus) { return; } Thread.Sleep(waitPeriod); } }