Demonstrates a job starting up multiple instances of a joblet on one or more resources. Because this job simply launches and returns immediately, it can also be useful for testing network latency.
> zos login --user vmmanager Please enter current password for 'vmmanager': Logged into grid as vmmanager > zos jobinfo --detail quickie Jobname/Parameters Attributes ------------------ ---------- quickie Desc: This example job does absolutely nothing. It just returns immediately. For testing network latency. sleeptime Desc: time to sleep (in seconds) Type: Integer Default: 0 numJoblets Desc: joblets to run Type: Integer Default: 100
The files that make up the Quickie job include:
quickie # Total: 56 lines|-- quickie.jdl # 33 lines `-- quickie.policy # 23 lines
1 import time 2 3 # 4 # Add to the 'examples' group on deployment 5 # 6 if __mode__ == "deploy": 7 try: 8 jobgroupname = "examples" 9 jobgroup = getMatrix().getGroup(TYPE_JOB, jobgroupname) 10 if jobgroup == None: 11 jobgroup = getMatrix().createGroup(TYPE_JOB, jobgroupname) 12 jobgroup.addMember(__jobname__) 13 except: 14 exc_type, exc_value, exc_traceback = sys.exc_info() 15 print "Error adding %s to %s group: %s %s" % (__jobname__, jobgroupname, exc_type, exc_value) 16 17 class quickieJob(Job): 18 19 def job_started_event(self): 20 21 # Launch the joblets 22 numJoblets = self.getFact("jobargs.numJoblets") 23 print 'Launching ', numJoblets, ' joblets' 24 25 self.schedule(quickieJoblet, numJoblets) 26 27 class quickieJoblet(Joblet): 28 29 def joblet_started_event(self): 30 sleeptime = self.getFact("jobargs.sleeptime") 31 time.sleep(sleeptime)
1 <policy> 2 <jobargs> 3 <fact name="numJoblets" 4 type="Integer" 5 description="joblets to run" 6 value="100" 7 visible="true" /> 8 9 <fact name="sleeptime" 10 type="Integer" 11 description="time to sleep (in seconds)" 12 value="0" 13 visible="true" /> 14 </jobargs> 15 16 <job> 17 <fact name="description" 18 type="String" 19 value="This example job does absolutely nothing. It just returns immediately. For testing network latency." /> 20 </job> 21 </policy>
A representation of a running job instance.
Defines execution on the resource.
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.
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.
The Quickie job can be broken down into the following separate operations:
The job is first deployed into the grid, as shown in lines 2-14 of quickie.jdl. When jobs are deployed into the grid, they can optionally be organized into groups for easy reference. In this example, the Quickie job is added to the group named examples and displays in the ZENworks Orchestrator Console in the Explorer panel at the location:
/ZOS/YOUR_GRID/Jobs/examples
As shown in line 25 of quickie.jdl, scheduling one or more instances of the Quickie joblet to run immediately is the second operation performed by the Quickie job. When the Quickie job class receives a job_started_event() notification, it schedules the number of QuickieJoblet instances as indicated by the value of the setting numJoblets, whose value might have been supplied on the command line or from the quickie.policy file (see line 3 in quickie.policy).
The final operation performed by the Quickie job is for the joblet to sleep an amount of time as specified by the value of the setting sleeptime (see line 31 in quickie.jdl), and then exit.
Deploy quickie.job into the grid:
> zosadmin deploy quickie.job
Display the list of deployed jobs:
> zos joblist
should appear in this list.
Run the job on one or more resources using the default values for numJoblets and sleeptime:
> zos run quickie
Run the job on one or more resources using supplied values for numJoblets and sleeptime:
> zos run quickie numJoblets=10 sleeptime=3 JobID: vmmanager.quickie.418 > zos status vmmanager.quickie.418 Completed > zos log vmmanager.quickie.418 Launching 10 joblets
Ten joblets will be run simultaneously, depending on the number of resources available in the grid and how many simultaneous jobs each resource is configured to run. After the job runs, each quickie joblet instance simply starts up, sleeps for 3 seconds, and then exits.
Setting Constraints Using Policies (Section 4.4, Policy Management and Section 5.0, Developing Policies).
Adding jobs to groups during deployment (see how the JDL code can print the ID of group of jobs in factJunction.job).
Scheduling multiple instances of a joblet