Skip to content

[REBASE] AFS Get-Container #364

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

Merged
merged 2 commits into from
Aug 23, 2018
Merged
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 @@ -41,7 +41,7 @@ public static ContainerBase GetContainerModel(ServiceClientModel.ProtectionConta
{
containerModel = new AzureVmContainer(protectionContainer);
}
if (protectionContainer.Properties.GetType() == typeof(ServiceClientModel.MabContainer))
else if (protectionContainer.Properties.GetType() == typeof(ServiceClientModel.MabContainer))
{
containerModel = new MabContainer(protectionContainer);
}
Expand All @@ -50,6 +50,11 @@ public static ContainerBase GetContainerModel(ServiceClientModel.ProtectionConta
{
containerModel = new AzureSqlContainer(protectionContainer);
}
else if (protectionContainer.Properties.GetType() ==
typeof(ServiceClientModel.AzureStorageContainer))
{
containerModel = new AzureFileShareContainer(protectionContainer);
}
}

return containerModel;
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 File Share specific container class.
/// </summary>
public class AzureFileShareContainer : 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 AzureFileShareContainer(ProtectionContainerResource protectionContainerResource)
: base(protectionContainerResource) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// ----------------------------------------------------------------------------------
//
// 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
{
public class AzureContainer : ContainerBase
{
/// <summary>
/// Resource Group where the Container is present
/// </summary>
public string ResourceGroupName { get; set; }
/// <summary>
/// Friendly name of the container
/// </summary>
public string FriendlyName { get; set; }

/// <summary>
/// Registration Status
/// </summary>
public ContainerRegistrationStatus Status { get; set; }

public AzureContainer(ProtectionContainerResource protectionContainer)
: base(protectionContainer)
{
ResourceGroupName = IdUtils.GetResourceGroupName(protectionContainer.Id);
FriendlyName = protectionContainer.Properties.FriendlyName;
Status = EnumUtils.GetEnum<ContainerRegistrationStatus>(protectionContainer.Properties.RegistrationStatus);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,14 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
/// <summary>
/// Azure VM specific container class.
/// </summary>
public class AzureVmContainer : ContainerBase
public class AzureVmContainer : AzureContainer
{
/// <summary>
/// Resource Group where the Container is present
/// </summary>
public string ResourceGroupName { get; set; }

/// <summary>
/// Friendly name of the container
/// </summary>
public string FriendlyName { get; set; }

/// <summary>
/// Registration Status
/// </summary>
public ContainerRegistrationStatus Status { get; set; }

/// <summary>
/// Constructor. Takes the service client object representing the container
/// and converts it in to the PS container model
/// </summary>
/// <param name="protectionContainer">Service client object representing the container</param>
public AzureVmContainer(ProtectionContainerResource protectionContainer)
: base(protectionContainer)
{
IaaSVMContainer iaasVmProtectionContainer =
(IaaSVMContainer)protectionContainer.Properties;
ResourceGroupName = IdUtils.GetResourceGroupName(protectionContainer.Id);
FriendlyName = iaasVmProtectionContainer.FriendlyName;
Status = EnumUtils.GetEnum<ContainerRegistrationStatus>(iaasVmProtectionContainer.RegistrationStatus);
}
: base(protectionContainer) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
<ItemGroup>
<Compile Include="AzureFileShareModels\AzureFileSharePolicy.cs" />
<Compile Include="AzureFileShareModels\AzureFileShareItem.cs" />
<Compile Include="AzureFileShareModels\AzureFileShareContainer.cs" />
<Compile Include="AzureModels\AzureContainer.cs" />
<Compile Include="AzureSqlModels\AzureSqlContainer.cs" />
<Compile Include="AzureSqlModels\AzureSqlItem.cs" />
<Compile Include="AzureSqlModels\AzureSqlPolicy.cs" />
Expand Down Expand Up @@ -94,9 +96,7 @@
<None Include="packages.config">
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="AzureWorkloadModels\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\..\..\tools\Common.Dependencies.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,52 @@ public void RefreshContainer(string vaultName = null, string resourceGroupName =

return itemModels;
}

public List<CmdletModel.ContainerBase> ListProtectionContainers(
Dictionary<Enum, object> providerData,
string backupManagementType)
{
string vaultName = (string)providerData[CmdletModel.VaultParams.VaultName];
string vaultResourceGroupName = (string)providerData[CmdletModel.VaultParams.ResourceGroupName];
string name = (string)providerData[CmdletModel.ContainerParams.Name];
string friendlyName = (string)providerData[CmdletModel.ContainerParams.FriendlyName];
CmdletModel.ContainerRegistrationStatus status =
(CmdletModel.ContainerRegistrationStatus)providerData[CmdletModel.ContainerParams.Status];

string nameQueryFilter = friendlyName;

if (!string.IsNullOrEmpty(name))
{
Logger.Instance.WriteWarning(Resources.GetContainerNameParamDeprecated);

if (string.IsNullOrEmpty(friendlyName))
{
nameQueryFilter = name;
}
}

ODataQuery<ServiceClientModel.BMSContainerQueryObject> queryParams = null;
if (status == 0)
{
queryParams = new ODataQuery<ServiceClientModel.BMSContainerQueryObject>(
q => q.FriendlyName == nameQueryFilter &&
q.BackupManagementType == backupManagementType);
}
else
{
var statusString = status.ToString();
queryParams = new ODataQuery<ServiceClientModel.BMSContainerQueryObject>(
q => q.FriendlyName == nameQueryFilter &&
q.BackupManagementType == backupManagementType &&
q.Status == statusString);
}

var listResponse = ServiceClientAdapter.ListContainers(
queryParams,
vaultName: vaultName,
resourceGroupName: vaultResourceGroupName);

return ConversionHelpers.GetContainerModelList(listResponse);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Linq;
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 CmdletModel = Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
using RestAzureNS = Microsoft.Rest.Azure;
Expand Down Expand Up @@ -67,8 +68,20 @@ public RestAzureNS.AzureOperationResponse DisableProtection()

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

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

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

public RestAzureNS.AzureOperationResponse TriggerBackup()
{
throw new NotImplementedException();
Expand Down Expand Up @@ -223,5 +236,16 @@ public ResourceBackupStatus CheckBackupStatus()
{
throw new NotImplementedException();
}

private void ValidateAzureStorageBackupManagementType(
CmdletModel.BackupManagementType backupManagementType)
{
if (backupManagementType != CmdletModel.BackupManagementType.AzureStorage)
{
throw new ArgumentException(string.Format(Resources.UnExpectedBackupManagementTypeException,
CmdletModel.BackupManagementType.AzureStorage.ToString(),
backupManagementType.ToString()));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -649,60 +649,21 @@ public RestAzureNS.AzureOperationResponse<ProtectionPolicyResource> ModifyPolicy
/// <returns>List of protection containers</returns>
public List<ContainerBase> ListProtectionContainers()
{
string vaultName = (string)ProviderData[VaultParams.VaultName];
string vaultResourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
CmdletModel.ContainerType containerType =
(CmdletModel.ContainerType)ProviderData[ContainerParams.ContainerType];
string resourceGroupName = (string)ProviderData[ContainerParams.ResourceGroupName];
CmdletModel.BackupManagementType? backupManagementTypeNullable =
(CmdletModel.BackupManagementType?)
ProviderData[ContainerParams.BackupManagementType];
string name = (string)ProviderData[ContainerParams.Name];
string friendlyName = (string)ProviderData[ContainerParams.FriendlyName];
string resourceGroupName = (string)ProviderData[ContainerParams.ResourceGroupName];
ContainerRegistrationStatus status =
(ContainerRegistrationStatus)ProviderData[ContainerParams.Status];

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

string nameQueryFilter = friendlyName;

if (!string.IsNullOrEmpty(name))
{
Logger.Instance.WriteWarning(Resources.GetContainerNameParamDeprecated);

if (string.IsNullOrEmpty(friendlyName))
{
nameQueryFilter = name;
}
}

ODataQuery<BMSContainerQueryObject> queryParams = null;
if (status == 0)
{
queryParams = new ODataQuery<BMSContainerQueryObject>(
q => q.FriendlyName == nameQueryFilter &&
q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureIaasVM);
}
else
{
var statusString = status.ToString();
queryParams = new ODataQuery<BMSContainerQueryObject>(
q => q.FriendlyName == nameQueryFilter &&
q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureIaasVM &&
q.Status == statusString);
}

var listResponse = ServiceClientAdapter.ListContainers(
queryParams,
vaultName: vaultName,
resourceGroupName: vaultResourceGroupName);

List<ContainerBase> containerModels = ConversionHelpers.GetContainerModelList(listResponse);
var containerModels = AzureWorkloadProviderHelper.ListProtectionContainers(
ProviderData,
ServiceClientModel.BackupManagementType.AzureIaasVM);

// 4. Filter by RG Name
// Filter by RG Name
if (!string.IsNullOrEmpty(resourceGroupName))
{
containerModels = containerModels.Where(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ public IPsBackupProvider GetProviderInstance
containerType));
}
break;
case ContainerType.AzureStorage:
if (backupManagementType == BackupManagementType.AzureStorage ||
backupManagementType == null)
{
providerType = PsBackupProviderTypes.AzureFiles;
}
else
{
throw new ArgumentException(
string.Format(
Resources.BackupManagementTypeRequiredForContainerType,
containerType));
}
break;
default:
throw new ArgumentException(
string.Format(Resources.UnsupportedContainerType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,17 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScenarioTests\AzureFiles\ContainerTests.cs" />
<Compile Include="ScenarioTests\AzureFiles\ItemTests.cs" />
<Compile Include="ScenarioTests\AzureFiles\PolicyTests.cs" />
<Compile Include="ScenarioTests\IaasVm\ProtectionCheckTests.cs" />
<Compile Include="TestConstants.cs" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
<None Include="ScenarioTests\AzureFiles\ContainerTests.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="ScenarioTests\AzureFiles\ItemTests.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ----------------------------------------------------------------------------------
//
// 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.Commands.RecoveryServices.Backup.Cmdlets.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using Xunit;

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Test.ScenarioTests
{
public partial class ContainerTests : RMTestBase
{
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(TestConstants.Workload, TestConstants.AzureFile)]
public void TestAzureFileContainer()
{
TestController.NewInstance.RunPsTest(
_logger, PsBackupProviderTypes.AzureFiles, "Test-AzureFileContainer");
}
}
}
Loading