/// <summary> /// Initializes a new instance of the PoolInner class. /// </summary> /// <param name="displayName">The display name for the pool.</param> /// <param name="lastModified">The last modified time of the /// pool.</param> /// <param name="creationTime">The creation time of the pool.</param> /// <param name="provisioningState">The current state of the /// pool.</param> /// <param name="provisioningStateTransitionTime">The time at which the /// pool entered its current state.</param> /// <param name="allocationState">Whether the pool is resizing.</param> /// <param name="allocationStateTransitionTime">The time at which the /// pool entered its current allocation state.</param> /// <param name="vmSize">The size of virtual machines in the pool. All /// VMs in a pool are the same size.</param> /// <param name="deploymentConfiguration">This property describes how /// the pool nodes will be deployed - using Cloud Services or Virtual /// Machines.</param> /// <param name="currentDedicatedNodes">The number of compute nodes /// currently in the pool.</param> /// <param name="currentLowPriorityNodes">The number of low priority /// compute nodes currently in the pool.</param> /// <param name="scaleSettings">Settings which configure the number of /// nodes in the pool.</param> /// <param name="autoScaleRun">The results and errors from the last /// execution of the autoscale formula.</param> /// <param name="interNodeCommunication">Whether the pool permits /// direct communication between nodes.</param> /// <param name="networkConfiguration">The network configuration for /// the pool.</param> /// <param name="maxTasksPerNode">The maximum number of tasks that can /// run concurrently on a single compute node in the pool.</param> /// <param name="taskSchedulingPolicy">How tasks are distributed across /// compute nodes in a pool.</param> /// <param name="userAccounts">The list of user accounts to be created /// on each node in the pool.</param> /// <param name="metadata">A list of name-value pairs associated with /// the pool as metadata.</param> /// <param name="startTask">A task specified to run on each compute /// node as it joins the pool.</param> /// <param name="certificates">The list of certificates to be installed /// on each compute node in the pool.</param> /// <param name="applicationPackages">The list of application packages /// to be installed on each compute node in the pool.</param> /// <param name="applicationLicenses">The list of application licenses /// the Batch service will make available on each compute node in the /// pool.</param> /// <param name="resizeOperationStatus">Contains details about the /// current or last completed resize operation.</param> /// <param name="mountConfiguration">A list of file systems to mount on /// each node in the pool.</param> /// <param name="etag">The ETag of the resource, used for concurrency /// statements.</param> public PoolInner(string id = default(string), string name = default(string), string type = default(string), string displayName = default(string), System.DateTime?lastModified = default(System.DateTime?), System.DateTime?creationTime = default(System.DateTime?), PoolProvisioningState?provisioningState = default(PoolProvisioningState?), System.DateTime?provisioningStateTransitionTime = default(System.DateTime?), AllocationState?allocationState = default(AllocationState?), System.DateTime?allocationStateTransitionTime = default(System.DateTime?), string vmSize = default(string), DeploymentConfiguration deploymentConfiguration = default(DeploymentConfiguration), int?currentDedicatedNodes = default(int?), int?currentLowPriorityNodes = default(int?), ScaleSettings scaleSettings = default(ScaleSettings), AutoScaleRun autoScaleRun = default(AutoScaleRun), InterNodeCommunicationState?interNodeCommunication = default(InterNodeCommunicationState?), NetworkConfiguration networkConfiguration = default(NetworkConfiguration), int?maxTasksPerNode = default(int?), TaskSchedulingPolicy taskSchedulingPolicy = default(TaskSchedulingPolicy), IList <UserAccount> userAccounts = default(IList <UserAccount>), IList <MetadataItem> metadata = default(IList <MetadataItem>), StartTask startTask = default(StartTask), IList <CertificateReference> certificates = default(IList <CertificateReference>), IList <ApplicationPackageReference> applicationPackages = default(IList <ApplicationPackageReference>), IList <string> applicationLicenses = default(IList <string>), ResizeOperationStatus resizeOperationStatus = default(ResizeOperationStatus), IList <MountConfiguration> mountConfiguration = default(IList <MountConfiguration>), string etag = default(string)) : base(id, name, type) { DisplayName = displayName; LastModified = lastModified; CreationTime = creationTime; ProvisioningState = provisioningState; ProvisioningStateTransitionTime = provisioningStateTransitionTime; AllocationState = allocationState; AllocationStateTransitionTime = allocationStateTransitionTime; VmSize = vmSize; DeploymentConfiguration = deploymentConfiguration; CurrentDedicatedNodes = currentDedicatedNodes; CurrentLowPriorityNodes = currentLowPriorityNodes; ScaleSettings = scaleSettings; AutoScaleRun = autoScaleRun; InterNodeCommunication = interNodeCommunication; NetworkConfiguration = networkConfiguration; MaxTasksPerNode = maxTasksPerNode; TaskSchedulingPolicy = taskSchedulingPolicy; UserAccounts = userAccounts; Metadata = metadata; StartTask = startTask; Certificates = certificates; ApplicationPackages = applicationPackages; ApplicationLicenses = applicationLicenses; ResizeOperationStatus = resizeOperationStatus; MountConfiguration = mountConfiguration; Etag = etag; CustomInit(); }
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 { } } } }
/// <summary> /// Validate the object. /// </summary> /// <exception cref="ValidationException"> /// Thrown if validation fails /// </exception> public virtual void Validate() { if (DeploymentConfiguration != null) { DeploymentConfiguration.Validate(); } if (ScaleSettings != null) { ScaleSettings.Validate(); } if (AutoScaleRun != null) { AutoScaleRun.Validate(); } if (NetworkConfiguration != null) { NetworkConfiguration.Validate(); } if (TaskSchedulingPolicy != null) { TaskSchedulingPolicy.Validate(); } if (UserAccounts != null) { foreach (var element in UserAccounts) { if (element != null) { element.Validate(); } } } if (Metadata != null) { foreach (var element1 in Metadata) { if (element1 != null) { element1.Validate(); } } } if (StartTask != null) { StartTask.Validate(); } if (Certificates != null) { foreach (var element2 in Certificates) { if (element2 != null) { element2.Validate(); } } } if (ApplicationPackages != null) { foreach (var element3 in ApplicationPackages) { if (element3 != null) { element3.Validate(); } } } if (MountConfiguration != null) { foreach (var element4 in MountConfiguration) { if (element4 != null) { element4.Validate(); } } } }