Skip to content

RP support for mercury #385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: mercury_dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
using System;
using System.Collections.Generic;
using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;

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

else if (rp.Properties.GetType().IsSubclassOf(typeof(ServiceClientModel.AzureWorkloadRecoveryPoint)))
{
result.Add(GetPSAzureWorkloadRecoveryPoint(rp, item));
}

else if (rp.Properties.GetType() == typeof(ServiceClientModel.GenericRecoveryPoint))
{
result.Add(GetPSAzureGenericRecoveryPoint(rp, item));
Expand Down Expand Up @@ -92,6 +97,11 @@ public static RecoveryPointBase GetPSAzureRecoveryPoints(
result = GetPSAzureFileRecoveryPoint(rpResponse, item);
}

else if (rpResponse.Properties.GetType().IsSubclassOf(typeof(ServiceClientModel.AzureWorkloadRecoveryPoint)))
{
result = GetPSAzureWorkloadRecoveryPoint(rpResponse, item);
}

else if (rpResponse.Properties.GetType() ==
typeof(ServiceClientModel.GenericRecoveryPoint))
{
Expand Down Expand Up @@ -203,6 +213,45 @@ public static RecoveryPointBase GetPSAzureFileRecoveryPoint(
return rpBase;
}

public static RecoveryPointBase GetPSAzureWorkloadRecoveryPoint(
ServiceClientModel.RecoveryPointResource rp, ItemBase item)
{
Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id);
string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, item.Id);

string containerName = IdUtils.GetNameFromUri(containerUri);
string protectedItemName = IdUtils.GetNameFromUri(protectedItemUri);

ServiceClientModel.AzureWorkloadRecoveryPoint recoveryPoint =
rp.Properties as ServiceClientModel.AzureWorkloadRecoveryPoint;

DateTime recoveryPointTime = DateTime.MinValue;

if (recoveryPoint.RecoveryPointTimeInUTC.HasValue)
{
recoveryPointTime = (DateTime)recoveryPoint.RecoveryPointTimeInUTC;
}
else
{
throw new ArgumentNullException("RecoveryPointTime is null");
}

AzureWorkloadRecoveryPoint rpBase = new AzureWorkloadRecoveryPoint()
{
RecoveryPointId = rp.Name,
BackupManagementType = item.BackupManagementType,
ItemName = protectedItemName,
ContainerName = containerName,
ContainerType = item.ContainerType,
RecoveryPointTime = recoveryPointTime,
RecoveryPointType = recoveryPoint.Type,
Id = rp.Id,
WorkloadType = item.WorkloadType,
};
return rpBase;
}

public static RecoveryPointBase GetPSAzureGenericRecoveryPoint(
ServiceClientModel.RecoveryPointResource rp, ItemBase item)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public static string GetServiceClientProviderType(CmdletModel.WorkloadType workl
case CmdletModel.WorkloadType.AzureFiles:
providerType = ServiceClientModel.BackupManagementType.AzureStorage.ToString();
break;
case CmdletModel.WorkloadType.MSSQL:
providerType = ServiceClientModel.BackupManagementType.AzureWorkload.ToString();
break;
default:
break;
}
Expand Down Expand Up @@ -353,4 +356,4 @@ public static string GetServiceClientWorkloadType(CmdletModel.WorkloadType workl
return serviceClientWorkloadType;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
{
/// <summary>
/// Azure workload specific recovery point class.
/// </summary>
public class AzureWorkloadRecoveryPoint : AzureRecoveryPoint
{
public AzureWorkloadRecoveryPoint()
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public enum RecoveryPointParams
TargetLocation,
KeyFileDownloadLocation,
FileDownloadLocation,
RestorePointQueryType
}

public enum RestoreBackupItemParams
Expand All @@ -70,6 +71,16 @@ public enum RestoreFSBackupItemParams
TargetFolder
}

public enum WorkloadRecoveryConfigParams
{
PointInTime,
RecoveryPoint,
OriginalWorkloadRestore,
Item,
TargetFileShareName,
TargetFolder
}

public enum PolicyParams
{
WorkloadType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ public enum ContainerType
/// <summary>
/// Represents any Azure Storage containers.
/// </summary>
AzureStorage
AzureStorage,

/// <summary>
/// Represents any Azure Workload containers.
/// </summary>
AzureWorkload
}

/// <summary>
Expand Down Expand Up @@ -70,6 +75,7 @@ public enum BackupManagementType
/// Represents Azure File Storage. https://docs.microsoft.com/en-in/azure/storage/files/storage-files-introduction
/// </summary>
AzureStorage,
AzureWorkload,
}

/// <summary>
Expand Down Expand Up @@ -103,6 +109,7 @@ public enum WorkloadType
/// Represents Azure File https://docs.microsoft.com/en-in/azure/storage/files/storage-files-introduction
/// </summary>
AzureFiles,
MSSQL,
}

/// <summary>
Expand Down Expand Up @@ -134,6 +141,7 @@ public enum PsBackupProviderTypes
/// Represents the Azure File provider for powershell cmdlets.
/// </summary>
AzureFiles,
AzureWorkload,
}

/// <summary>
Expand Down Expand Up @@ -334,4 +342,4 @@ public enum SourceFileType
File,
Directory
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ public static BackupManagementType GetPsBackupManagementType(string backupManage
return BackupManagementType.AzureSQL;
case ServiceClientModel.BackupManagementType.AzureStorage:
return BackupManagementType.AzureStorage;
case ServiceClientModel.BackupManagementType.AzureWorkload:
return BackupManagementType.AzureWorkload;
default:
throw new Exception("Unsupported BackupManagmentType: " + backupManagementType);
}
Expand Down Expand Up @@ -248,6 +250,11 @@ public static ContainerType GetPsContainerType(string containerType)
{
return ContainerType.AzureStorage;
}
else if (containerType ==
ServiceClientModel.BackupManagementType.AzureWorkload)
{
return ContainerType.AzureWorkload;
}
else
{
throw new Exception("Unsupported ContainerType: " + containerType);
Expand All @@ -265,14 +272,18 @@ public static WorkloadType GetPsWorkloadType(string workloadType)
{
return WorkloadType.AzureVM;
}
if (workloadType == ServiceClientModel.WorkloadType.AzureSqlDb.ToString())
else if (workloadType == ServiceClientModel.WorkloadType.AzureSqlDb.ToString())
{
return WorkloadType.AzureSQLDatabase;
}
if (workloadType == ServiceClientModel.WorkloadType.AzureFileShare)
else if (workloadType == ServiceClientModel.WorkloadType.AzureFileShare)
{
return WorkloadType.AzureFiles;
}
else if (workloadType == ServiceClientModel.WorkloadType.SQLDataBase)
{
return WorkloadType.MSSQL;
}
else
{
throw new Exception("Unsupported WorkloadType: " + workloadType);
Expand All @@ -290,14 +301,18 @@ public static string GetServiceClientWorkloadType(string workloadType)
{
return ServiceClientModel.WorkloadType.VM;
}
if (workloadType == WorkloadType.AzureSQLDatabase.ToString())
else if (workloadType == WorkloadType.AzureSQLDatabase.ToString())
{
return ServiceClientModel.WorkloadType.AzureSqlDb;
}
if (workloadType == WorkloadType.AzureFiles.ToString())
else if (workloadType == WorkloadType.AzureFiles.ToString())
{
return ServiceClientModel.WorkloadType.AzureFileShare;
}
else if (workloadType == WorkloadType.MSSQL.ToString())
{
return ServiceClientModel.WorkloadType.SQLDataBase;
}
else
{
throw new Exception("Unsupported WorkloadType: " + workloadType);
Expand Down Expand Up @@ -343,4 +358,4 @@ public static string GetWorkloadTypeFromArmType(string armType)
throw new Exception("Unsupported ArmType: " + armType);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
Expand Down Expand Up @@ -291,17 +292,18 @@ public void CopyScheduleTimeToRetentionTimes(CmdletModel.LongTermRetentionPolicy
}
}

public List<CmdletModel.RecoveryPointBase> ListRecoveryPoints(Dictionary<Enum, object> ProviderData)
public List<RecoveryPointBase> ListRecoveryPoints(Dictionary<Enum, object> ProviderData)
{
string vaultName = (string)ProviderData[CmdletModel.VaultParams.VaultName];
string resourceGroupName = (string)ProviderData[CmdletModel.VaultParams.ResourceGroupName];
DateTime startDate = (DateTime)(ProviderData[CmdletModel.RecoveryPointParams.StartDate]);
DateTime endDate = (DateTime)(ProviderData[CmdletModel.RecoveryPointParams.EndDate]);
string vaultName = (string)ProviderData[VaultParams.VaultName];
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
DateTime startDate = (DateTime)(ProviderData[RecoveryPointParams.StartDate]);
DateTime endDate = (DateTime)(ProviderData[RecoveryPointParams.EndDate]);
string restorePointQueryType = ProviderData.ContainsKey(RecoveryPointParams.RestorePointQueryType) ?
(string)ProviderData[RecoveryPointParams.RestorePointQueryType] : "All";

CmdletModel.ItemBase item = ProviderData[CmdletModel.RecoveryPointParams.Item]
as CmdletModel.ItemBase;
ItemBase item = ProviderData[RecoveryPointParams.Item] as ItemBase;

Dictionary<CmdletModel.UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id);
string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);

Expand All @@ -315,7 +317,8 @@ public void CopyScheduleTimeToRetentionTimes(CmdletModel.LongTermRetentionPolicy
var queryFilterString = QueryBuilder.Instance.GetQueryString(new BMSRPQueryObject()
{
StartDate = startDate,
EndDate = endDate
EndDate = endDate,
RestorePointQueryType = restorePointQueryType
});

ODataQuery<BMSRPQueryObject> queryFilter = new ODataQuery<BMSRPQueryObject>();
Expand All @@ -330,16 +333,70 @@ public void CopyScheduleTimeToRetentionTimes(CmdletModel.LongTermRetentionPolicy
return RecoveryPointConversions.GetPSAzureRecoveryPoints(rpListResponse, item);
}

public CmdletModel.RecoveryPointBase GetRecoveryPointDetails(Dictionary<Enum, object> ProviderData)
public List<PointInTimeRange> ListLogChains(Dictionary<Enum, object> ProviderData)
{
string vaultName = (string)ProviderData[CmdletModel.VaultParams.VaultName];
string resourceGroupName = (string)ProviderData[CmdletModel.VaultParams.ResourceGroupName];
CmdletModel.ItemBase item = ProviderData[CmdletModel.RecoveryPointParams.Item]
as CmdletModel.ItemBase;
string vaultName = (string)ProviderData[VaultParams.VaultName];
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
DateTime startDate = (DateTime)(ProviderData[RecoveryPointParams.StartDate]);
DateTime endDate = (DateTime)(ProviderData[RecoveryPointParams.EndDate]);
string restorePointQueryType = (string)ProviderData[RecoveryPointParams.RestorePointQueryType];

string recoveryPointId = ProviderData[CmdletModel.RecoveryPointParams.RecoveryPointId].ToString();
ItemBase item = ProviderData[RecoveryPointParams.Item] as ItemBase;

Dictionary<CmdletModel.UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id);
string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);

TimeSpan duration = endDate - startDate;
if (duration.TotalDays > 30)
{
throw new Exception(Resources.RestoreDiskTimeRangeError);
}

//we need to fetch the list of RPs
var queryFilterString = QueryBuilder.Instance.GetQueryString(new BMSRPQueryObject()
{
StartDate = startDate,
EndDate = endDate,
RestorePointQueryType = restorePointQueryType
});

ODataQuery<BMSRPQueryObject> queryFilter = new ODataQuery<BMSRPQueryObject>();
queryFilter.Filter = queryFilterString;

List<RecoveryPointResource> rpListResponse = ServiceClientAdapter.GetRecoveryPoints(
containerUri,
protectedItemName,
queryFilter,
vaultName: vaultName,
resourceGroupName: resourceGroupName);

List<PointInTimeRange> timeRanges = new List<PointInTimeRange>();
foreach (RecoveryPointResource rp in rpListResponse)
{
if (rp.Properties.GetType() == typeof(AzureWorkloadSQLPointInTimeRecoveryPoint))
{
AzureWorkloadSQLPointInTimeRecoveryPoint recoveryPoint =
rp.Properties as AzureWorkloadSQLPointInTimeRecoveryPoint;
foreach (PointInTimeRange timeRange in recoveryPoint.TimeRanges)
{
timeRanges.Add(timeRange);
}
}

}
return timeRanges;
}

public RecoveryPointBase GetRecoveryPointDetails(Dictionary<Enum, object> ProviderData)
{
string vaultName = (string)ProviderData[VaultParams.VaultName];
string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
ItemBase item = ProviderData[RecoveryPointParams.Item] as ItemBase;

string recoveryPointId = ProviderData[RecoveryPointParams.RecoveryPointId].ToString();

Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id);
string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);

Expand Down
Loading