Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

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