Skip to content

Commit d9cc0d1

Browse files
committed
Got rid of the linq zip expression in PoolUsageMetrics batchtesthelper
1 parent 4dc63ea commit d9cc0d1

12 files changed

+123
-75
lines changed

src/ResourceManager/AzureBatch/Commands.Batch.Test/BatchTestHelpers.cs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -392,20 +392,28 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
392392
}
393393

394394
/// <summary>
395-
/// Builds a CloudPoolUsageMetricsResponse object
395+
/// Builds a CloudPoolUsageMetricsResponse object.
396396
/// </summary>
397397
public static AzureOperationResponse<IPage<ProxyModels.PoolUsageMetrics>, ProxyModels.PoolListPoolUsageMetricsHeaders> CreatePoolListUsageMetricsResponse(
398398
IEnumerable<string> poolIds,
399399
IEnumerable<DateTime> startTimes,
400400
IEnumerable<DateTime> endTimes)
401401
{
402-
var poolUsageList = poolIds.Zip(startTimes.Zip(endTimes, Tuple.Create),
403-
(poolId, tuple) => new ProxyModels.PoolUsageMetrics()
402+
var s = startTimes.GetEnumerator();
403+
var e = endTimes.GetEnumerator();
404+
var p = poolIds.GetEnumerator();
405+
var poolUsageList = new List<ProxyModels.PoolUsageMetrics>();
406+
407+
// Create x PoolUsageMetrics where x is the smallest length of the three lists
408+
while (s.MoveNext() && e.MoveNext() && p.MoveNext())
409+
{
410+
poolUsageList.Add(new ProxyModels.PoolUsageMetrics()
404411
{
405-
PoolId = poolId,
406-
StartTime = tuple.Item1,
407-
EndTime = tuple.Item2
412+
PoolId = p.Current,
413+
StartTime = s.Current,
414+
EndTime = e.Current
408415
});
416+
}
409417

410418
var response = new AzureOperationResponse
411419
<IPage<ProxyModels.PoolUsageMetrics>, ProxyModels.PoolListPoolUsageMetricsHeaders>()
@@ -418,14 +426,16 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
418426
}
419427

420428
/// <summary>
421-
/// Builds a CloudPoolStatisticsResponse object
429+
/// Builds a CloudPoolStatisticsResponse object. Note: Using avgCPUPercentage and startTime for validating if the pipeline return the correct values
422430
/// </summary>
423-
public static AzureOperationResponse<ProxyModels.PoolStatistics, ProxyModels.PoolGetAllPoolsLifetimeStatisticsHeaders> CreatePoolStatisticsResponse()
431+
public static AzureOperationResponse<ProxyModels.PoolStatistics, ProxyModels.PoolGetAllPoolsLifetimeStatisticsHeaders> CreatePoolStatisticsResponse(
432+
double avgCPUPercentage,
433+
DateTime startTime)
424434
{
425435
var stats = new ProxyModels.PoolStatistics()
426436
{
427-
ResourceStats = new ProxyModels.ResourceStatistics(),
428-
UsageStats = new ProxyModels.UsageStatistics()
437+
ResourceStats = new ProxyModels.ResourceStatistics() { AvgCPUPercentage = avgCPUPercentage },
438+
UsageStats = new ProxyModels.UsageStatistics() { StartTime = startTime }
429439
};
430440

431441
var response = new AzureOperationResponse
@@ -439,11 +449,14 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
439449
}
440450

441451
/// <summary>
442-
/// Builds a CloudJobStatisticsResponse object
452+
/// Builds a CloudJobStatisticsResponse object.Note: Using startTime for validating if the pipeline return the correct values
443453
/// </summary>
444-
public static AzureOperationResponse<ProxyModels.JobStatistics, ProxyModels.JobGetAllJobsLifetimeStatisticsHeaders> CreateJobStatisticsResponse()
454+
public static AzureOperationResponse<ProxyModels.JobStatistics, ProxyModels.JobGetAllJobsLifetimeStatisticsHeaders> CreateJobStatisticsResponse(DateTime startTime)
445455
{
446-
var stats = new ProxyModels.JobStatistics();
456+
var stats = new ProxyModels.JobStatistics()
457+
{
458+
StartTime = startTime
459+
};
447460

448461
var response = new AzureOperationResponse
449462
<ProxyModels.JobStatistics, ProxyModels.JobGetAllJobsLifetimeStatisticsHeaders>()

src/ResourceManager/AzureBatch/Commands.Batch.Test/Jobs/GetBatchJobStatisticsCommandTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,26 @@ public void GetBatchJobStatisticsTest()
5454
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
5555
cmdlet.BatchContext = context;
5656

57+
DateTime startTime = DateTime.UtcNow;
58+
5759
AzureOperationResponse<
5860
ProxyModels.JobStatistics,
5961
ProxyModels.JobGetAllJobsLifetimeStatisticsHeaders> response =
60-
BatchTestHelpers.CreateJobStatisticsResponse();
62+
BatchTestHelpers.CreateJobStatisticsResponse(startTime);
6163

6264
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
6365
ProxyModels.JobGetAllJobsLifetimeStatisticsOptions,
6466
AzureOperationResponse<ProxyModels.JobStatistics, ProxyModels.JobGetAllJobsLifetimeStatisticsHeaders>>(responseToUse: response);
6567

6668
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
6769

68-
// Setup the cmdlet to write pipeline output to a list that can be examined later
70+
// Setup the cmdlet to write pipeline output to a variable that can be examined later
6971
PSJobStatistics statistics = null;
7072
commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny<PSJobStatistics>())).Callback<object>(c => statistics = (PSJobStatistics)c);
7173

7274
cmdlet.ExecuteCmdlet();
7375

74-
Assert.NotNull(statistics);
76+
Assert.Equal(startTime, statistics.StartTime);
7577
}
7678
}
7779
}

src/ResourceManager/AzureBatch/Commands.Batch.Test/Pools/GetBatchPoolStatisticsCommandTests.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,29 @@ public void GetBatchPoolStatisticsTest()
5454
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
5555
cmdlet.BatchContext = context;
5656

57+
double avgCPUPercentage = 10;
58+
DateTime startTime = DateTime.UtcNow;
59+
5760
AzureOperationResponse<
5861
ProxyModels.PoolStatistics,
5962
ProxyModels.PoolGetAllPoolsLifetimeStatisticsHeaders> response =
60-
BatchTestHelpers.CreatePoolStatisticsResponse();
63+
BatchTestHelpers.CreatePoolStatisticsResponse(avgCPUPercentage, startTime);
6164

6265
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
6366
ProxyModels.PoolGetAllPoolsLifetimeStatisticsOptions,
6467
AzureOperationResponse<ProxyModels.PoolStatistics, ProxyModels.PoolGetAllPoolsLifetimeStatisticsHeaders>>(responseToUse: response);
6568

6669
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
6770

68-
// Setup the cmdlet to write pipeline output to a list that can be examined later
71+
// Setup the cmdlet to write pipeline output to a variable that can be examined later
6972
PSPoolStatistics statistics = null;
7073
commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny<PSPoolStatistics>())).Callback<object>(c => statistics = (PSPoolStatistics)c);
7174

7275
cmdlet.ExecuteCmdlet();
7376

7477
Assert.NotNull(statistics);
78+
Assert.Equal(startTime, statistics.UsageStatistics.StartTime);
79+
Assert.Equal(avgCPUPercentage, statistics.ResourceStatistics.AverageCpuPercentage);
7580
}
7681
}
7782
}

src/ResourceManager/AzureBatch/Commands.Batch/Jobs/GetBatchJobStatisticsCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class GetBatchJobStatisticsCommand : BatchObjectModelCmdletBase
2424
{
2525
public override void ExecuteCmdlet()
2626
{
27-
PSJobStatistics jobStatistics = BatchClient.GetAggregateJobStatistics(this.BatchContext, this.AdditionalBehaviors);
27+
PSJobStatistics jobStatistics = BatchClient.GetAllJobsLifetimeStatistics(this.BatchContext, this.AdditionalBehaviors);
2828
WriteObject(jobStatistics);
2929
}
3030
}

src/ResourceManager/AzureBatch/Commands.Batch/Microsoft.Azure.Commands.Batch.dll-Help.xml

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4362,21 +4362,21 @@
43624362
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
43634363
<maml:name>EndTime</maml:name>
43644364
<maml:description>
4365-
<maml:para>The end time of the aggregation interval for this entry</maml:para>
4365+
<maml:para>The end time should be at least two hours earlier. If not specified, it defaults to the end time of the last aggregation interval currently available.</maml:para>
43664366
</maml:description>
43674367
<command:parameterValue required="true" variableLength="false">DateTime</command:parameterValue>
43684368
</command:parameter>
43694369
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
43704370
<maml:name>Filter</maml:name>
43714371
<maml:description>
4372-
<maml:para>The OData filter clause to use when querying for pools. If no filter is specified, then all pools under the Batch account specified with the BatchContext parameter will be returned.</maml:para>
4372+
<maml:para>The OData filter clause to use to filter the list of metrics returned. The only valid property is poolId with a string value. Possible operations are: eq, ge, gt, le, lt, startswith.</maml:para>
43734373
</maml:description>
43744374
<command:parameterValue required="true" variableLength="false">string</command:parameterValue>
43754375
</command:parameter>
43764376
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
43774377
<maml:name>StartTime</maml:name>
43784378
<maml:description>
4379-
<maml:para>The start time of the aggregation interval covered by this entry.</maml:para>
4379+
<maml:para>The start time should be at least two and half hours earlier. If not specified, it defaults to the start time of the last aggregation interval currently available.</maml:para>
43804380
</maml:description>
43814381
<command:parameterValue required="true" variableLength="false">DateTime</command:parameterValue>
43824382
</command:parameter>
@@ -4399,7 +4399,7 @@
43994399
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
44004400
<maml:name>EndTime</maml:name>
44014401
<maml:description>
4402-
<maml:para>The end time of the aggregation interval for this entry</maml:para>
4402+
<maml:para>The end time should be at least two hours earlier. If not specified, it defaults to the end time of the last aggregation interval currently available.</maml:para>
44034403
</maml:description>
44044404
<command:parameterValue required="true" variableLength="false">DateTime</command:parameterValue>
44054405
<dev:type>
@@ -4411,7 +4411,7 @@
44114411
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
44124412
<maml:name>Filter</maml:name>
44134413
<maml:description>
4414-
<maml:para>The OData filter clause to use when querying for pools. If no filter is specified, then all pools under the Batch account specified with the BatchContext parameter will be returned.</maml:para>
4414+
<maml:para>The OData filter clause to use to filter the list of metrics returned. The only valid property is poolId with a string value. Possible operations are: eq, ge, gt, le, lt, startswith.</maml:para>
44154415
</maml:description>
44164416
<command:parameterValue required="true" variableLength="false">string</command:parameterValue>
44174417
<dev:type>
@@ -4423,7 +4423,7 @@
44234423
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
44244424
<maml:name>StartTime</maml:name>
44254425
<maml:description>
4426-
<maml:para>The start time of the aggregation interval covered by this entry.</maml:para>
4426+
<maml:para>The start time should be at least two and half hours earlier. If not specified, it defaults to the start time of the last aggregation interval currently available.</maml:para>
44274427
</maml:description>
44284428
<command:parameterValue required="true" variableLength="false">DateTime</command:parameterValue>
44294429
<dev:type>
@@ -4511,7 +4511,32 @@
45114511
<dev:remarks>
45124512
<maml:para>Description</maml:para>
45134513
<maml:para>-----------</maml:para>
4514-
<maml:para>These commands queries for usage metrics, aggregated by each pool between Monday, May 16, 2016 12:00:00 AM and Monday, May 16, 2016 1:00:00 AM</maml:para>
4514+
<maml:para>These commands return all of the pool usage metrics, aggregated by each pool between Monday, May 16, 2016 12:00:00 AM and Monday, May 16, 2016 1:00:00 AM</maml:para>
4515+
</dev:remarks>
4516+
</command:example>
4517+
<command:example>
4518+
<maml:title>
4519+
-------------------------- EXAMPLE 2 --------------------------
4520+
</maml:title>
4521+
<maml:introduction>
4522+
<maml:para>C:\PS&gt;</maml:para>
4523+
</maml:introduction>
4524+
<dev:code>
4525+
$filter = &quot;poolId eq 'MyPool'&quot;
4526+
Get-AzureBatchPoolUsageMetrics -Filter $filter -BatchContext $context
4527+
4528+
DataEgressGiB : 9.0496614575386E-06
4529+
DataIngressGiB : 2.60043889284134E-05
4530+
EndTime : 5/16/2016 5:30:00 PM
4531+
PoolId : MyPool
4532+
StartTime : 5/16/2016 5:00:00 PM
4533+
TotalCoreHours : 12
4534+
VirtualMachineSize : standard_d4
4535+
</dev:code>
4536+
<dev:remarks>
4537+
<maml:para>Description</maml:para>
4538+
<maml:para>-----------</maml:para>
4539+
<maml:para>The command gets the usage metrics for pool MyPool with a filter string.</maml:para>
45154540
</dev:remarks>
45164541
</command:example>
45174542
</command:examples>

src/ResourceManager/AzureBatch/Commands.Batch/Models/BatchClient.Jobs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ public void TerminateJob(TerminateJobParameters parameters)
254254
/// </summary>
255255
/// <param name="context">The account to use.</param>
256256
/// <param name="additionalBehaviors">Additional client behaviors to perform.</param>
257-
public PSJobStatistics GetAggregateJobStatistics(BatchAccountContext context, IEnumerable<BatchClientBehavior> additionalBehaviors = null)
257+
public PSJobStatistics GetAllJobsLifetimeStatistics(BatchAccountContext context, IEnumerable<BatchClientBehavior> additionalBehaviors = null)
258258
{
259-
WriteVerbose(Resources.GetJobLifeStatistics);
259+
WriteVerbose(Resources.GetAllJobsLifetimeStatistics);
260260

261261
JobOperations jobOperations = context.BatchOMClient.JobOperations;
262262
JobStatistics jobStatistics = jobOperations.GetAllJobsLifetimeStatistics(additionalBehaviors);

src/ResourceManager/AzureBatch/Commands.Batch/Models/BatchClient.Pools.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,16 @@ public IEnumerable<PSCloudPool> ListPools(ListPoolOptions options)
6969
}
7070
}
7171

72-
public PSPoolStatistics ListAllPoolsLifetimeStatistics(BatchAccountContext context, IEnumerable<BatchClientBehavior> additionBehaviors = null)
72+
/// <summary>
73+
/// Gets all pools lifetime summary statistics
74+
/// </summary>
75+
/// <param name="context">The account to use.</param>
76+
/// <param name="additionBehaviors">Additional client behaviors to perform.</param>
77+
public PSPoolStatistics GetAllPoolsLifetimeStatistics(BatchAccountContext context, IEnumerable<BatchClientBehavior> additionBehaviors = null)
7378
{
7479
PoolOperations poolOperations = context.BatchOMClient.PoolOperations;
7580

76-
WriteVerbose(string.Format(Resources.GetPoolLifetimeStatistics));
81+
WriteVerbose(string.Format(Resources.GetAllPoolsLifetimeStatistics));
7782

7883
PoolStatistics poolStatistics = poolOperations.GetAllPoolsLifetimeStatistics(additionBehaviors);
7984
PSPoolStatistics psPoolStatistics = new PSPoolStatistics(poolStatistics);
@@ -310,15 +315,15 @@ public void ChangeOSVersion(ChangeOSVersionParameters parameters)
310315
/// Lists the usage metrics, aggregated by pool across individual time intervals, for the specified account.
311316
/// </summary>
312317
/// <param name="options">The options to use when aggregating usage for pools.</param>
313-
public IEnumerable<PSPoolUsageMetrics> GetPoolUsageMetrics(ListPoolUsageOptions options)
318+
public IEnumerable<PSPoolUsageMetrics> ListPoolUsageMetrics(ListPoolUsageOptions options)
314319
{
315320
string verboseLogString = null;
316-
ODATADetailLevel getDetailLevel = null;
321+
ODATADetailLevel detailLevel = null;
317322

318323
if (!string.IsNullOrEmpty(options.Filter))
319324
{
320-
verboseLogString = Resources.GetPoolUsageMetricsByOData;
321-
getDetailLevel = new ODATADetailLevel(filterClause: options.Filter);
325+
verboseLogString = Resources.GetPoolUsageMetricsByFilter;
326+
detailLevel = new ODATADetailLevel(filterClause: options.Filter);
322327
}
323328
else
324329
{
@@ -327,12 +332,10 @@ public IEnumerable<PSPoolUsageMetrics> GetPoolUsageMetrics(ListPoolUsageOptions
327332

328333
PoolOperations poolOperations = options.Context.BatchOMClient.PoolOperations;
329334
IPagedEnumerable<PoolUsageMetrics> poolUsageMetrics =
330-
poolOperations.ListPoolUsageMetrics(options.StartTime, options.EndTime, getDetailLevel, options.AdditionalBehaviors);
331-
332-
Func<PoolUsageMetrics, PSPoolUsageMetrics> mappingFunction = p => { return new PSPoolUsageMetrics(p); };
335+
poolOperations.ListPoolUsageMetrics(options.StartTime, options.EndTime, detailLevel, options.AdditionalBehaviors);
333336

334337
return PSPagedEnumerable<PSPoolUsageMetrics, PoolUsageMetrics>.CreateWithMaxCount(
335-
poolUsageMetrics, mappingFunction, Int32.MaxValue, () => WriteVerbose(verboseLogString));
338+
poolUsageMetrics, p => new PSPoolUsageMetrics(p), Int32.MaxValue, () => WriteVerbose(verboseLogString));
336339
}
337340
}
338341
}

src/ResourceManager/AzureBatch/Commands.Batch/Models/ListPoolUsageOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ public ListPoolUsageOptions(BatchAccountContext context, IEnumerable<BatchClient
3232
/// <summary>
3333
/// If specified, sets the start time of the last aggregation interval
3434
/// </summary>
35-
public DateTime StartTime{ get; set; }
35+
public DateTime? StartTime{ get; set; }
3636

3737
/// <summary>
3838
/// If specified, sets the end time of the last aggregation interval
3939
/// </summary>
40-
public DateTime EndTime { get; set; }
40+
public DateTime? EndTime { get; set; }
4141
}
4242
}

src/ResourceManager/AzureBatch/Commands.Batch/Pools/GetBatchPoolStatisticsCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class GetBatchPoolStatisticsCommand : BatchObjectModelCmdletBase
2424
{
2525
public override void ExecuteCmdlet()
2626
{
27-
PSPoolStatistics poolStatistics = BatchClient.ListAllPoolsLifetimeStatistics(this.BatchContext, this.AdditionalBehaviors);
27+
PSPoolStatistics poolStatistics = BatchClient.GetAllPoolsLifetimeStatistics(this.BatchContext, this.AdditionalBehaviors);
2828
WriteObject(poolStatistics);
2929
}
3030
}

src/ResourceManager/AzureBatch/Commands.Batch/Pools/GetBatchPoolUsageMetricsCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ public class GetBatchPoolUsageMetrics : BatchObjectModelCmdletBase
2525
{
2626
[Parameter]
2727
[ValidateNotNullOrEmpty]
28-
public DateTime StartTime { get; set; }
28+
public DateTime? StartTime { get; set; }
2929

3030
[Parameter]
3131
[ValidateNotNullOrEmpty]
32-
public DateTime EndTime { get; set; }
32+
public DateTime? EndTime { get; set; }
3333

3434
[Parameter]
3535
[ValidateNotNullOrEmpty]
@@ -44,7 +44,7 @@ public override void ExecuteCmdlet()
4444
Filter = this.Filter,
4545
};
4646

47-
foreach (PSPoolUsageMetrics poolUsageMetrics in BatchClient.GetPoolUsageMetrics(options))
47+
foreach (PSPoolUsageMetrics poolUsageMetrics in BatchClient.ListPoolUsageMetrics(options))
4848
{
4949
WriteObject(poolUsageMetrics);
5050
}

0 commit comments

Comments
 (0)