Launches the Notepad application on a Windows resource.
> zos login --user vmmanager Please enter current password for 'vmmanager': Logged into grid as vmmanager > zos jobinfo --detail notepad Jobname/Parameters Attributes ------------------ ---------- notepad Desc: No description available.
The files that make up the Notepad job include:
notepad # Total: 55 lines |-- notepad.jdl # 40 lines `-- notepad.policy # 15 lines
0 """ 1 2 Run Notepad Application on windows resource 3 4 """ 5 import os,time 6 7 # 8 # Add to the 'examples' group on deployment 9 # 10 if __mode__ == "deploy": 11 try: 12 jobgroupname = "examples" 13 jobgroup = getMatrix().getGroup(TYPE_JOB, jobgroupname) 14 if jobgroup == None: 15 jobgroup = getMatrix().createGroup(TYPE_JOB, jobgroupname) 16 jobgroup.addMember(__jobname__) 17 except: 18 exc_type, exc_value, exc_traceback = sys.exc_info() 19 print "Error adding %s to %s group: %s %s" % (__jobname__, jobgroupname, exc_type, exc_value) 21 22 class Notepad(Job): 23 24 def job_started_event(self): 25 print "Scheduling joblet" 26 self.schedule(NotepadJoblet) 27 28 29 class NotepadJoblet(Joblet): 30 31 def joblet_started_event(self): 32 print "Starting Notepad" 33 cmd = "notepad" 34 e = Exec() 35 e.setCommand(cmd) 36 e.writeStdoutToLog() 37 e.writeStderrToLog() 38 result = e.execute()
0 <policy> 1 <constraint type="accept" > 2 <gt fact="jobinstance.matchingresources" value="0" reason="No Windows's resources are available to run Notepad" /> 3 </constraint> 4 <constraint type="resource" > 5 <eq fact="resource.os.family" value="windows" reason="Notepad only runs on Windows OS" /> 6 </constraint> 7 </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.
Used to manage command line execution on resources.
The Notepad job is broken down into three separate operations:
In notepad.jdl, lines 7-19 deploy the job into the grid. After jobs are deployed into the grid, they can optionally be placed in groups for organization and easy reference. In this case, the Notepad job is added to the group named Examples and appears in the ZENworks Orchestrator Console in the Explorer panel at the location:
/ZOS/YOUR_GRID/Jobs/examples
For a general overview of how jobs are added to groups during deployment, see Deploying a Sample Job .
Scheduling the Notepad joblet to run immediately is the second operation performed by the Notepad job in line 26 of notepad.jdl. When the Notepad job class receives a job_started_event() notification, it simply schedules the NotepadJoblet class to be run on any target device that meets the restrictions identified in the notepad.policy file.
As specified in lines 2 and 5 of notepad.policy, there must be at least one Windows machine available in the grid for the Notepad job to run. The accept constraint in lines 1-3 prevents the Notepad job from being accepted for running if there are no Windows resources available.
The resource constraint in lines 4-7 constrain the Orchestrator scheduler to only choose a resource that is running a Windows OS.
For more information on setting constraints using policies, see Section 4.4, Policy Management and Section 5.0, Developing Policies.
As specified in lines 33-38 in notepad.jdl, the joblet executing a command on the target machine is the last operation performed by the Notepad job.
In this example, after the joblet_started_event() method of the NotepadJoblet class gets called, the ZENworks Orchestrator API class named Exec is used to run the command notepad on is captured and written to the log file for the Notepad job.
Execute the following commands to deploy and run notepad.job:
Deploy notepad.job into the grid:
> zosadmin deploy notepad.job
Display the list of deployed jobs:
> zos joblist
should appear in this list.
Run the job on the first available Windows resource.
> zos run notepad
You should now see the Windows Notepad application appear on the screen of the target Windows system.
Setting Constraints Using Policies see 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).
Executing Commands Using Exec