notepad.job

Launches the Notepad application on a Windows resource.

Usage

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

> zos jobinfo --detail notepad
Jobname/Parameters    Attributes
------------------    ----------
notepad            Desc: No description available.

Description

The files that make up the Notepad job include:

notepad                                     # Total: 86 lines
|-- notepad.jdl                             #   54 lines
`-- notepad.policy                          #   32 lines

notepad.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: notepad.jdl,v 1.3 2008/02/27 20:50:47 john Exp $
13  # -----------------------------------------------------------------------------
14
15  """
16
17  Run Notepad Application on windows resoure
18
19  """
20  import os,time
21
22  #
23  # Add to the 'examples' group on deployment
24  #
25  if __mode__ == "deploy":
26      try:
27          jobgroupname = "examples"
28          jobgroup = getMatrix().getGroup(TYPE_JOB, jobgroupname)
29          if jobgroup == None:
30              jobgroup = getMatrix().createGroup(TYPE_JOB, jobgroupname)
31          jobgroup.addMember(__jobname__)
32      except:
33          exc_type, exc_value, exc_traceback = sys.exc_info()
34          print "Error adding %s to %s group: %s %s" % (__jobname__, jobgroupname, exc_type, exc_value)
35
36
37  class Notepad(Job):
38
39       def job_started_event(self):
40            print "Scheduling joblet"
41            self.schedule(NotepadJoblet)
42
43
44  class NotepadJoblet(Joblet):
45
46       def joblet_started_event(self):
47            print "Starting Notepad"
48            cmd = "notepad"
49            e = Exec()
50            e.setCommand(cmd)
51            e.writeStdoutToLog()
52            e.writeStderrToLog()
53            result = e.execute()
54

notepad.policy

 1  <!--
 2   *=============================================================================
 3   * Copyright © 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: notepad.policy,v 1.2 2008/02/27 20:50:47 john Exp $
14   *=============================================================================
15   -->
16
17  <policy>
18
19       <constraint type="accept" >
20
21            <gt fact="jobinstance.matchingresources" value="0" reason="No Windows's resources are available to run Notepad" />
22
23       </constraint>
24
25       <constraint type="resource" >
26
27            <eq fact="resource.os.family" value="windows" reason="Notepad only runs on Windows OS" />
28
29       </constraint>
30
31  </policy>
32

Classes and Methods

Definitions:

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.

Job Details

The Notepad job is broken down into three separate operations:

zosadmin deploy

In notepad.jdl, lines 7-19 places the job into the “examples” job group. 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 view at the location:

/ZOS/YOUR_GRID/Jobs/examples

For a general overview of how jobs are added to groups during deployment, see Walkthrough: Deploy a Sample Job in the Novell ZENworks Orchestrator 1.3 Installation and Getting Started Guide.

job_started_event

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.

joblet_started_event

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.

Configure and Run

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

  1. Deploy notepad.job into the grid:

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

    > zos joblist
    

    notepad should appear in this list.

  3. 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. You will see the following error if there are no Windows resources.

    No Windows resources available to run Notepad 
    

See Also