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