Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

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