Asign node groups to a job using .Net SDK in Visual Basic RRS feed

  • Question

  • How can I assign a specific node groups to a job using the .Net SDK using the Visual Basic Language (new to HPC and new to HPC SDK).  The image show that the required node groups when done in the HPC Job Manager is "VSpecAvailableNodes".  I want to submit a job using the SDK instead of the HPC Job Manager Interface.  I'm able to get the job and task created but can't set the node group to be used for the job.  What is the syntax to use in .Net Visual Basic ?

    Below is my code sample:

    Imports Microsoft.Hpc.Scheduler
    Imports Microsoft.Hpc.Scheduler.Properties

    Public Class Form1
        Dim strUserID As String
        Dim strPassword As String

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnCreateJob.Click

            strUserID = Me.txtUserID.Text
            strPassword = Me.txtPassword.Text
            Call Main()

        End Sub

        ' Copyright � Microsoft Corporation.  All Rights Reserved.
        ' This code released under the terms of the 
        ' MICROSOFT LIMITED PUBLIC LICENSE version 1.1 (MS-LPL, http://go.microsoft.com/?linkid=9791213.)
        'Copyright (C) Microsoft Corporation.  All rights reserved.

        'Namespace HPCSchedulerBasics

        'Class Program

        Dim job As ISchedulerJob

        Dim task As ISchedulerTask

        'Private Shared jobFinishedEvent As ManualResetEvent = New ManualResetEvent(False)

        Sub Main() '(ByVal args() As String)
            Dim clusterName As String
            'If (args.Length > 0) Then
            'clusterName = args(0)
            'End If
            clusterName = Environ("CCP_SCHEDULER")
            ' Create a scheduler object to be used to 
            ' establish a connection to the scheduler on the headnode
            Dim scheduler As IScheduler = New Scheduler

            ' Connect to the scheduler
            'Console.WriteLine("Connecting to {0}...", clusterName)
            'Catch e As Exception
            'Console.Error.WriteLine("Could not connect to the scheduler: {0}", e.Message)
            'abort if no connection could be made
            'End Try

            'Create a job to submit to the scheduler
            'the job will be equivalent to the CLI command: job submit /numcores:1-1 "echo hello world"
            job = scheduler.CreateJob
            'Some of the optional job parameters to specify. If omitted, defaults are:
            ' Name = {blank}
            ' UnitType = Core
            ' Min/Max Resources = Autocalculated
            ' etc...
            job.Name = "HPCSchedulerBasics Job"
            Console.WriteLine("Creating job name {0}...", job.Name)
            job.UnitType = JobUnitType.Core
            job.AutoCalculateMin = False
            job.AutoCalculateMax = False
            job.MinimumNumberOfCores = 1
            job.MaximumNumberOfCores = 1
            job.NodeGroupOp = 2
            job.NodeGroups = "VSpecAvailableNodes"
            'Create a task to submit to the job
            task = job.CreateTask
            task.Name = "Hello World"
            Console.WriteLine("Creating a {0} task...", task.Name)
            'The commandline parameter tells the scheduler what the task should do
            'CommandLine is the only mandatory parameter you must set for every task
            task.CommandLine = "echo Hello World"
            'Don't forget to add the task to the job!
            'Use callback to check if a job is finished
            'AddHandler job.OnJobState, AddressOf Me.job_OnJobState
            'And to submit the job.
            'You can specify your username and password in the parameters, or set them to null and you will be prompted for your credentials
            Console.WriteLine("Submitting job to the cluster...")
            scheduler.SubmitJob(job, strUserID, strPassword)
            'wait for job to finish
            'Close the connection
            'Call scheduler.Dispose() to free the object when finished
        End Sub

        'Private Shared Sub job_OnJobState(ByVal sender As Object, ByVal e As JobStateEventArg)
        '    If (e.NewState = JobState.Finished) Then
        '        task.Refresh()
        '        ' update the task object with updates from the scheduler
        '        Console.WriteLine("Job completed.")
        '        Console.WriteLine(("Output: " + task.Output))
        '        'print the task's output
        '        jobFinishedEvent.Set()
        '    ElseIf ((e.NewState = JobState.Canceled) _
        '                OrElse (e.NewState = JobState.Failed)) Then
        '        Console.WriteLine("Job did not finish.")
        '        jobFinishedEvent.Set()
        '    ElseIf ((e.NewState = JobState.Queued) _
        '                AndAlso (e.PreviousState <> JobState.Validating)) Then
        '        Console.WriteLine("The job is currently queued.")
        '        Console.WriteLine("Waiting for job to start...")
        '    End If

        'End Sub
        'End Class
        'End Namespace
    End Class

    Monday, April 16, 2018 9:41 PM

All replies

  • Please use the NodeGroups property and and NodeGroupOp, refer to: https://msdn.microsoft.com/en-us/library/microsoft.hpc.scheduler.ischedulerjob_members(v=vs.85).aspx

    Qiufang Shi

    Tuesday, April 17, 2018 3:30 AM
  • I tried using the page you just suggested. Can you tell me what is wrong in the code provided initially. Since I’m new to VB.Net and HPC, I’m sure it is something I didn’t yet master in the language.
    Tuesday, April 17, 2018 3:48 AM