Subversion Repositories DevTools

Rev

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