Skip to content

A2A Policy enumeration, creation, association #8

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 1 commit into from
Mar 31, 2016
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 @@ -152,6 +152,11 @@ public static class Constants
/// </summary>
public const string HyperVReplicaAzure = "HyperVReplicaAzure";

/// <summary>
/// Represents AzureToAzure string constant.
/// </summary>
public const string AzureToAzure = "AzureToAzure";

/// <summary>
/// Represents HyperVReplicaAzureReplicationDetails string constant.
/// </summary>
Expand Down Expand Up @@ -356,6 +361,16 @@ public static class Constants
/// JSON field: InstanceType
/// </summary>
public const string InstanceType = "InstanceType";

/// <summary>
/// Enable.
/// </summary>
public const string Enable = "Enable";

/// <summary>
/// Disable.
/// </summary>
public const string Disable = "Disable";
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,26 @@ public ASRPolicy(Policy policy)

this.ReplicationProviderSettings = replicationProviderSettings;
}
else if (policy.Properties.ProviderSpecificDetails.InstanceType == Constants.AzureToAzure)
{
A2APolicyDetails details =
(A2APolicyDetails)policy.Properties.ProviderSpecificDetails;

ASRAzureToAzurePolicyDetails replicationProviderSettings =
new ASRAzureToAzurePolicyDetails();

replicationProviderSettings.AppConsistentFrequencyInMinutes =
details.AppConsistentFrequencyInMinutes;
replicationProviderSettings.CrashConsistentFrequencyInMinutes =
details.CrashConsistentFrequencyInMinutes;
replicationProviderSettings.MultiVmSyncStatus =
details.MultiVmSyncStatus;
replicationProviderSettings.RecoveryPointHistory = details.RecoveryPointHistory;
replicationProviderSettings.RecoveryPointThresholdInMinutes =
details.RecoveryPointThresholdInMinutes;

this.ReplicationProviderSettings = replicationProviderSettings;
}
}

#region Properties
Expand Down Expand Up @@ -790,6 +810,32 @@ public class ASRHyperVReplicaAzurePolicyDetails : ASRPolicyProviderSettingsDetai
public int ReplicationFrequencyInSeconds { get; set; }
}

/// <summary>
/// ASR AzureToAzure policy details.
/// </summary>
public class ASRAzureToAzurePolicyDetails : ASRPolicyProviderSettingsDetails
{
// Summary:
// Optional.
public int AppConsistentFrequencyInMinutes { get; set; }
//
// Summary:
// Optional.
public int CrashConsistentFrequencyInMinutes { get; set; }
//
// Summary:
// Optional.
public string MultiVmSyncStatus { get; set; }
//
// Summary:
// Optional.
public int RecoveryPointHistory { get; set; }
//
// Summary:
// Optional.
public int RecoveryPointThresholdInMinutes { get; set; }
}

/// <summary>
/// ASR Customer Storage Account.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ internal static class ASRParameterSets
/// </summary>
internal const string EnterpriseToAzure = "EnterpriseToAzure";

/// <summary>
/// To define Azure to Azure parameter set.
/// </summary>
internal const string AzureToAzure = "AzureToAzure";

/// <summary>
/// Mapping between HyperV Site to Azure.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,21 @@ public class NewAzureSiteRecoveryPolicy : SiteRecoveryCmdletBase
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzure, Mandatory = true)]
public string Name { get; set; }

/// <summary>
/// Gets or sets Replication Provider of the Policy.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzure, Mandatory = true)]
[ValidateNotNullOrEmpty]
[ValidateSet(
Constants.HyperVReplica2012R2,
Constants.HyperVReplica2012,
Constants.HyperVReplicaAzure)]
Constants.HyperVReplicaAzure,
Constants.AzureToAzure)]
public string ReplicationProvider { get; set; }

/// <summary>
Expand Down Expand Up @@ -147,6 +150,41 @@ public class NewAzureSiteRecoveryPolicy : SiteRecoveryCmdletBase
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure)]
public SwitchParameter Encrypt { get; set; }

/* TODO: SriramVu:
* Revise the mandatory inputs for A2A prameterset and use defaults if req.
* Check out the possible allowed values (if any) and use ValidateSet.
*/

/// <summary>
/// Gets or sets Recovery point threshold in minutes.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzure, Mandatory = true)]
public int RecoveryPointThresholdInMinutes { get; set; }

/// <summary>
/// Gets or sets Recovery point history.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzure, Mandatory = true)]
public int RecoveryPointHistory { get; set; }

/// <summary>
/// Gets or sets Crash consistent frequency in minutes.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzure, Mandatory = true)]
public int CrashConsistentFrequencyInMinutes { get; set; }

/// <summary>
/// Gets or sets App consistent frequency in minutes.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzure, Mandatory = true)]
public int AppConsistentFrequencyInMinutes { get; set; }

/// <summary>
/// Gets or sets EnableMultiVmSync parameter. On passing, MultiVmSync will be enabled.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzure)]
public SwitchParameter EnableMultiVmSync { get; set; }

#endregion Parameters

/// <summary>
Expand All @@ -164,6 +202,9 @@ public override void ExecuteSiteRecoveryCmdlet()
case ASRParameterSets.EnterpriseToAzure:
this.EnterpriseToAzurePolicyObject();
break;
case ASRParameterSets.AzureToAzure:
this.CreateAzureToAzurePolicy();
break;
}
}

Expand Down Expand Up @@ -294,5 +335,52 @@ private void EnterpriseToAzurePolicyObject()

WriteObject(new ASRJob(jobResponse.Job));
}

/// <summary>
/// Creates an A2A Policy.
/// </summary>
private void CreateAzureToAzurePolicy()
{
if (string.Compare(
this.ReplicationProvider,
Constants.AzureToAzure,
StringComparison.OrdinalIgnoreCase) != 0)
{
throw new InvalidOperationException(
string.Format(
Properties.Resources.IncorrectReplicationProvider,
this.ReplicationProvider));
}

var a2aPolicyCreationInput = new A2APolicyCreationInput()
{
AppConsistentFrequencyInMinutes = this.AppConsistentFrequencyInMinutes,
CrashConsistentFrequencyInMinutes = this.CrashConsistentFrequencyInMinutes,
MultiVmSyncStatus = this.EnableMultiVmSync ? Constants.Enable: Constants.Disable,
RecoveryPointHistory = this.RecoveryPointHistory,
RecoveryPointThresholdInMinutes = this.RecoveryPointThresholdInMinutes
};

var createPolicyInputProperties = new CreatePolicyInputProperties()
{
ProviderSpecificInput = a2aPolicyCreationInput
};

var createPolicyInput = new CreatePolicyInput()
{
Properties = createPolicyInputProperties
};

LongRunningOperationResponse response =
RecoveryServicesClient.CreatePolicy(this.Name, createPolicyInput);

string jobId = PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location);

JobResponse jobResponse =
RecoveryServicesClient
.GetAzureSiteRecoveryJobDetails(jobId);

WriteObject(new ASRJob(jobResponse.Job));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public override void ExecuteSiteRecoveryCmdlet()
case ASRParameterSets.EnterpriseToEnterprise:
this.EnterpriseToEnterpriseAssociation();
break;
////case ASRParameterSets.AzureToAzure:
//// this.EnterpriseToEnterpriseAssociation();
//// break;
}
}

Expand All @@ -88,12 +91,18 @@ public override void ExecuteSiteRecoveryCmdlet()
/// </summary>
private void EnterpriseToEnterpriseAssociation()
{
// TODO: SriramVu: Same parameter set can be used for both E2E and A2A - update
// methods and validations.

if (string.Compare(
this.Policy.ReplicationProvider,
Constants.HyperVReplica2012,
StringComparison.OrdinalIgnoreCase) != 0 && string.Compare(
this.Policy.ReplicationProvider,
Constants.HyperVReplica2012R2,
StringComparison.OrdinalIgnoreCase) != 0 && string.Compare(
this.Policy.ReplicationProvider,
"A2A",
StringComparison.OrdinalIgnoreCase) != 0)
{
throw new InvalidOperationException(
Expand Down Expand Up @@ -125,6 +134,25 @@ private void EnterpriseToAzureAssociation()
Associate(Constants.AzureContainer);
}

/// <summary>
/// Associates Policy with Azure based protection containers
/// </summary>
private void AzureToAzureAssociation()
{
if (string.Compare(
this.Policy.ReplicationProvider,
Constants.AzureToAzure,
StringComparison.OrdinalIgnoreCase) != 0)
{
throw new InvalidOperationException(
string.Format(
Properties.Resources.IncorrectReplicationProvider,
this.Policy.ReplicationProvider));
}

Associate(this.RecoveryProtectionContainer.ID);
}

/// <summary>
/// Helper to configure cloud
/// </summary>
Expand Down