Skip to content

Commit e3a14e3

Browse files
authored
Merge pull request #8624 from wastoresh/tablelib
[Storage] Upgrade to new XSCL and Table Lib
2 parents 10e331a + 0cc360b commit e3a14e3

File tree

56 files changed

+1157
-300
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1157
-300
lines changed

src/Storage/Storage.Management.Test/ScenarioTests/StorageDataPlaneTests.ps1

Lines changed: 133 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,43 @@ function Test-Table
248248
{
249249
$storageAccountKeyValue = $(Get-AzStorageAccountKey -ResourceGroupName $ResourceGroupName -Name $StorageAccountName)[0].Value
250250
$storageContext = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $storageAccountKeyValue
251-
251+
252+
# Create Table
252253
$tableName = "tabletest"
253254
New-AzStorageTable -Name $tableName -Context $storageContext
254255
$table =Get-AzStorageTable -Name $tableName -Context $storageContext
255256
Assert-AreEqual $table.Count 1
256257
Assert-AreEqual $table[0].Name $tableName
257258

259+
#Test run Table query - Insert Entity
260+
$partitionKey = "p123"
261+
$rowKey = "row123"
262+
$entity = New-Object -TypeName Microsoft.Azure.Cosmos.Table.DynamicTableEntity -ArgumentList $partitionKey, $rowKey
263+
$entity.Properties.Add("Name", "name1")
264+
$entity.Properties.Add("ID", 4567)
265+
$result = $table.CloudTable.ExecuteAsync([Microsoft.Azure.Cosmos.Table.TableOperation]::Insert($entity))
266+
267+
# Create Table Object - which reference to exist Table with SAS
268+
$tableSASUri = New-AzureStorageTableSASToken -Name $tablename -Permission "raud" -ExpiryTime (([DateTime]::UtcNow.AddDays(10))) -FullUri -Context $storageContext
269+
$uri = [System.Uri]$tableSASUri
270+
$sasTable = New-Object -TypeName Microsoft.Azure.Cosmos.Table.CloudTable $uri
271+
272+
#Test run Table query - Query Entity
273+
$query = New-Object Microsoft.Azure.Cosmos.Table.TableQuery
274+
## Define columns to select.
275+
$list = New-Object System.Collections.Generic.List[string]
276+
$list.Add("RowKey")
277+
$list.Add("ID")
278+
$list.Add("Name")
279+
## Set query details.
280+
$query.FilterString = "ID gt 0"
281+
$query.SelectColumns = $list
282+
$query.TakeCount = 20
283+
## Execute the query.
284+
$result = $sasTable.ExecuteQuerySegmentedAsync($query, $null)
285+
Assert-AreEqual $result.Result.Results.Count 1
286+
287+
# Get/Remove Table
258288
$tableCount1 = (Get-AzStorageTable -Context $storageContext).Count
259289
Remove-AzStorageTable -Name $tableName -Force -Context $storageContext
260290
$table2 = Get-AzStorageTable -Context $storageContext
@@ -370,18 +400,22 @@ function Test-Common
370400
{
371401
$storageAccountKeyValue = $(Get-AzStorageAccountKey -ResourceGroupName $ResourceGroupName -Name $StorageAccountName)[0].Value
372402
$storageContext = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $storageAccountKeyValue
403+
404+
# wait at most 120*5s=600s for the set sevice proeprty updated on server.
405+
$retryTimes = 120
373406

407+
# B/F/Q Service properties, in same code path
374408
$version = "1.0"
375409
$retentionDays = 2
376410
$LoggingOperations = "All"
377411

378412
Set-AzStorageServiceLoggingProperty -ServiceType blob -RetentionDays $retentionDays -Version $version -LoggingOperations $LoggingOperations -Context $storageContext
379413
$i = 0
380414
$propertyUpdated = $false
381-
while (($i -lt 120) -and ($propertyUpdated -eq $false))
415+
while (($i -lt $retryTimes ) -and ($propertyUpdated -eq $false))
382416
{
383417
$property = Get-AzStorageServiceLoggingProperty -ServiceType blob -Context $storageContext
384-
if (($property.RetentionDays -eq $retentionDays+1) -and ($property.Version -eq $version) -and ($property.LoggingOperations -eq $LoggingOperations))
418+
if (($property.RetentionDays -eq $retentionDays) -and ($property.Version -eq $version) -and ($property.LoggingOperations -eq $LoggingOperations))
385419
{
386420
$propertyUpdated = $true
387421
}
@@ -400,10 +434,10 @@ function Test-Common
400434
Set-AzStorageServiceMetricsProperty -ServiceType blob -Version $version -MetricsType Hour -RetentionDays $retentionDays -MetricsLevel $MetricsLevel -Context $storageContext
401435
$i = 0
402436
$propertyUpdated = $false
403-
while (($i -lt 120) -and ($propertyUpdated -eq $false))
437+
while (($i -lt $retryTimes ) -and ($propertyUpdated -eq $false))
404438
{
405-
$property = Get-AzStorageServiceLoggingProperty -ServiceType blob -Context $storageContext
406-
if (($property.RetentionDays -eq $retentionDays+1) -and ($property.Version -eq $version) -and ($property.MetricsLevel.ToString() -eq $MetricsLevel))
439+
$property = Get-AzStorageServiceMetricsProperty -ServiceType Blob -MetricsType Hour -Context $storageContext
440+
if (($property.RetentionDays -eq $retentionDays) -and ($property.Version -eq $version) -and ($property.MetricsLevel.ToString() -eq $MetricsLevel))
407441
{
408442
$propertyUpdated = $true
409443
}
@@ -431,7 +465,7 @@ function Test-Common
431465
AllowedMethods=@("Put")})
432466
$i = 0
433467
$corsRuleUpdated = $false
434-
while (($i -lt 120) -and ($corsRuleUpdated -eq $false))
468+
while (($i -lt $retryTimes ) -and ($corsRuleUpdated -eq $false))
435469
{
436470
$cors = Get-AzStorageCORSRule -ServiceType blob -Context $storageContext
437471
if ($cors.Count -eq 2)
@@ -450,7 +484,7 @@ function Test-Common
450484
Remove-AzStorageCORSRule -ServiceType blob -Context $storageContext
451485
$i = 0
452486
$corsRuleUpdated = $false
453-
while (($i -lt 120) -and ($corsRuleUpdated -eq $false))
487+
while (($i -lt $retryTimes ) -and ($corsRuleUpdated -eq $false))
454488
{
455489
$cors = Get-AzStorageCORSRule -ServiceType blob -Context $storageContext
456490
if ($cors.Count -eq 0)
@@ -464,7 +498,97 @@ function Test-Common
464498
}
465499
}
466500
$cors = Get-AzStorageCORSRule -ServiceType blob -Context $storageContext
467-
Assert-AreEqual 0 $cors.Count
501+
Assert-AreEqual 0 $cors.Count
502+
503+
# Table Service properties
504+
$version = "1.0"
505+
$retentionDays = 3
506+
$LoggingOperations = "Delete"
507+
508+
Set-AzStorageServiceLoggingProperty -ServiceType table -RetentionDays $retentionDays -Version $version -LoggingOperations $LoggingOperations -Context $storageContext
509+
$i = 0
510+
$propertyUpdated = $false
511+
while (($i -lt $retryTimes ) -and ($propertyUpdated -eq $false))
512+
{
513+
$property = Get-AzStorageServiceLoggingProperty -ServiceType table -Context $storageContext
514+
if (($property.RetentionDays -eq $retentionDays) -and ($property.Version -eq $version) -and ($property.LoggingOperations -eq $LoggingOperations))
515+
{
516+
$propertyUpdated = $true
517+
}
518+
else
519+
{
520+
sleep 5
521+
$i = $i + 5
522+
}
523+
}
524+
$property = Get-AzStorageServiceLoggingProperty -ServiceType table -Context $storageContext
525+
Assert-AreEqual $LoggingOperations $property.LoggingOperations.ToString()
526+
Assert-AreEqual $version $property.Version
527+
Assert-AreEqual $retentionDays $property.RetentionDays
528+
529+
$MetricsLevel = "ServiceAndApi"
530+
Set-AzStorageServiceMetricsProperty -ServiceType table -Version $version -MetricsType Minute -RetentionDays $retentionDays -MetricsLevel $MetricsLevel -Context $storageContext
531+
$i = 0
532+
$propertyUpdated = $false
533+
while (($i -lt $retryTimes ) -and ($propertyUpdated -eq $false))
534+
{
535+
$property = Get-AzStorageServiceMetricsProperty -ServiceType table -MetricsType Minute -Context $storageContext
536+
if (($property.RetentionDays -eq $retentionDays) -and ($property.Version -eq $version) -and ($property.MetricsLevel.ToString() -eq $MetricsLevel))
537+
{
538+
$propertyUpdated = $true
539+
}
540+
else
541+
{
542+
sleep 5
543+
$i = $i + 5
544+
}
545+
}
546+
$property = Get-AzStorageServiceMetricsProperty -ServiceType table -MetricsType Minute -Context $storageContext
547+
Assert-AreEqual $MetricsLevel $property.MetricsLevel.ToString()
548+
Assert-AreEqual $version $property.Version
549+
Assert-AreEqual $retentionDays $property.RetentionDays
550+
551+
Set-AzStorageCORSRule -ServiceType table -Context $storageContext -CorsRules (@{
552+
AllowedHeaders=@("x-ms-blob-content-type");
553+
AllowedOrigins=@("*");
554+
MaxAgeInSeconds=20;
555+
AllowedMethods=@("Get","Connect")})
556+
$i = 0
557+
$corsRuleUpdated = $false
558+
while (($i -lt $retryTimes ) -and ($corsRuleUpdated -eq $false))
559+
{
560+
$cors = Get-AzStorageCORSRule -ServiceType table -Context $storageContext
561+
if ($cors.Count -eq 1)
562+
{
563+
$corsRuleUpdated = $true
564+
}
565+
else
566+
{
567+
sleep 5
568+
$i = $i + 5
569+
}
570+
}
571+
$cors = Get-AzStorageCORSRule -ServiceType table -Context $storageContext
572+
Assert-AreEqual 1 $cors.Count
573+
574+
Remove-AzStorageCORSRule -ServiceType table -Context $storageContext
575+
$i = 0
576+
$corsRuleUpdated = $false
577+
while (($i -lt $retryTimes ) -and ($corsRuleUpdated -eq $false))
578+
{
579+
$cors = Get-AzStorageCORSRule -ServiceType table -Context $storageContext
580+
if ($cors.Count -eq 0)
581+
{
582+
$corsRuleUpdated = $true
583+
}
584+
else
585+
{
586+
sleep 5
587+
$i = $i + 5
588+
}
589+
}
590+
$cors = Get-AzStorageCORSRule -ServiceType table -Context $storageContext
591+
Assert-AreEqual 0 $cors.Count
468592
}
469593
finally
470594
{

src/Storage/Storage.Management/Az.Storage.psd1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,17 @@ RequiredModules = @(@{ModuleName = 'Az.Accounts'; ModuleVersion = '1.4.0'; })
5757

5858
# Assemblies that must be loaded prior to importing this module
5959
RequiredAssemblies = '.\Microsoft.Azure.Management.Storage.dll',
60-
'.\Microsoft.WindowsAzure.Storage.dll'
60+
'.\Microsoft.Azure.Storage.Common.dll',
61+
'.\Microsoft.Azure.Storage.Blob.dll',
62+
'.\Microsoft.Azure.Storage.File.dll',
63+
'.\Microsoft.Azure.Storage.Queue.dll',
64+
'.\Microsoft.Azure.Cosmos.Table.dll',
65+
'.\Microsoft.Azure.DocumentDB.Core.dll',
66+
'.\Microsoft.WindowsAzure.Storage.DataMovement.PowerShell.dll',
67+
'.\Microsoft.Azure.DocumentDB.Core.dll',
68+
'.\Microsoft.OData.Core.dll',
69+
'.\Microsoft.OData.Edm.dll',
70+
'.\Microsoft.Spatial.dll'
6171

6272
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
6373
# ScriptsToProcess = @()

src/Storage/Storage.Management/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Upgrade to Storage Client Library 9.4.2 and Microsoft.Azure.Cosmos.Table 0.10.1-preview
2122

2223
## Version 1.0.3
2324
* Support Kind BlockBlobStorage when create Storage account

src/Storage/Storage.Management/Storage.Management.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
</PropertyGroup>
1616
<ItemGroup>
1717
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="9.1.0-preview" />
18-
<PackageReference Include="WindowsAzure.Storage" Version="9.3.0" />
18+
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="9.4.2" />
19+
<PackageReference Include="Microsoft.Azure.Storage.File" Version="9.4.2" />
20+
<PackageReference Include="Microsoft.Azure.Storage.Queue" Version="9.4.2" />
21+
<PackageReference Include="Microsoft.Azure.KeyVault.Core" Version="2.0.4" />
1922
</ItemGroup>
2023
<ItemGroup>
2124
<Compile Include="$(StorageToolsPath)Adapters\ARM.Storage.6\ARMStorageProvider.cs" Link="Common\ARMStorageProvider.cs" />

src/Storage/Storage.Management/help/New-AzStorageTableSASToken.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---
1+
---
22
external help file: Microsoft.Azure.PowerShell.Cmdlets.Storage.dll-Help.xml
33
Module Name: Az.Storage
44
ms.assetid: 3CFA6E31-E243-4B22-AE8F-1942DD324639
@@ -222,7 +222,7 @@ The acceptable values for this parameter are:
222222
The default value is HttpsOrHttp.
223223

224224
```yaml
225-
Type: System.Nullable`1[Microsoft.WindowsAzure.Storage.SharedAccessProtocol]
225+
Type: System.Nullable`1[Microsoft.Azure.Cosmos.Table.SharedAccessProtocol]
226226
Parameter Sets: (All)
227227
Aliases:
228228
Accepted values: HttpsOnly, HttpsOrHttp

src/Storage/Storage.Test/Common/AccessPolicyHelperTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
using Microsoft.VisualStudio.TestTools.UnitTesting;
1818
using Microsoft.WindowsAzure.Commands.Storage.Common;
1919
using Microsoft.WindowsAzure.Storage.Blob;
20-
using Microsoft.WindowsAzure.Storage.Table;
20+
using Microsoft.Azure.Cosmos.Table;
2121
using Microsoft.WindowsAzure.Storage.File;
2222
using Microsoft.WindowsAzure.Storage.Queue;
2323

src/Storage/Storage.Test/Common/PSServicePropertiesTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
using Microsoft.WindowsAzure.Commands.Storage.Common;
1919
using Microsoft.WindowsAzure.Commands.Storage.Model.ResourceModel;
2020
using Microsoft.WindowsAzure.Storage.Blob;
21-
using Microsoft.WindowsAzure.Storage.Table;
21+
using XTable = Microsoft.Azure.Cosmos.Table;
2222
using Microsoft.WindowsAzure.Storage.File;
2323
using Microsoft.WindowsAzure.Storage.Queue;
2424
using Microsoft.WindowsAzure.Storage.Shared.Protocol;

src/Storage/Storage.Test/Service/MockStorageBlobManagement.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ----------------------------------------------------------------------------------
1+
// ----------------------------------------------------------------------------------
22
//
33
// Copyright Microsoft Corporation
44
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,6 +16,7 @@
1616
using System.Collections.Generic;
1717
using System.Threading;
1818
using System.Threading.Tasks;
19+
using XTable = Microsoft.Azure.Cosmos.Table;
1920
using Microsoft.WindowsAzure.Commands.Common.Storage;
2021
using Microsoft.WindowsAzure.Commands.Storage.Common;
2122
using Microsoft.WindowsAzure.Commands.Storage.Model.Contract;

src/Storage/Storage.Test/Service/MockStorageTableManagement.cs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
using Microsoft.WindowsAzure.Commands.Common.Storage;
1919
using Microsoft.WindowsAzure.Commands.Storage.Model.Contract;
2020
using Microsoft.WindowsAzure.Storage;
21-
using Microsoft.WindowsAzure.Storage.Table;
21+
using Microsoft.Azure.Cosmos.Table;
22+
using XTable = Microsoft.Azure.Cosmos.Table;
2223

2324
namespace Microsoft.WindowsAzure.Commands.Storage.Test.Service
2425
{
@@ -49,7 +50,7 @@ public class MockStorageTableManagement : IStorageTableManagement
4950
/// <param name="requestOptions">Table request options</param>
5051
/// <param name="operationContext">Operation context</param>
5152
/// <returns>An enumerable collection of tables that begin with the specified prefix</returns>
52-
public IEnumerable<CloudTable> ListTables(string prefix, TableRequestOptions requestOptions, OperationContext operationContext)
53+
public IEnumerable<CloudTable> ListTables(string prefix, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
5354
{
5455
if (String.IsNullOrEmpty(prefix))
5556
{
@@ -78,7 +79,7 @@ public IEnumerable<CloudTable> ListTables(string prefix, TableRequestOptions req
7879
/// <param name="requestOptions">Table request options</param>
7980
/// <param name="operationContext">Operation context</param>
8081
/// <returns>A CloudTable object if the specified table exists, otherwise null.</returns>
81-
public CloudTable GetTableReferenceFromServer(string name, TableRequestOptions requestOptions, OperationContext operationContext)
82+
public CloudTable GetTableReferenceFromServer(string name, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
8283
{
8384
foreach (CloudTable table in tableList)
8485
{
@@ -109,7 +110,7 @@ public CloudTable GetTableReference(string name)
109110
/// <param name="requestOptions">Table request options</param>
110111
/// <param name="operationContext">Operation context</param>
111112
/// <returns>True if table was created; otherwise, false.</returns>
112-
public bool CreateTableIfNotExists(CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext)
113+
public bool CreateTableIfNotExists(CloudTable table, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
113114
{
114115
CloudTable tableRef = GetTableReferenceFromServer(table.Name, requestOptions, operationContext);
115116

@@ -131,7 +132,7 @@ public bool CreateTableIfNotExists(CloudTable table, TableRequestOptions request
131132
/// <param name="table">Cloud table object</param>
132133
/// <param name="requestOptions">Table request options</param>
133134
/// <param name="operationContext">Operation context</param>
134-
public void Delete(CloudTable table, TableRequestOptions requestOptions = null, OperationContext operationContext = null)
135+
public void Delete(CloudTable table, TableRequestOptions requestOptions = null, XTable.OperationContext operationContext = null)
135136
{
136137
foreach (CloudTable tableRef in tableList)
137138
{
@@ -150,7 +151,7 @@ public void Delete(CloudTable table, TableRequestOptions requestOptions = null,
150151
/// <param name="requestOptions">Table request options</param>
151152
/// <param name="operationContext">Operation context</param>
152153
/// <returns>True if table exists; otherwise, false.</returns>
153-
public bool DoesTableExist(CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext)
154+
public bool DoesTableExist(CloudTable table, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
154155
{
155156
foreach (CloudTable tableRef in tableList)
156157
{
@@ -170,7 +171,7 @@ public bool DoesTableExist(CloudTable table, TableRequestOptions requestOptions,
170171
/// <param name="requestOptions">Table request options</param>
171172
/// <param name="operationContext">Operation context</param>
172173
/// <returns>Table permission</returns>
173-
public TablePermissions GetTablePermissions(CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext)
174+
public TablePermissions GetTablePermissions(CloudTable table, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
174175
{
175176
return this.tablePermissions;
176177
}
@@ -183,7 +184,7 @@ public TablePermissions GetTablePermissions(CloudTable table, TableRequestOption
183184
/// <param name="requestOptions">Table request options</param>
184185
/// <param name="operationContext">Operation context</param>
185186
/// <returns></returns>
186-
public void SetTablePermissions(CloudTable table, TablePermissions tablePermissions, TableRequestOptions requestOptions, OperationContext operationContext)
187+
public void SetTablePermissions(CloudTable table, TablePermissions tablePermissions, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
187188
{
188189
this.tablePermissions = tablePermissions;
189190
}
@@ -196,7 +197,7 @@ public void SetTablePermissions(CloudTable table, TablePermissions tablePermissi
196197
/// <param name="requestOptions">request options</param>
197198
/// <param name="operationContext">context</param>
198199
/// <returns></returns>
199-
public Task SetTablePermissionsAsync(CloudTable table, TablePermissions tablePermissions, TableRequestOptions requestOptions, OperationContext operationContext)
200+
public Task SetTablePermissionsAsync(CloudTable table, TablePermissions tablePermissions, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
200201
{
201202
return Task.Factory.StartNew(() => this.SetTablePermissions(table, tablePermissions, requestOptions, operationContext));
202203
}
@@ -208,16 +209,25 @@ public Task SetTablePermissionsAsync(CloudTable table, TablePermissions tablePer
208209
/// <param name="requestOptions">request options</param>
209210
/// <param name="operationContext">context</param>
210211
/// <returns></returns>
211-
public Task<TablePermissions> GetTablePermissionsAsync(CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext)
212+
public Task<TablePermissions> GetTablePermissionsAsync(CloudTable table, TableRequestOptions requestOptions, XTable.OperationContext operationContext)
212213
{
213214
return Task.Factory.StartNew(() => this.GetTablePermissions(table,
214215
requestOptions, operationContext));
215216
}
216217

217-
218218
public AzureStorageContext StorageContext
219219
{
220220
get { throw new NotImplementedException(); }
221221
}
222+
223+
public Azure.Cosmos.Table.ServiceProperties GetStorageTableServiceProperties(XTable.TableRequestOptions options, XTable.OperationContext operationContext)
224+
{
225+
throw new NotImplementedException();
226+
}
227+
228+
public void SetStorageTableServiceProperties(Azure.Cosmos.Table.ServiceProperties properties, XTable.TableRequestOptions options, XTable.OperationContext operationContext)
229+
{
230+
throw new NotImplementedException();
231+
}
222232
}
223233
}

0 commit comments

Comments
 (0)