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