locked
Assign a License Name and Number to a Job using the .Net SDK with Visual Basic RRS feed

  • Question

  • How can I assign a License Name and Number using the .Net SDK in Visual Basic (similar to doing it interactively in the HPC Job Manager).  The License name would be MD2 and the License number 1

    Here is a code sample that is not working:

    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
            MsgBox(strUserID)
            strPassword = Me.txtPassword.Text
            'MsgBox(strPassword)
            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")
            MsgBox(clusterName)
            ' 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)
            'Try
            scheduler.Connect(clusterName)
            'Catch e As Exception
            'Console.Error.WriteLine("Could not connect to the scheduler: {0}", e.Message)
            'Return
            '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.SoftwareLicense = "MD2:1"
            '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!
            job.AddTask(task)
            '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...")
            Console.WriteLine()
            MsgBox(strUserID)
            scheduler.SubmitJob(job, strUserID, strPassword)
            'wait for job to finish
            'jobFinishedEvent.WaitOne()
            'Close the connection
            scheduler.Close()
            '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:48 PM

All replies

  • https://msdn.microsoft.com/en-us/library/microsoft.hpc.scheduler.ischedulerjob_members(v=vs.85).aspx using the SoftwareLicense Property on the ISchedulerJob object.

    Qiufang Shi

    Tuesday, April 17, 2018 3:31 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:46 AM