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