Skip to content

Commit 24f8c94

Browse files
kavskalyanamisi01
andauthored
[CosmosDB] Exposing backup policy migration state (#16637)
* Exposing backup policy migration state * Added test for migration state validation Co-authored-by: REDMOND\amisi <amisi@microsoft.com>
1 parent 0a332cf commit 24f8c94

File tree

6 files changed

+879
-2
lines changed

6 files changed

+879
-2
lines changed

src/CosmosDB/CosmosDB.Test/ScenarioTests/RestoreTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,12 @@ public void TestMongoDBCollectionBackupInformationCmdLets()
6868
{
6969
TestController.NewInstance.RunPowerShellTest(_logger, "Test-MongoDBCollectionBackupInformationCmdLets");
7070
}
71+
72+
[Fact]
73+
[Trait(Category.AcceptanceType, Category.CheckIn)]
74+
public void TestUpdateCosmosDBAccountBackupPolicyCmdLet()
75+
{
76+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-UpdateCosmosDBAccountBackupPolicyCmdLet");
77+
}
7178
}
7279
}

src/CosmosDB/CosmosDB.Test/ScenarioTests/RestoreTests.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,31 @@ function Test-MongoDBCollectionBackupInformationCmdLets {
325325
Assert-NotNull $backupInfo
326326
Assert-NotNull $backupInfo.LatestRestorableTimestamp
327327
}
328+
329+
function Test-UpdateCosmosDBAccountBackupPolicyCmdLet {
330+
$rgName = "CosmosDBResourceGroup20"
331+
$location = "Central US"
332+
$cosmosDBAccountName = "cosmosdb-1220"
333+
$apiKind = "Sql"
334+
$consistencyLevel = "Session"
335+
$locations = @()
336+
$locations += New-AzCosmosDBLocationObject -Location $location -FailoverPriority 0 -IsZoneRedundant 0
337+
338+
$resourceGroup = New-AzResourceGroup -ResourceGroupName $rgName -Location $location
339+
340+
Try {
341+
New-AzCosmosDBAccount -ResourceGroupName $rgName -LocationObject $locations -Name $cosmosDBAccountName -ApiKind $apiKind -DefaultConsistencyLevel $consistencyLevel
342+
}
343+
Catch {
344+
Assert-AreEqual $_.Exception.Message ("Resource with Name " + $cosmosDBAccountName + " already exists.")
345+
}
346+
347+
$updatedCosmosDBAccount = Update-AzCosmosDBAccount -ResourceGroupName $rgName -Name $cosmosDBAccountName -BackupPolicyType Continuous
348+
Start-Sleep -s 50
349+
350+
$updatedCosmosDBAccount = Get-AzCosmosDBAccount -ResourceGroupName $rgName -Name $cosmosDBAccountName
351+
Assert-NotNull $updatedCosmosDBAccount.BackupPolicy.BackupPolicyMigrationState
352+
Assert-NotNull $updatedCosmosDBAccount.BackupPolicy.BackupPolicyMigrationState.Status
353+
Assert-NotNull $updatedCosmosDBAccount.BackupPolicy.BackupPolicyMigrationState.TargetType
354+
Assert-NotNull $updatedCosmosDBAccount.BackupPolicy.BackupPolicyMigrationState.StartTime
355+
}

src/CosmosDB/CosmosDB.Test/SessionRecords/Microsoft.Azure.Commands.CosmosDB.Test.ScenarioTests.ScenarioTest.RestoreTests/TestUpdateCosmosDBAccountBackupPolicyCmdLet.json

Lines changed: 770 additions & 0 deletions
Large diffs are not rendered by default.

src/CosmosDB/CosmosDB/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Exposing BackupPolicyMigrationState as a part of Get-AzCosmosDBAccount response.
23+
This shows the status of a backup policy migration state when an account is being converted from peroidic backup mode to continuous.
2224

2325
## Version 1.5.0
2426
* Fixed when a warning about the value of AnalyticalStorageSchemaType is displayed when no value was given.

src/CosmosDB/CosmosDB/Models/DatabaseAccount/PSBackupPolicy.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public PSBackupPolicy(BackupPolicy backupPolicy)
4242
{
4343
BackupType = ContinuousModeBackupType;
4444
}
45+
46+
if (backupPolicy.MigrationState != null)
47+
{
48+
BackupPolicyMigrationState = new PSBackupPolicyMigrationState(backupPolicy.MigrationState);
49+
}
4550
}
4651

4752
public int? BackupIntervalInMinutes { get; set; }
@@ -52,11 +57,14 @@ public PSBackupPolicy(BackupPolicy backupPolicy)
5257

5358
public string BackupStorageRedundancy { get; set; }
5459

60+
public PSBackupPolicyMigrationState BackupPolicyMigrationState { get; set;}
61+
5562
public BackupPolicy ToSDKModel()
5663
{
64+
BackupPolicy backupPolicy;
5765
if (BackupType.Equals(PSBackupPolicy.ContinuousModeBackupType))
5866
{
59-
return new ContinuousModeBackupPolicy();
67+
backupPolicy = new ContinuousModeBackupPolicy();
6068
}
6169
else
6270
{
@@ -70,8 +78,10 @@ public BackupPolicy ToSDKModel()
7078
}
7179
};
7280

73-
return periodicModeBackupPolicy;
81+
backupPolicy = periodicModeBackupPolicy;
7482
}
83+
84+
return backupPolicy;
7585
}
7686
}
7787
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using Microsoft.Azure.Management.CosmosDB.Models;
17+
18+
namespace Microsoft.Azure.Commands.CosmosDB.Models
19+
{
20+
public class PSBackupPolicyMigrationState
21+
{
22+
public PSBackupPolicyMigrationState()
23+
{
24+
}
25+
26+
public PSBackupPolicyMigrationState(BackupPolicyMigrationState backupPolicyMigrationState)
27+
{
28+
Status = backupPolicyMigrationState.Status;
29+
TargetType = backupPolicyMigrationState.TargetType;
30+
StartTime = backupPolicyMigrationState.StartTime;
31+
}
32+
33+
//
34+
// Summary:
35+
// Gets or sets describes the status of migration between backup policy types. Possible
36+
// values include: 'Invalid', 'InProgress', 'Completed', 'Failed'
37+
public string Status { get; set; }
38+
//
39+
// Summary:
40+
// Gets or sets describes the target backup policy type of the backup policy migration.
41+
// Possible values include: 'Periodic', 'Continuous'
42+
public string TargetType { get; set; }
43+
//
44+
// Summary:
45+
// Gets or sets time at which the backup policy migration started (ISO-8601 format).
46+
public DateTime? StartTime { get; set; }
47+
48+
public BackupPolicyMigrationState ToSDKModel()
49+
{
50+
BackupPolicyMigrationState backupPolicyMigrationState = new BackupPolicyMigrationState
51+
{
52+
StartTime = StartTime,
53+
Status = Status,
54+
TargetType = TargetType
55+
};
56+
57+
return backupPolicyMigrationState;
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)