public void CanReadUsesTaskDependenciesFromABoundCloudJobScheduleTest()
        {
            const string jobId = "id-123";
            const bool   usesTaskDependencies = true;

            using (BatchClient client = ClientUnitTestCommon.CreateDummyClient())
            {
                Protocol.RequestInterceptor interceptor = new Protocol.RequestInterceptor(
                    baseRequest =>
                {
                    var request = (Protocol.BatchRequest <Models.JobScheduleGetOptions, AzureOperationResponse <Models.CloudJobSchedule, Models.JobScheduleGetHeaders> >)baseRequest;

                    request.ServiceRequestFunc = token =>
                    {
                        var response = new AzureOperationResponse <Models.CloudJobSchedule, Models.JobScheduleGetHeaders>
                        {
                            Body = new Protocol.Models.CloudJobSchedule(jobId, schedule: new Protocol.Models.Schedule(), jobSpecification: new Protocol.Models.JobSpecification()
                            {
                                UsesTaskDependencies = true
                            })
                        };

                        return(Task.FromResult(response));
                    };
                });

                Microsoft.Azure.Batch.CloudJobSchedule unboundCloudJob = client.JobScheduleOperations.GetJobSchedule(jobId, additionalBehaviors: new List <BatchClientBehavior> {
                    interceptor
                });

                Assert.Equal(usesTaskDependencies, unboundCloudJob.JobSpecification.UsesTaskDependencies);
            }
        }
Пример #2
0
        public void CannotModifyUsesTaskDependenciesOnAJobScheduleAfterItHasBeenCommitted()
        {
            const bool usesTaskDependencies = true;


            using BatchClient client = ClientUnitTestCommon.CreateDummyClient();
            Protocol.RequestInterceptor interceptor = new Protocol.RequestInterceptor(
                baseRequest =>
            {
                var request = (Protocol.BatchRequests.JobScheduleAddBatchRequest)baseRequest;

                request.ServiceRequestFunc = token =>
                {
                    var response = new AzureOperationHeaderResponse <Models.JobScheduleAddHeaders> {
                        Response = new HttpResponseMessage(HttpStatusCode.Created)
                    };

                    return(Task.FromResult(response));
                };
            });

            Microsoft.Azure.Batch.CloudJobSchedule cloudJobSchedule = client.JobScheduleOperations.CreateJobSchedule();
            Microsoft.Azure.Batch.JobSpecification jobSpec          = new Microsoft.Azure.Batch.JobSpecification(poolInformation: null)
            {
                UsesTaskDependencies = usesTaskDependencies
            };
            cloudJobSchedule.JobSpecification = jobSpec;
            cloudJobSchedule.Commit(new List <BatchClientBehavior> {
                interceptor
            });

            // writing isn't allowed for a CloudJobSchedule.JobSpecification.UsesTaskDependencies that is in an invalid state.
            Assert.Throws <InvalidOperationException>(() => cloudJobSchedule.JobSpecification.UsesTaskDependencies = false);
        }
        /// <summary>
        /// Gets the specified <see cref="CloudJobSchedule"/>.
        /// </summary>
        /// <param name="jobScheduleId">The id of the job schedule to get.</param>
        /// <param name="detailLevel">A <see cref="DetailLevel"/> used for controlling which properties are retrieved from the service.</param>
        /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/> and <paramref name="detailLevel"/>.</param>
        /// <returns>A <see cref="CloudJobSchedule"/> containing information about the specified Azure Batch job schedule.</returns>
        /// <remarks>This is a blocking operation. For a non-blocking equivalent, see <see cref="GetJobScheduleAsync"/>.</remarks>
        public CloudJobSchedule GetJobSchedule(string jobScheduleId, DetailLevel detailLevel = null, IEnumerable <BatchClientBehavior> additionalBehaviors = null)
        {
            Task <CloudJobSchedule> asyncTask = this.GetJobScheduleAsync(jobScheduleId, detailLevel, additionalBehaviors);
            CloudJobSchedule        result    = asyncTask.WaitAndUnaggregateException(this.CustomBehaviors, additionalBehaviors);

            return(result);
        }
 internal PSCloudJobSchedule(Microsoft.Azure.Batch.CloudJobSchedule omObject)
 {
     if ((omObject == null))
     {
         throw new System.ArgumentNullException("omObject");
     }
     this.omObject = omObject;
 }
 internal PSCloudJobSchedule(Microsoft.Azure.Batch.CloudJobSchedule omObject)
 {
     if ((omObject == null))
     {
         throw new System.ArgumentNullException("omObject");
     }
     this.omObject = omObject;
 }
        public async Task CreateJobScheduleWithApplicationPackageReferences()
        {
            const string applicationId = "blender.exe";
            const string version       = "blender";
            const string jobId         = "mock-job";

            BatchSharedKeyCredentials credentials = ClientUnitTestCommon.CreateDummySharedKeyCredential();

            using (BatchClient client = BatchClient.Open(credentials))
            {
                Protocol.RequestInterceptor interceptor = new Protocol.RequestInterceptor(
                    baseRequest =>
                {
                    var request =
                        (Protocol.BatchRequest <Models.JobScheduleGetOptions, AzureOperationResponse <Models.CloudJobSchedule, Models.JobScheduleGetHeaders> >)baseRequest;

                    request.ServiceRequestFunc = (token) =>
                    {
                        var response = new AzureOperationResponse <Models.CloudJobSchedule, Models.JobScheduleGetHeaders>
                        {
                            Body = new Models.CloudJobSchedule
                            {
                                JobSpecification = new Protocol.Models.JobSpecification
                                {
                                    PoolInfo = new Models.PoolInformation
                                    {
                                        AutoPoolSpecification = new Models.AutoPoolSpecification
                                        {
                                            Pool = new Models.PoolSpecification
                                            {
                                                ApplicationPackageReferences = new[]
                                                {
                                                    new Protocol.Models.ApplicationPackageReference
                                                    {
                                                        ApplicationId = applicationId,
                                                        Version       = version,
                                                    }
                                                },
                                                MaxTasksPerNode = 4
                                            }
                                        }
                                    }
                                }
                            }
                        };
                        return(Task.FromResult(response));
                    };
                });

                Microsoft.Azure.Batch.CloudJobSchedule cloudJobSchedule = await client.JobScheduleOperations.GetJobScheduleAsync(jobId, additionalBehaviors : new List <BatchClientBehavior> {
                    interceptor
                });

                Assert.Equal(cloudJobSchedule.JobSpecification.PoolInformation.AutoPoolSpecification.PoolSpecification.ApplicationPackageReferences.First().ApplicationId, applicationId);
                Assert.Equal(cloudJobSchedule.JobSpecification.PoolInformation.AutoPoolSpecification.PoolSpecification.ApplicationPackageReferences.First().Version, version);
            }
        }
Пример #7
0
        /// <summary>
        /// Creates an instance of CloudJobSchedule that is unbound and does not have a consistency relationship to any job schedule in the Batch Service.
        /// </summary>
        /// <param name="jobScheduleId">The id of the job schedule.</param>
        /// <param name="schedule">The schedule that determines when jobs will be created.</param>
        /// <param name="jobSpecification">a <see cref="JobSpecification" /> containing details of the jobs to be created according to the <paramref name="schedule"/>.</param>
        /// <returns>A <see cref="CloudJobSchedule"/> representing a new job schedule that has not been submitted to the Batch service.</returns>
        public CloudJobSchedule CreateJobSchedule(string jobScheduleId, Schedule schedule, JobSpecification jobSpecification)
        {
            CloudJobSchedule newJobSchedule = new CloudJobSchedule(this.ParentBatchClient, this.CustomBehaviors)
            {
                Id               = jobScheduleId,
                Schedule         = schedule,
                JobSpecification = jobSpecification
            };

            return(newJobSchedule);
        }
Пример #8
0
        public async Task GetJobScheduleWithApplicationPackageReferences()
        {
            const string applicationId = "app-1";
            const string version       = "1.0";

            using (BatchClient client = ClientUnitTestCommon.CreateDummyClient())
            {
                Protocol.RequestInterceptor interceptor = new Protocol.RequestInterceptor(baseRequest =>
                {
                    var request = (Protocol.BatchRequest <Models.JobScheduleGetOptions, AzureOperationResponse <Models.CloudJobSchedule, Models.JobScheduleGetHeaders> >)baseRequest;

                    request.ServiceRequestFunc = (token) =>
                    {
                        var response = new AzureOperationResponse <Models.CloudJobSchedule, Models.JobScheduleGetHeaders>
                        {
                            Body = new Models.CloudJobSchedule
                            {
                                JobSpecification = new Protocol.Models.JobSpecification
                                {
                                    PoolInfo = new Models.PoolInformation
                                    {
                                        AutoPoolSpecification = new Protocol.Models.AutoPoolSpecification
                                        {
                                            Pool = new Models.PoolSpecification
                                            {
                                                ApplicationPackageReferences = new List <Protocol.Models.ApplicationPackageReference>
                                                {
                                                    new Protocol.Models.ApplicationPackageReference
                                                    {
                                                        ApplicationId = applicationId,
                                                        Version       = version
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        };
                        return(Task.FromResult(response));
                    };
                });

                Microsoft.Azure.Batch.CloudJobSchedule jobSchedule = await client.JobScheduleOperations.GetJobScheduleAsync("test", additionalBehaviors : new List <BatchClientBehavior> {
                    interceptor
                });

                Microsoft.Azure.Batch.ApplicationPackageReference apr = jobSchedule.JobSpecification.PoolInformation.AutoPoolSpecification.PoolSpecification.ApplicationPackageReferences.First();

                Assert.Equal(apr.ApplicationId, applicationId);
                Assert.Equal(apr.Version, version);
            }
        }
        /// <summary>
        /// Gets the specified <see cref="CloudJobSchedule"/>.
        /// </summary>
        /// <param name="jobScheduleId">The id of the job schedule to get.</param>
        /// <param name="detailLevel">A <see cref="DetailLevel"/> used for controlling which properties are retrieved from the service.</param>
        /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/> and <paramref name="detailLevel"/>.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param>
        /// <returns>A <see cref="CloudJobSchedule"/> containing information about the specified Azure Batch job schedule.</returns>
        /// <remarks>The get job schedule operation runs asynchronously.</remarks>
        public async System.Threading.Tasks.Task <CloudJobSchedule> GetJobScheduleAsync(
            string jobScheduleId,
            DetailLevel detailLevel = null,
            IEnumerable <BatchClientBehavior> additionalBehaviors = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            // set up behavior manager
            BehaviorManager bhMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors, detailLevel);

            Task <AzureOperationResponse <Models.CloudJobSchedule, Models.JobScheduleGetHeaders> > asyncTask =
                this.ParentBatchClient.ProtocolLayer.GetJobSchedule(jobScheduleId, bhMgr, cancellationToken);

            AzureOperationResponse <Models.CloudJobSchedule, Models.JobScheduleGetHeaders> result = await asyncTask.ConfigureAwait(continueOnCapturedContext : false);

            // construct a new object bound to the protocol layer object
            CloudJobSchedule newWI = new CloudJobSchedule(this.ParentBatchClient, result.Body, this.CustomBehaviors);

            return(newWI);
        }
Пример #10
0
        /// <summary>
        /// Creates an instance of CloudJobSchedule that is unbound and does not have a consistency relationship to any job schedule in the Batch Service.
        /// </summary>
        /// <returns>A <see cref="CloudJobSchedule"/> representing a new job schedule that has not been submitted to the Batch service.</returns>
        public CloudJobSchedule CreateJobSchedule()
        {
            CloudJobSchedule newJobSchedule = new CloudJobSchedule(this.ParentBatchClient, this.CustomBehaviors);

            return(newJobSchedule);
        }