jobargs.job

Demonstrates the usage of the various argument types that jobs can accept. These types are integer, Real, Boolean, String, Time, Date, List, Dictionary, and Array (which can contain the types Integer, Real, Boolean, Time, Date, String). For more information about how to define job arguments, and specify their values on the command line, see Section 7.7, Working with Facts and Constraints.

Usage

> zosadmin login --user zosadmin Login to server: skate
Please enter current password for 'zosadmin':
Logged into grid on server 'skate'

> cd /opt/novell/zenworks/zos/server/examples
> zosadmin deploy jobargs.job
jobargs successfully deployed

> zos login --user vmmanagerPlease enter current password for 'vmmanager':
 Logged into grid as vmmanager

> zos jobinfo --detail jobargs
Jobname/Parameters    Attributes
------------------    ----------
jobargs                Desc: This example job tests all fact types.

    TimeArgReq         Desc: Required Time arg test
                       Type: Time
                    Default: None! Value must be specified

    IntegerArg         Desc: Integer arg test
                       Type: Integer
                    Default: 1

    DateArg            Desc: Date arg test
                       Type: Date
                    Default: Wed Apr 05 09:00:00 EDT 2006

    RealArgReq         Desc: Required Real arg test
                       Type: Real
                    Default: None! Value must be specified

    IntegerArrayArg    Desc: Integer[] arg test
                       Type: Integer[]
                    Default: [100,200,300]

    RealArrayArg       Desc: Real[] arg test
                       Type: Real[]
                    Default: [1.23,3.456,7.0]

    DictArg            Desc: Dictionary arg test
                       Type: Dictionary
                    Default: {name=moe, dob=Fri Jan 02 00:00:00 EST 1970,
                             age=35}

    DateArrayArg       Desc: Date[] arg test
                       Type: Date[]
                    Default: [Wed Jul 08 22:00:00 EDT 2009,Thu Jan 02 00:01:00
                             EST 2003]

    StringArgReq       Desc: Required String arg test
                       Type: String
                    Default: None! Value must be specified

    TimeArrayArg       Desc: Time[] arg test
                       Type: Time[]
                    Default: [79200000,60000]

    StringArrayArg     Desc: String[] arg test
                       Type: String[]
                    Default: [abc,def,ghi jkl]

    TimeArg            Desc: Time arg test
                       Type: Time
                    Default: 32400000

    BooleanArgReq      Desc: Required Boolean arg test
                       Type: Boolean
                    Default: None! Value must be specified

    BooleanArg         Desc: Boolean arg test
                       Type: Boolean
                    Default: true

    IntegerArgReq      Desc: Required Integer arg test
                       Type: Integer
                    Default: None! Value must be specified

    StringArg          Desc: String arg test
                       Type: String
                    Default: Hello World

    BooleanArrayArg    Desc: Boolean[] arg test
                       Type: Boolean[]
                    Default: [true,false,true]

    RealArg            Desc: Real arg test
                       Type: Real
                    Default: 3.1415

    ListArg            Desc: List arg test
                       Type: List
                    Default: [abc, d, efghij]

    DateArgReq         Desc: Required Date arg test
                       Type: Date
                    Default: None! Value must be specified

Description

The files that make up the Jobargs job include:

jobargs                                          # Total: 210 lines
|-- jobargs.jdl                                  #   63 lines
`-- jobargs.policy                               #  147 lines

jobargs.jdl

 1  """
 2  Example job showing all available job argument types.
 3 
 4  Example cmd line to run job:
 5       matrix run jobargs TimeArgReq="12:01:02" RealArgReq="3.14" IntegerArgReq="123" StringArgReq="foo" BooleanArgReq="true" ListArg="hi,mom"
 6  """
 7  
 8  import time 
 9  
10  # 
11  # Add to the 'examples' group on deployment 
12  # 
13  if __mode__ == "deploy": 
14      try: 
15          jobgroupname = "examples" 
16          jobgroup = getMatrix().getGroup(TYPE_JOB, jobgroupname) 
17          if jobgroup == None: 
18              jobgroup = getMatrix().createGroup(TYPE_JOB, jobgroupname) 
19          jobgroup.addMember(__jobname__) 
20      except: 
21          exc_type, exc_value, exc_traceback = sys.exc_info() 
22          print "Error adding %s to %s group: %s %s" % (__jobname__, jobgroupname, exc_type, exc_value) 
23  
24  
25  class jobargs(Job): 
26  
27      def job_started_event(self): 
28  29          jobid = self.getFact("jobinstance.id") 30          print "*****Dumping %s JobInstance jobargs facts*****" % (jobid) 
31          keys = self.getFactNames() 
32          keys.sort() 
33          for s in keys: 
34              if s.startswith("jobargs"): 
35                  v = self.getFact(s) 
36                  ty = type(v) 
37  
38                  if str(ty).endswith("Dictionary"): 
39                      self.dump_dict(s,v) 
40                  else: 
41                      if s.endswith("TimeArg") or s.endswith("TimeArgReq"): 
42                          v = time.ctime(v/1000) 
43                      
44                      print "%s %s %s" % (s,type(v),str(v)) 
45          print "*****End %s dump*****" % (jobid) 
46  
47          #self.schedule(jobargsJoblet) 
48  
49      def dump_dict(self,name,dict): 
50          print "Dict: %s" % (name) 
51          keys = dict.keys() 
52          for k in keys: 
53              v = dict[k] 
54              ty = type(v) 
55              if k == "dob": 
56                  v = time.ctime(v/1000) 
57              print "   %s %s %s" % (k,ty,str(v)) 
58  
59                
60  class jobargsJoblet(Joblet): 
61  
62      def joblet_started_event(self): 
63          pass

jobargs.policy

  1  <policy> 
  2  
  3       <jobargs> 
  4            <fact name="IntegerArg" 
  5                  type="Integer" 
  6                  description="Integer arg test" 
  7                  value="1" 
  8                  /> 
  9  
 10            <fact name="IntegerArgReq" 
 11                  type="Integer" 
 12                  description="Required Integer arg test" 
 13                  /> 
 14  
 15            <fact name="RealArg" 
 16                  type="Real" 
 17                  description="Real arg test" 
 18                  value="3.1415" 
 19                  /> 
 20  
 21            <fact name="RealArgReq" 
 22                  type="Real" 
 23                  description="Required Real arg test" 
 24                  /> 
 25                                  
 26            <fact name="BooleanArg" 
 27                  type="Boolean" 
 28                  description="Boolean arg test" 
 29                  value="true" 
 30                  /> 
 31  
 32            <fact name="BooleanArgReq" 
 33                  type="Boolean" 
 34                  description="Required Boolean arg test" 
 35                  /> 
 36                  
 37            <fact name="StringArg" 
 38                  type="String" 
 39                  description="String arg test" 
 40                  value="Hello World" 
 41                  /> 
 42  
 43            <fact name="StringArgReq" 
 44                  type="String" 
 45                  description="Required String arg test" 
 46                  /> 
 47                  
 48            <fact name="TimeArg" 
 49                  type="Time" 
 50                  description="Time arg test" 
 51                  value="9:00 AM" 
 52                  /> 
 53  
 54            <fact name="TimeArgReq" 
 55                  type="Time" 
 56                  description="Required Time arg test" 
 57                  /> 
 58  
 59            <fact name="DateArg" 
 60                  type="Date" 
 61                  description="Date arg test" 
 62                  value="04/05/06 9:00 AM" 
 63                  /> 
 64  
 65            <fact name="DateArgReq" 
 66                  type="Date" 
 67                  description="Required Date arg test" 
 68                  /> 
 69  
 70            <fact name="ListArg" 
 71                  description="List arg test"> 
 72              <list> 
 73                  <listelement value="abc" /> 
 74                  <listelement value="d" /> 
 75                  <listelement value="efghij" /> 
 76              </list> 
 77            </fact> 
 78            
 79            <fact name="DictArg" 
 80                  description="Dictionary arg test"> 
 81              <dictionary> 
 82                  <dictelement key="name" type="String" value="moe" /> 
 83                  <dictelement key="age" type="Integer" value="35" /> 
 84                  <dictelement key="dob" type="Date" value="01/02/70" /> 
 85              </dictionary> 
 86            </fact> 
 87  
 88            <fact name="IntegerArrayArg" 
 89                  description="Integer[] arg test"> 
 90              <array> 
 91                  <integer>100</integer> 
 92                  <integer>200</integer> 
 93                  <integer>300</integer>  94              </array>  95            </fact> 
 96  
 97            <fact name="RealArrayArg" 
 98                  description="Real[] arg test"> 
 99              <array> 
100                  <real>1.23</real> 
101                  <real>3.456</real> 
102                  <real>7</real> 
103              </array> 
104            </fact> 
105  
106            <fact name="BooleanArrayArg" 
107                  description="Boolean[] arg test"> 
108              <array> 
109                  <boolean>true</boolean> 
110                  <boolean>false</boolean> 
111                  <boolean>true</boolean> 
112              </array> 
113            </fact> 
114  
115            <fact name="TimeArrayArg" 
116                  description="Time[] arg test"> 
117              <array> 
118                  <time>10:00 PM</time> 
119                  <time>12:01 AM</time> 
120              </array> 
121            </fact> 
122  
123            <fact name="DateArrayArg" 
124                  description="Date[] arg test"> 
125              <array> 
126                  <date>07/08/09 10:00 PM</date> 
127                  <date>01/02/03 12:01 AM</date> 
128              </array> 
129            </fact> 
130                                   
131            <fact name="StringArrayArg" 
132                  description="String[] arg test"> 
133              <array> 
134                  <string>abc</string> 
135                  <string>def</string> 
136                  <string>ghi jkl</string> 
137              </array> 
138            </fact> 
139       </jobargs> 
140       
141       <job> 
142            <fact name="description" 
143                  type="String" 
144                  value="This example job tests all fact types." /> 
145       </job> 
146            
147  </policy>

Schedule File (optional)

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.

Job Details

The Jobargs job performs its work by handling the following events:

zosadmin deploy

In jobargs.jdl, lines 10-229 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 jobargs job will be added to the group named “examples”, and will show up 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 .

job_started_event

After the Jobargs job receives a job_started_event, it gets a list of all the facts available to it, as shown in line 31 of jobargs.jdl. This list is sorted, filtered according to whether or not it’s a jobarg fact, and then enumerated (lines 32-42). Each jobarg fact is printed in a “name type value” format. When the complex Dictionary type is encountered (line 38), a separate method is used to print the values for all the key-value pairs (lines 49-57).

The list of optional and required arguments for this Jobargs example are available as facts within the <jobargs> section (see lines 3-139 in jobargs.policy).

For more information about defining job arguments and their types, see Developing Policies and Policy Management.

joblet_started_event

The Jobargs job only illustrates passing job arguments to a job. Therefore, no work is performed on the resource by the jobargsJoblet.

Configure and Run

To run this example, you must have ZENworks Orchestrator installed and configured properly. No agents on separate resources are required. You also must be logged into your Orchestrator server before you run zosadmin or zos commands.

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

  1. Deploy jobargs.job into the grid:

    > zosadmin deploy jobarg.job
    

    NOTE:Run zosadmin login to log in for zos administration.

  2. Display the list of deployed jobs:

    > zos joblist
    

    jobargs should appear in this list.

    NOTE:Run zos login to run zos client jobs.

  3. Display the list of optional and required arguments for this job:

    > zos jobinfo jobargs
    
  4. Run the jobargs job and view the results.

    NOTE:You must supply values for TimeArgReq, RealArgReq, StringArgReq, BooleanArgReq, IntegerArgReq, and DateArgReq as follows (see jobargs.policy for the full list of arguments that can be specified):

    > zos run jobargs TimeArgReq=12:01:02 RealArgReq=3.14 StringArgReq=Hello BooleanArgReq=True IntegerArgReq=42 DateArgReq="04/05/07 7:45 AM"
    
    zos log jobargs
    

See Also