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");
3302
        stmt.executeUpdate();
844 dpurdie 3303
        stmt.close();
898 mhunt 3304
        mDoNotCommit = true;
814 mhunt 3305
      }
3306
      catch ( SQLException e )
3307
      {
3308
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3309
        {
3310
          mLogger.error("claimMutex database access error only");
3311
          throw new SQLException();
3312
        }
3313
        else
3314
        {
3315
          mLogger.fatal("claimMutex show stopper");
868 mhunt 3316
          throw new Exception("claimMutex show stopper");
814 mhunt 3317
        }
3318
      }
896 mhunt 3319
      // about to start the planning process again, discard previous
3320
      discardVersions();
814 mhunt 3321
    }
3322
  }
3323
 
898 mhunt 3324
  /**essentially unlocks the row in the BUILD_SERVICE_CONFIG table with a service of MUTEX
3325
   */
3326
  public void releaseMutex() throws SQLException, Exception
3327
  {
3328
    mLogger.debug("releaseMutex");
3329
    if ( mUseDatabase )
3330
    {
3331
      try
3332
      {
3333
        mDoNotCommit = false;
3334
        commit();
3335
      }
3336
      catch ( SQLException e )
3337
      {
3338
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3339
        {
3340
          mLogger.error("releaseMutex database access error only");
3341
          throw new SQLException();
3342
        }
3343
        else
3344
        {
3345
          mLogger.fatal("releaseMutex show stopper");
3346
          throw new Exception("releaseMutex show stopper");
3347
        }
3348
      }
3349
    }
3350
  }
3351
 
3352
  /**central commit protection
3353
   */
3354
  private void commit() throws SQLException, Exception
3355
  {
3356
    mLogger.debug("commit");
3357
    if ( mUseDatabase )
3358
    {
3359
      if ( mDoNotCommit )
3360
      {
3361
        mLogger.error("commit attempted commit with mDoNotCommit set, this is a programming error");
3362
      }
3363
      else
3364
      {
3365
        mConnection.commit();
3366
      }
3367
    }
3368
  }
3369
 
814 mhunt 3370
  /**sets CURRENT_BUILD_FILES to NULL for the rcon_id
882 mhunt 3371
   * update release_manager.run_level set current_build_files=null where rcon_id=<rcon_id>
814 mhunt 3372
   */
882 mhunt 3373
  public void clearBuildFile(int rcon_id) throws SQLException, Exception
814 mhunt 3374
  {
3375
    mLogger.debug("clearBuildFile");
3376
 
3377
    try
3378
    {
3379
      connect();
882 mhunt 3380
 
3381
      if ( isRconIdConfigured( rcon_id ))
3382
      {
3383
        CallableStatement stmt = mConnection.prepareCall("update release_manager.run_level set current_build_files=null where rcon_id=" + rcon_id);
3384
        stmt.executeUpdate();
3385
        stmt.close();
898 mhunt 3386
        commit();
882 mhunt 3387
      }
814 mhunt 3388
    }
3389
    catch ( SQLException e )
3390
    {
3391
      if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3392
      {
3393
        mLogger.error("clearBuildFile database access error only");
3394
        throw new SQLException();
3395
      }
3396
      else
3397
      {
3398
        mLogger.fatal("clearBuildFile show stopper");
868 mhunt 3399
        throw new Exception("clearBuildFile show stopper");
814 mhunt 3400
      }
3401
    }
898 mhunt 3402
    finally
3403
    {
3404
      // this block is executed regardless of what happens in the try block
3405
      // even if an exception is thrown
3406
      // ensure disconnect
3407
      disconnect();
3408
    }
814 mhunt 3409
  }
3410
 
3411
  /**updates the CURRENT_BUILD_FILES for the rtag_id
3412
   * update (
882 mhunt 3413
   * select current_build_files from release_manager.release_manager.run_level rl, release_manager.release_manager.release_config rc
814 mhunt 3414
   * where rc.rtag_id=<rtag_id> and rl.rcon_id=rc.rcon_id
3415
   * ) set current_build_files=<buildFile>
3416
   */
882 mhunt 3417
  public void publishBuildFile(int rtag_id, String buildFile) throws SQLException, Exception
814 mhunt 3418
  {
3419
    mLogger.debug("publishBuildFile publishing a build file of length " + buildFile.length());
3420
 
3421
    try
3422
    {
3423
      connect();
882 mhunt 3424
 
3425
      if ( isRtagIdConfigured( rtag_id ) )
3426
      {
3427
        PreparedStatement stmt = mConnection.prepareStatement(
3428
        "update (" +
3429
        "select current_build_files from release_manager.run_level rl, release_manager.release_config rc " +
3430
        "where rc.rtag_id=? and rl.rcon_id=rc.rcon_id" +
3431
        ") set current_build_files=?");
3432
        stmt.setInt(1, rtag_id);
3433
        stmt.setString(2, buildFile);
3434
        stmt.executeUpdate();
3435
        stmt.close();
898 mhunt 3436
        commit();
882 mhunt 3437
      }
814 mhunt 3438
    }
3439
    catch ( SQLException e )
3440
    {
3441
      if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3442
      {
3443
        mLogger.error("publishBuildFile database access error only");
3444
        throw new SQLException();
3445
      }
3446
      else
3447
      {
3448
        mLogger.fatal("publishBuildFile show stopper");
868 mhunt 3449
        throw new Exception("publishBuildFile show stopper");
814 mhunt 3450
      }
3451
    }
3452
    catch ( Exception e )
3453
    {
3454
      // this catch and rethrow is historical
3455
      // problems were found using CallableStatement when updating a CLOB column with data > 4000 bytes
3456
      mLogger.fatal("publishBuildFile caught Exception " + e.getMessage());
868 mhunt 3457
      throw new Exception("publishBuildFile caught Exception " + e.getMessage());
814 mhunt 3458
    }
898 mhunt 3459
    finally
3460
    {
3461
      // this block is executed regardless of what happens in the try block
3462
      // even if an exception is thrown
3463
      // ensure disconnect
3464
      disconnect();
3465
    }
814 mhunt 3466
  }
3467
 
3468
  /**ensures a run_level_schedule row with a non null indefinite_pause column exists
3469
   * this is aimed at stopping all daemons dead
3470
   * it is raised when handling an unsupported exception case in either the main or slave daemons
3471
   * typically an SQLException other than a database connection related one
3472
   */
896 mhunt 3473
  public void indefinitePause()
814 mhunt 3474
  {
3475
    mLogger.debug("indefinitePause");
3476
    if ( mUseDatabase )
3477
    {
836 mhunt 3478
      try
3479
      {
896 mhunt 3480
        connect();
3481
        CallableStatement stmt = mConnection.prepareCall( "begin PK_BUILDAPI.SET_INFINITE_PAUSE(); end;" );
3482
        stmt.executeUpdate();
3483
        stmt.close();
898 mhunt 3484
        commit();
836 mhunt 3485
      }
3486
      catch( SQLException e )
3487
      {
3488
        // do not throw Exception
3489
        // this is part of Exception handling
3490
        mLogger.fatal( "indefinitePause caught SQLException " + e.getMessage() );
3491
      }
3492
      catch( Exception e )
3493
      {
3494
        mLogger.fatal( "indefinitePause caught Exception " + e.getMessage() );
3495
      }
898 mhunt 3496
      finally
3497
      {
3498
        // this block is executed regardless of what happens in the try block
3499
        // even if an exception is thrown
3500
        // ensure disconnect
3501
        try
3502
        {
3503
          disconnect();
3504
        }
3505
        catch( SQLException e )
3506
        {
3507
          // do not throw Exception
3508
          // this is part of Exception handling
3509
          mLogger.fatal( "indefinitePause2 caught SQLException " + e.getMessage() );
3510
        }
3511
        catch( Exception e )
3512
        {
3513
          mLogger.fatal( "indefinitePause2 caught Exception " + e.getMessage() );
3514
        }
3515
      }
814 mhunt 3516
    }
3517
  }
3518
 
896 mhunt 3519
  /**ensures a run_level_schedule row with a non null indefinite_pause column does not exist
3520
   * this is aimed at resuming all daemons
3521
   */
3522
  private void resume() throws SQLException, Exception
3523
  {
3524
    mLogger.debug("resume");
3525
    if ( mUseDatabase )
3526
    {
3527
      try
3528
      {
3529
        CallableStatement stmt = mConnection.prepareCall( "begin PK_BUILDAPI.SET_RESUME(); end;" );
3530
        stmt.executeUpdate();
3531
        stmt.close();
898 mhunt 3532
        commit();
896 mhunt 3533
      }
3534
      catch ( SQLException e )
3535
      {
3536
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3537
        {
3538
          mLogger.error("resume database access error only");
3539
          throw new SQLException();
3540
        }
3541
        else
3542
        {
3543
          mLogger.fatal("resume show stopper");
3544
          throw new Exception("resume show stopper");
3545
        }
3546
      }
3547
    }
3548
  }
3549
 
814 mhunt 3550
  /**only used in daemon mode to determine version existence in the database
882 mhunt 3551
   *  1 select pkg_id from release_manager.package_versions where pkg_id=<pkg_id> and pkg_version=<pkg_version>;
3552
   *  2 select pkg_id from release_manager.planned_versions where pkg_id=<pkg_id> and pkg_version=<pkg_version>;
814 mhunt 3553
   * returns true if either resultset contains one record to indicate it already exists
3554
   */
3555
  boolean queryPackageVersions(int pkg_id, String pkg_version) throws SQLException, Exception
3556
  {
3557
    mLogger.debug("queryPackageVersions");
3558
    boolean retVal = false;
3559
 
3560
    if ( mUseDatabase )
3561
    {
3562
      try
3563
      {
3564
        mLogger.info("queryPackageVersions release_manager.package_versions");
3565
        CallableStatement stmt1 = mConnection.prepareCall("select pkg_id from release_manager.package_versions where pkg_id=" + pkg_id + " and pkg_version='" + pkg_version + "'");
3566
        ResultSet rset1 = stmt1.executeQuery();
3567
        int rsetSize = 0;
3568
 
3569
        while( rset1.next() )
3570
        {
3571
          rsetSize++;
3572
        }
830 mhunt 3573
 
3574
        rset1.close();
3575
        stmt1.close();
814 mhunt 3576
 
3577
        if ( rsetSize > 1 )
3578
        {
3579
          mLogger.fatal("queryPackageVersions rsetSize > 1 " + pkg_id + " " + pkg_version);
3580
          // show stopper
868 mhunt 3581
          throw new Exception("queryPackageVersions rsetSize > 1 " + pkg_id + " " + pkg_version);
814 mhunt 3582
        }
3583
 
3584
        if ( rsetSize == 1 )
3585
        {
3586
          retVal = true;
3587
        }
3588
        else
3589
        {
3590
          mLogger.info("queryPackageVersions release_manager.planned_versions");
3591
          CallableStatement stmt2 = mConnection.prepareCall("select pkg_id from release_manager.planned_versions where pkg_id=" + pkg_id + " and pkg_version='" + pkg_version + "'");
3592
          ResultSet rset2 = stmt2.executeQuery();
3593
          rsetSize = 0;
3594
 
3595
          while( rset2.next() )
3596
          {
3597
            rsetSize++;
3598
          }
830 mhunt 3599
 
3600
          rset2.close();
3601
          stmt2.close();
814 mhunt 3602
 
3603
          if ( rsetSize > 1 )
3604
          {
3605
            mLogger.fatal("queryPackageVersions rsetSize > 1 " + pkg_id + " " + pkg_version);
3606
            // show stopper
868 mhunt 3607
            throw new Exception("queryPackageVersions rsetSize > 1 " + pkg_id + " " + pkg_version);
814 mhunt 3608
          }
3609
 
3610
          if ( rsetSize == 1 )
3611
          {
3612
            retVal = true;
3613
          }
3614
        }
3615
      }
3616
      catch ( SQLException e )
3617
      {
3618
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3619
        {
3620
          mLogger.error("queryPackageVersions database access error only");
3621
          throw new SQLException();
3622
        }
3623
        else
3624
        {
3625
          mLogger.fatal("queryPackageVersions show stopper");
868 mhunt 3626
          throw new Exception("queryPackageVersions show stopper");
814 mhunt 3627
        }
3628
      }
3629
    }
3630
 
3631
    mLogger.info("queryPackageVersions returned " + retVal);
3632
    return retVal;
3633
  }
3634
 
3635
  /**only used in daemon mode
882 mhunt 3636
   *  insert into release_manager.planned_versions (pkg_id, pkg_version) values (<pkg_id>, <pkg_version>);
814 mhunt 3637
   *  update
3638
   *  (
882 mhunt 3639
   *  select current_pkg_id_being_built from release_manager.run_level rl, release_manager.release_config rc
814 mhunt 3640
   *  where rc.rtag_id=<rtag_id> and rl.rcon_id=rc.rcon_id
3641
   *  )
3642
   *  set current_pkg_id_being_built=<pkg_id>
3643
   */
3644
  void claimVersion(int pkg_id, String pkg_version, int rtag_id) throws SQLException, Exception
3645
  {
3646
    mLogger.debug("claimVersion " + pkg_id + " " + pkg_version);
3647
    if ( mUseDatabase )
3648
    {
3649
      try
3650
      {
882 mhunt 3651
        if (isRtagIdConfigured( rtag_id ))
3652
        {
896 mhunt 3653
          CallableStatement stmt3 = mConnection.prepareCall("insert into release_manager.planned_versions (pkg_id, pkg_version, planned_time) values (" + pkg_id + ", '" + pkg_version + "', sysdate)");
882 mhunt 3654
          stmt3.executeUpdate();
3655
          stmt3.close();
3656
          CallableStatement stmt4 = mConnection.prepareCall(
3657
          "update " +
3658
          "(" +
3659
          "select current_pkg_id_being_built from release_manager.run_level rl, release_manager.release_config rc " +
3660
          "where rc.rtag_id=" + rtag_id + " and rl.rcon_id=rc.rcon_id" +
3661
          ")" +
3662
          "set current_pkg_id_being_built=" + pkg_id);
3663
          stmt4.executeUpdate();
3664
          stmt4.close();
896 mhunt 3665
          mPlannedPkgId = new String();
3666
          mPlannedPkgId += pkg_id;
3667
          mPlannedPkgVersion = new String( pkg_version );
882 mhunt 3668
        }
814 mhunt 3669
      }
3670
      catch ( SQLException e )
3671
      {
3672
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3673
        {
3674
          mLogger.error("claimVersion database access error only");
3675
          throw new SQLException();
3676
        }
3677
        else
3678
        {
3679
          mLogger.fatal("claimVersion show stopper");
868 mhunt 3680
          throw new Exception("claimVersion show stopper");
814 mhunt 3681
        }
3682
      }
3683
    }
3684
  }
3685
 
818 mhunt 3686
  /**only used in daemon mode
896 mhunt 3687
   * delete from release_manager.planned_versions where pkg_id=<pkg_id> and pkg_version=<pkg_version>;
3688
   */
3689
  public void discardVersion() throws SQLException, Exception
3690
  {
3691
    mLogger.debug("discardVersion");
3692
    if ( mPlannedPkgId != null && mPlannedPkgVersion != null )
3693
    {
3694
      try
3695
      {
3696
        CallableStatement stmt = mConnection.prepareCall("delete from release_manager.planned_versions where pkg_id=" + mPlannedPkgId + " and pkg_version='" + mPlannedPkgVersion + "'");
3697
        stmt.executeUpdate();
3698
        stmt.close();
898 mhunt 3699
        commit();
896 mhunt 3700
        mPlannedPkgId = null;
3701
        mPlannedPkgVersion = null;
3702
      }
3703
      catch ( SQLException e )
3704
      {
3705
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3706
        {
3707
          mLogger.error("discardVersion database access error only");
3708
          throw new SQLException();
3709
        }
3710
        else
3711
        {
3712
          mLogger.fatal("discardVersion show stopper");
3713
          throw new Exception("discardVersion show stopper");
3714
        }
3715
      }
3716
    }
3717
  }
3718
 
3719
  /**only used in daemon mode
3720
   * delete planned versions over 24 hours old (rounded to the nearest hour that is)
3721
   * delete from release_manager.planned_versions where planned_time < trunc(sysdate, 'hh') - 1");
3722
   */
3723
  private void discardVersions() throws SQLException, Exception
3724
  {
3725
    mLogger.debug("discardVersions");
3726
    try
3727
    {
3728
      // housekeep whilst the daemon has the mutex
3729
      // trunc(sysdate, 'hh') returns the time now rounded to the nearest hour
3730
      // trunc(sysdate, 'hh') - 1 returns the time 24 hours ago rounded to the nearest hour
3731
      // this statement does not return any rows when planned_time is null, though this should never be the case
3732
      CallableStatement stmt = mConnection.prepareCall("delete from release_manager.planned_versions where planned_time < trunc(sysdate, 'hh') - 1");
3733
      stmt.executeUpdate();
3734
      stmt.close();
3735
    }
3736
    catch ( SQLException e )
3737
    {
3738
      if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3739
      {
3740
        mLogger.error("discardVersions database access error only");
3741
        throw new SQLException();
3742
      }
3743
      else
3744
      {
3745
        mLogger.fatal("discardVersions show stopper");
3746
        throw new Exception("discardVersions show stopper");
3747
      }
3748
    }
3749
  }
3750
 
3751
  /**only used in daemon mode
818 mhunt 3752
   *  update
3753
   *  (
882 mhunt 3754
   *  select current_pkg_id_being_built from release_manager.run_level
818 mhunt 3755
   *  where rcon_id=<rcon_id>
3756
   *  )
3757
   *  set current_pkg_id_being_built=null
3758
   */
3759
  public void clearCurrentPackageBeingBuilt(int rcon_id) throws SQLException, Exception
3760
  {
3761
    mLogger.debug("clearCurrentPackageBeingBuilt " + rcon_id);
3762
    if ( mUseDatabase )
3763
    {
3764
      try
3765
      {
820 mhunt 3766
        connect();
882 mhunt 3767
 
3768
        if ( isRconIdConfigured( rcon_id ))
3769
        {
3770
          CallableStatement stmt4 = mConnection.prepareCall(
3771
          "update " +
3772
          "(" +
3773
          "select current_pkg_id_being_built from release_manager.run_level " +
3774
          "where rcon_id=" + rcon_id +
3775
          ")" +
3776
          "set current_pkg_id_being_built=null" );
3777
          stmt4.executeUpdate();
3778
          stmt4.close();
898 mhunt 3779
          commit();
882 mhunt 3780
        }
818 mhunt 3781
      }
3782
      catch ( SQLException e )
3783
      {
3784
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3785
        {
3786
          mLogger.error("clearCurrentPackageBeingBuilt database access error only");
3787
          throw new SQLException();
3788
        }
3789
        else
3790
        {
3791
          mLogger.fatal("clearCurrentPackageBeingBuilt show stopper");
868 mhunt 3792
          throw new Exception("clearCurrentPackageBeingBuilt show stopper");
818 mhunt 3793
        }
3794
      }
898 mhunt 3795
      finally
3796
      {
3797
        // this block is executed regardless of what happens in the try block
3798
        // even if an exception is thrown
3799
        // ensure disconnect
3800
        disconnect();
3801
      }
818 mhunt 3802
    }
3803
  }
3804
 
814 mhunt 3805
  /**handles database connection/disconnection
3806
   * executes the AutoMakeRelease stored procedure with the passed parameters
3807
   */
3808
  public void autoMakeRelease(String rtagId, String packageName, 
3809
                              String packageExtension, 
3810
                              String packageVersion, String packageLabel, 
3811
                              String packageDepends, String isRipple) throws SQLException, Exception
3812
  {
3813
    mLogger.debug("autoMakeRelease " + packageName);
3814
    if ( mUseDatabase )
3815
    {
3816
      try
3817
      {
3818
        connect();
3819
        CallableStatement stmt = mConnection.prepareCall( "begin ? := PK_RMAPI.AUTO_MAKE_RELEASE(?,?,?,?,?,?,?,?); end;" );
3820
        stmt.registerOutParameter( 1, Types.INTEGER);
3821
        stmt.setString( 2, rtagId );
3822
        stmt.setString( 3, packageName );
3823
        stmt.setString( 4, packageExtension );
3824
        stmt.setString( 5, packageVersion );
3825
        stmt.setString( 6, packageLabel );
3826
        stmt.setString( 7, packageDepends );
3827
        stmt.setString( 8, isRipple );
3828
        stmt.setString( 9, "buildadm" );
3829
        stmt.executeUpdate();
3830
        int result = stmt.getInt( 1 );
3831
 
3832
        if ( result <= 0 && result != -2 )
3833
        {
3834
          // -2 if already released
3835
          // flag build failure
3836
          mLogger.fatal("autoMakeRelease show stopper PK_RMAPI.AUTO_MAKE_RELEASE failed, returned" + result);
868 mhunt 3837
          throw new Exception("autoMakeRelease show stopper PK_RMAPI.AUTO_MAKE_RELEASE failed, returned" + result);
814 mhunt 3838
        }
844 dpurdie 3839
        stmt.close();
898 mhunt 3840
        commit();
814 mhunt 3841
      }
3842
      catch( SQLException e )
3843
      {
3844
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3845
        {
3846
          mLogger.error("autoMakeRelease database access error only");
3847
          throw new SQLException();
3848
        }
3849
        else
3850
        {
3851
          mLogger.fatal("autoMakeRelease show stopper");
868 mhunt 3852
          throw new Exception("autoMakeRelease show stopper");
814 mhunt 3853
        }
3854
      }
898 mhunt 3855
      finally
3856
      {
3857
        // this block is executed regardless of what happens in the try block
3858
        // even if an exception is thrown
3859
        // ensure disconnect
3860
        disconnect();
3861
      }
814 mhunt 3862
    }
3863
  }
3864
 
3865
  /**handles database connection/disconnection
834 mhunt 3866
   * executes the insertPackageMetrics stored procedure with the passed parameters
3867
   */
3868
  public void insertPackageMetrics(String rtagId, String packageName, 
3869
                              		 String packageExtension, String metrics) throws SQLException, Exception
3870
  {
3871
    mLogger.debug("insertPackageMetrics " + packageName);
3872
    if ( mUseDatabase )
3873
    {
3874
      try
3875
      {
3876
        connect();
3877
        CallableStatement stmt = mConnection.prepareCall( "begin ? := PK_RMAPI.INSERT_PACKAGE_METRICS(?,?,?,?); end;" );
3878
        stmt.registerOutParameter( 1, Types.INTEGER);
3879
        stmt.setString( 2, rtagId );
3880
        stmt.setString( 3, packageName );
3881
        stmt.setString( 4, packageExtension );
3882
        stmt.setString( 5, metrics );
3883
        stmt.executeUpdate();
3884
        int result = stmt.getInt( 1 );
3885
 
836 mhunt 3886
        if ( result != 0 )
834 mhunt 3887
        {
3888
          // flag build failure
3889
          mLogger.fatal("insertPackageMetrics show stopper PK_RMAPI.INSERT_PACKAGE_METRICS failed, returned" + result);
868 mhunt 3890
          throw new Exception("insertPackageMetrics show stopper PK_RMAPI.INSERT_PACKAGE_METRICS failed, returned" + result);
834 mhunt 3891
        }
844 dpurdie 3892
        stmt.close();
898 mhunt 3893
        commit();
834 mhunt 3894
      }
3895
      catch( SQLException e )
3896
      {
3897
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3898
        {
3899
          mLogger.error("insertPackageMetrics database access error only");
3900
          throw new SQLException();
3901
        }
3902
        else
3903
        {
3904
          mLogger.fatal("insertPackageMetrics show stopper");
868 mhunt 3905
          throw new Exception("insertPackageMetrics show stopper");
834 mhunt 3906
        }
3907
      }
898 mhunt 3908
      finally
3909
      {
3910
        // this block is executed regardless of what happens in the try block
3911
        // even if an exception is thrown
3912
        // ensure disconnect
3913
        disconnect();
3914
      }
834 mhunt 3915
    }
3916
  }
3917
 
900 mhunt 3918
  /**attempts to execute the Exclude_Indirect_From_Build stored procedure
3919
   * NB Execute_Indirect_From_Build will delete matching do_not_ripple rows prior to an insertion
3920
   * this is crucial!!
3921
   * 
3922
   * parameters:
3923
   * packageVersionId IN passed to Exclude_Indirect_From_Build 
3924
   * packageVersion   IN passed to Exclude_Indirect_From_Build 
3925
   * rtagId           IN passed to Exclude_Indirect_From_Build
3926
   * rootPvId         IN passed to Exclude_Indirect_From_Build
3927
   * rootCause        IN passed to Exclude_Indirect_From_Build
3928
   * rootFile         IN passed to Exclude_Indirect_From_Build
3929
   * supercede        IN checks for a row with a matching packageVersionId and rtagId when false
3930
   *                     such a row will prevent the execution of Exclude_Indirect_From_Build
908 mhunt 3931
   * testBuildInstruction IN will prevent the execution of Exclude_Indirect_From_Build when > 0
900 mhunt 3932
   * 
3933
   * returns:
3934
   * none
814 mhunt 3935
   */
3936
  public void excludeFromBuild(String packageVersionId, 
866 mhunt 3937
                               String packageVersion, String rtagId, String rootPvId,
908 mhunt 3938
                               String rootCause, String rootFile,
3939
                               boolean supercede, int testBuildInstruction) throws SQLException, Exception
814 mhunt 3940
  {
3941
    mLogger.debug("excludeFromBuild " + packageVersionId);
908 mhunt 3942
    if ( testBuildInstruction > 0 )
3943
    {
3944
      return;
3945
    }
3946
 
814 mhunt 3947
    if ( mUseDatabase )
3948
    {
3949
      try
3950
      {
908 mhunt 3951
        connect();
898 mhunt 3952
 
896 mhunt 3953
        boolean exist = false;
3954
 
900 mhunt 3955
        if ( !supercede )
814 mhunt 3956
        {
900 mhunt 3957
          // do not exclude a package already excluded ie let the first build failure count
3958
          // there is a window of opportunity here, but it is worth doing
3959
          // scenario 1
3960
          // 1 this query indicates no build failure exists on this version
3961
          // 2 another build machine reports a build failure on this version
3962
          // 3 this is then overridden by this thread
3963
          // does not matter
3964
          // doing this works well for the following
3965
          // scenario 2
3966
          // 1 this query (run by a slave) indicates no build failure exists on this version
3967
          // 2 build failure is reported
3968
          // 3 master build machine detects slave in state waiting
3969
          // 4 master daemon discovers slave did not deliver artifacts
3970
          // 5 master daemon is prevented from overriding the build failure
3971
          CallableStatement stmt = mConnection.prepareCall("select pv_id from release_manager.do_not_ripple where pv_id=" + packageVersionId + "and rtag_id=" + rtagId);
3972
          ResultSet rset = stmt.executeQuery();
3973
 
3974
          while( rset.next() )
3975
          {
3976
            exist = true;
3977
            break;
3978
          }
3979
 
3980
          rset.close();
3981
          stmt.close();
814 mhunt 3982
        }
896 mhunt 3983
 
3984
        if ( !exist )
3985
        {
900 mhunt 3986
          CallableStatement stmt = mConnection.prepareCall( "begin ? := PK_RMAPI.EXCLUDE_INDIRECT_FROM_BUILD(?,?,?,?,?,?,?); end;" );
896 mhunt 3987
          stmt.registerOutParameter( 1, Types.INTEGER);
3988
          stmt.setString( 2, packageVersionId );
3989
          stmt.setString( 3, packageVersion );
3990
          stmt.setString( 4, rtagId );
3991
          stmt.setString( 5, "buildadm" );
3992
          stmt.setString( 6, rootPvId);
3993
          stmt.setString( 7, rootCause);
3994
          stmt.setString( 8, rootFile);
3995
          stmt.executeUpdate();
3996
          int result = stmt.getInt( 1 );
3997
 
3998
          if ( result != 0 )
3999
          {
4000
            // flag build failure
4001
            mLogger.fatal( "excludeFromBuild show stopper PK_RMAPI.EXCLUDE_INDIRECT_FROM_BUILD failed, returned " + result );
4002
            throw new Exception("excludeFromBuild show stopper PK_RMAPI.EXCLUDE_INDIRECT_FROM_BUILD failed, returned " + result);
4003
          }
4004
          stmt.close();
908 mhunt 4005
          commit();
896 mhunt 4006
        }
814 mhunt 4007
      }
4008
      catch( SQLException e )
4009
      {
4010
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4011
        {
4012
          mLogger.error("excludeFromBuild database access error only");
4013
          throw new SQLException();
4014
        }
4015
        else
4016
        {
4017
          mLogger.fatal("excludeFromBuild show stopper");
868 mhunt 4018
          throw new Exception("excludeFromBuild show stopper");
814 mhunt 4019
        }
4020
      }
898 mhunt 4021
      finally
4022
      {
4023
        // this block is executed regardless of what happens in the try block
4024
        // even if an exception is thrown
4025
        // ensure disconnect
908 mhunt 4026
        disconnect();
4027
      }
4028
    }
4029
  }
4030
 
4031
  /**executes the get_daemon_inst function with the passed parameters
4032
   * returns true when an instruction exists
4033
   */
4034
  private boolean getDaemonInst(final int rtagId, MutableInt instruction, 
4035
                               final int opCode, MutableInt pvId, MutableInt userId ) throws SQLException, Exception
4036
  {
4037
    mLogger.debug("getDaemonInst " + instruction);
4038
    boolean retVal = false;
4039
 
4040
    if ( mUseDatabase )
4041
    {
4042
      try
4043
      {
4044
        CallableStatement stmt = mConnection.prepareCall( "begin ? := PK_BUILDAPI.GET_DAEMON_INST(?,?,?,?,?,?); end;" );
4045
        stmt.registerOutParameter(1, Types.INTEGER);
4046
        stmt.registerOutParameter(3, Types.INTEGER);
4047
        stmt.registerOutParameter(4, Types.INTEGER);
4048
        stmt.registerOutParameter(5, Types.INTEGER);
4049
        stmt.registerOutParameter(6, Types.INTEGER);
4050
        stmt.registerOutParameter(7, Types.INTEGER);
4051
        stmt.setInt(2, rtagId );
4052
        stmt.setInt( 3, instruction.value );
4053
        stmt.setInt( 4, opCode );
4054
        stmt.execute();
4055
        int result = stmt.getInt( 1 );
4056
 
4057
        if ( result == 1 )
898 mhunt 4058
        {
908 mhunt 4059
          retVal = true;
4060
          instruction.value = stmt.getInt( 3 );
4061
          pvId.value = stmt.getInt( 5 );
4062
          userId.value = stmt.getInt( 6 );
898 mhunt 4063
        }
908 mhunt 4064
 
4065
        stmt.close();
898 mhunt 4066
      }
908 mhunt 4067
      catch( SQLException e )
4068
      {
4069
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4070
        {
4071
          mLogger.error("getDaemonInst database access error only");
4072
          throw new SQLException();
4073
        }
4074
        else
4075
        {
4076
          mLogger.fatal("getDaemonInst show stopper");
4077
          throw new Exception("getDaemonInst show stopper");
4078
        }
4079
      }
814 mhunt 4080
    }
908 mhunt 4081
 
4082
    return retVal;
814 mhunt 4083
  }
4084
 
908 mhunt 4085
  /**executes the mark_daemon_inst_in_progress function with the passed parameters
4086
   */
4087
  public void markDaemonInstInProgress(final int instruction) throws SQLException, Exception
4088
  {
4089
    mLogger.debug("markDaemonInstInProgress " + instruction);
4090
 
4091
    if ( mUseDatabase )
4092
    {
4093
      try
4094
      {
4095
        CallableStatement stmt = mConnection.prepareCall( "call PK_BUILDAPI.MARK_DAEMON_INST_IN_PROGRESS(?)" );
4096
        stmt.setInt( 1, instruction );
4097
        stmt.executeUpdate();
4098
        stmt.close();
4099
      }
4100
      catch( SQLException e )
4101
      {
4102
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4103
        {
4104
          mLogger.error("markDaemonInstInProgress database access error only");
4105
          throw new SQLException();
4106
        }
4107
        else
4108
        {
4109
          mLogger.fatal("markDaemonInstInProgress show stopper");
4110
          throw new Exception("markDaemonInstInProgress show stopper");
4111
        }
4112
      }
4113
    }
4114
  }
4115
 
4116
  /**executes the mark_daemon_inst_completed function with the passed parameters
4117
   */
4118
  public void markDaemonInstCompleted(final int instruction) throws SQLException, Exception
4119
  {
4120
    mLogger.debug("markDaemonInstCompleted " + instruction);
4121
 
4122
    if ( mUseDatabase )
4123
    {
4124
      try
4125
      {
4126
        CallableStatement stmt = mConnection.prepareCall( "call PK_BUILDAPI.MARK_DAEMON_INST_COMPLETED(?)" );
4127
        stmt.setInt( 1, instruction );
4128
        stmt.executeUpdate();
4129
        stmt.close();
4130
      }
4131
      catch( SQLException e )
4132
      {
4133
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4134
        {
4135
          mLogger.error("markDaemonInstCompleted database access error only");
4136
          throw new SQLException();
4137
        }
4138
        else
4139
        {
4140
          mLogger.fatal("markDaemonInstCompleted show stopper");
4141
          throw new Exception("markDaemonInstCompleted show stopper");
4142
        }
4143
      }
4144
    }
4145
  }
4146
 
4147
  /**handles database connection/disconnection
4148
   * executes the mark_daemon_inst_completed function with the passed parameters
4149
   */
4150
  public void markDaemonInstCompletedConnect(final int instruction) throws SQLException, Exception
4151
  {
4152
    mLogger.debug("markDaemonInstCompletedConnect " + instruction);
4153
 
4154
    try
4155
    {
4156
      connect();
4157
      markDaemonInstCompleted(instruction);
4158
      commit();
4159
    }
4160
    catch( SQLException e )
4161
    {
4162
      if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4163
      {
4164
        mLogger.error("markDaemonInstCompletedConnect database access error only");
4165
        throw new SQLException();
4166
      }
4167
      else
4168
      {
4169
        mLogger.fatal("markDaemonInstCompletedConnect show stopper");
4170
        throw new Exception("markDaemonInstCompletedConnect show stopper");
4171
      }
4172
    }
4173
    finally
4174
    {
4175
      // this block is executed regardless of what happens in the try block
4176
      // even if an exception is thrown
4177
      // ensure disconnect
4178
      disconnect();
4179
    }
4180
  }
4181
 
866 mhunt 4182
  /**removes an excluded package from the do_not_ripple table
4183
   */
4184
  public void includeToBuild(String packageVersionId, String rtagId) throws SQLException, Exception
4185
  {
4186
    mLogger.debug("includeToBuild " + packageVersionId);
4187
    if ( mUseDatabase )
4188
    {
4189
      try
4190
      {
4191
        CallableStatement stmt = mConnection.prepareCall("delete from release_manager.do_not_ripple where rtag_id=" + rtagId + " and pv_id=" + packageVersionId);
4192
        stmt.executeUpdate();
4193
        stmt.close();
4194
      }
4195
      catch( SQLException e )
4196
      {
4197
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4198
        {
4199
          mLogger.error("includeToBuild database access error only");
4200
          throw new SQLException();
4201
        }
4202
        else
4203
        {
4204
          mLogger.fatal("includeToBuild show stopper");
868 mhunt 4205
          throw new Exception("includeToBuild show stopper");
866 mhunt 4206
        }
4207
      }
4208
    }
4209
  }
4210
 
814 mhunt 4211
  /**Representation of a row in the RELEASE_CONFIG table
4212
   */
4213
  private class ReleaseConfig
4214
  {
4215
    /**rtag_id column value
4216
     * @attribute
4217
     */
4218
    private int mRtag_id;
4219
 
4220
    /**rcon_id column value
4221
     * @attribute
4222
     */
4223
    private int mRcon_id;
4224
 
4225
    /**daemon_mode column value
4226
     * @attribute
4227
     */
4228
    private char mDaemon_mode;
4229
 
4230
    /**constructor
4231
     */
896 mhunt 4232
    ReleaseConfig(int rtag_id, int rcon_id, char daemon_mode)
814 mhunt 4233
    {
896 mhunt 4234
      mLogger.debug("ReleaseConfig rtag_id " + rtag_id + " rcon_id " + rcon_id + " daemon_mode " + daemon_mode );
814 mhunt 4235
      mRtag_id = rtag_id;
4236
      mRcon_id = rcon_id;
4237
      mDaemon_mode = daemon_mode;
4238
    }
4239
 
4240
    /**accessor method
4241
     */
4242
    int get_rtag_id()
4243
    {
4244
      mLogger.debug("get_rtag_id");
4245
      mLogger.info("get_rtag_id returned " + mRtag_id);
4246
      return mRtag_id;
4247
    }
4248
 
4249
    /**accessor method
4250
     */
4251
    int get_rcon_id()
4252
    {
4253
      mLogger.debug("get_rcon_id");
4254
      mLogger.info("get_rcon_id returned " + mRcon_id);
4255
      return mRcon_id;
4256
    }
4257
 
4258
    /**accessor method
4259
     */
4260
    char get_daemon_mode()
4261
    {
4262
      mLogger.debug("get_daemon_mode");
4263
      mLogger.info("get_daemon_mode returned " + mDaemon_mode);
4264
      return mDaemon_mode;
4265
    }
4266
  }
4267
 
4268
  /**Representation of a row in the RUN_LEVEL table
4269
   */
4270
  private class RunLevel
4271
  {
4272
    /**rcon_id column value
4273
     * @attribute
4274
     */
4275
    private int mRcon_id;
4276
 
4277
    /**current_build_files column value
4278
     * @attribute
4279
     */
4280
    private String mCurrent_build_file;
4281
 
4282
    /**current_run_level column value
4283
     * @attribute
4284
     */
4285
    private int mCurrent_run_level;
4286
 
4287
    /**pause column value
4288
     * @attribute
4289
     */
4290
    private boolean mPause;
4291
 
4292
    /**constructor
4293
     */
4294
    RunLevel(int rcon_id, String current_build_file, int current_run_level, 
4295
             boolean pause)
4296
    {
4297
      mLogger.debug("RunLevel");
4298
      mRcon_id = rcon_id;
4299
      mCurrent_build_file = current_build_file;
4300
      mCurrent_run_level = current_run_level;
4301
      mPause = pause;
4302
    }
4303
 
4304
    /**accessor method
4305
     */
4306
    int get_rcon_id()
4307
    {
4308
      mLogger.debug("get_rcon_id");
4309
      mLogger.info("get_rcon_id returned " + mRcon_id);
4310
      return mRcon_id;
4311
    }
4312
 
4313
    /**accessor method
4314
     */
4315
    String get_current_build_file()
4316
    {
4317
      mLogger.debug("get_current_build_file");
4318
      mLogger.info("get_current_build_file returned " + mCurrent_build_file);
4319
      return mCurrent_build_file;
4320
    }
4321
 
4322
    /**accessor method
4323
     */
4324
    int get_current_run_level()
4325
    {
4326
      mLogger.debug("get_current_run_level");
4327
      mLogger.info("get_current_run_level returned " + mCurrent_run_level);
4328
      return mCurrent_run_level;
4329
    }
4330
 
4331
    /**accessor method
4332
     */
4333
    boolean get_pause()
4334
    {
4335
      mLogger.debug("get_pause");
4336
      mLogger.debug("get_pause returned " + mPause);      
4337
      return mPause;
4338
    }
4339
 
4340
  }
4341
 
4342
  /**constructor
4343
   */
4344
  public ReleaseManager(final String connectionString, final String username, 
4345
                        final String password)
4346
  {
4347
    mLogger.debug("ReleaseManager " + connectionString);
4348
    mConnectionString = connectionString;
4349
    mUsername = username;
4350
    mPassword = password;
4351
  }
4352
 
4353
  /**constructor used when schema information is unknown eg location, username, password
4354
   */
4355
  public ReleaseManager()
4356
  {
4357
    // inherit mConnectionString, mUsername, mPassword
4358
     mLogger.debug("ReleaseManager");
4359
  }
4360
 
4361
  /**connect to oracle
4362
   */
4363
  public void connect() throws SQLException, Exception
4364
  {
4365
    mLogger.debug("connect");
4366
 
898 mhunt 4367
    if ( mSession.isHeldByCurrentThread() )
4368
    {
4369
      // by design a thread must NOT connect multiple times
4370
      // this is to ensure the lock is claimed only once
4371
      mLogger.error("connect thread already has the lock");
4372
    }
4373
    else
4374
    {
4375
      mLogger.warn("connect calling lock");
4376
      mSession.lock();
4377
      mLogger.warn("connect called lock");
4378
    }
4379
 
814 mhunt 4380
    if ( !mUseDatabase )
4381
    {
4382
      mLogger.info("connect !mUseDatabase");
4383
    }
4384
    else
4385
    {
838 mhunt 4386
      // DEVI 46868
4387
      // loop indefinitely until a connection attempt succeeds
4388
      // unless the failure is on the first attempt
4389
      boolean problemConnecting;
4390
 
4391
      do
814 mhunt 4392
      {
850 mhunt 4393
        mLogger.warn("connect check connection");
838 mhunt 4394
        problemConnecting = false;
4395
 
4396
        try
836 mhunt 4397
        {
850 mhunt 4398
          if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
838 mhunt 4399
          {
850 mhunt 4400
            mLogger.warn("connect calling getConnection");
906 mhunt 4401
            mConnection = DriverManager.getConnection(mConnectionString, mUsername, mPassword);
900 mhunt 4402
            // when connection to the database is established, the connection, by default, is in auto-commit mode
4403
            // to adhere to the design in the use of select for update, it is crucial to turn auto-commit off
4404
            // this also improves performance
4405
            mConnection.setAutoCommit(false);
838 mhunt 4406
          }
836 mhunt 4407
        }
838 mhunt 4408
        catch(SQLException e)
4409
        {
850 mhunt 4410
          mLogger.warn("connect determined problem connecting");
838 mhunt 4411
          problemConnecting = true;
4412
          try
4413
          {
4414
            // sleep 30 secs
844 dpurdie 4415
            mLogger.warn("connect getConnection failed. sleep 30secs");
838 mhunt 4416
            Thread.sleep(30000);
4417
          }
4418
          catch (InterruptedException f)
4419
          {
4420
            mLogger.warn("connect caught InterruptedException");
4421
          }
4422
 
844 dpurdie 4423
 
838 mhunt 4424
          if ( mConnection == null )
4425
          {
4426
            // failed on first connection attempt - unlikely due to database loading - likely bad connection parameters
4427
            throw new SQLException();
4428
          }
4429
        }
4430
      } while ( problemConnecting );
814 mhunt 4431
    }
844 dpurdie 4432
 
814 mhunt 4433
  }
4434
 
4435
  /**disconnect from oracle
4436
   */
836 mhunt 4437
  public void disconnect() throws Exception
814 mhunt 4438
  {
4439
    mLogger.debug("disconnect");
838 mhunt 4440
/* DEVI 46868 
4441
 * never disconnect, thus the only time a connection attempt is made
4442
 * is when the server has (timed out) disconnected the session
4443
 *  if ( mUseDatabase )
814 mhunt 4444
    {
4445
      try
4446
      {
4447
        mConnection.close();
4448
      }
4449
      catch(SQLException e)
4450
      {
4451
        mLogger.error("disconnect caught Exception");
836 mhunt 4452
        throw new Exception();
814 mhunt 4453
      }
838 mhunt 4454
    }*/
898 mhunt 4455
 
4456
    // by design, a thread may call disconnect multiple times
4457
    // this is a technique used in finally blocks
4458
    // it is to ensure the lock is released in all cases
4459
    // only unlock if it is held by this thread
4460
    // when unlock is called on a ReentrantLock held by this thread
4461
    // the hold count is decremented
4462
    // connect should only let the hold count be incremented to 1
4463
    // when the hold count is 0 the lock is released
4464
    // and the ReentrantLock is no longer held by this thread
4465
    // only call unlock when the lock is held by this thread
4466
    if ( mSession.isHeldByCurrentThread() )
4467
    {
4468
      mLogger.warn("disconnected calling unlock");
4469
      mSession.unlock();
4470
      mLogger.warn("disconnected called unlock");
4471
    }
814 mhunt 4472
  }
4473
 
4474
  /**returns true if the mReleaseConfigCollection is not empty and returns the rcon_id of the first element
4475
   */
4476
  public boolean getFirstReleaseConfig(MutableInt rcon_id)
4477
  {
4478
    mLogger.debug("getFirstReleaseConfig 1");
4479
    boolean retVal = true;
4480
 
4481
    try
4482
    {
4483
      mReleaseConfigIndex = 0;
864 mhunt 4484
      ReleaseConfig rc = mReleaseConfigCollection.get( mReleaseConfigIndex );
814 mhunt 4485
      rcon_id.value = rc.get_rcon_id();
4486
    }
4487
    catch( ArrayIndexOutOfBoundsException e )
4488
    {
4489
      retVal = false;
4490
    }
4491
 
4492
    mLogger.info("getFirstReleaseConfig 1 returning " + retVal);
4493
    return retVal;
4494
  }
4495
 
4496
  /**returns true if the mReleaseConfigCollection is not empty and returns the rcon_id, rtag_id, daemon_mode and gbebuildfilter of the first element
4497
   */
4498
  public boolean getFirstReleaseConfig(MutableInt rtag_id, 
4499
                                       MutableInt rcon_id, 
896 mhunt 4500
                                       MutableChar daemon_mode)
814 mhunt 4501
  {
4502
    mLogger.debug("getFirstReleaseConfig 2");
4503
    boolean retVal = true;
4504
 
4505
    try
4506
    {
4507
      mReleaseConfigIndex = 0;
864 mhunt 4508
      ReleaseConfig rc = mReleaseConfigCollection.get( mReleaseConfigIndex );
814 mhunt 4509
      rtag_id.value = rc.get_rtag_id();
4510
      rcon_id.value = rc.get_rcon_id();
4511
      daemon_mode.value = rc.get_daemon_mode();
4512
    }
4513
    catch( ArrayIndexOutOfBoundsException e )
4514
    {
4515
      retVal = false;
4516
    }
4517
 
4518
    mLogger.info("getFirstReleaseConfig 2 returning " + retVal);
4519
    return retVal;
4520
  }
4521
 
4522
  /**returns true if the mRunLevelCollection is not empty and returns the rcon_id and current_run_level of the first element
4523
   */
4524
  public boolean getFirstRunLevel(MutableInt rcon_id, 
4525
                                  MutableInt current_run_level)
4526
  {
4527
    mLogger.debug("getFirstRunLevel");
4528
    boolean retVal = true;
4529
 
4530
    try
4531
    {
4532
      mRunLevelIndex = 0;
864 mhunt 4533
      RunLevel rl = mRunLevelCollection.get( mRunLevelIndex );
814 mhunt 4534
      rcon_id.value = rl.get_rcon_id();
4535
      current_run_level.value = rl.get_current_run_level();
4536
    }
4537
    catch( ArrayIndexOutOfBoundsException e )
4538
    {
4539
      retVal = false;
4540
    }
4541
 
4542
    mLogger.info("getFirstRunLevel returning " + retVal);
4543
    return retVal;
4544
  }
4545
 
4546
  /**returns true if the mReleaseConfigCollection contains a next element and returns the rcon_id of the next element
4547
   */
4548
  public boolean getNextReleaseConfig(MutableInt rcon_id)
4549
  {
4550
    mLogger.debug("getNextReleaseConfig 1");
4551
    boolean retVal = true;
4552
 
4553
    try
4554
    {
4555
      mReleaseConfigIndex++;
864 mhunt 4556
      ReleaseConfig rc = mReleaseConfigCollection.get( mReleaseConfigIndex );
814 mhunt 4557
      rcon_id.value = rc.get_rcon_id();
4558
    }
4559
    catch( ArrayIndexOutOfBoundsException e )
4560
    {
4561
      retVal = false;
4562
    }
4563
 
4564
    mLogger.info("getNextReleaseConfig 1 returning " + retVal);
4565
    return retVal;
4566
  }
4567
 
4568
  /**returns true if the mReleaseConfigCollection contains a next element and returns the rcon_id, rtag_id, daemon_mode and gbebuildfilter of the next element
4569
   */
4570
  public boolean getNextReleaseConfig(MutableInt rtag_id, 
4571
                                      MutableInt rcon_id, 
896 mhunt 4572
                                      MutableChar daemon_mode)
814 mhunt 4573
  {
4574
    mLogger.debug("getNextReleaseConfig 2");
4575
    boolean retVal = true;
4576
 
4577
    try
4578
    {
4579
      mReleaseConfigIndex++;
864 mhunt 4580
      ReleaseConfig rc = mReleaseConfigCollection.get( mReleaseConfigIndex );
814 mhunt 4581
      rtag_id.value = rc.get_rtag_id();
4582
      rcon_id.value = rc.get_rcon_id();
4583
      daemon_mode.value = rc.get_daemon_mode();
4584
    }
4585
    catch( ArrayIndexOutOfBoundsException e )
4586
    {
4587
      retVal = false;
4588
    }
4589
 
4590
    mLogger.info("getNextReleaseConfig 2 returning " + retVal);
4591
    return retVal;
4592
  }
4593
 
4594
  /**returns true if the mRunLevelCollection contains a next element and returns the rcon_id and current_run_level of the next element
4595
   */
4596
  public boolean getNextRunLevel(MutableInt rcon_id, 
4597
                                 MutableInt current_run_level)
4598
  {
4599
    mLogger.debug("getNextRunLevel");
4600
    boolean retVal = true;
4601
 
4602
    try
4603
    {
4604
      mRunLevelIndex++;
864 mhunt 4605
      RunLevel rl = mRunLevelCollection.get( mRunLevelIndex );
814 mhunt 4606
      rcon_id.value = rl.get_rcon_id();
4607
      current_run_level.value = rl.get_current_run_level();
4608
    }
4609
    catch( ArrayIndexOutOfBoundsException e )
4610
    {
4611
      retVal = false;
4612
    }
4613
 
4614
    mLogger.info("getNextRunLevel returning " + retVal);
4615
    return retVal;
4616
  }
4617
 
4618
  /**queries the RUN_LEVEL table using the rcon_id primary key
4619
   * returns false if the query returns a result set containing one row with a non NULL pause column
882 mhunt 4620
   * returns false if the rcon_id is no longer configured
814 mhunt 4621
   * (indicating intent to pause the thread)
4622
   * refer to sequence diagram allowed to proceed
4623
   */
4624
  public boolean queryDirectedRunLevel(final int rcon_id) throws SQLException, Exception
4625
  {
4626
    mLogger.debug("queryDirectedRunLevel " + rcon_id);
4627
    boolean retVal = true;
4628
 
4629
    if ( mUseDatabase )
4630
    {
4631
      try
4632
      {
882 mhunt 4633
        if ( isRconIdConfigured( rcon_id ))
814 mhunt 4634
        {
882 mhunt 4635
          CallableStatement stmt = mConnection.prepareCall("select pause from release_manager.run_level where rcon_id=" + rcon_id);
4636
          ResultSet rset = stmt.executeQuery();
4637
          int rsetSize = 0;
814 mhunt 4638
 
882 mhunt 4639
          while( rset.next() )
814 mhunt 4640
          {
882 mhunt 4641
            rsetSize++;
4642
            rset.getInt("pause");
4643
 
4644
            if ( !rset.wasNull() )
4645
            {
4646
              retVal = false;
4647
            }
814 mhunt 4648
          }
882 mhunt 4649
 
4650
          rset.close();
4651
          stmt.close();
4652
 
4653
          if ( rsetSize > 1 )
4654
          {
4655
            mLogger.fatal("queryDirectedRunLevel rsetSize > 1");
4656
            // show stopper
4657
            throw new Exception("queryDirectedRunLevel rsetSize > 1");
4658
          }
814 mhunt 4659
        }
882 mhunt 4660
        else
814 mhunt 4661
        {
882 mhunt 4662
          retVal = false;
814 mhunt 4663
        }
4664
      }
4665
      catch ( SQLException e )
4666
      {
4667
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4668
        {
4669
          mLogger.error("queryDirectedRunLevel database access error only");
4670
          throw new SQLException();
4671
        }
4672
        else
4673
        {
4674
          mLogger.fatal("queryDirectedRunLevel show stopper");
868 mhunt 4675
          throw new Exception("queryDirectedRunLevel show stopper");
814 mhunt 4676
        }
4677
      }
4678
    }
4679
 
4680
    mLogger.info("queryDirectedRunLevel returning " + retVal);
4681
    return retVal;
4682
  }
4683
 
896 mhunt 4684
  /**queries the RELEASE_CONFIG table using the rcon_id primary key, rtag_id, daemon_hostname, daemon_mode
814 mhunt 4685
   * return true if the query contains a result set containing one row
896 mhunt 4686
   * (indicating the rcon_id is still configured and its configuration is unchanged, aside from the gbe_buildfilter)
4687
   * the gbe_buildfilter is queried prior to usage
814 mhunt 4688
   * refer to sequence diagram allowed to proceed
4689
   */
4690
  public boolean queryReleaseConfig(final int rtag_id, final int rcon_id, 
4691
                                    final String daemon_hostname, 
896 mhunt 4692
                                    final char daemon_mode) throws SQLException, Exception
814 mhunt 4693
  {
4694
    mLogger.debug("queryReleaseConfig 1");
4695
    boolean retVal = false;
4696
 
4697
    if ( !mUseDatabase )
4698
    {
4699
      mLogger.info("queryReleaseConfig 1 !mUseDatabase");
4700
 
4701
      if ( mConnectionString.compareTo("unit test exit") != 0 )
4702
      {
4703
        retVal = true;
4704
      }
4705
    }
4706
    else
4707
    {
4708
      try
4709
      {
856 mhunt 4710
        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 4711
        CallableStatement stmt = mConnection.prepareCall( sql );
4712
        ResultSet rset = stmt.executeQuery();
4713
        int rsetSize = 0;
4714
 
4715
        while( rset.next() )
4716
        {
4717
          rsetSize++;
896 mhunt 4718
          retVal = true;
814 mhunt 4719
        }
830 mhunt 4720
 
4721
        rset.close();
4722
        stmt.close();
814 mhunt 4723
 
4724
        if ( rsetSize > 1 )
4725
        {
4726
          mLogger.fatal("queryReleaseConfig 1 rsetSize > 1");
4727
          // show stopper
868 mhunt 4728
          throw new Exception("queryReleaseConfig 1 rsetSize > 1");
814 mhunt 4729
        }
4730
      }
4731
      catch ( SQLException e )
4732
      {
4733
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4734
        {
4735
          mLogger.error("queryReleaseConfig 1 database access error only");
4736
          throw new SQLException();
4737
        }
4738
        else
4739
        {
4740
          mLogger.fatal("queryReleaseConfig 1 show stopper");
868 mhunt 4741
          throw new Exception("queryReleaseConfig 1 show stopper");
814 mhunt 4742
        }
4743
      }
4744
    }
4745
 
4746
    mLogger.info("queryReleaseConfig 1 returning " + retVal);
4747
    return retVal;
4748
  }
4749
 
896 mhunt 4750
  /**queries the RELEASE_CONFIG table using the rcon_id primary key for the gbebuildfilter
4751
   */
4752
  public void queryBuildFilter(final int rcon_id, 
4753
                               MutableString gbebuildfilter) throws SQLException, Exception
4754
  {
4755
    mLogger.debug("queryBuildFilter");
4756
 
4757
    if ( !mUseDatabase )
4758
    {
4759
      mLogger.info("queryBuildFilter !mUseDatabase");
4760
    }
4761
    else
4762
    {
4763
      try
4764
      {
898 mhunt 4765
        connect();
896 mhunt 4766
        String sql = new String("select gbe_buildfilter from release_manager.release_config where rcon_id=" + rcon_id );
4767
        CallableStatement stmt = mConnection.prepareCall( sql );
4768
        ResultSet rset = stmt.executeQuery();
4769
        int rsetSize = 0;
4770
 
4771
        while( rset.next() )
4772
        {
4773
          rsetSize++;
4774
          gbebuildfilter.value = rset.getString("gbe_buildfilter");
4775
        }
4776
 
4777
        rset.close();
4778
        stmt.close();
4779
 
4780
        if ( rsetSize > 1 )
4781
        {
4782
          mLogger.fatal("queryBuildFilter rsetSize > 1");
4783
          // show stopper
4784
          throw new Exception("queryBuildFilter rsetSize > 1");
4785
        }
4786
      }
4787
      catch ( SQLException e )
4788
      {
4789
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4790
        {
4791
          mLogger.error("queryBuildFilter database access error only");
4792
          throw new SQLException();
4793
        }
4794
        else
4795
        {
4796
          mLogger.fatal("queryBuildFilter show stopper");
4797
          throw new Exception("queryBuildFilter show stopper");
4798
        }
4799
      }
898 mhunt 4800
      finally
4801
      {
4802
        // this block is executed regardless of what happens in the try block
4803
        // even if an exception is thrown
4804
        // ensure disconnect
4805
        disconnect();
4806
      }
896 mhunt 4807
    }
4808
  }
4809
 
814 mhunt 4810
  /**removes all elements from the mReleaseConfigCollection
4811
   * handles database connection and disconnection
4812
   * queries the RELEASE_CONFIG table using the rtag_id
4813
   * populates the mReleaseConfigCollection with the query result set
4814
   * partially implements the sequence diagrams coordinate slave threads generate build files
4815
   */
4816
  public void queryReleaseConfig(final int rtag_id) throws SQLException, Exception
4817
  {
4818
    mLogger.debug("queryReleaseConfig 2");
4819
    mReleaseConfigCollection.removeAllElements();
4820
 
4821
    if ( !mUseDatabase )
4822
    {
4823
      mLogger.info("queryReleaseConfig 2 !mUseDatabase");
896 mhunt 4824
      ReleaseConfig releaseConfig = new ReleaseConfig(1,1,'M');
814 mhunt 4825
      mReleaseConfigCollection.add(releaseConfig);
896 mhunt 4826
      releaseConfig = new ReleaseConfig(1,2,'S');
814 mhunt 4827
      mReleaseConfigCollection.add(releaseConfig);
4828
    }
4829
    else
4830
    {
4831
      try
4832
      {
4833
        connect();
882 mhunt 4834
 
896 mhunt 4835
        CallableStatement stmt = mConnection.prepareCall("select rcon_id, daemon_mode from release_manager.release_config where rtag_id=" + rtag_id );
814 mhunt 4836
        ResultSet rset = stmt.executeQuery();
4837
 
4838
        while( rset.next() )
4839
        {
4840
          int rcon_id = rset.getInt("rcon_id");
4841
 
4842
          if ( rset.wasNull() )
4843
          {
4844
            mLogger.fatal("queryReleaseConfig 2 null rcon_id " + rtag_id);
4845
            // show stopper
868 mhunt 4846
            throw new Exception("queryReleaseConfig 2 null rcon_id " + rtag_id);
814 mhunt 4847
          }
4848
 
4849
          char dm = 'S';          
4850
          String daemon_mode = rset.getString("daemon_mode");
4851
 
4852
          if ( daemon_mode != null )
4853
          {
4854
            mLogger.info("queryReleaseConfig 2 daemon_mode " + daemon_mode + ".");
4855
 
4856
            if ( daemon_mode.compareTo("M") == 0 )
4857
            {
4858
              dm = 'M';
4859
            }
4860
          }
4861
 
896 mhunt 4862
          ReleaseConfig releaseConfig = new ReleaseConfig( rtag_id, rcon_id, dm );
814 mhunt 4863
          mReleaseConfigCollection.add(releaseConfig);
4864
        }
4865
 
830 mhunt 4866
 
4867
        rset.close();
4868
        stmt.close();
814 mhunt 4869
      }
4870
      catch ( SQLException e )
4871
      {
4872
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4873
        {
4874
          mLogger.error("queryReleaseConfig 2 daemon_mode database access error only");
4875
          throw new SQLException();
4876
        }
4877
        else
4878
        {
4879
          mLogger.fatal("queryReleaseConfig 2 show stopper");
868 mhunt 4880
          throw new Exception("queryReleaseConfig 2 show stopper");
814 mhunt 4881
        }
4882
      }
898 mhunt 4883
      finally
4884
      {
4885
        // this block is executed regardless of what happens in the try block
4886
        // even if an exception is thrown
4887
        // ensure disconnect
4888
        disconnect();
4889
      }
814 mhunt 4890
    }
4891
  }
4892
 
4893
  /**removes all elements from the mReleaseConfigCollection
4894
   * handles database connection and disconnection
4895
   * queries the RELEASE_CONFIG table using the daemon_hostname
4896
   * populates the mReleaseConfigCollection with the query result set
4897
   * partially implements the sequence diagram spawn thread
4898
   */
4899
  public void queryReleaseConfig(final String hostname) throws SQLException, Exception
4900
  {
4901
    mLogger.debug("queryReleaseConfig 3 " + hostname);
4902
    mReleaseConfigCollection.removeAllElements();
4903
 
4904
    if ( mConnectionString.compareTo("unit test spawn thread") == 0)
4905
    {
4906
      mLogger.info("queryReleaseConfig 3 unit test spawn thread");
4907
      // specifying a gbebuildfilter of unit test is designed to invoke a benign thread for unit test purposes
896 mhunt 4908
      ReleaseConfig releaseConfig = new ReleaseConfig(1,1,'M');
814 mhunt 4909
      mReleaseConfigCollection.add(releaseConfig);
896 mhunt 4910
      releaseConfig = new ReleaseConfig(2,2,'S');
814 mhunt 4911
      mReleaseConfigCollection.add(releaseConfig);
4912
    }
4913
    else
4914
    {
4915
      try
4916
      {
4917
        connect();
896 mhunt 4918
        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 4919
        ResultSet rset = stmt.executeQuery();
4920
 
4921
        while( rset.next() )
4922
        {
4923
          int rtag_id = rset.getInt("rtag_id");
4924
 
4925
          if ( rset.wasNull() )
4926
          {
4927
            mLogger.fatal("queryReleaseConfig 3 null rtag_id");
4928
            // show stopper
868 mhunt 4929
            throw new Exception("queryReleaseConfig 3 null rtag_id");
814 mhunt 4930
          }
4931
 
4932
          int rcon_id = rset.getInt("rcon_id");
4933
 
4934
          if ( rset.wasNull() )
4935
          {
4936
            mLogger.fatal("queryReleaseConfig 3 null rcon_id");
4937
            // show stopper
868 mhunt 4938
            throw new Exception("queryReleaseConfig 3 null rcon_id");
814 mhunt 4939
          }
4940
 
4941
          char dm = 'S';          
4942
          String daemon_mode = rset.getString("daemon_mode");
4943
 
4944
          if ( daemon_mode != null )
4945
          {
4946
            mLogger.info("queryReleaseConfig 3 daemon_mode " + daemon_mode + ".");
4947
 
4948
            if ( daemon_mode.compareTo("M") == 0 )
4949
            {
4950
              dm = 'M';
4951
            }
4952
          }
4953
 
896 mhunt 4954
          ReleaseConfig releaseConfig = new ReleaseConfig( rtag_id, rcon_id, dm );
814 mhunt 4955
          mReleaseConfigCollection.add(releaseConfig);
4956
        }
4957
 
830 mhunt 4958
        rset.close();
4959
        stmt.close();
814 mhunt 4960
      }
4961
      catch ( SQLException e )
4962
      {
4963
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4964
        {
4965
          mLogger.error("queryReleaseConfig 3 database access error only");
4966
          throw new SQLException();
4967
        }
4968
        else
4969
        {
4970
          mLogger.fatal("queryReleaseConfig 3 show stopper");
868 mhunt 4971
          throw new Exception("queryReleaseConfig 3 show stopper");
814 mhunt 4972
        }
4973
      }
898 mhunt 4974
      finally
4975
      {
4976
        // this block is executed regardless of what happens in the try block
4977
        // even if an exception is thrown
4978
        // ensure disconnect
4979
        disconnect();
4980
      }
814 mhunt 4981
    }
4982
  }
4983
 
4984
  /**queries the RUN_LEVEL table using the rcon_id primary key
4985
   * handles database connection and disconnection
4986
   * returns the current_build_files
4987
   * implements the sequence diagram consume build files
4988
   */
4989
  public void queryRunLevel(int rcon_id, MutableString currentBuildFiles) throws SQLException, Exception
4990
  {
4991
    mLogger.debug("queryRunLevel 1 rcon_id " + rcon_id);
4992
    if ( !mUseDatabase )
4993
    {
4994
      mLogger.info("queryRunLevel 1 !mUseDatabase");
4995
      currentBuildFiles.value = "unit test build file content";
4996
    }
4997
    else
4998
    {
4999
      try
5000
      {
5001
        connect();
5002
        CallableStatement stmt = mConnection.prepareCall("select current_build_files from release_manager.run_level where rcon_id=" + rcon_id);
5003
        ResultSet rset = stmt.executeQuery();
5004
        int rsetSize = 0;
5005
 
5006
        while( rset.next() )
5007
        {
5008
          rsetSize++;
5009
          currentBuildFiles.value = rset.getString("current_build_files");
5010
          if (rset.wasNull())
5011
          {
5012
            currentBuildFiles.value = "";
5013
          }
5014
        }
5015
 
5016
        if ( rsetSize > 1 )
5017
        {
5018
          mLogger.fatal("queryRunLevel 1 rsetSize > 1");
5019
          // show stopper
868 mhunt 5020
          throw new Exception("queryRunLevel 1 rsetSize > 1");
814 mhunt 5021
        }
5022
 
830 mhunt 5023
        rset.close();
5024
        stmt.close();
814 mhunt 5025
      }
5026
      catch ( SQLException e )
5027
      {
5028
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
5029
        {
5030
          mLogger.error("queryRunLevel 1 database access error only");
5031
          throw new SQLException();
5032
        }
5033
        else
5034
        {
5035
          mLogger.fatal("queryRunLevel 1 show stopper");
868 mhunt 5036
          throw new Exception("queryRunLevel 1 show stopper");
814 mhunt 5037
        }
5038
      }
898 mhunt 5039
      finally
5040
      {
5041
        // this block is executed regardless of what happens in the try block
5042
        // even if an exception is thrown
5043
        // ensure disconnect
5044
        disconnect();
5045
      }
814 mhunt 5046
    }
5047
  }
5048
 
5049
  /**removes all elements from the mRunLevelCollection
5050
   * handles database connection and disconnection
882 mhunt 5051
   *   select rl.rcon_id, rl.current_run_level from release_manager.release_config rc, release_manager.run_level rl
814 mhunt 5052
   *   where rc.rtag_id=<rtag_id> and rl.rcon_id=rc.rcon_id;
5053
   * populates the mRunLevelCollection with the query result set
5054
   * refer to sequence diagram coordinate slave threads
5055
   */
5056
  public void queryRunLevel(final int rtag_id) throws SQLException, Exception
5057
  {
5058
    mLogger.debug("queryRunLevel 2 rtag_id " + rtag_id);
5059
    if ( mConnectionString.compareTo("unit test coordinate slave threads") == 0)
5060
    {
5061
      mLogger.info("queryRunLevel 2 unit test coordinate slave threads");
5062
 
5063
      if ( mRunLevelCollection.size() == 0)
5064
      {
5065
        // first time not all slave threads are waiting
5066
        RunLevel runLevel = new RunLevel(1, "", DB_WAITING, false);
5067
        mRunLevelCollection.add(runLevel);
5068
        runLevel = new RunLevel(2, "", DB_IDLE, false);
5069
        mRunLevelCollection.add(runLevel);
5070
      }
5071
      else
5072
      {
5073
        // subsequent times all slave threads are waiting
5074
        mRunLevelCollection.removeAllElements();
5075
        RunLevel runLevel = new RunLevel(1, "", DB_WAITING, false);
5076
        mRunLevelCollection.add(runLevel);
5077
        runLevel = new RunLevel(2, "", DB_WAITING, false);
5078
        mRunLevelCollection.add(runLevel);
5079
      }
5080
    }
5081
 
5082
    if ( mUseDatabase )
5083
    {
5084
      mRunLevelCollection.removeAllElements();
5085
 
5086
      try
5087
      {
5088
        connect();
5089
        CallableStatement stmt = mConnection.prepareCall(
882 mhunt 5090
        "select rl.rcon_id, rl.current_run_level from release_manager.release_config rc, release_manager.run_level rl " +
814 mhunt 5091
        "where rc.rtag_id=" +rtag_id + " and rl.rcon_id=rc.rcon_id");
5092
        ResultSet rset = stmt.executeQuery();
5093
        int rsetSize = 0;
5094
        int rcon_id = 0;
5095
        int current_run_level = 0;
5096
 
5097
        while( rset.next() )
5098
        {
5099
          rsetSize++;
5100
          rcon_id = rset.getInt("rcon_id");
5101
 
5102
          if ( rset.wasNull() )
5103
          {
5104
            mLogger.fatal("queryRunLevel 2 null rcon_id");
5105
            // show stopper
868 mhunt 5106
            throw new Exception("queryRunLevel 2 null rcon_id");
814 mhunt 5107
          }
5108
 
5109
          current_run_level = rset.getInt("current_run_level");
5110
 
5111
          if ( rset.wasNull() )
5112
          {
906 mhunt 5113
            // slave may never have started to insert run level
5114
            // use idle
5115
            current_run_level = DB_IDLE;
814 mhunt 5116
          }
5117
 
5118
          RunLevel runLevel = new RunLevel(rcon_id, "", current_run_level, false);
5119
          mRunLevelCollection.add(runLevel);
5120
        }
5121
 
830 mhunt 5122
        rset.close();
5123
        stmt.close();
814 mhunt 5124
      }
5125
      catch ( SQLException e )
5126
      {
5127
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
5128
        {
5129
          mLogger.error("queryRunLevel 2 database access error only");
5130
          throw new SQLException();
5131
        }
5132
        else
5133
        {
5134
          mLogger.fatal("queryRunLevel 2 show stopper");
868 mhunt 5135
          throw new Exception("queryRunLevel 2 show stopper");
814 mhunt 5136
        }
5137
      }
898 mhunt 5138
      finally
5139
      {
5140
        // this block is executed regardless of what happens in the try block
5141
        // even if an exception is thrown
5142
        // ensure disconnect
5143
        disconnect();
5144
      }
814 mhunt 5145
    }
5146
  }
5147
 
818 mhunt 5148
  /**removes all elements from the mRunLevelCollection
5149
   * handles database connection and disconnection
882 mhunt 5150
   *   select rcon_id, current_run_level from release_manager.run_level
818 mhunt 5151
   *   where rcon_id=<rcon_id>;
5152
   * populates the mRunLevelCollection with the query result set
5153
   */
5154
  public void querySingleRunLevel(final int rcon_id) throws SQLException, Exception
5155
  {
5156
    mLogger.debug("querySingleRunLevel rcon_id " + rcon_id);
5157
    if ( !mUseDatabase )
5158
    {
5159
      mLogger.info("querySingleRunLevel !mUseDatabase");
5160
 
5161
      mRunLevelCollection.removeAllElements();
5162
      RunLevel runLevel = new RunLevel(rcon_id, "", DB_ACTIVE, false);
5163
      mRunLevelCollection.add(runLevel);
5164
    }
5165
    else
5166
    {
5167
      mRunLevelCollection.removeAllElements();
5168
 
5169
      try
5170
      {
5171
        connect();
5172
 
882 mhunt 5173
        if (isRconIdConfigured( rcon_id ))
818 mhunt 5174
        {
882 mhunt 5175
          CallableStatement stmt = mConnection.prepareCall(
5176
          "select rcon_id, current_run_level from release_manager.run_level " +
5177
          "where rcon_id=" +rcon_id);
5178
          ResultSet rset = stmt.executeQuery();
5179
          int rsetSize = 0;
5180
          int current_run_level = 0;
5181
 
5182
          while( rset.next() )
818 mhunt 5183
          {
882 mhunt 5184
            rsetSize++;
5185
            current_run_level = rset.getInt("current_run_level");
5186
 
5187
            if ( rset.wasNull() )
5188
            {
5189
              mLogger.fatal("querySingleRunLevel null current_run_level");
5190
              // show stopper
5191
              throw new Exception("querySingleRunLevel null current_run_level");
5192
            }
5193
 
5194
            RunLevel runLevel = new RunLevel(rcon_id, "", current_run_level, false);
5195
            mRunLevelCollection.add(runLevel);
5196
          }
5197
 
5198
          rset.close();
5199
          stmt.close();
5200
 
5201
          if ( rsetSize != 1 )
5202
          {
5203
            mLogger.fatal("querySingleRunLevel rsetSize != 1");
818 mhunt 5204
            // show stopper
882 mhunt 5205
            throw new Exception("querySingleRunLevel rsetSize != 1");
818 mhunt 5206
          }
5207
        }
5208
      }
5209
      catch ( SQLException e )
5210
      {
5211
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
5212
        {
5213
          mLogger.error("querySingleRunLevel database access error only");
5214
          throw new SQLException();
5215
        }
5216
        else
5217
        {
5218
          mLogger.fatal("querySingleRunLevel show stopper");
868 mhunt 5219
          throw new Exception("querySingleRunLevel show stopper");
818 mhunt 5220
        }
5221
      }
898 mhunt 5222
      finally
5223
      {
5224
        // this block is executed regardless of what happens in the try block
5225
        // even if an exception is thrown
5226
        // ensure disconnect
5227
        disconnect();
5228
      }
818 mhunt 5229
    }
5230
  }
5231
 
814 mhunt 5232
  /**queries the RUN_LEVEL_SCHEDULE table
896 mhunt 5233
   * when recover is true, checks for archive existence and runs resume when both archives exist
5234
   * this should delete rows with a non NULL indefinite pause
814 mhunt 5235
   * returns false if a row in the query result set indicates build service downtime is scheduled
5236
   * returns false if a row in the query result set has a non NULL indefinite_pause
5237
   * refer to the sequence diagram allowed to proceed
5238
   */
896 mhunt 5239
  public boolean queryRunLevelSchedule(Date resumeTime, boolean recover) throws SQLException, Exception
814 mhunt 5240
  {
5241
    mLogger.debug("queryRunLevelSchedule");
5242
    boolean retVal = true;
5243
 
5244
    if ( !mUseDatabase )
5245
    {
5246
      mLogger.info("queryRunLevelSchedule !mUseDatabase");
5247
 
5248
      if ( mConnectionString.compareTo("unit test not allowed to proceed") == 0 )
5249
      {
5250
        // schedule a 100ms max wait
5251
        resumeTime.setTime( resumeTime.getTime() + 100 );
5252
        retVal = false;
5253
      }
5254
    }
5255
    else
5256
    {
5257
      try
5258
      {
896 mhunt 5259
        if ( recover )
5260
        {
5261
          if ( Package.recover() )
5262
          {
5263
            // dpkg and deploy archives exist
5264
            // clear the indefinite pause condition
5265
            resume();
5266
          }
5267
        }
814 mhunt 5268
        CallableStatement stmt = mConnection.prepareCall("select scheduled_pause, scheduled_resume, repeat, indefinite_pause from release_manager.run_level_schedule");
5269
        ResultSet rset = stmt.executeQuery();
5270
        Date now = new Date();
844 dpurdie 5271
 
5272
 
5273
        //
846 dpurdie 5274
        //  Scan the database information and determine if there is any reason
844 dpurdie 5275
        //  to pause. Terminate the loop on the first excuse to pause
5276
        //  as indefinite pause may have multiple (lots) of entries in the data
5277
        //  base.
5278
        //
5279
        while( retVal == true && rset.next() )
814 mhunt 5280
        {
846 dpurdie 5281
          //
5282
          //  Examine the current row from the data base
5283
          //  Expect one of two forms:
5284
          //    1) scheduled_pause
5285
          //       Must also have a scheduled_resume and a repeat
5286
          //    2) indefinite_pause
5287
          //
5288
 
5289
          //  Look for scheduled_pause style of entry
5290
          //
814 mhunt 5291
          Timestamp sp = rset.getTimestamp("scheduled_pause");
5292
          if ( sp != null )
5293
          {
5294
            Date scheduled_pause = new Date( sp.getTime() );
5295
            Timestamp sr = rset.getTimestamp("scheduled_resume");
5296
 
5297
            if ( sr != null )
5298
            {
5299
              Date scheduled_resume = new Date( sr.getTime() );
5300
              int repeat = rset.getInt("repeat");
5301
              mLogger.info("queryRunLevelSchedule repeat " + repeat);
846 dpurdie 5302
 
5303
              //
5304
              //  Have scheduled_pause and scheduled_resume
5305
              //  Examine the repeat field and determine how these are used
5306
              //  Supported repeat:
5307
              //      Once Only
5308
              //      Daily           Year, Month and Day information is ignored
5309
              //      Weekly          Only day of week is utilised
5310
              //
814 mhunt 5311
              if ( !rset.wasNull() )
5312
              {
5313
                switch( repeat )
5314
                {
5315
                  case 0:
5316
                  {
5317
                    // one off
5318
                    if ( scheduled_pause.before(now) && scheduled_resume.after(now) )
5319
                    {
5320
                      mLogger.warn("queryRunLevelSchedule one off scheduled downtime");
838 mhunt 5321
                      resumeTime = scheduled_resume;
814 mhunt 5322
                      retVal = false;
5323
                    }
5324
                    break;
5325
                  }
5326
                  case 1:
5327
                  {
846 dpurdie 5328
                    //  daily
5329
                    //  Create start and end fimes, then massage some fields
5330
                    //  to reflect todays date
5331
                    //
814 mhunt 5332
                    GregorianCalendar startOfDowntime = new GregorianCalendar();
5333
                    startOfDowntime.setTime(scheduled_pause);
5334
                    GregorianCalendar endOfDowntime = new GregorianCalendar();
5335
                    endOfDowntime.setTime(scheduled_resume);
5336
                    GregorianCalendar clock = new GregorianCalendar();
5337
                    clock.setTime(now);
846 dpurdie 5338
 
5339
                    // Force date fields to todays date
5340
                    endOfDowntime.set  ( clock.get(Calendar.YEAR), clock.get(Calendar.MONTH), clock.get(Calendar.DAY_OF_MONTH) );
5341
                    startOfDowntime.set( clock.get(Calendar.YEAR), clock.get(Calendar.MONTH), clock.get(Calendar.DAY_OF_MONTH) );
5342
 
814 mhunt 5343
                    if ( startOfDowntime.before(clock) && endOfDowntime.after(clock) )
5344
                    {
5345
                      mLogger.warn("queryRunLevelSchedule daily scheduled downtime");
838 mhunt 5346
                      resumeTime.setTime(endOfDowntime.getTimeInMillis());
814 mhunt 5347
                      retVal = false;
5348
                    }
5349
                    break;
5350
                  }
5351
                  case 7:
5352
                  {
5353
                    // weekly
846 dpurdie 5354
                    // Create start and end times, then massage some fields
5355
                    // to reflect todays date
5356
                    //
814 mhunt 5357
                    GregorianCalendar startOfDowntime = new GregorianCalendar();
5358
                    startOfDowntime.setTime(scheduled_pause);
5359
                    GregorianCalendar endOfDowntime = new GregorianCalendar();
5360
                    endOfDowntime.setTime(scheduled_resume);
5361
                    GregorianCalendar clock = new GregorianCalendar();
5362
                    clock.setTime(now);
846 dpurdie 5363
 
5364
                    // Only interested in one day of the week
814 mhunt 5365
                    if ( startOfDowntime.get(Calendar.DAY_OF_WEEK) == clock.get(Calendar.DAY_OF_WEEK) )
5366
                    {
846 dpurdie 5367
                      endOfDowntime.set  ( clock.get(Calendar.YEAR), clock.get(Calendar.MONTH), clock.get(Calendar.DAY_OF_MONTH) );
5368
                      startOfDowntime.set( clock.get(Calendar.YEAR), clock.get(Calendar.MONTH), clock.get(Calendar.DAY_OF_MONTH) );
814 mhunt 5369
 
5370
                      if ( startOfDowntime.before(clock) && endOfDowntime.after(clock) )
5371
                      {
5372
                        mLogger.warn("queryRunLevelSchedule weekly scheduled downtime");
838 mhunt 5373
                        resumeTime.setTime(endOfDowntime.getTimeInMillis());
814 mhunt 5374
                        retVal = false;
5375
                      }
5376
                    }
5377
                    break;
5378
                  }
5379
                }
5380
              }
5381
            }
5382
          }
5383
 
846 dpurdie 5384
          //
5385
          //  Look for indefinite_pause style of entry
5386
          //  Note: due to an implemenation error there may be many
5387
          //        rows that match. We only need one. The scan will
896 mhunt 5388
          //        be terminated if we find any
846 dpurdie 5389
          //  
5390
          //
836 mhunt 5391
          String ip = rset.getString("indefinite_pause");
5392
          if ( ip != null )
814 mhunt 5393
          {
5394
            // indefinite pause is non null
5395
            mLogger.warn("queryRunLevelSchedule indefinite pause");
838 mhunt 5396
            GregorianCalendar clock = new GregorianCalendar();
5397
            clock.setTime(now);
5398
            // wait a minute
5399
            resumeTime.setTime(clock.getTimeInMillis() + 60000);
814 mhunt 5400
            retVal = false;
5401
          }
5402
        }
830 mhunt 5403
 
5404
        rset.close();
5405
        stmt.close();
814 mhunt 5406
      }
5407
      catch ( SQLException e )
5408
      {
5409
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
5410
        {
5411
          mLogger.error("queryRunLevelSchedule database access error only");
5412
          throw new SQLException();
5413
        }
5414
        else
5415
        {
5416
          mLogger.fatal("queryRunLevelSchedule show stopper");
868 mhunt 5417
          throw new Exception("queryRunLevelSchedule show stopper");
814 mhunt 5418
        }
5419
      }
5420
    }
5421
 
5422
    mLogger.info("queryRunLevelSchedule returning " + retVal);
5423
    return retVal;
5424
  }
5425
 
882 mhunt 5426
  /**returns true if the rcon_id is configured
5427
   */
5428
  private boolean isRconIdConfigured(final int rcon_id) throws SQLException, Exception
5429
  {
5430
    mLogger.debug("isRconIdConfigured");
5431
    boolean retVal = false;
5432
 
5433
    try
5434
    {
5435
      // check if the rcon_id is still configured
5436
      CallableStatement stmt = mConnection.prepareCall("select rcon_id from release_manager.release_config where rcon_id=" + rcon_id);
5437
      ResultSet rset = stmt.executeQuery();
5438
 
5439
      while( rset.next() )
5440
      {
5441
        retVal = true;
5442
      }
5443
 
5444
      rset.close();
5445
      stmt.close();
5446
    }
5447
    catch( SQLException e )
5448
    {
5449
      if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
5450
      {
5451
        mLogger.fatal("isRconIdConfigured database access error only");
5452
        throw new Exception("isRconIdConfigured database access error only");
5453
      }
5454
      else
5455
      {
5456
        mLogger.fatal("isRconIdConfigured show stopper");
5457
        throw new Exception("isRconIdConfigured show stopper");
5458
      }
5459
    }
5460
    mLogger.info("isRconIdConfigured returning " + retVal);
5461
    return retVal;
5462
  }
5463
 
5464
  /**returns true if the rcon_id is configured
5465
   */
5466
  private boolean isRtagIdConfigured(final int rtag_id) throws SQLException, Exception
5467
  {
5468
    mLogger.debug("isRtagIdConfigured");
5469
    boolean retVal = false;
5470
 
5471
    try
5472
    {
5473
      // check if the rcon_id is still configured
5474
      CallableStatement stmt = mConnection.prepareCall("select rtag_id from release_manager.release_config where rtag_id=" + rtag_id);
5475
      ResultSet rset = stmt.executeQuery();
5476
 
5477
      while( rset.next() )
5478
      {
5479
        retVal = true;
5480
      }
5481
 
5482
      rset.close();
5483
      stmt.close();
5484
    }
5485
    catch( SQLException e )
5486
    {
5487
      if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
5488
      {
5489
        mLogger.fatal("isRtagIdConfigured database access error only");
5490
        throw new Exception("isRtagIdConfigured database access error only");
5491
      }
5492
      else
5493
      {
5494
        mLogger.fatal("isRtagIdConfigured show stopper");
5495
        throw new Exception("isRtagIdConfigured show stopper");
5496
      }
5497
    }
5498
    mLogger.info("isRtagIdConfigured returning " + retVal);
5499
    return retVal;
5500
  }
5501
 
5502
    /**persists the runLevel in the RUN_LEVEL table for the rcon_id primary key
814 mhunt 5503
   * refer to sequence diagrams generate build files, allowed to proceed, not allowed to proceed, exit, check environment
5504
   */
882 mhunt 5505
  public void updateCurrentRunLevel(final int rcon_id, final int runLevel, final boolean insert) throws SQLException, Exception
814 mhunt 5506
  {
5507
    mLogger.debug("updateCurrentRunLevel");
5508
    if ( !mUseDatabase )
5509
    {
5510
      mLogger.info("updateCurrentRunLevel !mUseDatabase");
5511
      Integer i = new Integer(runLevel);
5512
      mPersistedRunLevelCollection.add(i);
5513
    }
5514
    else
5515
    {
5516
      try
5517
      {
5518
        connect();
5519
        boolean update = false;
5520
        {
5521
          // check if the rcon_id exists in the table
5522
          CallableStatement stmt = mConnection.prepareCall("select rcon_id from release_manager.run_level where rcon_id=" + rcon_id);
5523
          ResultSet rset = stmt.executeQuery();
5524
 
5525
          while( rset.next() )
5526
          {
5527
            update = true;
5528
          }
830 mhunt 5529
 
5530
          rset.close();
5531
          stmt.close();
814 mhunt 5532
        }
5533
 
882 mhunt 5534
        // the insert flag ensures the insertion is controlled
5535
        // it should only be set initially in the BuildThread run methods
5536
        if ( !update && insert )
814 mhunt 5537
        {
864 mhunt 5538
 
882 mhunt 5539
          if (isRconIdConfigured( rcon_id ))
864 mhunt 5540
          {
5541
            CallableStatement stmt = mConnection.prepareCall("insert into release_manager.run_level (rcon_id) values (" + rcon_id + ")" );
5542
            stmt.executeUpdate();
5543
            stmt.close();
5544
          }
814 mhunt 5545
        }
5546
 
5547
        {
886 mhunt 5548
          // DEVI 52589 provide a keep alive indication
5549
          PreparedStatement stmt = mConnection.prepareCall("update release_manager.run_level set current_run_level=" + runLevel + ", keep_alive=SYSDATE where rcon_id=" + rcon_id);
814 mhunt 5550
          stmt.executeUpdate();
830 mhunt 5551
          stmt.close();
814 mhunt 5552
        }
898 mhunt 5553
        commit();
814 mhunt 5554
      }
5555
      catch( SQLException e )
5556
      {
5557
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
5558
        {
868 mhunt 5559
          mLogger.fatal("updateCurrentRunLevel database access error only");
882 mhunt 5560
          throw new SQLException("updateCurrentRunLevel database access error only");
814 mhunt 5561
        }
5562
        else
5563
        {
5564
          mLogger.fatal("updateCurrentRunLevel show stopper");
868 mhunt 5565
          throw new Exception("updateCurrentRunLevel show stopper");
814 mhunt 5566
        }
5567
      }
898 mhunt 5568
      finally
5569
      {
5570
        // this block is executed regardless of what happens in the try block
5571
        // even if an exception is thrown
5572
        // ensure disconnect
5573
        disconnect();
5574
      }
814 mhunt 5575
    }
5576
  }
5577
 
866 mhunt 5578
  public void queryBuildExclusions(Vector<BuildExclusion> buildExclusionCollection, int baseline) throws SQLException, Exception
5579
  {
5580
    mLogger.debug("queryBuildExclusions " + baseline);
5581
 
5582
    if ( !mUseDatabase )
5583
    {
5584
      mLogger.info("queryBuildExclusions !mUseDatabase");
5585
    }
5586
    else
5587
    {
5588
      try
5589
      {
5590
        CallableStatement stmt = mConnection.prepareCall("select pv_id, root_pv_id, root_cause from release_manager.do_not_ripple where rtag_id=" + baseline);
5591
        ResultSet rset = stmt.executeQuery();
5592
 
5593
        while( rset.next() )
5594
        {
5595
          int pvId = rset.getInt("pv_id");
5596
 
5597
          if ( rset.wasNull() )
5598
          {
5599
            mLogger.fatal("queryBuildExclusions rset null pv_id");
5600
            // show stopper
868 mhunt 5601
            throw new Exception("queryBuildExclusions rset null pv_id");
866 mhunt 5602
          }
5603
 
5604
          int rootPvId = rset.getInt("root_pv_id");
5605
 
5606
          if ( rset.wasNull() )
5607
          {
5608
            // quite acceptable
5609
            rootPvId = -1;
5610
          }
5611
 
5612
          // again, a null root_cause is quite acceptable
5613
          String rootCause = rset.getString("root_cause");
5614
 
908 mhunt 5615
          // force email notification by using a zero test build instruction
5616
          BuildExclusion buildExclusion = new BuildExclusion(pvId, rootPvId, rootCause, 0);
866 mhunt 5617
          buildExclusionCollection.add(buildExclusion);
5618
        }
5619
 
5620
        rset.close();
5621
        stmt.close();
5622
      }
5623
      catch ( SQLException e )
5624
      {
5625
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
5626
        {
5627
          mLogger.error("queryBuildExclusions database access error only");
5628
          throw new SQLException();
5629
        }
5630
        else
5631
        {
5632
          mLogger.fatal("queryBuildExclusions show stopper");
868 mhunt 5633
          throw new Exception("queryBuildExclusions show stopper");
866 mhunt 5634
        }
5635
      }
5636
    }
5637
  }
814 mhunt 5638
}