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 zenuser Please enter current password for 'zenuser':
 Logged into grid as zenuser

> 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.job                                      # Total: 254 lines
|-- jobargs.jdl                                  #   77 lines
`-- jobargs.policy                               #  177 lines

jobargs.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: jobargs.jdl,v 1.3 2008/02/27 20:50:31 john Exp $
13  # -----------------------------------------------------------------------------
14
15  """
16  Example job showing all available job argument types.
17
18  Example cmd line to run job:
19       zos run jobargs TimeArgReq="12:01:02" RealArgReq="3.14" IntegerArgR eq="123" StringArgReq="foo" BooleanArgReq="true" ListArg="hi,mom"
20  """
21
22  import time
23
24  #
25  # Add to the 'examples' group on deployment
26  #
27  if __mode__ == "deploy":
28      try:
29          jobgroupname = "examples"
30          jobgroup = getMatrix().getGroup(TYPE_JOB, jobgroupname)
31          if jobgroup == None:
32              jobgroup = getMatrix().createGroup(TYPE_JOB, jobgroupname)
33          jobgroup.addMember(__jobname__)
34      except:
35          exc_type, exc_value, exc_traceback = sys.exc_info()
36          print "Error adding %s to %s group: %s %s" % (__jobname__, jobgr oupname, exc_type, exc_value)
37
38
39  class jobargs(Job):
40
41       def job_started_event(self):
42
43            jobid = self.getFact("jobinstance.id")
44            print "*****Dumping %s JobInstance jobargs facts*****" % (jobi d)
45            keys = self.getFactNames()
46            keys.sort()
47            for s in keys:
48               if s.startswith("jobargs"):
49                   v = self.getFact(s)
50                   ty = type(v)
51
52                   if str(ty).endswith("Dictionary"):
53                        self.dump_dict(s,v)
54                   else:
55                        if s.endswith("TimeArg") or s.endswith("TimeArgReq "):
56                            v = time.ctime(v/1000)
57
58                        print "%s %s %s" % (s,type(v),str(v))
59            print "*****End %s dump*****" % (jobid)
60
61            #self.schedule(jobargsJoblet)
62
63       def dump_dict(self,name,dict):
64            print "Dict: %s" % (name)
65            keys = dict.keys()
66            for k in keys:
67                v = dict[k]
68                ty = type(v)
69                if k == "dob":
70                     v = time.ctime(v/1000)
71                print "   %s %s %s" % (k,ty,str(v))
72
73
74  class jobargsJoblet(Joblet):

jobargs.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: jobargs.policy,v 1.2 2008/02/27 20:50:31 john Exp $
 14   *=============================================================================
 15   -->
 16
 17  <policy>
 18
 19    <jobargs>
 20
 21      <!-- Optional job args -->
 22      <fact name="OptionalDateArg"
 23            description="Optional Date Arg"
 24            type="Date"
 25            value="1/2/06 12:01 PM"/>
 26
 27      <fact name="OptionalTimeArg"
 28            description="Optional Time Arg"
 29            type="Time"
 30            value="12:01 PM"/>
 31
 32      <fact name="OptionalRealArg"
 33            description="Optional Real Arg"
 34            type="Real"
 35            value="3.14" />
 36
 37      <fact name="OptionalIntegerArg"
 38            description="Optional Integer Arg"
 39            type="Integer"
 40            value="123" />
 41
 42      <fact name="OptionalStringArg"
 43            description="Optional String Arg"
 44            type="String"
 45            value="foo" />
 46
 47      <fact name="OptionalString2ArgAsTag"
 48            description="Optional String Arg as tag">
 49        <string>bar</string>
 50      </fact>
 51
 52      <fact name="OptionalString3ArgAsCDATA"
 53            description="Optional String Arg as CDATA">
 54        <string>
 55          <![CDATA[this text is part of
 56  a multi-line cdata section containing
 57  xml <html>test</html>
 58  <eq fact="foo.bar" value="qwerty" />
 59  cool!
 60  ]]>
 61        </string>
 62      </fact>
 63
 64      <fact name="OptionalBooleanArg"
 65            description="Optional Boolean Arg"
 66            type="Boolean"
 67            value="true" />
 68
 69      <fact name="OptionalListArg">
 70        <list>
 71          <listelement value="hi" type="String" />
 72          <listelement value="mom" />
 73          <listelement value="42" type="Integer" />
 74        </list>
 75      </fact>
 76
 77      <fact name="OptionalDictArg">
 78        <dictionary>
 79          <dictelement key="name" type="String"  value="joe" />
 80          <dictelement key="date" type="Date"    value="4/15/06" />
 81          <dictelement key="time" type="Time"    value="3:30 AM" />
 82          <dictelement key="age"  type="Integer" value="12" />
 83        </dictionary>
 84      </fact>
 85
 86      <fact name="OptionalDateArray">
 87        <array>
 88          <date>1/2/06 12:01 PM</date>
 89          <date>1/3/06 12:02 PM</date>
 90          <date>1/4/06</date>
 91        </array>
 92      </fact>
 93      <fact name="OptionalTimeArray">
 94        <array>
 95          <time>12:01 PM</time>
 96          <time>12:02 PM</time>
 97        </array>
 98      </fact>
 99      <fact name="OptionalRealArray">
100        <array>
101          <real>1.1</real>
102          <real>2.2</real>
103        </array>
104      </fact>
105      <fact name="OptionalIntegerArray">
106        <array>
107          <integer>1</integer>
108          <integer>2</integer>
109        </array>
110      </fact>
111      <fact name="OptionalStringArray">
112        <array>
113          <string>string1</string>
114          <string>string2</string>
115        </array>
116      </fact>
117  <!-- Arrays of dictionary or list not currently supported
118      <fact name="OptionalDictionaryArray">
119        <array>
120          <dictionary>
121            <dictelement key="name" type="String"  value="joe" />
122          </dictionary>
123        </array>
124      </fact>
125  -->
126
127      <!-- Required job args -->
128      <fact name="RequiredDateArg" type="Date" />
129      <fact name="RequiredTimeArg" type="Time" />
130      <fact name="RequiredRealArg" type="Real" />
131      <fact name="RequiredIntegerArg" type="Integer" />
132      <fact name="RequiredStringArg" type="String" />
133      <fact name="RequiredBooleanArg" type="Boolean" />
134    <!-- XXX Ooops, not currently supported without value!
135      <fact name="RequiredListArg" type="list" />
136      <fact name="RequiredDictArg" type="dictionary" />
137      <fact name="RequiredStringArray" type="string">
138        <array />
139      </fact>
140    -->
141
142      <!-- Invisible job args -->
143      <fact name="InvisibleDateArg" type="Date" value="1/2/06 12:01 PM" visible="False" />
144      <fact name="InvisibleTimeArg" type="Time" value="12:01 PM" visible="False" />
145      <fact name="InvisibleRealArg" type="Real" value="3.14" visible="False" />
146      <fact name="InvisibleIntegerArg" type="Integer" value="123" visible="False" />
147      <fact name="InvisibleStringArg" type="String" value="foo" visible="False" />
148      <fact name="InvisibleString2Arg" visible="False" >
149        <string>bar</string>
150      </fact>
151      <fact name="InvisibleBooleanArg" type="Boolean" value="true"  visible="False" />
152      <fact name="InvisibleListArg" visible="False">
153        <list>
154          <listelement value="hi" type="String" />
155          <listelement value="mom" />
156          <listelement value="42" type="integer" />
157        </list>
158      </fact>
159      <fact name="InvisibleDictArg" visible="False">
160        <dictionary>
161          <dictelement key="name" type="String"  value="joe" />
162          <dictelement key="date" type="Date"    value="4/15/06" />
163          <dictelement key="time" type="Time"    value="3:30 AM" />
164          <dictelement key="age"  type="Integer" value="12" />
165        </dictionary>
166      </fact>
167
168    </jobargs>
169
170    <job>
171      <fact name="description"
172            type="String"
173            value="This example job tests all fact types." />
174    </job>
175
176  </policy>
177

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 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

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 Section 5.0, Developing Policies and Section 4.4, 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