Пример #1
0
 internal PSCloudPool(Microsoft.Azure.Batch.CloudPool omObject)
 {
     if ((omObject == null))
     {
         throw new System.ArgumentNullException("omObject");
     }
     this.omObject = omObject;
 }
Пример #2
0
 internal PSCloudPool(Microsoft.Azure.Batch.CloudPool omObject)
 {
     if ((omObject == null))
     {
         throw new System.ArgumentNullException("omObject");
     }
     this.omObject = omObject;
 }
        public void GetPoolWithApplicationReferencesTest()
        {
            const string applicationId = "blender.exe";
            const string version       = "blender";

            BatchSharedKeyCredentials credentials = ClientUnitTestCommon.CreateDummySharedKeyCredential();

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

                    request.ServiceRequestFunc = (token) =>
                    {
                        var response = new AzureOperationResponse <Models.CloudPool, Models.PoolGetHeaders>
                        {
                            Body = new Models.CloudPool
                            {
                                ApplicationPackageReferences = new[]
                                {
                                    new Protocol.Models.ApplicationPackageReference
                                    {
                                        ApplicationId = applicationId,
                                        Version       = version
                                    }
                                },
                                CurrentDedicated          = 4,
                                CloudServiceConfiguration = new Models.CloudServiceConfiguration()
                                {
                                    CurrentOSVersion = "3"
                                },
                                Id = "pool-id"
                            },
                        };

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

                Microsoft.Azure.Batch.CloudPool cloudPool = client.PoolOperations.GetPool("pool-id", additionalBehaviors: new List <BatchClientBehavior> {
                    interceptor
                });

                Assert.Equal(cloudPool.ApplicationPackageReferences.First().Version, version);
                Assert.Equal(cloudPool.ApplicationPackageReferences.First().ApplicationId, applicationId);
            }
        }
Пример #4
0
        public async Task IfAPoolSpecifiesANonExistentApplicationPackage_ThenCommittingThePoolThrowsAnException()
        {
            await SynchronizationContextHelper.RunTestAsync(async() =>
            {
                var poolId = "app-ref-test-3-" + Guid.NewGuid();
                using BatchClient client = TestUtilities.OpenBatchClientFromEnvironmentAsync().Result;
                CloudPool pool           = client.PoolOperations.CreatePool(poolId, PoolFixture.VMSize, new CloudServiceConfiguration(PoolFixture.OSFamily));

                pool.ApplicationPackageReferences = new[] { new ApplicationPackageReference {
                                                                ApplicationId = "dud", Version = Version
                                                            } };

                await TestUtilities.AssertThrowsAsync <BatchException>(() => pool.CommitAsync()).ConfigureAwait(false);
            }, LongTestTimeout);
        }
        public void CheckIfGetApplicationPackageReferencesIsReadableButNotWritableOnABoundPool()
        {
            const string applicationId = "blender.exe";
            const string version       = "blender";

            BatchSharedKeyCredentials credentials = ClientUnitTestCommon.CreateDummySharedKeyCredential();

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

                    request.ServiceRequestFunc = (token) =>
                    {
                        var response = new AzureOperationResponse <Models.CloudPool, Models.PoolGetHeaders>
                        {
                            Body = new Models.CloudPool
                            {
                                ApplicationPackageReferences = new[]
                                {
                                    new Protocol.Models.ApplicationPackageReference
                                    {
                                        ApplicationId = applicationId,
                                        Version       = version
                                    }
                                }
                            }
                        };

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

                Microsoft.Azure.Batch.CloudPool cloudPool = client.PoolOperations.GetPool("pool-id", additionalBehaviors: new List <BatchClientBehavior> {
                    interceptor
                });
                Assert.Throws <InvalidOperationException>(() => cloudPool.ApplicationPackageReferences.First().ApplicationId = applicationId);
                Assert.Throws <InvalidOperationException>(() => cloudPool.ApplicationPackageReferences.First().Version       = version);
                Assert.Equal(cloudPool.ApplicationPackageReferences.First().Version, version);
                Assert.Equal(cloudPool.ApplicationPackageReferences.First().ApplicationId, applicationId);
            }
        }
Пример #6
0
        public async Task IfAPoolIsCommittedWithApplicationPackageReferences_ThenThoseReferencesArePersistedInTheService()
        {
            var poolId = "app-ref-test-1-" + Guid.NewGuid();

            async Task test()
            {
                using BatchClient client = await TestUtilities.OpenBatchClientFromEnvironmentAsync();

                CloudPool newPool = null;

                try
                {
                    List <ApplicationSummary> applicationSummaries = await client.ApplicationOperations.ListApplicationSummaries().ToListAsync().ConfigureAwait(false);

                    foreach (var applicationSummary in applicationSummaries.Where(app => app.Id == ApplicationId))
                    {
                        Assert.True(true, string.Format("{0} was found.", applicationSummary.Id));
                    }
                    CloudPool pool = client.PoolOperations.CreatePool(poolId, PoolFixture.VMSize, new CloudServiceConfiguration(PoolFixture.OSFamily));

                    pool.ApplicationPackageReferences = new[] { new ApplicationPackageReference {
                                                                    ApplicationId = ApplicationId, Version = Version
                                                                } };

                    await pool.CommitAsync().ConfigureAwait(false);

                    newPool = await client.PoolOperations.GetPoolAsync(poolId).ConfigureAwait(false);

                    ApplicationPackageReference apr = newPool.ApplicationPackageReferences.First();

                    Assert.Equal(ApplicationId, apr.ApplicationId);
                    Assert.Equal(Version, apr.Version);
                }
                finally
                {
                    TestUtilities.DeletePoolIfExistsAsync(client, poolId).Wait();
                }
            }

            await SynchronizationContextHelper.RunTestAsync(test, LongTestTimeout);
        }
        public async Task UpdateAnExistingPoolWithNewApplicationPackageReferences_AndChecksTheApplicationPackageReferencesIsOnThePool()
        {
            var poolId = "app-ref-test-2-" + Guid.NewGuid();

            Func <Task> test = async() =>
            {
                using (BatchClient client = await TestUtilities.OpenBatchClientFromEnvironmentAsync())
                {
                    try
                    {
                        CloudPool pool = client.PoolOperations.CreatePool(poolId, PoolFixture.VMSize, new CloudServiceConfiguration(PoolFixture.OSFamily));
                        await pool.CommitAsync().ConfigureAwait(false);

                        pool = await client.PoolOperations.GetPoolAsync(poolId).ConfigureAwait(false);

                        Assert.Null(pool.ApplicationPackageReferences);

                        pool.ApplicationPackageReferences = new[] { new ApplicationPackageReference {
                                                                        ApplicationId = ApplicationId, Version = Version
                                                                    } };

                        await pool.CommitAsync().ConfigureAwait(false);

                        CloudPool updatedPool = await client.PoolOperations.GetPoolAsync(poolId).ConfigureAwait(false);

                        ApplicationPackageReference apr = updatedPool.ApplicationPackageReferences.First();

                        Assert.Equal(ApplicationId, apr.ApplicationId);
                        Assert.Equal(Version, apr.Version);
                    }
                    finally
                    {
                        TestUtilities.DeletePoolIfExistsAsync(client, poolId).Wait();
                    }
                }
            };

            await SynchronizationContextHelper.RunTestAsync(test, LongTestTimeout);
        }
Пример #8
0
        public async Task UpdateAPoolWithNewApplicationPackages()
        {
            const string applicationId = "blender";
            const string version       = "beta";
            const string poolId        = "mock-pool";
            const string osFamily      = "3";

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

                    request.ServiceRequestFunc = (token) =>
                    {
                        var response = new AzureOperationResponse <Models.CloudPool, Models.PoolGetHeaders>
                        {
                            Body = new Protocol.Models.CloudPool
                            {
                                CurrentDedicatedNodes     = 4,
                                CloudServiceConfiguration = new Models.CloudServiceConfiguration(osFamily),
                                Id = poolId
                            }
                        };
                        return(Task.FromResult(response));
                    };
                });

                Microsoft.Azure.Batch.CloudPool cloudPool = client.PoolOperations.GetPool("pool-id", additionalBehaviors: new List <BatchClientBehavior> {
                    interceptor
                });

                // At this point the pool shouldn't have any application packages
                Assert.Null(cloudPool.ApplicationPackageReferences);

                cloudPool.ApplicationPackageReferences = new[]
                {
                    new Microsoft.Azure.Batch.ApplicationPackageReference()
                    {
                        ApplicationId = applicationId,
                        Version       = version
                    }
                };

                interceptor = new Protocol.RequestInterceptor(
                    baseRequest =>
                {
                    Protocol.BatchRequests.PoolUpdatePropertiesBatchRequest request =
                        (Protocol.BatchRequests.PoolUpdatePropertiesBatchRequest)baseRequest;

                    // Need to check to see if ApplicationPackageReferences is being populated.
                    Assert.Equal(applicationId, request.Parameters.ApplicationPackageReferences[0].ApplicationId);
                    Assert.Equal(version, request.Parameters.ApplicationPackageReferences[0].Version);

                    request.ServiceRequestFunc = token => Task.FromResult(new AzureOperationHeaderResponse <Models.PoolUpdatePropertiesHeaders>()
                    {
                        Response = new HttpResponseMessage(HttpStatusCode.NoContent)
                    });
                });

                // Updating application pool to contain packages.
                await cloudPool.CommitAsync(additionalBehaviors : new List <BatchClientBehavior> {
                    interceptor
                });
            }
        }