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.