Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

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