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