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