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

dugan
11.57.2008 1b00a59effd69fa2f9c8ec326fd5aea17dc0831d
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
<?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="parser" scope="local">
  
    <function-list-args>
      <function-required-arg name="configurationFile">
        Name of file containing XML to be parsed
      </function-required-arg>
    </function-list-args>
    
    <sequence>
      
      <!--=================================================================-->
      <!--==========  Load XML file  =========-->
      <message log="1"> 
        'configuration file is : %s' % configurationFile
      </message>
      <call function="'parseXML'">configurationFile</call>
      
      <!--=================================================================-->
      <!--==========  Parse xml  =========-->
      <script>
        instances = []
        suffix = []
        scheduler = []
        
        sys.path.append("%s/phases/parser" % TESTS_DIR )
        from parser import *
        parserResult  = main(STAXResult)
        msg           = parserResult[0]
        instances     = parserResult[1]
        suffix        = parserResult[2]
        scheduler     = parserResult[3]
        scenario      = parserResult[4]
        externalTools = parserResult[5]
        if (parserResult[6] != NOT_DEFINED):
          DOMAIN[0]  = '.%s' % parserResult[6]
      </script>
      
      <!--=================================================================-->
      <!--========  Set some attributes to add in instance objects   ======-->
      <paralleliterate in="instances" var="instance">
        <sequence>
          <call function="'pingStaf'">
            { 'targetHost' : instance.getHost(),
              'fileFd'     : NO_FILE}
          </call>
          <call function="'getOSvariables'">
            { 'hostname' : instance.getHost() }
          </call>
          <script>
            # Set OS
            OSName = STAXResult
            instance.setOs(OSName)
            
            # Set bin directory
            OSName = OSName.lower()
            if ( OSName.count('win') == 0 ):
              binDir = '%s/bin' % instance.getInstallDir()
            else:
              binDir = '%s/bat' % instance.getInstallDir()
            instance.setBinDir(binDir)
            
            # Set synchro date
            #import java.util.Date
            #date = '%s' % (strftime('%Y-%m-%d %H:%M:%S',localtime()))
            #instance.setSynchroDate(date)
          </script>
          <call function="'getOSDate'">
            { 'location' : instance.getHost() }
          </call>
          <script>
            instance.setSynchroDate(STAXResult[0])
          </script>
          <!-- Set log dir for each instance -->
          <script>
            instance.setLogDir('%s/%s' % (LOG_DIR,instance.getName()))
          </script>
          <!-- Set javaArgs tuning property -->
          <script>
            
            tuning = instance.getTuning()
            if tuning.getIsJava() == 'true':
              if tuning.getXms() != NOT_DEFINED:
                c1 = '-Xms%s' % tuning.getXms()
                
              if tuning.getXmx() != NOT_DEFINED:
                c2 = '-Xmx%s' % tuning.getXmx()
                
              if tuning.getXxNewSize() != NOT_DEFINED:
                c3 = '-XX&#58;NewSize=%s' % tuning.getXxNewSize()
                
              if tuning.getXxMaxNewSize() != NOT_DEFINED:
                c4 = '-XX&#58;MaxNewSize=%s' % tuning.getXxMaxNewSize()
                
              if tuning.getXxSurvivorRatio() != NOT_DEFINED:
                c5 = '-XX&#58;SurvivorRatio=%s' % tuning.getXxSurvivorRatio()
                
              if tuning.getXxPermSize() != NOT_DEFINED:
                c6 = '-XX&#58;PermSize=%s' % tuning.getXxPermSize()
                
              if tuning.getXxMaxPermSize() != NOT_DEFINED:
                c7 = '-XX&#58;MaxPermSize=%s' % tuning.getXxMaxPermSize()
                
              if tuning.getXxUseConcMarkSweepGC() == 'true':
                c8 = '-XX&#58;+UseConcMarkSweepGC'
              
              tuning.setJavaArgs('%s %s %s %s %s %s %s %s' % \
                                (c1,c2,c3,c4,c5,c6,c7,c8))
          </script>
          <!-- Check jdmk dependcy if snmp is enabled -->
          <if expr="instance.getSNMPPort() != NOT_DEFINED 
                    and externalTools.getJdmkrtPath() == NOT_DEFINED">
            <sequence>
              <message>
                'ERROR, jdmkrt path not defined, needed for instance %s' % \
                 instance.getName()
               </message>
               <script>ERR_NUM[0] += 1</script>
             </sequence>
           </if>
        </sequence>
      </paralleliterate>
      
      
      <!--========  Set/Check some attributes for client objects   ======-->
      <!--== Get the enabled clients list from all modules ==-->
      <call function="'getEnabledClients'">{'scheduler':scheduler}</call>
      <script>clients = STAXResult </script>
      <if expr="len(clients) > 0">
        <paralleliterate in="clients" var="client">
          <sequence>
            <!-- Check staf is alive on client host -->
            <call function="'pingStaf'">
              { 'targetHost' : client.getHost(),
                'fileFd'     : NO_FILE}
            </call>
            <!-- Set logDir for each client object -->
            <script>
              client.setLogDir('%s/client_%s_id%s' % \
              (LOG_DIR,client.getName(),client.getId()))
            </script>
            <!-- If monitoring client is enable, check dependencies -->
            <script>
              merr = ''
              if client.getName() == 'monitoring':
                if externalTools.getJdmkrtPath() == NOT_DEFINED:
                  merr = '%s\nERROR, jdmkrt path not defined,' % merr
                  merr = '%s needed for monitoring client' % merr
                  ERR_NUM[0] += 1
                if externalTools.getJcommonPath() == NOT_DEFINED:
                  merr = '%s\nERROR, jcommon path not defined,' % merr
                  merr = '%s needed for monitoring client' % merr
                  ERR_NUM[0] += 1
                if externalTools.getJfreechartPath() == NOT_DEFINED:
                  merr = '%s\nERROR, jfreechart path not defined,' % merr
                  merr = '%s needed for monitoring client' % merr
                  ERR_NUM[0] += 1
            </script>
            <if expr="merr != ''">
              <message>merr</message>
            </if>
          </sequence>
        </paralleliterate>
      <else>
        <script>
          msg = '%s\nWARNING : client list is empty,' % msg
          msg = '%s check clients are defined and modules are enabled\n' % msg
        </script>
      </else>
      </if>
      
      
      <!--=================================================================-->
      <!--========  Basic checks for extTools object                 ======-->
      
      <!-- check jdmk jar file exists -->
      <if expr="externalTools.getJdmkrtPath() != NOT_DEFINED">
        <sequence>
          <call function="'isFile'">
          {
            'location' : STAXServiceMachine,
            'fileName' : externalTools.getJdmkrtPath()
          }
          </call>
          <script>
            fileExist = STAXResult
          </script>
          <if expr="fileExist == FALSE">
            <script>
              msg = '%s\nERROR : canf find file %s' % \
                    (msg,externalTools.getJdmkrtPath())
            </script>
          </if>
        </sequence>
      </if>
      <!-- check jcommon jar file exists -->
      <if expr="externalTools.getJcommonPath() != NOT_DEFINED">
        <sequence>
          <call function="'isFile'">
          {
            'location' : STAXServiceMachine,
            'fileName' : externalTools.getJcommonPath()
          }
          </call>
          <script>
            fileExist = STAXResult
          </script>
          <if expr="fileExist == FALSE">
            <script>
              msg = '%s\nERROR : canf find file %s' % \
                    (msg,externalTools.getJcommonPath())
            </script>
          </if>
        </sequence>
      </if>
      <!-- check jfreechart jar file exists -->
      <if expr="externalTools.getJfreechartPath() != NOT_DEFINED">
        <sequence>
          <call function="'isFile'">
          {
            'location' : STAXServiceMachine,
            'fileName' : externalTools.getJfreechartPath()
          }
          </call>
          <script>
            fileExist = STAXResult
          </script>
          <if expr="fileExist == FALSE">
            <script>
              msg = '%s\nERROR : canf find file %s' % \
                    (msg,externalTools.getJfreechartPath())
            </script>
          </if>
        </sequence>
      </if>
      
      
      
      
      
      <!--=================================================================-->
      <!--========  Basic configuration checks                       ======-->
      
      <!-- replace localhost by real host name -->
      <script>
        # for instances
        for instance in instances:
          if (instance.getHost() == 'localhost'):
            instance.setHost(STAXServiceMachine.split('.')[0])
        
        # for clients
        for m in scheduler:
          for c in m.getClients():
            if (c.getHost() == 'localhost'):
              c.setHost(STAXServiceMachine.split('.')[0])
        
      </script>
      
      <!-- ports should not be the same           -->
      <!-- if several instances on the same host  -->
      <script>
        for instance in instances:
          product = instance.getProduct()
          if product == 'opends':
            name1      = instance.getName()
            host1      = instance.getHost()
            portLdap1  = instance.getLDAPPort()
            portLdaps1 = instance.getLDAPSPort()
            portJmx1   = instance.getJMXPort()
            
            if host1 == NOT_DEFINED:
              msg = '%s\nERROR : instance %s has host %s'%\
                    (msg,name1,host1)
            
            for instance2 in instances:
              name2      = instance2.getName()
              product2   = instance2.getProduct()
              host2      = instance2.getHost()
              portLdap2  = instance2.getLDAPPort()
              portLdaps2 = instance2.getLDAPSPort()
              portJmx2   = instance2.getJMXPort()
              
              if (name2 != name1 and product2 == 'opends' and
                  host1 == host2 and portLdap1 == portLdap2):
                msg = '%s\nWARNING : same LDAP port for %s and %s on %s'%\
                      (msg,name1,name2,host1)
              
              if (name2 != name1 and product2 == 'opends' and
                  host1 == host2 and portLdaps1 == portLdaps2):
                msg = '%s\nWARNING : same LDAPS port for %s and %s on %s'%\
                       (msg,name1,name2,host1)
              
              if (name2 != name1 and product2 == 'opends' and
                  host1 == host2 and portJmx1 == portJmx2):
                msg = '%s\nWARNING : same JMX port for %s and %s on %s' % \
                       (msg,name1,name2,host1)
          # end if product = 'opends'
      </script>
      
      <!-- client id should be unique -->
      <script>
        clients = []
        for m in scheduler:
          if (m.getEnabled() == "true"):
            clients.extend(m.getClients())
        
        nbClients = len(clients)
        i = 0
        while i &lt; nbClients:
          client1 = clients.pop()
          
          if client1.getHost() == NOT_DEFINED:
              msg = '%s\nWARNING : client %s has unknown host, taking %s'%\
                    (msg,client1.getName(),STAXServiceMachine)
              client1.setHost('STAXServiceMachine')
          
          for client2 in clients:
            if client1.getId() == client2.getId():
              msg = '%s\ERROR: clients %s and %s have same id %s, must NOT!'%\
                     (msg,client1.getName(),client2.getName(),client1.getId())
          i += 1
      </script>
      
      <!-- check instances have "synchronized" date -->
      <script>
        myInstances = []
        for instance in instances:
          myInstances.append(instance)
        
        for instance in instances:
          sDate1 = instance.getSynchroDate()
          day1 = sDate1[0:sDate1.find('-')-1].strip()
          time1 = sDate1[sDate1.find('-')+1:len(sDate1)].strip()
          hour1 = time1[0:time1.find(':')-1].strip()
          minute1 = time1[time1.find(':')+1:len(time1)].strip()
          myInstances.remove(instance)
          
          for instance2 in myInstances:
            sDate2 = instance2.getSynchroDate()
            day2 = sDate2[0:sDate2.find('-')-1].strip()
            time2 = sDate2[sDate2.find('-')+1:len(sDate2)].strip()
            hour2 = time1[0:time2.find(':')-1].strip()
            minute2 = time2[time2.find(':')+1:len(time2)].strip()
            
            if day1 != day2:
              msg = '%s\nERROR %s (%s) and %s (%s) day dates are not synchronised' % \
                    (msg,instance.getName(),day1,instance2.getName(),day2)
            if hour1 != hour2:
              msg = '%s\nERROR %s (%s) and %s (%s) hours are not synchronised' % \
                    (msg,instance.getName(),hour1,instance2.getName(),hour2)
            if minute1 != minute2:
              msg = '%s\nWARNING %s (%s) and %s (%s) minutes are not synchronised' % \
                    (msg,instance.getName(),minute1,instance2.getName(),minute2)
      </script>
      
      
      <!--==========  Display output parsing  =========-->
      <if expr="msg.find('TRACE') != -1">
        <!-- If trace found during parsing, display message -->
         <message log="1">'TRACE found : \"%s\"' % msg</message>
      </if>
      
      <if expr="msg.find('WARNING') != -1">
        <!-- If warning found during parsing, display message -->
        <message log="1">'WARNING found : \"%s\"' % msg</message>
      </if>
      
      <if expr="msg.find('ERROR') != -1">
        <!-- If errors found during parsing, exit -->
        <sequence>
           <script>ERR_NUM[0] += 1</script>
           <message log="1">'EXIT as error(s) found : \"%s\"' % msg</message>
           <return>msg</return>
         </sequence>
      </if>
      <return>
        parserResult
      </return>
    </sequence>
  </function>
 
 
  <!-- ******************************************************************* -->
  <!-- Following function is used to parse an XML file and return the DOM  -->
  <!-- document object                                                     -->
  <!-- ******************************************************************* -->
  <function name="parseXML" scope="local">
  
    <function-list-args>
      <function-required-arg name="xmlFileName">
        Name of file containing XML to be parsed
      </function-required-arg>
    </function-list-args>
    
    <sequence>
      
      <!-- Parse the XML -->
      <script>
        from java.io import File
        from java.io import StringReader
        from org.xml.sax import InputSource
        from org.xml.sax import SAXParseException
        from org.xml.sax.helpers import DefaultHandler
        from javax.xml.parsers import DocumentBuilderFactory
        from javax.xml.parsers import DocumentBuilder
        from org.w3c.dom import Document
        from org.w3c.dom import Element
        from org.w3c.dom import Node
        from org.w3c.dom import NodeList
        
        dtdFileName = '../../stax.dtd'  
        
        #********************************************** #
        # private Python classes                        #
        
        # This class handles XML Parsing exceptions
        class ParserException(Exception):
            pass
        
        # This class handles the exception raised by XML parser
        class ParserResolver(DefaultHandler):
            def resolveEntity (self, publicId, systemId):
                return InputSource(dtdFileName)
            def error (self, e):
                raise 'error', e
            def warning (self, e):
                raise 'warning', e
            def fatalError (self, e):
                raise 'fatal', e
        
        factory = DocumentBuilderFactory.newInstance()
        factory.setValidating(1)
        factory.setIgnoringElementContentWhitespace(0)
        
        try:
          parseError    = 0
          builder  = factory.newDocumentBuilder()
          document = builder.parse(xmlFileName)
        except SAXParseException, spe:
          parseError = 1
      </script>
      
      <!-- Quit if there is any parsing error -->
      <if expr="parseError">
        <sequence>
          <script>
            errmsg = 'Error occurred parsing file %s\n line: %s\n msg: %s' % \
                      (xmlFileName, spe.getLineNumber(), spe.getMessage())
          </script>
          <log>errmsg</log>
          <message log="1">errmsg</message>
          <terminate/>
        </sequence>
      </if>
      
      <return>document</return>
      
    </sequence>
  </function>
</stax>