Skip to content

Commit 409e5e4

Browse files
committed
Change Metadata and EnviornmentSettings to be IDictionary
- This makes it so that a response from the Batch service can be used as input to a New cmdlet. For example: `Get-AzBatchJob` `Metadata` can now be supplied as an input parameter to `New-AzBatchJob`. - This resolves issue #6611.
1 parent 31762e4 commit 409e5e4

34 files changed

+235
-223
lines changed

src/Batch/Batch.Test/JobSchedules/NewBatchJobScheduleCommandTests.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ public void NewBatchJobScheduleParametersGetPassedToRequestTest()
8080
Models.PSJobSpecification jobSpec = new Models.PSJobSpecification()
8181
{
8282
DisplayName = "job display name",
83-
CommonEnvironmentSettings = new List<Models.PSEnvironmentSetting>()
83+
CommonEnvironmentSettings = new Dictionary<string, string>
8484
{
85-
new Models.PSEnvironmentSetting("common1", "val1"),
86-
new Models.PSEnvironmentSetting("common2", "val2")
85+
{ "common1", "val1" },
86+
{ "common2", "val2" }
8787
},
8888
JobManagerTask = new Models.PSJobManagerTask("job manager", "cmd /c echo job manager"),
8989
JobPreparationTask = new Models.PSJobPreparationTask("cmd /c echo job prep"),
@@ -122,10 +122,12 @@ public void NewBatchJobScheduleParametersGetPassedToRequestTest()
122122
// Verify the request parameters match the cmdlet parameters
123123
Assert.Equal(cmdlet.DisplayName, requestParameters.DisplayName);
124124
Assert.Equal(jobSpec.CommonEnvironmentSettings.Count, requestParameters.JobSpecification.CommonEnvironmentSettings.Count);
125-
Assert.Equal(jobSpec.CommonEnvironmentSettings[0].Name, requestParameters.JobSpecification.CommonEnvironmentSettings[0].Name);
126-
Assert.Equal(jobSpec.CommonEnvironmentSettings[0].Value, requestParameters.JobSpecification.CommonEnvironmentSettings[0].Value);
127-
Assert.Equal(jobSpec.CommonEnvironmentSettings[1].Name, requestParameters.JobSpecification.CommonEnvironmentSettings[1].Name);
128-
Assert.Equal(jobSpec.CommonEnvironmentSettings[1].Value, requestParameters.JobSpecification.CommonEnvironmentSettings[1].Value);
125+
Assert.Contains(
126+
requestParameters.JobSpecification.CommonEnvironmentSettings,
127+
setting => setting.Name == "common1" && setting.Value == jobSpec.CommonEnvironmentSettings["common1"].ToString());
128+
Assert.Contains(
129+
requestParameters.JobSpecification.CommonEnvironmentSettings,
130+
setting => setting.Name == "common2" && setting.Value == jobSpec.CommonEnvironmentSettings["common2"].ToString());
129131
Assert.Equal(jobSpec.JobManagerTask.Id, requestParameters.JobSpecification.JobManagerTask.Id);
130132
Assert.Equal(jobSpec.JobPreparationTask.CommandLine, requestParameters.JobSpecification.JobPreparationTask.CommandLine);
131133
Assert.Equal(jobSpec.JobReleaseTask.CommandLine, requestParameters.JobSpecification.JobReleaseTask.CommandLine);

src/Batch/Batch.Test/JobSchedules/SetBatchJobScheduleCommandTests.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ public void SetBatchJobScheduleParametersGetPassedToRequestTest()
8080
PSJobSpecification jobSpec = new PSJobSpecification()
8181
{
8282
DisplayName = "job display name",
83-
CommonEnvironmentSettings = new List<PSEnvironmentSetting>()
83+
CommonEnvironmentSettings = new Dictionary<string, string>
8484
{
85-
new PSEnvironmentSetting("common1", "val1"),
86-
new PSEnvironmentSetting("common2", "val2")
85+
{ "common1", "val1" },
86+
{ "common2", "val2" }
8787
},
8888
JobManagerTask = new PSJobManagerTask("job manager", "cmd /c echo job manager"),
8989
JobPreparationTask = new PSJobPreparationTask("cmd /c echo job prep"),
@@ -104,9 +104,9 @@ public void SetBatchJobScheduleParametersGetPassedToRequestTest()
104104
};
105105
cmdlet.JobSchedule.Schedule = schedule;
106106

107-
cmdlet.JobSchedule.Metadata = new List<PSMetadataItem>()
107+
cmdlet.JobSchedule.Metadata = new Dictionary<string, string>
108108
{
109-
new PSMetadataItem("metadata1", "value1")
109+
{ "metadata1", "value1" }
110110
};
111111

112112
// Store the request parameters
@@ -123,10 +123,12 @@ public void SetBatchJobScheduleParametersGetPassedToRequestTest()
123123

124124
// Verify that the request parameters contain the updated properties
125125
Assert.Equal(jobSpec.CommonEnvironmentSettings.Count, requestParameters.JobSpecification.CommonEnvironmentSettings.Count);
126-
Assert.Equal(jobSpec.CommonEnvironmentSettings[0].Name, requestParameters.JobSpecification.CommonEnvironmentSettings[0].Name);
127-
Assert.Equal(jobSpec.CommonEnvironmentSettings[0].Value, requestParameters.JobSpecification.CommonEnvironmentSettings[0].Value);
128-
Assert.Equal(jobSpec.CommonEnvironmentSettings[1].Name, requestParameters.JobSpecification.CommonEnvironmentSettings[1].Name);
129-
Assert.Equal(jobSpec.CommonEnvironmentSettings[1].Value, requestParameters.JobSpecification.CommonEnvironmentSettings[1].Value);
126+
Assert.Contains(
127+
requestParameters.JobSpecification.CommonEnvironmentSettings,
128+
setting => setting.Name == "common1" && setting.Value == jobSpec.CommonEnvironmentSettings["common1"].ToString());
129+
Assert.Contains(
130+
requestParameters.JobSpecification.CommonEnvironmentSettings,
131+
setting => setting.Name == "common2" && setting.Value == jobSpec.CommonEnvironmentSettings["common2"].ToString());
130132
Assert.Equal(jobSpec.JobManagerTask.Id, requestParameters.JobSpecification.JobManagerTask.Id);
131133
Assert.Equal(jobSpec.JobPreparationTask.CommandLine, requestParameters.JobSpecification.JobPreparationTask.CommandLine);
132134
Assert.Equal(jobSpec.JobReleaseTask.CommandLine, requestParameters.JobSpecification.JobReleaseTask.CommandLine);
@@ -136,8 +138,9 @@ public void SetBatchJobScheduleParametersGetPassedToRequestTest()
136138
Assert.Equal(schedule.RecurrenceInterval, requestParameters.Schedule.RecurrenceInterval);
137139
Assert.Equal(schedule.StartWindow, requestParameters.Schedule.StartWindow);
138140
Assert.Equal(cmdlet.JobSchedule.Metadata.Count, requestParameters.Metadata.Count);
139-
Assert.Equal(cmdlet.JobSchedule.Metadata[0].Name, requestParameters.Metadata[0].Name);
140-
Assert.Equal(cmdlet.JobSchedule.Metadata[0].Value, requestParameters.Metadata[0].Value);
141+
Assert.Contains(
142+
requestParameters.Metadata,
143+
metadata => metadata.Name == "metadata1" && metadata.Value == cmdlet.JobSchedule.Metadata["metadata1"].ToString());
141144
}
142145
}
143146
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public void WhenGettingAJobFromTheService_ApplicationPackageReferencesAreMapped(
322322
Assert.Equal(cmdlet.Id, pipeline[0].Id);
323323

324324
var psApplicationPackageReference = pipeline[0].JobManagerTask.ApplicationPackageReferences.First();
325-
Assert.Equal(applicationName, psApplicationPackageReference.ApplicationName);
325+
Assert.Equal(applicationName, psApplicationPackageReference.ApplicationId);
326326
Assert.Equal(applicationVersion, psApplicationPackageReference.Version);
327327
}
328328
}

src/Batch/Batch.Test/Jobs/NewBatchJobCommandTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void ApplicationPackageReferencesAreSentToService()
142142

143143
cmdlet.JobManagerTask = new PSJobManagerTask { ApplicationPackageReferences = new[]
144144
{
145-
new PSApplicationPackageReference { ApplicationName = applicationName, Version = applicationVersion} ,
145+
new PSApplicationPackageReference { ApplicationId = applicationName, Version = applicationVersion} ,
146146
}};
147147

148148
// Don't go to the service on an Add CloudJob call

src/Batch/Batch.Test/Jobs/SetBatchJobCommandTests.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ public void SetBatchJobParametersGetPassedToRequestTest()
6363
PoolId = "myPool"
6464
};
6565
cmdlet.Job.Priority = 2;
66-
cmdlet.Job.Metadata = new List<PSMetadataItem>()
66+
cmdlet.Job.Metadata = new Dictionary<string, string>()
6767
{
68-
new PSMetadataItem("meta1", "value1"),
69-
new PSMetadataItem("meta2", "value2")
68+
{ "meta1", "value1" },
69+
{ "meta2", "value2" }
7070
};
7171

7272
JobUpdateParameter requestParameters = null;
@@ -88,10 +88,8 @@ public void SetBatchJobParametersGetPassedToRequestTest()
8888
Assert.Equal(cmdlet.Job.PoolInformation.PoolId, requestParameters.PoolInfo.PoolId);
8989
Assert.Equal(cmdlet.Job.Priority, requestParameters.Priority);
9090
Assert.Equal(cmdlet.Job.Metadata.Count, requestParameters.Metadata.Count);
91-
Assert.Equal(cmdlet.Job.Metadata[0].Name, requestParameters.Metadata[0].Name);
92-
Assert.Equal(cmdlet.Job.Metadata[0].Value, requestParameters.Metadata[0].Value);
93-
Assert.Equal(cmdlet.Job.Metadata[1].Name, requestParameters.Metadata[1].Name);
94-
Assert.Equal(cmdlet.Job.Metadata[1].Value, requestParameters.Metadata[1].Value);
91+
Assert.Contains(requestParameters.Metadata, p => p.Name == "meta1" && p.Value == cmdlet.Job.Metadata["meta1"].ToString());
92+
Assert.Contains(requestParameters.Metadata, p => p.Name == "meta2" && p.Value == cmdlet.Job.Metadata["meta2"].ToString());
9593
}
9694

9795
[Fact]

src/Batch/Batch.Test/Pools/SetBatchPoolCommandTests.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ public void SetBatchPoolParametersGetPassedToRequestTest()
9494
{
9595
new PSApplicationPackageReference()
9696
{
97-
ApplicationName = "myApp",
97+
ApplicationId = "myApp",
9898
Version = "1.0"
9999
}
100100
};
101-
cmdlet.Pool.Metadata = new List<PSMetadataItem>()
101+
cmdlet.Pool.Metadata = new Dictionary<string, string>
102102
{
103-
new PSMetadataItem("meta1", "value1")
103+
{ "meta1", "value1" }
104104
};
105105

106106
PoolUpdatePropertiesParameter requestParameters = null;
@@ -123,11 +123,12 @@ public void SetBatchPoolParametersGetPassedToRequestTest()
123123
Assert.Equal(cmdlet.Pool.CertificateReferences[0].Thumbprint, requestParameters.CertificateReferences[0].Thumbprint);
124124
Assert.Equal(cmdlet.Pool.CertificateReferences[0].ThumbprintAlgorithm, requestParameters.CertificateReferences[0].ThumbprintAlgorithm);
125125
Assert.Equal(cmdlet.Pool.ApplicationPackageReferences.Count, requestParameters.ApplicationPackageReferences.Count);
126-
Assert.Equal(cmdlet.Pool.ApplicationPackageReferences[0].ApplicationName, requestParameters.ApplicationPackageReferences[0].ApplicationId);
126+
Assert.Equal(cmdlet.Pool.ApplicationPackageReferences[0].ApplicationId, requestParameters.ApplicationPackageReferences[0].ApplicationId);
127127
Assert.Equal(cmdlet.Pool.ApplicationPackageReferences[0].Version, requestParameters.ApplicationPackageReferences[0].Version);
128128
Assert.Equal(cmdlet.Pool.Metadata.Count, requestParameters.Metadata.Count);
129-
Assert.Equal(cmdlet.Pool.Metadata[0].Name, requestParameters.Metadata[0].Name);
130-
Assert.Equal(cmdlet.Pool.Metadata[0].Value, requestParameters.Metadata[0].Value);
129+
Assert.Contains(
130+
requestParameters.Metadata,
131+
metadata => metadata.Name == "meta1" && metadata.Value == cmdlet.Pool.Metadata["meta1"].ToString());
131132
}
132133
}
133134
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ public void WhenGettingATaskFromTheService_ApplicationPackageReferencesAreMapped
363363
Assert.Equal(cmdlet.Id, pipeline[0].Id);
364364

365365
var psApplicationPackageReference = pipeline[0].ApplicationPackageReferences.First();
366-
Assert.Equal(applicationName, psApplicationPackageReference.ApplicationName);
366+
Assert.Equal(applicationName, psApplicationPackageReference.ApplicationId);
367367
Assert.Equal(applicationVersion, psApplicationPackageReference.Version);
368368
}
369369
}

src/Batch/Batch.Test/Tasks/NewBatchTaskCommandTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public void ApplicationPackageReferencesAreSentOnATask()
157157

158158
cmdlet.ApplicationPackageReferences = new[]
159159
{
160-
new PSApplicationPackageReference { ApplicationName = applicationName, Version = applicationVersion} ,
160+
new PSApplicationPackageReference { ApplicationId = applicationName, Version = applicationVersion} ,
161161
};
162162

163163
// Don't go to the service on an Add CloudJob call

src/Batch/Batch/Jobs/NewBatchJobCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Microsoft.Azure.Commands.Batch.Models;
1818
using System.Management.Automation;
1919
using Constants = Microsoft.Azure.Commands.Batch.Utils.Constants;
20+
using System.Collections.Generic;
2021

2122
namespace Microsoft.Azure.Commands.Batch
2223
{

src/Batch/Batch/Models.Generated/PSApplicationPackageReference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal PSApplicationPackageReference(Microsoft.Azure.Batch.ApplicationPackageR
4848
this.omObject = omObject;
4949
}
5050

51-
public string ApplicationName
51+
public string ApplicationId
5252
{
5353
get
5454
{

src/Batch/Batch/Models.Generated/PSAutoScaleRunError.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public IReadOnlyList<PSNameValuePair> Values
7878
{
7979
list.Add(new PSNameValuePair(enumerator.Current));
8080
}
81-
this.values = list.AsReadOnly();
81+
this.values = list;
8282
}
8383
return this.values;
8484
}

src/Batch/Batch/Models.Generated/PSCloudJob.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public partial class PSCloudJob
3434

3535
internal Microsoft.Azure.Batch.CloudJob omObject;
3636

37-
private IList<PSEnvironmentSetting> commonEnvironmentSettings;
37+
private IDictionary commonEnvironmentSettings;
3838

3939
private PSJobConstraints constraints;
4040

@@ -46,7 +46,7 @@ public partial class PSCloudJob
4646

4747
private PSJobReleaseTask jobReleaseTask;
4848

49-
private IList<PSMetadataItem> metadata;
49+
private IDictionary metadata;
5050

5151
private PSJobNetworkConfiguration networkConfiguration;
5252

@@ -63,24 +63,24 @@ internal PSCloudJob(Microsoft.Azure.Batch.CloudJob omObject)
6363
this.omObject = omObject;
6464
}
6565

66-
public IList<PSEnvironmentSetting> CommonEnvironmentSettings
66+
public IDictionary CommonEnvironmentSettings
6767
{
6868
get
6969
{
7070
if (((this.commonEnvironmentSettings == null)
7171
&& (this.omObject.CommonEnvironmentSettings != null)))
7272
{
73-
List<PSEnvironmentSetting> list;
74-
list = new List<PSEnvironmentSetting>();
73+
Dictionary<string, string> dict;
74+
dict = new Dictionary<string, string>();
7575
IEnumerator<Microsoft.Azure.Batch.EnvironmentSetting> enumerator;
7676
enumerator = this.omObject.CommonEnvironmentSettings.GetEnumerator();
7777
for (
7878
; enumerator.MoveNext();
7979
)
8080
{
81-
list.Add(new PSEnvironmentSetting(enumerator.Current));
81+
dict.Add(enumerator.Current.Name, enumerator.Current.Value);
8282
}
83-
this.commonEnvironmentSettings = list;
83+
this.commonEnvironmentSettings = dict;
8484
}
8585
return this.commonEnvironmentSettings;
8686
}
@@ -259,24 +259,24 @@ public System.DateTime? LastModified
259259
}
260260
}
261261

262-
public IList<PSMetadataItem> Metadata
262+
public IDictionary Metadata
263263
{
264264
get
265265
{
266266
if (((this.metadata == null)
267267
&& (this.omObject.Metadata != null)))
268268
{
269-
List<PSMetadataItem> list;
270-
list = new List<PSMetadataItem>();
269+
Dictionary<string, string> dict;
270+
dict = new Dictionary<string, string>();
271271
IEnumerator<Microsoft.Azure.Batch.MetadataItem> enumerator;
272272
enumerator = this.omObject.Metadata.GetEnumerator();
273273
for (
274274
; enumerator.MoveNext();
275275
)
276276
{
277-
list.Add(new PSMetadataItem(enumerator.Current));
277+
dict.Add(enumerator.Current.Name, enumerator.Current.Value);
278278
}
279-
this.metadata = list;
279+
this.metadata = dict;
280280
}
281281
return this.metadata;
282282
}

src/Batch/Batch/Models.Generated/PSCloudJobSchedule.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public partial class PSCloudJobSchedule
3838

3939
private PSJobSpecification jobSpecification;
4040

41-
private IList<PSMetadataItem> metadata;
41+
private IDictionary metadata;
4242

4343
private PSSchedule schedule;
4444

@@ -139,24 +139,24 @@ public System.DateTime? LastModified
139139
}
140140
}
141141

142-
public IList<PSMetadataItem> Metadata
142+
public IDictionary Metadata
143143
{
144144
get
145145
{
146146
if (((this.metadata == null)
147147
&& (this.omObject.Metadata != null)))
148148
{
149-
List<PSMetadataItem> list;
150-
list = new List<PSMetadataItem>();
149+
Dictionary<string, string> dict;
150+
dict = new Dictionary<string, string>();
151151
IEnumerator<Microsoft.Azure.Batch.MetadataItem> enumerator;
152152
enumerator = this.omObject.Metadata.GetEnumerator();
153153
for (
154154
; enumerator.MoveNext();
155155
)
156156
{
157-
list.Add(new PSMetadataItem(enumerator.Current));
157+
dict.Add(enumerator.Current.Name, enumerator.Current.Value);
158158
}
159-
this.metadata = list;
159+
this.metadata = dict;
160160
}
161161
return this.metadata;
162162
}

src/Batch/Batch/Models.Generated/PSCloudPool.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public partial class PSCloudPool
4444

4545
private PSCloudServiceConfiguration cloudServiceConfiguration;
4646

47-
private IList<PSMetadataItem> metadata;
47+
private IDictionary metadata;
4848

4949
private PSNetworkConfiguration networkConfiguration;
5050

@@ -352,24 +352,24 @@ public System.Int32? MaxTasksPerComputeNode
352352
}
353353
}
354354

355-
public IList<PSMetadataItem> Metadata
355+
public IDictionary Metadata
356356
{
357357
get
358358
{
359359
if (((this.metadata == null)
360360
&& (this.omObject.Metadata != null)))
361361
{
362-
List<PSMetadataItem> list;
363-
list = new List<PSMetadataItem>();
362+
Dictionary<string, string> dict;
363+
dict = new Dictionary<string, string>();
364364
IEnumerator<Microsoft.Azure.Batch.MetadataItem> enumerator;
365365
enumerator = this.omObject.Metadata.GetEnumerator();
366366
for (
367367
; enumerator.MoveNext();
368368
)
369369
{
370-
list.Add(new PSMetadataItem(enumerator.Current));
370+
dict.Add(enumerator.Current.Name, enumerator.Current.Value);
371371
}
372-
this.metadata = list;
372+
this.metadata = dict;
373373
}
374374
return this.metadata;
375375
}
@@ -429,7 +429,7 @@ public IReadOnlyList<PSResizeError> ResizeErrors
429429
{
430430
list.Add(new PSResizeError(enumerator.Current));
431431
}
432-
this.resizeErrors = list.AsReadOnly();
432+
this.resizeErrors = list;
433433
}
434434
return this.resizeErrors;
435435
}

0 commit comments

Comments
 (0)