Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

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