2.2 JDL Job Scripts

This section contains the following information:

2.2.1 What is JDL?

The PlateSpin Orchestrate job definition language (JDL) is an extended and embedded implementation of Python. The PlateSpin Orchestrate system provides additional constructs to control and access the following:

  • Interaction with the infrastructure under management (requesting resources, querying load, etc.)

  • Distributed variable space with job, user and system-wide scoping

  • Extensible event callbacks mechanism

  • Job logging

  • Datagrid for efficient movement of files across the infrastructure.

  • Automatic distribution of parallel operations

  • Failover logic

For more information about the PlateSpin Orchestrate JDL script editor, see Section 3.2, JDL Package.

The JDL language allows for the scripted construction of logic that can be modified by external parameters and constraints (through one or more associated policies) at the time the job instance is executed. Development of a job with the JDL (Python) language is very straightforward. For a listing of the job, joblet, and utility classes, see Section B.0, PlateSpin Orchestrate Job Classes and JDL Syntax.

A simple “hello world” Python script example that runs a given number of times (numTests) in parallel (subject to resource availability and policy) is shown below:

class exampleJob(Job):
    def job_started_event(self):
        print 'Hello world started: got job_started_event'
        # Launch the joblets
        numJoblets = self.getFact("jobargs.numTests")
        pspace = ParameterSpace()
        i = 1
        while i <= numJoblets:
            pspace.appendRow({'name':'test'+str(i)})
            i += 1
        self.schedule(exampleJoblet, pspace, {})

class exampleJoblet(Joblet):
    def joblet_started_event(self):
        print "Hello from resource%s" % self.getFact("resource.id")

This example script contains two sections:

  • The class that extends the job and runs on the server.

  • The class that extends the joblet that will run on any resource employed by this job.

Because the resources are not requested explicitly, they are allocated based on the resource constraints associated with this job. If none are specified, all resources match. The exampleJoblet class would typically execute some process or test based on unique parameters.

2.2.2 Using Facts in Job Scripts

This section contains the following information:

Fact Values

Facts can be retrieved, compared against, and written to (if not read-only) from within jobs. Every Grid object has a set of accessor and setter JDL functions. For example, to retrieve the cryptpw job argument fact in the job example listed in Section 2.3.2, Job Arguments and Parameter Lists in Policies, you would write the following JDL code:

1  def job_started_event(self):
2      pw = self.getFact("jobargs.cryptpw")

In line 2, the function getFact() retrieves the value of the job argument fact. getFact() is invoked on the job instance Grid object.

The following set of JDL Grid object functions retrieve facts:

getFact()
factExists()
getFactLastModified()
getFactNames()

The following set of JDL Grid object functions modify fact values (if they are not read-only) and remove facts (if they are not deleteable):

setFact
setDateFact
setTimeFact
setArrayFact
setBooleanArrayFact
setDateArrayFact
setIntegerArrayFact
setTimeArrayFact
setStringArrayFact
deleteFact

For more complete information on these fact values, see GridObjectInfo.

Fact Operations in the Joblet Class

Each joblet is also a Grid object with its own set of well known facts. These facts are listed in Section B.2, Joblet Class. An instance of the Joblet class runs on the resource. The joblet instance on the resource has access to the fact set of the resource where it is running. The resource fact set has no meaning outside of this execution context, because the Joblet can be scheduled to run on any of the resources that match the resource and allocation constraints.

For example, using the cracker job example shown in Job Arguments and Parameter Lists in Policies, you would write the following JDL code to retrieve the cryptpw job argument fact, the OS family fact for the resource, the Job instance ID fact, and the joblet number:

1 class CrackerJoblet(Joblet):
2    def joblet_started_event(self):
3        pw = self.getFact("jobargs.cryptpw")
4        osfamily = self.getFact("resource.os.family")
5        jobid = self.getFact("jobinstance.id")
6        jobletnum = self.getFact("joblet.number")

In line 3, the function getFact() retrieves the value of the job argument fact. getFact() is invoked on the joblet instance grid object. In line 4, the resource.os.family fact is retrieved for the resource where the Joblet is being executed. This varies, depending on which resource the Joblet is scheduled to run on. In line 5, the ID fact for the job instance is retrieved. This changes for every job instance. In line 6, the joblet index number for this joblet instance is returned. The index is 0 based.

Using the Policy Debugger to View Facts

The Policy Debugger page of the PlateSpin Orchestrate Development Client provides a table view of all facts in a running or completed job instance. This view includes the Job instance facts (jobinstance.* namespace) and the facts from the job context. After you select the Policy Debugger tab in the Job Monitor view, the right side panel displays this fact table. For more details, see The Policy Debugger in the PlateSpin Orchestrate 2.5 Development Client Reference.