Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

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