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