Subversion Repositories DevTools

Rev

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