/// <summary> /// Initializes a new instance of the ExitConditions class. /// </summary> /// <param name="exitCodes">A list of individual task exit codes and /// how the Batch service should respond to them.</param> /// <param name="exitCodeRanges">A list of task exit codes ranges and /// how the Batch service should respond to them.</param> /// <param name="schedulingError">How the Batch service should respond /// if the task fails with a scheduling error.</param> /// <param name="defaultProperty">How the Batch service should respond /// if the task fails with an exit condition not covered by any of /// the other properties – that is, any nonzero exit code not listed /// in the exitCodes or exitCodeRanges collection, or a scheduling /// error if the schedulingError property is not present.</param> public ExitConditions(System.Collections.Generic.IList <ExitCodeMapping> exitCodes = default(System.Collections.Generic.IList <ExitCodeMapping>), System.Collections.Generic.IList <ExitCodeRangeMapping> exitCodeRanges = default(System.Collections.Generic.IList <ExitCodeRangeMapping>), ExitOptions schedulingError = default(ExitOptions), ExitOptions defaultProperty = default(ExitOptions)) { ExitCodes = exitCodes; ExitCodeRanges = exitCodeRanges; SchedulingError = schedulingError; DefaultProperty = defaultProperty; }
/// <summary> /// Initializes a new instance of the ExitCodeRangeMapping class. /// </summary> /// <param name="start">The first exit code in the range.</param> /// <param name="end">The last exit code in the range.</param> /// <param name="exitOptions">How the Batch service should respond if /// the task exits with an exit code in the range start to end /// (inclusive).</param> public ExitCodeRangeMapping(int start, int end, ExitOptions exitOptions) { Start = start; End = end; ExitOptions = exitOptions; CustomInit(); }
public void WhenGettingATaskFromTheService_ExitConditionsAreMapped() { BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "task-1"; cmdlet.JobId = "job-1"; cmdlet.Filter = null; // Build a CloudTask instead of querying the service on a Get CloudTask call ProxyModels.ExitOptions none = new ProxyModels.ExitOptions { JobAction = ProxyModels.JobAction.None }; ProxyModels.ExitOptions terminate = new ProxyModels.ExitOptions { JobAction = ProxyModels.JobAction.Terminate }; ProxyModels.CloudTask cloudTask = new ProxyModels.CloudTask { Id = "task-1", ExitConditions = new ProxyModels.ExitConditions { ExitCodeRanges = new [] { new ProxyModels.ExitCodeRangeMapping(2, 5, none) }, ExitCodes = new[] { new ProxyModels.ExitCodeMapping(4, terminate) }, SchedulingError = terminate, DefaultProperty = none, } }; AzureOperationResponse <ProxyModels.CloudTask, ProxyModels.TaskGetHeaders> response = BatchTestHelpers.CreateCloudTaskGetResponse(cloudTask); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <ProxyModels.TaskGetOptions, AzureOperationResponse <ProxyModels.CloudTask, ProxyModels.TaskGetHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later var pipeline = new List <PSCloudTask>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudTask>())).Callback <object>(t => pipeline.Add((PSCloudTask)t)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the task returned from the OM to the pipeline Assert.Equal(1, pipeline.Count); Assert.Equal(cmdlet.Id, pipeline[0].Id); PSExitConditions psExitConditions = pipeline[0].ExitConditions; Assert.Equal(psExitConditions.Default.JobAction, JobAction.None); Assert.Equal(psExitConditions.ExitCodeRanges.First().ExitOptions.JobAction, JobAction.None); Assert.Equal(psExitConditions.SchedulingError.JobAction, JobAction.Terminate); Assert.Equal(4, psExitConditions.ExitCodes.First().Code); Assert.Equal(JobAction.Terminate, psExitConditions.ExitCodes.First().ExitOptions.JobAction); Assert.Equal(2, psExitConditions.ExitCodeRanges.First().Start); Assert.Equal(5, psExitConditions.ExitCodeRanges.First().End); Assert.Equal(JobAction.None, psExitConditions.ExitCodeRanges.First().ExitOptions.JobAction); }
public PropertyContainer(Models.ExitOptions protocolObject) : base(BindingState.Bound) { this.JobActionProperty = this.CreatePropertyAccessor( UtilitiesInternal.MapNullableEnum <Models.JobAction, Common.JobAction>(protocolObject.JobAction), "JobAction", BindingAccess.Read); }
public void CloudTask_WhenReturnedFromServer_HasExpectedBoundProperties() { const string jobId = "id-123"; const string taskId = "id-123"; const int exitCode = 1; const int exitCodeRangeStart = 0; const int exitCodeRangeEnd = 4; Models.ExitOptions terminateExitOption = new Models.ExitOptions() { JobAction = Models.JobAction.Terminate }; Models.ExitOptions disableExitOption = new Models.ExitOptions() { JobAction = Models.JobAction.Disable, DependencyAction = Models.DependencyAction.Satisfy }; using (BatchClient client = ClientUnitTestCommon.CreateDummyClient()) { Models.CloudTask cloudTask = new Models.CloudTask() { Id = jobId, ExitConditions = new Models.ExitConditions() { DefaultProperty = disableExitOption, ExitCodeRanges = new List <Models.ExitCodeRangeMapping>() { new Models.ExitCodeRangeMapping(exitCodeRangeStart, exitCodeRangeEnd, terminateExitOption) }, ExitCodes = new List <Models.ExitCodeMapping>() { new Models.ExitCodeMapping(exitCode, terminateExitOption) }, PreProcessingError = terminateExitOption, FileUploadError = disableExitOption } }; CloudTask boundTask = client.JobOperations.GetTask( jobId, taskId, additionalBehaviors: InterceptorFactory.CreateGetTaskRequestInterceptor(cloudTask)); Assert.Equal(taskId, boundTask.Id); // reading is allowed from a task that is returned from the server. // These need to be compared as strings because they are different types but we are interested in the values being the same. Assert.Equal(disableExitOption.JobAction.ToString(), boundTask.ExitConditions.Default.JobAction.ToString()); Assert.Equal(DependencyAction.Satisfy, boundTask.ExitConditions.Default.DependencyAction); Assert.Equal(DependencyAction.Satisfy, boundTask.ExitConditions.FileUploadError.DependencyAction); Assert.Throws <InvalidOperationException>(() => boundTask.ExitConditions = new ExitConditions()); Assert.Throws <InvalidOperationException>(() => boundTask.DependsOn = new TaskDependencies(new List <string>(), new List <TaskIdRange>())); Assert.Throws <InvalidOperationException>(() => boundTask.UserIdentity = new UserIdentity("abc")); Assert.Throws <InvalidOperationException>(() => boundTask.CommandLine = "Cannot change command line"); Assert.Throws <InvalidOperationException>(() => boundTask.ExitConditions.Default = new ExitOptions() { JobAction = JobAction.Terminate }); } }
/// <summary> /// Initializes a new instance of the ExitConditions class. /// </summary> /// <param name="exitCodes">A list of individual Task exit codes and /// how the Batch service should respond to them.</param> /// <param name="exitCodeRanges">A list of Task exit code ranges and /// how the Batch service should respond to them.</param> /// <param name="preProcessingError">How the Batch service should /// respond if the Task fails to start due to an error.</param> /// <param name="fileUploadError">How the Batch service should respond /// if a file upload error occurs.</param> /// <param name="defaultProperty">How the Batch service should respond /// if the Task fails with an exit condition not covered by any of the /// other properties.</param> public ExitConditions(IList <ExitCodeMapping> exitCodes = default(IList <ExitCodeMapping>), IList <ExitCodeRangeMapping> exitCodeRanges = default(IList <ExitCodeRangeMapping>), ExitOptions preProcessingError = default(ExitOptions), ExitOptions fileUploadError = default(ExitOptions), ExitOptions defaultProperty = default(ExitOptions)) { ExitCodes = exitCodes; ExitCodeRanges = exitCodeRanges; PreProcessingError = preProcessingError; FileUploadError = fileUploadError; DefaultProperty = defaultProperty; CustomInit(); }
public void CloudTask_WhenReturnedFromServer_HasExpectedBoundProperties() { const string jobId = "id-123"; const string taskId = "id-123"; const int exitCode = 1; const int exitCodeRangeStart = 0; const int exitCodeRangeEnd = 4; Models.ExitOptions terminateExitOption = new Models.ExitOptions() { JobAction = Models.JobAction.Terminate }; Models.ExitOptions disableExitOption = new Models.ExitOptions() { JobAction = Models.JobAction.Disable }; BatchSharedKeyCredentials credentials = ClientUnitTestCommon.CreateDummySharedKeyCredential(); using (BatchClient client = BatchClient.Open(credentials)) { Models.CloudTask cloudTask = new Models.CloudTask() { Id = jobId, ExitConditions = new Models.ExitConditions() { DefaultProperty = disableExitOption, ExitCodeRanges = new List <Models.ExitCodeRangeMapping>() { new Models.ExitCodeRangeMapping(exitCodeRangeStart, exitCodeRangeEnd, terminateExitOption) }, ExitCodes = new List <Models.ExitCodeMapping>() { new Models.ExitCodeMapping(exitCode, terminateExitOption) }, SchedulingError = terminateExitOption, } }; CloudTask boundTask = client.JobOperations.GetTask( jobId, taskId, additionalBehaviors: InterceptorFactory.CreateGetTaskRequestInterceptor(cloudTask)); Assert.Equal(taskId, boundTask.Id); // reading is allowed from a task that is returned from the server. Assert.Equal(disableExitOption.JobAction.ToString(), boundTask.ExitConditions.Default.JobAction.ToString()); Assert.Throws <InvalidOperationException>(() => boundTask.ExitConditions = new ExitConditions()); Assert.Throws <InvalidOperationException>(() => boundTask.DependsOn = new TaskDependencies(new List <string>(), new List <TaskIdRange>())); Assert.Throws <InvalidOperationException>(() => boundTask.RunElevated = true); Assert.Throws <InvalidOperationException>(() => boundTask.CommandLine = "Cannot change command line"); Assert.Throws <InvalidOperationException>(() => boundTask.ExitConditions.Default = new ExitOptions() { JobAction = JobAction.Terminate }); } }
public void WhenGettingATaskFromTheService_ExitConditionsAreMapped() { BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "task-1"; cmdlet.JobId = "job-1"; cmdlet.Filter = null; // Build a CloudTask instead of querying the service on a Get CloudTask call ProxyModels.ExitOptions none = new ProxyModels.ExitOptions { JobAction = ProxyModels.JobAction.None }; ProxyModels.ExitOptions terminate = new ProxyModels.ExitOptions { JobAction = ProxyModels.JobAction.Terminate }; ProxyModels.CloudTask cloudTask = new ProxyModels.CloudTask { Id = "task-1", ExitConditions = new ProxyModels.ExitConditions { ExitCodeRanges = new []{ new ProxyModels.ExitCodeRangeMapping(2, 5, none) }, ExitCodes = new[] { new ProxyModels.ExitCodeMapping(4, terminate) }, SchedulingError = terminate, DefaultProperty = none, }}; AzureOperationResponse<ProxyModels.CloudTask, ProxyModels.TaskGetHeaders> response = BatchTestHelpers.CreateCloudTaskGetResponse(cloudTask); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ProxyModels.TaskGetOptions, AzureOperationResponse<ProxyModels.CloudTask, ProxyModels.TaskGetHeaders>>(response); cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later var pipeline = new List<PSCloudTask>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny<PSCloudTask>())).Callback<object>(t => pipeline.Add((PSCloudTask)t)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the task returned from the OM to the pipeline Assert.Equal(1, pipeline.Count); Assert.Equal(cmdlet.Id, pipeline[0].Id); PSExitConditions psExitConditions = pipeline[0].ExitConditions; Assert.Equal(psExitConditions.Default.JobAction, JobAction.None); Assert.Equal(psExitConditions.ExitCodeRanges.First().ExitOptions.JobAction, JobAction.None); Assert.Equal(psExitConditions.SchedulingError.JobAction, JobAction.Terminate); Assert.Equal(4, psExitConditions.ExitCodes.First().Code); Assert.Equal(JobAction.Terminate, psExitConditions.ExitCodes.First().ExitOptions.JobAction); Assert.Equal(2, psExitConditions.ExitCodeRanges.First().Start); Assert.Equal(5, psExitConditions.ExitCodeRanges.First().End); Assert.Equal(JobAction.None, psExitConditions.ExitCodeRanges.First().ExitOptions.JobAction); }
/// <summary> /// Initializes a new instance of the ExitCodeMapping class. /// </summary> /// <param name="code">A process exit code.</param> /// <param name="exitOptions">How the Batch service should respond if /// the Task exits with this exit code.</param> public ExitCodeMapping(int code, ExitOptions exitOptions) { Code = code; ExitOptions = exitOptions; CustomInit(); }
/// <summary> /// Initializes a new instance of the ExitCodeMapping class. /// </summary> /// <param name="code">A process exit code.</param> /// <param name="exitOptions">How the Batch service should respond if /// the task exits with this exit code.</param> public ExitCodeMapping(int code, ExitOptions exitOptions) { Code = code; ExitOptions = exitOptions; }