Skip to content

Commit

Permalink
Container support for mercury
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharth7 committed Dec 26, 2018
1 parent 1ac99e4 commit 29a7e09
Show file tree
Hide file tree
Showing 24 changed files with 806 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public static ContainerBase GetContainerModel(ServiceClientModel.ProtectionConta
{
containerModel = new AzureFileShareContainer(protectionContainer);
}
else if (protectionContainer.Properties.GetType() ==
typeof(ServiceClientModel.AzureVMAppContainerProtectionContainer))
{
containerModel = new AzureWorkloadContainer(protectionContainer);
}
}

return containerModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ public static string GetServiceClientWorkloadType(CmdletModel.WorkloadType workl
case CmdletModel.WorkloadType.AzureVM:
serviceClientWorkloadType = ServiceClientModel.WorkloadType.VM.ToString();
break;
case CmdletModel.WorkloadType.MSSQL:
serviceClientWorkloadType = ServiceClientModel.WorkloadType.SQLDataBase.ToString();
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// ----------------------------------------------------------------------------------
//
// 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.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Management.RecoveryServices.Backup.Models;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
{
/// <summary>
/// Azure Workload specific container class.
/// </summary>
public class AzureWorkloadContainer : AzureContainer
{
/// <summary>
/// Constructor. Takes the service client object representing the container
/// and converts it in to the PS container model
/// </summary>
/// <param name="protectionContainerResource">Service client object representing the container</param>
public AzureWorkloadContainer(ProtectionContainerResource protectionContainerResource)
: base(protectionContainerResource) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public enum ContainerType
AzureStorage,

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

/// <summary>
/// Represents Azure Workload
/// </summary>
AzureWorkload
}

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

/// <summary>
/// Represents MSSQL in Azure VM.
/// </summary>
MSSQL,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ public void RefreshContainer(string vaultName = null, string vaultResourceGroupN
}
}

public void RegisterContainer(string storageAccountName,
public void RegisterContainer(string containerName,
ProtectionContainerResource protectionContainerResource,
string vaultName, string vaultResourceGroupName)
{
var registerResponse = ServiceClientAdapter.RegisterContainer(
storageAccountName,
containerName,
protectionContainerResource,
vaultName,
vaultResourceGroupName);
Expand All @@ -79,7 +79,7 @@ public void RegisterContainer(string storageAccountName,
operationId =>
ServiceClientAdapter.GetRegisterContainerOperationResult(
operationId,
storageAccountName,
containerName,
vaultName: vaultName,
resourceGroupName: vaultResourceGroupName));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,7 @@ public interface IPsBackupProvider
RPMountScriptDetails ProvisionItemLevelRecoveryAccess();

void RevokeItemLevelRecoveryAccess();

void RegisterContainer();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
using Microsoft.Azure.Management.Internal.Resources.Models;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using Microsoft.Rest.Azure.OData;
using System;
Expand Down Expand Up @@ -700,6 +699,11 @@ public List<ItemBase> ListProtectedItems()
return itemModels;
}

public void RegisterContainer()
{
throw new NotImplementedException();
}

private RestAzureNS.AzureOperationResponse EnableOrModifyProtection(bool disableWithRetentionData = false)
{
string vaultName = (string)ProviderData[VaultParams.VaultName];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,11 @@ public List<ItemBase> ListProtectedItems()
return itemModels;
}

public void RegisterContainer()
{
throw new NotImplementedException();
}

#region private
private void ValidateAzureSqlWorkloadType(CmdletModel.WorkloadType type)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@

using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using Microsoft.Rest.Azure.OData;
using System;
using System.Collections.Generic;
using System.Linq;
using CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using RestAzureNS = Microsoft.Rest.Azure;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel
{
Expand All @@ -35,9 +36,13 @@ public class AzureWorkloadPsBackupProvider : IPsBackupProvider
private const CmdletModel.RetentionDurationType defaultFileRetentionType =
CmdletModel.RetentionDurationType.Days;
private const int defaultFileRetentionCount = 30;

Dictionary<Enum, object> ProviderData { get; set; }

ServiceClientAdapter ServiceClientAdapter { get; set; }

AzureWorkloadProviderHelper AzureWorkloadProviderHelper { get; set; }

/// <summary>
/// Initializes the provider with the data recieved from the cmdlet layer
/// </summary>
Expand Down Expand Up @@ -102,7 +107,18 @@ public List<ItemBase> ListProtectedItems()

public List<ContainerBase> ListProtectionContainers()
{
throw new NotImplementedException();
CmdletModel.BackupManagementType? backupManagementTypeNullable =
(CmdletModel.BackupManagementType?)
ProviderData[ContainerParams.BackupManagementType];

if (backupManagementTypeNullable.HasValue)
{
ValidateAzureWorkloadBackupManagementType(backupManagementTypeNullable.Value);
}

return AzureWorkloadProviderHelper.ListProtectionContainers(
ProviderData,
ServiceClientModel.BackupManagementType.AzureWorkload);
}

public List<RecoveryPointBase> ListRecoveryPoints()
Expand Down Expand Up @@ -134,5 +150,71 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
{
throw new NotImplementedException();
}

private void ValidateAzureWorkloadBackupManagementType(
CmdletModel.BackupManagementType backupManagementType)
{
if (backupManagementType != CmdletModel.BackupManagementType.AzureWorkload)
{
throw new ArgumentException(string.Format(Resources.UnExpectedBackupManagementTypeException,
CmdletModel.BackupManagementType.AzureWorkload.ToString(),
backupManagementType.ToString()));
}
}

public void RegisterContainer()
{
string vaultName = (string)ProviderData[VaultParams.VaultName];
string vaultResourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
string containerName = (string)ProviderData[ContainerParams.Name];
string backupManagementType = (string)ProviderData[ContainerParams.BackupManagementType];
string workloadType = (string)ProviderData[ContainerParams.ContainerType];

//Trigger Discovery
ODataQuery<BMSRefreshContainersQueryObject> queryParam = new ODataQuery<BMSRefreshContainersQueryObject>(
q => q.BackupManagementType
== ServiceClientModel.BackupManagementType.AzureWorkload);
AzureWorkloadProviderHelper.RefreshContainer(vaultName, vaultResourceGroupName, queryParam);

List<ProtectableContainerResource> unregisteredVmContainers =
GetUnRegisteredVmContainers(vaultName, vaultResourceGroupName);
ProtectableContainerResource unregisteredVmContainer = unregisteredVmContainers.Find(
vmContainer => string.Compare(vmContainer.Name.Split(';').Last(),
containerName, true) == 0);

if (unregisteredVmContainer != null)
{
ProtectionContainerResource protectionContainerResource =
new ProtectionContainerResource(unregisteredVmContainer.Id,
unregisteredVmContainer.Name);
AzureVMAppContainerProtectionContainer azureVMContainer = new AzureVMAppContainerProtectionContainer(
friendlyName: containerName,
backupManagementType: backupManagementType,
sourceResourceId: unregisteredVmContainer.Properties.ContainerId,
workloadType: workloadType.ToString());
protectionContainerResource.Properties = azureVMContainer;

AzureWorkloadProviderHelper.RegisterContainer(unregisteredVmContainer.Name,
protectionContainerResource,
vaultName,
vaultResourceGroupName);
}
}

private List<ProtectableContainerResource> GetUnRegisteredVmContainers(string vaultName = null,
string vaultResourceGroupName = null)
{
ODataQuery<BMSContainerQueryObject> queryParams = null;
queryParams = new ODataQuery<BMSContainerQueryObject>(
q => q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureWorkload);

var listResponse = ServiceClientAdapter.ListUnregisteredContainers(
queryParams,
vaultName: vaultName,
resourceGroupName: vaultResourceGroupName);
List<ProtectableContainerResource> containerModels = listResponse.ToList();

return containerModels;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,10 @@ public List<ItemBase> ListProtectedItems()
{
throw new NotImplementedException();
}

public void RegisterContainer()
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
using Microsoft.Azure.Management.Internal.Resources.Models;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using Microsoft.Rest.Azure.OData;
using System;
Expand Down Expand Up @@ -812,7 +811,10 @@ public RetentionPolicyBase GetDefaultRetentionPolicyObject()
return defaultRetention;

}

public void RegisterContainer()
{
throw new NotImplementedException();
}

#region private

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,10 @@ public List<ItemBase> ListProtectedItems()
{
throw new NotImplementedException();
}

public void RegisterContainer()
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ public IPsBackupProvider GetProviderInstance
containerType));
}
break;
case ContainerType.AzureWorkload:
if (backupManagementType == BackupManagementType.AzureWorkload ||
backupManagementType == null)
{
providerType = PsBackupProviderTypes.AzureWorkload;
}
else
{
throw new ArgumentException(
string.Format(
Resources.BackupManagementTypeRequiredForContainerType,
containerType));
}
break;
default:
throw new ArgumentException(
string.Format(Resources.UnsupportedContainerType,
Expand Down Expand Up @@ -155,6 +169,9 @@ public IPsBackupProvider GetProviderInstance(WorkloadType workloadType)
case WorkloadType.AzureFiles:
providerType = PsBackupProviderTypes.AzureFiles;
break;
case WorkloadType.MSSQL:
providerType = PsBackupProviderTypes.AzureWorkload;
break;
default:
throw new ArgumentException(
string.Format(Resources.BackupManagementTypeRequiredForWorkloadType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using Microsoft.Rest.Azure.OData;
using System;
using System.Collections.Generic;
using RestAzureNS = Microsoft.Rest.Azure;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS
Expand Down
Loading

0 comments on commit 29a7e09

Please sign in to comment.