Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
814 mhunt 1
package com.erggroup.buildtool.ripple;
2
 
3
import java.sql.CallableStatement;
4
import java.sql.Connection;
5
 
6
import java.sql.DriverManager;
7
 
8
import java.sql.PreparedStatement;
9
import java.sql.ResultSet;
10
import java.sql.SQLException;
11
 
12
import java.sql.Timestamp;
13
 
14
import java.sql.Types;
15
 
16
import java.util.Calendar;
17
import java.util.Date;
18
import java.util.GregorianCalendar;
19
import java.util.Iterator;
20
import java.util.ListIterator;
21
import java.util.Vector;
850 mhunt 22
import java.util.concurrent.locks.ReentrantLock;
814 mhunt 23
 
850 mhunt 24
import oracle.jdbc.OracleDriver;
814 mhunt 25
 
26
import org.apache.log4j.Logger;
27
 
28
/**Release Manager schema abstraction
29
 */
30
public class ReleaseManager
31
{
32
  /**Unit test hook.
33
   * Prevents Oracle interaction when false.
34
   * @attribute
35
   */
36
  public static boolean mUseDatabase = true;
37
 
38
  /**Unit test hook
39
   * Container of persisted run levels for unit test usage
40
   * Must be managed by the unit test code
41
   * @attribute
42
   */
43
  public static Vector mPersistedRunLevelCollection = new Vector();
44
 
45
  /**database represented enumerated value
46
   * @attribute
47
   */
48
  public static final int DB_CANNOT_CONTINUE = 1;
49
 
50
  /**database represented enumerated value
51
   * @attribute
52
   */
53
  public static final int DB_PAUSED = 2;
54
 
55
  /**database represented enumerated value
56
   * @attribute
57
   */
58
  public static final int DB_ACTIVE = 3;
59
 
60
  /**database represented enumerated value
61
   * @attribute
62
   */
63
  public static final int DB_IDLE = 4;
64
 
65
  /**database represented enumerated value
66
   * @attribute
67
   */
68
  public static final int DB_WAITING = 5;
69
 
70
  /**package object of no consequence
71
   * @attribute
72
   */
73
  static final Package NULL_PACKAGE = new Package();
74
 
75
  /**registered status
76
   * @attribute
77
   */
78
  static boolean mRegistered = false;
79
 
80
  /**Logger
81
   * @attribute
82
   */
83
  private static final Logger mLogger = Logger.getLogger(ReleaseManager.class);
84
 
85
  /**database session handle
86
   * @attribute
87
   */
850 mhunt 88
  private static Connection mConnection = null;
814 mhunt 89
 
850 mhunt 90
  /**database session handle
91
   * @attribute
92
   */
93
  private static final ReentrantLock mSession = new ReentrantLock();
94
 
814 mhunt 95
  /**index to current ReleaseConfig item
96
   * @attribute
97
   */
98
  private int mReleaseConfigIndex = -1;
99
 
100
  /**index to current RunLevel item
101
   * @attribute
102
   */
103
  private int mRunLevelIndex = -1;
104
 
105
  /**collection of ReleaseConfig objects
106
   * @attribute
107
   */
108
  private Vector mReleaseConfigCollection = new Vector();
109
 
110
  /**database connection string
111
   * @attribute
112
   */
113
  private static String mConnectionString = new String();
114
 
115
  /**database username
116
   * @attribute
117
   */
118
  private static String mUsername = new String();
119
 
120
  /**database password
121
   * @attribute
122
   */
123
  private static String mPassword = new String();
124
 
125
  /**collection of RunLevel objects
126
   * @attribute
127
   */
128
  private Vector mRunLevelCollection = new Vector();
129
 
130
  /**in daemon mode
131
   *   select gm.gbe_value from release_config rc, gbe_machtype gm
132
   *   where rc.rtag_id=<baseline> and gm.gbe_id=rc.gbe_id;
133
   * in escrow mode
134
   *   select gm.gbe_value from boms b, release_manager.release_config rc,
135
   *   release_manager.gbe_machtype gm
136
   *   where b.bom_id=<baseline> and rc.rtag_id=b.rtag_id_fk and gm.gbe_id=rc.gbe_id;
137
   * populates the machtypeCollection with the resultset
138
   */
139
  void queryMachtypes(Vector machtypeCollection, boolean daemonMode, int baseline) throws SQLException, Exception
140
  {
141
    mLogger.debug("queryMachtypes " + daemonMode);
142
    if ( !mUseDatabase )
143
    {
144
      mLogger.info("queryMachtypes !mUseDatabase");
145
      // a highly unlikely set of machtypes
146
      String machtype = new String("linux_i386");
147
      machtypeCollection.add(machtype);
148
      machtype = new String("sparc");
149
      machtypeCollection.add(machtype);
150
      machtype = new String("solaris10_x86");
151
      machtypeCollection.add(machtype);
152
    }
153
    else
154
    {
155
      String sql = new String("");
156
 
157
      if ( daemonMode )
158
      {
159
        sql = "select gm.gbe_value from release_manager.release_config rc, release_manager.gbe_machtype gm where rc.rtag_id=" + baseline + " and gm.gbe_id=rc.gbe_id";
160
      }
161
      else
162
      {
163
        sql = 
164
        "select gm.gbe_value from boms b, release_manager.release_config rc, release_manager.gbe_machtype gm where b.bom_id=" + 
165
        baseline + " and rc.rtag_id=b.rtag_id_fk and gm.gbe_id=rc.gbe_id";
166
      }
167
 
168
      try
169
      {
170
        CallableStatement stmt = mConnection.prepareCall(sql);
171
        ResultSet rset = stmt.executeQuery();
172
 
173
        while( rset.next() )
174
        {
175
          String machtype = rset.getString("gbe_value");
176
 
177
          if ( machtype != null )
178
          {
179
            machtypeCollection.add(machtype);
180
          }
181
        }
830 mhunt 182
 
183
        rset.close();
184
        stmt.close();
814 mhunt 185
      }
186
      catch ( SQLException e )
187
      {
188
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
189
        {
190
          mLogger.error("queryMachtypes database access error only");
191
          throw new SQLException();
192
        }
193
        else
194
        {
195
          mLogger.fatal("queryMachtypes show stopper");
196
          throw new Exception();
197
        }
198
      }
199
    }
200
  }
201
 
202
  /**in daemon mode
203
   *   select p.proj_name, rt.rtag_name from projects p, release_tags rt
204
   *   where rt.rtag_id=<baseline> and p.proj_id=rt.proj_id;
205
   * returns a concatenation of the proj_name and rtag_name
206
   * in escrow mode
207
   *   select dp.proj_name, br.branch_name, b.bom_version, b.bom_lifecycle
208
   *   from dm_projects dp, branches br, boms b
209
   *   where b.bom_id=<baseline> and br.branch_id=b.branch_id and dp.proj_id=br.proj_id;
210
   * returns a concatenation of the proj_name, branch_name, bom_version and bom_lifecycle
211
   */
212
  String queryBaselineName(boolean daemonMode, int baseline) throws SQLException, Exception
213
  {
214
    mLogger.debug("queryBaselineName " + daemonMode);
215
    String retVal = new String();
216
 
217
    if ( !mUseDatabase )
218
    {
219
      mLogger.info("queryBaselineName !mUseDatabase");
220
      // a highly unlikely baseline name
221
      if (daemonMode)
222
      {
223
        retVal = "TIMBUKTU (TIM) > R7";
224
      }
225
      else
226
      {
227
        retVal = "TIMBUKTU (TIM) > R7 7.9";
228
      }
229
    }
230
    else
231
    {
232
      String sql = new String("");
233
 
234
      if ( daemonMode )
235
      {
236
        sql = "select p.proj_name, rt.rtag_name from release_manager.projects p, release_manager.release_tags rt where rt.rtag_id=" + baseline + " and p.proj_id=rt.proj_id";
237
      }
238
      else
239
      {
240
        sql = 
241
        "select dp.proj_name, br.branch_name, b.bom_version, b.bom_lifecycle from dm_projects dp, branches br, boms b where b.bom_id=" + 
242
        baseline + " and br.branch_id=b.branch_id and dp.proj_id=br.proj_id";
243
      }
244
 
245
      try
246
      {
247
        CallableStatement stmt = mConnection.prepareCall(sql);
248
        ResultSet rset = stmt.executeQuery();
249
 
250
        while( rset.next() )
251
        {
252
          String proj_name = rset.getString("proj_name");
253
 
254
          if ( proj_name != null )
255
          {
256
            retVal += proj_name;
257
          }
258
 
259
          if ( daemonMode )
260
          {
261
            String rtag_name = rset.getString("rtag_name");
262
 
263
            if ( rtag_name != null )
264
            {
265
              retVal += " > " + rtag_name;
266
            }
267
          }
268
          else
269
          {
270
            String branch_name = rset.getString("branch_name");
271
 
272
            if ( branch_name != null )
273
            {
274
              retVal += " > " + branch_name;
275
            }
276
 
277
            String bom_version = rset.getString("bom_version");
278
 
279
            if ( bom_version != null )
280
            {
281
              retVal += " " + bom_version;
282
            }
283
 
284
            String bom_lifecycle = rset.getString("bom_lifecycle");
285
 
286
            if ( bom_lifecycle != null )
287
            {
288
              retVal += "." + bom_lifecycle;
289
            }
290
          }
291
        }
830 mhunt 292
 
293
        rset.close();
294
        stmt.close();
814 mhunt 295
      }
296
      catch ( SQLException e )
297
      {
298
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
299
        {
300
          mLogger.error("queryBaselineName database access error only");
301
          throw new SQLException();
302
        }
303
        else
304
        {
305
          mLogger.fatal("queryBaselineName show stopper");
306
          throw new Exception();
307
        }
308
      }
309
    }
310
    mLogger.info("queryBaselineName returned " + retVal);
311
    return retVal;
312
  }
313
 
314
  /**in daemon mode
315
   *  1 get planned package info
316
   *     select pl.pv_id, p.pkg_id, p.pkg_name, pv.v_ext, pv.pkg_label, pv.src_path, pv.change_type
317
   *     from planned pl, package_versions pv, packages p
318
   *     where pl.rtag_id=<mBaseline> and pv.build_type='A' and pv.dlocked='A'
319
   *     and pv.pv_id=pl.pv_id and p.pkg_id=pv.pkg_id
320
   *     order by pl.pv_id;
321
   *  2 get planned package dependency info
322
   *     select pl.pv_id, p.pkg_name, dpv.v_ext
323
   *     from planned pl, package_versions pv, package_dependencies pd, package_versions dpv, packages p
324
   *     where pl.rtag_id=<mBaseline> and pv.build_type='A' and pv.dlocked='A'
325
   *     and pv.pv_id = pl.pv_id and pd.pv_id=pl.pv_id and dpv.pv_id=pd.dpv_id and p.pkg_id=dpv.pkg_id
326
   *     order by pl.pv_id;
327
   *  3 get planned package build info
328
   *     select pl.pv_id, bm.bm_name, bsa.bsa_name
329
   *     from planned pl, package_versions pv, package_build_info pbi, build_machines bm, build_standards_addendum bsa
330
   *     where pl.rtag_id=<mBaseline> and pv.build_type='A' and pv.dlocked='A'
331
   *     and pv.pv_id = pl.pv_id and pbi.pv_id=pv.pv_id and bm.bm_id=pbi.bm_id and bsa.bsa_id=pbi.bsa_id
332
   *     order by pl.pv_id;
333
   *  4 get planned package unit test info
334
   *     select pl.pv_id, tt.test_type_name
335
   *     from planned pl, package_versions pv, unit_tests ut, test_types tt
336
   *     where pl.rtag_id=<mBaseline> and pv.build_type='A' and pv.dlocked='A'
337
   *     and pv.pv_id = pl.pv_id and ut.pv_id=pv.pv_id and tt.test_type_id=ut.test_types_fk
338
   *     order by pl.pv_id;
339
   *  5 get planned package build failure info
340
   *     select pl.pv_id, u.user_email
341
   *     from planned pl, release_tags rt, package_versions pv, autobuild_failure af, members_group mg, users u
342
   *     where pl.rtag_id=<mBaseline> and rt.rtag_id=pl.rtag_id and pv.build_type='A' and pv.dlocked='A'
343
   *     and pv.pv_id = pl.pv_id and af.view_id=pl.view_id and mg.group_email_id=af.group_email_id and u.user_id=mg.user_id and af.proj_id=rt.proj_id
344
   *     order by pl.pv_id;
345
   *  6 get planned package do not ripple info
346
   *     select pl.pv_id
347
   *     from planned pl, package_versions pv, do_not_ripple dnr
348
   *     where pl.rtag_id=<mBaseline> and pv.build_type='A' and pv.dlocked='A'
349
   *     and pv.pv_id = pl.pv_id and dnr.rtag_id=pl.rtag_id and dnr.pv_id=pl.pv_id
350
   *     order by pl.pv_id;
351
   *  7 get planned package advisory ripple info
352
   *     select pl.pv_id
353
   *     from planned pl, package_versions pv, advisory_ripple ar
354
   *     where pl.rtag_id=<mBaseline> and pv.build_type='A' and pv.dlocked='A'
355
   *     and pv.pv_id = pl.pv_id and ar.rtag_id=pl.rtag_id and ar.pv_id=pl.pv_id
356
   *     order by pl.pv_id;
357
   *  8 get released package info
358
   *     select rc.pv_id, p.pkg_id, p.pkg_name, pv.pkg_version, pv.v_ext, pv.pkg_label, pv.src_path, pv.ripple_field
359
   *     from release_content rc, package_versions pv, packages p
360
   *     where rc.rtag_id=<mBaseline>
361
   *     and pv.pv_id = rc.pv_id and p.pkg_id = pv.pkg_id
362
   *     order by rc.pv_id;
363
   *  9 get released package dependency info
364
   *     select rc.pv_id, dpv.pv_id, p.pkg_name, dpv.v_ext
365
   *     from release_content rc, package_versions pv, package_dependencies pd, package_versions dpv, packages p
366
   *     where rc.rtag_id=<mBaseline>
367
   *     and pv.pv_id = rc.pv_id and pd.pv_id=pv.pv_id and dpv.pv_id=pd.dpv_id and p.pkg_id=dpv.pkg_id
368
   *     order by rc.pv_id;
369
   * 10 get released package build info
370
   *     select rc.pv_id, bm.bm_name, bsa.bsa_name
371
   *     from release_content rc, package_versions pv, package_build_info pbi, build_machines bm, build_standards_addendum bsa
372
   *     where rc.rtag_id=<mBaseline>
373
   *     and pv.pv_id = rc.pv_id and pbi.pv_id=pv.pv_id and bm.bm_id=pbi.bm_id and bsa.bsa_id=pbi.bsa_id
374
   *     order by rc.pv_id;
375
   * 11 get released package unit test info
376
   *     select rc.pv_id, tt.test_type_name
377
   *     from release_content rc, package_versions pv, unit_tests ut, test_types tt
378
   *     where rc.rtag_id=<mBaseline>
379
   *     and pv.pv_id = rc.pv_id and ut.pv_id=pv.pv_id and tt.test_type_id=ut.test_types_fk
380
   *     order by rc.pv_id;
381
   * 12 get released package build failure email info
382
   *     select rc.pv_id, u.user_email
383
   *     from release_content rc, release_tags rt, package_versions pv, autobuild_failure af, members_group mg, users u
384
   *     where rc.rtag_id=<mBaseline> and rt.rtag_id=rc.rtag_id
385
   *     and pv.pv_id = rc.pv_id and af.view_id=rc.base_view_id and mg.group_email_id=af.group_email_id and u.user_id=mg.user_id and af.proj_id=rt.proj_id
386
   *     order by rc.pv_id;
387
   * 13 get released package do not ripple info
388
   *     select rc.pv_id
389
   *     from release_content rc, package_versions pv, do_not_ripple dnr
390
   *     where rc.rtag_id=3741
391
   *     and pv.pv_id = rc.pv_id and dnr.rtag_id=rc.rtag_id and dnr.pv_id=rc.pv_id
392
   *     order by rc.pv_id;
393
   * 14 get released advisory ripple info
394
   *     select rc.pv_id
395
   *     from release_content rc, package_versions pv, advisory_ripple ar
396
   *     where rc.rtag_id=<mBaseline>
397
   *     and pv.pv_id = rc.pv_id and ar.rtag_id=rc.rtag_id and ar.pv_id=rc.pv_id
398
   *     order by rc.pv_id;
399
   * in escrow mode
400
   *  1 get released product info
401
   *     select oc.prod_id, p.pkg_name, pv.pkg_version, pv.v_ext, pv.pkg_label, pv.src_path
402
   *     from bom_contents bc, operating_systems os, os_contents oc, release_manager.package_versions pv, release_manager.packages p
403
   *     where bc.bom_id=<mBaseline> and os.node_id=bc.node_id and oc.os_id=os.os_id and pv.pv_id=oc.prod_id and p.pkg_id=pv.pkg_id
404
   *     order by oc.prod_id;
405
   *    this will generate a list of pv_ids associtaed with products
406
   *    many in the list will reference cots products outside the scope of a escrow build
407
   *  2 for each <pv_id>, call traverseDependencies( packageCollection, pv_id, false ) to traverse its set of dependencies
408
   *  3 for each Package, call queryBuildInfo to get released package build info
409
   *  
410
   * Supports
411
   *    test_type_name="Autobuild UTF"
412
   *    bm_name="Generic"|"Linux"|"Solaris"|"Win32"
413
   *    bsa_name="Debug"|"Production"|"Production and Debug"|"Java 1.4"|"Java 1.5"|"Java 1.6"
414
   */
415
  void queryPackageVersions(RippleEngine rippleEngine, 
416
                            Vector packageCollection, boolean daemonMode, int baseline) throws SQLException, Exception
417
  {
418
    mLogger.debug("queryPackageVersions " + daemonMode);
419
 
420
    if ( !mUseDatabase )
421
    {
422
      mLogger.info("queryPackageVersions !mUseDatabase");
423
 
424
      if (daemonMode)
425
      {
426
        /* a highly unlikely set of packages
427
         * planned info
428
         * pv_id pkg_id pkg_name                     v_ext pkg_label src_path                          change_type
429
         * 0     76     UncommonDependency           .tim  0.TIM.WIP \vob\UncommonDependency           P
430
         * 1     1011   DependencyMissingFromRelease .tim  1.TIM.WIP \vob\DependencyMissingFromRelease M
431
         * 2     34     CommonDependency             .tim  2.TIM.WIP \vob\CommonDependency             M
432
         * 3     908    SolarisCentricProduct        .tim  3.TIM.WIP \vob\SolarisCentricProduct        N
433
         * 4     6      GenericProduct               .tim  4.TIM.WIP \vob\GenericProduct               P
434
         * 5     11     Product                      .tim  5.TIM.WIP \vob\Product                      M
435
         * 6     113    UnfinishedProduct            .tim  6.TIM.WIP \vob\UnfinishedProduct            M
436
         */
437
         if ( mConnectionString.compareTo("iteration1") == 0 )
438
         {
439
           Package p = new Package(0, "UncommonDependency", ".tim", "UncommonDependency.tim", "0.TIM.WIP", "\\vob\\UncommonDependency", 'P');
440
           p.mPid = 76;
441
           p.mDirectlyPlanned = true;
442
           packageCollection.add(p);
443
         }
444
 
445
         Package p = new Package(1, "DependencyMissingFromRelease", ".tim", "DependencyMissingFromRelease.tim", "1.TIM.WIP", "\\vob\\DependencyMissingFromRelease", 'M');
446
         p.mPid = 1011;
447
         p.mDirectlyPlanned = true;
448
         packageCollection.add(p);
449
 
450
         if ( mConnectionString.compareTo("iteration1") == 0 || mConnectionString.compareTo("iteration2") == 0 )
451
         {
452
           p = new Package(2, "CommonDependency", ".tim", "CommonDependency.tim", "2.TIM.WIP", "\\vob\\CommonDependency", 'M');
453
           p.mPid = 34;
454
           p.mDirectlyPlanned = true;
455
           packageCollection.add(p);
456
         }
457
 
458
         if ( mConnectionString.compareTo("iteration1") == 0 
459
           || mConnectionString.compareTo("iteration2") == 0
460
           || mConnectionString.compareTo("iteration3") == 0 )
461
         {
462
           p = new Package(3, "SolarisCentricProduct", ".tim", "SolarisCentricProduct.tim", "3.TIM.WIP", "\\vob\\SolarisCentricProduct", 'N');
463
           p.mPid = 908;
464
           p.mDirectlyPlanned = true;
465
           packageCollection.add(p);
466
         }
467
 
468
         if ( mConnectionString.compareTo("iteration1") == 0 
469
           || mConnectionString.compareTo("iteration2") == 0
470
           || mConnectionString.compareTo("iteration3") == 0
471
           || mConnectionString.compareTo("iteration4") == 0 )
472
         {
473
           p = new Package(4, "GenericProduct", ".tim", "GenericProduct.tim", "4.TIM.WIP", "\\vob\\GenericProduct", 'P');
474
           p.mPid = 6;
475
           p.mDirectlyPlanned = true;
476
           packageCollection.add(p);
477
         }
478
 
479
         if ( mConnectionString.compareTo("iteration1") == 0 
480
           || mConnectionString.compareTo("iteration2") == 0
481
           || mConnectionString.compareTo("iteration3") == 0
482
           || mConnectionString.compareTo("iteration4") == 0
483
           || mConnectionString.compareTo("iteration5") == 0 )
484
         {
485
           p = new Package(5, "Product", ".tim", "Product.tim", "5.TIM.WIP", "\\vob\\Product", 'M');
486
           p.mPid = 11;
487
           p.mDirectlyPlanned = true;
488
           packageCollection.add(p);
489
         }
490
 
491
         p = new Package(6, "UnfinishedProduct", ".tim", "UnfinishedProduct.tim", "6.TIM.WIP", "\\vob\\UnfinishedProduct", 'M');
492
         p.mPid = 113;
493
         p.mDirectlyPlanned = true;
494
         packageCollection.add(p);
495
 
496
        /* planned dependencies
497
         * pv_id pkg_name                     v_ext
498
         * 1     NotInTheRelease              .cots
499
         * 2     CotsWithFunnyVersion         .cots
500
         * 2     UncommonDependency           .tim
501
         * 3     CommonDependency             .tim
502
         * 4     CommonDependency             .tim
503
         * 5     UncommonDependency           .tim
504
         */
505
         p = findPackage(1, packageCollection);
506
         p.mDependencyCollection.add("NotInTheRelease.cots");
507
         p.mDependencyIDCollection.add(-1);
508
 
509
         if ( mConnectionString.compareTo("iteration1") == 0 || mConnectionString.compareTo("iteration2") == 0 )
510
         {
511
           p = findPackage(2, packageCollection);
512
           p.mDependencyCollection.add("CotsWithFunnyVersion.cots");
513
           p.mDependencyIDCollection.add(-1);
514
           p.mDependencyCollection.add("UncommonDependency.tim");
515
           p.mDependencyIDCollection.add(-1);
516
         }
517
 
518
         if ( mConnectionString.compareTo("iteration1") == 0 
519
           || mConnectionString.compareTo("iteration2") == 0
520
           || mConnectionString.compareTo("iteration3") == 0 )
521
         {
522
           p = findPackage(3, packageCollection);
523
           p.mDependencyCollection.add("CommonDependency.tim");
524
           p.mDependencyIDCollection.add(-1);
525
         }
526
 
527
         if ( mConnectionString.compareTo("iteration1") == 0 
528
           || mConnectionString.compareTo("iteration2") == 0
529
           || mConnectionString.compareTo("iteration3") == 0
530
           || mConnectionString.compareTo("iteration4") == 0 )
531
         {
532
           p = findPackage(4, packageCollection);
533
           p.mDependencyCollection.add("CommonDependency.tim");
534
           p.mDependencyIDCollection.add(-1);
535
         }
536
 
537
         if ( mConnectionString.compareTo("iteration1") == 0 
538
           || mConnectionString.compareTo("iteration2") == 0
539
           || mConnectionString.compareTo("iteration3") == 0
540
           || mConnectionString.compareTo("iteration4") == 0
541
           || mConnectionString.compareTo("iteration5") == 0 )
542
         {
543
           p = findPackage(5, packageCollection);
544
           p.mDependencyCollection.add("UncommonDependency.tim");
545
           p.mDependencyIDCollection.add(-1);
546
         }
547
 
548
        /* planned build info
549
         * pv_id bm_name bsa_name
550
         * 0     Linux   Java 1.6
551
         * 1     Linux   Debug
552
         * 2     Linux   Debug
553
         * 2     Solaris Production
554
         * 2     Win32   Production and Debug
555
         * 3     Solaris Java 1.4
556
         * 4     Generic Java 1.5
557
         * 5     Linux   Java 1.6
558
         * 5     Win32   Java 1.6
559
         */
560
         if ( mConnectionString.compareTo("iteration1") == 0 )
561
         {
562
           p = findPackage(0, packageCollection);
563
           BuildStandard bs = new BuildStandard(rippleEngine);
564
           bs.setLinux();
565
           bs.set1_6();
566
           p.mBuildStandardCollection.add(bs);
567
         }
568
 
569
         p = findPackage(1, packageCollection);
570
         BuildStandard bs = new BuildStandard(rippleEngine);
571
         bs.setLinux();
572
         bs.setDebug();
573
         p.mBuildStandardCollection.add(bs);
574
 
575
         if ( mConnectionString.compareTo("iteration1") == 0 || mConnectionString.compareTo("iteration2") == 0 )
576
         {
577
           p = findPackage(2, packageCollection);
578
           bs = new BuildStandard(rippleEngine);
579
           bs.setLinux();
580
           bs.setDebug();
581
           p.mBuildStandardCollection.add(bs);
582
           bs = new BuildStandard(rippleEngine);
583
           bs.setSolaris();
584
           bs.setProduction();
585
           p.mBuildStandardCollection.add(bs);
586
           bs = new BuildStandard(rippleEngine);
587
           bs.setWin32();
588
           bs.setAll();
589
           p.mBuildStandardCollection.add(bs);
590
         }
591
 
592
         if ( mConnectionString.compareTo("iteration1") == 0 
593
           || mConnectionString.compareTo("iteration2") == 0
594
           || mConnectionString.compareTo("iteration3") == 0 )
595
         {
596
           p = findPackage(3, packageCollection);
597
           bs = new BuildStandard(rippleEngine);
598
           bs.setSolaris();
599
           bs.set1_4();
600
           p.mBuildStandardCollection.add(bs);
601
         }
602
 
603
         if ( mConnectionString.compareTo("iteration1") == 0 
604
           || mConnectionString.compareTo("iteration2") == 0
605
           || mConnectionString.compareTo("iteration3") == 0
606
           || mConnectionString.compareTo("iteration4") == 0 )
607
         {
608
           p = findPackage(4, packageCollection);
609
           bs = new BuildStandard(rippleEngine);
610
           bs.setGeneric();
611
           bs.set1_5();
612
           p.mBuildStandardCollection.add(bs);
613
         }
614
 
615
         if ( mConnectionString.compareTo("iteration1") == 0 
616
           || mConnectionString.compareTo("iteration2") == 0
617
           || mConnectionString.compareTo("iteration3") == 0
618
           || mConnectionString.compareTo("iteration4") == 0
619
           || mConnectionString.compareTo("iteration5") == 0 )
620
         {
621
           p = findPackage(5, packageCollection);
622
           bs = new BuildStandard(rippleEngine);
623
           bs.setLinux();
624
           bs.set1_6();
625
           p.mBuildStandardCollection.add(bs);
626
           bs = new BuildStandard(rippleEngine);
627
           bs.setWin32();
628
           bs.set1_6();
629
           p.mBuildStandardCollection.add(bs);
630
         }
631
 
632
        /* planned unit test info
633
         * pv_id test_type_name
634
         * 2     Manual Test
635
         * 2     Interactive Test
636
         * 2     Integration Test
637
         * 5     Autobuild UTF
638
         */
639
         if ( mConnectionString.compareTo("iteration1") == 0 
640
           || mConnectionString.compareTo("iteration2") == 0
641
           || mConnectionString.compareTo("iteration3") == 0
642
           || mConnectionString.compareTo("iteration4") == 0
643
           || mConnectionString.compareTo("iteration5") == 0 )
644
         {
645
           p = findPackage(5, packageCollection);
646
           p.mHasAutomatedUnitTests = true;
647
         }
648
 
649
        /* planned build failure info
650
         * pv_id user_email
651
         * 3     jimmyfishcake@erggroup.com
652
         * 3     rayhaddock@erggroup.com
653
         * 5     timbutdim@erggroup.com
654
         */
655
         if ( mConnectionString.compareTo("iteration1") == 0 
656
           || mConnectionString.compareTo("iteration2") == 0
657
           || mConnectionString.compareTo("iteration3") == 0 )
658
         {
659
           p = findPackage(3, packageCollection);
660
           p.mBuildFailureEmailCollection.add("jimmyfishcake@erggroup.com");
661
           p.mBuildFailureEmailCollection.add("rayhaddock@erggroup.com");
662
         }
663
 
664
         if ( mConnectionString.compareTo("iteration1") == 0 
665
           || mConnectionString.compareTo("iteration2") == 0
666
           || mConnectionString.compareTo("iteration3") == 0
667
           || mConnectionString.compareTo("iteration4") == 0
668
           || mConnectionString.compareTo("iteration5") == 0 )
669
         {
670
           p = findPackage(5, packageCollection);
671
           p.mBuildFailureEmailCollection.add("timbutdim@erggroup.com");
672
         }
673
 
674
        /* planned do not ripple info
675
         * pv_id
676
         * 6
677
         */
678
         p = findPackage(6, packageCollection);
679
         p.mDoNotRipple = true;
680
 
681
        /* planned advisory ripple info
682
         * pv_id
683
         * 0
684
         */
685
         if ( mConnectionString.compareTo("iteration1") == 0 )
686
         {
687
           p = findPackage(0, packageCollection);
688
           p.mAdvisoryRipple = true;
689
         }
690
 
691
        /* released info
692
         * pv_id pkg_id pkg_name                     pkg_version      v_ext pkg_label                           src_path                   ripple_field
693
         * 7     8      CotsWithFunnyVersion         hoopla2_x.cots   .cots CotsWithFunnyVersion_hoopla2_x.cots \vob\CotsWithFunnyVersion
694
         * 8     17     NotInAnyWayReproducible      1.0.0.tim        .tim  NA                                  NA
695
         * 9     34     CommonDependency             1.0.0000.tim     .tim  CommonDependency_1.0.0000.tim       \vob\CommonDependency
696
         * 10    908    SolarisCentricProduct        1.0.0000.tim     .tim  SolarisCentricProduct_1.0.0000.tim  \vob\SolarisCentricProduct m
697
         * 11    16     LinuxCentricProduct          1.0.0000.tim     .tim  LinuxCentricProduct_1.0.0000.tim    \vob\LinuxCentricProduct
698
         * 12    312    Win32CentricProduct          1.0.0000.tim     .tim  Win32CentricProduct_1.0.0000.tim    \vob\Win32CentricProduct
699
         * 13    6      GenericProduct               1.0.0000.tim     .tim  GenericProduct_1.0.0000.tim         \vob\ToBeMovedFromHere     M
700
         * 14    81     AdvisoryDependency           1.0.0000.tim     .tim  AdvisoryDependency_1.0.0000.tim     \vob\AdvisoryDependency
701
         * 15    1      MergedProduct                1.0.0000.tim     .tim  MergedProduct_1.0.0000.tim          \vob\MergedProduct         m
702
         */
703
         if ( mConnectionString.compareTo("iteration1") != 0 )
704
         {
705
           p = new Package(0, "UncommonDependency", "0.0.1000.tim", ".tim", "UncommonDependency.tim", "UncommonDependency_0.0.1000.tim", "\\vob\\UncommonDependency", 'x');
706
           p.mPid = 76;
707
           Integer pv_id = new Integer(0);
708
           rippleEngine.mReleasedPvIDCollection.add(pv_id);
709
           Package plannedPackage = findPackage(p.mAlias, packageCollection);
710
 
711
           if ( plannedPackage == NULL_PACKAGE )
712
           {
713
             packageCollection.add(p);
714
           }
715
           else
716
           {
717
             plannedPackage.mVersion = "0.0.1000";
718
           }
719
         }
720
 
721
         if ( mConnectionString.compareTo("iteration1") != 0 && mConnectionString.compareTo("iteration2") != 0 )
722
         {
723
           p = new Package(2, "CommonDependency", "2.0.0000.tim", ".tim", "CommonDependency.tim", "CommonDependency_2.0.0000.tim", "\\vob\\CommonDependency", 'x');
724
           p.mPid = 34;
725
           Integer pv_id = new Integer(2);
726
           rippleEngine.mReleasedPvIDCollection.add(pv_id);
727
           Package plannedPackage = findPackage(p.mAlias, packageCollection);
728
 
729
           if ( plannedPackage == NULL_PACKAGE )
730
           {
731
             packageCollection.add(p);
732
           }
733
           else
734
           {
735
             plannedPackage.mVersion = "2.0.0000";
736
           }
737
         }
738
 
739
         if ( mConnectionString.compareTo("iteration1") != 0 
740
           && mConnectionString.compareTo("iteration2") != 0
741
           && mConnectionString.compareTo("iteration3") != 0 )
742
         {
743
           p = new Package(3, "SolarisCentricProduct", "1.1.0000.tim", ".tim", "SolarisCentricProduct.tim", "SolarisCentricProduct_1.1.0000.tim", "\\vob\\SolarisCentricProduct", 'm');
744
           p.mPid = 908;
745
           Integer pv_id = new Integer(3);
746
           rippleEngine.mReleasedPvIDCollection.add(pv_id);
747
           Package plannedPackage = findPackage(p.mAlias, packageCollection);
748
 
749
           if ( plannedPackage == NULL_PACKAGE )
750
           {
751
             packageCollection.add(p);
752
           }
753
           else
754
           {
755
             plannedPackage.mVersion = "1.1.0000";
756
           }
757
         }
758
 
759
         if ( mConnectionString.compareTo("iteration1") != 0 
760
           && mConnectionString.compareTo("iteration2") != 0
761
           && mConnectionString.compareTo("iteration3") != 0
762
           && mConnectionString.compareTo("iteration4") != 0 )
763
         {
764
           p = new Package(4, "GenericProduct", "1.0.1000.tim", ".tim", "GenericProduct.tim", "GenericProduct_1.0.1000.tim", "\\vob\\GenericProduct", 'M');
765
           p.mPid = 6;
766
           Integer pv_id = new Integer(4);
767
           rippleEngine.mReleasedPvIDCollection.add(pv_id);
768
           Package plannedPackage = findPackage(p.mAlias, packageCollection);
769
 
770
           if ( plannedPackage == NULL_PACKAGE )
771
           {
772
             packageCollection.add(p);
773
           }
774
           else
775
           {
776
             plannedPackage.mVersion = "1.0.1000";
777
           }
778
         }
779
 
780
         if ( mConnectionString.compareTo("iteration1") != 0 
781
           && mConnectionString.compareTo("iteration2") != 0
782
           && mConnectionString.compareTo("iteration3") != 0
783
           && mConnectionString.compareTo("iteration4") != 0
784
           && mConnectionString.compareTo("iteration5") != 0 )
785
         {
786
           p = new Package(5, "Product", "1.0.0000.tim", ".tim", "Product.tim", "Product_1.0.0000.tim", "\\vob\\Product", 'M');
787
           p.mPid = 11;
788
           Integer pv_id = new Integer(5);
789
           rippleEngine.mReleasedPvIDCollection.add(pv_id);
790
           Package plannedPackage = findPackage(p.mAlias, packageCollection);
791
 
792
           if ( plannedPackage == NULL_PACKAGE )
793
           {
794
             packageCollection.add(p);
795
           }
796
           else
797
           {
798
             plannedPackage.mVersion = "1.0.0000";
799
           }
800
         }
801
 
802
         p = new Package(7, "CotsWithFunnyVersion", "hoopla2_x.cots", ".cots", "CotsWithFunnyVersion.cots", "CotsWithFunnyVersion_hoopla2_x", "\\vob\\CotsWithFunnyVersion", 'x');
803
         p.mPid = 8;
804
         Integer pv_id = new Integer(7);
805
         rippleEngine.mReleasedPvIDCollection.add(pv_id);
806
         Package plannedPackage = findPackage(p.mAlias, packageCollection);
807
 
808
         if ( plannedPackage == NULL_PACKAGE )
809
         {
810
           packageCollection.add(p);
811
         }
812
         else
813
         {
814
           plannedPackage.mVersion = "hoopla2_x";
815
         }
816
 
817
         p = new Package(8, "NotInAnyWayReproducible", "1.0.0.tim", ".tim", "NotInAnyWayReproducible.tim", "NA", "NA", 'x');
818
         p.mPid = 17;
819
         pv_id = new Integer(8);
820
         rippleEngine.mReleasedPvIDCollection.add(pv_id);
821
         plannedPackage = findPackage(p.mAlias, packageCollection);
822
 
823
         if ( plannedPackage == NULL_PACKAGE )
824
         {
825
           packageCollection.add(p);
826
         }
827
         else
828
         {
829
           plannedPackage.mVersion = "1.0.0";
830
         }
831
 
832
         if ( mConnectionString.compareTo("iteration1") == 0 || mConnectionString.compareTo("iteration2") == 0 )
833
         {
834
           p = new Package(9, "CommonDependency", "1.0.0000.tim", ".tim", "CommonDependency.tim", "CommonDependency_1.0.0000.tim", "\\vob\\CommonDependency", 'x');
835
           p.mPid = 34;
836
           pv_id = new Integer(9);
837
           rippleEngine.mReleasedPvIDCollection.add(pv_id);
838
           plannedPackage = findPackage(p.mAlias, packageCollection);
839
 
840
           if ( plannedPackage == NULL_PACKAGE )
841
           {
842
             packageCollection.add(p);
843
           }
844
           else
845
           {
846
             plannedPackage.mVersion = "1.0.0000";
847
           }
848
         }
849
 
850
         if ( mConnectionString.compareTo("iteration1") == 0 
851
           || mConnectionString.compareTo("iteration2") == 0
852
           || mConnectionString.compareTo("iteration3") == 0 )
853
         {
854
           p = new Package(10, "SolarisCentricProduct", "1.0.0000.tim", ".tim", "SolarisCentricProduct.tim", "SolarisCentricProduct_1.0.0000.tim", "\\vob\\SolarisCentricProduct", 'm');
855
           p.mPid = 908;
856
           pv_id = new Integer(10);
857
           rippleEngine.mReleasedPvIDCollection.add(pv_id);
858
           plannedPackage = findPackage(p.mAlias, packageCollection);
859
 
860
           if ( plannedPackage == NULL_PACKAGE )
861
           {
862
             packageCollection.add(p);
863
           }
864
           else
865
           {
866
             plannedPackage.mVersion = "1.0.0000";
867
           }
868
         }
869
 
870
         p = new Package(11, "LinuxCentricProduct", "1.0.0000.tim", ".tim", "LinuxCentricProduct.tim", "LinuxCentricProduct_1.0.0000.tim", "\\vob\\LinuxCentricProduct", 'x');
871
         p.mPid = 16;
872
         pv_id = new Integer(11);
873
         rippleEngine.mReleasedPvIDCollection.add(pv_id);
874
         plannedPackage = findPackage(p.mAlias, packageCollection);
875
 
876
         if ( plannedPackage == NULL_PACKAGE )
877
         {
878
           packageCollection.add(p);
879
         }
880
         else
881
         {
882
           plannedPackage.mVersion = "1.0.0000";
883
         }
884
 
885
         p = new Package(12, "Win32CentricProduct", "1.0.0000.tim", ".tim", "Win32CentricProduct.tim", "Win32CentricProduct_1.0.0000.tim", "\\vob\\Win32CentricProduct", 'x');
886
         p.mPid = 312;
887
         pv_id = new Integer(12);
888
         rippleEngine.mReleasedPvIDCollection.add(pv_id);
889
         plannedPackage = findPackage(p.mAlias, packageCollection);
890
 
891
         if ( plannedPackage == NULL_PACKAGE )
892
         {
893
           packageCollection.add(p);
894
         }
895
         else
896
         {
897
           plannedPackage.mVersion = "1.0.0000";
898
         }
899
 
900
         if ( mConnectionString.compareTo("iteration1") == 0 
901
           || mConnectionString.compareTo("iteration2") == 0
902
           || mConnectionString.compareTo("iteration3") == 0
903
           || mConnectionString.compareTo("iteration4") == 0 )
904
         {
905
           p = new Package(13, "GenericProduct", "1.0.0000.tim", ".tim", "GenericProduct.tim", "GenericProduct_1.0.0000.tim", "\\vob\\ToBeMovedFromHere", 'M');
906
           p.mPid = 6;
907
           pv_id = new Integer(13);
908
           rippleEngine.mReleasedPvIDCollection.add(pv_id);
909
           plannedPackage = findPackage(p.mAlias, packageCollection);
910
         }
911
 
912
         if ( plannedPackage == NULL_PACKAGE )
913
         {
914
           packageCollection.add(p);
915
         }
916
         else
917
         {
918
           plannedPackage.mVersion = "1.0.0000";
919
         }
920
 
921
         p = new Package(14, "AdvisoryDependency", "1.0.0000.tim", ".tim", "AdvisoryDependency.tim", "AdvisoryDependency_1.0.0000.tim", "\\vob\\AdvisoryDependency", 'x');
922
         p.mPid = 81;
923
         pv_id = new Integer(14);
924
         rippleEngine.mReleasedPvIDCollection.add(pv_id);
925
         plannedPackage = findPackage(p.mAlias, packageCollection);
926
 
927
         if ( plannedPackage == NULL_PACKAGE )
928
         {
929
           packageCollection.add(p);
930
         }
931
         else
932
         {
933
           plannedPackage.mVersion = "1.0.0000";
934
         }
935
 
936
         if ( mConnectionString.compareTo("iteration1") == 0 
937
           || mConnectionString.compareTo("iteration2") == 0
938
           || mConnectionString.compareTo("iteration3") == 0
939
           || mConnectionString.compareTo("iteration4") == 0
940
           || mConnectionString.compareTo("iteration5") == 0
941
           || mConnectionString.compareTo("iteration6") == 0 )
942
         {
943
           p = new Package(15, "MergedProduct", "1.0.0000.tim", ".tim", "MergedProduct.tim", "MergedProduct_1.0.0000.tim", "\\vob\\MergedProduct", 'm');
944
           p.mPid = 1;
945
           pv_id = new Integer(15);
946
           rippleEngine.mReleasedPvIDCollection.add(pv_id);
947
           plannedPackage = findPackage(p.mAlias, packageCollection);
948
         }
949
         else
950
         {
951
           p = new Package(16, "MergedProduct", "1.0.0000.tim", ".tim", "MergedProduct.tim", "MergedProduct_1.0.0000.tim", "\\vob\\MergedProduct", 'm');
952
           p.mPid = 1;
953
           pv_id = new Integer(16);
954
           rippleEngine.mReleasedPvIDCollection.add(pv_id);
955
           plannedPackage = findPackage(p.mAlias, packageCollection);
956
         }
957
 
958
         if ( plannedPackage == NULL_PACKAGE )
959
         {
960
           packageCollection.add(p);
961
         }
962
         else
963
         {
964
           plannedPackage.mVersion = "1.0.0000";
965
         }
966
 
967
        /* released dependencies
968
         * pv_id dpv_id pkg_name                     v_ext
969
         * 8     9      CommonDependency             .tim
970
         * 9     7      CotsWithFunnyVersion         .cots
971
         * 10    9      CommonDependency             .tim
972
         * 11    44     AdvisoryDependency           .tim
973
         * 13    9      CommonDependency             .tim
974
         * 15    99     CommonDependency             .tim
975
         */
976
         if ( mConnectionString.compareTo("iteration1") != 0 && mConnectionString.compareTo("iteration2") != 0 )
977
         {
978
           p = findPackage(2, packageCollection);
979
           p.mDependencyCollection.add("CotsWithFunnyVersion.cots");
980
           p.mDependencyIDCollection.add(7);
981
           p.mDependencyCollection.add("UncommonDependency.tim");
982
           p.mDependencyIDCollection.add(0);
983
         }
984
 
985
         if ( mConnectionString.compareTo("iteration1") != 0 
986
           && mConnectionString.compareTo("iteration2") != 0
987
           && mConnectionString.compareTo("iteration3") != 0 )
988
         {
989
           p = findPackage(3, packageCollection);
990
           p.mDependencyCollection.add("CommonDependency.tim");
991
           p.mDependencyIDCollection.add(2);
992
         }
993
 
994
         if ( mConnectionString.compareTo("iteration1") != 0 
995
           && mConnectionString.compareTo("iteration2") != 0
996
           && mConnectionString.compareTo("iteration3") != 0
997
           && mConnectionString.compareTo("iteration4") != 0 )
998
         {
999
           p = findPackage(4, packageCollection);
1000
           p.mDependencyCollection.add("CommonDependency.tim");
1001
           p.mDependencyIDCollection.add(2);
1002
         }
1003
 
1004
         if ( mConnectionString.compareTo("iteration1") != 0 
1005
           && mConnectionString.compareTo("iteration2") != 0
1006
           && mConnectionString.compareTo("iteration3") != 0
1007
           && mConnectionString.compareTo("iteration4") != 0
1008
           && mConnectionString.compareTo("iteration5") != 0 )
1009
         {
1010
           p = findPackage(5, packageCollection);
1011
           p.mDependencyCollection.add("UncommonDependency.tim");
1012
           p.mDependencyIDCollection.add(0);
1013
         }
1014
 
1015
         p = findPackage(8, packageCollection);
1016
         p.mDependencyCollection.add("CommonDependency.tim");
1017
         p.mDependencyIDCollection.add(9);
1018
 
1019
         if ( mConnectionString.compareTo("iteration1") == 0 || mConnectionString.compareTo("iteration2") == 0 )
1020
         {
1021
           p = findPackage(9, packageCollection);
1022
           p.mDependencyCollection.add("CotsWithFunnyVersion.cots");
1023
           p.mDependencyIDCollection.add(7);
1024
         }
1025
 
1026
         if ( mConnectionString.compareTo("iteration1") == 0 
1027
           || mConnectionString.compareTo("iteration2") == 0
1028
           || mConnectionString.compareTo("iteration3") == 0 )
1029
         {
1030
           p = findPackage(10, packageCollection);
1031
           p.mDependencyCollection.add("CommonDependency.tim");
1032
           p.mDependencyIDCollection.add(9);
1033
         }
1034
 
1035
         p = findPackage(11, packageCollection);
1036
         p.mDependencyCollection.add("AdvisoryDependency.tim");
1037
         p.mDependencyIDCollection.add(44);
1038
 
1039
         if ( mConnectionString.compareTo("iteration1") == 0 
1040
           || mConnectionString.compareTo("iteration2") == 0
1041
           || mConnectionString.compareTo("iteration3") == 0
1042
           || mConnectionString.compareTo("iteration4") == 0 )
1043
         {
1044
           p = findPackage(13, packageCollection);
1045
           p.mDependencyCollection.add("CommonDependency.tim");
1046
           p.mDependencyIDCollection.add(9);
1047
         }
1048
 
1049
         if ( mConnectionString.compareTo("iteration1") == 0 
1050
           || mConnectionString.compareTo("iteration2") == 0
1051
           || mConnectionString.compareTo("iteration3") == 0
1052
           || mConnectionString.compareTo("iteration4") == 0
1053
           || mConnectionString.compareTo("iteration5") == 0
1054
           || mConnectionString.compareTo("iteration6") == 0 )
1055
         {
1056
           p = findPackage(15, packageCollection);
1057
           p.mDependencyCollection.add("CommonDependency.tim");
1058
           p.mDependencyIDCollection.add(99);
1059
         }
1060
         else
1061
         {
1062
           p = findPackage(16, packageCollection);
1063
           p.mDependencyCollection.add("CommonDependency.tim");
1064
           p.mDependencyIDCollection.add(2);
1065
         }
1066
 
1067
        /* released build info
1068
         * pv_id bm_name bsa_name
1069
         * 7     Solaris Debug
1070
         * 9     Linux   Debug
1071
         * 9     Solaris Debug
1072
         * 9     Win32   Production
1073
         * 10    Solaris Java 1.4
1074
         * 11    Linux   Production and Debug
1075
         * 12    Win32   Java 1.6
1076
         * 13    Generic Java 1.4
1077
         * 14    Linux   Debug
1078
         * 15    Linux   Debug
1079
         */
1080
         if ( mConnectionString.compareTo("iteration1") != 0 )
1081
         {
1082
           p = findPackage(0, packageCollection);
1083
           bs = new BuildStandard(rippleEngine);
1084
           bs.setLinux();
1085
           bs.set1_6();
1086
           p.mBuildStandardCollection.add(bs);
1087
         }
1088
 
1089
         if ( mConnectionString.compareTo("iteration1") != 0 && mConnectionString.compareTo("iteration2") != 0 )
1090
         {
1091
           p = findPackage(2, packageCollection);
1092
           bs = new BuildStandard(rippleEngine);
1093
           bs.setLinux();
1094
           bs.setDebug();
1095
           p.mBuildStandardCollection.add(bs);
1096
           bs = new BuildStandard(rippleEngine);
1097
           bs.setSolaris();
1098
           bs.setProduction();
1099
           p.mBuildStandardCollection.add(bs);
1100
           bs = new BuildStandard(rippleEngine);
1101
           bs.setWin32();
1102
           bs.setAll();
1103
           p.mBuildStandardCollection.add(bs);
1104
         }
1105
 
1106
         if ( mConnectionString.compareTo("iteration1") != 0 
1107
           && mConnectionString.compareTo("iteration2") != 0
1108
           && mConnectionString.compareTo("iteration3") != 0 )
1109
         {
1110
           p = findPackage(3, packageCollection);
1111
           bs = new BuildStandard(rippleEngine);
1112
           bs.setSolaris();
1113
           bs.set1_4();
1114
           p.mBuildStandardCollection.add(bs);
1115
         }
1116
 
1117
         if ( mConnectionString.compareTo("iteration1") != 0 
1118
           && mConnectionString.compareTo("iteration2") != 0
1119
           && mConnectionString.compareTo("iteration3") != 0
1120
           && mConnectionString.compareTo("iteration4") != 0 )
1121
         {
1122
           p = findPackage(4, packageCollection);
1123
           bs = new BuildStandard(rippleEngine);
1124
           bs.setGeneric();
1125
           bs.set1_5();
1126
           p.mBuildStandardCollection.add(bs);
1127
         }
1128
 
1129
         if ( mConnectionString.compareTo("iteration1") != 0 
1130
           && mConnectionString.compareTo("iteration2") != 0
1131
           && mConnectionString.compareTo("iteration3") != 0
1132
           && mConnectionString.compareTo("iteration4") != 0
1133
           && mConnectionString.compareTo("iteration5") != 0 )
1134
         {
1135
           p = findPackage(5, packageCollection);
1136
           bs = new BuildStandard(rippleEngine);
1137
           bs.setLinux();
1138
           bs.set1_6();
1139
           p.mBuildStandardCollection.add(bs);
1140
           bs = new BuildStandard(rippleEngine);
1141
           bs.setWin32();
1142
           bs.set1_6();
1143
           p.mBuildStandardCollection.add(bs);
1144
         }
1145
 
1146
         p = findPackage(7, packageCollection);
1147
         bs = new BuildStandard(rippleEngine);
1148
         bs.setSolaris();
1149
         bs.setDebug();
1150
         p.mBuildStandardCollection.add(bs);
1151
 
1152
         if ( mConnectionString.compareTo("iteration1") == 0 || mConnectionString.compareTo("iteration2") == 0 )
1153
         {
1154
           p = findPackage(9, packageCollection);
1155
           bs = new BuildStandard(rippleEngine);
1156
           bs.setLinux();
1157
           bs.setDebug();
1158
           p.mBuildStandardCollection.add(bs);
1159
           bs = new BuildStandard(rippleEngine);
1160
           bs.setSolaris();
1161
           bs.setDebug();
1162
           p.mBuildStandardCollection.add(bs);
1163
           bs = new BuildStandard(rippleEngine);
1164
           bs.setWin32();
1165
           bs.setProduction();
1166
           p.mBuildStandardCollection.add(bs);
1167
         }
1168
 
1169
         if ( mConnectionString.compareTo("iteration1") == 0 
1170
           || mConnectionString.compareTo("iteration2") == 0
1171
           || mConnectionString.compareTo("iteration3") == 0 )
1172
         {
1173
           p = findPackage(10, packageCollection);
1174
           bs = new BuildStandard(rippleEngine);
1175
           bs.setSolaris();
1176
           bs.set1_4();
1177
           p.mBuildStandardCollection.add(bs);
1178
         }
1179
 
1180
         p = findPackage(11, packageCollection);
1181
         bs = new BuildStandard(rippleEngine);
1182
         bs.setLinux();
1183
         bs.setAll();
1184
         p.mBuildStandardCollection.add(bs);
1185
 
1186
         p = findPackage(12, packageCollection);
1187
         bs = new BuildStandard(rippleEngine);
1188
         bs.setWin32();
1189
         bs.set1_6();
1190
         p.mBuildStandardCollection.add(bs);
1191
 
1192
         if ( mConnectionString.compareTo("iteration1") == 0 
1193
           || mConnectionString.compareTo("iteration2") == 0
1194
           || mConnectionString.compareTo("iteration3") == 0
1195
           || mConnectionString.compareTo("iteration4") == 0 )
1196
         {
1197
           p = findPackage(13, packageCollection);
1198
           bs = new BuildStandard(rippleEngine);
1199
           bs.setGeneric();
1200
           bs.set1_4();
1201
           p.mBuildStandardCollection.add(bs);
1202
         }
1203
 
1204
         p = findPackage(14, packageCollection);
1205
         bs = new BuildStandard(rippleEngine);
1206
         bs.setLinux();
1207
         bs.setDebug();
1208
         p.mBuildStandardCollection.add(bs);
1209
 
1210
         if ( mConnectionString.compareTo("iteration1") == 0 
1211
           || mConnectionString.compareTo("iteration2") == 0
1212
           || mConnectionString.compareTo("iteration3") == 0
1213
           || mConnectionString.compareTo("iteration4") == 0
1214
           || mConnectionString.compareTo("iteration5") == 0
1215
           || mConnectionString.compareTo("iteration6") == 0 )
1216
         {
1217
           p = findPackage(15, packageCollection);
1218
           bs = new BuildStandard(rippleEngine);
1219
           bs.setLinux();
1220
           bs.setDebug();
1221
           p.mBuildStandardCollection.add(bs);
1222
         }
1223
         else
1224
         {
1225
           p = findPackage(16, packageCollection);
1226
           bs = new BuildStandard(rippleEngine);
1227
           bs.setLinux();
1228
           bs.setDebug();
1229
           p.mBuildStandardCollection.add(bs);
1230
         }
1231
 
1232
        /* released package unit test info
1233
         * pv_id tt.test_type_name
1234
         * 9     Manual Test
1235
         * 9     Interactive Test
1236
         * 9     Integration Test
1237
         * 11    Autobuild UTF
1238
         */
1239
         if ( mConnectionString.compareTo("iteration1") != 0 
1240
           && mConnectionString.compareTo("iteration2") != 0
1241
           && mConnectionString.compareTo("iteration3") != 0
1242
           && mConnectionString.compareTo("iteration4") != 0
1243
           && mConnectionString.compareTo("iteration5") != 0 )
1244
         {
1245
           p = findPackage(5, packageCollection);
1246
           p.mHasAutomatedUnitTests = true;
1247
         }
1248
 
1249
         p = findPackage(11, packageCollection);
1250
         p.mHasAutomatedUnitTests = true;
1251
 
1252
        /* released build failure email info
1253
         * pv_id user_email
1254
         * 10    jimmyfishcake@erggroup.com
1255
         */
1256
         if ( mConnectionString.compareTo("iteration1") != 0 
1257
           && mConnectionString.compareTo("iteration2") != 0
1258
           && mConnectionString.compareTo("iteration3") != 0 )
1259
         {
1260
           p = findPackage(3, packageCollection);
1261
           p.mBuildFailureEmailCollection.add("jimmyfishcake@erggroup.com");
1262
           p.mBuildFailureEmailCollection.add("rayhaddock@erggroup.com");
1263
         }
1264
 
1265
         if ( mConnectionString.compareTo("iteration1") != 0 
1266
           && mConnectionString.compareTo("iteration2") != 0
1267
           && mConnectionString.compareTo("iteration3") != 0
1268
           && mConnectionString.compareTo("iteration4") != 0
1269
           && mConnectionString.compareTo("iteration5") != 0 )
1270
         {
1271
           p = findPackage(5, packageCollection);
1272
           p.mBuildFailureEmailCollection.add("timbutdim@erggroup.com");
1273
         }
1274
 
1275
         if ( mConnectionString.compareTo("iteration1") == 0 
1276
           || mConnectionString.compareTo("iteration2") == 0
1277
           || mConnectionString.compareTo("iteration3") == 0 )
1278
         {
1279
           p = findPackage(10, packageCollection);
1280
           p.mBuildFailureEmailCollection.add("jimmyfishcake@erggroup.com");
1281
         }
1282
 
1283
        /* released do not ripple info
1284
         * pv_id
1285
         * 11
1286
         */
1287
         p = findPackage(11, packageCollection);
1288
         p.mDoNotRipple = true;
1289
 
1290
        /* released advisory ripple info
1291
         * pv_id
1292
         * 14
1293
         */
1294
         if ( mConnectionString.compareTo("iteration1") != 0 )
1295
         {
1296
           p = findPackage(0, packageCollection);
1297
           p.mAdvisoryRipple = true;
1298
         }
1299
 
1300
         p = findPackage(14, packageCollection);
1301
         p.mAdvisoryRipple = true;
1302
      }
1303
      else
1304
      {
1305
        /* prod_id pkg_name                pkg_version  v_ext pkg_label                           src_path
1306
         * 8       NotInAnyWayReproducible 1.0.0.tim    .tim  NA                                  NA
1307
         * 10      SolarisCentricProduct   1.0.0000.tim .tim  SolarisCentricProduct_1.0.0000.tim  \vob\SolarisCentricProduct
1308
         * 11      LinuxCentricProduct     1.0.0000.tim .tim  LinuxCentricProduct_1.0.0000.tim    \vob\LinuxCentricProduct
1309
         * 12      Win32CentricProduct     1.0.0000.tim .tim  Win32CentricProduct_1.0.0000.tim    \vob\Win32CentricProduct
1310
         * 13      GenericProduct          1.0.0000.tim .tim  GenericProduct_1.0.0000.tim         \vob\ToBeMovedFromHere
1311
         */
1312
         Package p = new Package(8, "NotInAnyWayReproducible", "1.0.0.tim", ".tim", "NotInAnyWayReproducible.1.0.0.tim", "NA", "NA", 'x');
1313
         packageCollection.add(p);
1314
         p = new Package(10, "SolarisCentricProduct", "1.0.0000.tim", ".tim", "SolarisCentricProduct.1.0.0000.tim", "SolarisCentricProduct_1.0.0000.tim", "\\vob\\SolarisCentricProduct", 'x');
1315
         packageCollection.add(p);
1316
         p = new Package(11, "LinuxCentricProduct", "1.0.0000.tim", ".tim", "LinuxCentricProduct.1.0.0000.tim", "LinuxCentricProduct_1.0.0000.tim", "\\vob\\LinuxCentricProduct", 'x');
1317
         packageCollection.add(p);
1318
         p = new Package(12, "Win32CentricProduct", "1.0.0000.tim", ".tim", "Win32CentricProduct.1.0.0000.tim", "Win32CentricProduct_1.0.0000.tim", "\\vob\\Win32CentricProduct", 'x');
1319
         packageCollection.add(p);
1320
         p = new Package(13, "GenericProduct", "1.0.0000.tim", ".tim", "GenericProduct.1.0.0000.tim", "GenericProduct_1.0.0000.tim", "\\vob\\ToBeMovedFromHere", 'x');
1321
         packageCollection.add(p);
1322
 
1323
        /* the above products have the following dependencies which will be discovered in traverseDependencies
1324
         * pv_id   pkg_name, dpv.pkg_version, dpv.v_ext, dpv.pkg_label, dpv.src_path
1325
         * 7     CotsWithFunnyVersion         hoopla2_x.cots   .cots CotsWithFunnyVersion_hoopla2_x.cots \vob\CotsWithFunnyVersion
1326
         * 9     CommonDependency             1.0.0000.tim     .tim  CommonDependency_1.0.0000.tim       \vob\CommonDependency
1327
         * 14    AdvisoryDependency           1.0.0000.tim     .tim  AdvisoryDependency_1.0.0000.tim     \vob\AdvisoryDependency
1328
         * the above packages have the following build info
1329
         * pv_id bm_name bsa_name
1330
         * 7     Solaris Debug
1331
         * 9     Linux   Debug
1332
         * 9     Solaris Debug
1333
         * 9     Win32   Production
1334
         * 10    Solaris Java 1.4
1335
         * 11    Linux   Production and Debug
1336
         * 12    Win32   Java 1.6
1337
         * 13    Generic Java 1.4
1338
         * 14    Linux   Debug
1339
         */
1340
      }
1341
    }
1342
    else
1343
    {
1344
      try
1345
      {
1346
        if (daemonMode)
1347
        {
1348
          // get planned package info
1349
          CallableStatement stmt1 = mConnection.prepareCall(
1350
          "select pl.pv_id, p.pkg_id, p.pkg_name, pv.v_ext, pv.pkg_label, pv.src_path, pv.change_type " +
1351
          "from release_manager.planned pl, release_manager.package_versions pv, release_manager.packages p " +
1352
          "where pl.rtag_id=" + baseline + " and pv.build_type='A' and pv.dlocked='A' " +
1353
          "and pv.pv_id=pl.pv_id and p.pkg_id=pv.pkg_id " +
1354
          "order by pl.pv_id"
1355
          );
1356
          ResultSet rset1 = stmt1.executeQuery();
1357
 
1358
          while( rset1.next() )
1359
          {
1360
            int pv_id = rset1.getInt("pv_id");
1361
 
1362
            if ( rset1.wasNull() )
1363
            {
1364
              mLogger.fatal("queryPackageVersions rset1 null pv_id");
1365
              // show stopper
1366
              throw new Exception();
1367
            }
1368
 
1369
            int pkg_id = rset1.getInt("pkg_id");
1370
 
1371
            if ( rset1.wasNull() )
1372
            {
1373
              mLogger.fatal("queryPackageVersions rset1 null pkg_id " + pv_id);
1374
              // show stopper
1375
              throw new Exception();
1376
            }
1377
 
1378
            String pkg_name = rset1.getString("pkg_name");
1379
 
1380
            if ( pkg_name == null )
1381
            {
1382
              mLogger.fatal("queryPackageVersions rset1 null pkg_name " + pv_id);
1383
              // show stopper
1384
              throw new Exception();
1385
            }
1386
 
1387
            String v_ext = rset1.getString("v_ext");
1388
 
1389
            if ( v_ext == null )
1390
            {
1391
              v_ext = "";
1392
            }
1393
 
1394
            String pkg_label = rset1.getString("pkg_label");
1395
 
1396
            if ( pkg_label == null )
1397
            {
1398
              pkg_label = "NA";
1399
            }
1400
 
1401
            String src_path = rset1.getString("src_path");
1402
 
1403
            if ( src_path == null )
1404
            {
1405
              src_path = "NA";
1406
            }
1407
 
1408
            String change_type = rset1.getString("change_type");
1409
 
1410
            if ( change_type == null )
1411
            {
1412
              change_type = "P";
1413
            }
1414
 
1415
            char ct = 'x';
1416
 
1417
            if ( change_type.compareTo("M") == 0 )
1418
            {
1419
              ct = 'M';
1420
            }
1421
            else if ( change_type.compareTo("N") == 0 )
1422
            {
1423
              ct = 'N';
1424
            }
1425
            else if ( change_type.compareTo("P") == 0 )
1426
            {
1427
              ct = 'P';
1428
            }
1429
 
1430
            if ( ct != 'x' )
1431
            {
1432
              Package p = new Package(pv_id, pkg_name, v_ext, pkg_name + v_ext, pkg_label, src_path, ct);
1433
              p.mPid = pkg_id;
1434
              p.mDirectlyPlanned = true;
1435
              packageCollection.add(p);
1436
            }
1437
          }
830 mhunt 1438
 
1439
          rset1.close();
1440
          stmt1.close();
814 mhunt 1441
 
1442
          // get planned package dependency info
1443
          CallableStatement stmt2 = mConnection.prepareCall(
1444
          "select pl.pv_id, p.pkg_name, dpv.v_ext " +
1445
          "from release_manager.planned pl, release_manager.package_versions pv, release_manager.package_dependencies pd, release_manager.package_versions dpv, release_manager.packages p " +
1446
          "where pl.rtag_id=" + baseline + " and pv.build_type='A' and pv.dlocked='A' " +
1447
          "and pv.pv_id = pl.pv_id and pd.pv_id=pl.pv_id and dpv.pv_id=pd.dpv_id and p.pkg_id=dpv.pkg_id " +
1448
          "order by pl.pv_id"
1449
          );
1450
          ResultSet rset2 = stmt2.executeQuery();
1451
 
1452
          while( rset2.next() )
1453
          {
1454
            boolean ignore = false;
1455
 
1456
            int pv_id = rset2.getInt("pv_id");
1457
 
1458
            if ( rset2.wasNull() )
1459
            {
1460
              mLogger.fatal("queryPackageVersions rset2 null pv_id");
1461
              // show stopper
1462
              throw new Exception();
1463
            }
1464
 
1465
            Package p = findPackage(pv_id, packageCollection);
1466
 
1467
            if ( p == NULL_PACKAGE )
1468
            {
1469
              mLogger.info("queryPackageVersions rset2 highly unlikely " + pv_id);
1470
              // highly unlikely but package may have been added in between queries
1471
              ignore = true;
1472
            }
1473
 
1474
            String pkg_name = rset2.getString("pkg_name");
1475
 
1476
            if ( pkg_name == null )
1477
            {
1478
              mLogger.fatal("queryPackageVersions rset2 null pkg_name " + pv_id);
1479
              // show stopper
1480
              throw new Exception();
1481
            }
1482
 
1483
            String v_ext = rset2.getString("v_ext");
1484
 
1485
            if ( v_ext == null )
1486
            {
1487
              v_ext = "";
1488
            }
1489
 
1490
            if ( !ignore )
1491
            {
1492
              p.mDependencyCollection.add(pkg_name + v_ext);
1493
              p.mDependencyIDCollection.add(-1);
1494
            }
1495
          }
1496
 
830 mhunt 1497
          rset2.close();
1498
          stmt2.close();
1499
 
814 mhunt 1500
          // get planned package build info
1501
          CallableStatement stmt3 = mConnection.prepareCall(
1502
          "select pl.pv_id, bm.bm_name, bsa.bsa_name " +
1503
          "from release_manager.planned pl, release_manager.package_versions pv, release_manager.package_build_info pbi, release_manager.build_machines bm, release_manager.build_standards_addendum bsa " +
1504
          "where pl.rtag_id=" + baseline + " and pv.build_type='A' and pv.dlocked='A' " +
1505
          "and pv.pv_id = pl.pv_id and pbi.pv_id=pv.pv_id and bm.bm_id=pbi.bm_id and bsa.bsa_id=pbi.bsa_id " +
1506
          "order by pl.pv_id"
1507
          );
1508
          ResultSet rset3 = stmt3.executeQuery();
1509
 
1510
          while( rset3.next() )
1511
          {
1512
            boolean ignore = false;
1513
            int pv_id = rset3.getInt("pv_id");
1514
 
1515
            if ( rset3.wasNull() )
1516
            {
1517
              mLogger.fatal("queryPackageVersions rset3 null pv_id");
1518
              // show stopper
1519
              throw new Exception();
1520
            }
1521
 
1522
            Package p = findPackage(pv_id, packageCollection);
1523
 
1524
            if ( p == NULL_PACKAGE )
1525
            {
1526
              mLogger.info("queryPackageVersions rset3 highly unlikely " + pv_id);
1527
              // highly unlikely but package may have been added in between queries
1528
              ignore = true;
1529
            }
1530
 
1531
            String bm_name = rset3.getString("bm_name");
1532
 
1533
            if ( bm_name == null )
1534
            {
1535
              mLogger.fatal("queryPackageVersions rset3 null bm_name " + pv_id);
1536
              // show stopper
1537
              throw new Exception();
1538
            }
1539
 
1540
            String bsa_name = rset3.getString("bsa_name");
1541
 
1542
            if ( bsa_name == null )
1543
            {
1544
              mLogger.fatal("queryPackageVersions rset3 null bsa_name " + pv_id);
1545
              // show stopper
1546
              throw new Exception();
1547
            }
1548
 
1549
            if ( !ignore )
1550
            {
1551
              boolean supportedBuildStandard = true;
1552
              BuildStandard bs = new BuildStandard(rippleEngine);
1553
 
1554
              if ( bm_name.compareTo("Solaris") == 0 )
1555
              {
1556
                bs.setSolaris();
1557
              }
1558
              else if ( bm_name.compareTo("Win32") == 0 )
1559
              {
1560
                bs.setWin32();
1561
              }
1562
              else if ( bm_name.compareTo("Linux") == 0 )
1563
              {
1564
                bs.setLinux();
1565
              }
1566
              else if ( bm_name.compareTo("Generic") == 0 )
1567
              {
1568
                bs.setGeneric();
1569
              }
1570
              else
1571
              {
1572
                supportedBuildStandard = false;
1573
              }
1574
 
1575
              if ( bsa_name.compareTo("Production") == 0 )
1576
              {
1577
                bs.setProduction();
1578
              }
1579
              else if ( bsa_name.compareTo("Debug") == 0 )
1580
              {
1581
                bs.setDebug();
1582
              }
1583
              else if ( bsa_name.compareTo("Production and Debug") == 0 )
1584
              {
1585
                bs.setAll();
1586
              }
1587
              else if ( bsa_name.compareTo("Java 1.4") == 0 )
1588
              {
1589
                bs.set1_4();
1590
              }
1591
              else if ( bsa_name.compareTo("Java 1.5") == 0 )
1592
              {
1593
                bs.set1_5();
1594
              }
1595
              else if ( bsa_name.compareTo("Java 1.6") == 0 )
1596
              {
1597
                bs.set1_6();
1598
              }
1599
              else
1600
              {
1601
                supportedBuildStandard = false;
1602
              }
1603
 
1604
              if ( supportedBuildStandard )
1605
              {
1606
                p.mBuildStandardCollection.add(bs);
1607
              }
1608
            }
1609
          }
830 mhunt 1610
 
1611
          rset3.close();
1612
          stmt3.close();
814 mhunt 1613
 
1614
          // get planned package unit test info
1615
          CallableStatement stmt4 = mConnection.prepareCall(
1616
          "select pl.pv_id, tt.test_type_name " +
1617
          "from release_manager.planned pl, release_manager.package_versions pv, release_manager.unit_tests ut, release_manager.test_types tt " +
1618
          "where pl.rtag_id=" + baseline + " and pv.build_type='A' and pv.dlocked='A' " +
1619
          "and pv.pv_id = pl.pv_id and ut.pv_id=pv.pv_id and tt.test_type_id=ut.test_types_fk " +
1620
          "order by pl.pv_id"
1621
          );
1622
          ResultSet rset4 = stmt4.executeQuery();
1623
 
1624
          while( rset4.next() )
1625
          {
1626
            boolean ignore = false;
1627
 
1628
            int pv_id = rset4.getInt("pv_id");
1629
 
1630
            if ( rset4.wasNull() )
1631
            {
1632
              mLogger.fatal("queryPackageVersions rset4 null pv_id");
1633
              // show stopper
1634
              throw new Exception();
1635
            }
1636
 
1637
            Package p = findPackage(pv_id, packageCollection);
1638
 
1639
            if ( p == NULL_PACKAGE )
1640
            {
1641
              mLogger.info("queryPackageVersions rset4 highly unlikely " + pv_id);
1642
              // highly unlikely but package may have been added in between queries
1643
              ignore = true;
1644
            }
1645
 
1646
            String test_type_name = rset4.getString("test_type_name");
1647
 
1648
            if ( test_type_name == null )
1649
            {
1650
              mLogger.fatal("queryPackageVersions rset4 null test_type_name " + pv_id);
1651
              // show stopper
1652
              throw new Exception();
1653
            }
1654
 
1655
            if ( !ignore )
1656
            {
1657
              if ( test_type_name.compareTo("Autobuild UTF") == 0 )
1658
              {
1659
                p.mHasAutomatedUnitTests = true;
1660
              }
1661
            }
1662
          }
830 mhunt 1663
 
1664
          rset4.close();
1665
          stmt4.close();
814 mhunt 1666
 
1667
          // get planned package build failure info
1668
          CallableStatement stmt5 = mConnection.prepareCall(
1669
          "select pl.pv_id, u.user_email " +
1670
          "from release_manager.planned pl, release_manager.release_tags rt, release_manager.package_versions pv, release_manager.autobuild_failure af, release_manager.members_group mg, release_manager.users u " +
1671
          "where pl.rtag_id=" + baseline + " and rt.rtag_id=pl.rtag_id and pv.build_type='A' and pv.dlocked='A' " +
1672
          "and pv.pv_id = pl.pv_id and af.view_id=pl.view_id and mg.group_email_id=af.group_email_id and u.user_id=mg.user_id and af.proj_id=rt.proj_id " +
1673
          "order by pl.pv_id"
1674
          );
1675
          ResultSet rset5 = stmt5.executeQuery();
1676
 
1677
          while( rset5.next() )
1678
          {
1679
            boolean ignore = false;
1680
 
1681
            int pv_id = rset5.getInt("pv_id");
1682
 
1683
            if ( rset5.wasNull() )
1684
            {
1685
              mLogger.fatal("queryPackageVersions rset5 null pv_id");
1686
              // show stopper
1687
              throw new Exception();
1688
            }
1689
 
1690
            Package p = findPackage(pv_id, packageCollection);
1691
 
1692
            if ( p == NULL_PACKAGE )
1693
            {
1694
              mLogger.info("queryPackageVersions rset5 highly unlikely " + pv_id);
1695
              // highly unlikely but package may have been added in between queries
1696
              ignore = true;
1697
            }
1698
 
1699
            String user_email = rset5.getString("user_email");
1700
 
1701
            if ( user_email == null )
1702
            {
1703
              // this can be null!
1704
              ignore = true;
1705
            }
1706
 
1707
            if ( !ignore )
1708
            {
1709
              p.mBuildFailureEmailCollection.add(user_email);
1710
            }
1711
          }
830 mhunt 1712
 
1713
          rset5.close();
1714
          stmt5.close();
814 mhunt 1715
 
1716
          // get planned package do not ripple info
1717
          CallableStatement stmt6 = mConnection.prepareCall(
1718
          "select pl.pv_id " +
1719
          "from release_manager.planned pl, release_manager.package_versions pv, release_manager.do_not_ripple dnr " +
1720
          "where pl.rtag_id=" + baseline + " and pv.build_type='A' and pv.dlocked='A' " +
1721
          "and pv.pv_id = pl.pv_id and dnr.rtag_id=pl.rtag_id and dnr.pv_id=pl.pv_id " +
1722
          "order by pl.pv_id"
1723
          );
1724
          ResultSet rset6 = stmt6.executeQuery();
1725
 
1726
          while( rset6.next() )
1727
          {
1728
            boolean ignore = false;
1729
 
1730
            int pv_id = rset6.getInt("pv_id");
1731
 
1732
            if ( rset6.wasNull() )
1733
            {
1734
              mLogger.fatal("queryPackageVersions rset6 null pv_id");
1735
              // show stopper
1736
              throw new Exception();
1737
            }
1738
 
1739
            Package p = findPackage(pv_id, packageCollection);
1740
 
1741
            if ( p == NULL_PACKAGE )
1742
            {
1743
              mLogger.info("queryPackageVersions rset6 highly unlikely " + pv_id);
1744
              // highly unlikely but package may have been added in between queries
1745
              ignore = true;
1746
            }
1747
 
1748
            if ( !ignore )
1749
            {
1750
              p.mDoNotRipple = true;
1751
            }
1752
          }
830 mhunt 1753
 
1754
          rset6.close();
1755
          stmt6.close();
814 mhunt 1756
 
1757
          // get planned package advisory ripple info
1758
          CallableStatement stmt7 = mConnection.prepareCall(
1759
          "select pl.pv_id " +
1760
          "from release_manager.planned pl, release_manager.package_versions pv, release_manager.advisory_ripple ar " +
1761
          "where pl.rtag_id=" + baseline + " and pv.build_type='A' and pv.dlocked='A' " +
1762
          "and pv.pv_id = pl.pv_id and ar.rtag_id=pl.rtag_id and ar.pv_id=pl.pv_id " +
1763
          "order by pl.pv_id"
1764
          );
1765
          ResultSet rset7 = stmt7.executeQuery();
1766
 
1767
          while( rset7.next() )
1768
          {
1769
            boolean ignore = false;
1770
 
1771
            int pv_id = rset7.getInt("pv_id");
1772
 
1773
            if ( rset7.wasNull() )
1774
            {
1775
              mLogger.fatal("queryPackageVersions rset7 null pv_id");
1776
              // show stopper
1777
              throw new Exception();
1778
            }
1779
 
1780
            Package p = findPackage(pv_id, packageCollection);
1781
 
1782
            if ( p == NULL_PACKAGE )
1783
            {
1784
              mLogger.info("queryPackageVersions rset7 highly unlikely " + pv_id);
1785
              // highly unlikely but package may have been added in between queries
1786
              ignore = true;
1787
            }
1788
 
1789
            if ( !ignore )
1790
            {
1791
              p.mAdvisoryRipple = true;
1792
            }
1793
          }
1794
 
830 mhunt 1795
          rset7.close();
1796
          stmt7.close();
1797
 
814 mhunt 1798
          // get released package info
1799
          CallableStatement stmt8 = mConnection.prepareCall(
1800
          "select rc.pv_id, p.pkg_id, p.pkg_name, pv.pkg_version, pv.v_ext, pv.pkg_label, pv.src_path, pv.ripple_field " +
1801
          "from release_manager.release_content rc, release_manager.package_versions pv, release_manager.packages p " +
1802
          "where rc.rtag_id=" + baseline +
1803
          " and pv.pv_id = rc.pv_id and p.pkg_id = pv.pkg_id " +
1804
          "order by rc.pv_id"
1805
          );
1806
          ResultSet rset8 = stmt8.executeQuery();
1807
 
1808
          while( rset8.next() )
1809
          {
1810
            int pv_id = rset8.getInt("pv_id");
1811
 
1812
            if ( rset8.wasNull() )
1813
            {
1814
              mLogger.fatal("queryPackageVersions rset8 null pv_id");
1815
              // show stopper
1816
              throw new Exception();
1817
            }
1818
 
1819
            int pkg_id = rset8.getInt("pkg_id");
1820
 
1821
            if ( rset8.wasNull() )
1822
            {
1823
              mLogger.fatal("queryPackageVersions rset8 null pkg_id " + pv_id);
1824
              // show stopper
1825
              throw new Exception();
1826
            }
1827
 
1828
            String pkg_name = rset8.getString("pkg_name");
1829
 
1830
            if ( pkg_name == null )
1831
            {
1832
              mLogger.fatal("queryPackageVersions rset8 null pkg_name " + pv_id);
1833
              // show stopper
1834
              throw new Exception();
1835
            }
1836
 
1837
            String pkg_version = rset8.getString("pkg_version");
1838
 
1839
            if ( pkg_version == null )
1840
            {
1841
              mLogger.fatal("queryPackageVersions rset8 null pkg_version " + pv_id);
1842
              // show stopper
1843
              throw new Exception();
1844
            }
1845
 
1846
            String v_ext = rset8.getString("v_ext");
1847
 
1848
            if ( v_ext == null )
1849
            {
1850
              v_ext = "";
1851
            }
1852
 
1853
            String pkg_label = rset8.getString("pkg_label");
1854
 
1855
            if ( pkg_label == null )
1856
            {
1857
              pkg_label = "NA";
1858
            }
1859
 
1860
            String src_path = rset8.getString("src_path");
1861
 
1862
            if ( src_path == null )
1863
            {
1864
              src_path = "NA";
1865
            }
1866
 
1867
            String ripple_field = rset8.getString("ripple_field");
1868
 
1869
            if ( ripple_field == null )
1870
            {
1871
              ripple_field = "x";
1872
            }
1873
            else if ( ripple_field.length() == 0 )
1874
            {
1875
              ripple_field = "x";
1876
            }
1877
 
1878
            Package p = new Package(pv_id, pkg_name, pkg_version, v_ext, pkg_name + v_ext, pkg_label, src_path, ripple_field.charAt(0));
1879
            p.mPid = pkg_id;
1880
            Integer ipv_id = new Integer(pv_id);
1881
            rippleEngine.mReleasedPvIDCollection.add(ipv_id);
1882
            Package plannedPackage = findPackage(p.mAlias, packageCollection);
1883
 
1884
            if ( plannedPackage == NULL_PACKAGE )
1885
            {
1886
              mLogger.info("queryPackageVersions rset8 no planned package " + pv_id);
1887
              packageCollection.add(p);
1888
            }
1889
            else
1890
            {
1891
              int endindex = pkg_version.length() - v_ext.length();
1892
 
1893
              if ( endindex > 0 )
1894
              {
1895
                pkg_version = pkg_version.substring(0, endindex);
1896
              }
1897
 
1898
              plannedPackage.mVersion = pkg_version;
1899
            }
1900
          }
830 mhunt 1901
 
1902
          rset8.close();
1903
          stmt8.close();
814 mhunt 1904
 
1905
          // get released package dependency info
1906
          CallableStatement stmt9 = mConnection.prepareCall(
1907
          "select rc.pv_id, dpv.pv_id, p.pkg_name, dpv.v_ext " +
1908
          "from release_manager.release_content rc, release_manager.package_versions pv, release_manager.package_dependencies pd, release_manager.package_versions dpv, release_manager.packages p " +
1909
          "where rc.rtag_id=" + baseline +
1910
          " and pv.pv_id = rc.pv_id and pd.pv_id=pv.pv_id and dpv.pv_id=pd.dpv_id and p.pkg_id=dpv.pkg_id " +
1911
          "order by rc.pv_id"
1912
          );
1913
          ResultSet rset9 = stmt9.executeQuery();
1914
 
1915
          while( rset9.next() )
1916
          {
1917
            boolean ignore = false;
1918
 
1919
            int pv_id = rset9.getInt(1);
1920
 
1921
            if ( rset9.wasNull() )
1922
            {
1923
              mLogger.fatal("queryPackageVersions rset9 null pv_id");
1924
              // show stopper
1925
              throw new Exception();
1926
            }
1927
 
1928
            int dpv_id = rset9.getInt(2);
1929
 
1930
            if ( rset9.wasNull() )
1931
            {
1932
              mLogger.fatal("queryPackageVersions rset9 null dpv_id " + pv_id);
1933
              // show stopper
1934
              throw new Exception();
1935
            }
1936
 
1937
            Package p = findPackage(pv_id, packageCollection);
1938
 
1939
            if ( p == NULL_PACKAGE )
1940
            {
1941
              mLogger.info("queryPackageVersions rset9 package may have been superceded by planned " + pv_id);
1942
              ignore = true;
1943
            }
1944
 
1945
            String pkg_name = rset9.getString("pkg_name");
1946
 
1947
            if ( pkg_name == null )
1948
            {
1949
              mLogger.fatal("queryPackageVersions rset9 null pkg_name " + pv_id);
1950
              // show stopper
1951
              throw new Exception();
1952
            }
1953
 
1954
            String v_ext = rset9.getString("v_ext");
1955
 
1956
            if ( v_ext == null )
1957
            {
1958
              v_ext = "";
1959
            }
1960
 
1961
            if ( !ignore )
1962
            {
1963
              p.mDependencyCollection.add(pkg_name + v_ext);
1964
              p.mDependencyIDCollection.add(dpv_id);
1965
            }
1966
          }
830 mhunt 1967
 
1968
          rset9.close();
1969
          stmt9.close();
814 mhunt 1970
 
1971
          // get released package build info
1972
          CallableStatement stmt10 = mConnection.prepareCall(
1973
          "select rc.pv_id, bm.bm_name, bsa.bsa_name " +
1974
          "from release_manager.release_content rc, release_manager.package_versions pv, release_manager.package_build_info pbi, release_manager.build_machines bm, release_manager.build_standards_addendum bsa " +
1975
          "where rc.rtag_id=" + baseline +
1976
          " and pv.pv_id = rc.pv_id and pbi.pv_id=pv.pv_id and bm.bm_id=pbi.bm_id and bsa.bsa_id=pbi.bsa_id " +
1977
          "order by rc.pv_id"
1978
          );
1979
          ResultSet rset10 = stmt10.executeQuery();
1980
 
1981
          while( rset10.next() )
1982
          {
1983
            boolean ignore = false;
1984
            int pv_id = rset10.getInt("pv_id");
1985
 
1986
            if ( rset10.wasNull() )
1987
            {
1988
              mLogger.fatal("queryPackageVersions rset10 null pv_id");
1989
              // show stopper
1990
              throw new Exception();
1991
            }
1992
 
1993
            Package p = findPackage(pv_id, packageCollection);
1994
 
1995
            if ( p == NULL_PACKAGE )
1996
            {
1997
              mLogger.info("queryPackageVersions rset10 package may have been superceded by planned " + pv_id);
1998
              ignore = true;
1999
            }
2000
 
2001
            String bm_name = rset10.getString("bm_name");
2002
 
2003
            if ( bm_name == null )
2004
            {
2005
              mLogger.fatal("queryPackageVersions rset10 null bm_name " + pv_id);
2006
              // show stopper
2007
              throw new Exception();
2008
            }
2009
 
2010
            String bsa_name = rset10.getString("bsa_name");
2011
 
2012
            if ( bsa_name == null )
2013
            {
2014
              mLogger.fatal("queryPackageVersions rset10 null bsa_name " + pv_id);
2015
              // show stopper
2016
              throw new Exception();
2017
            }
2018
 
2019
            if ( !ignore )
2020
            {
2021
              boolean supportedBuildStandard = true;
2022
              BuildStandard bs = new BuildStandard(rippleEngine);
2023
 
2024
              if ( bm_name.compareTo("Solaris") == 0 )
2025
              {
2026
                bs.setSolaris();
2027
              }
2028
              else if ( bm_name.compareTo("Win32") == 0 )
2029
              {
2030
                bs.setWin32();
2031
              }
2032
              else if ( bm_name.compareTo("Linux") == 0 )
2033
              {
2034
                bs.setLinux();
2035
              }
2036
              else if ( bm_name.compareTo("Generic") == 0 )
2037
              {
2038
                bs.setGeneric();
2039
              }
2040
              else
2041
              {
2042
                supportedBuildStandard = false;
2043
              }
2044
 
2045
              if ( bsa_name.compareTo("Production") == 0 )
2046
              {
2047
                bs.setProduction();
2048
              }
2049
              else if ( bsa_name.compareTo("Debug") == 0 )
2050
              {
2051
                bs.setDebug();
2052
              }
2053
              else if ( bsa_name.compareTo("Production and Debug") == 0 )
2054
              {
2055
                bs.setAll();
2056
              }
2057
              else if ( bsa_name.compareTo("Java 1.4") == 0 )
2058
              {
2059
                bs.set1_4();
2060
              }
2061
              else if ( bsa_name.compareTo("Java 1.5") == 0 )
2062
              {
2063
                bs.set1_5();
2064
              }
2065
              else if ( bsa_name.compareTo("Java 1.6") == 0 )
2066
              {
2067
                bs.set1_6();
2068
              }
2069
              else
2070
              {
2071
                supportedBuildStandard = false;
2072
              }
2073
 
2074
              if ( supportedBuildStandard )
2075
              {
2076
                p.mBuildStandardCollection.add(bs);
2077
              }
2078
            }
2079
          }
830 mhunt 2080
 
2081
          rset10.close();
2082
          stmt10.close();
814 mhunt 2083
 
2084
          // get released package unit test info
2085
          CallableStatement stmt11 = mConnection.prepareCall(
2086
          "select rc.pv_id, tt.test_type_name " +
2087
          "from release_manager.release_content rc, release_manager.package_versions pv, release_manager.unit_tests ut, release_manager.test_types tt " +
2088
          "where rc.rtag_id=" + baseline +
2089
          " and pv.pv_id = rc.pv_id and ut.pv_id=pv.pv_id and tt.test_type_id=ut.test_types_fk " +
2090
          "order by rc.pv_id"
2091
          );
2092
          ResultSet rset11 = stmt11.executeQuery();
2093
 
2094
          while( rset11.next() )
2095
          {
2096
            boolean ignore = false;
2097
 
2098
            int pv_id = rset11.getInt("pv_id");
2099
 
2100
            if ( rset11.wasNull() )
2101
            {
2102
              mLogger.fatal("queryPackageVersions rset11 null pv_id");
2103
              // show stopper
2104
              throw new Exception();
2105
            }
2106
 
2107
            Package p = findPackage(pv_id, packageCollection);
2108
 
2109
            if ( p == NULL_PACKAGE )
2110
            {
2111
              mLogger.info("queryPackageVersions rset11 package may have been superceded by planned " + pv_id);
2112
              ignore = true;
2113
            }
2114
 
2115
            String test_type_name = rset11.getString("test_type_name");
2116
 
2117
            if ( test_type_name == null )
2118
            {
2119
              mLogger.fatal("queryPackageVersions rset11 null test_type_name " + pv_id);
2120
              // show stopper
2121
              throw new Exception();
2122
            }
2123
 
2124
            if ( !ignore )
2125
            {
2126
              if ( test_type_name.compareTo("Autobuild UTF") == 0 )
2127
              {
2128
                p.mHasAutomatedUnitTests = true;
2129
              }
2130
            }
2131
          }
830 mhunt 2132
 
2133
          rset11.close();
2134
          stmt11.close();
814 mhunt 2135
 
2136
          // get released package build failure email info
2137
          CallableStatement stmt12 = mConnection.prepareCall(
2138
          "select rc.pv_id, u.user_email " +
2139
          "from release_manager.release_content rc, release_manager.release_tags rt, release_manager.package_versions pv, release_manager.autobuild_failure af, release_manager.members_group mg, release_manager.users u " +
2140
          "where rc.rtag_id=" + baseline + " and rt.rtag_id=rc.rtag_id " +
2141
          "and pv.pv_id = rc.pv_id and af.view_id=rc.base_view_id and mg.group_email_id=af.group_email_id and u.user_id=mg.user_id and af.proj_id=rt.proj_id " +
2142
          "order by rc.pv_id"
2143
          );
2144
          ResultSet rset12 = stmt12.executeQuery();
2145
 
2146
          while( rset12.next() )
2147
          {
2148
            boolean ignore = false;
2149
 
2150
            int pv_id = rset12.getInt("pv_id");
2151
 
2152
            if ( rset12.wasNull() )
2153
            {
2154
              mLogger.fatal("queryPackageVersions rset12 null pv_id");
2155
              // show stopper
2156
              throw new Exception();
2157
            }
2158
 
2159
            Package p = findPackage(pv_id, packageCollection);
2160
 
2161
            if ( p == NULL_PACKAGE )
2162
            {
2163
              mLogger.info("queryPackageVersions rset12 package may have been superceded by planned " + pv_id);
2164
              ignore = true;
2165
            }
2166
 
2167
            String user_email = rset12.getString("user_email");
2168
 
2169
            if ( user_email == null )
2170
            {
2171
              // this can be null
2172
              ignore = true;
2173
            }
2174
 
2175
            if ( !ignore )
2176
            {
2177
              p.mBuildFailureEmailCollection.add(user_email);
2178
            }
2179
          }
830 mhunt 2180
 
2181
          rset12.close();
2182
          stmt12.close();
814 mhunt 2183
 
2184
          // get released package do not ripple info
2185
          CallableStatement stmt13 = mConnection.prepareCall(
2186
          "select rc.pv_id " +
2187
          "from release_manager.release_content rc, release_manager.package_versions pv, release_manager.do_not_ripple dnr " +
2188
          "where rc.rtag_id=" + baseline +
2189
          " and pv.pv_id = rc.pv_id and dnr.rtag_id=rc.rtag_id and dnr.pv_id=rc.pv_id " +
2190
          "order by rc.pv_id"
2191
          );
2192
          ResultSet rset13 = stmt13.executeQuery();
2193
 
2194
          while( rset13.next() )
2195
          {
2196
            boolean ignore = false;
2197
 
2198
            int pv_id = rset13.getInt("pv_id");
2199
 
2200
            if ( rset13.wasNull() )
2201
            {
2202
              mLogger.fatal("queryPackageVersions rset13 null pv_id");
2203
              // show stopper
2204
              throw new Exception();
2205
            }
2206
 
2207
            Package p = findPackage(pv_id, packageCollection);
2208
 
2209
            if ( p == NULL_PACKAGE )
2210
            {
2211
              mLogger.info("queryPackageVersions rset13 package may have been superceded by planned " + pv_id);
2212
              ignore = true;
2213
            }
2214
 
2215
            if ( !ignore )
2216
            {
2217
              p.mDoNotRipple = true;
2218
            }
2219
          }
830 mhunt 2220
 
2221
          rset13.close();
2222
          stmt13.close();
814 mhunt 2223
 
2224
          // get released advisory ripple info
2225
          CallableStatement stmt14 = mConnection.prepareCall(
2226
          "select rc.pv_id " +
2227
          "from release_manager.release_content rc, release_manager.package_versions pv, release_manager.advisory_ripple ar " +
2228
          "where rc.rtag_id=" + baseline +
2229
          " and pv.pv_id = rc.pv_id and ar.rtag_id=rc.rtag_id and ar.pv_id=rc.pv_id " +
2230
          "order by rc.pv_id"
2231
          );
2232
          ResultSet rset14 = stmt14.executeQuery();
2233
 
2234
          while( rset14.next() )
2235
          {
2236
            boolean ignore = false;
2237
 
2238
            int pv_id = rset14.getInt("pv_id");
2239
 
2240
            if ( rset14.wasNull() )
2241
            {
2242
              mLogger.fatal("queryPackageVersions rset14 null pv_id");
2243
              // show stopper
2244
              throw new Exception();
2245
            }
2246
 
2247
            Package p = findPackage(pv_id, packageCollection);
2248
 
2249
            if ( p == NULL_PACKAGE )
2250
            {
2251
              mLogger.info("queryPackageVersions rset14 package may have been superceded by planned " + pv_id);
2252
              ignore = true;
2253
            }
2254
 
2255
            if ( !ignore )
2256
            {
2257
              p.mAdvisoryRipple = true;
2258
            }
2259
          }
830 mhunt 2260
 
2261
          rset14.close();
2262
          stmt14.close();
814 mhunt 2263
        }
2264
        else
2265
        {
2266
          // get released product info
2267
          CallableStatement stmt = mConnection.prepareCall(
2268
          "select oc.prod_id, p.pkg_name, pv.pkg_version, pv.v_ext, pv.pkg_label, pv.src_path " +
2269
          "from bom_contents bc, operating_systems os, os_contents oc, release_manager.package_versions pv, release_manager.packages p " +
2270
          "where bc.bom_id=" + baseline + " and os.node_id=bc.node_id and oc.os_id=os.os_id and pv.pv_id=oc.prod_id and p.pkg_id=pv.pkg_id " +
2271
          "order by oc.prod_id"
2272
          );
2273
          ResultSet rset = stmt.executeQuery();
2274
 
2275
          while( rset.next() )
2276
          {
2277
            int pv_id = rset.getInt("prod_id");
2278
 
2279
            if ( rset.wasNull() )
2280
            {
2281
              mLogger.fatal("queryPackageVersions rset null prod_id");
2282
              // show stopper
2283
              throw new Exception();
2284
            }
2285
 
2286
            String pkg_name = rset.getString("pkg_name");
2287
 
2288
            if ( pkg_name == null )
2289
            {
2290
              mLogger.fatal("queryPackageVersions rset null pkg_name " + pv_id);
2291
              // show stopper
2292
              throw new Exception();
2293
            }
2294
 
2295
            String pkg_version = rset.getString("pkg_version");
2296
 
2297
            if ( pkg_version == null )
2298
            {
2299
              mLogger.fatal("queryPackageVersions rset null pkg_version " + pv_id);
2300
              // show stopper
2301
              throw new Exception();
2302
            }
2303
 
2304
            String v_ext = rset.getString("v_ext");
2305
 
2306
            if ( v_ext == null )
2307
            {
2308
              v_ext = "";
2309
            }
2310
 
2311
            String pkg_label = rset.getString("pkg_label");
2312
 
2313
            if ( pkg_label == null )
2314
            {
2315
              pkg_label = "NA";
2316
            }
2317
 
2318
            String src_path = rset.getString("src_path");
2319
 
2320
            if ( src_path == null )
2321
            {
2322
              src_path = "NA";
2323
            }
2324
 
834 mhunt 2325
            Package p = findPackage(pv_id, packageCollection);
2326
 
2327
            if ( p == NULL_PACKAGE )
2328
            {
2329
	            Package q = new Package(pv_id, pkg_name, pkg_version, v_ext, pkg_name + "." + pkg_version, pkg_label, src_path, 'x');
2330
	            packageCollection.add(q);
2331
            }
814 mhunt 2332
          }
830 mhunt 2333
 
2334
          rset.close();
2335
          stmt.close();
814 mhunt 2336
        }
2337
      }
2338
      catch ( SQLException e )
2339
      {
2340
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
2341
        {
2342
          mLogger.error("queryPackageVersions database access error only");
2343
          throw new SQLException();
2344
        }
2345
        else
2346
        {
2347
          mLogger.fatal("queryPackageVersions show stopper");
2348
          throw new Exception();
2349
        }
2350
      }
2351
    }
2352
 
2353
    if (!daemonMode)
2354
    {
2355
      // use a ListIterator as it allows traverseDependencies to modify the packageCollection
2356
      for (ListIterator it = packageCollection.listIterator(); it.hasNext(); )
2357
      {
2358
        Package p = (Package) it.next();
2359
        traverseDependencies(packageCollection, p, false, it);
2360
      }
2361
 
2362
      for (Iterator it = packageCollection.iterator(); it.hasNext(); )
2363
      {
2364
        Package p = (Package) it.next();
2365
        queryBuildInfo(rippleEngine, p);
2366
      }
2367
    }
2368
 
2369
  }
2370
 
2371
  /**only used in daemon mode
2372
   *   select config from build_service_config where service='MAIL SERVER';
2373
   * returns the configured service
2374
   */
2375
  String queryMailServer() throws SQLException, Exception
2376
  {
2377
    mLogger.debug("queryMailServer");
2378
    String retVal = new String();
2379
 
2380
    if ( !mUseDatabase )
2381
    {
2382
      mLogger.info("queryMailServer !mUseDatabase");
2383
      // a highly likely mail server
2384
      retVal = "aupera03.aupera.erggroup.com";
2385
    }
2386
    else
2387
    {
2388
      try
2389
      {
2390
        CallableStatement stmt = mConnection.prepareCall("select config from release_manager.build_service_config where service='MAIL SERVER'");
2391
        ResultSet rset = stmt.executeQuery();
2392
 
2393
        while( rset.next() )
2394
        {
2395
          String config = rset.getString("config");
2396
 
2397
          if ( config != null )
2398
          {
2399
            retVal += config;
2400
          }
2401
        }
830 mhunt 2402
 
2403
        rset.close();
2404
        stmt.close();
814 mhunt 2405
      }
2406
      catch ( SQLException e )
2407
      {
2408
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
2409
        {
2410
          mLogger.error("queryMailServer database access error only");
2411
          throw new SQLException();
2412
        }
2413
        else
2414
        {
2415
          mLogger.fatal("queryMailServer show stopper");
2416
          throw new Exception();
2417
        }
2418
      }
2419
    }
2420
 
2421
    mLogger.info("queryMailServer returned " + retVal);
2422
    return retVal;
2423
  }
2424
 
2425
  /**only used in daemon mode
2426
   *   select config from build_service_config where service='BUILD FAILURE MAIL SENDER';
2427
   * returns the configured service
2428
   */
2429
  String queryMailSender() throws SQLException, Exception
2430
  {
2431
    mLogger.debug("queryMailSender");
2432
    String retVal = new String();
2433
 
2434
    if ( !mUseDatabase )
2435
    {
2436
      mLogger.info("queryMailSender !mUseDatabase");
2437
      // a highly likely mail sender
2438
      retVal = "buildadm@erggroup.com";
2439
    }
2440
    else
2441
    {
2442
      try
2443
      {
2444
        CallableStatement stmt = mConnection.prepareCall("select config from release_manager.build_service_config where service='BUILD FAILURE MAIL SENDER'");
2445
        ResultSet rset = stmt.executeQuery();
2446
 
2447
        while( rset.next() )
2448
        {
2449
          String config = rset.getString("config");
2450
 
2451
          if ( config != null )
2452
          {
2453
            retVal += config;
2454
          }
2455
        }
830 mhunt 2456
 
2457
        rset.close();
2458
        stmt.close();
814 mhunt 2459
      }
2460
      catch ( SQLException e )
2461
      {
2462
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
2463
        {
2464
          mLogger.error("queryMailSender database access error only");
2465
          throw new SQLException();
2466
        }
2467
        else
2468
        {
2469
          mLogger.fatal("queryMailSender show stopper");
2470
          throw new Exception();
2471
        }
2472
      }
2473
    }
2474
 
2475
    mLogger.debug("queryMailSender returned " + retVal);
2476
    return retVal;
2477
  }
2478
 
2479
  /**called only in escrow mode
2480
   * if checkCollection is true, checks the pv_id is in the packageCollection
2481
   * if checkCollection is false, or the pv_id is not in the collection
2482
   * 1 traverses the pv_id package dependencies
2483
   *   select dpv.pv_id, p.pkg_name, dpv.pkg_version, dpv.v_ext, dpv.pkg_label, dpv.src_path
2484
   *   from release_manager.package_versions pv, release_manager.package_dependencies pd, release_manager.package_versions dpv, release_manager.packages p
2485
   *   where pv.pv_id = <pv_id> and pd.pv_id=pv.pv_id and dpv.pv_id=pd.dpv_id and p.pkg_id=dpv.pkg_id
2486
   *   order by pv.pv_id;
2487
   * 2 for each dpv.pv_id in the resultset
2488
   *     call traverseDependencies( packageCollection, dpv.pv_id, true )
2489
   *     if the pv_id is not in the collection, add it
2490
   *   
2491
   */
2492
  private void traverseDependencies(Vector packageCollection, Package pkg, 
2493
                                     boolean checkCollection, 
2494
                                     ListIterator listIterator) throws SQLException, Exception
2495
  {
2496
    mLogger.debug("traverseDependencies " + checkCollection);
2497
    boolean pvIdInCollection = false;
2498
 
2499
    if ( checkCollection )
2500
    {
2501
      for (Iterator it = packageCollection.iterator(); it.hasNext(); )
2502
      {
2503
        Package p = (Package) it.next();
2504
 
2505
        if ( p.mId == pkg.mId )
2506
        {
2507
          pvIdInCollection = true;
2508
          break;
2509
        }
2510
      }
2511
    }
2512
 
2513
    if ( !pvIdInCollection )
2514
    {
2515
      Vector resultset = new Vector();
2516
 
2517
      if ( !mUseDatabase )
2518
      {
2519
        mLogger.info("traverseDependencies !mUseDatabase");
2520
 
2521
        if ( pkg.mId == 8 || pkg.mId == 10 || pkg.mId == 13 )
2522
        {
2523
          Package p = new Package(9, "CommonDependency", "1.0.0000.tim", ".tim", "CommonDependency.1.0.0000.tim", "CommonDependency_1.0.0000.tim", "\\vob\\CommonDependency", 'x');
2524
          resultset.add(p);
2525
          pkg.mDependencyCollection.add(p.mAlias);
2526
        }
2527
        else if ( pkg.mId == 9 )
2528
        {
2529
          Package p = new Package(7, "CotsWithFunnyVersion", "hoopla2_x.cots", ".cots", "CotsWithFunnyVersion.hoopla2_x.cots", "CotsWithFunnyVersion_hoopla2_x.cots", "\\vob\\CotsWithFunnyVersion", 'x');
2530
          resultset.add(p);
2531
          pkg.mDependencyCollection.add(p.mAlias);
2532
        }
2533
        else if ( pkg.mId == 11 )
2534
        {
2535
          Package p = new Package(14, "AdvisoryDependency", "1.0.0000.tim", ".tim", "AdvisoryDependency.1.0.0000.tim", "AdvisoryDependency_1.0.0000.tim", "\\vob\\AdvisoryDependency", 'x');
2536
          resultset.add(p);
2537
          pkg.mDependencyCollection.add(p.mAlias);
2538
        }
2539
      }
2540
      else
2541
      {
2542
        try
2543
        {
2544
          CallableStatement stmt = mConnection.prepareCall(
2545
          "select dpv.pv_id, p.pkg_name, dpv.pkg_version, dpv.v_ext, dpv.pkg_label, dpv.src_path " +
2546
          "from release_manager.package_versions pv, release_manager.package_dependencies pd, release_manager.package_versions dpv, release_manager.packages p " +
2547
          "where pv.pv_id=" + pkg.mId + " and pd.pv_id=pv.pv_id and dpv.pv_id=pd.dpv_id and p.pkg_id=dpv.pkg_id " +
2548
          "order by pv.pv_id"
2549
          );
2550
          ResultSet rset = stmt.executeQuery();
2551
 
2552
          while( rset.next() )
2553
          {
2554
            int pv_id = rset.getInt("pv_id");
2555
 
2556
            if ( rset.wasNull() )
2557
            {
2558
              mLogger.fatal("traverseDependencies null pv_id");
2559
              // show stopper
2560
              throw new Exception();
2561
            }
2562
 
2563
            String pkg_name = rset.getString("pkg_name");
2564
 
2565
            if ( pkg_name == null )
2566
            {
2567
              mLogger.fatal("traverseDependencies null pkg_name " + pv_id);
2568
              // show stopper
2569
              throw new Exception();
2570
            }
2571
 
2572
            String pkg_version = rset.getString("pkg_version");
2573
 
2574
            if ( pkg_version == null )
2575
            {
2576
              mLogger.fatal("traverseDependencies null pkg_version " + pv_id);
2577
              // show stopper
2578
              throw new Exception();
2579
            }
2580
 
2581
            String v_ext = rset.getString("v_ext");
2582
 
2583
            if ( v_ext == null )
2584
            {
2585
              v_ext = "";
2586
            }
2587
 
2588
            String pkg_label = rset.getString("pkg_label");
2589
 
2590
            if ( pkg_label == null )
2591
            {
2592
              pkg_label = "NA";
2593
            }
2594
 
2595
            String src_path = rset.getString("src_path");
2596
 
2597
            if ( src_path == null )
2598
            {
2599
              src_path = "NA";
2600
            }
2601
 
2602
            Package p = new Package(pv_id, pkg_name, pkg_version, v_ext, pkg_name + "." + pkg_version, pkg_label, src_path, 'x');
2603
            resultset.add(p);
2604
            pkg.mDependencyCollection.add(p.mAlias);
2605
          }
830 mhunt 2606
 
2607
          rset.close();
2608
          stmt.close();
814 mhunt 2609
        }
2610
        catch ( SQLException e )
2611
        {
2612
          if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
2613
          {
2614
            mLogger.fatal("traverseDependencies database access error only");
2615
            throw new SQLException();
2616
          }
2617
          else
2618
          {
2619
            mLogger.fatal("traverseDependencies show stopper");
2620
            throw new Exception();
2621
          }
2622
        }
2623
      }
2624
 
2625
      for (Iterator it = resultset.iterator(); it.hasNext(); )
2626
      {
2627
        Package r = (Package) it.next();
2628
        traverseDependencies(packageCollection, r, true, listIterator);
2629
 
2630
        pvIdInCollection = false;
2631
 
2632
        for (Iterator it2 = packageCollection.iterator(); it2.hasNext(); )
2633
        {
2634
          Package p = (Package) it2.next();
2635
 
2636
          if ( p.mId == r.mId )
2637
          {
2638
            pvIdInCollection = true;
2639
            break;
2640
          }
2641
        }
2642
 
2643
        if (!pvIdInCollection)
2644
        {
2645
          // insert the Package immediately before the next Package returned by next
2646
          // this does not change the next Package (if any) to be returned by next
2647
          listIterator.add(r);
2648
        }
2649
 
2650
      }
2651
    }
2652
  }
2653
 
2654
  /**returns the Package with the matching mID or NULL_PACKAGE if no package has the mID
2655
   */
2656
  private Package findPackage(int id, Vector packageCollection)
2657
  {
2658
    mLogger.debug("findPackage 1 id " + id);
2659
    Package retVal = NULL_PACKAGE;
2660
 
2661
    for (Iterator it = packageCollection.iterator(); it.hasNext(); )
2662
    {
2663
      Package p = (Package) it.next();
2664
 
2665
      if ( p.mId == id )
2666
      {
2667
        retVal = p;
2668
        break;
2669
      }
2670
    }
2671
 
2672
    mLogger.debug("findPackage 1 returned " + retVal.mName);
2673
    return retVal;
2674
  }
2675
 
2676
  /**called only in escrow mode to add build info to the Package
2677
   * select bm.bm_name, bsa.bsa_name
2678
   * from release_manager.package_versions pv, release_manager.package_build_info pbi, release_manager.build_machines bm, release_manager.build_standards_addendum bsa
2679
   * where pv.pv_id = <p.pv_id> and pbi.pv_id=pv.pv_id and bm.bm_id=pbi.bm_id and bsa.bsa_id=pbi.bsa_id
2680
   * order by pv.pv_id;
2681
   */
2682
  private void queryBuildInfo(RippleEngine rippleEngine, Package p) throws SQLException, Exception
2683
  {
2684
    mLogger.debug("queryBuildInfo");
2685
    if ( !mUseDatabase )
2686
    {
2687
      mLogger.info("queryBuildInfo !mUseDatabase");
2688
 
2689
      if (p.mId == 7)
2690
      {
2691
        BuildStandard bs = new BuildStandard(rippleEngine);
2692
        bs.setSolaris();
2693
        bs.setDebug();
2694
        p.mBuildStandardCollection.add(bs);
2695
      }
2696
      else if (p.mId == 9)
2697
      {
2698
        BuildStandard bs = new BuildStandard(rippleEngine);
2699
        bs.setLinux();
2700
        bs.setDebug();
2701
        p.mBuildStandardCollection.add(bs);
2702
        bs = new BuildStandard(rippleEngine);
2703
        bs.setSolaris();
2704
        bs.setDebug();
2705
        p.mBuildStandardCollection.add(bs);
2706
        bs = new BuildStandard(rippleEngine);
2707
        bs.setWin32();
2708
        bs.setProduction();
2709
        p.mBuildStandardCollection.add(bs);
2710
      }
2711
      else if (p.mId == 10)
2712
      {
2713
        BuildStandard bs = new BuildStandard(rippleEngine);
2714
        bs.setSolaris();
2715
        bs.set1_4();
2716
        p.mBuildStandardCollection.add(bs);
2717
      }
2718
      else if (p.mId == 11)
2719
      {
2720
        BuildStandard bs = new BuildStandard(rippleEngine);
2721
        bs.setLinux();
2722
        bs.setAll();
2723
        p.mBuildStandardCollection.add(bs);
2724
      }
2725
      else if (p.mId == 12)
2726
      {
2727
        BuildStandard bs = new BuildStandard(rippleEngine);
2728
        bs.setWin32();
2729
        bs.set1_6();
2730
        p.mBuildStandardCollection.add(bs);
2731
      }
2732
      else if (p.mId == 13)
2733
      {
2734
        BuildStandard bs = new BuildStandard(rippleEngine);
2735
        bs.setGeneric();
2736
        bs.set1_4();
2737
        p.mBuildStandardCollection.add(bs);
2738
      }
2739
      else if (p.mId == 14)
2740
      {
2741
        BuildStandard bs = new BuildStandard(rippleEngine);
2742
        bs.setLinux();
2743
        bs.setDebug();
2744
        p.mBuildStandardCollection.add(bs);
2745
      }
2746
 
2747
    }
2748
    else
2749
    {
2750
      try
2751
      {
2752
        CallableStatement stmt = mConnection.prepareCall(
2753
        "select bm.bm_name, bsa.bsa_name " +
2754
        "from release_manager.package_versions pv, release_manager.package_build_info pbi, release_manager.build_machines bm, release_manager.build_standards_addendum bsa " +
2755
        "where pv.pv_id=" + p.mId + " and pbi.pv_id=pv.pv_id and bm.bm_id=pbi.bm_id and bsa.bsa_id=pbi.bsa_id " +
2756
        "order by pv.pv_id"
2757
        );
2758
        ResultSet rset = stmt.executeQuery();
2759
 
2760
        while( rset.next() )
2761
        {
2762
          boolean supportedBuildStandard = true;
2763
          BuildStandard bs = new BuildStandard(rippleEngine);
2764
          String bm_name = rset.getString("bm_name");
2765
 
2766
          if ( bm_name == null )
2767
          {
2768
            mLogger.fatal("queryBuildInfo null bm_name " + p.mId);
2769
            // show stopper
2770
            throw new Exception();
2771
          }
2772
          else if ( bm_name.compareTo("Solaris") == 0 )
2773
          {
2774
            bs.setSolaris();
2775
          }
2776
          else if ( bm_name.compareTo("Win32") == 0 )
2777
          {
2778
            bs.setWin32();
2779
          }
2780
          else if ( bm_name.compareTo("Linux") == 0 )
2781
          {
2782
            bs.setLinux();
2783
          }
2784
          else if ( bm_name.compareTo("Generic") == 0 )
2785
          {
2786
            bs.setGeneric();
2787
          }
2788
          else
2789
          {
2790
            supportedBuildStandard = false;
2791
          }
2792
 
2793
          String bsa_name = rset.getString("bsa_name");
2794
 
2795
          if ( bsa_name == null )
2796
          {
2797
            mLogger.fatal("queryBuildInfo null bsa_name " + p.mId);
2798
            // show stopper
2799
            throw new Exception();
2800
          }
2801
          else if ( bsa_name.compareTo("Production") == 0 )
2802
          {
2803
            bs.setProduction();
2804
          }
2805
          else if ( bsa_name.compareTo("Debug") == 0 )
2806
          {
2807
            bs.setDebug();
2808
          }
2809
          else if ( bsa_name.compareTo("Production and Debug") == 0 )
2810
          {
2811
            bs.setAll();
2812
          }
2813
          else if ( bsa_name.compareTo("Java 1.4") == 0 )
2814
          {
2815
            bs.set1_4();
2816
          }
2817
          else if ( bsa_name.compareTo("Java 1.5") == 0 )
2818
          {
2819
            bs.set1_5();
2820
          }
2821
          else if ( bsa_name.compareTo("Java 1.6") == 0 )
2822
          {
2823
            bs.set1_6();
2824
          }
2825
          else
2826
          {
2827
            supportedBuildStandard = false;
2828
          }
2829
 
2830
          if ( supportedBuildStandard )
2831
          {
2832
            p.mBuildStandardCollection.add(bs);
2833
          }
2834
        }
830 mhunt 2835
 
2836
        rset.close();
2837
        stmt.close();
814 mhunt 2838
      }
2839
      catch ( SQLException e )
2840
      {
2841
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
2842
        {
2843
          mLogger.error("queryBuildInfo database access error only");
2844
          throw new SQLException();
2845
        }
2846
        else
2847
        {
2848
          mLogger.fatal("queryBuildInfo show stopper");
2849
          throw new Exception();
2850
        }
2851
      }
2852
    }
2853
  }
2854
 
2855
  /**returns the Package with the matching mAlias or NULL_PACKAGE if no package has the mAlias
2856
   */
2857
  private Package findPackage(String alias, Vector packageCollection)
2858
  {
2859
    mLogger.debug("findPackage 2 alias " + alias);
2860
    Package retVal = NULL_PACKAGE;
2861
 
2862
    for (Iterator it = packageCollection.iterator(); it.hasNext(); )
2863
    {
2864
      Package p = (Package) it.next();
2865
 
2866
      if ( p.mAlias.compareTo( alias ) == 0 )
2867
      {
2868
        retVal = p;
2869
        break;
2870
      }
2871
    }
844 dpurdie 2872
 
814 mhunt 2873
    mLogger.info("findPackage 2 returned " + retVal.mName);
2874
    return retVal;
2875
  }
2876
 
2877
  /**essentially locks the row in the BUILD_SERVICE_CONFIG table with a service of MUTEX
2878
   * for the duration of the connection
2879
   * this prevents other MasterThreads from generating build files in parallel
2880
   * and hence prevents planned version numbering contention
2881
   * select CONFIG from BUILD_SERVICE_CONFIG WHERE SERVICE='MUTEX' FOR UPDATE
2882
   */
2883
  public void claimMutex() throws SQLException, Exception
2884
  {
2885
    mLogger.debug("claimMutex");
2886
    if ( mUseDatabase )
2887
    {
2888
      try
2889
      {
2890
        CallableStatement stmt = mConnection.prepareCall("select CONFIG from release_manager.BUILD_SERVICE_CONFIG WHERE SERVICE='MUTEX' FOR UPDATE");
2891
        stmt.executeUpdate();
844 dpurdie 2892
        stmt.close();
814 mhunt 2893
      }
2894
      catch ( SQLException e )
2895
      {
2896
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
2897
        {
2898
          mLogger.error("claimMutex database access error only");
2899
          throw new SQLException();
2900
        }
2901
        else
2902
        {
2903
          mLogger.fatal("claimMutex show stopper");
2904
          throw new Exception();
2905
        }
2906
      }
2907
    }
2908
  }
2909
 
2910
  /**sets CURRENT_BUILD_FILES to NULL for the rcon_id
2911
   * update run_level set current_build_files=null where rcon_id=<rcon_id>
2912
   * returns true if successful
2913
   */
2914
  public boolean clearBuildFile(int rcon_id) throws SQLException, Exception
2915
  {
2916
    mLogger.debug("clearBuildFile");
2917
    boolean retVal = false;
2918
 
2919
    try
2920
    {
2921
      connect();
2922
      CallableStatement stmt = mConnection.prepareCall("update release_manager.run_level set current_build_files=null where rcon_id=" + rcon_id);
2923
      stmt.executeUpdate();
844 dpurdie 2924
      stmt.close();
814 mhunt 2925
      mConnection.commit();
2926
      disconnect();
2927
      retVal = true;
2928
    }
2929
    catch ( SQLException e )
2930
    {
2931
      if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
2932
      {
2933
        mLogger.error("clearBuildFile database access error only");
2934
        throw new SQLException();
2935
      }
2936
      else
2937
      {
2938
        mLogger.fatal("clearBuildFile show stopper");
2939
        throw new Exception();
2940
      }
2941
    }
2942
 
2943
    mLogger.info("clearBuildFile returned " + retVal);
2944
    return retVal;
2945
  }
2946
 
2947
  /**updates the CURRENT_BUILD_FILES for the rtag_id
2948
   * update (
2949
   * select current_build_files from run_level rl, release_config rc
2950
   * where rc.rtag_id=<rtag_id> and rl.rcon_id=rc.rcon_id
2951
   * ) set current_build_files=<buildFile>
2952
   * returns true if successful
2953
   */
2954
  public boolean publishBuildFile(int rtag_id, String buildFile) throws SQLException, Exception
2955
  {
2956
    mLogger.debug("publishBuildFile publishing a build file of length " + buildFile.length());
2957
    boolean retVal = false;
2958
 
2959
    try
2960
    {
2961
      connect();
2962
 
2963
      PreparedStatement stmt = mConnection.prepareStatement(
2964
      "update (" +
2965
      "select current_build_files from release_manager.run_level rl, release_manager.release_config rc " +
2966
      "where rc.rtag_id=? and rl.rcon_id=rc.rcon_id" +
2967
      ") set current_build_files=?");
2968
      stmt.setInt(1, rtag_id);
2969
      stmt.setString(2, buildFile);
2970
      stmt.executeUpdate();
2971
      mConnection.commit();
844 dpurdie 2972
      stmt.close();
814 mhunt 2973
      disconnect();
2974
      retVal = true;
2975
    }
2976
    catch ( SQLException e )
2977
    {
2978
      if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
2979
      {
2980
        mLogger.error("publishBuildFile database access error only");
2981
        throw new SQLException();
2982
      }
2983
      else
2984
      {
2985
        mLogger.fatal("publishBuildFile show stopper");
2986
        throw new Exception();
2987
      }
2988
    }
2989
    catch ( Exception e )
2990
    {
2991
      // this catch and rethrow is historical
2992
      // problems were found using CallableStatement when updating a CLOB column with data > 4000 bytes
2993
      mLogger.fatal("publishBuildFile caught Exception " + e.getMessage());
2994
      throw new Exception();
2995
    }
2996
    mLogger.info("publishBuildFile returned " + retVal);
2997
    return retVal;
2998
  }
2999
 
3000
  /**ensures a run_level_schedule row with a non null indefinite_pause column exists
3001
   * this is aimed at stopping all daemons dead
3002
   * it is raised when handling an unsupported exception case in either the main or slave daemons
3003
   * typically an SQLException other than a database connection related one
3004
   */
836 mhunt 3005
  public void indefinitePause() throws SQLException
814 mhunt 3006
  {
3007
    mLogger.debug("indefinitePause");
3008
    if ( mUseDatabase )
3009
    {
836 mhunt 3010
      try
3011
      {
814 mhunt 3012
      connect();
836 mhunt 3013
      CallableStatement stmt = mConnection.prepareCall( "begin PK_BUILDAPI.SET_INFINITE_PAUSE(); end;" );
814 mhunt 3014
      stmt.executeUpdate();
844 dpurdie 3015
      stmt.close();
814 mhunt 3016
      mConnection.commit();
3017
      disconnect();
836 mhunt 3018
      }
3019
      catch( SQLException e )
3020
      {
3021
        // do not throw Exception
3022
        // this is part of Exception handling
3023
        mLogger.fatal( "indefinitePause caught SQLException " + e.getMessage() );
3024
      }
3025
      catch( Exception e )
3026
      {
3027
        mLogger.fatal( "indefinitePause caught Exception " + e.getMessage() );
3028
      }
814 mhunt 3029
    }
3030
  }
3031
 
3032
  /**only used in daemon mode to determine version existence in the database
3033
   *  1 select pkg_id from package_versions where pkg_id=<pkg_id> and pkg_version=<pkg_version>;
3034
   *  2 select pkg_id from planned_versions where pkg_id=<pkg_id> and pkg_version=<pkg_version>;
3035
   * returns true if either resultset contains one record to indicate it already exists
3036
   */
3037
  boolean queryPackageVersions(int pkg_id, String pkg_version) throws SQLException, Exception
3038
  {
3039
    mLogger.debug("queryPackageVersions");
3040
    boolean retVal = false;
3041
 
3042
    if ( mUseDatabase )
3043
    {
3044
      try
3045
      {
3046
        mLogger.info("queryPackageVersions release_manager.package_versions");
3047
        CallableStatement stmt1 = mConnection.prepareCall("select pkg_id from release_manager.package_versions where pkg_id=" + pkg_id + " and pkg_version='" + pkg_version + "'");
3048
        ResultSet rset1 = stmt1.executeQuery();
3049
        int rsetSize = 0;
3050
 
3051
        while( rset1.next() )
3052
        {
3053
          rsetSize++;
3054
        }
830 mhunt 3055
 
3056
        rset1.close();
3057
        stmt1.close();
814 mhunt 3058
 
3059
        if ( rsetSize > 1 )
3060
        {
3061
          mLogger.fatal("queryPackageVersions rsetSize > 1 " + pkg_id + " " + pkg_version);
3062
          // show stopper
3063
          throw new Exception();
3064
        }
3065
 
3066
        if ( rsetSize == 1 )
3067
        {
3068
          retVal = true;
3069
        }
3070
        else
3071
        {
3072
          mLogger.info("queryPackageVersions release_manager.planned_versions");
3073
          CallableStatement stmt2 = mConnection.prepareCall("select pkg_id from release_manager.planned_versions where pkg_id=" + pkg_id + " and pkg_version='" + pkg_version + "'");
3074
          ResultSet rset2 = stmt2.executeQuery();
3075
          rsetSize = 0;
3076
 
3077
          while( rset2.next() )
3078
          {
3079
            rsetSize++;
3080
          }
830 mhunt 3081
 
3082
          rset2.close();
3083
          stmt2.close();
814 mhunt 3084
 
3085
          if ( rsetSize > 1 )
3086
          {
3087
            mLogger.fatal("queryPackageVersions rsetSize > 1 " + pkg_id + " " + pkg_version);
3088
            // show stopper
3089
            throw new Exception();
3090
          }
3091
 
3092
          if ( rsetSize == 1 )
3093
          {
3094
            retVal = true;
3095
          }
3096
          else
3097
          {
3098
            mLogger.info("queryPackageVersions archive_manager.package_versions");
3099
            CallableStatement stmt3 = mConnection.prepareCall("select pkg_id from archive_manager.package_versions where pkg_id=" + pkg_id + " and pkg_version='" + pkg_version + "'");
3100
            ResultSet rset3 = stmt3.executeQuery();
3101
            rsetSize = 0;
3102
 
3103
            while( rset3.next() )
3104
            {
3105
              rsetSize++;
3106
            }
830 mhunt 3107
 
3108
            rset3.close();
3109
            stmt3.close();
814 mhunt 3110
 
3111
            if ( rsetSize > 1 )
3112
            {
3113
              mLogger.fatal("queryPackageVersions rsetSize > 1 " + pkg_id + " " + pkg_version);
3114
              // show stopper
3115
              throw new Exception();
3116
            }
3117
 
3118
            if ( rsetSize == 1 )
3119
            {
3120
              retVal = true;
3121
            }
3122
          }
3123
        }
3124
      }
3125
      catch ( SQLException e )
3126
      {
3127
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3128
        {
3129
          mLogger.error("queryPackageVersions database access error only");
3130
          throw new SQLException();
3131
        }
3132
        else
3133
        {
3134
          mLogger.fatal("queryPackageVersions show stopper");
3135
          throw new Exception();
3136
        }
3137
      }
3138
    }
3139
 
3140
    mLogger.info("queryPackageVersions returned " + retVal);
3141
    return retVal;
3142
  }
3143
 
3144
  /**only used in daemon mode
3145
   *  insert into planned_versions (pkg_id, pkg_version) values (<pkg_id>, <pkg_version>);
3146
   *  update
3147
   *  (
3148
   *  select current_pkg_id_being_built from run_level rl, release_config rc
3149
   *  where rc.rtag_id=<rtag_id> and rl.rcon_id=rc.rcon_id
3150
   *  )
3151
   *  set current_pkg_id_being_built=<pkg_id>
3152
   */
3153
  void claimVersion(int pkg_id, String pkg_version, int rtag_id) throws SQLException, Exception
3154
  {
3155
    mLogger.debug("claimVersion " + pkg_id + " " + pkg_version);
3156
    if ( mUseDatabase )
3157
    {
3158
      try
3159
      {
3160
        CallableStatement stmt3 = mConnection.prepareCall("insert into release_manager.planned_versions (pkg_id, pkg_version) values (" + pkg_id + ", '" + pkg_version + "')");
3161
        stmt3.executeUpdate();
844 dpurdie 3162
        stmt3.close();
814 mhunt 3163
        CallableStatement stmt4 = mConnection.prepareCall(
3164
        "update " +
3165
        "(" +
3166
        "select current_pkg_id_being_built from release_manager.run_level rl, release_manager.release_config rc " +
3167
        "where rc.rtag_id=" + rtag_id + " and rl.rcon_id=rc.rcon_id" +
3168
        ")" +
3169
        "set current_pkg_id_being_built=" + pkg_id);
3170
        stmt4.executeUpdate();
844 dpurdie 3171
        stmt4.close();
814 mhunt 3172
        mConnection.commit();
3173
      }
3174
      catch ( SQLException e )
3175
      {
3176
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3177
        {
3178
          mLogger.error("claimVersion database access error only");
3179
          throw new SQLException();
3180
        }
3181
        else
3182
        {
3183
          mLogger.fatal("claimVersion show stopper");
3184
          throw new Exception();
3185
        }
3186
      }
3187
    }
3188
  }
3189
 
818 mhunt 3190
  /**only used in daemon mode
3191
   *  update
3192
   *  (
3193
   *  select current_pkg_id_being_built from run_level
3194
   *  where rcon_id=<rcon_id>
3195
   *  )
3196
   *  set current_pkg_id_being_built=null
3197
   */
3198
  public void clearCurrentPackageBeingBuilt(int rcon_id) throws SQLException, Exception
3199
  {
3200
    mLogger.debug("clearCurrentPackageBeingBuilt " + rcon_id);
3201
    if ( mUseDatabase )
3202
    {
3203
      try
3204
      {
820 mhunt 3205
        connect();
818 mhunt 3206
        CallableStatement stmt4 = mConnection.prepareCall(
3207
        "update " +
3208
        "(" +
3209
        "select current_pkg_id_being_built from run_level " +
3210
        "where rcon_id=" + rcon_id +
3211
        ")" +
3212
        "set current_pkg_id_being_built=null" );
3213
        stmt4.executeUpdate();
844 dpurdie 3214
        stmt4.close();
818 mhunt 3215
        mConnection.commit();
820 mhunt 3216
        disconnect();
818 mhunt 3217
      }
3218
      catch ( SQLException e )
3219
      {
3220
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3221
        {
3222
          mLogger.error("clearCurrentPackageBeingBuilt database access error only");
3223
          throw new SQLException();
3224
        }
3225
        else
3226
        {
3227
          mLogger.fatal("clearCurrentPackageBeingBuilt show stopper");
3228
          throw new Exception();
3229
        }
3230
      }
3231
    }
3232
  }
3233
 
814 mhunt 3234
  /**handles database connection/disconnection
3235
   * executes the AutoMakeRelease stored procedure with the passed parameters
3236
   */
3237
  public void autoMakeRelease(String rtagId, String packageName, 
3238
                              String packageExtension, 
3239
                              String packageVersion, String packageLabel, 
3240
                              String packageDepends, String isRipple) throws SQLException, Exception
3241
  {
3242
    mLogger.debug("autoMakeRelease " + packageName);
3243
    if ( mUseDatabase )
3244
    {
3245
      try
3246
      {
3247
        connect();
3248
        CallableStatement stmt = mConnection.prepareCall( "begin ? := PK_RMAPI.AUTO_MAKE_RELEASE(?,?,?,?,?,?,?,?); end;" );
3249
        stmt.registerOutParameter( 1, Types.INTEGER);
3250
        stmt.setString( 2, rtagId );
3251
        stmt.setString( 3, packageName );
3252
        stmt.setString( 4, packageExtension );
3253
        stmt.setString( 5, packageVersion );
3254
        stmt.setString( 6, packageLabel );
3255
        stmt.setString( 7, packageDepends );
3256
        stmt.setString( 8, isRipple );
3257
        stmt.setString( 9, "buildadm" );
3258
        stmt.executeUpdate();
3259
        int result = stmt.getInt( 1 );
3260
 
3261
        if ( result <= 0 && result != -2 )
3262
        {
3263
          // -2 if already released
3264
          // flag build failure
3265
          mLogger.fatal("autoMakeRelease show stopper PK_RMAPI.AUTO_MAKE_RELEASE failed, returned" + result);
3266
          throw new Exception();
3267
        }
844 dpurdie 3268
        stmt.close();
814 mhunt 3269
        mConnection.commit();
3270
        disconnect();
3271
      }
3272
      catch( SQLException e )
3273
      {
3274
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3275
        {
3276
          mLogger.error("autoMakeRelease database access error only");
3277
          throw new SQLException();
3278
        }
3279
        else
3280
        {
3281
          mLogger.fatal("autoMakeRelease show stopper");
3282
          throw new Exception();
3283
        }
3284
      }
3285
    }
3286
  }
3287
 
3288
  /**handles database connection/disconnection
834 mhunt 3289
   * executes the insertPackageMetrics stored procedure with the passed parameters
3290
   */
3291
  public void insertPackageMetrics(String rtagId, String packageName, 
3292
                              		 String packageExtension, String metrics) throws SQLException, Exception
3293
  {
3294
    mLogger.debug("insertPackageMetrics " + packageName);
3295
    if ( mUseDatabase )
3296
    {
3297
      try
3298
      {
3299
        connect();
3300
        CallableStatement stmt = mConnection.prepareCall( "begin ? := PK_RMAPI.INSERT_PACKAGE_METRICS(?,?,?,?); end;" );
3301
        stmt.registerOutParameter( 1, Types.INTEGER);
3302
        stmt.setString( 2, rtagId );
3303
        stmt.setString( 3, packageName );
3304
        stmt.setString( 4, packageExtension );
3305
        stmt.setString( 5, metrics );
3306
        stmt.executeUpdate();
3307
        int result = stmt.getInt( 1 );
3308
 
836 mhunt 3309
        if ( result != 0 )
834 mhunt 3310
        {
3311
          // flag build failure
3312
          mLogger.fatal("insertPackageMetrics show stopper PK_RMAPI.INSERT_PACKAGE_METRICS failed, returned" + result);
3313
          throw new Exception();
3314
        }
844 dpurdie 3315
        stmt.close();
834 mhunt 3316
        mConnection.commit();
3317
        disconnect();
3318
      }
3319
      catch( SQLException e )
3320
      {
3321
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3322
        {
3323
          mLogger.error("insertPackageMetrics database access error only");
3324
          throw new SQLException();
3325
        }
3326
        else
3327
        {
3328
          mLogger.fatal("insertPackageMetrics show stopper");
3329
          throw new Exception();
3330
        }
3331
      }
3332
    }
3333
  }
3334
 
3335
  /**handles database connection/disconnection
814 mhunt 3336
   * executes the ExcludeFromBuild stored procedure with the passed parameters
3337
   */
3338
  public void excludeFromBuild(String packageVersionId, 
3339
                               String packageVersion, String rtagId) throws SQLException, Exception
3340
  {
3341
    mLogger.debug("excludeFromBuild " + packageVersionId);
3342
    if ( mUseDatabase )
3343
    {
3344
      try
3345
      {
3346
        connect();
3347
        CallableStatement stmt = mConnection.prepareCall( "begin ? := PK_RMAPI.EXCLUDE_FROM_BUILD(?,?,?,?); end;" );
3348
        stmt.registerOutParameter( 1, Types.INTEGER);
3349
        stmt.setString( 2, packageVersionId );
3350
        stmt.setString( 3, packageVersion );
3351
        stmt.setString( 4, rtagId );
3352
        stmt.setString( 5, "buildadm" );
3353
        stmt.executeUpdate();
3354
        int result = stmt.getInt( 1 );
3355
 
3356
        if ( result != 0 )
3357
        {
3358
          // flag build failure
3359
          mLogger.fatal( "excludeFromBuild show stopper PK_RMAPI.EXCLUDE_FROM_BUILD failed, returned " + result );
3360
          throw new Exception();
3361
        }
844 dpurdie 3362
        stmt.close();
814 mhunt 3363
        mConnection.commit();
3364
        disconnect();
3365
      }
3366
      catch( SQLException e )
3367
      {
3368
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3369
        {
3370
          mLogger.error("excludeFromBuild database access error only");
3371
          throw new SQLException();
3372
        }
3373
        else
3374
        {
3375
          mLogger.fatal("excludeFromBuild show stopper");
3376
          throw new Exception();
3377
        }
3378
      }
3379
    }
3380
  }
3381
 
3382
  /**Representation of a row in the RELEASE_CONFIG table
3383
   */
3384
  private class ReleaseConfig
3385
  {
3386
    /**rtag_id column value
3387
     * @attribute
3388
     */
3389
    private int mRtag_id;
3390
 
3391
    /**rcon_id column value
3392
     * @attribute
3393
     */
3394
    private int mRcon_id;
3395
 
3396
    /**daemon_mode column value
3397
     * @attribute
3398
     */
3399
    private char mDaemon_mode;
3400
 
3401
    /**gbebuildfilter column value
3402
     * @attribute
3403
     */
3404
    private String mGbebuildfilter;
3405
 
3406
    /**constructor
3407
     */
3408
    ReleaseConfig(int rtag_id, int rcon_id, char daemon_mode, 
3409
                  String gbebuildfilter)
3410
    {
3411
      mLogger.debug("ReleaseConfig rtag_id " + rtag_id + " rcon_id " + rcon_id + " daemon_mode " + daemon_mode + " gbebuildfilter " + gbebuildfilter );
3412
      mRtag_id = rtag_id;
3413
      mRcon_id = rcon_id;
3414
      mDaemon_mode = daemon_mode;
3415
      mGbebuildfilter = gbebuildfilter;
3416
    }
3417
 
3418
    /**accessor method
3419
     */
3420
    int get_rtag_id()
3421
    {
3422
      mLogger.debug("get_rtag_id");
3423
      mLogger.info("get_rtag_id returned " + mRtag_id);
3424
      return mRtag_id;
3425
    }
3426
 
3427
    /**accessor method
3428
     */
3429
    int get_rcon_id()
3430
    {
3431
      mLogger.debug("get_rcon_id");
3432
      mLogger.info("get_rcon_id returned " + mRcon_id);
3433
      return mRcon_id;
3434
    }
3435
 
3436
    /**accessor method
3437
     */
3438
    char get_daemon_mode()
3439
    {
3440
      mLogger.debug("get_daemon_mode");
3441
      mLogger.info("get_daemon_mode returned " + mDaemon_mode);
3442
      return mDaemon_mode;
3443
    }
3444
 
3445
    /**accessor method
3446
     */
3447
    String get_gbebuildfilter()
3448
    {
3449
      mLogger.debug("get_gbebuildfilter");
3450
      mLogger.info("get_gbebuildfilter returned " + mGbebuildfilter);
3451
      return mGbebuildfilter;
3452
    }
3453
  }
3454
 
3455
  /**Representation of a row in the RUN_LEVEL table
3456
   */
3457
  private class RunLevel
3458
  {
3459
    /**rcon_id column value
3460
     * @attribute
3461
     */
3462
    private int mRcon_id;
3463
 
3464
    /**current_build_files column value
3465
     * @attribute
3466
     */
3467
    private String mCurrent_build_file;
3468
 
3469
    /**current_run_level column value
3470
     * @attribute
3471
     */
3472
    private int mCurrent_run_level;
3473
 
3474
    /**pause column value
3475
     * @attribute
3476
     */
3477
    private boolean mPause;
3478
 
3479
    /**constructor
3480
     */
3481
    RunLevel(int rcon_id, String current_build_file, int current_run_level, 
3482
             boolean pause)
3483
    {
3484
      mLogger.debug("RunLevel");
3485
      mRcon_id = rcon_id;
3486
      mCurrent_build_file = current_build_file;
3487
      mCurrent_run_level = current_run_level;
3488
      mPause = pause;
3489
    }
3490
 
3491
    /**accessor method
3492
     */
3493
    int get_rcon_id()
3494
    {
3495
      mLogger.debug("get_rcon_id");
3496
      mLogger.info("get_rcon_id returned " + mRcon_id);
3497
      return mRcon_id;
3498
    }
3499
 
3500
    /**accessor method
3501
     */
3502
    String get_current_build_file()
3503
    {
3504
      mLogger.debug("get_current_build_file");
3505
      mLogger.info("get_current_build_file returned " + mCurrent_build_file);
3506
      return mCurrent_build_file;
3507
    }
3508
 
3509
    /**accessor method
3510
     */
3511
    int get_current_run_level()
3512
    {
3513
      mLogger.debug("get_current_run_level");
3514
      mLogger.info("get_current_run_level returned " + mCurrent_run_level);
3515
      return mCurrent_run_level;
3516
    }
3517
 
3518
    /**accessor method
3519
     */
3520
    boolean get_pause()
3521
    {
3522
      mLogger.debug("get_pause");
3523
      mLogger.debug("get_pause returned " + mPause);      
3524
      return mPause;
3525
    }
3526
 
3527
  }
3528
 
3529
  /**constructor
3530
   */
3531
  public ReleaseManager(final String connectionString, final String username, 
3532
                        final String password)
3533
  {
3534
    mLogger.debug("ReleaseManager " + connectionString);
3535
    mConnectionString = connectionString;
3536
    mUsername = username;
3537
    mPassword = password;
3538
  }
3539
 
3540
  /**constructor used when schema information is unknown eg location, username, password
3541
   */
3542
  public ReleaseManager()
3543
  {
3544
    // inherit mConnectionString, mUsername, mPassword
3545
     mLogger.debug("ReleaseManager");
3546
  }
3547
 
3548
  /**connect to oracle
3549
   */
3550
  public void connect() throws SQLException, Exception
3551
  {
3552
    mLogger.debug("connect");
850 mhunt 3553
    mSession.lock();
814 mhunt 3554
 
3555
    if ( !mUseDatabase )
3556
    {
3557
      mLogger.info("connect !mUseDatabase");
3558
    }
3559
    else
3560
    {
3561
      if ( !mRegistered )
3562
      {
3563
        try
3564
        {
3565
          // the JDBC driver is registered only once per database that needs to be accessed
3566
          mLogger.debug("connect registering driver");
3567
          DriverManager.registerDriver( new OracleDriver() );
3568
          mRegistered = true;
3569
        }
3570
        catch(SQLException e)
3571
        {
3572
          mLogger.fatal("connect failed to register the oracle jdbc driver with the driver manager");
3573
          throw new Exception();
3574
        }
3575
      }
3576
 
838 mhunt 3577
      // DEVI 46868
3578
      // loop indefinitely until a connection attempt succeeds
3579
      // unless the failure is on the first attempt
3580
      boolean problemConnecting;
3581
 
3582
      do
814 mhunt 3583
      {
850 mhunt 3584
        mLogger.warn("connect check connection");
838 mhunt 3585
        problemConnecting = false;
3586
 
3587
        try
836 mhunt 3588
        {
850 mhunt 3589
          if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
838 mhunt 3590
          {
850 mhunt 3591
            mLogger.warn("connect calling getConnection");
838 mhunt 3592
            mConnection = DriverManager.getConnection(mConnectionString, mUsername, mPassword);
3593
          }
836 mhunt 3594
        }
838 mhunt 3595
        catch(SQLException e)
3596
        {
850 mhunt 3597
          mLogger.warn("connect determined problem connecting");
838 mhunt 3598
          problemConnecting = true;
3599
          try
3600
          {
3601
            // sleep 30 secs
844 dpurdie 3602
            mLogger.warn("connect getConnection failed. sleep 30secs");
838 mhunt 3603
            Thread.sleep(30000);
3604
          }
3605
          catch (InterruptedException f)
3606
          {
3607
            mLogger.warn("connect caught InterruptedException");
3608
          }
3609
 
844 dpurdie 3610
 
838 mhunt 3611
          if ( mConnection == null )
3612
          {
3613
            // failed on first connection attempt - unlikely due to database loading - likely bad connection parameters
3614
            throw new SQLException();
3615
          }
3616
        }
3617
      } while ( problemConnecting );
814 mhunt 3618
    }
844 dpurdie 3619
 
814 mhunt 3620
  }
3621
 
3622
  /**disconnect from oracle
3623
   */
836 mhunt 3624
  public void disconnect() throws Exception
814 mhunt 3625
  {
3626
    mLogger.debug("disconnect");
838 mhunt 3627
/* DEVI 46868 
3628
 * never disconnect, thus the only time a connection attempt is made
3629
 * is when the server has (timed out) disconnected the session
3630
 *  if ( mUseDatabase )
814 mhunt 3631
    {
3632
      try
3633
      {
3634
        mConnection.close();
3635
      }
3636
      catch(SQLException e)
3637
      {
3638
        mLogger.error("disconnect caught Exception");
836 mhunt 3639
        throw new Exception();
814 mhunt 3640
      }
838 mhunt 3641
    }*/
850 mhunt 3642
    mSession.unlock();
814 mhunt 3643
  }
3644
 
3645
  /**returns true if the mReleaseConfigCollection is not empty and returns the rcon_id of the first element
3646
   */
3647
  public boolean getFirstReleaseConfig(MutableInt rcon_id)
3648
  {
3649
    mLogger.debug("getFirstReleaseConfig 1");
3650
    boolean retVal = true;
3651
 
3652
    try
3653
    {
3654
      mReleaseConfigIndex = 0;
3655
      ReleaseConfig rc = (ReleaseConfig)mReleaseConfigCollection.get( mReleaseConfigIndex );
3656
      rcon_id.value = rc.get_rcon_id();
3657
    }
3658
    catch( ArrayIndexOutOfBoundsException e )
3659
    {
3660
      retVal = false;
3661
    }
3662
 
3663
    mLogger.info("getFirstReleaseConfig 1 returning " + retVal);
3664
    return retVal;
3665
  }
3666
 
3667
  /**returns true if the mReleaseConfigCollection is not empty and returns the rcon_id, rtag_id, daemon_mode and gbebuildfilter of the first element
3668
   */
3669
  public boolean getFirstReleaseConfig(MutableInt rtag_id, 
3670
                                       MutableInt rcon_id, 
3671
                                       MutableChar daemon_mode, 
3672
                                       MutableString gbebuildfilter)
3673
  {
3674
    mLogger.debug("getFirstReleaseConfig 2");
3675
    boolean retVal = true;
3676
 
3677
    try
3678
    {
3679
      mReleaseConfigIndex = 0;
3680
      ReleaseConfig rc = (ReleaseConfig)mReleaseConfigCollection.get( mReleaseConfigIndex );
3681
      rtag_id.value = rc.get_rtag_id();
3682
      rcon_id.value = rc.get_rcon_id();
3683
      daemon_mode.value = rc.get_daemon_mode();
3684
      gbebuildfilter.value = rc.get_gbebuildfilter();
3685
    }
3686
    catch( ArrayIndexOutOfBoundsException e )
3687
    {
3688
      retVal = false;
3689
    }
3690
 
3691
    mLogger.info("getFirstReleaseConfig 2 returning " + retVal);
3692
    return retVal;
3693
  }
3694
 
3695
  /**returns true if the mRunLevelCollection is not empty and returns the rcon_id and current_run_level of the first element
3696
   */
3697
  public boolean getFirstRunLevel(MutableInt rcon_id, 
3698
                                  MutableInt current_run_level)
3699
  {
3700
    mLogger.debug("getFirstRunLevel");
3701
    boolean retVal = true;
3702
 
3703
    try
3704
    {
3705
      mRunLevelIndex = 0;
3706
      RunLevel rl = (RunLevel)mRunLevelCollection.get( mRunLevelIndex );
3707
      rcon_id.value = rl.get_rcon_id();
3708
      current_run_level.value = rl.get_current_run_level();
3709
    }
3710
    catch( ArrayIndexOutOfBoundsException e )
3711
    {
3712
      retVal = false;
3713
    }
3714
 
3715
    mLogger.info("getFirstRunLevel returning " + retVal);
3716
    return retVal;
3717
  }
3718
 
3719
  /**returns true if the mReleaseConfigCollection contains a next element and returns the rcon_id of the next element
3720
   */
3721
  public boolean getNextReleaseConfig(MutableInt rcon_id)
3722
  {
3723
    mLogger.debug("getNextReleaseConfig 1");
3724
    boolean retVal = true;
3725
 
3726
    try
3727
    {
3728
      mReleaseConfigIndex++;
3729
      ReleaseConfig rc = (ReleaseConfig)mReleaseConfigCollection.get( mReleaseConfigIndex );
3730
      rcon_id.value = rc.get_rcon_id();
3731
    }
3732
    catch( ArrayIndexOutOfBoundsException e )
3733
    {
3734
      retVal = false;
3735
    }
3736
 
3737
    mLogger.info("getNextReleaseConfig 1 returning " + retVal);
3738
    return retVal;
3739
  }
3740
 
3741
  /**returns true if the mReleaseConfigCollection contains a next element and returns the rcon_id, rtag_id, daemon_mode and gbebuildfilter of the next element
3742
   */
3743
  public boolean getNextReleaseConfig(MutableInt rtag_id, 
3744
                                      MutableInt rcon_id, 
3745
                                      MutableChar daemon_mode, 
3746
                                      MutableString gbebuildfilter)
3747
  {
3748
    mLogger.debug("getNextReleaseConfig 2");
3749
    boolean retVal = true;
3750
 
3751
    try
3752
    {
3753
      mReleaseConfigIndex++;
3754
      ReleaseConfig rc = (ReleaseConfig)mReleaseConfigCollection.get( mReleaseConfigIndex );
3755
      rtag_id.value = rc.get_rtag_id();
3756
      rcon_id.value = rc.get_rcon_id();
3757
      daemon_mode.value = rc.get_daemon_mode();
3758
      gbebuildfilter.value = rc.get_gbebuildfilter();
3759
    }
3760
    catch( ArrayIndexOutOfBoundsException e )
3761
    {
3762
      retVal = false;
3763
    }
3764
 
3765
    mLogger.info("getNextReleaseConfig 2 returning " + retVal);
3766
    return retVal;
3767
  }
3768
 
3769
  /**returns true if the mRunLevelCollection contains a next element and returns the rcon_id and current_run_level of the next element
3770
   */
3771
  public boolean getNextRunLevel(MutableInt rcon_id, 
3772
                                 MutableInt current_run_level)
3773
  {
3774
    mLogger.debug("getNextRunLevel");
3775
    boolean retVal = true;
3776
 
3777
    try
3778
    {
3779
      mRunLevelIndex++;
3780
      RunLevel rl = (RunLevel)mRunLevelCollection.get( mRunLevelIndex );
3781
      rcon_id.value = rl.get_rcon_id();
3782
      current_run_level.value = rl.get_current_run_level();
3783
    }
3784
    catch( ArrayIndexOutOfBoundsException e )
3785
    {
3786
      retVal = false;
3787
    }
3788
 
3789
    mLogger.info("getNextRunLevel returning " + retVal);
3790
    return retVal;
3791
  }
3792
 
3793
  /**queries the RUN_LEVEL table using the rcon_id primary key
3794
   * returns false if the query returns a result set containing one row with a non NULL pause column
3795
   * (indicating intent to pause the thread)
3796
   * refer to sequence diagram allowed to proceed
3797
   */
3798
  public boolean queryDirectedRunLevel(final int rcon_id) throws SQLException, Exception
3799
  {
3800
    mLogger.debug("queryDirectedRunLevel " + rcon_id);
3801
    boolean retVal = true;
3802
 
3803
    if ( mUseDatabase )
3804
    {
3805
      try
3806
      {
3807
        CallableStatement stmt = mConnection.prepareCall("select pause from release_manager.run_level where rcon_id=" + rcon_id);
3808
        ResultSet rset = stmt.executeQuery();
3809
        int rsetSize = 0;
3810
 
3811
        while( rset.next() )
3812
        {
3813
          rsetSize++;
3814
          rset.getInt("pause");
3815
 
3816
          if ( !rset.wasNull() )
3817
          {
3818
            retVal = false;
3819
          }
3820
        }
830 mhunt 3821
 
3822
        rset.close();
3823
        stmt.close();
814 mhunt 3824
 
3825
        if ( rsetSize > 1 )
3826
        {
3827
          mLogger.fatal("queryDirectedRunLevel rsetSize > 1");
3828
          // show stopper
3829
          throw new Exception();
3830
        }
3831
      }
3832
      catch ( SQLException e )
3833
      {
3834
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3835
        {
3836
          mLogger.error("queryDirectedRunLevel database access error only");
3837
          throw new SQLException();
3838
        }
3839
        else
3840
        {
3841
          mLogger.fatal("queryDirectedRunLevel show stopper");
3842
          throw new Exception();
3843
        }
3844
      }
3845
    }
3846
 
3847
    mLogger.info("queryDirectedRunLevel returning " + retVal);
3848
    return retVal;
3849
  }
3850
 
3851
  /**queries the RELEASE_CONFIG table using the rcon_id primary key, rtag_id, daemon_hostname, daemon_mode, gbebuildfilter
3852
   * return true if the query contains a result set containing one row
3853
   * (indicating the rcon_id is still configured and its configuration is unchanged)
3854
   * refer to sequence diagram allowed to proceed
3855
   */
3856
  public boolean queryReleaseConfig(final int rtag_id, final int rcon_id, 
3857
                                    final String daemon_hostname, 
3858
                                    final char daemon_mode, 
3859
                                    final String gbebuildfilter) throws SQLException, Exception
3860
  {
3861
    mLogger.debug("queryReleaseConfig 1");
3862
    boolean retVal = false;
3863
 
3864
    if ( !mUseDatabase )
3865
    {
3866
      mLogger.info("queryReleaseConfig 1 !mUseDatabase");
3867
 
3868
      if ( mConnectionString.compareTo("unit test exit") != 0 )
3869
      {
3870
        retVal = true;
3871
      }
3872
    }
3873
    else
3874
    {
3875
      try
3876
      {
3877
        String sql = new String("select gbe_buildfilter from release_manager.release_config where rtag_id=" + rtag_id + " and rcon_id=" + rcon_id + " and daemon_hostname='" + daemon_hostname + "' and daemon_mode='" + daemon_mode + "'" );
3878
        CallableStatement stmt = mConnection.prepareCall( sql );
3879
        ResultSet rset = stmt.executeQuery();
3880
        int rsetSize = 0;
3881
 
3882
        while( rset.next() )
3883
        {
3884
          rsetSize++;
3885
          String gbe_buildfilter = rset.getString("gbe_buildfilter");
3886
 
3887
          if ( gbe_buildfilter == null )
3888
          {
3889
            mLogger.info("queryReleaseConfig 1 gbe_buildfilter == null");
3890
            if ( gbebuildfilter.length() == 0 )
3891
            {
3892
              retVal = true;
3893
            }
3894
          }
3895
          else
3896
          {
3897
            if ( gbebuildfilter.compareTo( gbe_buildfilter ) == 0 )
3898
            {
3899
              retVal = true;
3900
            }
3901
          }
3902
        }
830 mhunt 3903
 
3904
        rset.close();
3905
        stmt.close();
814 mhunt 3906
 
3907
        if ( rsetSize > 1 )
3908
        {
3909
          mLogger.fatal("queryReleaseConfig 1 rsetSize > 1");
3910
          // show stopper
3911
          throw new Exception();
3912
        }
3913
      }
3914
      catch ( SQLException e )
3915
      {
3916
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3917
        {
3918
          mLogger.error("queryReleaseConfig 1 database access error only");
3919
          throw new SQLException();
3920
        }
3921
        else
3922
        {
3923
          mLogger.fatal("queryReleaseConfig 1 show stopper");
3924
          throw new Exception();
3925
        }
3926
      }
3927
    }
3928
 
3929
    mLogger.info("queryReleaseConfig 1 returning " + retVal);
3930
    return retVal;
3931
  }
3932
 
3933
  /**removes all elements from the mReleaseConfigCollection
3934
   * handles database connection and disconnection
3935
   * queries the RELEASE_CONFIG table using the rtag_id
3936
   * populates the mReleaseConfigCollection with the query result set
3937
   * partially implements the sequence diagrams coordinate slave threads generate build files
3938
   */
3939
  public void queryReleaseConfig(final int rtag_id) throws SQLException, Exception
3940
  {
3941
    mLogger.debug("queryReleaseConfig 2");
3942
    mReleaseConfigCollection.removeAllElements();
3943
 
3944
    if ( !mUseDatabase )
3945
    {
3946
      mLogger.info("queryReleaseConfig 2 !mUseDatabase");
3947
      ReleaseConfig releaseConfig = new ReleaseConfig(1,1,'M',"unittestbuildfilter");
3948
      mReleaseConfigCollection.add(releaseConfig);
3949
      releaseConfig = new ReleaseConfig(1,2,'S',"anotherunittestbuildfilter");
3950
      mReleaseConfigCollection.add(releaseConfig);
3951
    }
3952
    else
3953
    {
3954
      try
3955
      {
3956
        connect();
3957
        CallableStatement stmt = mConnection.prepareCall("select rcon_id, daemon_mode, gbe_buildfilter from release_manager.release_config where rtag_id=" + rtag_id );
3958
        ResultSet rset = stmt.executeQuery();
3959
 
3960
        while( rset.next() )
3961
        {
3962
          int rcon_id = rset.getInt("rcon_id");
3963
 
3964
          if ( rset.wasNull() )
3965
          {
3966
            mLogger.fatal("queryReleaseConfig 2 null rcon_id " + rtag_id);
3967
            // show stopper
3968
            throw new Exception();
3969
          }
3970
 
3971
          char dm = 'S';          
3972
          String daemon_mode = rset.getString("daemon_mode");
3973
 
3974
          if ( daemon_mode != null )
3975
          {
3976
            mLogger.info("queryReleaseConfig 2 daemon_mode " + daemon_mode + ".");
3977
 
3978
            if ( daemon_mode.compareTo("M") == 0 )
3979
            {
3980
              dm = 'M';
3981
            }
3982
          }
3983
 
3984
          String gbe_buildfilter = rset.getString("gbe_buildfilter");
3985
 
3986
          if ( gbe_buildfilter == null )
3987
          {
3988
            gbe_buildfilter = new String("");
3989
          }
3990
 
3991
          ReleaseConfig releaseConfig = new ReleaseConfig( rtag_id, rcon_id, dm, gbe_buildfilter );
3992
          mReleaseConfigCollection.add(releaseConfig);
3993
        }
3994
 
830 mhunt 3995
 
3996
        rset.close();
3997
        stmt.close();
814 mhunt 3998
        disconnect();
3999
      }
4000
      catch ( SQLException e )
4001
      {
4002
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4003
        {
4004
          mLogger.error("queryReleaseConfig 2 daemon_mode database access error only");
4005
          throw new SQLException();
4006
        }
4007
        else
4008
        {
4009
          mLogger.fatal("queryReleaseConfig 2 show stopper");
4010
          throw new Exception();
4011
        }
4012
      }
4013
    }
4014
  }
4015
 
4016
  /**removes all elements from the mReleaseConfigCollection
4017
   * handles database connection and disconnection
4018
   * queries the RELEASE_CONFIG table using the daemon_hostname
4019
   * populates the mReleaseConfigCollection with the query result set
4020
   * partially implements the sequence diagram spawn thread
4021
   */
4022
  public void queryReleaseConfig(final String hostname) throws SQLException, Exception
4023
  {
4024
    mLogger.debug("queryReleaseConfig 3 " + hostname);
4025
    mReleaseConfigCollection.removeAllElements();
4026
 
4027
    if ( mConnectionString.compareTo("unit test spawn thread") == 0)
4028
    {
4029
      mLogger.info("queryReleaseConfig 3 unit test spawn thread");
4030
      // specifying a gbebuildfilter of unit test is designed to invoke a benign thread for unit test purposes
4031
      ReleaseConfig releaseConfig = new ReleaseConfig(1,1,'M',"unit test spawn thread");
4032
      mReleaseConfigCollection.add(releaseConfig);
4033
      releaseConfig = new ReleaseConfig(2,2,'S',"unit test spawn thread");
4034
      mReleaseConfigCollection.add(releaseConfig);
4035
    }
4036
    else
4037
    {
4038
      try
4039
      {
4040
        connect();
4041
        CallableStatement stmt = mConnection.prepareCall("select rtag_id, rcon_id, daemon_mode, gbe_buildfilter from release_manager.release_config where daemon_hostname='" + hostname + "'" );
4042
        ResultSet rset = stmt.executeQuery();
4043
 
4044
        while( rset.next() )
4045
        {
4046
          int rtag_id = rset.getInt("rtag_id");
4047
 
4048
          if ( rset.wasNull() )
4049
          {
4050
            mLogger.fatal("queryReleaseConfig 3 null rtag_id");
4051
            // show stopper
4052
            throw new Exception();
4053
          }
4054
 
4055
          int rcon_id = rset.getInt("rcon_id");
4056
 
4057
          if ( rset.wasNull() )
4058
          {
4059
            mLogger.fatal("queryReleaseConfig 3 null rcon_id");
4060
            // show stopper
4061
            throw new Exception();
4062
          }
4063
 
4064
          char dm = 'S';          
4065
          String daemon_mode = rset.getString("daemon_mode");
4066
 
4067
          if ( daemon_mode != null )
4068
          {
4069
            mLogger.info("queryReleaseConfig 3 daemon_mode " + daemon_mode + ".");
4070
 
4071
            if ( daemon_mode.compareTo("M") == 0 )
4072
            {
4073
              dm = 'M';
4074
            }
4075
          }
4076
 
4077
          String gbe_buildfilter = rset.getString("gbe_buildfilter");
4078
 
4079
          if ( gbe_buildfilter == null )
4080
          {
4081
            gbe_buildfilter = new String("");
4082
          }
4083
 
4084
          ReleaseConfig releaseConfig = new ReleaseConfig( rtag_id, rcon_id, dm, gbe_buildfilter );
4085
          mReleaseConfigCollection.add(releaseConfig);
4086
        }
4087
 
830 mhunt 4088
        rset.close();
4089
        stmt.close();
814 mhunt 4090
        disconnect();
4091
      }
4092
      catch ( SQLException e )
4093
      {
4094
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4095
        {
4096
          mLogger.error("queryReleaseConfig 3 database access error only");
4097
          throw new SQLException();
4098
        }
4099
        else
4100
        {
4101
          mLogger.fatal("queryReleaseConfig 3 show stopper");
4102
          throw new Exception();
4103
        }
4104
      }
4105
    }
4106
  }
4107
 
4108
  /**queries the RUN_LEVEL table using the rcon_id primary key
4109
   * handles database connection and disconnection
4110
   * polls indefinitely until CURRENT_BUILD_FILES column is non NULL
4111
   * returns the current_build_files
4112
   * implements the sequence diagram consume build files
4113
   */
4114
  public void queryRunLevel(int rcon_id, MutableString currentBuildFiles) throws SQLException, Exception
4115
  {
4116
    mLogger.debug("queryRunLevel 1 rcon_id " + rcon_id);
4117
    if ( !mUseDatabase )
4118
    {
4119
      mLogger.info("queryRunLevel 1 !mUseDatabase");
4120
      currentBuildFiles.value = "unit test build file content";
4121
    }
4122
    else
4123
    {
4124
      try
4125
      {
4126
        connect();
4127
        CallableStatement stmt = mConnection.prepareCall("select current_build_files from release_manager.run_level where rcon_id=" + rcon_id);
4128
        ResultSet rset = stmt.executeQuery();
4129
        int rsetSize = 0;
4130
 
4131
        while( rset.next() )
4132
        {
4133
          rsetSize++;
4134
          currentBuildFiles.value = rset.getString("current_build_files");
4135
          if (rset.wasNull())
4136
          {
4137
            currentBuildFiles.value = "";
4138
          }
4139
        }
4140
 
4141
        if ( rsetSize > 1 )
4142
        {
4143
          mLogger.fatal("queryRunLevel 1 rsetSize > 1");
4144
          // show stopper
4145
          throw new Exception();
4146
        }
4147
 
830 mhunt 4148
        rset.close();
4149
        stmt.close();
814 mhunt 4150
        disconnect();
4151
      }
4152
      catch ( SQLException e )
4153
      {
4154
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4155
        {
4156
          mLogger.error("queryRunLevel 1 database access error only");
4157
          throw new SQLException();
4158
        }
4159
        else
4160
        {
4161
          mLogger.fatal("queryRunLevel 1 show stopper");
4162
          throw new Exception();
4163
        }
4164
      }
4165
    }
4166
  }
4167
 
4168
  /**removes all elements from the mRunLevelCollection
4169
   * handles database connection and disconnection
4170
   *   select rl.rcon_id, rl.current_run_level from release_config rc, run_level rl
4171
   *   where rc.rtag_id=<rtag_id> and rl.rcon_id=rc.rcon_id;
4172
   * populates the mRunLevelCollection with the query result set
4173
   * refer to sequence diagram coordinate slave threads
4174
   */
4175
  public void queryRunLevel(final int rtag_id) throws SQLException, Exception
4176
  {
4177
    mLogger.debug("queryRunLevel 2 rtag_id " + rtag_id);
4178
    if ( mConnectionString.compareTo("unit test coordinate slave threads") == 0)
4179
    {
4180
      mLogger.info("queryRunLevel 2 unit test coordinate slave threads");
4181
 
4182
      if ( mRunLevelCollection.size() == 0)
4183
      {
4184
        // first time not all slave threads are waiting
4185
        RunLevel runLevel = new RunLevel(1, "", DB_WAITING, false);
4186
        mRunLevelCollection.add(runLevel);
4187
        runLevel = new RunLevel(2, "", DB_IDLE, false);
4188
        mRunLevelCollection.add(runLevel);
4189
      }
4190
      else
4191
      {
4192
        // subsequent times all slave threads are waiting
4193
        mRunLevelCollection.removeAllElements();
4194
        RunLevel runLevel = new RunLevel(1, "", DB_WAITING, false);
4195
        mRunLevelCollection.add(runLevel);
4196
        runLevel = new RunLevel(2, "", DB_WAITING, false);
4197
        mRunLevelCollection.add(runLevel);
4198
      }
4199
    }
4200
 
4201
    if ( mUseDatabase )
4202
    {
4203
      mRunLevelCollection.removeAllElements();
4204
 
4205
      try
4206
      {
4207
        connect();
4208
        CallableStatement stmt = mConnection.prepareCall(
4209
        "select rl.rcon_id, rl.current_run_level from release_config rc, run_level rl " +
4210
        "where rc.rtag_id=" +rtag_id + " and rl.rcon_id=rc.rcon_id");
4211
        ResultSet rset = stmt.executeQuery();
4212
        int rsetSize = 0;
4213
        int rcon_id = 0;
4214
        int current_run_level = 0;
4215
 
4216
        while( rset.next() )
4217
        {
4218
          rsetSize++;
4219
          rcon_id = rset.getInt("rcon_id");
4220
 
4221
          if ( rset.wasNull() )
4222
          {
4223
            mLogger.fatal("queryRunLevel 2 null rcon_id");
4224
            // show stopper
4225
            throw new Exception();
4226
          }
4227
 
4228
          current_run_level = rset.getInt("current_run_level");
4229
 
4230
          if ( rset.wasNull() )
4231
          {
4232
            mLogger.fatal("queryRunLevel 2 null current_run_level");
4233
            // show stopper
4234
            throw new Exception();
4235
          }
4236
 
4237
          RunLevel runLevel = new RunLevel(rcon_id, "", current_run_level, false);
4238
          mRunLevelCollection.add(runLevel);
4239
        }
4240
 
4241
        if ( rsetSize == 0 )
4242
        {
4243
          mLogger.fatal("queryRunLevel 2 rsetSize == 0");
4244
          // show stopper
4245
          throw new Exception();
4246
        }
4247
 
830 mhunt 4248
        rset.close();
4249
        stmt.close();
814 mhunt 4250
        disconnect();
4251
      }
4252
      catch ( SQLException e )
4253
      {
4254
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4255
        {
4256
          mLogger.error("queryRunLevel 2 database access error only");
4257
          throw new SQLException();
4258
        }
4259
        else
4260
        {
4261
          mLogger.fatal("queryRunLevel 2 show stopper");
4262
          throw new Exception();
4263
        }
4264
      }
4265
 
4266
 
4267
    }
4268
  }
4269
 
818 mhunt 4270
  /**removes all elements from the mRunLevelCollection
4271
   * handles database connection and disconnection
4272
   *   select rcon_id, current_run_level from run_level
4273
   *   where rcon_id=<rcon_id>;
4274
   * populates the mRunLevelCollection with the query result set
4275
   */
4276
  public void querySingleRunLevel(final int rcon_id) throws SQLException, Exception
4277
  {
4278
    mLogger.debug("querySingleRunLevel rcon_id " + rcon_id);
4279
    if ( !mUseDatabase )
4280
    {
4281
      mLogger.info("querySingleRunLevel !mUseDatabase");
4282
 
4283
      mRunLevelCollection.removeAllElements();
4284
      RunLevel runLevel = new RunLevel(rcon_id, "", DB_ACTIVE, false);
4285
      mRunLevelCollection.add(runLevel);
4286
    }
4287
    else
4288
    {
4289
      mRunLevelCollection.removeAllElements();
4290
 
4291
      try
4292
      {
4293
        connect();
4294
        CallableStatement stmt = mConnection.prepareCall(
4295
        "select rcon_id, current_run_level from run_level " +
4296
        "where rcon_id=" +rcon_id);
4297
        ResultSet rset = stmt.executeQuery();
4298
        int rsetSize = 0;
4299
        int current_run_level = 0;
4300
 
4301
        while( rset.next() )
4302
        {
4303
          rsetSize++;
4304
          current_run_level = rset.getInt("current_run_level");
4305
 
4306
          if ( rset.wasNull() )
4307
          {
4308
            mLogger.fatal("querySingleRunLevel null current_run_level");
4309
            // show stopper
4310
            throw new Exception();
4311
          }
4312
 
4313
          RunLevel runLevel = new RunLevel(rcon_id, "", current_run_level, false);
4314
          mRunLevelCollection.add(runLevel);
4315
        }
4316
 
4317
        if ( rsetSize != 1 )
4318
        {
4319
          mLogger.fatal("querySingleRunLevel rsetSize != 1");
4320
          // show stopper
4321
          throw new Exception();
4322
        }
4323
 
830 mhunt 4324
        rset.close();
4325
        stmt.close();
818 mhunt 4326
        disconnect();
4327
      }
4328
      catch ( SQLException e )
4329
      {
4330
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4331
        {
4332
          mLogger.error("querySingleRunLevel database access error only");
4333
          throw new SQLException();
4334
        }
4335
        else
4336
        {
4337
          mLogger.fatal("querySingleRunLevel show stopper");
4338
          throw new Exception();
4339
        }
4340
      }
4341
    }
4342
  }
4343
 
814 mhunt 4344
  /**queries the RUN_LEVEL_SCHEDULE table
4345
   * returns false if a row in the query result set indicates build service downtime is scheduled
4346
   * returns false if a row in the query result set has a non NULL indefinite_pause
4347
   * refer to the sequence diagram allowed to proceed
4348
   */
4349
  public boolean queryRunLevelSchedule(Date resumeTime) throws SQLException, Exception
4350
  {
4351
    mLogger.debug("queryRunLevelSchedule");
4352
    boolean retVal = true;
4353
 
4354
    if ( !mUseDatabase )
4355
    {
4356
      mLogger.info("queryRunLevelSchedule !mUseDatabase");
4357
 
4358
      if ( mConnectionString.compareTo("unit test not allowed to proceed") == 0 )
4359
      {
4360
        // schedule a 100ms max wait
4361
        resumeTime.setTime( resumeTime.getTime() + 100 );
4362
        retVal = false;
4363
      }
4364
    }
4365
    else
4366
    {
4367
      try
4368
      {
4369
        CallableStatement stmt = mConnection.prepareCall("select scheduled_pause, scheduled_resume, repeat, indefinite_pause from release_manager.run_level_schedule");
4370
        ResultSet rset = stmt.executeQuery();
4371
        Date now = new Date();
844 dpurdie 4372
 
4373
 
4374
        //
846 dpurdie 4375
        //  Scan the database information and determine if there is any reason
844 dpurdie 4376
        //  to pause. Terminate the loop on the first excuse to pause
4377
        //  as indefinite pause may have multiple (lots) of entries in the data
4378
        //  base.
4379
        //
4380
        while( retVal == true && rset.next() )
814 mhunt 4381
        {
846 dpurdie 4382
          //
4383
          //  Examine the current row from the data base
4384
          //  Expect one of two forms:
4385
          //    1) scheduled_pause
4386
          //       Must also have a scheduled_resume and a repeat
4387
          //    2) indefinite_pause
4388
          //
4389
 
4390
          //  Look for scheduled_pause style of entry
4391
          //
814 mhunt 4392
          Timestamp sp = rset.getTimestamp("scheduled_pause");
4393
          if ( sp != null )
4394
          {
4395
            Date scheduled_pause = new Date( sp.getTime() );
4396
            Timestamp sr = rset.getTimestamp("scheduled_resume");
4397
 
4398
            if ( sr != null )
4399
            {
4400
              Date scheduled_resume = new Date( sr.getTime() );
4401
              int repeat = rset.getInt("repeat");
4402
              mLogger.info("queryRunLevelSchedule repeat " + repeat);
846 dpurdie 4403
 
4404
              //
4405
              //  Have scheduled_pause and scheduled_resume
4406
              //  Examine the repeat field and determine how these are used
4407
              //  Supported repeat:
4408
              //      Once Only
4409
              //      Daily           Year, Month and Day information is ignored
4410
              //      Weekly          Only day of week is utilised
4411
              //
814 mhunt 4412
              if ( !rset.wasNull() )
4413
              {
4414
                switch( repeat )
4415
                {
4416
                  case 0:
4417
                  {
4418
                    // one off
4419
                    if ( scheduled_pause.before(now) && scheduled_resume.after(now) )
4420
                    {
4421
                      mLogger.warn("queryRunLevelSchedule one off scheduled downtime");
838 mhunt 4422
                      resumeTime = scheduled_resume;
814 mhunt 4423
                      retVal = false;
4424
                    }
4425
                    break;
4426
                  }
4427
                  case 1:
4428
                  {
846 dpurdie 4429
                    //  daily
4430
                    //  Create start and end fimes, then massage some fields
4431
                    //  to reflect todays date
4432
                    //
814 mhunt 4433
                    GregorianCalendar startOfDowntime = new GregorianCalendar();
4434
                    startOfDowntime.setTime(scheduled_pause);
4435
                    GregorianCalendar endOfDowntime = new GregorianCalendar();
4436
                    endOfDowntime.setTime(scheduled_resume);
4437
                    GregorianCalendar clock = new GregorianCalendar();
4438
                    clock.setTime(now);
846 dpurdie 4439
 
4440
                    // Force date fields to todays date
4441
                    endOfDowntime.set  ( clock.get(Calendar.YEAR), clock.get(Calendar.MONTH), clock.get(Calendar.DAY_OF_MONTH) );
4442
                    startOfDowntime.set( clock.get(Calendar.YEAR), clock.get(Calendar.MONTH), clock.get(Calendar.DAY_OF_MONTH) );
4443
 
814 mhunt 4444
                    if ( startOfDowntime.before(clock) && endOfDowntime.after(clock) )
4445
                    {
4446
                      mLogger.warn("queryRunLevelSchedule daily scheduled downtime");
838 mhunt 4447
                      resumeTime.setTime(endOfDowntime.getTimeInMillis());
814 mhunt 4448
                      retVal = false;
4449
                    }
4450
                    break;
4451
                  }
4452
                  case 7:
4453
                  {
4454
                    // weekly
846 dpurdie 4455
                    // Create start and end times, then massage some fields
4456
                    // to reflect todays date
4457
                    //
814 mhunt 4458
                    GregorianCalendar startOfDowntime = new GregorianCalendar();
4459
                    startOfDowntime.setTime(scheduled_pause);
4460
                    GregorianCalendar endOfDowntime = new GregorianCalendar();
4461
                    endOfDowntime.setTime(scheduled_resume);
4462
                    GregorianCalendar clock = new GregorianCalendar();
4463
                    clock.setTime(now);
846 dpurdie 4464
 
4465
                    // Only interested in one day of the week
814 mhunt 4466
                    if ( startOfDowntime.get(Calendar.DAY_OF_WEEK) == clock.get(Calendar.DAY_OF_WEEK) )
4467
                    {
846 dpurdie 4468
                      endOfDowntime.set  ( clock.get(Calendar.YEAR), clock.get(Calendar.MONTH), clock.get(Calendar.DAY_OF_MONTH) );
4469
                      startOfDowntime.set( clock.get(Calendar.YEAR), clock.get(Calendar.MONTH), clock.get(Calendar.DAY_OF_MONTH) );
814 mhunt 4470
 
4471
                      if ( startOfDowntime.before(clock) && endOfDowntime.after(clock) )
4472
                      {
4473
                        mLogger.warn("queryRunLevelSchedule weekly scheduled downtime");
838 mhunt 4474
                        resumeTime.setTime(endOfDowntime.getTimeInMillis());
814 mhunt 4475
                        retVal = false;
4476
                      }
4477
                    }
4478
                    break;
4479
                  }
4480
                }
4481
              }
4482
            }
4483
          }
4484
 
846 dpurdie 4485
          //
4486
          //  Look for indefinite_pause style of entry
4487
          //  Note: due to an implemenation error there may be many
4488
          //        rows that match. We only need one. The scan will
4489
          //        be termineted if we find any
4490
          //  
4491
          //
836 mhunt 4492
          String ip = rset.getString("indefinite_pause");
4493
          if ( ip != null )
814 mhunt 4494
          {
4495
            // indefinite pause is non null
4496
            mLogger.warn("queryRunLevelSchedule indefinite pause");
838 mhunt 4497
            GregorianCalendar clock = new GregorianCalendar();
4498
            clock.setTime(now);
4499
            // wait a minute
4500
            resumeTime.setTime(clock.getTimeInMillis() + 60000);
814 mhunt 4501
            retVal = false;
4502
          }
4503
        }
830 mhunt 4504
 
4505
        rset.close();
4506
        stmt.close();
814 mhunt 4507
      }
4508
      catch ( SQLException e )
4509
      {
4510
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4511
        {
4512
          mLogger.error("queryRunLevelSchedule database access error only");
4513
          throw new SQLException();
4514
        }
4515
        else
4516
        {
4517
          mLogger.fatal("queryRunLevelSchedule show stopper");
4518
          throw new Exception();
4519
        }
4520
      }
4521
    }
4522
 
4523
    mLogger.info("queryRunLevelSchedule returning " + retVal);
4524
    return retVal;
4525
  }
4526
 
4527
  /**persists the runLevel in the RUN_LEVEL table for the rcon_id primary key
4528
   * refer to sequence diagrams generate build files, allowed to proceed, not allowed to proceed, exit, check environment
4529
   */
4530
  public void updateCurrentRunLevel(final int rcon_id, final int runLevel) throws SQLException, Exception
4531
  {
4532
    mLogger.debug("updateCurrentRunLevel");
4533
    if ( !mUseDatabase )
4534
    {
4535
      mLogger.info("updateCurrentRunLevel !mUseDatabase");
4536
      Integer i = new Integer(runLevel);
4537
      mPersistedRunLevelCollection.add(i);
4538
    }
4539
    else
4540
    {
4541
      try
4542
      {
4543
        connect();
4544
        boolean update = false;
4545
        {
4546
          // check if the rcon_id exists in the table
4547
          CallableStatement stmt = mConnection.prepareCall("select rcon_id from release_manager.run_level where rcon_id=" + rcon_id);
4548
          ResultSet rset = stmt.executeQuery();
4549
 
4550
          while( rset.next() )
4551
          {
4552
            update = true;
4553
          }
830 mhunt 4554
 
4555
          rset.close();
4556
          stmt.close();
814 mhunt 4557
        }
4558
 
4559
        if ( !update )
4560
        {
4561
          // check if the rcon_id is still configured
4562
          boolean configured = false;
4563
          {
4564
            CallableStatement stmt = mConnection.prepareCall("select rcon_id from release_manager.release_config where rcon_id=" + rcon_id);
4565
            ResultSet rset = stmt.executeQuery();
4566
 
4567
            while( rset.next() )
4568
            {
4569
              configured = true;
4570
            }
830 mhunt 4571
 
4572
            rset.close();
4573
            stmt.close();
814 mhunt 4574
          }
4575
          CallableStatement stmt = mConnection.prepareCall("insert into release_manager.run_level (rcon_id) values (" + rcon_id + ")" );
4576
          stmt.executeUpdate();
830 mhunt 4577
          stmt.close();
814 mhunt 4578
        }
4579
 
4580
        {
4581
          CallableStatement stmt = mConnection.prepareCall("update release_manager.run_level set current_run_level=" + runLevel + " where rcon_id=" + rcon_id);
4582
          stmt.executeUpdate();
830 mhunt 4583
          stmt.close();
814 mhunt 4584
        }
4585
        mConnection.commit();
4586
        disconnect();
4587
      }
4588
      catch( SQLException e )
4589
      {
4590
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4591
        {
4592
          mLogger.error("updateCurrentRunLevel database access error only");
4593
          throw new Exception();
4594
        }
4595
        else
4596
        {
4597
          mLogger.fatal("updateCurrentRunLevel show stopper");
4598
          throw new Exception();
4599
        }
4600
      }
4601
    }
4602
  }
4603
 
4604
}