Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

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