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