Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

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