Skip to content

Commit

Permalink
Merge pull request #59 from MabOneSdk/anudeeb
Browse files Browse the repository at this point in the history
SDKBash1
  • Loading branch information
Samuel Anudeep committed Jun 26, 2015
2 parents 4b450e4 + 718130b commit 474e80f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ function Test-GetAzureBackupVaultCredentialsReturnsFileNameAndDownloadsCert

function Test-SetAzureBackupVaultStorageTypeWithFreshResourceDoesNotThrowException
{
$freshVault = New-AzureBackupVault -ResourceGroupName $ResourceGroupName -Name "storagetestrn" -Region $Location;
$freshVaultName = "storagetestrn";

Assert-Throws { New-AzureBackupVault -ResourceGroupName $ResourceGroupName -Name $freshVaultName -Region $Location };

$freshVault = Get-AzureBackupVault -Name $freshVaultName;

Set-AzureBackupVaultStorageType $freshVault -Type GeoRedundant

Expand All @@ -43,7 +47,6 @@ function Test-SetAzureBackupVaultStorageTypeWithFreshResourceDoesNotThrowExcepti

function Test-SetAzureBackupVaultStorageTypeWithLockedResourceThrowsException
{
# TODO: Check for exception based on current storage type - obtained by vault properties
$vault = Get-AzureBackupVault -Name $ResourceName;

Assert-Throws { Set-AzureBackupVaultStorageType $vault -Type GeoRedundant }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override void ExecuteCmdlet()
WriteDebug("Triggered backup. Converting response");

var operationStatus = TrackOperation(operationId);
this.WriteObject(operationStatus.Jobs.FirstOrDefault());
this.WriteObject(operationStatus.JobList.FirstOrDefault());
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
using Microsoft.Azure.Management.BackupServices.Models;
using MBS = Microsoft.Azure.Management.BackupServices;
using Microsoft.WindowsAzure.Commands.ServiceManagement.Model;
using Microsoft.Azure.Commands.AzureBackup.Properties;
using Microsoft.Azure.Commands.AzureBackup.Models;
using Microsoft.Azure.Commands.AzureBackup.Helpers;
using Microsoft.Azure.Management.BackupServices;
Expand All @@ -39,15 +38,15 @@ public class RegisterAzureBackupContainer : AzureBackupVaultCmdletBase
internal const string V1VMParameterSet = "V1VM";
internal const string V2VMParameterSet = "V2VM";

[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = V1VMParameterSet, HelpMessage = AzureBackupCmdletHelpMessage.VMName)]
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = V2VMParameterSet, HelpMessage = AzureBackupCmdletHelpMessage.VMName)]
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = V1VMParameterSet, HelpMessage = AzureBackupCmdletHelpMessage.VirtualMachine)]
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = V2VMParameterSet, HelpMessage = AzureBackupCmdletHelpMessage.VirtualMachine)]
public string Name { get; set; }

[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = V1VMParameterSet, HelpMessage = AzureBackupCmdletHelpMessage.ServiceName)]
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = V1VMParameterSet, HelpMessage = AzureBackupCmdletHelpMessage.VirtualMachine)]
public string ServiceName { get; set; }

[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = V2VMParameterSet, HelpMessage = AzureBackupCmdletHelpMessage.RGName)]
public string ResourceGroupName { get; set; }
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = V2VMParameterSet, HelpMessage = AzureBackupCmdletHelpMessage.VirtualMachine)]
public string VMResourceGroupName { get; set; }


public override void ExecuteCmdlet()
Expand All @@ -70,7 +69,7 @@ public override void ExecuteCmdlet()
else if(this.ParameterSetName == V2VMParameterSet)
{
vmName = Name;
rgName = ResourceGroupName;
rgName = VMResourceGroupName;
WriteDebug(String.Format("Registering ARM-V2 VM, VMName: {0}, ResourceGroupName: {1}", vmName, rgName));
ServiceOrRG = "ResourceGroupName";
}
Expand All @@ -95,7 +94,7 @@ public override void ExecuteCmdlet()
//Container is not discovered. Throw exception
string errMsg = String.Format("Failed to discover VM {0} under {1} {2}. Please make sure names are correct and VM is not deleted", vmName, ServiceOrRG, rgName);
WriteDebug(errMsg);
ThrowTerminatingError(new ErrorRecord(new Exception(Resources.AzureVMNotFound), string.Empty, ErrorCategory.InvalidArgument, null));
throw new Exception(errMsg); //TODO: Sync with piyush and srub error msg
}
}

Expand All @@ -107,43 +106,41 @@ public override void ExecuteCmdlet()
var operationId = AzureBackupClient.RegisterContainer(registrationRequest);

var operationStatus = GetOperationStatus(operationId);
WriteObject(operationStatus.Jobs.FirstOrDefault());
WriteObject(operationStatus.JobList.FirstOrDefault());
});
}

private void RefreshContainer()
{
bool isRetryNeeded = true;
bool isRetyNeeded = true;
int retryCount = 1;
bool isDiscoverySuccessful = false;
string errorMessage = string.Empty;
while (isRetryNeeded && retryCount <= 3)
while (isRetyNeeded && retryCount <= 3)
{
var operationId = AzureBackupClient.RefreshContainers();

//Now wait for the operation to Complete
isRetryNeeded = WaitForDiscoveryToComplete(operationId, out isDiscoverySuccessful, out errorMessage);
isRetyNeeded = WaitForDiscoveryToCOmplete(operationId, out isDiscoverySuccessful);
retryCount++;
}

if (!isDiscoverySuccessful)
{
ThrowTerminatingError(new ErrorRecord(new Exception(errorMessage), string.Empty, ErrorCategory.InvalidArgument, null));
//Discovery failed
throw new Exception(); //TODO:
}
}

private bool WaitForDiscoveryToComplete(Guid operationId, out bool isDiscoverySuccessful, out string errorMessage)
private bool WaitForDiscoveryToCOmplete(Guid operationId, out bool isDiscoverySuccessful)
{
bool isRetryNeeded = false;
var status = TrackOperation(operationId);
errorMessage = String.Empty;
var status = TrackOperation(operationId);

isDiscoverySuccessful = true;
//If operation fails check if retry is needed or not
if (status.OperationResult != AzureBackupOperationResult.Succeeded.ToString())
{
isDiscoverySuccessful = false;
errorMessage = status.Message;
WriteDebug(String.Format("Discovery operation failed with ErrorCode: {0}", status.ErrorCode));
if ((status.ErrorCode == AzureBackupOperationErrorCode.DiscoveryInProgress.ToString() ||
(status.ErrorCode == AzureBackupOperationErrorCode.BMSUserErrorObjectLocked.ToString())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
[Cmdlet(VerbsLifecycle.Unregister, "AzureBackupContainer"), OutputType(typeof(string))]
public class UnregisterAzureBackupContainer : AzureBackupVaultCmdletBase
{
[Parameter(Position = 1, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.AzureBackupContainerToUnregister, ValueFromPipeline = true)]
[Parameter(Position = 2, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.VirtualMachine, ValueFromPipeline = true)]
[ValidateNotNullOrEmpty]
public AzureBackupContainer AzureBackupContainer { get; set; }

Expand All @@ -46,7 +46,7 @@ public override void ExecuteCmdlet()
UnregisterContainerRequestInput unregRequest = new UnregisterContainerRequestInput(containerUniqueName, AzureBackupContainerType.IaasVMContainer.ToString());
var operationId = AzureBackupClient.UnRegisterContainer(unregRequest);

var jobId = GetOperationStatus(operationId).Jobs.FirstOrDefault();
var jobId = GetOperationStatus(operationId).JobList.FirstOrDefault();
WriteObject(jobId);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public override void ExecuteCmdlet()

WriteVerbose("Received disable azure backup protection response");
var operationStatus = GetOperationStatus(operationId);
this.WriteObject(operationStatus.Jobs.FirstOrDefault());
this.WriteObject(operationStatus.JobList.FirstOrDefault());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public override void ExecuteCmdlet()
WriteDebug("Received enable azure backup protection response");

var operationStatus = GetOperationStatus(operationId);
this.WriteObject(operationStatus.Jobs.FirstOrDefault());
this.WriteObject(operationStatus.JobList.FirstOrDefault());
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public VaultCreds(string subscriptionId, string resourceType, string resourceNam
/// Class to define backup vault credentials
/// </summary>
[SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "Grouping classes based on entity")]
[DataContract]
internal class BackupVaultCreds : VaultCreds
{
/// <summary>
Expand Down Expand Up @@ -128,21 +129,25 @@ public BackupVaultCreds(string subscriptionId, string resourceType, string resou
/// <summary>
/// AcsNamespace is where the certificate is uploaded into
/// </summary>
[DataContract]
internal class AcsNamespace
{
/// <summary>
/// Gets or sets the key name for HostName entry
/// </summary>
[DataMember(Order = 0)]
public string HostName { get; set; }

/// <summary>
/// Gets or sets the key name for Namespace entry
/// </summary>
[DataMember(Order = 1)]
public string Namespace { get; set; }

/// <summary>
/// Gets or sets the value for ResourceProviderRealm entry
/// </summary>
[DataMember(Order = 2)]
public string ResourceProviderRealm { get; set; }

/// <summary>
Expand Down

0 comments on commit 474e80f

Please sign in to comment.