public void Bug2338301_CheckStreamPositionAfterFileRead() { Action test = () => { using (BatchClient batchCli = TestUtilities.OpenBatchClientAsync(TestUtilities.GetCredentialsFromEnvironment()).Result) { JobOperations jobOperations = batchCli.JobOperations; { string jobId = "Bug2338301Job-" + TestUtilities.GetMyName(); try { const string taskId = "hiWorld"; // // Create the job // CloudJob unboundJob = jobOperations.CreateJob(jobId, new PoolInformation() { PoolId = this.poolFixture.PoolId }); unboundJob.Commit(); CloudJob boundJob = jobOperations.GetJob(jobId); CloudTask myTask = new CloudTask(taskId, "cmd /c echo hello world"); boundJob.AddTask(myTask); this.testOutputHelper.WriteLine("Initial job commit()"); // // Wait for task to go to completion // Utilities utilities = batchCli.Utilities; TaskStateMonitor taskStateMonitor = utilities.CreateTaskStateMonitor(); taskStateMonitor.WaitAll( boundJob.ListTasks(), Microsoft.Azure.Batch.Common.TaskState.Completed, TimeSpan.FromMinutes(3)); CloudTask boundTask = boundJob.GetTask(taskId); //Get the task file const string fileToGet = "stdout.txt"; NodeFile file = boundTask.GetNodeFile(fileToGet); //Download the file data string result = file.ReadAsString(); Assert.True(result.Length > 0); } finally { jobOperations.DeleteJob(jobId); } } } }; SynchronizationContextHelper.RunTest(test, TestTimeout); }
/// <summary> /// Lists the jobs matching the specified filter options. /// </summary> /// <param name="options">The options to use when querying for jobs.</param> /// <returns>The jobs matching the specified filter options.</returns> public IEnumerable <PSCloudJob> ListJobs(ListJobOptions options) { if (options == null) { throw new ArgumentNullException("options"); } // Get the single job matching the specified id if (!string.IsNullOrEmpty(options.JobId)) { WriteVerbose(string.Format(Resources.GetJobById, options.JobId)); JobOperations jobOperations = options.Context.BatchOMClient.JobOperations; ODATADetailLevel getDetailLevel = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand); CloudJob job = jobOperations.GetJob(options.JobId, detailLevel: getDetailLevel, additionalBehaviors: options.AdditionalBehaviors); PSCloudJob psJob = new PSCloudJob(job); return(new PSCloudJob[] { psJob }); } // List jobs using the specified filter else { string jobScheduleId = options.JobSchedule == null ? options.JobScheduleId : options.JobSchedule.Id; bool filterByJobSchedule = !string.IsNullOrEmpty(jobScheduleId); ODATADetailLevel listDetailLevel = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand); string verboseLogString = null; if (!string.IsNullOrEmpty(options.Filter)) { verboseLogString = filterByJobSchedule ? Resources.GetJobByOData : string.Format(Resources.GetJobByODataAndJobSChedule, jobScheduleId); listDetailLevel.FilterClause = options.Filter; } else { verboseLogString = filterByJobSchedule ? Resources.GetJobNoFilter : string.Format(Resources.GetJobByJobScheduleNoFilter, jobScheduleId); } WriteVerbose(verboseLogString); IPagedEnumerable <CloudJob> jobs = null; if (filterByJobSchedule) { JobScheduleOperations jobScheduleOperations = options.Context.BatchOMClient.JobScheduleOperations; jobs = jobScheduleOperations.ListJobs(jobScheduleId, listDetailLevel, options.AdditionalBehaviors); } else { JobOperations jobOperations = options.Context.BatchOMClient.JobOperations; jobs = jobOperations.ListJobs(listDetailLevel, options.AdditionalBehaviors); } Func <CloudJob, PSCloudJob> mappingFunction = j => { return(new PSCloudJob(j)); }; return(PSPagedEnumerable <PSCloudJob, CloudJob> .CreateWithMaxCount( jobs, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount)))); } }
/// <summary> /// Create a job associated with the specific pool, giving it the specified ID /// </summary> private static CloudJob CreateBoundJob(JobOperations jobOps, string poolId, string jobId) { // get an empty unbound Job var unboundJob = jobOps.CreateJob(); unboundJob.Id = jobId; unboundJob.PoolInformation = new PoolInformation() { PoolId = poolId }; // Commit Job to create it in the service unboundJob.Commit(); // Get a new version of the object with all its properties filled in CloudJob boundJob = jobOps.GetJob(jobId); return(boundJob); }
private static void AssertJobCorrectness( JobOperations jobOperations, string jobId, ref CloudJob boundJob, string expectedPoolId, int expectedPriority, JobConstraints expectedJobConstraints) { //boundJob.Refresh(); boundJob = jobOperations.GetJob(jobId); //TODO: Have to do this due to parent prop item loss on commit Assert.Equal(expectedPriority, boundJob.Priority); Assert.Equal(expectedPoolId, boundJob.ExecutionInformation.PoolId); if (expectedJobConstraints != null) { Assert.NotNull(boundJob.Constraints); Assert.Equal(expectedJobConstraints.MaxTaskRetryCount, boundJob.Constraints.MaxTaskRetryCount); Assert.Equal(expectedJobConstraints.MaxWallClockTime, boundJob.Constraints.MaxWallClockTime); } }
public void TestGetNodeFileByTask() { Action test = () => { using (BatchClient batchCli = TestUtilities.OpenBatchClientAsync(TestUtilities.GetCredentialsFromEnvironment()).Result) { JobOperations jobOperations = batchCli.JobOperations; string jobId = Constants.DefaultConveniencePrefix + TestUtilities.GetMyName() + "-" + nameof(TestGetNodeFileByTask); try { // // Create the job // CloudJob job = jobOperations.CreateJob(jobId, new PoolInformation()); job.PoolInformation = new PoolInformation() { PoolId = this.poolFixture.PoolId }; this.testOutputHelper.WriteLine("Initial job schedule commit()"); job.Commit(); // // Wait for the job // this.testOutputHelper.WriteLine("Waiting for job"); CloudJob boundJob = jobOperations.GetJob(jobId); // // Add task to the job // const string taskId = "T1"; const string taskMessage = "This is a test"; this.testOutputHelper.WriteLine("Adding task: {0}", taskId); CloudTask task = new CloudTask(taskId, string.Format("cmd /c echo {0}", taskMessage)); boundJob.AddTask(task); // // Wait for the task to complete // this.testOutputHelper.WriteLine("Waiting for the task to complete"); Utilities utilities = batchCli.Utilities; TaskStateMonitor taskStateMonitor = utilities.CreateTaskStateMonitor(); //Wait for the task state to be running taskStateMonitor.WaitAll( jobOperations.ListTasks(jobId), TaskState.Completed, TimeSpan.FromSeconds(30)); //Download the data this.testOutputHelper.WriteLine("Downloading the stdout for the file"); NodeFile file = jobOperations.GetNodeFile(jobId, taskId, Constants.StandardOutFileName); string data = file.ReadAsString(); this.testOutputHelper.WriteLine("Data: {0}", data); Assert.Contains(taskMessage, data); // Download the data again using the JobOperations read file content helper data = batchCli.JobOperations.CopyNodeFileContentToString(jobId, taskId, Constants.StandardOutFileName); this.testOutputHelper.WriteLine("Data: {0}", data); Assert.Contains(taskMessage, data); } finally { jobOperations.DeleteJob(jobId); } } }; SynchronizationContextHelper.RunTest(test, TestTimeout); }
/// <summary> /// Create a job associated with the specific pool, giving it the specified ID /// </summary> private static CloudJob CreateBoundJob(JobOperations jobOps, string poolId, string jobId) { // get an empty unbound Job var unboundJob = jobOps.CreateJob(); unboundJob.Id = jobId; unboundJob.PoolInformation = new PoolInformation() { PoolId = poolId }; // Commit Job to create it in the service unboundJob.Commit(); // Get a new version of the object with all its properties filled in CloudJob boundJob = jobOps.GetJob(jobId); return boundJob; }