7.3 Job Class

The Job class is a representation of a running job instance. This class defines functions for interacting with the server, including handling notification of job state transitions, child job submission, managing joblets and for receiving and sending events from resources and from clients. A job writer defines a subclass of the job class and uses the methods available on the job class for scheduling joblets and event processing.

For more information about the methods this class uses, see Section 7.3.1, Job State Transition Events.

The following example demonstrates a job that schedules a single joblet to run on one resource:

 class Simple(Job):
      def job_started_event(self):

 class SimpleJoblet(Joblet):
      def joblet_started_event(self):
          print "Hello from Joblet"

For the above example, the class Simple is instantiated on the server when a job is run either by client tools or by the job scheduler. When a job transitions to the started state, the method job_started_event is invoked. Here the job_started_event invokes the base class method schedule() to create a single joblet and schedule the joblet to run on a resource. The SimpleJoblet class is instantiated and run on a resource.

7.3.1 Job State Transition Events

Each job has a set of events that are invoked at the state transistions of a job. On the starting state of a job, the job_started_event is always invoked.

The following is a list of job events that are invoked upon job state transitions:


The following is a list of job events that are invoked upon child job state transitions:


The following is a list of provisioner events that are invoked upon provisioner state transitions:


The following is a list of joblet events that are invoked as the joblet state transitions:


NOTE:*Only the job_started_event is required; other events are optional.

7.3.2 Handling Custom Events

A job writer can also handle and invoke custom events within a job. Events can come from clients, other jobs, and from joblets.

The folowing example defines an event handler named mycustom_event in a job:

 class Simple(Job):
      def job_started_event(self):

      def mycustom_event(self,params):
          dir = params["directory_to_list"]
          self.schedule(MyJoblet,{ "dir" : dir } )

In this example, the event retrieves a element from the params dictionary that is supplied to every custom event. The dictionary is optionally filled by the caller of the event.

The following example invokes the custom event named mycustom_event from the Orchestrator client command line tool:

      zos event mycustom_event directory_to_list="/tmp" 

In this example, a message is sent from the client tool to the job running on the server.The following example invokes the same custom event from a joblet:

 class SimpleJoblet(Joblet):
      def joblet_started_event(self):
          self.sendEvent("mycustom_event", { ... } ) 

In this example, a message is sent from the joblet running on a resource to the job running on the server. The running job has access to a factset which is the aggregation of the job instance factset (jobinstance.*), the deployed job factset (job.*, jobargs.*), the User factset (user.*), the Matrix factset (matrix.*) and any jobargs or policy facts supplied at the time the job is started.

Fact values are retrieved using the GridObjectInfo functions that the job class inherits.

The following example retrieves the value of the job instance fact state.string from the jobinstance namespace:

 class Simple(Job):
      def job_started_event(self):
          jobstate = self.getFact("jobinstance.state.string")
          print "job state=%s" % (jobstate)