Skip to content

Commit 46f09ae

Browse files
author
jasper-schneider
committed
Create data models for convenience client calls per feedback
1 parent fce43fb commit 46f09ae

18 files changed

+399
-109
lines changed

src/ResourceManager/Batch/Commands.Batch.Test/Jobs/GetBatchJobCommandTests.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,6 @@ public void ListJobsMaxCountTest()
176176
// Verify default max count
177177
Assert.Equal(Microsoft.Azure.Commands.Batch.Utils.Constants.DefaultMaxCount, cmdlet.MaxCount);
178178

179-
// Verify setting max count <= 0
180-
cmdlet.MaxCount = -5;
181-
Assert.Equal(int.MaxValue, cmdlet.MaxCount);
182-
183179
// Setup cmdlet to list Jobs without filters and a max count
184180
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
185181
cmdlet.BatchContext = context;
@@ -214,6 +210,13 @@ public void ListJobsMaxCountTest()
214210

215211
// Verify that the max count was respected
216212
Assert.Equal(maxCount, pipeline.Count);
213+
214+
// Verify setting max count <= 0 doesn't return nothing
215+
cmdlet.MaxCount = -5;
216+
pipeline.Clear();
217+
cmdlet.ExecuteCmdlet();
218+
219+
Assert.Equal(namesOfConstructedJobs.Length, pipeline.Count);
217220
}
218221
}
219222
}

src/ResourceManager/Batch/Commands.Batch.Test/Pools/GetBatchPoolCommandTests.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,6 @@ public void ListPoolsMaxCountTest()
173173
// Verify default max count
174174
Assert.Equal(Microsoft.Azure.Commands.Batch.Utils.Constants.DefaultMaxCount, cmdlet.MaxCount);
175175

176-
// Verify setting max count <= 0
177-
cmdlet.MaxCount = -5;
178-
Assert.Equal(int.MaxValue, cmdlet.MaxCount);
179-
180176
// Setup cmdlet to list Pools without filters and a max count
181177
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
182178
cmdlet.BatchContext = context;
@@ -210,6 +206,13 @@ public void ListPoolsMaxCountTest()
210206

211207
// Verify that the max count was respected
212208
Assert.Equal(maxCount, pipeline.Count);
209+
210+
// Verify setting max count <= 0 doesn't return nothing
211+
cmdlet.MaxCount = -5;
212+
pipeline.Clear();
213+
cmdlet.ExecuteCmdlet();
214+
215+
Assert.Equal(namesOfConstructedPools.Length, pipeline.Count);
213216
}
214217
}
215218
}

src/ResourceManager/Batch/Commands.Batch.Test/ScenarioTests/ScenarioTestHelpers.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,16 @@ public static string WaitForRecentJob(BatchController controller, BatchAccountCo
134134
YieldInjectionInterceptor interceptor = CreateHttpRecordingInterceptor();
135135
BatchClientBehavior[] behaviors = new BatchClientBehavior[] { interceptor };
136136
BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient);
137-
PSCloudWorkItem workItem = client.ListWorkItems(context, workItemName, null, Constants.DefaultMaxCount, behaviors).First();
137+
138+
ListWorkItemOptions options = new ListWorkItemOptions()
139+
{
140+
Context = context,
141+
WorkItemName = workItemName,
142+
Filter = null,
143+
MaxCount = Constants.DefaultMaxCount,
144+
AdditionalBehaviors = behaviors
145+
};
146+
PSCloudWorkItem workItem = client.ListWorkItems(options).First();
138147

139148
while (workItem.ExecutionInformation.RecentJob == null || string.Equals(workItem.ExecutionInformation.RecentJob.Name, previousJob, StringComparison.OrdinalIgnoreCase))
140149
{
@@ -143,7 +152,7 @@ public static string WaitForRecentJob(BatchController controller, BatchAccountCo
143152
throw new TimeoutException("Timed out waiting for recent job");
144153
}
145154
Sleep(5000);
146-
workItem = client.ListWorkItems(context, workItemName, null, Constants.DefaultMaxCount, behaviors).First();
155+
workItem = client.ListWorkItems(options).First();
147156
}
148157
return workItem.ExecutionInformation.RecentJob.Name;
149158
}

src/ResourceManager/Batch/Commands.Batch.Test/Tasks/GetBatchTaskCommandTests.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,6 @@ public void ListTasksMaxCountTest()
179179
// Verify default max count
180180
Assert.Equal(Microsoft.Azure.Commands.Batch.Utils.Constants.DefaultMaxCount, cmdlet.MaxCount);
181181

182-
// Verify setting max count <= 0
183-
cmdlet.MaxCount = -5;
184-
Assert.Equal(int.MaxValue, cmdlet.MaxCount);
185-
186182
// Setup cmdlet to list Tasks without filters and a max count
187183
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
188184
cmdlet.BatchContext = context;
@@ -218,6 +214,13 @@ public void ListTasksMaxCountTest()
218214

219215
// Verify that the max count was respected
220216
Assert.Equal(maxCount, pipeline.Count);
217+
218+
// Verify setting max count <= 0 doesn't return nothing
219+
cmdlet.MaxCount = -5;
220+
pipeline.Clear();
221+
cmdlet.ExecuteCmdlet();
222+
223+
Assert.Equal(namesOfConstructedTasks.Length, pipeline.Count);
221224
}
222225
}
223226
}

src/ResourceManager/Batch/Commands.Batch.Test/WorkItems/GetBatchWorkItemCommandTests.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,6 @@ public void ListWorkItemMaxCountTest()
173173
// Verify default max count
174174
Assert.Equal(Microsoft.Azure.Commands.Batch.Utils.Constants.DefaultMaxCount, cmdlet.MaxCount);
175175

176-
// Verify setting max count <= 0
177-
cmdlet.MaxCount = -5;
178-
Assert.Equal(int.MaxValue, cmdlet.MaxCount);
179-
180176
// Setup cmdlet to list WorkItems without filters and a max count
181177
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
182178
cmdlet.BatchContext = context;
@@ -210,6 +206,13 @@ public void ListWorkItemMaxCountTest()
210206

211207
// Verify that the max count was respected
212208
Assert.Equal(maxCount, pipeline.Count);
209+
210+
// Verify setting max count <= 0 doesn't return nothing
211+
cmdlet.MaxCount = -5;
212+
pipeline.Clear();
213+
cmdlet.ExecuteCmdlet();
214+
215+
Assert.Equal(namesOfConstructedWorkItems.Length, pipeline.Count);
213216
}
214217

215218
}

src/ResourceManager/Batch/Commands.Batch/Commands.Batch.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@
152152
<Compile Include="Models\BatchClient.Pools.cs" />
153153
<Compile Include="Models\BatchClient.Tasks.cs" />
154154
<Compile Include="Models\BatchClient.WorkItems.cs" />
155+
<Compile Include="Models\ListJobOptions.cs" />
156+
<Compile Include="Models\ListPoolOptions.cs" />
157+
<Compile Include="Models\ListTaskOptions.cs" />
158+
<Compile Include="Models\ListWorkItemOptions.cs" />
155159
<Compile Include="Models\PSAffinitiyInformation.cs" />
156160
<Compile Include="Models\PSAsyncEnumerable.cs" />
157161
<Compile Include="Models\PSAutoPoolSpecification.cs" />

src/ResourceManager/Batch/Commands.Batch/Jobs/GetBatchJobCommand.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,26 @@ public class GetBatchJobCommand : BatchObjectModelCmdletBase
4848
public int MaxCount
4949
{
5050
get { return this.maxCount; }
51-
set { this.maxCount = value <= 0 ? Int32.MaxValue : value; }
51+
set { this.maxCount = value; }
5252
}
5353

5454
public override void ExecuteCmdlet()
5555
{
56+
ListJobOptions options = new ListJobOptions()
57+
{
58+
Context = this.BatchContext,
59+
WorkItemName = this.WorkItemName,
60+
JobName = this.Name,
61+
WorkItem = this.WorkItem,
62+
Filter = this.Filter,
63+
MaxCount = this.MaxCount,
64+
AdditionalBehaviors = this.AdditionalBehaviors
65+
};
66+
5667
// The enumerator will internally query the service in chunks. Using WriteObject with the enumerate flag will enumerate
5768
// the entire collection first and then write the items out one by one in a single group. Using foreach, we can take
5869
// advantage of the enumerator's behavior and write output to the pipeline in bursts.
59-
foreach (PSCloudJob job in BatchClient.ListJobs(BatchContext, WorkItemName, WorkItem, Name, Filter, MaxCount, AdditionalBehaviors))
70+
foreach (PSCloudJob job in BatchClient.ListJobs(options))
6071
{
6172
WriteObject(job);
6273
}

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

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,53 +26,55 @@ public partial class BatchClient
2626
/// <summary>
2727
/// Lists the Jobs matching the specified filter options
2828
/// </summary>
29-
/// <param name="context">The account details</param>
30-
/// <param name="workItemName">The name of the WorkItem to query for Jobs</param>
31-
/// <param name="workItem">The WorkItem to query for Jobs</param>
32-
/// <param name="jobName">If specified, the single Job with this name will be returned</param>
33-
/// <param name="filter">The OData filter to use when querying for Jobs</param>
34-
/// <param name="maxCount">The maximum number of Jobs to return</param>
35-
/// <param name="additionalBehaviors">Additional client behaviors to perform</param>
29+
/// <param name="options">The options to use when querying for Jobs</param>
3630
/// <returns>The Jobs matching the specified filter options</returns>
37-
public IEnumerable<PSCloudJob> ListJobs(BatchAccountContext context, string workItemName, PSCloudWorkItem workItem, string jobName,
38-
string filter, int maxCount, IEnumerable<BatchClientBehavior> additionalBehaviors = null)
31+
public IEnumerable<PSCloudJob> ListJobs(ListJobOptions options)
3932
{
40-
if (string.IsNullOrEmpty(workItemName) && workItem == null)
33+
if (options == null)
34+
{
35+
throw new ArgumentNullException("options");
36+
}
37+
38+
if (string.IsNullOrEmpty(options.WorkItemName) && options.WorkItem == null)
4139
{
4240
throw new ArgumentNullException(Resources.GBJ_NoWorkItem);
4341
}
44-
string wiName = workItem == null ? workItemName : workItem.Name;
42+
string wiName = options.WorkItem == null ? options.WorkItemName : options.WorkItem.Name;
4543

4644
// Get the single Job matching the specified name
47-
if (!string.IsNullOrEmpty(jobName))
45+
if (!string.IsNullOrEmpty(options.JobName))
4846
{
49-
WriteVerbose(string.Format(Resources.GBJ_GetByName, jobName, wiName));
50-
using (IWorkItemManager wiManager = context.BatchOMClient.OpenWorkItemManager())
47+
WriteVerbose(string.Format(Resources.GBJ_GetByName, options.JobName, wiName));
48+
using (IWorkItemManager wiManager = options.Context.BatchOMClient.OpenWorkItemManager())
5149
{
52-
ICloudJob job = wiManager.GetJob(wiName, jobName, additionalBehaviors: additionalBehaviors);
50+
ICloudJob job = wiManager.GetJob(wiName, options.JobName, additionalBehaviors: options.AdditionalBehaviors);
5351
PSCloudJob psJob = new PSCloudJob(job);
5452
return new PSCloudJob[] { psJob };
5553
}
5654
}
5755
// List Jobs using the specified filter
5856
else
5957
{
58+
if (options.MaxCount <= 0)
59+
{
60+
options.MaxCount = Int32.MaxValue;
61+
}
6062
ODATADetailLevel odata = null;
61-
if (!string.IsNullOrEmpty(filter))
63+
if (!string.IsNullOrEmpty(options.Filter))
6264
{
63-
WriteVerbose(string.Format(Resources.GBJ_GetByOData, wiName, maxCount));
64-
odata = new ODATADetailLevel(filterClause: filter);
65+
WriteVerbose(string.Format(Resources.GBJ_GetByOData, wiName, options.MaxCount));
66+
odata = new ODATADetailLevel(filterClause: options.Filter);
6567
}
6668
else
6769
{
68-
WriteVerbose(string.Format(Resources.GBJ_GetNoFilter, wiName, maxCount));
70+
WriteVerbose(string.Format(Resources.GBJ_GetNoFilter, wiName, options.MaxCount));
6971
}
7072

71-
using (IWorkItemManager wiManager = context.BatchOMClient.OpenWorkItemManager())
73+
using (IWorkItemManager wiManager = options.Context.BatchOMClient.OpenWorkItemManager())
7274
{
73-
IEnumerableAsyncExtended<ICloudJob> jobs = wiManager.ListJobs(wiName, odata, additionalBehaviors);
75+
IEnumerableAsyncExtended<ICloudJob> jobs = wiManager.ListJobs(wiName, odata, options.AdditionalBehaviors);
7476
Func<ICloudJob, PSCloudJob> mappingFunction = j => { return new PSCloudJob(j); };
75-
return new PSAsyncEnumerable<PSCloudJob, ICloudJob>(jobs, mappingFunction).Take(maxCount);
77+
return new PSAsyncEnumerable<PSCloudJob, ICloudJob>(jobs, mappingFunction).Take(options.MaxCount);
7678
}
7779
}
7880
}

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,44 +26,48 @@ public partial class BatchClient
2626
/// <summary>
2727
/// Lists the Pools matching the specified filter options
2828
/// </summary>
29-
/// <param name="context">The account details</param>
30-
/// <param name="poolName">If specified, the single Pool with this name will be returned</param>
31-
/// <param name="filter">The OData filter to use when querying for Pools</param>
32-
/// <param name="maxCount">The maximum number of Pools to return</param>
33-
/// <param name="additionalBehaviors">Additional client behaviors to perform</param>
29+
/// <param name="options">The options to use when querying for Pools</param>
3430
/// <returns>The Pools matching the specified filter options</returns>
35-
public IEnumerable<PSCloudPool> ListPools(BatchAccountContext context, string poolName, string filter, int maxCount,
36-
IEnumerable<BatchClientBehavior> additionalBehaviors = null)
31+
public IEnumerable<PSCloudPool> ListPools(ListPoolOptions options)
3732
{
33+
if (options == null)
34+
{
35+
throw new ArgumentNullException("options");
36+
}
37+
3838
// Get the single Pool matching the specified name
39-
if (!string.IsNullOrEmpty(poolName))
39+
if (!string.IsNullOrEmpty(options.PoolName))
4040
{
41-
WriteVerbose(string.Format(Resources.GBP_GetByName, poolName));
42-
using (IPoolManager poolManager = context.BatchOMClient.OpenPoolManager())
41+
WriteVerbose(string.Format(Resources.GBP_GetByName, options.PoolName));
42+
using (IPoolManager poolManager = options.Context.BatchOMClient.OpenPoolManager())
4343
{
44-
ICloudPool pool = poolManager.GetPool(poolName, additionalBehaviors: additionalBehaviors);
44+
ICloudPool pool = poolManager.GetPool(options.PoolName, additionalBehaviors: options.AdditionalBehaviors);
4545
PSCloudPool psPool = new PSCloudPool(pool);
4646
return new PSCloudPool[] { psPool };
4747
}
4848
}
4949
// List Pools using the specified filter
5050
else
5151
{
52+
if (options.MaxCount <= 0)
53+
{
54+
options.MaxCount = Int32.MaxValue;
55+
}
5256
ODATADetailLevel odata = null;
53-
if (!string.IsNullOrEmpty(filter))
57+
if (!string.IsNullOrEmpty(options.Filter))
5458
{
55-
WriteVerbose(string.Format(Resources.GBP_GetByOData, maxCount));
56-
odata = new ODATADetailLevel(filterClause: filter);
59+
WriteVerbose(string.Format(Resources.GBP_GetByOData, options.MaxCount));
60+
odata = new ODATADetailLevel(filterClause: options.Filter);
5761
}
5862
else
5963
{
60-
WriteVerbose(string.Format(Resources.GBP_NoFilter, maxCount));
64+
WriteVerbose(string.Format(Resources.GBP_NoFilter, options.MaxCount));
6165
}
62-
using (IPoolManager poolManager = context.BatchOMClient.OpenPoolManager())
66+
using (IPoolManager poolManager = options.Context.BatchOMClient.OpenPoolManager())
6367
{
64-
IEnumerableAsyncExtended<ICloudPool> pools = poolManager.ListPools(odata, additionalBehaviors);
68+
IEnumerableAsyncExtended<ICloudPool> pools = poolManager.ListPools(odata, options.AdditionalBehaviors);
6569
Func<ICloudPool, PSCloudPool> mappingFunction = p => { return new PSCloudPool(p); };
66-
return new PSAsyncEnumerable<PSCloudPool, ICloudPool>(pools, mappingFunction).Take(maxCount);
70+
return new PSAsyncEnumerable<PSCloudPool, ICloudPool>(pools, mappingFunction).Take(options.MaxCount);
6771
}
6872
}
6973
}

0 commit comments

Comments
 (0)