From 2833cfbf667f3f793671b3ec7849403ed17ac7aa Mon Sep 17 00:00:00 2001 From: ayfathim Date: Wed, 20 May 2020 17:04:48 +0530 Subject: [PATCH 1/4] z2z --- .../Models/PSRecoveryPlanObjects.cs | 20 ++++- ...tAzureRmRecoveryServicesAsrRecoveryPlan.cs | 3 +- ...wAzureRmRecoveryServicesAsrRecoveryPlan.cs | 3 +- .../Utilities/Utilities.cs | 79 +++++++++++++++++++ .../RecoveryServices/ChangeLog.md | 1 + 5 files changed, 101 insertions(+), 5 deletions(-) diff --git a/src/RecoveryServices/RecoveryServices.SiteRecovery/Models/PSRecoveryPlanObjects.cs b/src/RecoveryServices/RecoveryServices.SiteRecovery/Models/PSRecoveryPlanObjects.cs index 344a0f918eab..67e203fefb0d 100644 --- a/src/RecoveryServices/RecoveryServices.SiteRecovery/Models/PSRecoveryPlanObjects.cs +++ b/src/RecoveryServices/RecoveryServices.SiteRecovery/Models/PSRecoveryPlanObjects.cs @@ -298,10 +298,24 @@ public ASRRecoveryPlanGroup( public IList StartGroupActions { get; set; } } + // + // Summary: + // Recovery plan specific details. + public class ASRRecoveryPlanProviderSpecificDetails + { + // + // Summary: + // Initializes a new instance of the ASRRecoveryPlanProviderSpecificDetails class. + // + public ASRRecoveryPlanProviderSpecificDetails() + { + } + } + // // Summary: // Recovery plan A2A specific details. - public class ASRRecoveryPlanA2ADetails + public class ASRRecoveryPlanA2ADetails: ASRRecoveryPlanProviderSpecificDetails { // // Summary: @@ -391,7 +405,7 @@ public ASRRecoveryPlan( if (recoveryPlan.Properties.ProviderSpecificDetails != null && recoveryPlan.Properties.ProviderSpecificDetails.Count > 0) { - this.ProviderSpecificDetails = new List(); + this.ProviderSpecificDetails = new List(); foreach (var providerSpecificDetails in recoveryPlan.Properties.ProviderSpecificDetails) { if (providerSpecificDetails is RecoveryPlanA2ADetails) @@ -485,7 +499,7 @@ public ASRRecoveryPlan RefreshASRRecoveryPlanGroupNames() /// /// Gets or sets Provider Specific Details /// - public List ProviderSpecificDetails { get; set; } + public List ProviderSpecificDetails { get; set; } #endregion } diff --git a/src/RecoveryServices/RecoveryServices.SiteRecovery/RecoveryPlan/GetAzureRmRecoveryServicesAsrRecoveryPlan.cs b/src/RecoveryServices/RecoveryServices.SiteRecovery/RecoveryPlan/GetAzureRmRecoveryServicesAsrRecoveryPlan.cs index e5e7d3d944a6..416f8118ba58 100644 --- a/src/RecoveryServices/RecoveryServices.SiteRecovery/RecoveryPlan/GetAzureRmRecoveryServicesAsrRecoveryPlan.cs +++ b/src/RecoveryServices/RecoveryServices.SiteRecovery/RecoveryPlan/GetAzureRmRecoveryServicesAsrRecoveryPlan.cs @@ -197,7 +197,8 @@ private void GetRecoveryPlanFile( var json = JsonConvert.SerializeObject( recoveryPlan, Formatting.Indented, - new RecoveryPlanActionDetailsConverter()); + new RecoveryPlanActionDetailsConverter(), + new RecoveryPlanProviderSpecificDetailsConverter()); file.WriteLine(json); } } diff --git a/src/RecoveryServices/RecoveryServices.SiteRecovery/RecoveryPlan/NewAzureRmRecoveryServicesAsrRecoveryPlan.cs b/src/RecoveryServices/RecoveryServices.SiteRecovery/RecoveryPlan/NewAzureRmRecoveryServicesAsrRecoveryPlan.cs index 1c4304665851..2f8dd3295456 100644 --- a/src/RecoveryServices/RecoveryServices.SiteRecovery/RecoveryPlan/NewAzureRmRecoveryServicesAsrRecoveryPlan.cs +++ b/src/RecoveryServices/RecoveryServices.SiteRecovery/RecoveryPlan/NewAzureRmRecoveryServicesAsrRecoveryPlan.cs @@ -209,7 +209,8 @@ public override void ExecuteSiteRecoveryCmdlet() { this.recoveryPlan = JsonConvert.DeserializeObject( file.ReadToEnd(), - new RecoveryPlanActionDetailsConverter()); + new RecoveryPlanActionDetailsConverter(), + new RecoveryPlanProviderSpecificDetailsConverter()); } break; diff --git a/src/RecoveryServices/RecoveryServices.SiteRecovery/Utilities/Utilities.cs b/src/RecoveryServices/RecoveryServices.SiteRecovery/Utilities/Utilities.cs index 264d2508fd96..7555b9cf63ff 100644 --- a/src/RecoveryServices/RecoveryServices.SiteRecovery/Utilities/Utilities.cs +++ b/src/RecoveryServices/RecoveryServices.SiteRecovery/Utilities/Utilities.cs @@ -737,6 +737,77 @@ public override void WriteJson( } + /// + /// Custom Convertor for deserializing RecoveryPlanProviderSpecificDetails(RecoveryPlan) object + /// + [JsonConverter(typeof(RecoveryPlanProviderSpecificDetails))] + public class RecoveryPlanProviderSpecificDetailsConverter : + JsonCreationConverter + { + /// + /// Gets a value indicating whether this Newtonsoft.Json.JsonConverter can write JSON + /// + public override bool CanWrite => true; + + /// + /// Creates RecoveryPlanProviderSpecific details. + /// + /// Object type. + /// JSON object that will be deserialized. + /// Returns recovery plan action custom details. + protected override RecoveryPlanProviderSpecificDetails Create( + Type objectType, + JObject jObject) + { + RecoveryPlanProviderSpecificDetails outputType = null; + var actionType = (RecoveryPlanProviderType)Enum.Parse( + typeof(RecoveryPlanProviderType), + jObject.Value(Constants.InstanceType)); + + switch (actionType) + { + case RecoveryPlanProviderType.A2A: + outputType = new RecoveryPlanA2ADetails(); + break; + } + + return outputType; + } + + /// + /// Writes the JSON representation of the object. + /// + /// The Newtonsoft.Json.JsonWriter to write to. + /// The value. + /// The calling serializer. + public override void WriteJson( + JsonWriter writer, + object value, + JsonSerializer serializer) + { + JToken t = JToken.FromObject(value); + string instanceType = null; + if (value != null) + { + if (string.Compare(value.GetType().ToString(), typeof(RecoveryPlanA2ADetails).ToString()) == 0) + { + instanceType = RecoveryPlanProviderType.A2A.ToString(); + } + } + + if (t.Type != JTokenType.Object) + { + t.WriteTo(writer); + } + else + { + JObject o = (JObject)t; + IList propertyNames = o.Properties().Select(p => p.Name).ToList(); + o.AddFirst(new JProperty(Constants.InstanceType, instanceType)); + o.WriteTo(writer); + } + } + } /// /// Recovery Plan Action Types /// @@ -746,4 +817,12 @@ public enum RecoveryPlanActionDetailsType ManualActionDetails, ScriptActionDetails } + + /// + /// Recovery Plan Provider Types + /// + public enum RecoveryPlanProviderType + { + A2A + } } diff --git a/src/RecoveryServices/RecoveryServices/ChangeLog.md b/src/RecoveryServices/RecoveryServices/ChangeLog.md index 1ca85e15edd5..d72a79f3d9ef 100644 --- a/src/RecoveryServices/RecoveryServices/ChangeLog.md +++ b/src/RecoveryServices/RecoveryServices/ChangeLog.md @@ -18,6 +18,7 @@ - Additional information about change #1 --> ## Upcoming Release +* Azure Site Recovery support for creating recovery plan for zone to zoen replication from xml input. ## Version 2.9.0 * Azure Site Recovery added support for protecting proximity placement group virtual machines for Azure to Azure provider. From 39d253b928f9b3ff1835262bcd1411180a5ac941 Mon Sep 17 00:00:00 2001 From: ayfathim Date: Thu, 21 May 2020 00:29:47 +0530 Subject: [PATCH 2/4] get output fix --- .../RecoveryPlan/GetAzureRmRecoveryServicesAsrRecoveryPlan.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/RecoveryServices/RecoveryServices.SiteRecovery/RecoveryPlan/GetAzureRmRecoveryServicesAsrRecoveryPlan.cs b/src/RecoveryServices/RecoveryServices.SiteRecovery/RecoveryPlan/GetAzureRmRecoveryServicesAsrRecoveryPlan.cs index 416f8118ba58..e5e7d3d944a6 100644 --- a/src/RecoveryServices/RecoveryServices.SiteRecovery/RecoveryPlan/GetAzureRmRecoveryServicesAsrRecoveryPlan.cs +++ b/src/RecoveryServices/RecoveryServices.SiteRecovery/RecoveryPlan/GetAzureRmRecoveryServicesAsrRecoveryPlan.cs @@ -197,8 +197,7 @@ private void GetRecoveryPlanFile( var json = JsonConvert.SerializeObject( recoveryPlan, Formatting.Indented, - new RecoveryPlanActionDetailsConverter(), - new RecoveryPlanProviderSpecificDetailsConverter()); + new RecoveryPlanActionDetailsConverter()); file.WriteLine(json); } } From 187379953846a0eb3921cf321dbcd1c23190a2cf Mon Sep 17 00:00:00 2001 From: ayfathim Date: Thu, 21 May 2020 01:01:06 +0530 Subject: [PATCH 3/4] correcting get output --- .../Models/PSRecoveryPlanObjects.cs | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/RecoveryServices/RecoveryServices.SiteRecovery/Models/PSRecoveryPlanObjects.cs b/src/RecoveryServices/RecoveryServices.SiteRecovery/Models/PSRecoveryPlanObjects.cs index 67e203fefb0d..344a0f918eab 100644 --- a/src/RecoveryServices/RecoveryServices.SiteRecovery/Models/PSRecoveryPlanObjects.cs +++ b/src/RecoveryServices/RecoveryServices.SiteRecovery/Models/PSRecoveryPlanObjects.cs @@ -298,24 +298,10 @@ public ASRRecoveryPlanGroup( public IList StartGroupActions { get; set; } } - // - // Summary: - // Recovery plan specific details. - public class ASRRecoveryPlanProviderSpecificDetails - { - // - // Summary: - // Initializes a new instance of the ASRRecoveryPlanProviderSpecificDetails class. - // - public ASRRecoveryPlanProviderSpecificDetails() - { - } - } - // // Summary: // Recovery plan A2A specific details. - public class ASRRecoveryPlanA2ADetails: ASRRecoveryPlanProviderSpecificDetails + public class ASRRecoveryPlanA2ADetails { // // Summary: @@ -405,7 +391,7 @@ public ASRRecoveryPlan( if (recoveryPlan.Properties.ProviderSpecificDetails != null && recoveryPlan.Properties.ProviderSpecificDetails.Count > 0) { - this.ProviderSpecificDetails = new List(); + this.ProviderSpecificDetails = new List(); foreach (var providerSpecificDetails in recoveryPlan.Properties.ProviderSpecificDetails) { if (providerSpecificDetails is RecoveryPlanA2ADetails) @@ -499,7 +485,7 @@ public ASRRecoveryPlan RefreshASRRecoveryPlanGroupNames() /// /// Gets or sets Provider Specific Details /// - public List ProviderSpecificDetails { get; set; } + public List ProviderSpecificDetails { get; set; } #endregion } From f699fe993c7141411002d0c53ca1c36430508a92 Mon Sep 17 00:00:00 2001 From: ayfathim Date: Thu, 21 May 2020 02:14:29 +0530 Subject: [PATCH 4/4] fixing get output --- .../RecoveryPlan/GetAzureRmRecoveryServicesAsrRecoveryPlan.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/RecoveryServices/RecoveryServices.SiteRecovery/RecoveryPlan/GetAzureRmRecoveryServicesAsrRecoveryPlan.cs b/src/RecoveryServices/RecoveryServices.SiteRecovery/RecoveryPlan/GetAzureRmRecoveryServicesAsrRecoveryPlan.cs index e5e7d3d944a6..416f8118ba58 100644 --- a/src/RecoveryServices/RecoveryServices.SiteRecovery/RecoveryPlan/GetAzureRmRecoveryServicesAsrRecoveryPlan.cs +++ b/src/RecoveryServices/RecoveryServices.SiteRecovery/RecoveryPlan/GetAzureRmRecoveryServicesAsrRecoveryPlan.cs @@ -197,7 +197,8 @@ private void GetRecoveryPlanFile( var json = JsonConvert.SerializeObject( recoveryPlan, Formatting.Indented, - new RecoveryPlanActionDetailsConverter()); + new RecoveryPlanActionDetailsConverter(), + new RecoveryPlanProviderSpecificDetailsConverter()); file.WriteLine(json); } }