Skip to content

Commit 2d5728c

Browse files
committed
Merge pull request #39 from AsrOneSdk/sanjkuma-dev
EndTime and ObjectId filter in GetJob; Commit should show warning for wi...
2 parents dccc0e3 + 4eb3fbe commit 2d5728c

11 files changed

+152
-29
lines changed

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ ClientRequestId: {3}</value>
230230
<data name="NetworkArgumentsMissingForUpdateVmProperties" xml:space="preserve">
231231
<value>Please provide both Source Nic and Recovery Target to update</value>
232232
</data>
233+
<data name="MandatoryParamFromNextRelease" xml:space="preserve">
234+
<value>"'{0}' will be a mandatory paramter from next release."</value>
235+
</data>
236+
<data name="IDBasedParamUsageNotSupportedFromNextRelease" xml:space="preserve">
237+
<value>"Calls using ID based parameter '{0}' will not be supported from next release. Please use its corresponding full object parameter instead."</value>
238+
</data>
233239
<data name="InvalidReplicationFrequency" xml:space="preserve">
234240
<value>Replication Frequency {0} is invalid</value>
235241
</data>

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/RecoveryServicesCmdletBase.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,21 @@ protected override void StopProcessing()
168168
/// Validates if the usage by ID is allowed or not.
169169
/// </summary>
170170
/// <param name="replicationProvider">Replication provider.</param>
171-
protected void ValidateUsageById(string replicationProvider)
171+
/// <param name="paramName">Parameter name.</param>
172+
protected void ValidateUsageById(string replicationProvider, string paramName)
172173
{
173174
if (replicationProvider != Constants.HyperVReplica)
174175
{
175-
throw new Exception("Call using ID parameter is not supported.");
176+
throw new Exception(
177+
string.Format(
178+
Properties.Resources.IDBasedParamUsageNotSupportedFromNextRelease,
179+
paramName));
176180
}
177181
else
178182
{
179-
this.WriteWarning("Call using 'ID' parameter will not be supported from next release. Please use full object parameter instead.");
183+
this.WriteDebugWithTimestamp(
184+
Properties.Resources.IDBasedParamUsageNotSupportedFromNextRelease,
185+
paramName);
180186
}
181187
}
182188

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ public class GetAzureSiteRecoveryJob : RecoveryServicesCmdletBase
5252
[ValidateNotNullOrEmpty]
5353
public DateTime? StartTime { get; set; }
5454

55+
/// <summary>
56+
/// Gets or sets end time. Allows to filter the list of jobs ended before it.
57+
/// </summary>
58+
[Parameter(ParameterSetName = ASRParameterSets.ByParam, HelpMessage = "Represents end time of jobs to query.")]
59+
[ValidateNotNullOrEmpty]
60+
public DateTime? EndTime { get; set; }
61+
62+
/// <summary>
63+
/// Gets or sets target object id.
64+
/// </summary>
65+
[Parameter(ParameterSetName = ASRParameterSets.ByParam, HelpMessage = "ID of the object on which Job was targeted to.")]
66+
[ValidateNotNullOrEmpty]
67+
public string TargetObjectId { get; set; }
68+
5569
/// <summary>
5670
/// Gets or sets state. Take string input for possible States of ASR Job. Use this parameter
5771
/// to get filtered view of Jobs
@@ -121,7 +135,15 @@ private void GetByParam()
121135
this.StartTime.Value.ToUniversalTime().ToBinary().ToString();
122136
}
123137

138+
if (this.EndTime.HasValue)
139+
{
140+
jqp.EndTime =
141+
this.EndTime.Value.ToUniversalTime().ToBinary().ToString();
142+
}
143+
124144
jqp.State = this.State;
145+
jqp.ObjectId = this.TargetObjectId;
146+
125147
this.WriteJobs(RecoveryServicesClient.GetAzureSiteRecoveryJob(jqp).Jobs);
126148
}
127149

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

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,23 +168,47 @@ public override void ExecuteCmdlet()
168168
string profileId = string.Empty;
169169
var input = new EnableProtectionInput();
170170

171+
if (this.ProtectionEntity == null)
172+
{
173+
var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity(
174+
this.ProtectionContainerId,
175+
this.Id);
176+
this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity);
177+
}
178+
171179
// Get the replciation provider from profile object otherwise assume its E2E.
172180
// Let the call go without profileId set.
173-
string replicationProvider = Constants.HyperVReplica;
181+
string replicationProvider = null;
182+
174183
if (this.ProtectionProfile != null)
175184
{
176185
profileId = this.ProtectionProfile.ID;
177186
replicationProvider = this.ProtectionProfile.ReplicationProvider;
178187
}
179-
180-
if (this.ProtectionEntity == null)
188+
else
181189
{
182-
var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity(
183-
this.ProtectionContainerId,
184-
this.Id);
185-
this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity);
190+
this.WriteDebugWithTimestamp(
191+
Properties.Resources.MandatoryParamFromNextRelease,
192+
"ProtectionProfile");
193+
string pcId = this.ProtectionContainerId ?? this.ProtectionEntity.ProtectionContainerId;
194+
var pc = RecoveryServicesClient.GetAzureSiteRecoveryProtectionContainer(
195+
pcId);
196+
197+
// PC will have all profiles associated with same replciation providers only.
198+
replicationProvider =
199+
pc.ProtectionContainer.AvailableProtectionProfiles.Count < 1 ?
200+
null :
201+
pc.ProtectionContainer.AvailableProtectionProfiles[0].ReplicationProvider;
186202

187-
this.ValidateUsageById(replicationProvider);
203+
if (replicationProvider != Constants.HyperVReplica)
204+
{
205+
throw new Exception("Please provide the protection profile object. It can be chosen from available protection profiles of the protection container.");
206+
}
207+
}
208+
209+
if (this.ParameterSetName == ASRParameterSets.ByIDs)
210+
{
211+
this.ValidateUsageById(replicationProvider, "Id");
188212
}
189213

190214
if (replicationProvider == Constants.HyperVReplicaAzure)

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ public override void ExecuteCmdlet()
9393
{
9494
try
9595
{
96+
if (string.IsNullOrEmpty(this.Direction))
97+
{
98+
this.WriteDebugWithTimestamp(
99+
Properties.Resources.MandatoryParamFromNextRelease,
100+
Constants.Direction);
101+
}
102+
96103
switch (this.ParameterSetName)
97104
{
98105
case ASRParameterSets.ByRPObject:
@@ -131,7 +138,7 @@ private void SetRpCommit()
131138
this.RPId);
132139
this.RecoveryPlan = new ASRRecoveryPlan(rp.RecoveryPlan);
133140

134-
this.ValidateUsageById(this.RecoveryPlan.ReplicationProvider);
141+
this.ValidateUsageById(this.RecoveryPlan.ReplicationProvider, "RPId");
135142
}
136143

137144
request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider;
@@ -164,7 +171,9 @@ private void SetPECommit()
164171
this.ProtectionEntityId);
165172
this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity);
166173

167-
this.ValidateUsageById(this.ProtectionEntity.ReplicationProvider);
174+
this.ValidateUsageById(
175+
this.ProtectionEntity.ReplicationProvider,
176+
Constants.ProtectionEntityId);
168177
}
169178

170179
request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,13 @@ public class StartAzureSiteRecoveryPlannedFailoverJob : RecoveryServicesCmdletBa
5858
/// Gets or sets Recovery Plan object.
5959
/// </summary>
6060
[Parameter(ParameterSetName = ASRParameterSets.ByRPObject, Mandatory = true, ValueFromPipeline = true)]
61-
[Parameter(ParameterSetName = ASRParameterSets.ByRPObjectE2AFailback, Mandatory = true, ValueFromPipeline = true)]
6261
[ValidateNotNullOrEmpty]
6362
public ASRRecoveryPlan RecoveryPlan { get; set; }
6463

6564
/// <summary>
6665
/// Gets or sets Protection Entity object.
6766
/// </summary>
6867
[Parameter(ParameterSetName = ASRParameterSets.ByPEObject, Mandatory = true, ValueFromPipeline = true)]
69-
[Parameter(ParameterSetName = ASRParameterSets.ByPEObjectE2AFailback, Mandatory = true, ValueFromPipeline = true)]
7068
[ValidateNotNullOrEmpty]
7169
public ASRProtectionEntity ProtectionEntity { get; set; }
7270

@@ -88,8 +86,7 @@ public class StartAzureSiteRecoveryPlannedFailoverJob : RecoveryServicesCmdletBa
8886
/// <summary>
8987
/// Gets or sets the Optimize value.
9088
/// </summary>
91-
[Parameter(ParameterSetName = ASRParameterSets.ByPEObjectE2AFailback)]
92-
[Parameter(ParameterSetName = ASRParameterSets.ByPEObjectE2AFailback)]
89+
[Parameter]
9390
[ValidateSet(
9491
Constants.ForDowntime,
9592
Constants.ForSynchronization)]
@@ -112,12 +109,10 @@ public override void ExecuteCmdlet()
112109
switch (this.ParameterSetName)
113110
{
114111
case ASRParameterSets.ByRPObject:
115-
case ASRParameterSets.ByRPObjectE2AFailback:
116112
this.RPId = this.RecoveryPlan.ID;
117113
this.StartRpPlannedFailover();
118114
break;
119115
case ASRParameterSets.ByPEObject:
120-
case ASRParameterSets.ByPEObjectE2AFailback:
121116
this.ProtectionEntityId = this.ProtectionEntity.ID;
122117
this.ProtectionContainerId = this.ProtectionEntity.ProtectionContainerId;
123118
this.StartPEPlannedFailover();
@@ -150,7 +145,7 @@ private void StartPEPlannedFailover()
150145
this.ProtectionEntityId);
151146
this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity);
152147

153-
this.ValidateUsageById(this.ProtectionEntity.ReplicationProvider);
148+
this.ValidateUsageById(this.ProtectionEntity.ReplicationProvider, Constants.ProtectionEntityId);
154149
}
155150

156151
if (this.ProtectionEntity.ReplicationProvider == Constants.HyperVReplicaAzure)
@@ -203,7 +198,9 @@ private void StartRpPlannedFailover()
203198
this.RPId);
204199
this.RecoveryPlan = new ASRRecoveryPlan(rp.RecoveryPlan);
205200

206-
this.ValidateUsageById(this.RecoveryPlan.ReplicationProvider);
201+
this.ValidateUsageById(
202+
this.RecoveryPlan.ReplicationProvider,
203+
Constants.RPId);
207204
}
208205

209206
if (this.RecoveryPlan.ReplicationProvider == Constants.HyperVReplicaAzure)

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,16 @@ public override void ExecuteCmdlet()
156156
{
157157
if (this.NetworkType == null)
158158
{
159-
this.WriteWarning("'NetworkType' will be a mandatory paramter from next release.");
159+
this.WriteDebugWithTimestamp(
160+
Properties.Resources.MandatoryParamFromNextRelease,
161+
Constants.NetworkType);
160162
}
161163

162164
if (this.VmNetworkId != null)
163165
{
164-
this.WriteWarning("Call using 'NetworkId' parameter will not be supported from next release. Please use 'Network' parameter instead.");
166+
this.WriteDebugWithTimestamp(
167+
Properties.Resources.IDBasedParamUsageNotSupportedFromNextRelease,
168+
"VmNetworkId");
165169
}
166170

167171
if (this.NetworkType == Constants.Existing && (this.Network == null && this.VmNetworkId == null))
@@ -269,7 +273,9 @@ private void StartRpTestFailover()
269273
this.RpId);
270274
this.RecoveryPlan = new ASRRecoveryPlan(rp.RecoveryPlan);
271275

272-
this.ValidateUsageById(this.RecoveryPlan.ReplicationProvider);
276+
this.ValidateUsageById(
277+
this.RecoveryPlan.ReplicationProvider,
278+
Constants.RPId);
273279
}
274280

275281
request.ReplicationProviderSettings = string.Empty;
@@ -316,7 +322,9 @@ private void StartPETestFailover()
316322
this.ProtectionEntityId);
317323
this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity);
318324

319-
this.ValidateUsageById(this.ProtectionEntity.ReplicationProvider);
325+
this.ValidateUsageById(
326+
this.ProtectionEntity.ReplicationProvider,
327+
Constants.ProtectionEntityId);
320328
}
321329

322330
request.ReplicationProviderSettings = string.Empty;

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ private void StartPEUnplannedFailover()
149149
this.ProtectionEntityId);
150150
this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity);
151151

152-
this.ValidateUsageById(this.ProtectionEntity.ReplicationProvider);
152+
this.ValidateUsageById(
153+
this.ProtectionEntity.ReplicationProvider,
154+
Constants.ProtectionEntityId);
153155
}
154156

155157
request.ReplicationProviderSettings = string.Empty;
@@ -194,7 +196,9 @@ private void StartRpUnPlannedFailover()
194196
this.RPId);
195197
this.RecoveryPlan = new ASRRecoveryPlan(rp.RecoveryPlan);
196198

197-
this.ValidateUsageById(this.RecoveryPlan.ReplicationProvider);
199+
this.ValidateUsageById(
200+
this.RecoveryPlan.ReplicationProvider,
201+
Constants.RPId);
198202
}
199203

200204
request.ReplicationProviderSettings = string.Empty;

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ private void SetRpReprotect()
129129
this.RPId);
130130
this.RecoveryPlan = new ASRRecoveryPlan(rp.RecoveryPlan);
131131

132-
this.ValidateUsageById(this.RecoveryPlan.ReplicationProvider);
132+
this.ValidateUsageById(
133+
this.RecoveryPlan.ReplicationProvider,
134+
Constants.RPId);
133135
}
134136

135137
request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider;
@@ -170,7 +172,9 @@ private void SetPEReprotect()
170172
this.ProtectionEntityId);
171173
this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity);
172174

173-
this.ValidateUsageById(this.ProtectionEntity.ReplicationProvider);
175+
this.ValidateUsageById(
176+
this.ProtectionEntity.ReplicationProvider,
177+
this.ProtectionEntityId);
174178
}
175179

176180
request.ReplicationProviderSettings = string.Empty;

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/lib/PSObjects.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,31 @@ public class Constants
188188
/// </summary>
189189
public const string DisableProtection = "Disable";
190190

191+
/// <summary>
192+
/// Represents Direction string value.
193+
/// </summary>
194+
public const string Direction = "Direction";
195+
196+
/// <summary>
197+
/// Represents RPId string value.
198+
/// </summary>
199+
public const string RPId = "RPId";
200+
201+
/// <summary>
202+
/// Represents ID string value.
203+
/// </summary>
204+
public const string ID = "ID";
205+
206+
/// <summary>
207+
/// Represents NetworkType string value.
208+
/// </summary>
209+
public const string NetworkType = "NetworkType";
210+
211+
/// <summary>
212+
/// Represents ProtectionEntityId string value.
213+
/// </summary>
214+
public const string ProtectionEntityId = "ProtectionEntityId";
215+
191216
/// <summary>
192217
/// Azure fabric Id. In E2A context Recovery Server Id is always this.
193218
/// </summary>

0 commit comments

Comments
 (0)