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