Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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