mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

andrug
31.49.2008 09336a459e6a014540e977029d94a3627caae6fb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "../../../../shared/stax.dtd">
<!--
 ! CDDL HEADER START
 !
 ! The contents of this file are subject to the terms of the
 ! Common Development and Distribution License, Version 1.0 only
 ! (the "License").  You may not use this file except in compliance
 ! with the License.
 !
 ! You can obtain a copy of the license at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE
 ! or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 ! See the License for the specific language governing permissions
 ! and limitations under the License.
 !
 ! When distributing Covered Code, include this CDDL HEADER in each
 ! file and include the License file at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 ! add the following below this CDDL HEADER, with the fields enclosed
 ! by brackets "[]" replaced with your own identifying information:
 !      Portions Copyright [yyyy] [name of copyright owner]
 !
 ! CDDL HEADER END
 !
 !      Copyright 2008 Sun Microsystems, Inc.
 ! -->
<stax>
  
  <!-- ************************************************************ -->
  <function name="checkRC" scope="local">
    <function-prolog>
      This function checks a return code against an expected return code
    </function-prolog>
    
    <function-map-args>
      <function-arg-def name="returncode" type="required">
        <function-arg-description>
          return code received from command
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="result" type="required">
        <function-arg-description>
          the output of the result
        </function-arg-description>
      </function-arg-def>          
      <function-arg-def name="expected" type="optional" default="[0]">
        <function-arg-description>
          the expected return code (list of value : [0] or [0,5])
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="fileFd" type="optional" default="LOG_MAIN_FD">
        <function-arg-description>
          file descriptor, keywords : NO_FILE
        </function-arg-description>
      </function-arg-def>
    </function-map-args>
 
    <sequence>
<!-- TBD
      <script>
        result = result.replace('"','&quot;')
#        result = result.replace('<','&lt;')
#        result = result.replace('>','&gt;')
      </script>
      
      see the call in scheduler.xml
      clientSearchLoad() checkRC after process "running java program : searchLoad"
-->
      <script>
        _errNum = 0
        verdict = 'FAIL'
        for expRC in expected:
          if ( expRC == returncode ):
            verdict = 'PASS'
      </script>
      <if expr="verdict == 'PASS'">
        <sequence>
          <call function="'writeOperationResult'">
          {
            'returncode' : returncode,
            'expected'   : expected,
            'result'     : '',
            'status'     : 'SUCCESS',
            'fileFd'     : fileFd
          }
          </call>
        </sequence>
      <else>
        <sequence>
          <call function="'writeOperationResult'">
          {
            'returncode' : returncode,
            'expected'   : expected,
            'result'     : result,
            'status'     : 'ERROR',
            'fileFd'     : fileFd
          }
          </call>
          <script>
            _errNum = 1
          </script>
        </sequence>
      </else>
      </if>
      <script>
        ERR_NUM[0] += _errNum
      </script>
      <return>
        _errNum
      </return>
    </sequence>
  </function>
 
 
  <!-- ************************************************************ -->
  <function name="phasePreamble" scope="local">
    <function-prolog>
      Performs all the preoperations for a phase
    </function-prolog>
    
    <function-map-args>
      <function-arg-def name="phaseName" type="required">
      </function-arg-def>
      <function-arg-def name="tagAttr" type="optional" default='[]'>
        <function-arg-description>
          attribute/value of the tag [[attr1,val1],[attr2,val2],...]
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="fileFd" type="required">
      </function-arg-def>
    </function-map-args>
    
    <sequence>
      <!-- Start time of test suite -->      
      <script>
        phaseStartTime=strftime("%Y%m%d@%H:%M:%S",localtime())
        ERR_NUM[0] = 0
        if tagAttr == []:
          tagAttr = [['date',phaseStartTime]]
        else:
          tagAttr.append(['date',phaseStartTime])
      </script>
      
      <message log="1">''</message>
      <message log="1">
        '=================== START PHASE %s @ %s  ========================='\
        % (phaseName,phaseStartTime)
      </message>
      
      <call function="'writeStartTagPhase'">
      {
        'tagName' : phaseName ,
        'tagAttr' : tagAttr,
        'fileFd'  : fileFd
      }
      </call>
      
    </sequence>
  </function>
 
 
 
  <!-- ************************************************************ -->
  <function name="phasePostamble" scope="local">
    <function-prolog>
      Performs all the post operations for a phase
    </function-prolog>
    <function-map-args>
      <function-arg-def name="phaseName" type="required">
        <function-arg-description>
          Name of the phase
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="fileFd" type="required">
        <function-arg-description>
          Name of output file descriptor
        </function-arg-description>
      </function-arg-def>
    </function-map-args>
    
    <sequence>
      
      <if expr="phaseName == 'verdict'">
        <message log="1">
          '== Found a TOTAL of %s Error(s)' % (ERR_NUM[0])
        </message>
      <else>
        <message log="1">
          '== Found %s Error(s) during this phase' % (ERR_NUM[0])
        </message>
      </else>
      </if>
      <message log="1">
        '===================  STOP PHASE %s  ============================' \
        % (phaseName)
      </message>
      
      <call function="'writeTag'">
      {
        'tagName' : 'phaseResult',
        'tagAttr' : [['errNum',ERR_NUM[0]]] ,
        'fileFd'  : LOG_MAIN_FD
      }
      </call>
      
      <call function="'writeEndTagPhase'">
      {
        'fileFd'  : LOG_MAIN_FD
      }
      </call>
    </sequence>
  </function>
 
 
  <!-- ************************************************************ -->
  <function name="sleep" scope="local">
    <function-prolog>
      Sleep for number of milliseconds
    </function-prolog>
    <function-map-args>
      <function-arg-def name="location" type="optional" default="'%s' % STAXServiceMachine">
        <function-arg-description>
          Location of target host
      </function-arg-description>
      <function-arg-property name="type" value="hostname"/>
      </function-arg-def>
      <function-arg-def name="sleepForMilliSeconds" type="required">
        <function-arg-description>
          Number of milliseconds to sleep
        </function-arg-description>
        <function-arg-property name="type" value="seconds"/>
      </function-arg-def>
      <function-arg-def name="silentMode" type="optional" default="FALSE">
        <function-arg-description>
          do not write message in log file if set to TRUE
        </function-arg-description>
        <function-arg-property name="type" value="seconds"/>
      </function-arg-def>
      <function-arg-def name="fileFd" type="required">
        <function-arg-description>
          Name of output file descriptor
        </function-arg-description>
      </function-arg-def>
    </function-map-args>
    
    <sequence>
      <if expr="silentMode == 'FALSE'">
        <sequence>
          <call function="'writeStartTagOperation'">
          { 'tagName' : 'sleep',
            'fileFd'  : fileFd }
          </call>
          <call function="'writeMessage'">
          { 'fileFd'  : fileFd,
            'content' : 'sleep for %s milliseconds on %s' % (sleepForMilliSeconds,location)
          }
          </call>
        </sequence>
      </if>
      
      <stafcmd name="'STAF Command: Delay'">
        <location>'%s' % location</location>
        <service>'delay'</service>
        <request>
          'delay %i' % sleepForMilliSeconds
        </request>
      </stafcmd>
      
      <if expr="silentMode == 'FALSE'">
        <sequence>
          <call function="'checkRC'">
            { 'returncode' : RC ,
              'result'     : STAFResult,
              'fileFd'     : fileFd }
          </call>
          <call function="'writeEndTagOperation'">{'fileFd'  : fileFd}</call>
        </sequence>
      </if>
    </sequence>
  </function>
 
 
  <!-- ************************************************************ -->
  <function name="ldifDiff" scope="local">
    <function-prolog>
      This function  compares two LDIF files and reports the differences in LDIF format
    </function-prolog>
    <function-map-args>
      <function-arg-def name="location" type="optional" default="STAF_REMOTE_HOSTNAME">
        <function-arg-description>
          Location of target host
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="dsPath" type="required">
        <function-arg-description>
          Pathname to installation root
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="version" type="optional">
        <function-arg-description>
          Display Directory Server version information
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="sourceLdif" type="required">
        <function-arg-description>
          LDIF file to use as the source data
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="targetLdif" type="required">
        <function-arg-description>
          LDIF file to use as the target data
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="outputLdif" type="required">
        <function-arg-description>
          File to which the diffs should be written
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="overwriteExisting" type="optional" default="TRUE">
        <function-arg-description>
          Overwrite existing output file rather than append to it
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="singleValueChanges" type="optional">
        <function-arg-description>
          Write each attribute-level change as a separate modification 
          per attribute value rather than one modification per entry
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="Help" type="optional">
        <function-arg-description>
          Help option
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="fileFd" type="required">
        <function-arg-description>
          Name of output file descriptor
        </function-arg-description>
      </function-arg-def>
    </function-map-args>
    <sequence>
      <call function="'writeStartTagOperation'">
      { 'tagName' : 'ldifDiff',
        'fileFd'  : fileFd }
      </call>
      <call function="'writeMessage'">
      { 'fileFd'  : fileFd,
        'content' : 'Compares two LDIF files and reports the differences in LDIF format'
      }
      </call>
 
      
      <!-- Build the Command -->
      <script>
        STAFCmdParamsList=[]
        STAFCmdParams=''
        
        if dsPath:
          dsBinPath='%s/bin' % (dsPath) 
          STAFCmd='%s/ldif-diff' % (dsBinPath)
        
        if version:
          STAFCmdParamsList.append('-V')
        
        if sourceLdif:
          STAFCmdParamsList.append('-s %s' % sourceLdif)
        
        if targetLdif:
          STAFCmdParamsList.append('-t %s' % targetLdif)
        
        if outputLdif:
          STAFCmdParamsList.append('-o %s' % outputLdif)
        
        if overwriteExisting:
          STAFCmdParamsList.append('-O')
        
        if singleValueChanges:
          STAFCmdParamsList.append('-S')
        
        if Help:
          STAFCmdParamsList.append('-H')
        
        STAFCmdParams=' '.join(STAFCmdParamsList)
      </script>
      <call function="'writeMessage'">
      { 'fileFd'  : fileFd,
        'content' : '%s %s' % (STAFCmd,STAFCmdParams)
      }
      </call>
      <process name="'LDIF Diff Script'">
        <location>location</location>
        <command>STAFCmd</command>
        <parms>STAFCmdParams</parms>
        <workdir>dsBinPath</workdir>
        <envs>
          ['PATH=/bin:/usr/bin:%s' % dsBinPath]
        </envs>
        <console use="'same'"/>
        <stderr mode="'stdout'"/>
        <returnstdout/>          
        <returnfile>outputLdif</returnfile>
      </process>
      
      <script>
        STAXCode=RC
        STAXReason=STAXResult
      </script>
      
      <script>
        diffsInfo = STAXReason[1]
        diffs = diffsInfo[1]           
        if (diffsInfo[0] == 0) and (diffs.startswith("# No differences were detected between the source and target LDIF files")) :
          diffRC = 0
        else:
          diffRC = 1
      </script>
      <call function="'checkRC'">
        { 'returncode' : diffRC,
          'result'     : 'diff file : %s' % outputLdif,
          'fileFd'     : fileFd }
      </call>
      <call function="'writeEndTagOperation'">{'fileFd'  : fileFd}</call>
 
      <return> diffRC </return>
    </sequence>
  </function>
 
 
 
  <!-- ************************************************************ -->
  <function name="grep" scope="local">
    <function-prolog>
      This function compares grep a string in a file
    </function-prolog>
    <function-map-args>
      <function-arg-def name="location" type="optional" default="STAF_REMOTE_HOSTNAME">
        <function-arg-description>
          Location of target host
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="string2grep" type="required">
        <function-arg-description>
          string to grep
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="file" type="required">
        <function-arg-description>
          File where grep will be done
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="expect2Find" type="optional" default="TRUE">
        <function-arg-description>
          if true, return SUCCESS if string2find is in the file
          if false, return SUCCESS if string2find is NOT in the file
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="caseSensitive" type="optional" default="TRUE">
        <function-arg-description>
          if true, grep with case sensitive mode
          if false, grep with case insensitive mode
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="fileFd" type="required">
        <function-arg-description>
          Name of output file descriptor
        </function-arg-description>
      </function-arg-def>
    </function-map-args>
    <sequence>
      <!-- ========== -->
      <call function="'writeStartTagOperation'">
      { 'tagName' : 'grep',
        'fileFd'  : fileFd }
      </call>
      <if expr="expect2Find == TRUE">
        <call function="'writeMessage'">
        { 'fileFd'  : fileFd,
          'content' : "Check '%s' is in %s" % (string2grep,file)
        }
        </call>
      <else>
        <call function="'writeMessage'">
        { 'fileFd'  : fileFd,
          'content' : "Check '%s' is NOT in %s" % (string2grep,file)
        }
        </call>
      </else>
      </if>
      <!-- ========== -->
      <script>
        result = 'NOTHING'
        
        if (caseSensitive == TRUE):
          options = ''
        else:
          options = '-i'
      </script>
      <process name="'Grep'">
        <location>location</location>
        <command mode="'shell'">
          "grep %s '%s' %s" % (options,string2grep,file)
        </command>
        <envs>['PATH=/bin:/usr/bin']</envs>
        <stderr mode="'stdout'"/>
        <stdout/>
        <returnstdout/>
      </process>
      <script>
        grepRC=RC
        grepRC2=STAXResult[0][0]
        result=STAXResult[0][1]
      </script>
      
      <if expr="expect2Find == TRUE">
        <if expr="(result != 'NOTHING') and (grepRC == 0)">
          <call function="'checkRC'">
            { 'returncode' : 0,
              'result'     : '',
              'fileFd'     : fileFd }
          </call>
        <else>
          <call function="'checkRC'">
            { 'returncode' : grepRC,
              'result'     : result,
              'fileFd'     : fileFd }
          </call>
        </else>
        </if>
      
      <!-- == expect2Find == FALSE == -->
      <else>
        <if expr="(result == '') and (grepRC != 0)">
          <call function="'checkRC'">
            { 'returncode' : 0,
              'result'     : '',
              'fileFd'     : fileFd }
          </call>
        <else>
          <call function="'checkRC'">
            { 'returncode' : grepRC,
              'expected'   : [1],
              'result'     : result,
              'fileFd'     : fileFd }
          </call>
        </else>
        </if>
        
      </else>
      </if>
      
      <!-- ========== -->
      <call function="'writeEndTagOperation'">{'fileFd'  : fileFd}</call>
    </sequence>
  </function>
 
 
 
  <!-- ************************************************************ -->
  <function name="getOSvariables" scope="local">
    <function-prolog>
      Get OS related variables
    </function-prolog>
    <function-map-args>
      <function-arg-def name="hostname" type="required">
        <function-arg-description>
          Name of host on which to retrieve variables
        </function-arg-description>
        <function-arg-property name="type" value="hostname"/>
      </function-arg-def>
    </function-map-args>
    <sequence>
      <stafcmd name="'STAF Command: Get OS Name'">
        <location>'%s' % hostname</location>
        <service>'var'</service>
        <request>
          'get system var STAF/Config/OS/Name'
        </request>
      </stafcmd>
      <return>STAFResult</return>
    </sequence>
  </function>
 
 
  <!-- ************************************************************ -->
  <function name="getOSDate" scope="local">
    <function-prolog>
        This function returns the date (MONTH/DAY/YEARS-HOURS/MIN) of the OS
    </function-prolog>
    
    <function-map-args>
      <function-arg-def name="location" type="optional"
                        default="'%s' % STAXServiceMachine">
        <function-arg-description>
          Location of target host
        </function-arg-description>
      </function-arg-def>
    </function-map-args>
    <sequence>
      <call function="'getOSvariables'">
        { 'hostname' : location }
      </call>
      <script>
        import re
        winPattern=re.compile('win', re.IGNORECASE)
        isWindows=winPattern.search(STAXResult)
      </script>
      <!-- OS is windows -->
      <if expr="isWindows">
        <sequence>
          <process name="'get date on %s' % location">
            <location>location</location>
            <command mode="'shell'">'date /T'</command>
            <workdir>'/'</workdir>
            <stderr mode="'stdout'"/>
            <returnstdout/>
          </process>
          <script>
            date = STAFResult
            date = date[date.find(' ')+1:len(date)].strip()
          </script>
          <process name="'get time on %s' % location">
            <location>location</location>
            <command mode="'shell'">'time /T'</command>
            <workdir>'/'</workdir>
            <stderr mode="'stdout'"/>
            <returnstdout/>
          </process>
          <script>
            time = STAFResult
            #time = time[0:time.find(' ')].strip()
            date = '%s-%s' % (date,time)
          </script>
        </sequence>
      
      <!-- OS is UNIX based -->
      <else>
        <sequence>
          <process name="'get date on %s' % location">
            <location>location</location>
            <command mode="'shell'">'date'</command>
            <parms>"'+%m/%d/%Y-%H:%M:%S'"</parms>
            <workdir>'/'</workdir>
            <envs>['PATH=/bin:/usr/bin']</envs>
            <stderr mode="'stdout'"/>
            <returnstdout/>
          </process>
          <script>
            date = STAXResult[0][1].split('\n')
          </script>
        </sequence>
      </else>
      </if>
      <return>date</return>
    </sequence>
  </function>
  
  
  <function name="runCommand" scope="local">
    <function-description>
      A general wrapper to run a command without having to write a dedicated 
      function for it
    </function-description>
    <function-map-args>
      <function-arg-def name="command" type="required">
        <function-arg-description>
          the command to run
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="path" type="required">
        <function-arg-description>
          the path where the command is to be run from
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="arguments" type="optional" default="''">
        <function-arg-description>
          the path where the command is to be found
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="env" 
                        type="optional">
        <function-arg-description>
          the environment variables to set. The default set here should just
          work for OpenDS commands
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="location" 
                        type="optional" 
                        default="STAXServiceMachine">
        <function-arg-description>
          Which machine should the command be executed on
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="name" 
                        default="'Running %s' % command" 
                        type="optional">
        <function-arg-description>
          The name to give the process (only matters in the STAX Monitor really)
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="stripOutput" default="'true'" type="optional">
        <function-arg-description>
          A boolean (use True or False here, case matters) to enable disable
          stripping the output of a command
          TODO: consider allowing passing a function name to enable custom
                output manipulation (overkill?)
        </function-arg-description>
        <function-arg-property name="type" value="enum">
          <function-arg-property-description>
            This argument can only have boolean values
          </function-arg-property-description>
          <function-arg-property-data type="choice" value="'true'"/>
          <function-arg-property-data type="choice" value="'false'"/>
        </function-arg-property>
      </function-arg-def>
      <function-arg-def name="timerDuration" 
                        type="optional" 
                        default="'5m'">
        <function-arg-description>
          The duration that the process is allowed to run
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="outputFile" type="optional" default="'None'">
        <function-arg-description>
          Output file containing the command output
        </function-arg-description>
        <function-arg-property name="type" value="file"/>
      </function-arg-def>
      <function-arg-def name="outputPath" 
                        type="optional" 
                        default="LOG_TMP_DIR">
        <function-arg-description>
          Path containing the outputFile
        </function-arg-description>
        <function-arg-property name="type" value="filepath"/>
      </function-arg-def>  
      <function-arg-def name="expectedRC" type="optional" default="0">
        <function-arg-description>
          Expected return code value. Default value is 0.
          Wildcard 'noCheck' to not check the RC
        </function-arg-description>
      </function-arg-def>
      <function-arg-def name="logStderr" type="optional" default="'true'">
        <function-arg-description>
          If true, stderr for the command is redirect to stdout.
        </function-arg-description>
        <function-arg-property name="type" value="enum">
          <function-arg-property-description>
            This argument can only have boolean values
          </function-arg-property-description>
          <function-arg-property-data type="choice" value="'true'"/>
          <function-arg-property-data type="choice" value="'false'"/>
        </function-arg-property>
      </function-arg-def>
      <function-arg-def name="fileFd" type="required">
        <function-arg-description>
          output file descriptor
        </function-arg-description>
      </function-arg-def>
    </function-map-args>
    <sequence>
      <script>
        import random
        import java.util.Date
        random.seed(java.util.Date().getTime())
        _id = '%s#%d' % (strftime('%Y-%m-%d %H:%M:%S',localtime()),random.randint(0,999))
        
        if not env:
          #if isWindows:
          #  env=['PATH=C:\Windows;C:\Windows\system32;%s' % path, 'JAVA_HOME=%s' % JAVA_HOME]
          #else:
            env=['PATH=/bin:/usr/bin:%s' % path, 'JAVA_HOME=%s' % JAVA_HOME]
      </script>
      <call function="'writeStartTagOperation'">
      { 'tagName' : name,
        'fileFd'  : fileFd }
      </call>
      
      <!-- check if command exists -->
      <call function="'isFile'">
      {
        'location' : location,
        'fileName' : command
      }
      </call>
      <script>
        STAFCmdExist = STAXResult
      </script>
      <if expr="STAFCmdExist == TRUE">
        <sequence>
          <call function="'writeMessage'">
            { 'content'  : 'Running cmd: %s' % command,
              'fileFd'   : fileFd }
          </call>
          
          <!-- If 'logStderr' is True then redirect sdterr to sdtout -->
          <if expr="logStderr == 'true'">
            <process name="name">
              <location>location</location>
              <command>command</command>
              <parms>arguments</parms>
              <workdir>path</workdir>
              <envs>env</envs>
              <console use="'same'"/>
              <stdout if="outputFile != 'None'" mode="'replace'">
                '%s/%s' % (outputPath, outputFile)
              </stdout>
              <stderr mode="'stdout'"/>
              <returnstdout/>
            </process>
            <else>
              <process name="name">
                <location>location</location>
                <command>command</command>
                <parms>arguments</parms>
                <workdir>path</workdir>
                <envs>env</envs>
                <console use="'same'"/>
                <stdout if="outputFile != 'None'" mode="'replace'">
                  '%s/%s' % (outputPath, outputFile)
                </stdout>
                <returnstdout/>
              </process>
            </else>
          </if>
          
          <!-- The problem here is that STAXResult can either be a
               string, list or a map object -->
          <script>
            try:
              cmdOutput=STAXResult[0][1]
              cmdRC = RC
            except:
              cmdOutput=STAXResult
              cmdRC = RC
              
            cmdResult=STAXResult
          </script>
          
          <if expr="expectedRC != 'noCheck'">
            <call function="'checkRC'">
              { 'returncode' : cmdRC,
                'result'     : cmdOutput,
                'expected'   : [expectedRC],
                'fileFd'     : fileFd
              }
            </call>
          </if>
          <!--
          <script>
            def dig(var):
              try:
                if var.__class__==[].__class__:
                  for i in range(len(var)):
                    var[i]=dig(var[i])
                  return var
                else:
                  if var.__class__==''.__class__:
                    return re.compile(r'EMMA:.*\n').sub('',var)
                  else:
                    return var
              except TypeError:
                return 'could not evaluate the following component: %s' % var
            
            if stripOutput == 'true':
              cmdResult=dig(cmdResult)
          </script>
          -->
        </sequence>
      <else>
        <sequence>
          <call function="'writeMessage'">
          { 
            'content' : 'ERROR : file does not exist on %s : %s'\
                        % (location,command),
            'fileFd'  : fileFd
          }
          </call>
          <script>
            ERR_NUM[0] += 1
          </script>
        </sequence>
      </else>
      </if>
      <call function="'writeEndTagOperation'">{'fileFd' : fileFd}</call>
      <return>
        cmdResult
      </return>
    </sequence>
  </function>
  
  
  
  
  
  
</stax>