| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. See License.txt in the project root for license information. |
| | 3 | |
|
| | 4 | | namespace Microsoft.Azure.Batch |
| | 5 | | { |
| | 6 | | using System; |
| | 7 | | using System.Collections.Concurrent; |
| | 8 | | using System.Collections.Generic; |
| | 9 | | using System.Threading; |
| | 10 | | using System.Threading.Tasks; |
| | 11 | | using Microsoft.Rest.Azure; |
| | 12 | | using Utils; |
| | 13 | | using Models = Microsoft.Azure.Batch.Protocol.Models; |
| | 14 | |
|
| | 15 | | /// <summary> |
| | 16 | | /// An Azure Batch job. |
| | 17 | | /// </summary> |
| | 18 | | public partial class CloudJob : IRefreshable |
| | 19 | | { |
| | 20 | |
|
| | 21 | | #region // CloudJob |
| | 22 | |
|
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// Commits this <see cref="CloudJob" /> to the Azure Batch service. |
| | 26 | | /// </summary> |
| | 27 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| | 28 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynch |
| | 29 | | /// <returns>A <see cref="System.Threading.Tasks.Task"/> that represents the asynchronous operation.</returns> |
| | 30 | | /// <remarks> |
| | 31 | | /// <para>If the <see cref="CloudJob"/> already exists on the Batch service, its properties are replaced by the |
| | 32 | | /// <para>The commit operation runs asynchronously.</para> |
| | 33 | | /// </remarks> |
| | 34 | | public async System.Threading.Tasks.Task CommitAsync( |
| | 35 | | IEnumerable<BatchClientBehavior> additionalBehaviors = null, |
| | 36 | | CancellationToken cancellationToken = default(CancellationToken)) |
| | 37 | | { |
| | 38 | | // first forbid actions during commit |
| 4 | 39 | | this.propertyContainer.IsReadOnly = true; |
| | 40 | |
|
| | 41 | | // craft the behavior manager for this call |
| 4 | 42 | | BehaviorManager behaveMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors); |
| | 43 | |
|
| | 44 | | // hold the tpl task for the server call |
| | 45 | | System.Threading.Tasks.Task asyncTask; |
| | 46 | |
|
| 4 | 47 | | if (BindingState.Unbound == this.propertyContainer.BindingState) // unbound commit |
| | 48 | | { |
| | 49 | | // take all property changes and create a job |
| 4 | 50 | | Models.JobAddParameter protoJob = this.GetTransportObject(); |
| | 51 | |
|
| 112 | 52 | | asyncTask = this.parentBatchClient.ProtocolLayer.AddJob(protoJob, behaveMgr, cancellationToken); |
| | 53 | | } |
| 108 | 54 | | else |
| 108 | 55 | | { |
| 108 | 56 | | Models.MetadataItem[] modelMetadata = UtilitiesInternal.ConvertToProtocolArray(this.Metadata); |
| 108 | 57 | | Models.JobConstraints modelJobConstraints = UtilitiesInternal.CreateObjectWithNullCheck(this.Constraints |
| 108 | 58 | | Models.PoolInformation modelPoolInformation = UtilitiesInternal.CreateObjectWithNullCheck(this.PoolInfor |
| 108 | 59 | |
|
| 108 | 60 | | asyncTask = this.parentBatchClient.ProtocolLayer.UpdateJob( |
| 108 | 61 | | this.Id, |
| 108 | 62 | | this.Priority, |
| 108 | 63 | | UtilitiesInternal.MapNullableEnum<Common.OnAllTasksComplete, Models.OnAllTasksComplete>(this.OnAllTa |
| 108 | 64 | | modelPoolInformation, |
| 108 | 65 | | modelJobConstraints, |
| 108 | 66 | | modelMetadata, |
| 108 | 67 | | behaveMgr, |
| 108 | 68 | | cancellationToken); |
| 108 | 69 | | } |
| 108 | 70 | |
|
| 112 | 71 | | await asyncTask.ConfigureAwait(continueOnCapturedContext: false); |
| 110 | 72 | | } |
| 108 | 73 | |
|
| 108 | 74 | | /// <summary> |
| 108 | 75 | | /// Commits this <see cref="CloudJob" /> to the Azure Batch service. |
| 108 | 76 | | /// </summary> |
| 108 | 77 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| 108 | 78 | | /// <remarks> |
| | 79 | | /// <para>If the <see cref="CloudJob"/> already exists on the Batch service, its properties are replaced by the |
| 1016 | 80 | | /// <para>This is a blocking operation. For a non-blocking equivalent, see <see cref="CommitAsync"/>.</para> |
| | 81 | | /// </remarks> |
| 1016 | 82 | | public void Commit(IEnumerable<BatchClientBehavior> additionalBehaviors = null) |
| 1016 | 83 | | { |
| 1017 | 84 | | Task asyncTask = CommitAsync(additionalBehaviors); |
| 1017 | 85 | | asyncTask.WaitAndUnaggregateException(this.CustomBehaviors, additionalBehaviors); |
| 1017 | 86 | | } |
| 1517 | 87 | |
|
| 1016 | 88 | | /// <summary> |
| 1016 | 89 | | /// Commits all pending changes to this <see cref="CloudJob" /> to the Azure Batch service. |
| 1016 | 90 | | /// </summary> |
| 1016 | 91 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| 1016 | 92 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynch |
| 1016 | 93 | | /// <returns>A <see cref="System.Threading.Tasks.Task"/> that represents the asynchronous operation.</returns> |
| 1016 | 94 | | /// <remarks> |
| 1016 | 95 | | /// <para> |
| 1016 | 96 | | /// Updates an existing <see cref="CloudJob"/> on the Batch service by replacing its properties with the propert |
| 1016 | 97 | | /// Unchanged properties are ignored. |
| 1016 | 98 | | /// All changes since the last time this entity was retrieved from the Batch service (either via <see cref="Refr |
| 1016 | 99 | | /// or <see cref="JobOperations.ListJobs"/>) are applied. |
| 1016 | 100 | | /// Properties which are explicitly set to null will cause an exception because the Batch service does not suppo |
| 1016 | 101 | | /// If you need to set a property to null, use <see cref="Commit"/>. |
| 1016 | 102 | | /// </para> |
| 1531 | 103 | | /// <para>This operation runs asynchronously.</para> |
| 1016 | 104 | | /// </remarks> |
| 1016 | 105 | | public async Task CommitChangesAsync( |
| 1016 | 106 | | IEnumerable<BatchClientBehavior> additionalBehaviors = null, |
| 1016 | 107 | | CancellationToken cancellationToken = default(CancellationToken)) |
| 1016 | 108 | | { |
| 1024 | 109 | | UtilitiesInternal.ThrowOnUnbound(this.propertyContainer.BindingState); |
| 1016 | 110 | |
|
| 1516 | 111 | | // first forbid actions during patch |
| 1023 | 112 | | this.propertyContainer.IsReadOnly = true; |
| 1016 | 113 | |
|
| 1016 | 114 | | // craft the behavior manager for this call |
| 1543 | 115 | | BehaviorManager behaveMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors); |
| 1016 | 116 | |
|
| 1023 | 117 | | Models.MetadataItem[] modelMetadata = this.propertyContainer.MetadataProperty. |
| 1023 | 118 | | GetTransportObjectIfChanged<MetadataItem, Models.MetadataItem>(); |
| 1531 | 119 | | Models.JobConstraints modelJobConstraints = this.propertyContainer.ConstraintsProperty. |
| 1023 | 120 | | GetTransportObjectIfChanged<JobConstraints, Models.JobConstraints>(); |
| 1023 | 121 | | Models.PoolInformation modelPoolInformation = this.propertyContainer.PoolInformationProperty. |
| 1023 | 122 | | GetTransportObjectIfChanged<PoolInformation, Models.PoolInformation>(); |
| 1022 | 123 | | int? priority = this.propertyContainer.PriorityProperty.GetIfChangedOrNull(); |
| 1016 | 124 | |
|
| 1022 | 125 | | Task asyncTask = this.parentBatchClient.ProtocolLayer.PatchJob( |
| 1022 | 126 | | this.Id, |
| 1022 | 127 | | priority, |
| 1022 | 128 | | UtilitiesInternal.MapNullableEnum<Common.OnAllTasksComplete, Models.OnAllTasksComplete>(this.OnAllTasksC |
| 1022 | 129 | | modelPoolInformation, |
| 1022 | 130 | | modelJobConstraints, |
| 1522 | 131 | | modelMetadata, |
| 1022 | 132 | | behaveMgr, |
| 1022 | 133 | | cancellationToken); |
| 1016 | 134 | |
|
| 1022 | 135 | | await asyncTask.ConfigureAwait(continueOnCapturedContext: false); |
| 1022 | 136 | | } |
| 1016 | 137 | |
|
| 1016 | 138 | | /// <summary> |
| 1016 | 139 | | /// Commits all pending changes to this <see cref="CloudJob" /> to the Azure Batch service. |
| 1016 | 140 | | /// </summary> |
| 1016 | 141 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| 1016 | 142 | | /// <remarks> |
| 1523 | 143 | | /// <para> |
| 1016 | 144 | | /// Updates an existing <see cref="CloudJob"/> on the Batch service by replacing its properties with the propert |
| 1016 | 145 | | /// Unchanged properties are ignored. |
| 1016 | 146 | | /// All changes since the last time this entity was retrieved from the Batch service (either via <see cref="Refr |
| 1016 | 147 | | /// or <see cref="JobOperations.ListJobs"/>) are applied. |
| 1016 | 148 | | /// Properties which are explicitly set to null will cause an exception because the Batch service does not suppo |
| 1016 | 149 | | /// If you need to set a property to null, use <see cref="Commit"/>. |
| 1016 | 150 | | /// </para> |
| 1016 | 151 | | /// <para>This is a blocking operation. For a non-blocking equivalent, see <see cref="CommitChangesAsync"/>.</pa |
| 1016 | 152 | | /// </remarks> |
| 1016 | 153 | | public void CommitChanges(IEnumerable<BatchClientBehavior> additionalBehaviors = null) |
| 1016 | 154 | | { |
| 1024 | 155 | | Task asyncTask = this.CommitChangesAsync(additionalBehaviors); |
| 1024 | 156 | | asyncTask.WaitAndUnaggregateException(this.CustomBehaviors, additionalBehaviors); |
| 1022 | 157 | | } |
| 1016 | 158 | |
|
| 1016 | 159 | | /// <summary> |
| 1016 | 160 | | /// Adds a single task to this <see cref="CloudJob"/>. To add multiple tasks, |
| 1016 | 161 | | /// use <see cref="JobOperations.AddTaskAsync(string,IEnumerable{CloudTask},BatchClientParallelOptions,Concurren |
| 1016 | 162 | | /// </summary> |
| 1016 | 163 | | /// <param name="taskToAdd">The <see cref="CloudTask"/> to add.</param> |
| 1016 | 164 | | /// <param name="allFileStagingArtifacts">An optional collection to customize and receive information about the |
| 1016 | 165 | | /// For more information see <see cref="IFileStagingArtifact"/>.</param> |
| 1016 | 166 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| 1521 | 167 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynch |
| 1016 | 168 | | /// <returns>A <see cref="System.Threading.Tasks.Task"/> that represents the asynchronous operation.</returns> |
| 1016 | 169 | | /// <remarks> |
| 1016 | 170 | | /// <para> |
| 1016 | 171 | | /// Each call to this method incurs a request to the Batch service. Therefore, using this method to add |
| 1016 | 172 | | /// multiple tasks is less efficient than using a bulk add method, and can incur HTTP connection restrictions. |
| 1016 | 173 | | /// If you are performing many of these operations in parallel and are seeing client side timeouts (a <see cref= |
| 1016 | 174 | | /// http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit%28v=vs.110%29. |
| 1016 | 175 | | /// or use |
| 1016 | 176 | | /// <see cref="JobOperations.AddTaskAsync(string,IEnumerable{CloudTask},BatchClientParallelOptions,ConcurrentBag |
| 1016 | 177 | | /// </para> |
| 1016 | 178 | | /// <para>The add task operation runs asynchronously.</para> |
| | 179 | | /// </remarks> |
| | 180 | | public async System.Threading.Tasks.Task AddTaskAsync( |
| | 181 | | CloudTask taskToAdd, |
| | 182 | | ConcurrentDictionary<Type, IFileStagingArtifact> allFileStagingArtifacts = null, |
| | 183 | | IEnumerable<BatchClientBehavior> additionalBehaviors = null, |
| | 184 | | CancellationToken cancellationToken = default(CancellationToken)) |
| | 185 | | { |
| 7 | 186 | | UtilitiesInternal.ThrowOnUnbound(this.propertyContainer.BindingState); |
| | 187 | |
|
| | 188 | | // craft the behavior manager for this call |
| 7 | 189 | | BehaviorManager behaveMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors); |
| | 190 | |
|
| 7 | 191 | | System.Threading.Tasks.Task asyncTask = this.parentBatchClient.JobOperations.AddTaskAsyncImpl(this.Id, taskT |
| 108 | 192 | |
|
| 115 | 193 | | await asyncTask.ConfigureAwait(continueOnCapturedContext: false); |
| 115 | 194 | | } |
| | 195 | |
|
| 108 | 196 | | /// <summary> |
| 108 | 197 | | /// Adds a single task to this <see cref="CloudJob"/>. To add multiple tasks, |
| 108 | 198 | | /// use <see cref="JobOperations.AddTask(string,IEnumerable{CloudTask},BatchClientParallelOptions,ConcurrentBag{ |
| 108 | 199 | | /// </summary> |
| | 200 | | /// <param name="taskToAdd">The <see cref="CloudTask"/> to add.</param> |
| 1015 | 201 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| 1015 | 202 | | /// <returns>A collection of information about the file staging process (see <see cref="CloudTask.FilesToStage"/ |
| 1015 | 203 | | /// For more information see <see cref="IFileStagingArtifact"/>.</returns> |
| 1015 | 204 | | /// <remarks> |
| | 205 | | /// <para> |
| 1015 | 206 | | /// Each call to this method incurs a request to the Batch service. Therefore, using this method to add |
| 1015 | 207 | | /// multiple tasks is less efficient than using a bulk add method, and can incur HTTP connection restrictions. |
| 1015 | 208 | | /// If you are performing many of these operations in parallel and are seeing client side timeouts (a <see cref= |
| 1015 | 209 | | /// http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit%28v=vs.110%29. |
| | 210 | | /// or use |
| | 211 | | /// <see cref="JobOperations.AddTask(string,IEnumerable{CloudTask},BatchClientParallelOptions,ConcurrentBag{Conc |
| | 212 | | /// </para> |
| | 213 | | /// <para>This is a blocking operation. For a non-blocking equivalent, see <see cref="AddTaskAsync(CloudTask, Co |
| | 214 | | /// </remarks> |
| | 215 | | public ConcurrentDictionary<Type, IFileStagingArtifact> AddTask(CloudTask taskToAdd, IEnumerable<BatchClientBeha |
| | 216 | | { |
| 7 | 217 | | UtilitiesInternal.ThrowOnUnbound(this.propertyContainer.BindingState); |
| | 218 | |
|
| 7 | 219 | | ConcurrentDictionary<Type, IFileStagingArtifact> allFileStagingArtifacts = new ConcurrentDictionary<Type, IF |
| | 220 | |
|
| 7 | 221 | | Task asyncTask = AddTaskAsync(taskToAdd, allFileStagingArtifacts, additionalBehaviors); |
| 7 | 222 | | asyncTask.WaitAndUnaggregateException(this.CustomBehaviors, additionalBehaviors); |
| 1212 | 223 | |
|
| 7 | 224 | | return allFileStagingArtifacts; |
| | 225 | | } |
| | 226 | |
|
| | 227 | | /// <summary> |
| | 228 | | /// Adds tasks to a job. |
| | 229 | | /// </summary> |
| | 230 | | /// <param name="tasksToAdd">The <see cref="CloudTask"/>s to add.</param> |
| | 231 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| | 232 | | /// <param name="parallelOptions"> |
| | 233 | | /// Controls the number of simultaneous parallel AddTaskCollection requests issued to the Batch service. Each A |
| | 234 | | /// <see cref="Constants.MaxTasksInSingleAddTaskCollectionRequest"/> tasks in it. |
| 1205 | 235 | | /// Also controls the cancellation token for the operation. |
| | 236 | | /// If omitted, the default is used (see <see cref="BatchClientParallelOptions"/>.) |
| | 237 | | /// </param> |
| 52 | 238 | | /// <param name="fileStagingArtifacts">An optional collection to receive information about the file staging proc |
| 51 | 239 | | /// An entry is added to the <see cref="ConcurrentBag{T}"/> for each set of tasks grouped for submission to the |
| | 240 | | /// Unlike single-task adds, you cannot use this parameter to customize the file staging process. |
| | 241 | | /// For more information about the format of each entry, see <see cref="IFileStagingArtifact"/>.</param> |
| | 242 | | /// <param name="timeout">The amount of time after which the operation times out.</param> |
| | 243 | | /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</ret |
| | 244 | | /// <remarks> |
| | 245 | | /// <para>The add task operation runs asynchronously.</para> |
| | 246 | | /// <para>This method is not atomic; that is, it is possible for the method to start adding tasks and |
| 1208 | 247 | | /// then fail. The collection of tasks to add is broken down into chunks of size at most <see cref="Constants.Ma |
| 95 | 248 | | /// and an AddTaskCollection request is issued for each chunk. Requests may be issued in parallel according to |
| | 249 | | /// the <paramref name="parallelOptions"/>.</para> |
| | 250 | | /// <para>Issuing a large number of simultaneous requests to the Batch service can incur HTTP connection restric |
| | 251 | | /// If you are performing many of these operations in parallel (or have specified a large MaxDegreeOfParallelism |
| | 252 | | /// the parallelOptions) and are seeing client side timeouts (a <see cref="TaskCanceledException"/>), please see |
| | 253 | | /// http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit%28v=vs.110%29. |
| | 254 | | /// <para>The progress of the operation in the face of errors is determined by <see cref="AddTaskCollectionResul |
| | 255 | | /// You do not normally need to specify this behavior, as the Batch client uses a default which works in normal |
| 1002 | 256 | | /// If you do want to customize this behavior, specify an AddTaskCollectionResultHandler in the <see cref="Custo |
| | 257 | | /// or <paramref name="additionalBehaviors"/> collections.</para> |
| | 258 | | /// </remarks> |
| | 259 | | /// <exception cref="ParallelOperationsException">Thrown if one or more requests to the Batch service fail.</exc |
| | 260 | | public async Task AddTaskAsync( |
| | 261 | | IEnumerable<CloudTask> tasksToAdd, |
| | 262 | | BatchClientParallelOptions parallelOptions = null, |
| | 263 | | ConcurrentBag<ConcurrentDictionary<Type, IFileStagingArtifact>> fileStagingArtifacts = null, |
| 1207 | 264 | | TimeSpan? timeout = null, |
| 111 | 265 | | IEnumerable<BatchClientBehavior> additionalBehaviors = null) |
| | 266 | | { |
| 0 | 267 | | UtilitiesInternal.ThrowOnUnbound(this.propertyContainer.BindingState); |
| | 268 | |
|
| | 269 | | // craft the behavior manager for this call |
| 0 | 270 | | BehaviorManager behaveMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors); |
| | 271 | |
|
| 0 | 272 | | Task asyncTask = this.parentBatchClient.JobOperations.AddTaskAsyncImpl(this.Id, tasksToAdd, parallelOptions, |
| 1001 | 273 | |
|
| 0 | 274 | | await asyncTask.ConfigureAwait(continueOnCapturedContext: false); |
| 0 | 275 | | } |
| | 276 | |
|
| | 277 | | /// <summary> |
| | 278 | | /// Adds tasks to a job. |
| | 279 | | /// </summary> |
| | 280 | | /// <param name="tasksToAdd">The <see cref="CloudTask"/>s to add.</param> |
| 1001 | 281 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| | 282 | | /// <param name="parallelOptions"> |
| | 283 | | /// Controls the number of simultaneous parallel AddTaskCollection requests issued to the Batch service. Each A |
| | 284 | | /// <see cref="Constants.MaxTasksInSingleAddTaskCollectionRequest"/> tasks in it. |
| | 285 | | /// Also controls the cancellation token for the operation. |
| | 286 | | /// If omitted, the default is used (see <see cref="BatchClientParallelOptions"/>.) |
| | 287 | | /// </param> |
| | 288 | | /// <param name="fileStagingArtifacts">An optional collection to receive information about the file staging proc |
| 1229 | 289 | | /// An entry is added to the <see cref="ConcurrentBag{T}"/> for each set of tasks grouped for submission to the |
| 119 | 290 | | /// Unlike single-task adds, you cannot use this parameter to customize the file staging process. |
| | 291 | | /// For more information about the format of each entry, see <see cref="IFileStagingArtifact"/>.</param> |
| | 292 | | /// <param name="timeout">The amount of time after which the operation times out.</param> |
| | 293 | | /// <remarks> |
| | 294 | | /// <para>This is a blocking operation; for a non-blocking equivalent, see <see cref="AddTaskAsync(IEnumerable{C |
| | 295 | | /// <para>This method is not atomic; that is, it is possible for the method to start adding tasks and |
| | 296 | | /// then fail. The collection of tasks to add is broken down into chunks of size at most <see cref="Constants.Ma |
| | 297 | | /// and an AddTaskCollection request is issued for each chunk. Requests may be issued in parallel according to |
| 1211 | 298 | | /// the <paramref name="parallelOptions"/>.</para> |
| 98 | 299 | | /// <para>Issuing a large number of simultaneous requests to the Batch service can incur HTTP connection restric |
| | 300 | | /// If you are performing many of these operations in parallel (or have specified a large MaxDegreeOfParallelism |
| | 301 | | /// the parallelOptions) and are seeing client side timeouts (a <see cref="TaskCanceledException"/>), please see |
| | 302 | | /// http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit%28v=vs.110%29. |
| | 303 | | /// <para>The progress of the operation in the face of errors is determined by <see cref="AddTaskCollectionResul |
| | 304 | | /// You do not normally need to specify this behavior, as the Batch client uses a default which works in normal |
| | 305 | | /// If you do want to customize this behavior, specify an AddTaskCollectionResultHandler in the <see cref="Custo |
| | 306 | | /// or <paramref name="additionalBehaviors"/> collections.</para> |
| | 307 | | /// </remarks> |
| 1207 | 308 | | /// <exception cref="ParallelOperationsException">Thrown if one or more requests to the Batch service fail.</exc |
| 105 | 309 | | public void AddTask( |
| | 310 | | IEnumerable<CloudTask> tasksToAdd, |
| | 311 | | BatchClientParallelOptions parallelOptions = null, |
| | 312 | | ConcurrentBag<ConcurrentDictionary<Type, IFileStagingArtifact>> fileStagingArtifacts = null, |
| | 313 | | TimeSpan? timeout = null, |
| | 314 | | IEnumerable<BatchClientBehavior> additionalBehaviors = null) |
| | 315 | | { |
| 0 | 316 | | UtilitiesInternal.ThrowOnUnbound(this.propertyContainer.BindingState); |
| | 317 | |
|
| 1205 | 318 | | Task asyncTask = this.AddTaskAsync(tasksToAdd, parallelOptions, fileStagingArtifacts, timeout, additionalBeh |
| 99 | 319 | | asyncTask.WaitAndUnaggregateException(this.CustomBehaviors, additionalBehaviors); |
| 0 | 320 | | } |
| | 321 | |
|
| | 322 | | /// <summary> |
| | 323 | | /// Enumerates the <see cref="CloudTask">tasks</see> of this <see cref="CloudJob"/>. |
| | 324 | | /// </summary> |
| | 325 | | /// <param name="detailLevel">A <see cref="DetailLevel"/> used for filtering the list and for controlling which |
| | 326 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| 1001 | 327 | | /// <returns>An <see cref="IPagedEnumerable{CloudTask}"/> that can be used to enumerate tasks asynchronously or |
| | 328 | | /// <remarks>This method returns immediately; the tasks are retrieved from the Batch service only when the colle |
| | 329 | | /// Retrieval is non-atomic; tasks are retrieved in pages during enumeration of the collection.</remarks> |
| | 330 | | public IPagedEnumerable<CloudTask> ListTasks(DetailLevel detailLevel = null, IEnumerable<BatchClientBehavior> ad |
| | 331 | | { |
| | 332 | | // throw if if this object is unbound |
| 0 | 333 | | UtilitiesInternal.ThrowOnUnbound(this.propertyContainer.BindingState); |
| | 334 | |
|
| 1210 | 335 | | // craft the behavior manager for this call |
| 0 | 336 | | BehaviorManager behaveMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors); |
| | 337 | |
|
| 51 | 338 | | IPagedEnumerable<CloudTask> ienumAsync = this.parentBatchClient.JobOperations.ListTasksImpl(this.Id, behaveM |
| 50 | 339 | |
|
| 0 | 340 | | return ienumAsync; |
| | 341 | | } |
| | 342 | |
|
| | 343 | | /// <summary> |
| | 344 | | /// Gets the specified <see cref="CloudTask"/>. |
| | 345 | | /// </summary> |
| | 346 | | /// <param name="taskId">The id of the task to get.</param> |
| 1205 | 347 | | /// <param name="detailLevel">A <see cref="DetailLevel"/> used for controlling which properties are retrieved fr |
| 99 | 348 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| | 349 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynch |
| | 350 | | /// <returns>A <see cref="CloudTask"/> containing information about the specified Azure Batch task.</returns> |
| | 351 | | /// <remarks>The get task operation runs asynchronously.</remarks> |
| | 352 | | public async System.Threading.Tasks.Task<CloudTask> GetTaskAsync( |
| | 353 | | string taskId, |
| | 354 | | DetailLevel detailLevel = null, |
| | 355 | | IEnumerable<BatchClientBehavior> additionalBehaviors = null, |
| | 356 | | CancellationToken cancellationToken = default(CancellationToken)) |
| 1215 | 357 | | { |
| 113 | 358 | | // throw if if this object is unbound |
| 0 | 359 | | UtilitiesInternal.ThrowOnUnbound(this.propertyContainer.BindingState); |
| | 360 | |
|
| | 361 | | // craft the behavior manager for this call |
| 0 | 362 | | BehaviorManager bhMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors, detailLevel); |
| | 363 | |
|
| 0 | 364 | | Task<CloudTask> asyncTask = this.parentBatchClient.JobOperations.GetTaskAsyncImpl(this.Id, taskId, bhMgr, ca |
| 0 | 365 | | CloudTask theTask = await asyncTask.ConfigureAwait(continueOnCapturedContext: false); |
| | 366 | |
|
| 0 | 367 | | return theTask; |
| 0 | 368 | | } |
| | 369 | |
|
| 1207 | 370 | | /// <summary> |
| 93 | 371 | | /// Gets the specified <see cref="CloudTask"/>. |
| | 372 | | /// </summary> |
| | 373 | | /// <param name="taskId">The id of the task to get.</param> |
| | 374 | | /// <param name="detailLevel">A <see cref="DetailLevel"/> used for controlling which properties are retrieved fr |
| | 375 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| | 376 | | /// <returns>A <see cref="CloudTask"/> containing information about the specified Azure Batch task.</returns> |
| | 377 | | /// <remarks>This is a blocking operation. For a non-blocking equivalent, see <see cref="GetTaskAsync"/>.</remar |
| | 378 | | public CloudTask GetTask( |
| 1212 | 379 | | string taskId, |
| 125 | 380 | | DetailLevel detailLevel = null, |
| | 381 | | IEnumerable<BatchClientBehavior> additionalBehaviors = null) |
| | 382 | | { |
| 0 | 383 | | Task<CloudTask> asyncTask = GetTaskAsync(taskId, detailLevel, additionalBehaviors); |
| 0 | 384 | | CloudTask cloudTask = asyncTask.WaitAndUnaggregateException(this.CustomBehaviors, additionalBehaviors); |
| | 385 | |
|
| 0 | 386 | | return cloudTask; |
| | 387 | | } |
| | 388 | |
|
| | 389 | | /// <summary> |
| | 390 | | /// Enables this <see cref="CloudJob"/>, allowing new tasks to run. |
| 1001 | 391 | | /// </summary> |
| | 392 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| | 393 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynch |
| | 394 | | /// <returns>A <see cref="System.Threading.Tasks.Task"/> that represents the asynchronous operation.</returns> |
| | 395 | | /// <remarks>The enable operation runs asynchronously.</remarks> |
| | 396 | | public System.Threading.Tasks.Task EnableAsync(IEnumerable<BatchClientBehavior> additionalBehaviors = null, Canc |
| | 397 | | { |
| | 398 | | // throw if if this object is unbound |
| 0 | 399 | | UtilitiesInternal.ThrowOnUnbound(this.propertyContainer.BindingState); |
| | 400 | |
|
| | 401 | | // craft the behavior manager for this call |
| 0 | 402 | | BehaviorManager bhMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors); |
| 1001 | 403 | |
|
| | 404 | | // start call |
| 0 | 405 | | System.Threading.Tasks.Task asyncTask = this.parentBatchClient.ProtocolLayer.EnableJob(this.Id, bhMgr, cance |
| | 406 | |
|
| 0 | 407 | | return asyncTask; |
| | 408 | | } |
| | 409 | |
|
| | 410 | | /// <summary> |
| | 411 | | /// Enables this <see cref="CloudJob"/>, allowing new tasks to run. |
| | 412 | | /// </summary> |
| | 413 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| | 414 | | /// <remarks>This is a blocking operation. For a non-blocking equivalent, see <see cref="EnableAsync"/>.</remark |
| 1212 | 415 | | public void Enable(IEnumerable<BatchClientBehavior> additionalBehaviors = null) |
| 111 | 416 | | { |
| 0 | 417 | | Task asyncTask = EnableAsync(additionalBehaviors); |
| 0 | 418 | | asyncTask.WaitAndUnaggregateException(this.CustomBehaviors, additionalBehaviors); |
| 0 | 419 | | } |
| | 420 | |
|
| | 421 | | /// <summary> |
| | 422 | | /// Disables this <see cref="CloudJob"/>. Disabled jobs do not run new tasks, but may be re-enabled later. |
| | 423 | | /// </summary> |
| 1001 | 424 | | /// <param name="disableJobOption">Specifies what to do with active tasks associated with the job.</param> |
| | 425 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| | 426 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynch |
| | 427 | | /// <returns>A <see cref="System.Threading.Tasks.Task"/> that represents the asynchronous operation.</returns> |
| | 428 | | /// <remarks>The disable operation runs asynchronously.</remarks> |
| | 429 | | public System.Threading.Tasks.Task DisableAsync( |
| | 430 | | Common.DisableJobOption disableJobOption, |
| | 431 | | IEnumerable<BatchClientBehavior> additionalBehaviors = null, |
| 1001 | 432 | | CancellationToken cancellationToken = default(CancellationToken)) |
| | 433 | | { |
| | 434 | | // throw if if this object is unbound |
| 0 | 435 | | UtilitiesInternal.ThrowOnUnbound(this.propertyContainer.BindingState); |
| | 436 | |
|
| | 437 | | // craft the behavior manager for this call |
| 0 | 438 | | BehaviorManager bhMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors); |
| | 439 | |
|
| | 440 | | // start call |
| 0 | 441 | | System.Threading.Tasks.Task asyncTask = this.parentBatchClient.ProtocolLayer.DisableJob(this.Id, disableJobO |
| | 442 | |
|
| 0 | 443 | | return asyncTask; |
| | 444 | | } |
| 1001 | 445 | |
|
| | 446 | | /// <summary> |
| | 447 | | /// Disables this <see cref="CloudJob"/>. Disabled jobs do not run new tasks, but may be re-enabled later. |
| | 448 | | /// </summary> |
| | 449 | | /// <param name="disableJobOption">Specifies what to do with active tasks associated with the job.</param> |
| | 450 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| | 451 | | /// <remarks>This is a blocking operation. For a non-blocking equivalent, see <see cref="DisableAsync"/>.</remar |
| | 452 | | public void Disable(Common.DisableJobOption disableJobOption, IEnumerable<BatchClientBehavior> additionalBehavio |
| 1003 | 453 | | { |
| 0 | 454 | | Task asyncTask = DisableAsync(disableJobOption, additionalBehaviors); |
| 0 | 455 | | asyncTask.WaitAndUnaggregateException(this.CustomBehaviors, additionalBehaviors); |
| 0 | 456 | | } |
| | 457 | |
|
| | 458 | | /// <summary> |
| | 459 | | /// Terminates this <see cref="CloudJob"/>, marking it as completed. |
| | 460 | | /// </summary> |
| | 461 | | /// <param name="terminateReason">The text you want to appear as the job's <see cref="JobExecutionInformation.Te |
| | 462 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| | 463 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynch |
| 1206 | 464 | | /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</ret |
| 108 | 465 | | /// <remarks>The terminate operation runs asynchronously.</remarks> |
| | 466 | | public System.Threading.Tasks.Task TerminateAsync( |
| | 467 | | string terminateReason = null, |
| | 468 | | IEnumerable<BatchClientBehavior> additionalBehaviors = null, |
| | 469 | | CancellationToken cancellationToken = default(CancellationToken)) |
| | 470 | | { |
| | 471 | | // throw if if this object is unbound |
| 0 | 472 | | UtilitiesInternal.ThrowOnUnbound(this.propertyContainer.BindingState); |
| | 473 | |
|
| 0 | 474 | | // craft the behavior manager for this call |
| 0 | 475 | | BehaviorManager bhMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors); |
| | 476 | |
|
| | 477 | | // start call |
| 0 | 478 | | System.Threading.Tasks.Task asyncTask = this.parentBatchClient.ProtocolLayer.TerminateJob(this.Id, terminate |
| 0 | 479 | |
|
| 2 | 480 | | return asyncTask; |
| | 481 | | } |
| | 482 | |
|
| | 483 | | /// <summary> |
| | 484 | | /// Terminates this <see cref="CloudJob"/>, marking it as completed. |
| | 485 | | /// </summary> |
| | 486 | | /// <param name="terminateReason">The text you want to appear as the job's <see cref="JobExecutionInformation.Te |
| | 487 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| | 488 | | /// <remarks>This is a blocking operation. For a non-blocking equivalent, see <see cref="TerminateAsync"/>.</rem |
| | 489 | | public void Terminate(string terminateReason = null, IEnumerable<BatchClientBehavior> additionalBehaviors = null |
| | 490 | | { |
| 0 | 491 | | Task asyncTask = TerminateAsync(terminateReason, additionalBehaviors); |
| 104 | 492 | | asyncTask.WaitAndUnaggregateException(this.CustomBehaviors, additionalBehaviors); |
| 104 | 493 | | } |
| 104 | 494 | |
|
| 150 | 495 | | /// <summary> |
| 104 | 496 | | /// Deletes this <see cref="CloudJob" />. |
| 104 | 497 | | /// </summary> |
| 152 | 498 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| 156 | 499 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynch |
| 153 | 500 | | /// <returns>A <see cref="System.Threading.Tasks.Task"/> that represents the asynchronous operation.</returns> |
| 104 | 501 | | /// <remarks> |
| 153 | 502 | | /// <para>The delete operation requests that the job be deleted. The request puts the job in the <see cref="Com |
| 104 | 503 | | /// The Batch service will stop any running tasks and perform the actual job deletion without any further client |
| 104 | 504 | | /// <para>The delete operation runs asynchronously.</para> |
| 161 | 505 | | /// </remarks> |
| 104 | 506 | | public System.Threading.Tasks.Task DeleteAsync(IEnumerable<BatchClientBehavior> additionalBehaviors = null, Canc |
| 104 | 507 | | { |
| 104 | 508 | | // throw if if this object is unbound |
| 0 | 509 | | UtilitiesInternal.ThrowOnUnbound(this.propertyContainer.BindingState); |
| 104 | 510 | |
|
| | 511 | | // craft the behavior manager for this call |
| 0 | 512 | | BehaviorManager bhMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors); |
| | 513 | |
|
| | 514 | | // start call |
| 0 | 515 | | System.Threading.Tasks.Task asyncTask = this.parentBatchClient.ProtocolLayer.DeleteJob(this.Id, bhMgr, cance |
| | 516 | |
|
| 0 | 517 | | return asyncTask; |
| | 518 | | } |
| | 519 | |
|
| | 520 | | /// <summary> |
| | 521 | | /// Deletes this <see cref="CloudJob" />. |
| | 522 | | /// </summary> |
| | 523 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| | 524 | | /// <remarks> |
| | 525 | | /// <para>The delete operation requests that the job be deleted. The request puts the job in the <see cref="Com |
| | 526 | | /// The Batch service will stop any running tasks and perform the actual job deletion without any further client |
| | 527 | | /// <para>This is a blocking operation. For a non-blocking equivalent, see <see cref="DeleteAsync"/>.</para> |
| | 528 | | /// </remarks> |
| | 529 | | public void Delete(IEnumerable<BatchClientBehavior> additionalBehaviors = null) |
| | 530 | | { |
| 0 | 531 | | Task asyncTask = DeleteAsync(additionalBehaviors); |
| 0 | 532 | | asyncTask.WaitAndUnaggregateException(this.CustomBehaviors, additionalBehaviors); |
| 0 | 533 | | } |
| | 534 | |
|
| | 535 | | /// <summary> |
| | 536 | | /// Refreshes the current <see cref="CloudJob"/>. |
| | 537 | | /// </summary> |
| | 538 | | /// <param name="detailLevel">The detail level for the refresh. If a detail level which omits the <see cref="Id |
| | 539 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| | 540 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynch |
| | 541 | | /// <returns>A <see cref="Task"/> representing the asynchronous refresh operation.</returns> |
| | 542 | | public async System.Threading.Tasks.Task RefreshAsync( |
| | 543 | | DetailLevel detailLevel = null, |
| | 544 | | IEnumerable<BatchClientBehavior> additionalBehaviors = null, |
| | 545 | | CancellationToken cancellationToken = default(CancellationToken)) |
| | 546 | | { |
| | 547 | | // create the behavior managaer |
| 2 | 548 | | BehaviorManager bhMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors, detailLevel); |
| | 549 | |
|
| | 550 | | // start operation |
| 2 | 551 | | System.Threading.Tasks.Task<AzureOperationResponse<Models.CloudJob, Models.JobGetHeaders>> asyncTask = |
| 2 | 552 | | this.parentBatchClient.ProtocolLayer.GetJob(this.Id, bhMgr, cancellationToken); |
| | 553 | |
|
| 2 | 554 | | AzureOperationResponse<Models.CloudJob, Models.JobGetHeaders> response = await asyncTask.ConfigureAwait(cont |
| | 555 | |
|
| | 556 | | // get job from response |
| 1 | 557 | | Models.CloudJob newProtocolJob = response.Body; |
| | 558 | |
|
| 1 | 559 | | PropertyContainer container = new PropertyContainer(newProtocolJob); |
| | 560 | |
|
| | 561 | | // immediately available to all threads |
| 1 | 562 | | this.propertyContainer = container; |
| 1 | 563 | | } |
| | 564 | |
|
| | 565 | | /// <summary> |
| | 566 | | /// Refreshes the current <see cref="CloudJob"/>. |
| | 567 | | /// </summary> |
| | 568 | | /// <param name="detailLevel">The detail level for the refresh. If a detail level which omits the <see cref="Id |
| | 569 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| | 570 | | public void Refresh(DetailLevel detailLevel = null, IEnumerable<BatchClientBehavior> additionalBehaviors = null) |
| | 571 | | { |
| 0 | 572 | | Task asyncTask = RefreshAsync(detailLevel, additionalBehaviors); |
| 0 | 573 | | asyncTask.WaitAndUnaggregateException(this.CustomBehaviors, additionalBehaviors); |
| 0 | 574 | | } |
| | 575 | |
|
| | 576 | | /// <summary> |
| | 577 | | /// Gets the task counts for the job. |
| | 578 | | /// </summary> |
| | 579 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| | 580 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynch |
| | 581 | | /// <remarks>The get job task counts operation runs asynchronously.</remarks> |
| | 582 | | /// <returns>A <see cref="TaskCounts"/> object containing the task counts for the job.</returns> |
| | 583 | | public async Task<TaskCounts> GetTaskCountsAsync( |
| | 584 | | IEnumerable<BatchClientBehavior> additionalBehaviors = null, |
| | 585 | | CancellationToken cancellationToken = default(CancellationToken)) |
| | 586 | | { |
| | 587 | | // set up behavior manager |
| 0 | 588 | | BehaviorManager bhMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors, detailLevel: null); |
| 0 | 589 | | TaskCounts counts = await this.parentBatchClient.JobOperations.GetJobTaskCountsAsyncImpl(this.Id, bhMgr, can |
| | 590 | |
|
| 0 | 591 | | return counts; |
| 0 | 592 | | } |
| | 593 | |
|
| | 594 | | /// <summary> |
| | 595 | | /// Gets the task counts for the job. |
| | 596 | | /// </summary> |
| | 597 | | /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are appli |
| | 598 | | /// <returns>A <see cref="TaskCounts"/> object containing the task counts for the job</returns> |
| | 599 | | /// <remarks>This is a blocking operation. For a non-blocking equivalent, see <see cref="GetTaskCountsAsync"/>.< |
| | 600 | | public TaskCounts GetTaskCounts(IEnumerable<BatchClientBehavior> additionalBehaviors = null) |
| | 601 | | { |
| 0 | 602 | | TaskCounts result = GetTaskCountsAsync(additionalBehaviors).WaitAndUnaggregateException(this.CustomBehaviors |
| 0 | 603 | | return result; |
| | 604 | | } |
| | 605 | |
|
| | 606 | | #endregion // CloudJob |
| | 607 | |
|
| | 608 | | } |
| | 609 | | } |