Skip to content

[REBASE] afs enable protection #361

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 27, 2018
Merged

Conversation

siddharth7
Copy link

Description


This checklist is used to make sure that common guidelines for a pull request are followed. You can find a more complete discussion of PowerShell cmdlet best practices here.

General Guidelines

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.
  • The pull request does not introduce breaking changes (unless a major version change occurs in the assembly and module).

Testing Guidelines

  • Pull request includes test coverage for the included changes.
  • PowerShell scripts used in tests should do any necessary setup as part of the test or suite setup, and should not use hard-coded values for locations or existing resources.

Cmdlet Signature Guidelines

  • New cmdlets that make changes or have side effects should implement ShouldProcess and have SupportShouldProcess=true specified in the cmdlet attribute. You can find more information on ShouldProcess here.
  • Cmdlet specifies OutputType attribute if any output is produced - if the cmdlet produces no output, it should implement a PassThrough parameter.

Cmdlet Parameter Guidelines

  • Parameter types should not expose types from the management library - complex parameter types should be defined in the module.
  • Complex parameter types are discouraged - a parameter type should be simple types as often as possible. If complex types are used, they should be shallow and easily creatable from a constructor or another cmdlet.
  • Cmdlet parameter sets should be mutually exclusive - each parameter set must have at least one mandatory parameter not in other parameter sets.

}

/// <summary>
/// Helper function to convert ps backup container model from service response.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary text should be Helper function to convert PS Protectable Container model from service response.

/// <summary>
/// Helper function to convert ps backup container model from service response.
/// </summary>
public static ContainerBase GetProtectableContainerModel(ServiceClientModel.ProtectableContainerResource protectableContainer)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid converting this object as it doesn't need to be exposed to the customer.

@@ -93,7 +111,7 @@ public static ContainerBase GetContainerModel(ServiceClientModel.ProtectionConta
public static List<ContainerBase> GetContainerModelList(IEnumerable<ServiceClientModel.ProtectionContainerResource> protectionContainers)
{
List<ContainerBase> containerModels = new List<ContainerBase>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Extra white space

/// <summary>
/// Helper function to convert ps backup container model list from service response.
/// </summary>
public static List<ContainerBase> GetProtectableContainerModelList(IEnumerable<ServiceClientModel.ProtectableContainerResource> protectableContainers)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid converting this object as it doesn't need to be exposed to the customer.

/// and converts it in to the PS container model
/// </summary>
/// <param name="protectableContainer">Service client object representing the container</param>
public AzureFileShareContainer(ProtectableContainerResource protectableContainer)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid converting this object as it doesn't need to be exposed to the customer.

/// <returns>List of protection containers</returns>
public IEnumerable<ProtectableContainerResource> ListUnregisteredContainers(
ODataQuery<BMSContainerQueryObject> queryFilter,
string skipToken = default(string),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skipToken is not used anywhere in the method

@@ -138,6 +138,9 @@ public IPsBackupProvider GetProviderInstance(WorkloadType workloadType)
case WorkloadType.AzureVM:
providerType = PsBackupProviderTypes.IaasVm;
break;
case WorkloadType.AzureFiles:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have AzureFiles and AzureFile. Shouldn't they be same?

@@ -23,6 +23,22 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClient
{
public partial class ServiceClientAdapter
{

public RestAzureNS.AzureOperationResponse InquireContainers(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add summary


public RestAzureNS.AzureOperationResponse InquireContainers(
string containerName,
ODataQuery<BMSContainersInquiryQueryObject> queryFilter,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is BMSContainersInquiryQueryObject defined?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -92,6 +136,25 @@ public partial class ServiceClientAdapter
return response;
}

/// <summary>
/// Triggers register of container catalog in service

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Triggers register of container in service

@dragonfly91 dragonfly91 changed the title [DO NOT MERGE] afs enable protection [REBASE] afs enable protection Aug 21, 2018
@siddharth7 siddharth7 force-pushed the users/sisi/afs-enable-protection branch 2 times, most recently from 9a995e1 to d451bf9 Compare August 21, 2018 12:14
Copy link

@dragonfly91 dragonfly91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review is incomplete. But you can work on these comments and publish an update and then I'll review the remaining changes as well.

@@ -92,8 +96,7 @@ public static ContainerBase GetContainerModel(ServiceClientModel.ProtectionConta
/// </summary>
public static List<ContainerBase> GetContainerModelList(IEnumerable<ServiceClientModel.ProtectionContainerResource> protectionContainers)
{
List<ContainerBase> containerModels = new List<ContainerBase>();

List<ContainerBase> containerModels = new List<ContainerBase>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like extra whitespace. One good practice is to run "Ctrl + K + D" in all the touched files.

/// <summary>
/// Helper function to convert ps backup container model list from service response.
/// </summary>
public static List<ServiceClientModel.ProtectableContainerResource> GetProtectableContainerModelList(IEnumerable<ServiceClientModel.ProtectableContainerResource> protectableContainers)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this method is not needed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is being used in AzureFilesPsBackupProvider

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use System.Linq.ToList extension method instead. https://stackoverflow.com/questions/7617771/converting-from-ienumerable-to-list

/// <param name="response">Response of the operation returned by the service.</param>
/// <param name="getOpStatus">Delegate method to fetch the operation status of the operation.</param>
/// <returns>Result of the operation once it completes.</returns>
public static RestAzureNS.AzureOperationResponse<T> GetOperationResult<T>(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method looks very similar to this method. Can you confirm why this is needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its different, the second parameter is different ( RestAzureNS.AzureOperationResponse vs RestAzureNS.AzureOperationResponse)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closed

AzureFileshareProtectedItem protectedItem = (AzureFileshareProtectedItem)protectedItemResource.Properties;
LastBackupStatus = protectedItem.LastBackupStatus;
LastBackupTime = protectedItem.LastBackupTime;
ProtectionPolicyName = policyName;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be moved to AzureItem ctor

{
AzureStorageContainer azureStorageContainer =
(AzureStorageContainer)protectionContainer.Properties;
ResourceGroupName = IdUtils.GetResourceGroupName(protectionContainer.Id);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This property assignment can be moved to AzureContainer ctor

string storageContainer = null;
string classicStorageContainer = null;
List<ContainerBase> registeredStorageAccounts = GetRegisteredStorageAccount(vaultName, resourceGroupName);
foreach (var storageAccount in registeredStorageAccounts)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using foreach loop to search, use the C# Find method.


//get unregistered storage account
if (!isRegistered)
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comments apply here as well.

}

private void TriggerInquiry(string vaultName, string resourceGroupName,
string storageContainer)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be storageContainerName

private void TriggerInquiry(string vaultName, string resourceGroupName,
string storageContainer)
{
ODataQuery<BMSContainersInquiryQueryObject> queryParam = new ODataQuery<BMSContainersInquiryQueryObject>(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be queryParams

if (protectableObjectResource == null)
{
// Container is not discovered. Throw exception
string errMsg = string.Format(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readable variable names

@siddharth7 siddharth7 force-pushed the users/sisi/afs-enable-protection branch from 1a9323d to 26b4427 Compare August 22, 2018 09:06
@dragonfly91
Copy link

@siddharth7 Please fix the conflicts. Will review afterward the fix.

@dragonfly91 dragonfly91 added the needs revision The PR needs revision from the author label Aug 23, 2018
@siddharth7 siddharth7 force-pushed the users/sisi/afs-enable-protection branch from 095c6f2 to c68a8f9 Compare August 27, 2018 09:42
Copy link

@dragonfly91 dragonfly91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the comments. Otherwise LGTM.

/// <summary>
/// Helper function to convert ps backup container model list from service response.
/// </summary>
public static List<ServiceClientModel.ProtectableContainerResource> GetProtectableContainerModelList(IEnumerable<ServiceClientModel.ProtectableContainerResource> protectableContainers)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use System.Linq.ToList extension method instead. https://stackoverflow.com/questions/7617771/converting-from-ienumerable-to-list

@@ -62,12 +37,11 @@ public class AzureFileShareItem : ItemBase
/// <param name="policyName">Name of the protection policy associated with this protected item</param>
public AzureFileShareItem(ProtectedItemResource protectedItemResource,
string containerName, ContainerType containerType, string policyName)
: base(protectedItemResource, containerName, containerType)
: base(protectedItemResource, containerName, containerType, policyName)
{
AzureFileshareProtectedItem protectedItem = (AzureFileshareProtectedItem)protectedItemResource.Properties;
LastBackupStatus = protectedItem.LastBackupStatus;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the initialization for LastBackupStatus, LastBackupTime, ProtectionState and ProtectionStatus to the base class - both in VM and Files.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

workload specific properties, can't move it to base class


namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
{
public class AzureItem : ItemBase

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide summary text for this class.

@@ -12,16 +12,17 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Run refactoring once again

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

string storageContainerName = null;
List<ContainerBase> registeredStorageAccounts = GetRegisteredStorageAccounts(vaultName, vaultResourceGroupName);
ContainerBase registeredStorageAccount = registeredStorageAccounts.Find(storageAccount =>
string.Compare(storageAccount.Name.Split(';').Last(), storageAccountName) == 0);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Please fix indent.


//get protectable item
WorkloadProtectableItemResource protectableObjectResource = null;
protectableObjectResource = TriggerDiscovery(vaultName, vaultResourceGroupName, azureFileShareName, storageAccountName);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name should be GetProtectableItem

AzureFileShareProtectableItem azureFileShareProtectableItem =
(AzureFileShareProtectableItem)protectableItem.Properties;
if (azureFileShareProtectableItem != null &&
string.Compare(azureFileShareProtectableItem.FriendlyName, azureFileShareName, true) == 0 &&

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check with PM about how to deal with case

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tracking

/// </summary>
[Parameter(Position = 2, Mandatory = true, ValueFromPipelineByPropertyName = true,
ParameterSetName = AzureFileShareParameterSet, HelpMessage = ParamHelpMsgs.Item.AzureFileShareName)]
public string FileShareName { get; set; }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be Name. Check PM for details.

ParameterSetName = AzureFileShareParameterSet,
HelpMessage = ParamHelpMsgs.Item.AzureFileStorageAccountResourceGroupName)]
[ResourceGroupCompleter]
public string StorageAccountResourceGroupName { get; set; }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove this parameter

@@ -36,7 +36,7 @@ internal static class Common
{
public const string Vault = "The Azure Backup vault object which is the parent resource.";
public const string VaultId = "Resource ID of the Recovery Services Vault.";
public const string WorkloadType = "Workload type of the resource (for example: AzureVM, WindowsServer, AzureFile).";
public const string WorkloadType = "Workload type of the resource (for example: AzureVM, WindowsServer, Azure File).";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for the right values here

@siddharth7 siddharth7 force-pushed the users/sisi/afs-enable-protection branch from 6313148 to b2b88f3 Compare August 27, 2018 12:28
enable protection 14/8

updated trigger discovery

file->files

added tracker for enquiry

added tracking for register container

minor changes

fix for classic storage accounts

rebase changes

rebase changes

addressed comments

used storageaccountRg instead of Rg

blank lines added to file share provider

removed storageaccountresourcegroupname dependancy

resolved issues during rebase

resolved issues during rebase

rebase changes

Review comments
@siddharth7 siddharth7 force-pushed the users/sisi/afs-enable-protection branch from b2b88f3 to 863f285 Compare August 27, 2018 12:35
@siddharth7 siddharth7 merged commit b06f08b into afs_dev Aug 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs revision The PR needs revision from the author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants