Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

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