Skip to content

Commit

Permalink
Add CloudStorageAccount support in AzureTableInstanceStore (Azure#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
shwetabhartimsft authored Oct 15, 2021
1 parent f2dc50f commit e6e1ce6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 10 deletions.
27 changes: 18 additions & 9 deletions src/DurableTask.ServiceBus/Tracking/AzureTableClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ namespace DurableTask.ServiceBus.Tracking
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.RetryPolicies;
using Microsoft.WindowsAzure.Storage.Table;
using Microsoft.WindowsAzure.Storage.Table.Protocol;

internal class AzureTableClient
{
Expand All @@ -49,27 +48,37 @@ static readonly IDictionary<FilterComparisonType, string> ComparisonOperatorMap
volatile CloudTable jumpStartTable;

public AzureTableClient(string hubName, string tableConnectionString)
: this(hubName, CloudStorageAccount.Parse(tableConnectionString))
{
if (string.IsNullOrWhiteSpace(tableConnectionString))
{
throw new ArgumentException("Invalid connection string", nameof(tableConnectionString));
}

}

public AzureTableClient(string hubName, CloudStorageAccount cloudStorageAccount)
{
if (string.IsNullOrWhiteSpace(hubName))
{
throw new ArgumentException("Invalid hub name", nameof(hubName));
}

this.tableClient = CloudStorageAccount.Parse(tableConnectionString).CreateCloudTableClient();
this.tableClient.DefaultRequestOptions.RetryPolicy = new ExponentialRetry(DeltaBackOff,
MaxRetries);
this.tableClient.DefaultRequestOptions.MaximumExecutionTime = MaximumExecutionTime;
if (cloudStorageAccount == null)
{
throw new ArgumentException("Invalid Cloud Storage Account", nameof(cloudStorageAccount));
}

this.tableClient = CreateAzureTableClient(cloudStorageAccount);
this.hubName = hubName;
this.historyTable = this.tableClient.GetTableReference(TableName);
this.jumpStartTable = this.tableClient.GetTableReference(JumpStartTableName);
}

private static CloudTableClient CreateAzureTableClient(CloudStorageAccount cloudStorageAccount)
{
CloudTableClient tableClient = cloudStorageAccount.CreateCloudTableClient();
tableClient.DefaultRequestOptions.RetryPolicy = new ExponentialRetry(DeltaBackOff, MaxRetries);
tableClient.DefaultRequestOptions.MaximumExecutionTime = MaximumExecutionTime;
return tableClient;
}

public string TableName => AzureTableConstants.InstanceHistoryTableNamePrefix + "00" + this.hubName;

public string JumpStartTableName => AzureTableConstants.JumpStartTableNamePrefix + "00" + this.hubName;
Expand Down
34 changes: 34 additions & 0 deletions src/DurableTask.ServiceBus/Tracking/AzureTableInstanceStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace DurableTask.ServiceBus.Tracking
using DurableTask.Core.Common;
using DurableTask.Core.Serializing;
using DurableTask.Core.Tracking;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;

/// <summary>
Expand All @@ -45,12 +46,45 @@ public class AzureTableInstanceStore : IOrchestrationServiceInstanceStore
/// <param name="tableConnectionString">Azure table connection string</param>
public AzureTableInstanceStore(string hubName, string tableConnectionString)
{
if (string.IsNullOrWhiteSpace(tableConnectionString))
{
throw new ArgumentException("Invalid connection string", nameof(tableConnectionString));
}

if (string.IsNullOrWhiteSpace(hubName))
{
throw new ArgumentException("Invalid hub name", nameof(hubName));
}

this.tableClient = new AzureTableClient(hubName, tableConnectionString);

// Workaround an issue with Storage that throws exceptions for any date < 1600 so DateTime.Min cannot be used
DateTimeUtils.SetMinDateTimeForStorageEmulator();
}

/// <summary>
/// Creates a new AzureTableInstanceStore using the supplied hub name and cloud storage account
/// </summary>
/// <param name="hubName">The hub name for this instance store</param>
/// <param name="cloudStorageAccount">Cloud Storage Account</param>
public AzureTableInstanceStore(string hubName, CloudStorageAccount cloudStorageAccount)
{
if (cloudStorageAccount == null)
{
throw new ArgumentException("Invalid Cloud Storage Account", nameof(cloudStorageAccount));
}

if (string.IsNullOrWhiteSpace(hubName))
{
throw new ArgumentException("Invalid hub name", nameof(hubName));
}

this.tableClient = new AzureTableClient(hubName, cloudStorageAccount);

// Workaround an issue with Storage that throws exceptions for any date < 1600 so DateTime.Min cannot be used
DateTimeUtils.SetMinDateTimeForStorageEmulator();
}

/// <summary>
/// Runs initialization to prepare the storage for use
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/DurableTask.ServiceBus/Tracking/BlobStorageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public BlobStorageClient(string hubName, CloudStorageAccount cloudStorageAccount
/// Creates a blob storage client with cloudStorageAccount
/// </summary>
/// <param name="cloudStorageAccount">The Cloud Storage Account</param>
public static CloudBlobClient CreateBlobClient(CloudStorageAccount cloudStorageAccount)
private static CloudBlobClient CreateBlobClient(CloudStorageAccount cloudStorageAccount)
{
CloudBlobClient blobClient = cloudStorageAccount.CreateCloudBlobClient();
blobClient.DefaultRequestOptions.RetryPolicy = new ExponentialRetry(DeltaBackOff, MaxRetries);
Expand Down

0 comments on commit e6e1ce6

Please sign in to comment.