Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

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