Subversion Repositories DevTools

Rev

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.BuildThread;
818 mhunt 4
import com.erggroup.buildtool.ripple.MutableInt;
814 mhunt 5
import com.erggroup.buildtool.ripple.MutableString;
868 mhunt 6
import com.erggroup.buildtool.ripple.Package;
818 mhunt 7
import com.erggroup.buildtool.ripple.ReleaseManager;
868 mhunt 8
import com.erggroup.buildtool.ripple.RippleEngine;
818 mhunt 9
 
868 mhunt 10
import java.io.File;
814 mhunt 11
import java.sql.SQLException;
12
import org.apache.log4j.Logger;
13
 
14
/**Slave Thread sub component
15
 */
16
public class SlaveThread
17
  extends BuildThread
18
{
19
 
20
  /**Logger
21
   * @attribute
22
   */
23
  private static final Logger mLogger = Logger.getLogger(SlaveThread.class);
24
 
25
  /**constructor
26
   */
27
  public SlaveThread(int rtag_id, int rcon_id, String gbebuildfilter)
28
  {
818 mhunt 29
    mLogger.warn("SlaveThread rtag_id " + rtag_id + " rcon_id " + rcon_id);
814 mhunt 30
    mRtagId = rtag_id;
31
    mRconId = rcon_id;
32
    mGbebuildfilter = gbebuildfilter;
33
  }
34
 
35
  /**implements the sequence diagrams consume build files, allowed to proceed, check environment
36
   */
37
  public void run()
38
  {
39
    Integer id = new Integer(mRtagId);
40
    setName(id.toString());
41
    mLogger.debug("run");
42
    boolean exit = false;
868 mhunt 43
    RippleEngine rippleEngine = new RippleEngine(mReleaseManager, mRtagId, true);
814 mhunt 44
    MutableString buildFileContent = new MutableString();
45
 
46
    while(!exit)
47
    {
48
      try
49
      {
868 mhunt 50
        rippleEngine.collectMetaData();
51
 
814 mhunt 52
        if ( Thread.currentThread().isInterrupted() )
53
        {
54
          mLogger.warn("run is interrupted");
55
          // unit test technique
56
          throw new ExitException();
57
        }
58
 
59
        if ( mGbebuildfilter.compareTo("unit test spawn thread") == 0)
60
        {
61
          throw new Exception();
62
        }
63
 
64
        // allowed to proceed
65
        if ( mGbebuildfilter.compareTo("unit test consume build files") != 0)
66
        {
67
          mLogger.warn("run checking allowedToProceed");
868 mhunt 68
          allowedToProceed(false);
814 mhunt 69
          mLogger.info("run allowedToProceed returned");
70
        }
71
 
72
        // consume build files
73
        mLogger.warn("run consume build files");
74
        buildFileContent.value = "";
816 mhunt 75
        boolean logWarning = true;
814 mhunt 76
 
818 mhunt 77
        // additional handshake
78
        // Master waits for Slave to be in state waiting
79
        // wait for the Master to signal we are active
80
        MutableInt rconId = new MutableInt();
81
        MutableInt current_run_level = new MutableInt();
82
 
814 mhunt 83
        do
84
        {
818 mhunt 85
          mReleaseManager.querySingleRunLevel(mRconId);
86
          mReleaseManager.getFirstRunLevel(rconId, current_run_level);
814 mhunt 87
 
818 mhunt 88
          if (current_run_level.value != ReleaseManager.DB_ACTIVE)
814 mhunt 89
          {
90
            try
91
            {
816 mhunt 92
              if ( logWarning )
93
              {
818 mhunt 94
                mLogger.warn("run sleep 3 secs waiting for Master to set Slave run level ACTIVE");
816 mhunt 95
                logWarning = false;
96
              }
97
              else
98
              {
818 mhunt 99
                mLogger.info("run sleep 3 secs waiting for Master to set Slave run level ACTIVE");
816 mhunt 100
              }
814 mhunt 101
              // to do, sleep for periodicMs
102
              Thread.sleep(3000);
103
              mLogger.info("run sleep returned");
104
            }
105
            catch (InterruptedException e)
106
            {
107
              mLogger.warn("run caught InterruptedException");
108
            }
109
          }
818 mhunt 110
        } while (current_run_level.value != ReleaseManager.DB_ACTIVE);
111
 
112
        mReleaseManager.queryRunLevel(mRconId, buildFileContent);
814 mhunt 113
 
818 mhunt 114
        if ( buildFileContent.value.compareTo("") == 0)
115
        {
868 mhunt 116
          mLogger.fatal("run empty buildFileContent");
117
          throw new Exception("run empty buildFileContent");
818 mhunt 118
        }
119
 
814 mhunt 120
        mLogger.info("run consumed build files");
121
 
122
        if ( mGbebuildfilter.compareTo("unit test consume build files") == 0 )
123
        {
124
          throw new ExitException();
125
        }
126
 
127
        // set CURRENT_BUILD_FILES to null
128
        mReleaseManager.clearBuildFile(mRconId);
129
 
130
        // check environment
131
        mLogger.warn("run checkEnvironment");
132
        checkEnvironment();
133
        mLogger.info("run checkEnvironment returned");
134
 
135
        mSleep = true;
136
        if ( buildFileContent.value.compareTo(mDummyBuildFileContent) != 0 )
137
        {
138
          // deliver change to product baseline
139
          mLogger.warn("run deliverChange");
140
          setViewUp(buildFileContent.value, false);
866 mhunt 141
 
868 mhunt 142
          if ( mGbeGatherMetricsOnly != null )
143
          {
144
            // special for metrics
145
            // deliverChange on a benign target to get mReportingPackageName and mReportingPackageVersion set up
146
            // nb in the metrics gathering world the <rtagid>build.xml is provided by the master thread
147
            deliverChange(null, "fullstart", false);
148
 
149
            String archive = Package.mGbeDpkg;
150
 
151
            if (archive != null)
152
            {
153
              String fs = System.getProperty( "file.separator" );
154
              String destination = archive + fs + mReportingPackageName + fs + mReportingPackageVersion;
155
 
156
              // do this for all unix based platforms
157
              new File( destination ).mkdirs();
158
              new File( destination, "built.sparc" ).createNewFile();
159
              new File( destination, "built.solaris10_sparc32" ).createNewFile();
160
              new File( destination, "built.solaris10_x86" ).createNewFile();
161
              new File( destination, "built.linux_i386" ).createNewFile();
162
            }
163
 
164
          }
165
          else
166
          {
167
            deliverChange(null, null, false);
168
            deliverChange(null, "AbtTearDown", false);
169
          }
170
 
866 mhunt 171
          if ( mReportingBuildFailureLogFile != null )
172
          {
173
            // tweak the build failure log file in the database
174
            Integer rtagId = mRtagId;
175
 
176
            mReleaseManager.excludeFromBuild(mReportingPackageVersionId, mReportingPackageVersion, rtagId.toString(), null, null, mReportingBuildFailureLogFile);
177
          }
178
 
814 mhunt 179
          mLogger.info("run deliverChange returned");
180
          mSleep = false;
181
        }
182
 
183
      }
184
      catch( SQLException e )
185
      {
186
        // oracle connection issues        
187
         mLogger.warn("run oracle connection issues");
820 mhunt 188
         mSleep = true;
814 mhunt 189
      }
190
      catch( ExitException e )
191
      {
858 mhunt 192
        mLogger.warn("run ExitException");
814 mhunt 193
        exit = true;
194
      }
195
      catch( InterruptedException e )
196
      {
197
        mLogger.warn("run InterruptedException");
198
      }
199
      catch( Exception e )
200
      {
201
        mLogger.error("run indefinitePause");
868 mhunt 202
        String cause = e.getMessage();
203
 
204
        if ( cause != null )
814 mhunt 205
        {
868 mhunt 206
          try
207
          {
208
            // notify first
209
            // many reasons for indefinite pause, including database related, so do database last
210
            indefinitePause(rippleEngine, cause);
211
            mReleaseManager.indefinitePause();
212
          }
213
          catch( Exception f )
214
          {
215
            mLogger.error("run indefinitePause failed");
216
          }
814 mhunt 217
        }
218
      }
219
    }
220
  }
221
 
222
  /**returns 'S'
223
   */
224
  protected char getMode()
225
  {
226
    mLogger.debug("getMode");
227
    return 'S';
228
  }
229
}