コード例 #1
0
        public async Task CanCreateBatchAccountWithPool()
        {
            using (var context = FluentMockContext.Start(this.GetType().FullName))
            {
                var rgName             = TestUtilities.GenerateName("rgstg");
                var batchAccountName   = TestUtilities.GenerateName("batchaccount");
                var storageAccountName = TestUtilities.GenerateName("sa");
                try
                {
                    var poolId          = TestUtilities.GenerateName("testPool");
                    var poolDisplayName = TestUtilities.GenerateName("my-pool-name");
                    var vmSize          = "STANDARD_D4";
                    var maxTasksPerNode = 13;

                    //create task scheduling policy
                    var taskSchedulingPolicy = new TaskSchedulingPolicy();
                    taskSchedulingPolicy.NodeFillType = ComputeNodeFillType.Pack;

                    //create deployment configuration
                    var deploymentConfiguration = new DeploymentConfiguration();
                    deploymentConfiguration.CloudServiceConfiguration           = new CloudServiceConfiguration();
                    deploymentConfiguration.CloudServiceConfiguration.OsFamily  = "4";
                    deploymentConfiguration.CloudServiceConfiguration.OsVersion = "WA-GUEST-OS-4.45_201708-01";

                    //create scaling settings
                    var scalingSettings = new Microsoft.Azure.Management.Batch.Fluent.Models.ScaleSettings();
                    scalingSettings.FixedScale = new FixedScaleSettings();
                    scalingSettings.FixedScale.TargetDedicatedNodes   = 6;
                    scalingSettings.FixedScale.NodeDeallocationOption = ComputeNodeDeallocationOption.TaskCompletion;

                    //create metadata
                    var metadata = new List <MetadataItem>();
                    metadata.Add(new MetadataItem("metadata-1", "value-1"));
                    metadata.Add(new MetadataItem("metadata-2", "value-2"));

                    //create start task
                    var startTask         = new StartTask();
                    var cmdLine           = "cmd /c SET";
                    var maxTaskRetryCount = 6;
                    startTask.CommandLine         = cmdLine;
                    startTask.EnvironmentSettings = new List <EnvironmentSetting>();
                    startTask.EnvironmentSettings.Add(new EnvironmentSetting("MYSET", "1234"));
                    startTask.UserIdentity      = new UserIdentity(default(string), new AutoUserSpecification(AutoUserScope.Pool, ElevationLevel.Admin));
                    startTask.MaxTaskRetryCount = maxTaskRetryCount;
                    startTask.WaitForSuccess    = true;
                    startTask.ResourceFiles     = new List <ResourceFile>();
                    startTask.ResourceFiles.Add(new ResourceFile(default(string), default(string), "https://testaccount.blob.core.windows.net/example-blob-file", default(string), "c:\\\\temp\\\\gohere", "777"));

                    //create user accounts
                    var userAccounts = new List <UserAccount>();
                    userAccounts.Add(new UserAccount("username1", "examplepassword", ElevationLevel.Admin, new LinuxUserConfiguration(1234, 4567, "sshprivatekeyvalue"), default(WindowsUserConfiguration)));

                    var batchManager = TestHelper.CreateBatchManager();

                    // Create
                    var batchAccount = await batchManager.BatchAccounts
                                       .Define(batchAccountName)
                                       .WithRegion(Region.AsiaSouthEast)
                                       .WithNewResourceGroup(rgName)
                                       .WithNewStorageAccount(storageAccountName)
                                       .CreateAsync();

                    batchAccount.Update().DefineNewPool(poolId)
                    .WithDisplayName(poolDisplayName)
                    .WithVmSize(vmSize)
                    .WithInterNodeCommunication(InterNodeCommunicationState.Enabled)
                    .WithMaxTasksPerNode(maxTasksPerNode)
                    .WithTaskSchedulingPolicy(taskSchedulingPolicy)
                    .WithDeploymentConfiguration(deploymentConfiguration)
                    .WithScaleSettings(scalingSettings)
                    .WithMetadata(metadata)
                    .WithStartTask(startTask)
                    .WithUserAccount(userAccounts)
                    .Attach()
                    .Apply();

                    Assert.Equal(rgName, batchAccount.ResourceGroupName);
                    Assert.NotNull(batchAccount.AutoStorage);
                    Assert.Equal(ResourceUtils.NameFromResourceId(batchAccount.AutoStorage.StorageAccountId), storageAccountName);

                    // List
                    var accounts = batchManager.BatchAccounts.ListByResourceGroup(rgName);
                    Assert.Contains(accounts, account => StringComparer.OrdinalIgnoreCase.Equals(account.Name, batchAccountName));

                    // Get
                    batchAccount = batchManager.BatchAccounts.GetByResourceGroup(rgName, batchAccountName);
                    Assert.NotNull(batchAccount);

                    Assert.True(batchAccount.Pools.ContainsKey(poolId));
                    batchAccount.Refresh();

                    Assert.True(batchAccount.Pools.ContainsKey(poolId));
                    var pool = batchAccount.Pools[poolId];

                    Assert.NotNull(pool);
                    Assert.Equal(vmSize, pool.VmSize);
                    Assert.Null(pool.MountConfiguration);
                    Assert.NotNull(pool.StartTask);
                    Assert.Equal(cmdLine, pool.StartTask.CommandLine);
                    Assert.NotNull(pool.StartTask.MaxTaskRetryCount);
                    Assert.Equal(maxTaskRetryCount, pool.StartTask.MaxTaskRetryCount);
                    Assert.Equal(1, pool.UserAccounts.Count);

                    batchAccount.Update()
                    .WithoutPool(poolId)
                    .Apply();

                    Assert.False(batchAccount.Pools.ContainsKey(poolId));

                    try
                    {
                        await batchManager.BatchAccounts.DeleteByResourceGroupAsync(batchAccount.ResourceGroupName, batchAccountName);
                    }
                    catch
                    {
                    }
                    var batchAccounts = batchManager.BatchAccounts.ListByResourceGroup(rgName);

                    Assert.Empty(batchAccounts);
                }
                finally
                {
                    try
                    {
                        var resourceManager = TestHelper.CreateResourceManager();
                        resourceManager.ResourceGroups.DeleteByName(rgName);
                    }
                    catch { }
                }
            }
        }
コード例 #2
0
ファイル: BatchUtils.cs プロジェクト: QuickNS/azure-batch
        public static async Task <CloudPool> CreatePoolIfNotExistAsync(BatchClient batchClient, string poolId, string nodeSize = "standard_a1_v2", int dedicatedNodes = 0, int lowPriorityNodes = 2, int maxTasksPerNode = 1, TaskSchedulingPolicy schedulingPolicy = null, StartTask startTask = null)
        {
            var imageReference = CreateImageReference();
            var vmConfig       = CreateVirtualMachineConfiguration(imageReference);

            var pool = batchClient.PoolOperations.CreatePool(
                poolId: poolId,
                targetDedicatedComputeNodes: dedicatedNodes,
                targetLowPriorityComputeNodes: lowPriorityNodes,
                virtualMachineSize: nodeSize,
                virtualMachineConfiguration: vmConfig);

            pool.MaxTasksPerComputeNode = maxTasksPerNode;

            if (schedulingPolicy != null)
            {
                pool.TaskSchedulingPolicy = schedulingPolicy;
            }

            if (startTask != null)
            {
                pool.StartTask = startTask;
            }

            await BatchUtils.CreatePoolIfNotExist(batchClient, pool).ConfigureAwait(continueOnCapturedContext: false);

            return(await batchClient.PoolOperations.GetPoolAsync(poolId).ConfigureAwait(continueOnCapturedContext: false));
        }
コード例 #3
0
 /// <summary>
 /// Specifies the task sceduling policy for the pool.
 /// </summary>
 /// <param name="taskSchedulingPolicy">The taskScedulingPolicy value.</param>
 /// <return>The next stage of the update.</return>
 Pool.Update.IUpdate Pool.Update.IWithAttach.WithTaskSchedulingPolicy(TaskSchedulingPolicy taskSchedulingPolicy)
 {
     return(this.WithTaskSchedulingPolicy(taskSchedulingPolicy));
 }
コード例 #4
0
 /// <summary>
 /// Specifies the task sceduling policy for the pool.
 /// </summary>
 /// <param name="taskSchedulingPolicy">The taskScedulingPolicy value.</param>
 /// <return>The next stage of the definition.</return>
 Pool.UpdateDefinition.IWithAttach <BatchAccount.Update.IUpdate> Pool.UpdateDefinition.IWithAttach <BatchAccount.Update.IUpdate> .WithTaskSchedulingPolicy(TaskSchedulingPolicy taskSchedulingPolicy)
 {
     return(this.WithTaskSchedulingPolicy(taskSchedulingPolicy));
 }
コード例 #5
0
 /// <summary>
 /// Specifies the task sceduling policy for the pool.
 /// </summary>
 /// <param name="taskSchedulingPolicy">The taskScedulingPolicy value.</param>
 /// <return>The next stage of the definition.</return>
 Pool.Definition.IWithAttach <BatchAccount.Definition.IWithPool> Pool.Definition.IWithAttach <BatchAccount.Definition.IWithPool> .WithTaskSchedulingPolicy(TaskSchedulingPolicy taskSchedulingPolicy)
 {
     return(this.WithTaskSchedulingPolicy(taskSchedulingPolicy));
 }
コード例 #6
0
 public PoolImpl WithTaskSchedulingPolicy(TaskSchedulingPolicy taskSchedulingPolicy)
 {
     Inner.TaskSchedulingPolicy = taskSchedulingPolicy;
     return(this);
 }