Example #1
0
 /// <summary>
 /// Initializes a new instance of the Pool class.
 /// </summary>
 /// <param name="id">The ID of the resource.</param>
 /// <param name="name">The name of the resource.</param>
 /// <param name="type">The type of the resource.</param>
 /// <param name="etag">The ETag of the resource, used for concurrency
 /// statements.</param>
 /// <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>
 public Pool(string id = default(string), string name = default(string), string type = default(string), string etag = 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))
     : base(id, name, type, etag)
 {
     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;
     CustomInit();
 }
Example #2
0
 /// <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();
             }
         }
     }
 }
Example #3
0
        private async Task <bool> CreateBatchPool(CommandLineArgs cmdLine, string poolId)
        {
            var batchAccountName = cmdLine.ConnectionArgs.BatchAccountName;
            var batchAccountKey  = cmdLine.ConnectionArgs.BatchAccountKey.EncodeBase64();
            var batchUrl         = cmdLine.ConnectionArgs.BatchAccountUrl;

            var nodeCount = cmdLine.BatchArgs.BatchNodeCount;
            var vmSize    = cmdLine.BatchArgs.BatchVmSize;
            var os        = cmdLine.BatchArgs.BatchPoolOs;

            var userAssignedResourceId = cmdLine.IdentityArgs.ResourceId;
            var userAssignedPrinId     = cmdLine.IdentityArgs.PrincipalId;
            var userAssignedClientId   = cmdLine.IdentityArgs.ClientId;
            var resourceGroupName      = cmdLine.IdentityArgs.ResourceGroup;
            var subscriptionId         = cmdLine.IdentityArgs.SubscriptionId;


            log.LogInformation($"Creating pool [{poolId}]...");

            //var creds = new BatchSharedKeyCredential(batchAccountName, batchAccountKey);
            if (cmdLine.IdentityArgs != null)
            {
                AadHelper.ManagedIdentityClientId = cmdLine.IdentityArgs.ClientId;
            }
            var creds            = new CustomClientCredentials(AadHelper.TokenCredential);
            var managementClient = new BatchManagementClient(creds);

            managementClient.SubscriptionId = subscriptionId;

            //// From: https://docs.microsoft.com/en-us/azure/batch/managed-identity-pools
            bm.ImageReference imageReference;
            bm.VirtualMachineConfiguration virtualMachineConfiguration;
            switch (os)
            {
            case OsType.Linux:
                imageReference = new bm.ImageReference(publisher: "Canonical", offer: "UbuntuServer", sku: "18.04-lts", version: "latest");
                virtualMachineConfiguration = new bm.VirtualMachineConfiguration(imageReference: imageReference, nodeAgentSkuId: "batch.node.ubuntu 18.04");
                break;

            case OsType.Windows:
            default:
                imageReference = new bm.ImageReference(publisher: "MicrosoftWindowsServer", offer: "WindowsServer", sku: "2016-Datacenter-with-containers", version: "latest");
                virtualMachineConfiguration = new bm.VirtualMachineConfiguration(imageReference: imageReference, nodeAgentSkuId: "batch.node.windows amd64");

                break;
            }

            var deploymentConfig = new bm.DeploymentConfiguration()
            {
                VirtualMachineConfiguration = virtualMachineConfiguration
            };
            var ids = new Dictionary <string, bm.UserAssignedIdentities>();

            ids.Add(userAssignedResourceId, new bm.UserAssignedIdentities(principalId: userAssignedPrinId, clientId: userAssignedClientId));

            var poolIdentity = new bm.BatchPoolIdentity()
            {
                Type = bm.PoolIdentityType.UserAssigned, UserAssignedIdentities = ids
            };
            var scaleSettings = new bm.ScaleSettings()
            {
                FixedScale = new bm.FixedScaleSettings()
                {
                    TargetDedicatedNodes = nodeCount
                }
            };

            var poolParameters = new bm.Pool(name: poolId)
            {
                VmSize                  = vmSize,
                ScaleSettings           = scaleSettings,
                DeploymentConfiguration = deploymentConfig,
                Identity                = poolIdentity
            };

            try
            {
                var pool = await managementClient.Pool.CreateWithHttpMessagesAsync(
                    poolName : poolId,
                    resourceGroupName : resourceGroupName,
                    accountName : batchAccountName,
                    parameters : poolParameters,
                    cancellationToken : default(CancellationToken));

                if (!pool.Response.IsSuccessStatusCode)
                {
                    log.LogWarning($"Issue creating pool: {pool.Body.ProvisioningState.ToString()}");
                    return(false);
                }
            }
            catch (Exception exe)
            {
                log.LogError($"Error creating Batch Pool: {exe.ToString()}");
                return(false);
            }
            return(true);
        }