Skip to content

Commit 8471704

Browse files
committed
Merging branch 'dev' into neha-dev
2 parents 969808c + 6032c57 commit 8471704

13 files changed

+260
-240
lines changed

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesClient.cs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public PSRecoveryServicesClient(AzureSubscription azureSubscription)
9595
AzureSession.ClientFactory.CreateClient<RecoveryServicesManagementClient>(azureSubscription, AzureEnvironment.Endpoint.ServiceManagement);
9696
}
9797

98+
9899
/// <summary>
99100
/// Retrieves Azure Cloud services.
100101
/// </summary>
@@ -262,4 +263,101 @@ private SiteRecoveryManagementClient GetSiteRecoveryClient()
262263
return siteRecoveryClient;
263264
}
264265
}
266+
267+
/// <summary>
268+
/// Helper around serialization/deserialization of objects. This one is a thin wrapper around
269+
/// DataContractUtils template class which is the one doing the heavy lifting.
270+
/// </summary>
271+
[SuppressMessage(
272+
"Microsoft.StyleCop.CSharp.MaintainabilityRules",
273+
"SA1402:FileMayOnlyContainASingleClass",
274+
Justification = "Keeping all contracts together.")]
275+
public static class DataContractUtils
276+
{
277+
/// <summary>
278+
/// Serializes the supplied object to the string.
279+
/// </summary>
280+
/// <typeparam name="T">The object type.</typeparam>
281+
/// <param name="obj">Object to serialize</param>
282+
/// <returns>Serialized string.</returns>
283+
public static string Serialize<T>(T obj)
284+
{
285+
return DataContractUtils<T>.Serialize(obj);
286+
}
287+
288+
/// <summary>
289+
/// Deserialize the string to the expected object type.
290+
/// </summary>
291+
/// <typeparam name="T">The object type</typeparam>
292+
/// <param name="xmlString">Serialized string</param>
293+
/// <param name="result">Deserialized object</param>
294+
public static void Deserialize<T>(string xmlString, out T result)
295+
{
296+
result = DataContractUtils<T>.Deserialize(xmlString);
297+
}
298+
}
299+
300+
/// <summary>
301+
/// Template class for DataContractUtils.
302+
/// </summary>
303+
/// <typeparam name="T">The object type</typeparam>
304+
[SuppressMessage(
305+
"Microsoft.StyleCop.CSharp.MaintainabilityRules",
306+
"SA1402:FileMayOnlyContainASingleClass",
307+
Justification = "Keeping all contracts together.")]
308+
public static class DataContractUtils<T>
309+
{
310+
/// <summary>
311+
/// Serializes the propertyBagContainer to the string.
312+
/// </summary>
313+
/// <param name="propertyBagContainer">Property bag</param>
314+
/// <returns>Serialized string </returns>
315+
public static string Serialize(T propertyBagContainer)
316+
{
317+
var serializer = new DataContractSerializer(typeof(T));
318+
string xmlString;
319+
StringWriter sw = null;
320+
try
321+
{
322+
sw = new StringWriter();
323+
using (var writer = new XmlTextWriter(sw))
324+
{
325+
// Indent the XML so it's human readable.
326+
writer.Formatting = Formatting.Indented;
327+
serializer.WriteObject(writer, propertyBagContainer);
328+
writer.Flush();
329+
xmlString = sw.ToString();
330+
}
331+
}
332+
finally
333+
{
334+
if (sw != null)
335+
{
336+
sw.Close();
337+
}
338+
}
339+
340+
return xmlString;
341+
}
342+
343+
/// <summary>
344+
/// Deserialize the string to the propertyBagContainer.
345+
/// </summary>
346+
/// <param name="xmlString">Serialized string</param>
347+
/// <returns>Deserialized object</returns>
348+
public static T Deserialize(string xmlString)
349+
{
350+
T propertyBagContainer;
351+
using (Stream stream = new MemoryStream())
352+
{
353+
byte[] data = System.Text.Encoding.UTF8.GetBytes(xmlString);
354+
stream.Write(data, 0, data.Length);
355+
stream.Position = 0;
356+
DataContractSerializer deserializer = new DataContractSerializer(typeof(T));
357+
propertyBagContainer = (T)deserializer.ReadObject(stream);
358+
}
359+
360+
return propertyBagContainer;
361+
}
362+
}
265363
}

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesNetworkMappingClient.cs

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -42,103 +42,6 @@ public enum NetworkTargetType
4242
Azure,
4343
}
4444

45-
/// <summary>
46-
/// Helper around serialization/deserialization of objects. This one is a thin wrapper around
47-
/// DataContractUtils template class which is the one doing the heavy lifting.
48-
/// </summary>
49-
[SuppressMessage(
50-
"Microsoft.StyleCop.CSharp.MaintainabilityRules",
51-
"SA1402:FileMayOnlyContainASingleClass",
52-
Justification = "Keeping all contracts together.")]
53-
public static class DataContractUtils
54-
{
55-
/// <summary>
56-
/// Serializes the supplied object to the string.
57-
/// </summary>
58-
/// <typeparam name="T">The object type.</typeparam>
59-
/// <param name="obj">Object to serialize</param>
60-
/// <returns>Serialized string.</returns>
61-
public static string Serialize<T>(T obj)
62-
{
63-
return DataContractUtils<T>.Serialize(obj);
64-
}
65-
66-
/// <summary>
67-
/// Deserialize the string to the expected object type.
68-
/// </summary>
69-
/// <typeparam name="T">The object type</typeparam>
70-
/// <param name="xmlString">Serialized string</param>
71-
/// <param name="result">Deserialized object</param>
72-
public static void Deserialize<T>(string xmlString, out T result)
73-
{
74-
result = DataContractUtils<T>.Deserialize(xmlString);
75-
}
76-
}
77-
78-
/// <summary>
79-
/// Template class for DataContractUtils.
80-
/// </summary>
81-
/// <typeparam name="T">The object type</typeparam>
82-
[SuppressMessage(
83-
"Microsoft.StyleCop.CSharp.MaintainabilityRules",
84-
"SA1402:FileMayOnlyContainASingleClass",
85-
Justification = "Keeping all contracts together.")]
86-
public static class DataContractUtils<T>
87-
{
88-
/// <summary>
89-
/// Serializes the propertyBagContainer to the string.
90-
/// </summary>
91-
/// <param name="propertyBagContainer">Property bag</param>
92-
/// <returns>Serialized string </returns>
93-
public static string Serialize(T propertyBagContainer)
94-
{
95-
var serializer = new DataContractSerializer(typeof(T));
96-
string xmlString;
97-
StringWriter sw = null;
98-
try
99-
{
100-
sw = new StringWriter();
101-
using (var writer = new XmlTextWriter(sw))
102-
{
103-
// Indent the XML so it's human readable.
104-
writer.Formatting = Formatting.Indented;
105-
serializer.WriteObject(writer, propertyBagContainer);
106-
writer.Flush();
107-
xmlString = sw.ToString();
108-
}
109-
}
110-
finally
111-
{
112-
if (sw != null)
113-
{
114-
sw.Close();
115-
}
116-
}
117-
118-
return xmlString;
119-
}
120-
121-
/// <summary>
122-
/// Deserialize the string to the propertyBagContainer.
123-
/// </summary>
124-
/// <param name="xmlString">Serialized string</param>
125-
/// <returns>Deserialized object</returns>
126-
public static T Deserialize(string xmlString)
127-
{
128-
T propertyBagContainer;
129-
using (Stream stream = new MemoryStream())
130-
{
131-
byte[] data = System.Text.Encoding.UTF8.GetBytes(xmlString);
132-
stream.Write(data, 0, data.Length);
133-
stream.Position = 0;
134-
DataContractSerializer deserializer = new DataContractSerializer(typeof(T));
135-
propertyBagContainer = (T)deserializer.ReadObject(stream);
136-
}
137-
138-
return propertyBagContainer;
139-
}
140-
}
141-
14245
/// <summary>
14346
/// Create network mapping input.
14447
/// </summary>

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesPEClient.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,13 @@ public JobResponse StartAzureSiteRecoveryCommitFailover(
172172
/// </summary>
173173
/// <param name="protectionContainerId">Protection Container ID</param>
174174
/// <param name="protectionEntityId">Recovery Plan ID</param>
175+
/// <param name="request">Re-protect request.</param>
175176
/// <returns>Job response</returns>
176177
public JobResponse StartAzureSiteRecoveryReprotection(
177178
string protectionContainerId,
178-
string protectionEntityId)
179+
string protectionEntityId,
180+
ReprotectRequest request)
179181
{
180-
var request = new ReprotectRequest();
181182
return this.GetSiteRecoveryClient().ProtectionEntity.Reprotect(
182183
protectionContainerId,
183184
protectionEntityId,

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Service/CreateAzureSiteRecoveryProtectionProfileObject.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,13 @@ private void EnterpriseToAzureProtectionProfileObject()
197197
ReplicationProvider = this.ReplicationProvider,
198198
HyperVReplicaAzureProviderSettingsObject = new HyperVReplicaAzureProviderSettings()
199199
{
200-
ReplicationMethod = this.ReplicationMethod,
201200
RecoveryAzureSubscription = this.RecoveryAzureSubscription,
202201
RecoveryAzureStorageAccountName = this.RecoveryAzureStorageAccount,
203202
EncryptStoredData = this.EncryptStoredData,
204203
ReplicationFrequencyInSeconds = this.ReplicationFrequencyInSeconds,
205204
RecoveryPoints = this.RecoveryPoints,
206205
ApplicationConsistentSnapshotFrequencyInHours = this.ApplicationConsistentSnapshotFrequencyInHours,
207-
CompressionEnabled = this.CompressionEnabled,
208-
ReplicationPort = this.ReplicationPort,
209206
ReplicationStartTime = this.ReplicationStartTime,
210-
AllowReplicaDeletion = this.AllowReplicaDeletion
211207
},
212208
HyperVReplicaProviderSettingsObject = null
213209
};

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Service/SetAzureSiteRecoveryProtectionEntity.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ public override void ExecuteCmdlet()
208208

209209
input.ReplicationProviderInput = DataContractUtils.Serialize<AzureEnableProtectionInput>(azureInput);
210210
}
211+
else
212+
{
213+
input.ReplicationProviderInput = string.Empty;
214+
input.ProtectionProfileId = this.ProtectionProfile.ID;
215+
}
211216

212217
this.jobResponse =
213218
RecoveryServicesClient.EnableProtection(

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Service/StartAzureSiteRecoveryCommitFailoverJob.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ public class StartAzureSiteRecoveryCommitFailoverJob : RecoveryServicesCmdletBas
7070
[ValidateNotNullOrEmpty]
7171
public ASRProtectionEntity ProtectionEntity { get; set; }
7272

73+
/// <summary>
74+
/// Gets or sets Failover direction for the recovery plan.
75+
/// </summary>
76+
[Parameter(Mandatory = false)]
77+
[ValidateSet(
78+
Constants.PrimaryToRecovery,
79+
Constants.RecoveryToPrimary)]
80+
public string Direction { get; set; }
81+
7382
/// <summary>
7483
/// Gets or sets switch parameter. This is required to wait for job completion.
7584
/// </summary>
@@ -116,27 +125,19 @@ private void SetRpCommit()
116125
{
117126
var request = new CommitFailoverRequest();
118127

119-
if (this.ProtectionEntity == null)
128+
if (this.RecoveryPlan == null)
120129
{
121-
var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity(
122-
this.ProtectionContainerId,
123-
this.ProtectionEntityId);
124-
this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity);
130+
var rp = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(
131+
this.RPId);
132+
this.RecoveryPlan = new ASRRecoveryPlan(rp.RecoveryPlan);
125133

126-
this.ValidateUsageById(this.ProtectionEntity.ReplicationProvider);
134+
this.ValidateUsageById(this.RecoveryPlan.ReplicationProvider);
127135
}
128136

129-
request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
137+
request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider;
130138
request.ReplicationProviderSettings = string.Empty;
131139

132-
if (this.ProtectionEntity.ActiveLocation == Constants.PrimaryLocation)
133-
{
134-
request.FailoverDirection = Constants.PrimaryToRecovery;
135-
}
136-
else
137-
{
138-
request.FailoverDirection = Constants.RecoveryToPrimary;
139-
}
140+
request.FailoverDirection = this.Direction;
140141

141142
this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryCommitFailover(
142143
this.RPId);

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Service/StartAzureSiteRecoveryPlannedFailoverJob.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ private void StartPEPlannedFailover()
151151

152152
if (this.ProtectionEntity.ReplicationProvider == Constants.HyperVReplicaAzure)
153153
{
154-
request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
155154
if (this.Direction == Constants.PrimaryToRecovery)
156155
{
157156
var blob = new AzureFailoverInput();
@@ -166,8 +165,14 @@ private void StartPEPlannedFailover()
166165
request.ReplicationProviderSettings = DataContractUtils.Serialize<AzureFailbackInput>(blob);
167166
}
168167
}
168+
else
169+
{
170+
request.ReplicationProviderSettings = string.Empty;
171+
}
169172

173+
request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
170174
request.FailoverDirection = this.Direction;
175+
171176
this.jobResponse =
172177
RecoveryServicesClient.StartAzureSiteRecoveryPlannedFailover(
173178
this.ProtectionContainerId,
@@ -199,7 +204,6 @@ private void StartRpPlannedFailover()
199204

200205
if (this.RecoveryPlan.ReplicationProvider == Constants.HyperVReplicaAzure)
201206
{
202-
request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider;
203207
if (this.Direction == Constants.PrimaryToRecovery)
204208
{
205209
var blob = new AzureFailoverInput();
@@ -215,6 +219,7 @@ private void StartRpPlannedFailover()
215219
}
216220
}
217221

222+
request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider;
218223
request.FailoverDirection = this.Direction;
219224

220225
this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryPlannedFailover(

0 commit comments

Comments
 (0)