public void GetJobManagerTaskWithApplicationPackageReferences() { const string jobId = "id-123"; const string applicationId = "foo"; const string version = "beta"; using (BatchClient client = ClientUnitTestCommon.CreateDummyClient()) { Models.CloudJob protoJob = new Models.CloudJob { Id = jobId, JobManagerTask = new Models.JobManagerTask { ApplicationPackageReferences = new List <Models.ApplicationPackageReference> { new Models.ApplicationPackageReference { Version = version, ApplicationId = applicationId } } } }; var job = client.JobOperations.GetJob(jobId, additionalBehaviors: InterceptorFactory.CreateGetJobRequestInterceptor(protoJob)); Assert.Equal(applicationId, job.JobManagerTask.ApplicationPackageReferences.First().ApplicationId); Assert.Equal(version, job.JobManagerTask.ApplicationPackageReferences.First().Version); } }
internal CloudJob( BatchClient parentBatchClient, Models.CloudJob protocolObject, IEnumerable <BatchClientBehavior> baseBehaviors) { this.parentBatchClient = parentBatchClient; InheritUtil.InheritClientBehaviorsAndSetPublicProperty(this, baseBehaviors); this.propertyContainer = new PropertyContainer(protocolObject); }
public void CloudJob_WhenReturnedFromServer_HasExpectedBoundProperties() { const string jobId = "id-123"; const string displayName = "DisplayNameFoo"; string applicationVersion = "beta"; string applicationId = "test"; MetadataItem metadataItem = new MetadataItem("foo", "bar"); const int priority = 0; var onAllTasksComplete = OnAllTasksComplete.TerminateJob; BatchSharedKeyCredentials credentials = ClientUnitTestCommon.CreateDummySharedKeyCredential(); using (BatchClient client = BatchClient.Open(credentials)) { DateTime creationTime = DateTime.Now; Models.CloudJob protoJob = new Models.CloudJob( jobId, displayName, jobManagerTask: new Models.JobManagerTask() { ApplicationPackageReferences = new [] { new Models.ApplicationPackageReference() { ApplicationId = applicationId, Version = applicationVersion } } }, metadata: new[] { new Models.MetadataItem { Name = metadataItem.Name, Value = metadataItem.Value } }, creationTime: creationTime, priority: priority, url: ClientUnitTestCommon.DummyBaseUrl, onAllTasksComplete: Models.OnAllTasksComplete.NoAction); CloudJob boundJob = client.JobOperations.GetJob(jobId, additionalBehaviors: InterceptorFactory.CreateGetJobRequestInterceptor(protoJob)); Assert.Equal(jobId, boundJob.Id); // reading is allowed from a job that is returned from the server. Assert.Equal(creationTime, boundJob.CreationTime); Assert.Equal(displayName, boundJob.DisplayName); Assert.Equal(applicationId, boundJob.JobManagerTask.ApplicationPackageReferences.First().ApplicationId); Assert.Equal(applicationVersion, boundJob.JobManagerTask.ApplicationPackageReferences.First().Version); AssertPatchableJobPropertiesCanBeWritten(boundJob, priority, metadataItem, onAllTasksComplete); // Can only read a url from a returned object. Assert.Equal(ClientUnitTestCommon.DummyBaseUrl, boundJob.Url); // Cannot change a bound displayName, Id and any property on a JobManagerTask. Assert.Throws <InvalidOperationException>(() => boundJob.DisplayName = "cannot-change-display-name"); Assert.Throws <InvalidOperationException>(() => boundJob.Id = "cannot-change-id"); Assert.Throws <InvalidOperationException>(() => boundJob.JobManagerTask.ApplicationPackageReferences = new List <ApplicationPackageReference>()); Assert.Throws <InvalidOperationException>(() => boundJob.JobManagerTask = new JobManagerTask()); } }
/// <summary> /// Builds a CloudJobGetResponse object /// </summary> public static ProxyModels.CloudJobGetResponse CreateCloudJobGetResponse(string jobId) { ProxyModels.CloudJobGetResponse response = new ProxyModels.CloudJobGetResponse(); response.StatusCode = HttpStatusCode.OK; ProxyModels.CloudJob job = new ProxyModels.CloudJob(); job.Id = jobId; response.Job = job; return(response); }
/// <summary> /// Builds a CloudJobGetResponse object /// </summary> public static AzureOperationResponse <ProxyModels.CloudJob, ProxyModels.JobGetHeaders> CreateCloudJobGetResponse(string jobId) { var response = new AzureOperationResponse <ProxyModels.CloudJob, ProxyModels.JobGetHeaders>(); response.Response = new HttpResponseMessage(HttpStatusCode.OK); ProxyModels.CloudJob job = new ProxyModels.CloudJob(); job.Id = jobId; response.Body = job; return(response); }
public void WhenGettingAJobFromTheService_ApplicationPackageReferencesAreMapped() { // Setup cmdlet to get a Job by id BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "job-1"; cmdlet.Filter = null; // Build a CloudJob instead of querying the service on a Get CloudJob call string applicationId = "foo"; string applicationVersion = "beta"; ProxyModels.CloudJob cloudTask = new ProxyModels.CloudJob { Id = "job-1", JobManagerTask = new ProxyModels.JobManagerTask { ApplicationPackageReferences = new[] { new ProxyModels.ApplicationPackageReference(applicationId, applicationVersion) } } }; AzureOperationResponse <ProxyModels.CloudJob, ProxyModels.JobGetHeaders> response = BatchTestHelpers.CreateCloudJobGetResponse(cloudTask); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <ProxyModels.JobGetOptions, AzureOperationResponse <ProxyModels.CloudJob, ProxyModels.JobGetHeaders> >(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 <PSCloudJob>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudJob>())).Callback <object>(t => pipeline.Add((PSCloudJob)t)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the task returned from the OM to the pipeline Assert.Single(pipeline); Assert.Equal(cmdlet.Id, pipeline[0].Id); var psApplicationPackageReference = pipeline[0].JobManagerTask.ApplicationPackageReferences.First(); Assert.Equal(applicationId, psApplicationPackageReference.ApplicationId); Assert.Equal(applicationVersion, psApplicationPackageReference.Version); }
public async Task UpdateBoundJobWithNewAutoTerminationPropertiesTest() { using BatchClient client = ClientUnitTestCommon.CreateDummyClient(); Models.CloudJob protoJob = new Models.CloudJob(id: "id", onAllTasksComplete: Models.OnAllTasksComplete.NoAction, onTaskFailure: Models.OnTaskFailure.PerformExitOptionsJobAction); CloudJob boundJob = await client.JobOperations.GetJobAsync(string.Empty, additionalBehaviors : InterceptorFactory.CreateGetJobRequestInterceptor(protoJob)); Assert.Equal(OnAllTasksComplete.NoAction, boundJob.OnAllTasksComplete); Assert.Equal(OnTaskFailure.PerformExitOptionsJobAction, boundJob.OnTaskFailure); // Can update job's auto complete properties. boundJob.OnAllTasksComplete = OnAllTasksComplete.TerminateJob; Assert.Equal(OnAllTasksComplete.TerminateJob, boundJob.OnAllTasksComplete); }
/// <summary> /// Builds a CloudJobListResponse object /// </summary> public static ProxyModels.CloudJobListResponse CreateCloudJobListResponse(IEnumerable <string> jobIds) { ProxyModels.CloudJobListResponse response = new ProxyModels.CloudJobListResponse(); response.StatusCode = HttpStatusCode.OK; List <ProxyModels.CloudJob> jobs = new List <ProxyModels.CloudJob>(); foreach (string id in jobIds) { ProxyModels.CloudJob job = new ProxyModels.CloudJob(); job.Id = id; jobs.Add(job); } response.Jobs = jobs; return(response); }
/// <summary> /// Builds a JobListFromJobScheduleResponse object /// </summary> public static AzureOperationResponse <IPage <ProxyModels.CloudJob>, ProxyModels.JobListFromJobScheduleHeaders> CreateJobListFromJobScheduleResponse(IEnumerable <string> jobIds) { var response = new AzureOperationResponse <IPage <ProxyModels.CloudJob>, ProxyModels.JobListFromJobScheduleHeaders>(); response.Response = new HttpResponseMessage(HttpStatusCode.OK); List <ProxyModels.CloudJob> jobs = new List <ProxyModels.CloudJob>(); foreach (string id in jobIds) { ProxyModels.CloudJob job = new ProxyModels.CloudJob(id: id); jobs.Add(job); } response.Body = new MockPagedEnumerable <ProxyModels.CloudJob>(jobs); return(response); }
/// <summary> /// Fabricates a CloudJob that's in the bound state /// </summary> public static CloudJob CreateFakeBoundJob(BatchAccountContext context, ProxyModels.CloudJob cloudJob) { RequestInterceptor interceptor = new RequestInterceptor((baseRequest) => { JobGetBatchRequest request = (JobGetBatchRequest)baseRequest; request.ServiceRequestFunc = (cancellationToken) => { var response = new AzureOperationResponse <ProxyModels.CloudJob, ProxyModels.JobGetHeaders> { Body = cloudJob }; Task <AzureOperationResponse <ProxyModels.CloudJob, ProxyModels.JobGetHeaders> > task = Task.FromResult(response); return(task); }; }); return(context.BatchOMClient.JobOperations.GetJob(cloudJob.Id, additionalBehaviors: new BatchClientBehavior[] { interceptor })); }
public void GetBatchJobTest() { // Setup cmdlet to get a Job by name BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "job-1"; cmdlet.Filter = null; // Build a CloudJob instead of querying the service on a Get CloudJob call ProxyModels.CloudJob job = new ProxyModels.CloudJob { Id = cmdlet.Id, OnAllTasksComplete = ProxyModels.OnAllTasksComplete.TerminateJob, OnTaskFailure = ProxyModels.OnTaskFailure.PerformExitOptionsJobAction }; AzureOperationResponse <ProxyModels.CloudJob, ProxyModels.JobGetHeaders> response = BatchTestHelpers.CreateCloudJobGetResponse(job); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.JobGetOptions, AzureOperationResponse <ProxyModels.CloudJob, ProxyModels.JobGetHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSCloudJob> pipeline = new List <PSCloudJob>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudJob>())).Callback <object>(j => pipeline.Add((PSCloudJob)j)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the job returned from the OM to the pipeline Assert.Single(pipeline); Assert.Equal(cmdlet.Id, pipeline[0].Id); Assert.Equal(OnTaskFailure.PerformExitOptionsJobAction, pipeline[0].OnTaskFailure); Assert.Equal(OnAllTasksComplete.TerminateJob, pipeline[0].OnAllTasksComplete); }
/// <summary> /// Refreshes the current <see cref="CloudJob"/>. /// </summary> /// <param name="detailLevel">The detail level for the refresh. If a detail level which omits the <see cref="Id"/> property is specified, refresh will fail.</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"/> representing the asynchronous refresh operation.</returns> public async System.Threading.Tasks.Task RefreshAsync( DetailLevel detailLevel = null, IEnumerable <BatchClientBehavior> additionalBehaviors = null, CancellationToken cancellationToken = default(CancellationToken)) { // create the behavior managaer BehaviorManager bhMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors, detailLevel); // start operation System.Threading.Tasks.Task <AzureOperationResponse <Models.CloudJob, Models.JobGetHeaders> > asyncTask = this.parentBatchClient.ProtocolLayer.GetJob(this.Id, bhMgr, cancellationToken); AzureOperationResponse <Models.CloudJob, Models.JobGetHeaders> response = await asyncTask.ConfigureAwait(continueOnCapturedContext : false); // get job from response Models.CloudJob newProtocolJob = response.Body; PropertyContainer container = new PropertyContainer(newProtocolJob); // immediately available to all threads this.propertyContainer = container; }
public void CreateCloudTaskWithApplicationPackageReferences() { const string jobId = "id-123"; const string taskId = "id-123"; const string applicationId = "testApp"; const string applicationVersion = "beta"; using (BatchClient client = ClientUnitTestCommon.CreateDummyClient()) { Models.CloudJob returnFakeJob = new Models.CloudJob(jobId); var job = client.JobOperations.GetJob(jobId, additionalBehaviors: InterceptorFactory.CreateGetJobRequestInterceptor(returnFakeJob)); var verifyAPRs = ClientUnitTestCommon.SimulateServiceResponse <Models.TaskAddParameter, Models.TaskAddOptions, AzureOperationHeaderResponse <Models.TaskAddHeaders> >( (parameters, options) => { Assert.Equal(applicationId, parameters.ApplicationPackageReferences.First().ApplicationId); Assert.Equal(applicationVersion, parameters.ApplicationPackageReferences.First().Version); return(new AzureOperationHeaderResponse <Models.TaskAddHeaders> { Response = new HttpResponseMessage(HttpStatusCode.Accepted) }); }); var taskWithAPRs = new CloudTask(taskId, "cmd /c hostname") { ApplicationPackageReferences = new List <ApplicationPackageReference> { new ApplicationPackageReference { ApplicationId = applicationId, Version = applicationVersion } } }; job.AddTask(taskWithAPRs, additionalBehaviors: verifyAPRs); // assertions happen in the callback } }
public void GetBatchJobTest() { // Setup cmdlet to get a Job by name BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "job-1"; cmdlet.Filter = null; // Build a CloudJob instead of querying the service on a Get CloudJob call ProxyModels.CloudJob job = new ProxyModels.CloudJob { Id = cmdlet.Id, OnAllTasksComplete = ProxyModels.OnAllTasksComplete.TerminateJob, OnTaskFailure = ProxyModels.OnTaskFailure.PerformExitOptionsJobAction }; AzureOperationResponse<ProxyModels.CloudJob, ProxyModels.JobGetHeaders> response = BatchTestHelpers.CreateCloudJobGetResponse(job); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor< ProxyModels.JobGetOptions, AzureOperationResponse<ProxyModels.CloudJob, ProxyModels.JobGetHeaders>>(response); cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List<PSCloudJob> pipeline = new List<PSCloudJob>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny<PSCloudJob>())).Callback<object>(j => pipeline.Add((PSCloudJob)j)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the job returned from the OM to the pipeline Assert.Equal(1, pipeline.Count); Assert.Equal(cmdlet.Id, pipeline[0].Id); Assert.Equal(OnTaskFailure.PerformExitOptionsJobAction, pipeline[0].OnTaskFailure); Assert.Equal(OnAllTasksComplete.TerminateJob, pipeline[0].OnAllTasksComplete); }
/// <summary> /// Builds a CloudJobGetResponse object /// </summary> public static ProxyModels.CloudJobGetResponse CreateCloudJobGetResponse(string jobId) { ProxyModels.CloudJobGetResponse response = new ProxyModels.CloudJobGetResponse(); response.StatusCode = HttpStatusCode.OK; ProxyModels.CloudJob job = new ProxyModels.CloudJob(); job.Id = jobId; response.Job = job; return response; }
public PropertyContainer(Models.CloudJob protocolObject) : base(BindingState.Bound) { this.CommonEnvironmentSettingsProperty = this.CreatePropertyAccessor( EnvironmentSetting.ConvertFromProtocolCollectionAndFreeze(protocolObject.CommonEnvironmentSettings), "CommonEnvironmentSettings", BindingAccess.Read); this.ConstraintsProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.Constraints, o => new JobConstraints(o)), "Constraints", BindingAccess.Read | BindingAccess.Write); this.CreationTimeProperty = this.CreatePropertyAccessor( protocolObject.CreationTime, "CreationTime", BindingAccess.Read); this.DisplayNameProperty = this.CreatePropertyAccessor( protocolObject.DisplayName, "DisplayName", BindingAccess.Read); this.ETagProperty = this.CreatePropertyAccessor( protocolObject.ETag, "ETag", BindingAccess.Read); this.ExecutionInformationProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.ExecutionInfo, o => new JobExecutionInformation(o).Freeze()), "ExecutionInformation", BindingAccess.Read); this.IdProperty = this.CreatePropertyAccessor( protocolObject.Id, "Id", BindingAccess.Read); this.JobManagerTaskProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.JobManagerTask, o => new JobManagerTask(o).Freeze()), "JobManagerTask", BindingAccess.Read); this.JobPreparationTaskProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.JobPreparationTask, o => new JobPreparationTask(o).Freeze()), "JobPreparationTask", BindingAccess.Read); this.JobReleaseTaskProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.JobReleaseTask, o => new JobReleaseTask(o).Freeze()), "JobReleaseTask", BindingAccess.Read); this.LastModifiedProperty = this.CreatePropertyAccessor( protocolObject.LastModified, "LastModified", BindingAccess.Read); this.MetadataProperty = this.CreatePropertyAccessor( MetadataItem.ConvertFromProtocolCollection(protocolObject.Metadata), "Metadata", BindingAccess.Read | BindingAccess.Write); this.OnAllTasksCompleteProperty = this.CreatePropertyAccessor( UtilitiesInternal.MapNullableEnum <Models.OnAllTasksComplete, Common.OnAllTasksComplete>(protocolObject.OnAllTasksComplete), "OnAllTasksComplete", BindingAccess.Read | BindingAccess.Write); this.OnTaskFailureProperty = this.CreatePropertyAccessor( UtilitiesInternal.MapNullableEnum <Models.OnTaskFailure, Common.OnTaskFailure>(protocolObject.OnTaskFailure), "OnTaskFailure", BindingAccess.Read); this.PoolInformationProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.PoolInfo, o => new PoolInformation(o)), "PoolInformation", BindingAccess.Read | BindingAccess.Write); this.PreviousStateProperty = this.CreatePropertyAccessor( UtilitiesInternal.MapNullableEnum <Models.JobState, Common.JobState>(protocolObject.PreviousState), "PreviousState", BindingAccess.Read); this.PreviousStateTransitionTimeProperty = this.CreatePropertyAccessor( protocolObject.PreviousStateTransitionTime, "PreviousStateTransitionTime", BindingAccess.Read); this.PriorityProperty = this.CreatePropertyAccessor( protocolObject.Priority, "Priority", BindingAccess.Read | BindingAccess.Write); this.StateProperty = this.CreatePropertyAccessor( UtilitiesInternal.MapNullableEnum <Models.JobState, Common.JobState>(protocolObject.State), "State", BindingAccess.Read); this.StateTransitionTimeProperty = this.CreatePropertyAccessor( protocolObject.StateTransitionTime, "StateTransitionTime", BindingAccess.Read); this.StatisticsProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.Stats, o => new JobStatistics(o).Freeze()), "Statistics", BindingAccess.Read); this.UrlProperty = this.CreatePropertyAccessor( protocolObject.Url, "Url", BindingAccess.Read); this.UsesTaskDependenciesProperty = this.CreatePropertyAccessor( protocolObject.UsesTaskDependencies, "UsesTaskDependencies", BindingAccess.Read); }
public PropertyContainer(Models.CloudJob protocolObject) : base(BindingState.Bound) { this.CommonEnvironmentSettingsProperty = this.CreatePropertyAccessor( EnvironmentSetting.ConvertFromProtocolCollectionAndFreeze(protocolObject.CommonEnvironmentSettings), nameof(CommonEnvironmentSettings), BindingAccess.Read); this.ConstraintsProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.Constraints, o => new JobConstraints(o)), nameof(Constraints), BindingAccess.Read | BindingAccess.Write); this.CreationTimeProperty = this.CreatePropertyAccessor( protocolObject.CreationTime, nameof(CreationTime), BindingAccess.Read); this.DisplayNameProperty = this.CreatePropertyAccessor( protocolObject.DisplayName, nameof(DisplayName), BindingAccess.Read); this.ETagProperty = this.CreatePropertyAccessor( protocolObject.ETag, nameof(ETag), BindingAccess.Read); this.ExecutionInformationProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.ExecutionInfo, o => new JobExecutionInformation(o).Freeze()), nameof(ExecutionInformation), BindingAccess.Read); this.IdProperty = this.CreatePropertyAccessor( protocolObject.Id, nameof(Id), BindingAccess.Read); this.JobManagerTaskProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.JobManagerTask, o => new JobManagerTask(o).Freeze()), nameof(JobManagerTask), BindingAccess.Read); this.JobPreparationTaskProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.JobPreparationTask, o => new JobPreparationTask(o).Freeze()), nameof(JobPreparationTask), BindingAccess.Read); this.JobReleaseTaskProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.JobReleaseTask, o => new JobReleaseTask(o).Freeze()), nameof(JobReleaseTask), BindingAccess.Read); this.LastModifiedProperty = this.CreatePropertyAccessor( protocolObject.LastModified, nameof(LastModified), BindingAccess.Read); this.MetadataProperty = this.CreatePropertyAccessor( MetadataItem.ConvertFromProtocolCollection(protocolObject.Metadata), nameof(Metadata), BindingAccess.Read | BindingAccess.Write); this.NetworkConfigurationProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.NetworkConfiguration, o => new JobNetworkConfiguration(o).Freeze()), nameof(NetworkConfiguration), BindingAccess.Read); this.OnAllTasksCompleteProperty = this.CreatePropertyAccessor( UtilitiesInternal.MapNullableEnum <Models.OnAllTasksComplete, Common.OnAllTasksComplete>(protocolObject.OnAllTasksComplete), nameof(OnAllTasksComplete), BindingAccess.Read | BindingAccess.Write); this.OnTaskFailureProperty = this.CreatePropertyAccessor( UtilitiesInternal.MapNullableEnum <Models.OnTaskFailure, Common.OnTaskFailure>(protocolObject.OnTaskFailure), nameof(OnTaskFailure), BindingAccess.Read); this.PoolInformationProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.PoolInfo, o => new PoolInformation(o)), nameof(PoolInformation), BindingAccess.Read | BindingAccess.Write); this.PreviousStateProperty = this.CreatePropertyAccessor( UtilitiesInternal.MapNullableEnum <Models.JobState, Common.JobState>(protocolObject.PreviousState), nameof(PreviousState), BindingAccess.Read); this.PreviousStateTransitionTimeProperty = this.CreatePropertyAccessor( protocolObject.PreviousStateTransitionTime, nameof(PreviousStateTransitionTime), BindingAccess.Read); this.PriorityProperty = this.CreatePropertyAccessor( protocolObject.Priority, nameof(Priority), BindingAccess.Read | BindingAccess.Write); this.StateProperty = this.CreatePropertyAccessor( UtilitiesInternal.MapNullableEnum <Models.JobState, Common.JobState>(protocolObject.State), nameof(State), BindingAccess.Read); this.StateTransitionTimeProperty = this.CreatePropertyAccessor( protocolObject.StateTransitionTime, nameof(StateTransitionTime), BindingAccess.Read); this.StatisticsProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.Stats, o => new JobStatistics(o).Freeze()), nameof(Statistics), BindingAccess.Read); this.UrlProperty = this.CreatePropertyAccessor( protocolObject.Url, nameof(Url), BindingAccess.Read); this.UsesTaskDependenciesProperty = this.CreatePropertyAccessor( protocolObject.UsesTaskDependencies, nameof(UsesTaskDependencies), BindingAccess.Read); }
public async Task CreateTaskWithExitConditionsTest() { const string jobId = "id-123"; const string taskId = "id-001"; BatchSharedKeyCredentials credentials = ClientUnitTestCommon.CreateDummySharedKeyCredential(); using (BatchClient client = await BatchClient.OpenAsync(credentials)) { Models.CloudJob protoJob = new Models.CloudJob(id: jobId, onAllTasksComplete: Models.OnAllTasksComplete.NoAction, onTaskFailure: Models.OnTaskFailure.PerformExitOptionsJobAction); var fakeAddTaskResponse = ClientUnitTestCommon.SimulateServiceResponse <Models.TaskAddParameter, Models.TaskAddOptions, AzureOperationHeaderResponse <Models.TaskAddHeaders> >((parameters, options) => { Assert.Equal((Models.JobAction?)JobAction.Terminate, parameters.ExitConditions.DefaultProperty.JobAction); Assert.Equal(0, parameters.ExitConditions.ExitCodeRanges.First().Start); Assert.Equal(4, parameters.ExitConditions.ExitCodeRanges.First().End); Assert.Equal((Models.JobAction?)JobAction.Disable, parameters.ExitConditions.ExitCodeRanges.First().ExitOptions.JobAction); Assert.Equal(3, parameters.ExitConditions.ExitCodes.First().Code); Assert.Equal((Models.JobAction?)JobAction.None, parameters.ExitConditions.ExitCodes.First().ExitOptions.JobAction); return(new AzureOperationHeaderResponse <Models.TaskAddHeaders>() { Response = new HttpResponseMessage(HttpStatusCode.Accepted) }); }); CloudJob boundJob = await client.JobOperations.GetJobAsync(string.Empty, additionalBehaviors : InterceptorFactory.CreateGetJobRequestInterceptor(protoJob)); boundJob.OnAllTasksComplete = OnAllTasksComplete.TerminateJob; // Cannot change OnTaskFailure on a bound job Assert.Throws <InvalidOperationException>(() => boundJob.OnTaskFailure = OnTaskFailure.NoAction); CloudTask cloudTask = new CloudTask(taskId, "cmd /c echo hello world"); cloudTask.ExitConditions = new ExitConditions() { Default = new ExitOptions() { JobAction = JobAction.Terminate }, ExitCodeRanges = new List <ExitCodeRangeMapping>() { new ExitCodeRangeMapping(0, 4, new ExitOptions() { JobAction = JobAction.Disable }) }, ExitCodes = new List <ExitCodeMapping>() { new ExitCodeMapping(3, new ExitOptions() { JobAction = JobAction.None }) }, SchedulingError = new ExitOptions() { JobAction = JobAction.Terminate }, }; boundJob.AddTask(cloudTask, additionalBehaviors: fakeAddTaskResponse); } }
/// <summary> /// Builds a CloudJobGetResponse object /// </summary> public static AzureOperationResponse <ProxyModels.CloudJob, ProxyModels.JobGetHeaders> CreateCloudJobGetResponse(ProxyModels.CloudJob job) { var response = new AzureOperationResponse <ProxyModels.CloudJob, ProxyModels.JobGetHeaders> { Response = new HttpResponseMessage(HttpStatusCode.OK), Body = job }; return(response); }
public async Task ExitConditionsAreSentOnTask() { const string jobId = "id-123"; const string taskId = "id-001"; using (BatchClient client = ClientUnitTestCommon.CreateDummyClient()) { Models.CloudJob protoJob = new Models.CloudJob(id: jobId, onAllTasksComplete: Models.OnAllTasksComplete.NoAction, onTaskFailure: Models.OnTaskFailure.PerformExitOptionsJobAction); var fakeAddTaskResponse = ClientUnitTestCommon.SimulateServiceResponse <Models.TaskAddParameter, Models.TaskAddOptions, AzureOperationHeaderResponse <Models.TaskAddHeaders> >((parameters, options) => { Assert.Equal((Models.JobAction?)JobAction.Terminate, parameters.ExitConditions.DefaultProperty.JobAction); Assert.Equal(0, parameters.ExitConditions.ExitCodeRanges.First().Start); Assert.Equal(4, parameters.ExitConditions.ExitCodeRanges.First().End); Assert.Equal((Models.JobAction?)JobAction.Disable, parameters.ExitConditions.ExitCodeRanges.First().ExitOptions.JobAction); // These need to be compared as strings because they are different types but we are interested in the values being the same. Assert.Equal(DependencyAction.Satisfy.ToString(), parameters.ExitConditions.ExitCodeRanges.First().ExitOptions.DependencyAction.ToString()); Assert.Equal(3, parameters.ExitConditions.ExitCodes.First().Code); Assert.Equal((Models.JobAction?)JobAction.None, parameters.ExitConditions.ExitCodes.First().ExitOptions.JobAction); Assert.Equal((Models.JobAction?)JobAction.Terminate, parameters.ExitConditions.FileUploadError.JobAction); return(new AzureOperationHeaderResponse <Models.TaskAddHeaders>() { Response = new HttpResponseMessage(HttpStatusCode.Accepted) }); }); CloudJob boundJob = await client.JobOperations.GetJobAsync(string.Empty, additionalBehaviors : InterceptorFactory.CreateGetJobRequestInterceptor(protoJob)); boundJob.OnAllTasksComplete = OnAllTasksComplete.TerminateJob; CloudTask cloudTask = new CloudTask(taskId, "cmd /c echo hello world"); cloudTask.ExitConditions = new ExitConditions() { Default = new ExitOptions() { JobAction = JobAction.Terminate }, ExitCodeRanges = new List <ExitCodeRangeMapping>() { new ExitCodeRangeMapping(0, 4, new ExitOptions() { DependencyAction = DependencyAction.Satisfy, JobAction = JobAction.Disable, }) }, ExitCodes = new List <ExitCodeMapping>() { new ExitCodeMapping(3, new ExitOptions() { JobAction = JobAction.None }) }, PreProcessingError = new ExitOptions() { JobAction = JobAction.Terminate }, FileUploadError = new ExitOptions() { JobAction = JobAction.Terminate } }; boundJob.AddTask(cloudTask, additionalBehaviors: fakeAddTaskResponse); } }
public static IEnumerable <Protocol.RequestInterceptor> CreateGetJobRequestInterceptor(Protocol.Models.CloudJob jobToReturn, JobGetHeaders getHeaders = null) { return(CreateGetRequestInterceptor <Protocol.Models.JobGetOptions, Protocol.Models.CloudJob, Protocol.Models.JobGetHeaders>(jobToReturn, getHeaders)); }
/// <summary> /// Builds a CloudJobListResponse object /// </summary> public static ProxyModels.CloudJobListResponse CreateCloudJobListResponse(IEnumerable<string> jobIds) { ProxyModels.CloudJobListResponse response = new ProxyModels.CloudJobListResponse(); response.StatusCode = HttpStatusCode.OK; List<ProxyModels.CloudJob> jobs = new List<ProxyModels.CloudJob>(); foreach (string id in jobIds) { ProxyModels.CloudJob job = new ProxyModels.CloudJob(); job.Id = id; jobs.Add(job); } response.Jobs = jobs; return response; }
public void WhenGettingAJobFromTheService_ApplicationPackageReferencesAreMapped() { // Setup cmdlet to get a Job by id BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "job-1"; cmdlet.Filter = null; // Build a CloudJob instead of querying the service on a Get CloudJob call string applicationId = "foo"; string applicationVersion = "beta"; ProxyModels.CloudJob cloudTask = new ProxyModels.CloudJob { Id = "job-1", JobManagerTask = new ProxyModels.JobManagerTask { ApplicationPackageReferences = new[] { new ProxyModels.ApplicationPackageReference(applicationId, applicationVersion) } } }; AzureOperationResponse<ProxyModels.CloudJob, ProxyModels.JobGetHeaders> response = BatchTestHelpers.CreateCloudJobGetResponse(cloudTask); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ProxyModels.JobGetOptions, AzureOperationResponse<ProxyModels.CloudJob, ProxyModels.JobGetHeaders>>(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<PSCloudJob>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny<PSCloudJob>())).Callback<object>(t => pipeline.Add((PSCloudJob)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); var psApplicationPackageReference = pipeline[0].JobManagerTask.ApplicationPackageReferences.First(); Assert.Equal(applicationId, psApplicationPackageReference.ApplicationId); Assert.Equal(applicationVersion, psApplicationPackageReference.Version); }