Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
814 mhunt 1
package com.erggroup.buildtool.daemon;
2
 
3
import com.erggroup.buildtool.daemon.ResumeTimerTask;
4
import com.erggroup.buildtool.ripple.ReleaseManager;
868 mhunt 5
import com.erggroup.buildtool.smtp.Smtpsend;
6
import com.erggroup.buildtool.ripple.RippleEngine;
896 mhunt 7
import com.erggroup.buildtool.ripple.MutableString;
814 mhunt 8
 
9
import java.io.BufferedReader;
10
import java.io.File;
11
import java.io.FileNotFoundException;
12
import java.io.FileOutputStream;
13
import java.io.FileWriter;
14
import java.io.FilenameFilter;
15
 
16
import java.io.IOException;
17
import java.io.PrintStream;
18
import java.io.StringReader;
19
 
20
import java.sql.SQLException;
21
 
22
import java.util.Date;
23
import java.util.Timer;
24
 
25
import org.apache.log4j.Logger;
26
import org.apache.tools.ant.BuildException;
27
import org.apache.tools.ant.DefaultLogger;
28
import org.apache.tools.ant.Project;
29
import org.apache.tools.ant.ProjectHelper;
30
 
31
/**Build Thread sub component
32
 */
33
public abstract class BuildThread
34
  extends Thread
35
{
36
  /**baseline identifier (which release manager release this BuildThread is dealing with)
37
   * @attribute
38
   */
39
  protected int mRtagId = 0;
40
 
41
  /**unique identifier of this BuildThread
42
   * @attribute
43
   */
44
  protected int mRconId = 0;
45
 
46
  /**
47
   * @aggregation composite
48
   */
49
  protected RunLevel mRunLevel;
50
 
51
  /**
52
   * @aggregation composite
53
   */
54
  protected ReleaseManager mReleaseManager;
55
 
56
  /**configured GBEBUILDFILTER for this BuildThread
57
   * @attribute
58
   */
896 mhunt 59
  protected String mGbebuildfilter = null;
814 mhunt 60
 
896 mhunt 61
  /**unit test support
62
   * @attribute
63
   */
64
  protected String mUnitTest = "";
65
 
814 mhunt 66
  /**
67
   * @aggregation composite
68
   */
69
  protected static ResumeTimerTask mResumeTimerTask;
70
 
71
  /**
72
   * @aggregation composite
73
   */
74
  private static Timer mTimer;
75
 
76
  /**Synchroniser object
77
   * Use to Synchronize on by multiple threads
78
   * @attribute
79
   */
80
  static final Object mSynchroniser = new Object();
81
 
82
  /**BuildThread group
83
   * @attribute
84
   */
85
  public static final ThreadGroup mThreadGroup = new ThreadGroup("BuildThread");
86
 
87
  /**the advertised build file content when either
88
   * a) no package in the baseline has a build requirement
89
   * b) the next package in the baseline with a build requirement is generic
90
   * @attribute
91
   */
92
  protected static final String mDummyBuildFileContent = new String("<dummy/>");
93
 
94
  /**Set true when last build cycle was benign.
95
   * @attribute
96
   */
97
  protected boolean mSleep;
98
 
886 mhunt 99
  /**Set true when last build cycle caught SQLException or Exception.
100
   * @attribute
101
   */
102
  protected boolean mException;
103
 
854 mhunt 104
  /**Set true when ant error reported on any target.
105
   * @attribute
106
   */
107
  private boolean mErrorReported;
108
 
866 mhunt 109
  /**Logger
854 mhunt 110
   * @attribute
111
   */
866 mhunt 112
  private static final Logger mLogger = Logger.getLogger(BuildThread.class);
854 mhunt 113
 
866 mhunt 114
  /**Package name for reporting purposes.
814 mhunt 115
   * @attribute
116
   */
866 mhunt 117
  protected String mReportingPackageName;
814 mhunt 118
 
866 mhunt 119
  /**Package version for reporting purposes.
120
   * @attribute
121
   */
122
  protected String mReportingPackageVersion;
123
 
124
  /**Package extension for reporting purposes.
125
   * @attribute
126
   */
127
  protected String mReportingPackageExtension;
128
 
129
  /**Package location for reporting purposes.
130
   * @attribute
131
   */
132
  protected String mReportingPackageLocation;
133
 
134
  /**Package dependencies for reporting purposes.
135
   * @attribute
136
   */
137
  protected String mReportingPackageDepends;
138
 
139
  /**Is ripple flag for reporting purposes.
140
   * @attribute
141
   */
142
  protected String mReportingIsRipple;
143
 
144
  /**Package version identifier for reporting purposes.
145
   * @attribute
146
   */
147
  protected String mReportingPackageVersionId;
148
 
149
  /**Fully published flag for reporting purposes.
150
   * @attribute
151
   */
152
  protected String mReportingFullyPublished;
153
 
154
  /**New label for reporting purposes.
155
   * @attribute
156
   */
157
  protected String mReportingNewLabel;
158
 
159
  /**Source control interaction for reporting purposes.
160
   * @attribute
161
   */
162
  protected String mReportingDoesNotRequireSourceControlInteraction;
163
 
908 mhunt 164
  /**Source control interaction for reporting purposes.
165
   * @attribute
166
   */
167
  protected String mReportingTestBuild;
168
 
866 mhunt 169
  /**Log file location for reporting purposes.
170
   * @attribute
171
   */
172
  protected String mReportingBuildFailureLogFile;
173
 
868 mhunt 174
  /**Non null determines to only gather metrics
175
   * @attribute
176
   */
177
  protected static final String mGbeGatherMetricsOnly = System.getenv("GBE_GATHER_METRICS");
178
 
896 mhunt 179
  /**Non null determines to only gather metrics
180
   * @attribute
181
   */
182
  protected boolean mRecoverable;
183
 
814 mhunt 184
  /**constructor
185
   */
186
  BuildThread()
187
  {
188
    super(mThreadGroup, "");
189
    mLogger.debug("BuildThread");
190
    mSleep = false;
886 mhunt 191
    mException = false;
854 mhunt 192
    mErrorReported = false;
814 mhunt 193
    mReleaseManager = new ReleaseManager();
896 mhunt 194
    mRecoverable = false;
814 mhunt 195
 
196
    // no need to be synchronized - BuildThreads are instantiated in a single thread
197
    if ( mResumeTimerTask == null )
198
    {
199
      mResumeTimerTask = new ResumeTimerTask();
200
      mTimer = new Timer();
201
      mResumeTimerTask.setTimer(mTimer);
202
    }
203
  }
204
 
886 mhunt 205
  /**sleeps when mException is set
206
   */
207
  protected void sleepCheck()
208
  {
209
    if (mException)
210
    {
211
      try
212
      {
213
        Integer sleepTime = 300000;
214
        mLogger.warn("sleepCheck sleep " + sleepTime.toString() + " secs");
215
        Thread.sleep(sleepTime);
216
        mLogger.info("sleepCheck sleep returned");
217
      }
218
      catch(InterruptedException e)
219
      {
220
        mLogger.warn("sleepCheck sleep caught InterruptedException");
221
      }
222
 
223
    }
224
    mException = false;
225
  }
226
 
814 mhunt 227
  /**initially changes the run level to IDLE
228
   * determines if the BuildThread is still configured
229
   * a) determines if the BuildThread is running in scheduled downtime
230
   * b) determines if the BuildThread is directed to pause
231
   * changes the run level to PAUSED if a) or b) are true
232
   * throws ExitException when not configured
233
   * implements the sequence diagrams allowed to proceed, not allowed to proceed, exit
234
   */
868 mhunt 235
  protected void allowedToProceed(boolean master) throws ExitException, SQLException, Exception
814 mhunt 236
  {
237
    mLogger.debug("allowedToProceed");
886 mhunt 238
 
239
    try
240
    {
241
      mRunLevel = RunLevel.IDLE;
242
      mLogger.warn("allowedToProceed changing run level to IDLE for rcon_id " + mRconId);
243
      mRunLevel.persist(mReleaseManager, mRconId);
896 mhunt 244
      if ( master )
245
      {
246
        mReleaseManager.discardVersion();
247
      }
886 mhunt 248
      mReleaseManager.clearCurrentPackageBeingBuilt(mRconId);      
249
    }
250
    catch(SQLException e)
251
    {
252
      mLogger.warn("allowedToProceed caught SQLException");
253
    }
814 mhunt 254
 
255
    if (mSleep)
256
    {
257
      try
258
      {
868 mhunt 259
        Integer sleepTime = 300000;
260
 
261
        if ( !master )
262
        {
263
          // sleep only 3 secs on slave
264
          sleepTime = 3000;
265
        }
266
        mLogger.warn("allowedToProceed sleep " + sleepTime.toString() + " secs no build requirement");
267
        Thread.sleep(sleepTime);
814 mhunt 268
        mLogger.info("allowedToProceed sleep returned");
269
      }
270
      catch(InterruptedException e)
271
      {
272
        mLogger.warn("allowedToProceed sleep caught InterruptedException");
273
      }
274
    }
275
 
276
    boolean proceed = false;
277
 
898 mhunt 278
    try
814 mhunt 279
    {
898 mhunt 280
      while ( !proceed )
814 mhunt 281
      {
898 mhunt 282
        mReleaseManager.connect();
283
        if ( !mReleaseManager.queryReleaseConfig(mRtagId, mRconId, BuildDaemon.mHostname, getMode()) )
284
        {
285
          mReleaseManager.disconnect();
286
          mLogger.warn("allowedToProceed queryReleaseConfig failed");
287
          throw new ExitException();
288
        }
814 mhunt 289
 
898 mhunt 290
        Date resumeTime = new Date( 0 );
291
        if ( !mReleaseManager.queryRunLevelSchedule(resumeTime, mRecoverable) )
814 mhunt 292
        {
898 mhunt 293
          mLogger.info("allowedToProceed scheduled downtime");
294
          mReleaseManager.disconnect();
295
          mRunLevel = RunLevel.PAUSED;
296
          mLogger.warn("allowedToProceed changing run level to PAUSED for rcon_id " + mRconId);
297
          mRunLevel.persist(mReleaseManager, mRconId);
298
 
299
          synchronized(mSynchroniser)
814 mhunt 300
          {
898 mhunt 301
            // contain the schedule and wait in the same synchronized block to prevent a deadlock
302
            // eg this thread calls schedule, timer thread calls notifyall, this thread calls wait (forever)
303
            try
814 mhunt 304
            {
898 mhunt 305
              if (mResumeTimerTask.isCancelled())
306
              {
307
                mResumeTimerTask = new ResumeTimerTask();
308
                mTimer = new Timer();
309
                mResumeTimerTask.setTimer(mTimer);
310
              }
311
              mLogger.warn("allowedToProceed schedule passed " + resumeTime.getTime());
312
              mTimer.schedule(mResumeTimerTask, resumeTime);
814 mhunt 313
            }
898 mhunt 314
            catch( IllegalStateException e )
814 mhunt 315
            {
898 mhunt 316
              // this may be thrown by schedule if already scheduled
317
              // it signifies another BuildThread has already scheduled the ResumeTimerTask
318
               mLogger.warn("allowedToProceed already scheduled");
814 mhunt 319
            }
898 mhunt 320
 
321
            try
322
            {
323
              mLogger.warn("allowedToProceed wait");
324
              mSynchroniser.wait();
325
              mLogger.warn("allowedToProceed wait returned");
326
 
327
              if ( mUnitTest.compareTo("unit test not allowed to proceed") == 0 )
328
              {
329
                throw new ExitException();
330
              }
331
            }
332
            catch( InterruptedException e )
333
            {
334
              mLogger.warn("allowedToProceed caught InterruptedException");
335
            }
814 mhunt 336
          }
898 mhunt 337
 
814 mhunt 338
        }
898 mhunt 339
        else
814 mhunt 340
        {
898 mhunt 341
          if ( !mReleaseManager.queryDirectedRunLevel(mRconId) )
814 mhunt 342
          {
898 mhunt 343
            mLogger.info("allowedToProceed downtime");
344
            mReleaseManager.disconnect();
345
            mRunLevel = RunLevel.PAUSED;
346
            mLogger.warn("allowedToProceed changing run level to PAUSED for rcon_id " + mRconId);
347
            mRunLevel.persist(mReleaseManager, mRconId);
348
            try
349
            {
350
              // to do, sleep for periodicMs
351
              mLogger.warn("allowedToProceed sleep 5 mins directed downtime");
352
              Thread.sleep(300000);
353
              mLogger.info("allowedToProceed sleep returned");
354
            }
355
            catch (InterruptedException e)
356
            {
357
              mLogger.warn("allowedToProceed caught InterruptedException");
358
            }
814 mhunt 359
          }
898 mhunt 360
          else
814 mhunt 361
          {
898 mhunt 362
            mReleaseManager.disconnect();
363
            proceed = true;
814 mhunt 364
          }
365
        }
366
      }
367
    }
898 mhunt 368
    finally
369
    {
370
      // this block is executed regardless of what happens in the try block
371
      // even if an exception is thrown
372
      // ensure disconnect
373
      mReleaseManager.disconnect();
374
    }
896 mhunt 375
 
376
    mRecoverable = false;
814 mhunt 377
  }
378
 
379
  /**periodically 
380
   * a) performs disk housekeeping
381
   * b) determines if a minimum threshold of disk space is available
894 mhunt 382
   * c) determines if a file can be touched
814 mhunt 383
   * changes the run level to CANNOT_CONTINUE if insufficient disk space
384
   * otherwise changes the run level to ACTIVE and returns
385
   * implements the sequence diagram check environment
386
   */
387
  protected void checkEnvironment() throws Exception
388
  {
389
    mLogger.debug("checkEnvironment");
390
    boolean exit = false;
391
 
392
    while( !exit )
393
    {
394
      housekeep();
395
 
396
      // attempt to exit
397
      exit = true;
398
 
894 mhunt 399
      if ( !hasSufficientDiskSpace() || !touch() )
814 mhunt 400
      {
894 mhunt 401
        mLogger.warn("checkEnvironment below disk free threshold or read only file system detected");
814 mhunt 402
        exit = false;
403
        mRunLevel = RunLevel.CANNOT_CONTINUE;
816 mhunt 404
        mLogger.warn("checkEnvironment changing run level to CANNOT_CONTINUE for rcon_id " + mRconId);
814 mhunt 405
        mRunLevel.persist(mReleaseManager, mRconId);
406
        try
407
        {
408
          // to do, sleep for periodicMs
896 mhunt 409
          if ( mUnitTest.compareTo("unit test check environment") != 0 )
814 mhunt 410
          {
411
            mLogger.warn("checkEnvironment sleep 5 mins below disk free threshold");
412
            Thread.sleep(300000);
413
            mLogger.info("checkEnvironment sleep returned");
414
          }
415
        }
416
        catch (InterruptedException e)
417
        {
418
          mLogger.warn("checkEnvironment caught InterruptedException");
419
        }
420
      }
421
    }
422
 
423
    mRunLevel = RunLevel.ACTIVE;    
816 mhunt 424
    mLogger.warn("checkEnvironment changing run level to ACTIVE for rcon_id " + mRconId);
814 mhunt 425
    mRunLevel.persist(mReleaseManager, mRconId);
426
  }
427
 
428
  /**performs disk housekeeping which involves deleting build directories > 5 days old
429
   * refer to the sequence diagram check environment
430
   */
431
  private void housekeep()
432
  {
433
    mLogger.debug("housekeep");
434
    FilenameFilter filter = new FilenameFilter()
435
    {
436
      public boolean accept(File file, String name)
437
      {
438
        mLogger.debug("accept " + name);
439
        boolean retVal = false;
440
 
441
        if ( file.isDirectory() && !name.startsWith( "." ) )
442
        {
443
          retVal = true;
444
        }
445
 
446
        mLogger.info("accept returned " + retVal);
447
        return retVal;
448
      }
449
    };
450
 
451
    try
452
    {
842 mhunt 453
      // DEVI 46729, 46730, solaris 10 core dumps implicate deleteDirectory
454
      // let each BuildThread look after its own housekeeping
854 mhunt 455
      File ocwd = new File( BuildDaemon.mGbeLog );
456
      File hcwd = new File( ocwd, BuildDaemon.mHostname );
457
      File cwd = new File( hcwd, String.valueOf( mRtagId ) );
842 mhunt 458
 
814 mhunt 459
      File[] children = cwd.listFiles( filter );
460
 
461
      if ( children != null )
462
      {
463
        for ( int child=0; child < children.length; child++ )
464
        {
854 mhunt 465
          // child is named uniquely to encapsulate a build
466
          // 5 days = 432,000,000 milliseconds
467
          if ( ( System.currentTimeMillis() - children[ child ].lastModified() ) > 432000000 )
814 mhunt 468
          {
854 mhunt 469
            // the directory is over 5 days old
470
            mLogger.warn("housekeep deleting directory " + children[ child ].getName());
896 mhunt 471
            if ( mUnitTest.compareTo("unit test check environment") != 0 )
814 mhunt 472
            {
854 mhunt 473
              deleteDirectory( children[ child ] );
814 mhunt 474
            }
475
          }
476
        }
477
      }
478
    }
479
    catch( SecurityException e )
480
    {
481
      // this can be thrown by lastModified
894 mhunt 482
      mLogger.warn("housekeep caught SecurityException");
814 mhunt 483
    }
484
 
485
  }
486
 
894 mhunt 487
  /**returns true if a file exists and can be deleted,
488
   * created and exists in the file system
489
   * this is to guard against read-only file systems
490
   */
491
  private boolean touch()
492
  {
493
    mLogger.debug("touch");
494
    boolean retVal = true;
495
 
496
    try
497
    {
498
      File touch = new File( String.valueOf( mRtagId ) + "touch" );
499
 
500
      if ( touch.exists() )
501
      {
502
        // delete it
503
        retVal = touch.delete();
504
      }
505
 
506
      if ( retVal )
507
      {
508
        // file does not exist
509
        retVal = touch.createNewFile();
510
      }
511
    }
512
    catch( SecurityException e )
513
    {
514
      // this can be thrown by exists, delete, createNewFile
515
      retVal = false;
516
      mLogger.warn("touch caught SecurityException");
517
    }
518
    catch( IOException e )
519
    {
520
      // this can be thrown by createNewFile
521
      retVal = false;
522
      mLogger.warn("touch caught IOException");
523
    }
524
 
525
    mLogger.info("touch returned " + retVal);
526
    return retVal;
527
  }
528
 
814 mhunt 529
  /**returns true if free disk space > 10G
530
   * this may become configurable if the need arises
531
   * refer to the sequence diagram check environment
532
   */
533
  private boolean hasSufficientDiskSpace()
534
  {
535
    mLogger.debug("hasSufficientDiskSpace");
536
    boolean retVal = true;
537
    long freeSpace = 0;
538
 
539
    try
540
    {
541
      File cwd = new File( "." );
542
 
543
      // 5G = 5368709120 bytes
886 mhunt 544
      // 1G = 1073741824 bytes - useful for testing
896 mhunt 545
      if ( mUnitTest.compareTo("unit test check environment") == 0 )
814 mhunt 546
      {
864 mhunt 547
        if ( ReleaseManager.mPersistedRunLevelCollection.size() == 0 )
814 mhunt 548
        {
549
          retVal = false;
550
        }
551
        else
552
        {
553
          retVal = true;
554
        }
555
      }
556
      else
557
      {
816 mhunt 558
        freeSpace = cwd.getUsableSpace();
814 mhunt 559
 
560
        if ( freeSpace < 5368709120L )
561
        {
816 mhunt 562
          mLogger.warn("hasSufficientDiskSpace on " + cwd.getAbsolutePath() + " freeSpace " + freeSpace);
814 mhunt 563
          retVal = false;
564
        }
565
      }
566
    }
567
    catch( SecurityException e )
568
    {
569
      // this can be thrown by getFreeSpace
570
       mLogger.warn("hasSufficientDiskSpace caught SecurityException");
571
    }
572
 
573
    mLogger.info("hasSufficientDiskSpace returned " + retVal + " " + freeSpace);
574
    return retVal;
575
  }
576
 
577
  /**abstract method
578
   */
579
  public abstract void run();
580
 
581
  /**deletes directory and all its files
582
   */
583
  protected void deleteDirectory(File directory)
584
  {
585
    mLogger.debug("deleteDirectory " + directory.getName());
586
    try
587
    {
588
      if ( directory.exists() )
589
      {
590
        FilenameFilter filter = new FilenameFilter()
591
        {
592
          public boolean accept(File file, String name)
593
          {
594
            mLogger.debug("accept " + name);
595
            boolean retVal = false;
596
 
840 mhunt 597
            if ( name.compareTo(".") != 0 && ( name.compareTo("..") != 0 ) )
814 mhunt 598
            {
599
              retVal = true;
600
            }
601
 
602
            mLogger.info("accept returned " + retVal);
603
            return retVal;
604
          }
605
        };
606
 
607
        File[] children = directory.listFiles( filter );
608
 
609
        if ( children != null )
610
        {
611
          for ( int child=0; child < children.length; child++ )
612
          {
613
            if ( children[ child ].isDirectory() )
614
            {
615
              deleteDirectory( children[ child ] );
616
            }
617
            else
618
            {
619
              children[ child ].delete();
620
            }
621
          }
622
        }
623
        directory.delete();
624
      }
625
    }
626
    catch( SecurityException e )
627
    {
628
      // this can be thrown by exists and delete
629
       mLogger.warn("deleteDirectory caught SecurityException");
630
    }
631
  }
632
 
633
  /**abstract method
634
   */
635
  protected abstract char getMode();
636
 
637
  /**injects GBE_BUILDFILTER into the passed buildFileContent
638
   * builds a buildFile from the buildFileContent
639
   * triggers ant to operate on the buildFile
640
   */
854 mhunt 641
  protected void deliverChange(String buildFileContent, String target, boolean master)
814 mhunt 642
  {
643
    mLogger.debug("deliverChange");
854 mhunt 644
 
902 mhunt 645
    // always perform a AbtSetUp and AbtTearDown
646
    if ( ( target == null && mErrorReported ) || ( target == "AbtPublish" && mErrorReported ) )
854 mhunt 647
    {
902 mhunt 648
      // AbtSetUp or the build failed
866 mhunt 649
      // the default target will inevitably fail and will generate further email if allowed to proceed
650
      // do not mask the root cause
854 mhunt 651
      return;
652
    }
653
 
814 mhunt 654
    File buildFile = new File(mRtagId + "build.xml");
862 mhunt 655
    boolean logError = true;
866 mhunt 656
    Project p = new Project();
814 mhunt 657
 
658
    try
659
    {
660
      // clear the file contents
661
      if ( buildFileContent != null && target != null && target.compareTo("AbtSetUp") == 0 )
662
      {
663
        FileOutputStream buildFileOutputStream = new FileOutputStream(buildFile, false);
664
        buildFileOutputStream.close();
665
 
666
        StringReader buildFileContentStringReader = new StringReader(buildFileContent);
667
        BufferedReader buildFileBufferedReader = new BufferedReader(buildFileContentStringReader);
668
 
669
        // sanitise the buildFileContent
670
        // it may contain line.separators of "\n", "\r", or "\r\n" variety, depending on the location of the ripple engine
671
        String sanitisedBFC = new String();
672
        String lf = new String( System.getProperty("line.separator") );
673
        int lineCount = 0;
674
        String line = new String();
675
 
676
        while( ( line = buildFileBufferedReader.readLine() ) != null)
677
        {
678
          sanitisedBFC += line + lf;
679
          lineCount++;
680
 
681
          if ( lineCount == 2 )
682
          {
683
            // have read the first two lines
862 mhunt 684
            String inject = "<property name=\"abt_MASTER\" value=\"";
814 mhunt 685
 
686
            if ( master )
687
            {
688
              inject += "yes\"/>" + lf;
689
            }
690
            else
691
            {
692
              inject += "no\"/>" + lf;
693
            }
896 mhunt 694
 
814 mhunt 695
            // insert a GBE_BUILDFILTER property if necessary
896 mhunt 696
            if ( mGbebuildfilter != null && mGbebuildfilter.length() > 0 )
814 mhunt 697
            {
862 mhunt 698
              inject += "<property name=\"abt_GBE_BUILDFILTER\" value=\"" + mGbebuildfilter + "\"/>" + lf;
814 mhunt 699
            }
700
 
701
            mLogger.info("deliverChange injecting " + inject);
702
            sanitisedBFC += inject;
703
          }
704
        }
705
        buildFileBufferedReader.close();
706
        FileWriter buildFileWriter = new FileWriter(buildFile);
707
        buildFileWriter.write(sanitisedBFC);
708
        buildFileWriter.close();
709
      }
710
 
866 mhunt 711
      mReportingPackageName = null;
712
      mReportingPackageVersion = null;
713
      mReportingPackageExtension = null;
714
      mReportingPackageLocation = null;
715
      mReportingPackageDepends = null;
716
      mReportingIsRipple = null;
717
      mReportingPackageVersionId = null;
718
      mReportingDoesNotRequireSourceControlInteraction = null;
908 mhunt 719
      mReportingTestBuild = null;
866 mhunt 720
      mReportingFullyPublished = null;
721
      mReportingNewLabel = null;
722
 
723
      if ( buildFile.exists() )
814 mhunt 724
      {
866 mhunt 725
        p.setProperty("ant.file", buildFile.getAbsolutePath());
726
        DefaultLogger dl = new DefaultLogger();
727
        PrintStream ps = new PrintStream(mRtagId + ".log");
728
        dl.setOutputPrintStream(ps);
729
        dl.setMessageOutputLevel(Project.MSG_INFO);
730
        p.addBuildListener(dl);
731
        p.init();
732
        ProjectHelper pH = ProjectHelper.getProjectHelper();
733
        p.addReference("ant.projectHelper", pH);
734
 
735
        // parse can throw BuildException, this is serious
736
        pH.parse(p, buildFile);
737
        mLogger.warn("deliverChange ant launched on " + buildFile.getAbsolutePath());
738
 
739
        if ( target == null )
740
        {
741
          target = p.getDefaultTarget();
742
        }
743
        mLogger.warn("deliverChange ant launched against target " + target);
744
 
745
        // executeTarget can throw BuildException, this is not serious
746
        logError = false;
747
        // set up project properties for reporting purposes
748
        // this first group are hard coded in the build file
749
        mReportingPackageName = p.getProperty("abt_package_name");
750
        mReportingPackageVersion = p.getProperty("abt_package_version");
751
        mReportingPackageExtension = p.getProperty("abt_package_extension");
752
        mReportingPackageLocation = p.getProperty("basedir") + p.getProperty("abt_package_location");
753
        mReportingPackageDepends = p.getProperty("abt_package_depends");
754
        mReportingIsRipple = p.getProperty("abt_is_ripple");
755
        mReportingPackageVersionId = p.getProperty("abt_package_version_id");
756
        mReportingDoesNotRequireSourceControlInteraction = p.getProperty("abt_does_not_require_source_control_interaction");
908 mhunt 757
        mReportingTestBuild = p.getProperty("abt_test_build_instruction");
866 mhunt 758
 
759
        p.executeTarget(target);
760
        mLogger.warn("deliverChange ant returned");
761
 
814 mhunt 762
      }
763
    }
764
    catch( BuildException e )
765
    {
862 mhunt 766
      if ( logError )
767
      {
768
        mLogger.error("deliverChange caught BuildException, the build failed " + e.getMessage());
769
      }
770
      else
771
      {
866 mhunt 772
        if ( mReportingBuildFailureLogFile == null )
773
        {
774
          mReportingBuildFailureLogFile = e.getMessage();
775
        }
776
        mLogger.debug("deliverChange caught BuildException, big deal, the build failed " + mReportingBuildFailureLogFile);
862 mhunt 777
      }
854 mhunt 778
 
779
      mErrorReported = true;
814 mhunt 780
    }
781
    catch( FileNotFoundException e )
782
    {
783
      mLogger.error("deliverChange caught FileNotFoundException");
784
    }
785
    catch( IOException e )
786
    {
787
      mLogger.error("deliverChange caught IOException");
788
    }
789
 
866 mhunt 790
    // this group are set at run time (by the AbtPublish target only)
791
    // they will be null for every other target,
792
    // and null if an error occurs in the AbtPublish target
793
    mReportingFullyPublished = p.getProperty("abt_fully_published");
794
    mReportingNewLabel = p.getProperty("abt_new_label");
795
 
814 mhunt 796
  }
797
 
798
  /**sets up a ClearCase static view
799
   */
896 mhunt 800
  protected void setViewUp(String content, boolean master) throws SQLException, Exception
814 mhunt 801
  {
802
    mLogger.debug("setViewUp");
866 mhunt 803
    mReportingBuildFailureLogFile = null;
854 mhunt 804
    mErrorReported = false;
868 mhunt 805
 
806
    if ( !master && mGbeGatherMetricsOnly != null )
807
    {
808
      // do not run AbtSetUp on slave in metrics gathering mode
809
      return;
810
    }
811
 
896 mhunt 812
    MutableString buildFilter = new MutableString();
813
    mReleaseManager.queryBuildFilter(mRconId, buildFilter);
814
    mGbebuildfilter = buildFilter.value;
815
 
814 mhunt 816
    // run ant on the AbtSetUp target
817
    deliverChange(content, "AbtSetUp", master);
818
  }
819
 
820
  /**Checks the archive for the <packageName>/<packageVersion>/built.<machtype> existence
821
   */
822
  protected boolean published(String archive, String packageName, 
823
                            String packageVersion, String machtype,
824
                            String generic)
825
  {
826
    mLogger.debug("published");
827
    boolean retVal = false;
828
 
829
    String fs = System.getProperty( "file.separator" );
830
    String destination = archive + fs + packageName + fs + packageVersion;
831
 
832
    mLogger.debug("published " + destination);
833
    String filename = "built.";
834
 
835
    if ( generic.compareTo("generic") == 0 )
836
    {
837
      filename += "generic";
838
    }
839
    else
840
    {
841
      filename += machtype;
842
    }
843
 
844
    mLogger.debug("published " + filename);
845
    File flag = new File( destination, filename );
846
 
847
    if ( flag.exists() )
848
    {
849
      retVal = true;
850
    }
851
    mLogger.debug("published returned " + retVal);
852
    return retVal;
853
  }
868 mhunt 854
 
855
  /**
856
   * indefinite pause notification
857
  */
858
   protected void indefinitePause(RippleEngine rippleEngine, String cause)
859
   {
860
     mLogger.debug("indefinitePause");
861
 
862
     String body =
863
     "Hostname: " + BuildDaemon.mHostname + "<p>" +
864
     "Release: " + rippleEngine.mBaselineName + "<p>" +
865
     cause;
866
 
867
     try
868
     {
869
       Smtpsend.send(
870
       rippleEngine.mMailServer, // mailServer
871
       rippleEngine.mMailSender, // source
872
       rippleEngine.mGlobalTarget, // target
873
       null, // cc
874
       null, // bcc
875
       "BUILD DAEMON INDEFINITE PAUSE", // subject
876
       body, // body
877
       null // attachment
878
       );
879
     }
880
     catch( Exception e )
881
     {
882
     }
883
   }
884
 
814 mhunt 885
}