Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

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