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