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.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
   */
896 mhunt 27
  public SlaveThread(int rtag_id, int rcon_id, String unitTest)
814 mhunt 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;
896 mhunt 32
    if ( unitTest == null )
33
    {
34
      unitTest = new String();
35
    }
36
    mUnitTest = unitTest;
814 mhunt 37
  }
38
 
39
  /**implements the sequence diagrams consume build files, allowed to proceed, check environment
40
   */
41
  public void run()
42
  {
43
    Integer id = new Integer(mRtagId);
44
    setName(id.toString());
45
    mLogger.debug("run");
46
    boolean exit = false;
868 mhunt 47
    RippleEngine rippleEngine = new RippleEngine(mReleaseManager, mRtagId, true);
814 mhunt 48
    MutableString buildFileContent = new MutableString();
49
 
50
    while(!exit)
51
    {
52
      try
53
      {
886 mhunt 54
        sleepCheck();
868 mhunt 55
        rippleEngine.collectMetaData();
56
 
814 mhunt 57
        if ( Thread.currentThread().isInterrupted() )
58
        {
59
          mLogger.warn("run is interrupted");
60
          // unit test technique
61
          throw new ExitException();
62
        }
63
 
896 mhunt 64
        if ( mUnitTest.compareTo("unit test spawn thread") == 0)
814 mhunt 65
        {
66
          throw new Exception();
67
        }
68
 
69
        // allowed to proceed
896 mhunt 70
        if ( mUnitTest.compareTo("unit test consume build files") != 0)
814 mhunt 71
        {
886 mhunt 72
          mRunLevel = RunLevel.IDLE;
73
          mLogger.warn("run changing run level to IDLE for rcon_id " + mRconId);
74
          mRunLevel.persistNew(mReleaseManager, mRconId);
75
 
814 mhunt 76
          mLogger.warn("run checking allowedToProceed");
868 mhunt 77
          allowedToProceed(false);
814 mhunt 78
          mLogger.info("run allowedToProceed returned");
79
        }
80
 
886 mhunt 81
        mRunLevel = RunLevel.WAITING;
82
        mLogger.warn("run changing run level to WAITING for rcon_id " + mRconId);
83
        mRunLevel.persist(mReleaseManager, mRconId);
84
 
814 mhunt 85
        // consume build files
86
        mLogger.warn("run consume build files");
87
        buildFileContent.value = "";
816 mhunt 88
        boolean logWarning = true;
814 mhunt 89
 
818 mhunt 90
        // additional handshake
91
        // Master waits for Slave to be in state waiting
92
        // wait for the Master to signal we are active
93
        MutableInt rconId = new MutableInt();
94
        MutableInt current_run_level = new MutableInt();
95
 
814 mhunt 96
        do
97
        {
818 mhunt 98
          mReleaseManager.querySingleRunLevel(mRconId);
882 mhunt 99
          if ( !mReleaseManager.getFirstRunLevel(rconId, current_run_level) )
100
          {
101
            mLogger.warn("run no longer configured 1");
102
            throw new ExitException();
103
          }
814 mhunt 104
 
818 mhunt 105
          if (current_run_level.value != ReleaseManager.DB_ACTIVE)
814 mhunt 106
          {
107
            try
108
            {
816 mhunt 109
              if ( logWarning )
110
              {
818 mhunt 111
                mLogger.warn("run sleep 3 secs waiting for Master to set Slave run level ACTIVE");
816 mhunt 112
                logWarning = false;
113
              }
114
              else
115
              {
818 mhunt 116
                mLogger.info("run sleep 3 secs waiting for Master to set Slave run level ACTIVE");
816 mhunt 117
              }
814 mhunt 118
              // to do, sleep for periodicMs
119
              Thread.sleep(3000);
120
              mLogger.info("run sleep returned");
121
            }
122
            catch (InterruptedException e)
123
            {
124
              mLogger.warn("run caught InterruptedException");
125
            }
126
          }
818 mhunt 127
        } while (current_run_level.value != ReleaseManager.DB_ACTIVE);
128
 
129
        mReleaseManager.queryRunLevel(mRconId, buildFileContent);
814 mhunt 130
 
818 mhunt 131
        if ( buildFileContent.value.compareTo("") == 0)
132
        {
882 mhunt 133
          mLogger.warn("run no longer configured 2");
134
          throw new ExitException();
818 mhunt 135
        }
136
 
814 mhunt 137
        mLogger.info("run consumed build files");
138
 
896 mhunt 139
        if ( mUnitTest.compareTo("unit test consume build files") == 0 )
814 mhunt 140
        {
141
          throw new ExitException();
142
        }
143
 
144
        // set CURRENT_BUILD_FILES to null
145
        mReleaseManager.clearBuildFile(mRconId);
146
 
147
        // check environment
148
        mLogger.warn("run checkEnvironment");
149
        checkEnvironment();
150
        mLogger.info("run checkEnvironment returned");
151
 
152
        mSleep = true;
153
        if ( buildFileContent.value.compareTo(mDummyBuildFileContent) != 0 )
154
        {
155
          // deliver change to product baseline
156
          mLogger.warn("run deliverChange");
157
          setViewUp(buildFileContent.value, false);
866 mhunt 158
 
868 mhunt 159
          if ( mGbeGatherMetricsOnly != null )
160
          {
161
            // special for metrics
162
            // deliverChange on a benign target to get mReportingPackageName and mReportingPackageVersion set up
163
            // nb in the metrics gathering world the <rtagid>build.xml is provided by the master thread
164
            deliverChange(null, "fullstart", false);
165
 
166
            String archive = Package.mGbeDpkg;
167
 
168
            if (archive != null)
169
            {
170
              String fs = System.getProperty( "file.separator" );
171
              String destination = archive + fs + mReportingPackageName + fs + mReportingPackageVersion;
172
 
173
              // do this for all unix based platforms
174
              new File( destination ).mkdirs();
175
              new File( destination, "built.sparc" ).createNewFile();
176
              new File( destination, "built.solaris10_sparc32" ).createNewFile();
177
              new File( destination, "built.solaris10_x86" ).createNewFile();
178
              new File( destination, "built.linux_i386" ).createNewFile();
179
            }
180
 
181
          }
182
          else
183
          {
184
            deliverChange(null, null, false);
185
            deliverChange(null, "AbtTearDown", false);
186
          }
187
 
866 mhunt 188
          if ( mReportingBuildFailureLogFile != null )
189
          {
190
            // tweak the build failure log file in the database
191
            Integer rtagId = mRtagId;
192
 
908 mhunt 193
            // force exclusion by default
194
            int testBuildInstruction = 0;
195
            try
196
            {
197
              testBuildInstruction = Integer.parseInt( mReportingTestBuild );
198
            }
199
            catch( NumberFormatException nfe )
200
            {
201
            }
202
            mReleaseManager.excludeFromBuild(mReportingPackageVersionId, mReportingPackageVersion, rtagId.toString(), null, null, mReportingBuildFailureLogFile, false, testBuildInstruction);
866 mhunt 203
          }
204
 
814 mhunt 205
          mLogger.info("run deliverChange returned");
206
          mSleep = false;
207
        }
208
 
209
      }
210
      catch( SQLException e )
211
      {
212
        // oracle connection issues        
213
         mLogger.warn("run oracle connection issues");
886 mhunt 214
         mException = true;
814 mhunt 215
      }
216
      catch( ExitException e )
217
      {
858 mhunt 218
        mLogger.warn("run ExitException");
814 mhunt 219
        exit = true;
220
      }
221
      catch( InterruptedException e )
222
      {
223
        mLogger.warn("run InterruptedException");
224
      }
225
      catch( Exception e )
226
      {
227
        mLogger.error("run indefinitePause");
868 mhunt 228
        String cause = e.getMessage();
229
 
230
        if ( cause != null )
814 mhunt 231
        {
868 mhunt 232
          try
233
          {
234
            // notify first
235
            // many reasons for indefinite pause, including database related, so do database last
896 mhunt 236
            mRecoverable = false;
237
 
238
            if ( cause.compareTo(Package.mRecoverable) == 0 )
239
            {
240
              mRecoverable = true;
241
            }
242
 
868 mhunt 243
            indefinitePause(rippleEngine, cause);
244
            mReleaseManager.indefinitePause();
886 mhunt 245
            // DEVI 51366 force sleep at beginning of while loop
246
            mException = true;
868 mhunt 247
          }
248
          catch( Exception f )
249
          {
250
            mLogger.error("run indefinitePause failed");
251
          }
814 mhunt 252
        }
253
      }
254
    }
255
  }
256
 
257
  /**returns 'S'
258
   */
259
  protected char getMode()
260
  {
261
    mLogger.debug("getMode");
262
    return 'S';
263
  }
264
}