sweeper.job

This example job illustrates how to schedule a "sweep," which is an ordered, serialized scheduling of the joblets across all matching resources.

Usage

> zos login --user zenuser
Please enter current password for 'zenuser':
 Logged into grid as zenuser

> zos jobinfo --detail sweeper
Jobname/Parameters    Attributes
------------------    ----------
sweeper            Desc: This example job ilustrates how to schedule a 'sweep'
                         accross all matching resources.

    sleeptime      Desc: time to sleep (in seconds)
                   Type: Integer
                Default: 1

Options

Job

A representation of a running job instance.

Joblet

Defines execution on the resource.

MatrixInfo

A representation of the matrix grid object, which provides operations for retrieving and creating grid objects in the system. MatrixInfo is retrieved using the built-in getMatrix() function. Write capability is dependent on the context in which getMatrix() is called. For example, in a joblet process on a resource, creating new grid objects is not supported.

GroupInfo

A representation of Group grid objects. Operations include retrieving the group member lists and adding/removing from the group member lists, and retrieving and setting facts on the group.

Exec

Used to manage command line execution on resources.

sleeptime

Specifies the time in seconds that the job remains dormant before running (default 1).

Description

The files that make up the Sweeper job include:

sweeper                                          # Total: 140 lines
|-- sweeper.jdl                                  #   66 lines
`-- sweeper.policy                               #   74 lines

The ScheduleSpec utility class is also related to this example.

sweeper.jdl

 1  # -----------------------------------------------------------------------------
 2  #  Copyright © 2008 Novell, Inc. All Rights Reserved.
 3  #
 4  #  NOVELL PROVIDES THE SOFTWARE "AS IS," WITHOUT ANY EXPRESS OR IMPLIED
 5  #  WARRANTY, INCLUDING WITHOUT THE IMPLIED WARRANTIES OF MERCHANTABILITY,
 6  #  FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGMENT.  NOVELL, THE AUTHORS
 7  #  OF THE SOFTWARE, AND THE OWNERS OF COPYRIGHT IN THE SOFTWARE ARE NOT LIABLE
 8  #  FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 9  #  TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE
10  #  OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11  # -----------------------------------------------------------------------------
12  #  $Id: sweeper.jdl,v 1.3 2008/02/27 20:51:24 john Exp $
13  # -----------------------------------------------------------------------------
14
15  import time
16
17  #
18  # Add to the 'examples' group on deployment
19  #
20  if __mode__ == "deploy":
21      try:
22          jobgroupname = "examples"
23          jobgroup = getMatrix().getGroup(TYPE_JOB, jobgroupname)
24          if jobgroup == None:
25              jobgroup = getMatrix().createGroup(TYPE_JOB, jobgroupname)
26          jobgroup.addMember(__jobname__)
27      except:
28          exc_type, exc_value, exc_traceback = sys.exc_info()
29          print "Error adding %s to %s group: %s %s" % (__jobname__, jobgroupname, exc_type, exc_value)
30
31
32  class sweeperJob(Job):
33
34       def job_started_event(self):
35            self.setFact("jobinstance.memo", self.getFact("job.description"))
36
37            sp = ScheduleSpec()
38
39            # Optionally a constraint can be specified to further limit matching
40            # resources from the job's default 'resource' constraint. Could also
41            # compose an object Constraint.
42            # For example, uncomment to restrict to resource group 'sweeper'
43            #sp.setConstraint("<contains fact='resource.groups' value='sweeper' />")
44
45            # Specify the joblet to run on each resource
46            sp.setJobletClass(sweeperJoblet)
47
48            # Specify the sweep across active nodes
49            sp.setUseNodeSet(sp.ACTIVE_NODE_SET)
50
51            # Schedule a sweep (creates preassigned joblets)
52            self.scheduleSweep(sp)
53
54            # Now the ScheduleSpec contains the number of joblets created
55            print 'Launched', sp.getCount(), 'joblets'
56
57
58  class sweeperJoblet(Joblet):
59
60       def joblet_started_event(self):
61            msg = "run on resource %s" % (self.getFact("resource.id"))
62            self.setFact("joblet.memo", msg)
63            print "Sweep", msg
64            sleeptime = self.getFact("jobargs.sleeptime")
65            time.sleep(sleeptime)
66

sweeper.policy

 1  <!--
 2   *=============================================================================
 3   * Copyright (c) 2008 Novell, Inc. All Rights Reserved.
 4   *
 5   * NOVELL PROVIDES THE SOFTWARE "AS IS," WITHOUT ANY EXPRESS OR IMPLIED
 6   * WARRANTY, INCLUDING WITHOUT THE IMPLIED WARRANTIES OF MERCHANTABILITY,
 7   * FITNESS FOR A PARTICULAR PURPOSE, AND NON INFRINGMENT.  NOVELL, THE AUTHORS
 8   * OF THE SOFTWARE, AND THE OWNERS OF COPYRIGHT IN THE SOFTWARE ARE NOT LIABLE
 9   * FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10   * TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE
11   * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12   *=============================================================================
13   * $Id: sweeper.policy,v 1.2 2008/02/27 20:51:24 john Exp $
14   *=============================================================================
15   -->
16
17  <policy>
18
19       <jobargs>
20            <!--
21              -  Defines and sets the length of time the joblet should pretend
22              -  it is doing something important
23              -->
24            <fact name="sleeptime"
25                  type="Integer"
26                  description="time to sleep (in seconds)"
27                  value="1"
28                  visible="true" />
29       </jobargs>
30
31
32       <job>
33            <!--
34              -  Give the job a description for GUI's
35              -->
36            <fact name="description"
37                  type="String"
38                  value="This example job ilustrates how to schedule a 'sweep' accross all matching resources." />
39
40            <!--
41              -  This activates a built in throttle to limit the number of
42              -  resources this job will run on at a time
43              -->
44            <fact name="maxresources"
45                  type="Integer"
46                  value="3" />
47
48            <!--
49              -  Rank resources from least loaded to the highest loaded. The
50              -  idea is to run the joblets on the least loaded node first
51              -  and hopefully by the time we get to the higher loaded machines
52              -  their load may have gone down
53              -->
54            <!--
55            <fact name="resources.rankby">
56              <array>
57                <string>resource.loadaverage/a</string>
58              </array>
59            </fact>
60             -->
61
62            <!--
63              -  Alternative ranking that is easier to see:
64              -  decending alphabetic of node name
65              -->
66            <fact name="resources.rankby">
67              <array>
68                <string>resource.id/d</string>
69              </array>
70            </fact>
71       </job>
72
73  </policy>
74

Classes and Methods

The class sweeperJob (see line 18, sweeper.jdl) is derived from the Job Class.

The class sweeperJoblet (see line 44, sweeper.jdl) is derived from the Joblet Class.

Definitions:

Job

A representation of a running job instance.

Joblet

Defines execution on the resource.

Job Details

The sweeper.job can be broken down into four separate parts:

Policy

In addition to specifying the jobarg and default settings for sleeptime in lines 8-12, sweeper.policy), there also is the <job/> section in lines 16-55, which describes static facts (see Facts).

The resources.rankby array has two notable setting in this example:

  • resource.loadaverage: This is the first string assignment (lines 38-44), which is commented out, that causes joblets to run on the least loaded nodes first.This is the default value and the default launch order for scheduleSweep.

  • resource.id: This is the second string assignment (lines 50-54), which is actually used, and assigns the string to the rank by array so that joblets run on nodes in reverse alphabetical order.

zosadmin deploy

When the Orchestrator server deploys a job for the first time (see Section 7.5, Deploying Jobs), the job JDL files are executed in a special deploy mode. When sweeper.jdl is run in this way (either via the zoc or the zosadmin deploy command), lines 6-15 are executed. This attempts to locate the examples jobgroup (lines 8-9), creates the group if it is not found (lines 10-11), and adds the sweeper job to the group (line 12).

If the deployment fails for any reason, then an exception is thrown (line 13), which prints the job name, group name, exception type and value (line 15).

job_started_event

The sweeperJob class (line 18) defines only the required job_started_event (line 20) method. This method runs on the Orchestrator server when the job is run to launch the joblets.

When executed, job_started_event displays a message on the memo line of the Job Log tab within the Jobs view in the Orchestrator console (line 21), via jobinstance.memo (see Section 7.12.1, Creating a Job Memo).

Jumping ahead for a moment, instead of calling self.schedule() as most the other examples do to instantiate joblets, sweeperJob calls self.scheduleSweep() (line 38). scheduleSweep requires an instance of ScheduleSpec, so one is created (line 23).

The ScheduleSpec method setConstraint can be used to constrain the available resources to a particular group, as shown with a comment (line 29). If this setConstraint line is uncommented, joblets will only run on members of the sweeper resource.group instead of using the default resource group all.

NOTE:The sweeper group must already be created and have computing nodes assigned to it (see Walkthrough: Create a Resource Account. This constraint would also be ANDed to any existing constraint, including any aggregated policies.

The sweeperJoblet is set to be scheduled (line 32), and setUseNodeSet(intnodeSet) is assigned (line 35) the value sp.ACTIVE_NODE_SET. So, the joblet set is constructed after applying resource constraints to the active/online resources. This in contrast to the other possible value of sp.PROVISIONABLE_NODE_SET, where constraints are applied to all provisionable resources.

joblet_started_event

The sweeperJoblet class (lines 44-51) defines only the required joblet_started_event (line 46) method. After this method is executed, it displays a message on the memo line of the Joblet tab within the Jobs view in the Orchestrator console (lines 47-48). It. also prints a similar log message (line 49), and then just sleeps for jobargs.sleeptime seconds (lines 50-51) before completion.

Configure and Run

Execute the following commands to deploy and run sweeper.job:

  1. Deploy notepad.job into the grid:

    > zosadmin deploy sweeper.job
    
  2. Display the list of deployed jobs:

    > zos joblist
    

    sweeper should appear in this list.

  3. Run the job on one or more resources using the default values for numJoblets and resource, specified in the sweeper.policy file:

    > zos run sweeper sleeptime=30
    JobID: zenuser.sweeper.420
    
    > zos status zenuser.sweeper.420
    Completed
    
    > zos log zenuser.sweeper.420
    Launched 3 joblets
    [melt] Sweep run on resource melt
    [freeze] Sweep run on resource freeze
    [skate] Sweep run on resource skate
    

See Also