/
JobOperations.cs
1231 lines (1082 loc) · 72 KB
/
JobOperations.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System.IO;
namespace Microsoft.Azure.Batch
{
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Linq;
using System.Text;
using System.Security;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Batch.Common;
using Models = Microsoft.Azure.Batch.Protocol.Models;
using Microsoft.Rest.Azure;
/// <summary>
/// Performs operations on Azure Batch jobs.
/// </summary>
/// <seealso cref="CloudJob"/>
public class JobOperations : IInheritedBehaviors
{
#region // constructors
public JobOperations()
{
}
internal JobOperations(BatchClient parentBatchClient, IEnumerable<BatchClientBehavior> inheritedBehaviors)
{
ParentBatchClient = parentBatchClient;
// set up the behavior inheritance
InheritUtil.InheritClientBehaviorsAndSetPublicProperty(this, inheritedBehaviors);
}
#endregion //constructors
#region IInheritedBehaviors
/// <summary>
/// Gets or sets a list of behaviors that modify or customize requests to the Batch service
/// made via this <see cref="JobOperations"/>.
/// </summary>
/// <remarks>
/// <para>These behaviors are inherited by child objects.</para>
/// <para>Modifications are applied in the order of the collection. The last write wins.</para>
/// </remarks>
public IList<BatchClientBehavior> CustomBehaviors { get; set; }
#endregion IInheritedBehaviors
#region // JobOperations
/// <summary>
/// Creates an instance of CloudJob that is unbound and does not have a consistency relationship to any job in the Batch Service.
/// </summary>
/// <returns>A <see cref="CloudJob"/> representing a new job that has not been submitted to the Batch service.</returns>
public CloudJob CreateJob()
{
string id = Guid.NewGuid().ToString();
CloudJob unboundJob = new CloudJob(ParentBatchClient, CustomBehaviors)
{
//TODO: Do we want to do this...?
Id = id // we lose the ability to construct an unbound job with zero changes (ie not marked dirty)
};
return unboundJob;
}
/// <summary>
/// Creates an instance of CloudJob that is unbound and does not have a consistency relationship to any job in the Batch Service.
/// </summary>
/// <param name="jobId">The Id of the job.</param>
/// <param name="poolInformation">The information about the pool the job will run on.</param>
/// <returns>A <see cref="CloudJob"/> representing a new job that has not been submitted to the Batch service.</returns>
public CloudJob CreateJob(string jobId, PoolInformation poolInformation)
{
CloudJob unboundJob = new CloudJob(ParentBatchClient, CustomBehaviors)
{
Id = jobId,
PoolInformation = poolInformation
};
return unboundJob;
}
internal IPagedEnumerable<CloudJob> ListJobsImpl(BehaviorManager bhMgr, DetailLevel detailLevel)
{
PagedEnumerable<CloudJob> enumerable = new PagedEnumerable<CloudJob>( // the lamda will be the enumerator factory
() =>
{
// here is the actual strongly typed enumerator
AsyncListJobsEnumerator typedEnumerator = new AsyncListJobsEnumerator(ParentBatchClient, bhMgr, detailLevel);
// here is the base
PagedEnumeratorBase<CloudJob> enumeratorBase = typedEnumerator;
return enumeratorBase;
});
return enumerable;
}
/// <summary>
/// Enumerates the <see cref="CloudJob">jobs</see> in the Batch account.
/// </summary>
/// <param name="detailLevel">A <see cref="DetailLevel"/> used for filtering the list and for controlling which properties are retrieved from the service.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/> and <paramref name="detailLevel"/>.</param>
/// <returns>An <see cref="IPagedEnumerable{CloudJob}"/> that can be used to enumerate jobs asynchronously or synchronously.</returns>
/// <remarks>This method returns immediately; the jobs are retrieved from the Batch service only when the collection is enumerated.
/// Retrieval is non-atomic; jobs are retrieved in pages during enumeration of the collection.</remarks>
public IPagedEnumerable<CloudJob> ListJobs(DetailLevel detailLevel = null, IEnumerable<BatchClientBehavior> additionalBehaviors = null)
{
// set up behavior manager
BehaviorManager bhMgr = new BehaviorManager(CustomBehaviors, additionalBehaviors);
IPagedEnumerable<CloudJob> enumerable = ListJobsImpl(bhMgr, detailLevel);
return enumerable;
}
internal async Task<CloudJob> GetJobAsyncImpl(string jobId, BehaviorManager bhMgr, CancellationToken cancellationToken)
{
Task<AzureOperationResponse<Models.CloudJob, Models.JobGetHeaders>> asyncTask = ParentBatchClient.ProtocolLayer.GetJob(jobId, bhMgr, cancellationToken);
AzureOperationResponse<Models.CloudJob, Models.JobGetHeaders> response = await asyncTask.ConfigureAwait(continueOnCapturedContext: false);
// extract job from response
Models.CloudJob protoJob = response.Body;
// convert to bound object layer equiv
CloudJob openedJob = new CloudJob(ParentBatchClient, protoJob, bhMgr.BaseBehaviors);
return openedJob;
}
/// <summary>
/// Gets the specified <see cref="CloudJob"/>.
/// </summary>
/// <param name="jobId">The id of the job to get.</param>
/// <param name="detailLevel">A <see cref="DetailLevel"/> used for controlling which properties are retrieved from the service.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/> and <paramref name="detailLevel"/>.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
/// <returns>A <see cref="CloudJob"/> containing information about the specified Azure Batch job.</returns>
/// <remarks>The get job operation runs asynchronously.</remarks>
public async Task<CloudJob> GetJobAsync(
string jobId,
DetailLevel detailLevel = null,
IEnumerable<BatchClientBehavior> additionalBehaviors = null,
CancellationToken cancellationToken = default)
{
// set up behavior manager
BehaviorManager bhMgr = new BehaviorManager(CustomBehaviors, additionalBehaviors, detailLevel);
Task<CloudJob> asyncTask = GetJobAsyncImpl(jobId, bhMgr, cancellationToken);
CloudJob openedJob = await asyncTask.ConfigureAwait(continueOnCapturedContext: false);
return openedJob;
}
/// <summary>
/// Gets the specified <see cref="CloudJob"/>.
/// </summary>
/// <param name="jobId">The id of the job to get.</param>
/// <param name="detailLevel">A <see cref="DetailLevel"/> used for controlling which properties are retrieved from the service.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/> and <paramref name="detailLevel"/>.</param>
/// <returns>A <see cref="CloudJob"/> containing information about the specified Azure Batch job.</returns>
/// <remarks>This is a blocking operation. For a non-blocking equivalent, see <see cref="GetJobAsync"/>.</remarks>
public CloudJob GetJob(string jobId, DetailLevel detailLevel = null, IEnumerable<BatchClientBehavior> additionalBehaviors = null)
{
Task<CloudJob> asyncTask = GetJobAsync(jobId, detailLevel, additionalBehaviors);
CloudJob newJob = asyncTask.WaitAndUnaggregateException(CustomBehaviors, additionalBehaviors);
return newJob;
}
internal async Task<TaskCountsResult> GetJobTaskCountsAsyncImpl(string jobId, BehaviorManager bhMgr, CancellationToken cancellationToken)
{
AzureOperationResponse<Models.TaskCountsResult, Models.JobGetTaskCountsHeaders> response = await ParentBatchClient.ProtocolLayer.GetJobTaskCounts(
jobId,
bhMgr,
cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
Models.TaskCountsResult protoTaskCounts = response.Body;
TaskCountsResult result = new TaskCountsResult(protoTaskCounts);
return result;
}
/// <summary>
/// Gets the task counts for the specified job.
/// </summary>
/// <param name="jobId">The id of the job.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
/// <remarks>The get job task counts operation runs asynchronously.</remarks>
/// <returns>A <see cref="TaskCounts"/> object containing the task counts for the job.</returns>
public async Task<TaskCountsResult> GetJobTaskCountsAsync(
string jobId,
IEnumerable<BatchClientBehavior> additionalBehaviors = null,
CancellationToken cancellationToken = default)
{
// set up behavior manager
BehaviorManager bhMgr = new BehaviorManager(CustomBehaviors, additionalBehaviors, detailLevel: null);
TaskCountsResult counts = await GetJobTaskCountsAsyncImpl(jobId, bhMgr, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
return counts;
}
/// <summary>
/// Gets the task counts for the specified job.
/// </summary>
/// <param name="jobId">The id of the job.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <returns>A <see cref="TaskCounts"/> object containing the task counts for the job.</returns>
/// <remarks>This is a blocking operation. For a non-blocking equivalent, see <see cref="GetJobTaskCountsAsync"/>.</remarks>
public TaskCountsResult GetJobTaskCounts(string jobId, IEnumerable<BatchClientBehavior> additionalBehaviors = null)
{
TaskCountsResult result = GetJobTaskCountsAsync(jobId, additionalBehaviors).WaitAndUnaggregateException(CustomBehaviors, additionalBehaviors);
return result;
}
/// <summary>
/// Enables the specified job, allowing new tasks to run.
/// </summary>
/// <param name="jobId">The id of the job.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The enable operation runs asynchronously.</remarks>
public async Task EnableJobAsync(string jobId, IEnumerable<BatchClientBehavior> additionalBehaviors = null, CancellationToken cancellationToken = default)
{
// set up behavior manager
BehaviorManager bhMgr = new BehaviorManager(CustomBehaviors, additionalBehaviors);
Task asyncTask = ParentBatchClient.ProtocolLayer.EnableJob(jobId, bhMgr, cancellationToken);
await asyncTask.ConfigureAwait(continueOnCapturedContext: false);
}
/// <summary>
/// Enables the specified job, allowing new tasks to run.
/// </summary>
/// <param name="jobId">The id of the job.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <remarks>This is a blocking operation. For a non-blocking equivalent, see <see cref="EnableJobAsync"/>.</remarks>
public void EnableJob(string jobId, IEnumerable<BatchClientBehavior> additionalBehaviors = null)
{
Task asyncTask = EnableJobAsync(jobId, additionalBehaviors);
asyncTask.WaitAndUnaggregateException(CustomBehaviors, additionalBehaviors);
}
/// <summary>
/// Disables the specified job. Disabled jobs do not run new tasks, but may be re-enabled later.
/// </summary>
/// <param name="jobId">The id of the job.</param>
/// <param name="disableJobOption">Specifies what to do with active tasks associated with the job.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The disable operation runs asynchronously.</remarks>
public async Task DisableJobAsync(
string jobId,
Common.DisableJobOption disableJobOption,
IEnumerable<BatchClientBehavior> additionalBehaviors = null,
CancellationToken cancellationToken = default)
{
// set up behavior manager
BehaviorManager bhMgr = new BehaviorManager(CustomBehaviors, additionalBehaviors);
Task asyncTask = ParentBatchClient.ProtocolLayer.DisableJob(jobId, disableJobOption, bhMgr, cancellationToken);
await asyncTask.ConfigureAwait(continueOnCapturedContext: false);
}
/// <summary>
/// Disables the specified job. Disabled jobs do not run new tasks, but may be re-enabled later.
/// </summary>
/// <param name="jobId">The id of the job.</param>
/// <param name="disableJobOption">Specifies what to do with active tasks associated with the job.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <remarks>This is a blocking operation. For a non-blocking equivalent, see <see cref="DisableJobAsync"/>.</remarks>
public void DisableJob(string jobId, Common.DisableJobOption disableJobOption, IEnumerable<BatchClientBehavior> additionalBehaviors = null)
{
Task asyncTask = DisableJobAsync(jobId, disableJobOption, additionalBehaviors);
asyncTask.WaitAndUnaggregateException(CustomBehaviors, additionalBehaviors);
}
/// <summary>
/// Terminates the specified job, marking it as completed.
/// </summary>
/// <param name="jobId">The id of the job.</param>
/// <param name="terminateReason">The text you want to appear as the job's <see cref="JobExecutionInformation.TerminateReason"/>.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
/// <returns>A <see cref="Task"/> object that represents the asynchronous operation.</returns>
/// <remarks>The terminate operation runs asynchronously.</remarks>
public async Task TerminateJobAsync(
string jobId,
string terminateReason = null,
IEnumerable<BatchClientBehavior> additionalBehaviors = null,
CancellationToken cancellationToken = default)
{
// set up behavior manager
BehaviorManager bhMgr = new BehaviorManager(CustomBehaviors, additionalBehaviors);
Task asyncTask = ParentBatchClient.ProtocolLayer.TerminateJob(jobId, terminateReason, bhMgr, cancellationToken);
await asyncTask.ConfigureAwait(continueOnCapturedContext: false);
}
/// <summary>
/// Terminates the specified job, marking it as completed.
/// </summary>
/// <param name="jobId">The id of the job.</param>
/// <param name="terminateReason">The text you want to appear as the job's <see cref="JobExecutionInformation.TerminateReason"/>.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <remarks>This is a blocking operation. For a non-blocking equivalent, see <see cref="TerminateJobAsync"/>.</remarks>
public void TerminateJob(string jobId, string terminateReason = null, IEnumerable<BatchClientBehavior> additionalBehaviors = null)
{
Task asyncTask = TerminateJobAsync(jobId, terminateReason, additionalBehaviors);
asyncTask.WaitAndUnaggregateException(CustomBehaviors, additionalBehaviors);
}
/// <summary>
/// Deletes the specified job.
/// </summary>
/// <param name="jobId">The id of the job.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>
/// <para>The delete operation requests that the job be deleted. The request puts the job in the <see cref="Common.JobState.Deleting"/> state.
/// The Batch service will stop any running tasks and perform the actual job deletion without any further client action.</para>
/// <para>The delete operation runs asynchronously.</para>
/// </remarks>
public async Task DeleteJobAsync(string jobId, IEnumerable<BatchClientBehavior> additionalBehaviors = null, CancellationToken cancellationToken = default)
{
// set up behavior manager
BehaviorManager bhMgr = new BehaviorManager(CustomBehaviors, additionalBehaviors);
Task asyncTask = ParentBatchClient.ProtocolLayer.DeleteJob(jobId, bhMgr, cancellationToken);
await asyncTask.ConfigureAwait(continueOnCapturedContext: false);
}
/// <summary>
/// Deletes the specified job.
/// </summary>
/// <param name="jobId">The id of the job.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <remarks>
/// <para>The delete operation requests that the job be deleted. The request puts the job in the <see cref="Common.JobState.Deleting"/> state.
/// The Batch service will stop any running tasks and perform the actual job deletion without any further client action.</para>
/// <para>This is a blocking operation. For a non-blocking equivalent, see <see cref="DeleteJobAsync"/>.</para>
/// </remarks>
public void DeleteJob(string jobId, IEnumerable<BatchClientBehavior> additionalBehaviors = null)
{
Task asyncTask = DeleteJobAsync(jobId, additionalBehaviors);
asyncTask.WaitAndUnaggregateException(CustomBehaviors, additionalBehaviors);
}
internal IPagedEnumerable<CloudTask> ListTasksImpl(string jobId, BehaviorManager bhMgr, DetailLevel detailLevel)
{
PagedEnumerable<CloudTask> enumerable = new PagedEnumerable<CloudTask>( // the lamda will be the enumerator factory
() =>
{
// here is the actual strongly typed enumerator
AsyncListTasksEnumerator typedEnumerator = new AsyncListTasksEnumerator(this, jobId, bhMgr, detailLevel);
// here is the base
PagedEnumeratorBase<CloudTask> enumeratorBase = typedEnumerator;
return enumeratorBase;
});
return enumerable;
}
/// <summary>
/// Enumerates the <see cref="CloudTask">tasks</see> of the specified job.
/// </summary>
/// <param name="jobId">The id of the job.</param>
/// <param name="detailLevel">A <see cref="DetailLevel"/> used for filtering the list and for controlling which properties are retrieved from the service.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/> and <paramref name="detailLevel"/>.</param>
/// <returns>An <see cref="IPagedEnumerable{CloudTask}"/> that can be used to enumerate tasks asynchronously or synchronously.</returns>
/// <remarks>This method returns immediately; the tasks are retrieved from the Batch service only when the collection is enumerated.
/// Retrieval is non-atomic; tasks are retrieved in pages during enumeration of the collection.</remarks>
public IPagedEnumerable<CloudTask> ListTasks(
string jobId,
DetailLevel detailLevel = null,
IEnumerable<BatchClientBehavior> additionalBehaviors = null)
{
// set up behavior manager
BehaviorManager bhMgr = new BehaviorManager(CustomBehaviors, additionalBehaviors);
// get the enumerable
IPagedEnumerable<CloudTask> enumerable = ListTasksImpl(jobId, bhMgr, detailLevel);
return enumerable;
}
internal async Task<CloudTask> GetTaskAsyncImpl(
string jobId,
string taskId,
BehaviorManager bhMgr,
CancellationToken cancellationToken)
{
Task<AzureOperationResponse<Models.CloudTask, Models.TaskGetHeaders>> asyncTask =
ParentBatchClient.ProtocolLayer.GetTask(
jobId,
taskId,
bhMgr,
cancellationToken);
AzureOperationResponse<Models.CloudTask, Models.TaskGetHeaders> response = await asyncTask.ConfigureAwait(continueOnCapturedContext: false);
// extract protocol task
Models.CloudTask protoTask = response.Body;
// bind CloudTask to protocol task
CloudTask newTask = new CloudTask(ParentBatchClient, jobId, protoTask, bhMgr.BaseBehaviors);
return newTask;
}
/// <summary>
/// Gets the specified <see cref="CloudTask"/>.
/// </summary>
/// <param name="jobId">The id of the job from which to get the task.</param>
/// <param name="taskId">The id of the task to get.</param>
/// <param name="detailLevel">A <see cref="DetailLevel"/> used for controlling which properties are retrieved from the service.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/> and <paramref name="detailLevel"/>.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
/// <returns>A <see cref="CloudTask"/> containing information about the specified Azure Batch task.</returns>
/// <remarks>The get task operation runs asynchronously.</remarks>
public Task<CloudTask> GetTaskAsync(
string jobId,
string taskId,
DetailLevel detailLevel = null,
IEnumerable<BatchClientBehavior> additionalBehaviors = null,
CancellationToken cancellationToken = default)
{
// set up behavior manager
BehaviorManager bhMgr = new BehaviorManager(CustomBehaviors, additionalBehaviors, detailLevel);
Task<CloudTask> asyncTask = GetTaskAsyncImpl(jobId, taskId, bhMgr, cancellationToken);
return asyncTask;
}
/// <summary>
/// Gets the specified <see cref="CloudTask"/>.
/// </summary>
/// <param name="jobId">The id of the job from which to get the task.</param>
/// <param name="taskId">The id of the task to get.</param>
/// <param name="detailLevel">A <see cref="DetailLevel"/> used for controlling which properties are retrieved from the service.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/> and <paramref name="detailLevel"/>.</param>
/// <returns>A <see cref="CloudTask"/> containing information about the specified Azure Batch task.</returns>
/// <remarks>This is a blocking operation. For a non-blocking equivalent, see <see cref="GetTaskAsync"/>.</remarks>
public CloudTask GetTask(string jobId, string taskId, DetailLevel detailLevel = null, IEnumerable<BatchClientBehavior> additionalBehaviors = null)
{
Task<CloudTask> asyncTask = GetTaskAsync(jobId, taskId, detailLevel, additionalBehaviors);
CloudTask newTask = asyncTask.WaitAndUnaggregateException(CustomBehaviors, additionalBehaviors);
return newTask;
}
/// <summary>
/// Enumerates the <see cref="SubtaskInformation">subtask information</see> of the specified task.
/// </summary>
/// <param name="jobId">The id of the job.</param>
/// <param name="taskId">The id of the task to get.</param>
/// <param name="detailLevel">A <see cref="DetailLevel"/> used for filtering the list and for controlling which properties are retrieved from the service.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/> and <paramref name="detailLevel"/>.</param>
/// <returns>An <see cref="IPagedEnumerable{SubtaskInformation}"/> that can be used to enumerate subtasks asynchronously or synchronously.</returns>
/// <remarks>This method returns immediately; the tasks are retrieved from the Batch service only when the collection is enumerated.
/// Retrieval is non-atomic; tasks are retrieved in pages during enumeration of the collection.</remarks>
public IPagedEnumerable<SubtaskInformation> ListSubtasks(string jobId,
string taskId,
DetailLevel detailLevel = null,
IEnumerable<BatchClientBehavior> additionalBehaviors = null)
{
// set up behavior manager
BehaviorManager bhMgr = new BehaviorManager(CustomBehaviors, additionalBehaviors);
// get the enumerable
IPagedEnumerable<SubtaskInformation> enumerable = ListSubtasksImpl(jobId, taskId, bhMgr, detailLevel);
return enumerable;
}
internal async Task AddTaskAsyncImpl(
string jobId,
CloudTask taskToAdd,
BehaviorManager bhMgr,
CancellationToken cancellationToken,
ConcurrentDictionary<Type, IFileStagingArtifact> allFileStagingArtifacts = null)
{
// only our implementation can be used to GetProtocolObject.
CloudTask implTask = taskToAdd;
if (null == implTask)
{
throw new ArgumentOutOfRangeException("taskToAdd");
}
// ensure we have artifacts
if (null == allFileStagingArtifacts)
{
allFileStagingArtifacts = new ConcurrentDictionary<Type, IFileStagingArtifact>();
}
// start file staging
Task stagingTask = implTask.StageFilesAsync(allFileStagingArtifacts);
// wait for the files to be staged
await stagingTask.ConfigureAwait(continueOnCapturedContext: false);
// get the CloudTask to convert itself to a protocol object
Models.TaskAddParameter protoTask = implTask.GetTransportObject();
implTask.Freeze(); //Mark the underlying task readonly
// start the AddTask request
Task asyncTask = ParentBatchClient.ProtocolLayer.AddTask(jobId, protoTask, bhMgr, cancellationToken);
await asyncTask.ConfigureAwait(continueOnCapturedContext: false);
}
/// <summary>
/// Adds a single task to a job. To add multiple tasks,
/// use <see cref="AddTaskAsync(string,IEnumerable{CloudTask},BatchClientParallelOptions,ConcurrentBag{ConcurrentDictionary{Type, IFileStagingArtifact}},TimeSpan?,IEnumerable{BatchClientBehavior})">JobOperations.AddTaskAsync</see>.
/// </summary>
/// <param name="jobId">The id of the job to which to add the task.</param>
/// <param name="taskToAdd">The <see cref="CloudTask"/> to add.</param>
/// <param name="allFileStagingArtifacts">An optional collection to customize and receive information about the file staging process (see <see cref="CloudTask.FilesToStage"/>).
/// For more information see <see cref="IFileStagingArtifact"/>.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
/// <returns>A <see cref="Task"/> object that represents the asynchronous operation.</returns>
/// <remarks>
/// <para>Each call to this method incurs a request to the Batch service. Therefore, using this method to add
/// multiple tasks is less efficient than using a bulk add method, and can incur HTTP connection restrictions.
/// If you are performing many of these operations in parallel and are seeing client side timeouts, please see
/// http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit%28v=vs.110%29.aspx
/// or use the multiple-task overload of AddTaskAsync.</para>
/// <para>The add task operation runs asynchronously.</para>
/// </remarks>
public Task AddTaskAsync(
string jobId,
CloudTask taskToAdd,
ConcurrentDictionary<Type, IFileStagingArtifact> allFileStagingArtifacts = null,
IEnumerable<BatchClientBehavior> additionalBehaviors = null,
CancellationToken cancellationToken = default)
{
// set up behavior manager
BehaviorManager bhMgr = new BehaviorManager(CustomBehaviors, additionalBehaviors);
Task asyncTask = AddTaskAsyncImpl(jobId, taskToAdd, bhMgr, cancellationToken, allFileStagingArtifacts);
return asyncTask;
}
/// <summary>
/// Adds a single task to a job. To add multiple tasks,
/// use <see cref="AddTask(string,IEnumerable{CloudTask},BatchClientParallelOptions,ConcurrentBag{ConcurrentDictionary{Type, IFileStagingArtifact}},TimeSpan?,IEnumerable{BatchClientBehavior})">JobOperations.AddTaskAsync</see>.
/// </summary>
/// <param name="jobId">The id of the job to which to add the task.</param>
/// <param name="taskToAdd">The <see cref="CloudTask"/> to add.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <returns>A collection of information about the file staging process (see <see cref="CloudTask.FilesToStage"/>).
/// For more information see <see cref="IFileStagingArtifact"/>.</returns>
/// <remarks>
/// <para>Each call to this method incurs a request to the Batch service. Therefore, using this method to add
/// multiple tasks is less efficient than using a bulk add method, and can incur HTTP connection restrictions.
/// If you are performing many of these operations in parallel and are seeing client side timeouts, please see
/// http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit%28v=vs.110%29.aspx
/// or use the multiple-task overload of AddTask.</para>
/// <para>This is a blocking operation. For a non-blocking equivalent, see <see cref="AddTaskAsync(string, CloudTask, ConcurrentDictionary{Type, IFileStagingArtifact}, IEnumerable{BatchClientBehavior}, CancellationToken)"/>.</para>
/// </remarks>
public ConcurrentDictionary<Type, IFileStagingArtifact> AddTask(string jobId, CloudTask taskToAdd, IEnumerable<BatchClientBehavior> additionalBehaviors = null)
{
ConcurrentDictionary<Type, IFileStagingArtifact> artifacts = new ConcurrentDictionary<Type, IFileStagingArtifact>();
Task asyncTask = AddTaskAsync(jobId, taskToAdd, artifacts, additionalBehaviors);
asyncTask.WaitAndUnaggregateException(CustomBehaviors, additionalBehaviors);
return artifacts;
}
internal IPagedEnumerable<NodeFile> ListNodeFilesImpl(
string jobId,
string taskId,
bool? recursive,
BehaviorManager bhMgr,
DetailLevel detailLevel)
{
PagedEnumerable<NodeFile> enumerable = new PagedEnumerable<NodeFile>( // the lamda will be the enumerator factory
() =>
{
// here is the actual strongly typed enumerator
AsyncListNodeFilesByTaskEnumerator typedEnumerator = new AsyncListNodeFilesByTaskEnumerator(this, jobId, taskId, recursive, bhMgr, detailLevel);
// here is the base
PagedEnumeratorBase<NodeFile> enumeratorBase = typedEnumerator;
return enumeratorBase;
});
return enumerable;
}
internal IPagedEnumerable<SubtaskInformation> ListSubtasksImpl(
string jobId,
string taskId,
BehaviorManager bhMgr,
DetailLevel detailLevel)
{
PagedEnumerable<SubtaskInformation> enumerable = new PagedEnumerable<SubtaskInformation>( // the lamda will be the enumerator factory
() =>
{
// here is the actual strongly typed enumerator
AsyncListSubtasksEnumerator typedEnumerator = new AsyncListSubtasksEnumerator(this, jobId, taskId, bhMgr, detailLevel);
// here is the base
PagedEnumeratorBase<SubtaskInformation> enumeratorBase = typedEnumerator;
return enumeratorBase;
});
return enumerable;
}
/// <summary>
/// Enumerates the <see cref="NodeFile">NodeFiles</see> in the specified task's directory on its compute node.
/// </summary>
/// <param name="jobId">The id of the job.</param>
/// <param name="taskId">The id of the task.</param>
/// <param name="recursive">If true, performs a recursive list of all files of the task. If false, returns only the files in the root task directory.</param>
/// <param name="detailLevel">A <see cref="DetailLevel"/> used for filtering the list and for controlling which properties are retrieved from the service.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/> and <paramref name="detailLevel"/>.</param>
/// <returns>An <see cref="IPagedEnumerable{NodeFile}"/> that can be used to enumerate files asynchronously or synchronously.</returns>
/// <remarks>This method returns immediately; the file data is retrieved from the Batch service only when the collection is enumerated.
/// Retrieval is non-atomic; file data is retrieved in pages during enumeration of the collection.</remarks>
public IPagedEnumerable<NodeFile> ListNodeFiles(
string jobId,
string taskId,
bool? recursive = null,
DetailLevel detailLevel = null,
IEnumerable<BatchClientBehavior> additionalBehaviors = null)
{
// set up behavior manager
BehaviorManager bhMgr = new BehaviorManager(CustomBehaviors, additionalBehaviors);
// get the enumerable
IPagedEnumerable<NodeFile> enumerable = ListNodeFilesImpl(jobId, taskId, recursive, bhMgr, detailLevel);
return enumerable;
}
/// <summary>
/// Terminates the specified task.
/// </summary>
/// <param name="jobId">The id of the job containing the task.</param>
/// <param name="taskId">The id of the task.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The terminate operation runs asynchronously.</remarks>
public Task TerminateTaskAsync(
string jobId,
string taskId,
IEnumerable<BatchClientBehavior> additionalBehaviors = null,
CancellationToken cancellationToken = default)
{
// set up behavior manager
BehaviorManager bhMgr = new BehaviorManager(CustomBehaviors, additionalBehaviors);
Task asyncTask = ParentBatchClient.ProtocolLayer.TerminateTask(jobId, taskId, bhMgr, cancellationToken);
return asyncTask;
}
/// <summary>
/// Terminates the specified task.
/// </summary>
/// <param name="jobId">The id of the job containing the task.</param>
/// <param name="taskId">The id of the task.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>This is a blocking operation. For a non-blocking equivalent, see <see cref="TerminateTaskAsync"/>.</remarks>
public void TerminateTask(
string jobId,
string taskId,
IEnumerable<BatchClientBehavior> additionalBehaviors = null)
{
Task asyncTask = TerminateTaskAsync(jobId, taskId, additionalBehaviors);
asyncTask.WaitAndUnaggregateException(CustomBehaviors, additionalBehaviors);
}
/// <summary>
/// Deletes the specified task.
/// </summary>
/// <param name="jobId">The id of the job containing the task.</param>
/// <param name="taskId">The id of the task.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>The delete operation runs asynchronously.</remarks>
public Task DeleteTaskAsync(
string jobId,
string taskId,
IEnumerable<BatchClientBehavior> additionalBehaviors = null,
CancellationToken cancellationToken = default)
{
// set up behavior manager
BehaviorManager bhMgr = new BehaviorManager(CustomBehaviors, additionalBehaviors);
Task asyncTask = ParentBatchClient.ProtocolLayer.DeleteTask(jobId, taskId, bhMgr, cancellationToken);
return asyncTask;
}
/// <summary>
/// Deletes the specified task.
/// </summary>
/// <param name="jobId">The id of the job containing the task.</param>
/// <param name="taskId">The id of the task.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <remarks>This is a blocking operation. For a non-blocking equivalent, see <see cref="DeleteTaskAsync"/>.</remarks>
public void DeleteTask(
string jobId,
string taskId,
IEnumerable<BatchClientBehavior> additionalBehaviors = null)
{
Task asyncTask = DeleteTaskAsync(jobId, taskId, additionalBehaviors);
asyncTask.WaitAndUnaggregateException(CustomBehaviors, additionalBehaviors);
}
/// <summary>
/// Reactivates a task, allowing it to run again even if its retry count has been exhausted.
/// </summary>
/// <param name="jobId">The id of the job containing the task.</param>
/// <param name="taskId">The id of the task.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
/// <remarks>
/// <para>
/// Reactivation makes a task eligible to be retried again up to its maximum retry count.
/// </para>
/// <para>
/// Additionally, this will fail if the job is in the <see cref="JobState.Completed"/> or <see cref="JobState.Terminating"/> or <see cref="JobState.Deleting"/> state.
/// This is a blocking operation. For a non-blocking equivalent, see <see cref="ReactivateTaskAsync"/>.
/// </para>
/// <para>
/// The reactivate operation runs asynchronously.
/// </para>
/// </remarks>
public Task ReactivateTaskAsync(
string jobId,
string taskId,
IEnumerable<BatchClientBehavior> additionalBehaviors = null,
CancellationToken cancellationToken = default)
{
// set up behavior manager
BehaviorManager bhMgr = new BehaviorManager(CustomBehaviors, additionalBehaviors);
Task asyncTask = ParentBatchClient.ProtocolLayer.ReactivateTask(jobId, taskId, bhMgr, cancellationToken);
return asyncTask;
}
/// <summary>
/// Reactivates a task, allowing it to run again even if its retry count has been exhausted.
/// </summary>
/// <param name="jobId">The id of the job containing the task.</param>
/// <param name="taskId">The id of the task.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <remarks>
/// <para>
/// Reactivation makes a task eligible to be retried again up to its maximum retry count.
/// </para>
/// <para>
/// This operation will fail for tasks that are not completed or that previously completed successfully (with an exit code of 0).
/// </para>
/// <para>
/// Additionally, this will fail if the job is in the <see cref="JobState.Completed"/> or <see cref="JobState.Terminating"/> or <see cref="JobState.Deleting"/> state.
/// This is a blocking operation. For a non-blocking equivalent, see <see cref="ReactivateTaskAsync"/>.
/// </para>
/// </remarks>
public void ReactivateTask(
string jobId,
string taskId,
IEnumerable<BatchClientBehavior> additionalBehaviors = null)
{
Task asyncTask = ReactivateTaskAsync(jobId, taskId, additionalBehaviors);
asyncTask.WaitAndUnaggregateException(CustomBehaviors, additionalBehaviors);
}
internal async Task<NodeFile> GetNodeFileAsyncImpl(
string jobId,
string taskId,
string filePath,
BehaviorManager bhMgr,
CancellationToken cancellationToken)
{
var getNodeFilePropertiesTask = await ParentBatchClient.ProtocolLayer.GetNodeFilePropertiesByTask(
jobId,
taskId,
filePath,
bhMgr,
cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
Models.NodeFile file = getNodeFilePropertiesTask.Body;
// wrap protocol object
NodeFile wrapped = new TaskFile(this, jobId, taskId, file, bhMgr.BaseBehaviors);
return wrapped;
}
/// <summary>
/// Gets the specified <see cref="NodeFile"/> from the specified task's directory on its compute node.
/// </summary>
/// <param name="jobId">The id of the job containing the task.</param>
/// <param name="taskId">The id of the task.</param>
/// <param name="filePath">The path of the file to retrieve.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
/// <returns>A <see cref="NodeFile"/> representing the specified file.</returns>
/// <remarks>The get file operation runs asynchronously.</remarks>
public Task<NodeFile> GetNodeFileAsync(
string jobId,
string taskId,
string filePath,
IEnumerable<BatchClientBehavior> additionalBehaviors = null,
CancellationToken cancellationToken = default)
{
// set up behavior manager
BehaviorManager bhMgr = new BehaviorManager(CustomBehaviors, additionalBehaviors);
Task<NodeFile> asyncTask = GetNodeFileAsyncImpl(jobId, taskId, filePath, bhMgr, cancellationToken);
return asyncTask;
}
/// <summary>
/// Gets the specified <see cref="NodeFile"/> from the specified task's directory on its compute node.
/// </summary>
/// <param name="jobId">The id of the job containing the task.</param>
/// <param name="taskId">The id of the task.</param>
/// <param name="filePath">The path of the file to retrieve.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <returns>A <see cref="NodeFile"/> representing the specified file.</returns>
/// <remarks>This is a blocking operation. For a non-blocking equivalent, see <see cref="GetNodeFileAsync"/>.</remarks>
public NodeFile GetNodeFile(
string jobId,
string taskId,
string filePath,
IEnumerable<BatchClientBehavior> additionalBehaviors = null)
{
Task<NodeFile> asyncTask = GetNodeFileAsync(jobId, taskId, filePath, additionalBehaviors);
NodeFile file = asyncTask.WaitAndUnaggregateException(CustomBehaviors, additionalBehaviors);
return file;
}
internal async Task CopyNodeFileContentToStreamAsyncImpl(
string jobId,
string taskId,
string filePath,
Stream stream,
GetFileRequestByteRange byteRange,
BehaviorManager bhMgr,
CancellationToken cancellationToken)
{
await ParentBatchClient.ProtocolLayer.GetNodeFileByTask(
jobId,
taskId,
filePath,
stream,
byteRange,
bhMgr,
cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
}
/// <summary>
/// Copies the contents of a file from the specified task's directory on its compute node to the given <see cref="Stream"/>.
/// </summary>
/// <param name="jobId">The id of the job containing the task.</param>
/// <param name="taskId">The id of the task.</param>
/// <param name="filePath">The path of the file to retrieve.</param>
/// <param name="stream">The stream to copy the file contents to.</param>
/// <param name="byteRange">A byte range defining what section of the file to copy. If omitted, the entire file is downloaded.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
/// <remarks>The get file operation runs asynchronously.</remarks>
public Task CopyNodeFileContentToStreamAsync(
string jobId,
string taskId,
string filePath,
Stream stream,
GetFileRequestByteRange byteRange = null,
IEnumerable<BatchClientBehavior> additionalBehaviors = null,
CancellationToken cancellationToken = default)
{
// set up behavior manager
BehaviorManager bhMgr = new BehaviorManager(CustomBehaviors, additionalBehaviors);
return CopyNodeFileContentToStreamAsyncImpl(jobId, taskId, filePath, stream, byteRange, bhMgr, cancellationToken);
}
/// <summary>
/// Copies the contents of a file from the specified task's directory on its compute node to the given <see cref="Stream"/>.
/// </summary>
/// <param name="jobId">The id of the job containing the task.</param>
/// <param name="taskId">The id of the task.</param>
/// <param name="filePath">The path of the file to retrieve.</param>
/// <param name="stream">The stream to copy the file contents to.</param>
/// <param name="byteRange">A byte range defining what section of the file to copy. If omitted, the entire file is downloaded.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <remarks>This is a blocking operation. For a non-blocking equivalent, see <see cref="CopyNodeFileContentToStreamAsync"/>.</remarks>
public void CopyNodeFileContentToStream(
string jobId,
string taskId,
string filePath,
Stream stream,
GetFileRequestByteRange byteRange = null,
IEnumerable<BatchClientBehavior> additionalBehaviors = null)
{
Task asyncTask = CopyNodeFileContentToStreamAsync(jobId, taskId, filePath, stream, byteRange, additionalBehaviors);
asyncTask.WaitAndUnaggregateException(CustomBehaviors, additionalBehaviors);
}
internal Task<string> CopyNodeFileContentToStringAsyncImpl(
string jobId,
string taskId,
string filePath,
Encoding encoding,
GetFileRequestByteRange byteRange,
BehaviorManager bhMgr,
CancellationToken cancellationToken)
{
return UtilitiesInternal.ReadNodeFileAsStringAsync(
// Note that behaviors is purposefully dropped in the below call since it's already managed by the bhMgr
(stream, bRange, behaviors, ct) => CopyNodeFileContentToStreamAsyncImpl(jobId, taskId, filePath, stream, bRange, bhMgr, ct),
encoding,
byteRange,
additionalBehaviors: null,
cancellationToken: cancellationToken);
}
/// <summary>
/// Reads the contents of a file from the specified task's directory on its compute node into a string.
/// </summary>
/// <param name="jobId">The id of the job containing the task.</param>
/// <param name="taskId">The id of the task.</param>
/// <param name="filePath">The path of the file to retrieve.</param>
/// <param name="encoding">The encoding to use. If no value or null is specified, UTF8 is used.</param>
/// <param name="byteRange">A byte range defining what section of the file to copy. If omitted, the entire file is downloaded.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
/// <returns>The contents of the file, as a string</returns>
public Task<string> CopyNodeFileContentToStringAsync(
string jobId,
string taskId,
string filePath,
Encoding encoding = null,
GetFileRequestByteRange byteRange = null,
IEnumerable<BatchClientBehavior> additionalBehaviors = null,
CancellationToken cancellationToken = default)
{
// set up behavior manager
BehaviorManager bhMgr = new BehaviorManager(CustomBehaviors, additionalBehaviors);
return CopyNodeFileContentToStringAsyncImpl(jobId, taskId, filePath, encoding, byteRange, bhMgr, cancellationToken);
}
/// <summary>
/// Reads the contents of a file from the specified task's directory on its compute node into a string.
/// </summary>
/// <param name="jobId">The id of the job containing the task.</param>
/// <param name="taskId">The id of the task.</param>
/// <param name="filePath">The path of the file to retrieve.</param>
/// <param name="encoding">The encoding to use. If no value or null is specified, UTF8 is used.</param>
/// <param name="byteRange">A byte range defining what section of the file to copy. If omitted, the entire file is downloaded.</param>
/// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param>
/// <returns>The contents of the file, as a string</returns>
public string CopyNodeFileContentToString(
string jobId,
string taskId,
string filePath,
Encoding encoding = null,