Skip to content

Commit 012860a

Browse files
committed
RP support for mercury
1 parent 8560b30 commit 012860a

File tree

16 files changed

+438
-30
lines changed

16 files changed

+438
-30
lines changed

src/RecoveryServices/RecoveryServices.Backup.Helpers/Conversions/RecoveryPointConversions.cs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System;
16-
using System.Collections.Generic;
1715
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
1816
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
17+
using System;
18+
using System.Collections.Generic;
1919
using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;
2020

2121
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers
@@ -57,6 +57,11 @@ public static List<RecoveryPointBase> GetPSAzureRecoveryPoints(
5757
result.Add(GetPSAzureFileRecoveryPoint(rp, item));
5858
}
5959

60+
else if (rp.Properties.GetType().IsSubclassOf(typeof(ServiceClientModel.AzureWorkloadRecoveryPoint)))
61+
{
62+
result.Add(GetPSAzureWorkloadRecoveryPoint(rp, item));
63+
}
64+
6065
else if (rp.Properties.GetType() == typeof(ServiceClientModel.GenericRecoveryPoint))
6166
{
6267
result.Add(GetPSAzureGenericRecoveryPoint(rp, item));
@@ -92,6 +97,11 @@ public static RecoveryPointBase GetPSAzureRecoveryPoints(
9297
result = GetPSAzureFileRecoveryPoint(rpResponse, item);
9398
}
9499

100+
else if (rpResponse.Properties.GetType().IsSubclassOf(typeof(ServiceClientModel.AzureWorkloadRecoveryPoint)))
101+
{
102+
result = GetPSAzureWorkloadRecoveryPoint(rpResponse, item);
103+
}
104+
95105
else if (rpResponse.Properties.GetType() ==
96106
typeof(ServiceClientModel.GenericRecoveryPoint))
97107
{
@@ -203,6 +213,45 @@ public static RecoveryPointBase GetPSAzureFileRecoveryPoint(
203213
return rpBase;
204214
}
205215

216+
public static RecoveryPointBase GetPSAzureWorkloadRecoveryPoint(
217+
ServiceClientModel.RecoveryPointResource rp, ItemBase item)
218+
{
219+
Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
220+
string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id);
221+
string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, item.Id);
222+
223+
string containerName = IdUtils.GetNameFromUri(containerUri);
224+
string protectedItemName = IdUtils.GetNameFromUri(protectedItemUri);
225+
226+
ServiceClientModel.AzureWorkloadRecoveryPoint recoveryPoint =
227+
rp.Properties as ServiceClientModel.AzureWorkloadRecoveryPoint;
228+
229+
DateTime recoveryPointTime = DateTime.MinValue;
230+
231+
if (recoveryPoint.RecoveryPointTimeInUTC.HasValue)
232+
{
233+
recoveryPointTime = (DateTime)recoveryPoint.RecoveryPointTimeInUTC;
234+
}
235+
else
236+
{
237+
throw new ArgumentNullException("RecoveryPointTime is null");
238+
}
239+
240+
AzureWorkloadRecoveryPoint rpBase = new AzureWorkloadRecoveryPoint()
241+
{
242+
RecoveryPointId = rp.Name,
243+
BackupManagementType = item.BackupManagementType,
244+
ItemName = protectedItemName,
245+
ContainerName = containerName,
246+
ContainerType = item.ContainerType,
247+
RecoveryPointTime = recoveryPointTime,
248+
RecoveryPointType = recoveryPoint.Type,
249+
Id = rp.Id,
250+
WorkloadType = item.WorkloadType,
251+
};
252+
return rpBase;
253+
}
254+
206255
public static RecoveryPointBase GetPSAzureGenericRecoveryPoint(
207256
ServiceClientModel.RecoveryPointResource rp, ItemBase item)
208257
{

src/RecoveryServices/RecoveryServices.Backup.Models/CmdletParamEnums.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public enum RecoveryPointParams
4545
TargetLocation,
4646
KeyFileDownloadLocation,
4747
FileDownloadLocation,
48+
RestorePointQueryType
4849
}
4950

5051
public enum RestoreBackupItemParams

src/RecoveryServices/RecoveryServices.Backup.Providers/AzureWorkloadProviderHelper.cs

Lines changed: 73 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
1516
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS;
1617
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
1718
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
@@ -317,17 +318,18 @@ public void CopyScheduleTimeToRetentionTimes(CmdletModel.LongTermRetentionPolicy
317318
}
318319
}
319320

320-
public List<CmdletModel.RecoveryPointBase> ListRecoveryPoints(Dictionary<Enum, object> ProviderData)
321+
public List<RecoveryPointBase> ListRecoveryPoints(Dictionary<Enum, object> ProviderData)
321322
{
322-
string vaultName = (string)ProviderData[CmdletModel.VaultParams.VaultName];
323-
string resourceGroupName = (string)ProviderData[CmdletModel.VaultParams.ResourceGroupName];
324-
DateTime startDate = (DateTime)(ProviderData[CmdletModel.RecoveryPointParams.StartDate]);
325-
DateTime endDate = (DateTime)(ProviderData[CmdletModel.RecoveryPointParams.EndDate]);
323+
string vaultName = (string)ProviderData[VaultParams.VaultName];
324+
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
325+
DateTime startDate = (DateTime)(ProviderData[RecoveryPointParams.StartDate]);
326+
DateTime endDate = (DateTime)(ProviderData[RecoveryPointParams.EndDate]);
327+
string restorePointQueryType = ProviderData.ContainsKey(RecoveryPointParams.RestorePointQueryType) ?
328+
(string)ProviderData[RecoveryPointParams.RestorePointQueryType] : "All";
326329

327-
CmdletModel.ItemBase item = ProviderData[CmdletModel.RecoveryPointParams.Item]
328-
as CmdletModel.ItemBase;
330+
ItemBase item = ProviderData[RecoveryPointParams.Item] as ItemBase;
329331

330-
Dictionary<CmdletModel.UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
332+
Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
331333
string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id);
332334
string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);
333335

@@ -341,7 +343,8 @@ public void CopyScheduleTimeToRetentionTimes(CmdletModel.LongTermRetentionPolicy
341343
var queryFilterString = QueryBuilder.Instance.GetQueryString(new BMSRPQueryObject()
342344
{
343345
StartDate = startDate,
344-
EndDate = endDate
346+
EndDate = endDate,
347+
RestorePointQueryType = restorePointQueryType
345348
});
346349

347350
ODataQuery<BMSRPQueryObject> queryFilter = new ODataQuery<BMSRPQueryObject>();
@@ -356,16 +359,70 @@ public void CopyScheduleTimeToRetentionTimes(CmdletModel.LongTermRetentionPolicy
356359
return RecoveryPointConversions.GetPSAzureRecoveryPoints(rpListResponse, item);
357360
}
358361

359-
public CmdletModel.RecoveryPointBase GetRecoveryPointDetails(Dictionary<Enum, object> ProviderData)
362+
public List<PointInTimeRange> ListLogChains(Dictionary<Enum, object> ProviderData)
360363
{
361-
string vaultName = (string)ProviderData[CmdletModel.VaultParams.VaultName];
362-
string resourceGroupName = (string)ProviderData[CmdletModel.VaultParams.ResourceGroupName];
363-
CmdletModel.ItemBase item = ProviderData[CmdletModel.RecoveryPointParams.Item]
364-
as CmdletModel.ItemBase;
364+
string vaultName = (string)ProviderData[VaultParams.VaultName];
365+
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
366+
DateTime startDate = (DateTime)(ProviderData[RecoveryPointParams.StartDate]);
367+
DateTime endDate = (DateTime)(ProviderData[RecoveryPointParams.EndDate]);
368+
string restorePointQueryType = (string)ProviderData[RecoveryPointParams.RestorePointQueryType];
365369

366-
string recoveryPointId = ProviderData[CmdletModel.RecoveryPointParams.RecoveryPointId].ToString();
370+
ItemBase item = ProviderData[RecoveryPointParams.Item] as ItemBase;
367371

368-
Dictionary<CmdletModel.UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
372+
Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
373+
string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id);
374+
string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);
375+
376+
TimeSpan duration = endDate - startDate;
377+
if (duration.TotalDays > 30)
378+
{
379+
throw new Exception(Resources.RestoreDiskTimeRangeError);
380+
}
381+
382+
//we need to fetch the list of RPs
383+
var queryFilterString = QueryBuilder.Instance.GetQueryString(new BMSRPQueryObject()
384+
{
385+
StartDate = startDate,
386+
EndDate = endDate,
387+
RestorePointQueryType = restorePointQueryType
388+
});
389+
390+
ODataQuery<BMSRPQueryObject> queryFilter = new ODataQuery<BMSRPQueryObject>();
391+
queryFilter.Filter = queryFilterString;
392+
393+
List<RecoveryPointResource> rpListResponse = ServiceClientAdapter.GetRecoveryPoints(
394+
containerUri,
395+
protectedItemName,
396+
queryFilter,
397+
vaultName: vaultName,
398+
resourceGroupName: resourceGroupName);
399+
400+
List<PointInTimeRange> timeRanges = new List<PointInTimeRange>();
401+
foreach (RecoveryPointResource rp in rpListResponse)
402+
{
403+
if (rp.Properties.GetType() == typeof(AzureWorkloadSQLPointInTimeRecoveryPoint))
404+
{
405+
AzureWorkloadSQLPointInTimeRecoveryPoint recoveryPoint =
406+
rp.Properties as AzureWorkloadSQLPointInTimeRecoveryPoint;
407+
foreach (PointInTimeRange timeRange in recoveryPoint.TimeRanges)
408+
{
409+
timeRanges.Add(timeRange);
410+
}
411+
}
412+
413+
}
414+
return timeRanges;
415+
}
416+
417+
public RecoveryPointBase GetRecoveryPointDetails(Dictionary<Enum, object> ProviderData)
418+
{
419+
string vaultName = (string)ProviderData[VaultParams.VaultName];
420+
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
421+
ItemBase item = ProviderData[RecoveryPointParams.Item] as ItemBase;
422+
423+
string recoveryPointId = ProviderData[RecoveryPointParams.RecoveryPointId].ToString();
424+
425+
Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
369426
string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id);
370427
string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);
371428

src/RecoveryServices/RecoveryServices.Backup.Providers/IPsBackupProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,7 @@ public interface IPsBackupProvider
6262
void RevokeItemLevelRecoveryAccess();
6363

6464
void RegisterContainer();
65+
66+
List<PointInTimeRange> GetLogChains();
6567
}
6668
}

src/RecoveryServices/RecoveryServices.Backup.Providers/Providers/AzureFilesPsBackupProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,5 +918,10 @@ private void ValidateLocationRestoreRequest(string targetFileShareName, string t
918918
throw new ArgumentException(string.Format(Resources.AzureFileTargetSANameMissingException));
919919
}
920920
}
921+
922+
public List<PointInTimeRange> GetLogChains()
923+
{
924+
throw new NotImplementedException();
925+
}
921926
}
922927
}

src/RecoveryServices/RecoveryServices.Backup.Providers/Providers/AzureSqlPsBackupProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,11 @@ public void RegisterContainer()
490490
throw new NotImplementedException();
491491
}
492492

493+
public List<PointInTimeRange> GetLogChains()
494+
{
495+
throw new NotImplementedException();
496+
}
497+
493498
#region private
494499
private void ValidateAzureSqlWorkloadType(CmdletModel.WorkloadType type)
495500
{

src/RecoveryServices/RecoveryServices.Backup.Providers/Providers/AzureWorkloadPsBackupProvider.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
using System.Collections.Generic;
2020
using CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
2121
using RestAzureNS = Microsoft.Rest.Azure;
22-
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
23-
using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;
24-
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
2522

2623
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel
2724
{
@@ -87,7 +84,7 @@ public ProtectedItemResource GetProtectedItem()
8784

8885
public RecoveryPointBase GetRecoveryPointDetails()
8986
{
90-
throw new NotImplementedException();
87+
return AzureWorkloadProviderHelper.GetRecoveryPointDetails(ProviderData);
9188
}
9289

9390
public List<CmdletModel.BackupEngineBase> ListBackupManagementServers()
@@ -107,7 +104,7 @@ public List<ContainerBase> ListProtectionContainers()
107104

108105
public List<RecoveryPointBase> ListRecoveryPoints()
109106
{
110-
throw new NotImplementedException();
107+
return AzureWorkloadProviderHelper.ListRecoveryPoints(ProviderData);
111108
}
112109

113110
public RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> ModifyPolicy()
@@ -134,5 +131,10 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
134131
{
135132
throw new NotImplementedException();
136133
}
134+
135+
public List<PointInTimeRange> GetLogChains()
136+
{
137+
return AzureWorkloadProviderHelper.ListLogChains(ProviderData);
138+
}
137139
}
138140
}

src/RecoveryServices/RecoveryServices.Backup.Providers/Providers/DpmPsBackupProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,10 @@ public void RegisterContainer()
159159
{
160160
throw new NotImplementedException();
161161
}
162+
163+
public List<ServiceClientModel.PointInTimeRange> GetLogChains()
164+
{
165+
throw new NotImplementedException();
166+
}
162167
}
163168
}

src/RecoveryServices/RecoveryServices.Backup.Providers/Providers/IaasVmPsBackupProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,11 @@ private bool ShouldUseOsa(AzureVmRecoveryPoint rp, bool osaOption)
12391239
return useOsa;
12401240
}
12411241

1242+
public List<PointInTimeRange> GetLogChains()
1243+
{
1244+
throw new NotImplementedException();
1245+
}
1246+
12421247
#endregion
12431248
}
12441249
}

src/RecoveryServices/RecoveryServices.Backup.Providers/Providers/MabPsBackupProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,10 @@ public void RegisterContainer()
162162
{
163163
throw new NotImplementedException();
164164
}
165+
166+
public List<PointInTimeRange> GetLogChains()
167+
{
168+
throw new NotImplementedException();
169+
}
165170
}
166171
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
18+
using Xunit;
19+
20+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Test.ScenarioTests
21+
{
22+
public partial class ItemTests : RMTestBase
23+
{
24+
[Fact]
25+
[Trait(Category.AcceptanceType, Category.CheckIn)]
26+
[Trait(TestConstants.Workload, TestConstants.AzureWorkload)]
27+
public void TestAzureWorkloadGetRPs()
28+
{
29+
TestController.NewInstance.RunPsTest(
30+
_logger, PsBackupProviderTypes.AzureWorkload, "Test-AzureWorkloadGetRPs");
31+
}
32+
33+
[Fact]
34+
[Trait(Category.AcceptanceType, Category.CheckIn)]
35+
[Trait(TestConstants.Workload, TestConstants.AzureWorkload)]
36+
public void TestAzureWorkloadGetLogChains()
37+
{
38+
TestController.NewInstance.RunPsTest(
39+
_logger, PsBackupProviderTypes.AzureWorkload, "Test-AzureWorkloadGetLogChains");
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)