Skip to content

Commit

Permalink
Merge pull request #16 from AsrOneSdk/sanjkuma-dev
Browse files Browse the repository at this point in the history
Version change with few changes for smooth E2E VM/RP flow.
  • Loading branch information
sanjkuma committed Jan 22, 2015
2 parents 7a3fe28 + 2b73a1d commit 6032c57
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public PSRecoveryServicesClient(AzureSubscription azureSubscription)
AzureSession.ClientFactory.CreateClient<RecoveryServicesManagementClient>(azureSubscription, AzureEnvironment.Endpoint.ServiceManagement);
}


/// <summary>
/// Retrieves Azure Cloud services.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,13 @@ public JobResponse StartAzureSiteRecoveryCommitFailover(
/// </summary>
/// <param name="protectionContainerId">Protection Container ID</param>
/// <param name="protectionEntityId">Recovery Plan ID</param>
/// <param name="request">Re-protect request.</param>
/// <returns>Job response</returns>
public JobResponse StartAzureSiteRecoveryReprotection(
string protectionContainerId,
string protectionEntityId)
string protectionEntityId,
ReprotectRequest request)
{
var request = new ReprotectRequest();
return this.GetSiteRecoveryClient().ProtectionEntity.Reprotect(
protectionContainerId,
protectionEntityId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ protected override void StopProcessing()
/// </summary>
private void EnterpriseToAzureProtectionProfileObject()
{
// Verify whether the storage account is associated with the account or not.
// PSRecoveryServicesClientHelper.ValidateStorageAccountAssociation(this.RecoveryAzureStorageAccount);
//// Verify whether the storage account is associated with the account or not.
//// PSRecoveryServicesClientHelper.ValidateStorageAccountAssociation(this.RecoveryAzureStorageAccount);

// Verify whether the subscription is associated with the account or not.
// PSRecoveryServicesClientHelper.ValidateSubscriptionAccountAssociation(this.RecoveryAzureSubscription);
//// Verify whether the subscription is associated with the account or not.
//// PSRecoveryServicesClientHelper.ValidateSubscriptionAccountAssociation(this.RecoveryAzureSubscription);

this.ValidateReplicationStartTime(this.ReplicationStartTime);

Expand All @@ -184,7 +184,6 @@ private void EnterpriseToAzureProtectionProfileObject()
ReplicationFrequencyInSeconds = this.ReplicationFrequencyInSeconds,
RecoveryPoints = this.RecoveryPoints,
ApplicationConsistentSnapshotFrequencyInHours = this.ApplicationConsistentSnapshotFrequencyInHours,
CompressionEnabled = this.CompressionEnabled,
ReplicationPort = this.ReplicationPort,
ReplicationStartTime = this.ReplicationStartTime,
AllowReplicaDeletion = this.AllowReplicaDeletion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ public override void ExecuteCmdlet()
input.ReplicationProviderInput = DataContractUtils.Serialize<AzureEnableProtectionInput>(azureInput);
}
else
{
input.ReplicationProviderInput = string.Empty;
input.ProtectionProfileId = this.ProtectionProfile.ID;
}
this.jobResponse =
RecoveryServicesClient.EnableProtection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ public class StartAzureSiteRecoveryCommitFailoverJob : RecoveryServicesCmdletBas
[ValidateNotNullOrEmpty]
public ASRProtectionEntity ProtectionEntity { get; set; }

/// <summary>
/// Gets or sets Failover direction for the recovery plan.
/// </summary>
[Parameter(Mandatory = false)]
[ValidateSet(
Constants.PrimaryToRecovery,
Constants.RecoveryToPrimary)]
public string Direction { get; set; }

/// <summary>
/// Gets or sets switch parameter. This is required to wait for job completion.
/// </summary>
Expand Down Expand Up @@ -116,27 +125,19 @@ private void SetRpCommit()
{
var request = new CommitFailoverRequest();

if (this.ProtectionEntity == null)
if (this.RecoveryPlan == null)
{
var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity(
this.ProtectionContainerId,
this.ProtectionEntityId);
this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity);
var rp = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(
this.RPId);
this.RecoveryPlan = new ASRRecoveryPlan(rp.RecoveryPlan);

this.ValidateUsageById(this.ProtectionEntity.ReplicationProvider);
this.ValidateUsageById(this.RecoveryPlan.ReplicationProvider);
}

request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider;
request.ReplicationProviderSettings = string.Empty;

if (this.ProtectionEntity.ActiveLocation == Constants.PrimaryLocation)
{
request.FailoverDirection = Constants.PrimaryToRecovery;
}
else
{
request.FailoverDirection = Constants.RecoveryToPrimary;
}
request.FailoverDirection = this.Direction;

this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryCommitFailover(
this.RPId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ private void StartPEPlannedFailover()

if (this.ProtectionEntity.ReplicationProvider == Constants.HyperVReplicaAzure)
{
request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
if (this.Direction == Constants.PrimaryToRecovery)
{
var blob = new AzureFailoverInput();
Expand All @@ -166,8 +165,14 @@ private void StartPEPlannedFailover()
request.ReplicationProviderSettings = DataContractUtils.Serialize<AzureFailbackInput>(blob);
}
}
else
{
request.ReplicationProviderSettings = string.Empty;
}

request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
request.FailoverDirection = this.Direction;

this.jobResponse =
RecoveryServicesClient.StartAzureSiteRecoveryPlannedFailover(
this.ProtectionContainerId,
Expand Down Expand Up @@ -199,7 +204,6 @@ private void StartRpPlannedFailover()

if (this.RecoveryPlan.ReplicationProvider == Constants.HyperVReplicaAzure)
{
request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider;
if (this.Direction == Constants.PrimaryToRecovery)
{
var blob = new AzureFailoverInput();
Expand All @@ -215,6 +219,7 @@ private void StartRpPlannedFailover()
}
}

request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider;
request.FailoverDirection = this.Direction;

this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryPlannedFailover(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ private void StartRpTestFailover()
else
{
request.NetworkID = this.networkId;
if (string.IsNullOrEmpty(this.networkType))
{
request.NetworkType = "DisconnectedVMNetworkTypeForTestFailover";
}
}

if (this.RecoveryPlan == null)
Expand All @@ -203,7 +207,6 @@ private void StartRpTestFailover()

if (this.RecoveryPlan.ReplicationProvider == Constants.HyperVReplicaAzure)
{
request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider;
if (this.Direction == Constants.PrimaryToRecovery)
{
var blob = new AzureFailoverInput();
Expand All @@ -212,18 +215,9 @@ private void StartRpTestFailover()
}
}

request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider;
request.FailoverDirection = this.Direction;

if (this.Network != null)
{
request.NetworkID = this.Network.ID;
this.networkType = "UseVMNetworkTypeForTestFailover";
}
else
{
request.NetworkID = this.networkId;
}

this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryTestFailover(
this.RpId,
request);
Expand Down Expand Up @@ -257,7 +251,6 @@ private void StartPETestFailover()

if (this.ProtectionEntity.ReplicationProvider == Constants.HyperVReplicaAzure)
{
request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
if (this.Direction == Constants.PrimaryToRecovery)
{
var blob = new AzureFailoverInput();
Expand All @@ -266,6 +259,7 @@ private void StartPETestFailover()
}
}

request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
request.FailoverDirection = this.Direction;

if (this.Network != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ private void StartPEUnplannedFailover()
this.ValidateUsageById(this.ProtectionEntity.ReplicationProvider);
}

request.ReplicationProviderSettings = string.Empty;

if (this.ProtectionEntity.ReplicationProvider == Constants.HyperVReplicaAzure)
{
request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
Expand All @@ -163,6 +165,7 @@ private void StartPEUnplannedFailover()
}
}

request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
request.FailoverDirection = this.Direction;
request.SourceSiteOperations = this.PerformSourceSiteOperations;
this.jobResponse =
Expand Down Expand Up @@ -194,6 +197,8 @@ private void StartRpUnPlannedFailover()
this.ValidateUsageById(this.RecoveryPlan.ReplicationProvider);
}

request.ReplicationProviderSettings = string.Empty;

if (this.RecoveryPlan.ReplicationProvider == Constants.HyperVReplicaAzure)
{
request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider;
Expand All @@ -205,6 +210,7 @@ private void StartRpUnPlannedFailover()
}
}

request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider;
request.FailoverDirection = this.Direction;
request.PrimaryAction = this.PrimaryAction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ public override void ExecuteCmdlet()
/// </summary>
private void SetRpReprotect()
{
var request = new ReprotectRequest();

if (this.RecoveryPlan == null)
{
var rp = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(
this.RPId);
this.RecoveryPlan = new ASRRecoveryPlan(rp.RecoveryPlan);

this.ValidateUsageById(this.RecoveryPlan.ReplicationProvider);
}

request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider;
request.ReplicationProviderSettings = string.Empty;

request.FailoverDirection = this.Direction;

this.jobResponse = RecoveryServicesClient.UpdateAzureSiteRecoveryProtection(
this.RPId);

Expand All @@ -137,16 +153,15 @@ private void SetRpReprotect()
/// </summary>
private void SetPEReprotect()
{
// Until RR is done active location remains same from where FO was initiated.
if ((this.Direction == Constants.PrimaryToRecovery &&
this.ProtectionEntity.ActiveLocation != Constants.RecoveryLocation) ||
this.ProtectionEntity.ActiveLocation == Constants.RecoveryLocation) ||
(this.Direction == Constants.RecoveryToPrimary &&
this.ProtectionEntity.ActiveLocation != Constants.PrimaryLocation))
this.ProtectionEntity.ActiveLocation == Constants.PrimaryLocation))
{
throw new ArgumentException("Parameter value is not correct.", "Direction");
}

var request = new PlannedFailoverRequest();
var request = new ReprotectRequest();

if (this.ProtectionEntity == null)
{
Expand All @@ -158,9 +173,10 @@ private void SetPEReprotect()
this.ValidateUsageById(this.ProtectionEntity.ReplicationProvider);
}

request.ReplicationProviderSettings = string.Empty;

if (this.ProtectionEntity.ReplicationProvider == Constants.HyperVReplicaAzure)
{
request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
if (this.Direction == Constants.PrimaryToRecovery)
{
var blob = new AzureReProtectionInput();
Expand All @@ -174,11 +190,13 @@ private void SetPEReprotect()
}
}

request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
request.FailoverDirection = this.Direction;

this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryReprotection(
this.ProtectionContainerId,
this.ProtectionEntityId);
this.ProtectionEntityId,
request);

this.WriteJob(this.jobResponse.Job);

Expand Down
Binary file not shown.
Loading

0 comments on commit 6032c57

Please sign in to comment.