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